title: Limiting a signal by multiplying it by an array
body: <p>I'm trying to limit a signal by multiplying the signal by an array to limit the amplitude within a certain range.  The signal in <strong>(green) the tot array</strong> isn't suppose to go past the limiting array in <strong>(red) the ptest array</strong>, but it does, <em>how can I fix this so the green signal doesn't go past the red line (ptest array)</em>? see code and plot below.  <strong>Please note this is a simple test the signals will be more complicated.</strong> </p>
  
  <p>I'm using octave 3.8.1 which is like matlab</p>
  
  <p><a href="https://i.stack.imgur.com/lXOjB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lXOjB.jpg" alt="plot"></a></p>
  
  <pre><code>fs=200
  x=[0,.2,.5,1]
  y=[1,.5,.1,0]
  
  t=linspace(0,x(end),fs);
  peq=polyfit(x,y,length(y)); %create polynomial from points
  
  ptest=polyval(peq,t); %plug numbers into polynomial
  plot(ptest,t,'-ro') 
  hold on 
  plot(x,y,'b*')
  
  t2=linspace(0,2*pi,fs);
  s1 = sin(10*t2) ; %signal to limit
  tot=ptest.*s1;
  plot(t,tot,'-g')
  </code></pre>