title: How do I turn a square signal into a triangular signal in matlab
body: <p>I want to turn the square signal below into a triangular signal. How do I do that? I have tried to do it using the sawtooth/square functions but I have to do it without using those (Also, sawtooth is not triangular, so there goes that). I have managed to write the code for a square signal but I don't know what exactly to change in order for it to be triangular.</p>
  
  <pre><code>P=40; 
  D=12; 
  N=50; 
  f=1/P; 
  w0=2*pi*f; %angular frequency
  rez=0.1; %signal's temporal resolution
  
  s1=[ones(1,D/rez),zeros(1,(P-D)/rez)]; %a period of the square signal
  t=0:rez:P; %equivalent time for a period
  perioada=P/rez;%number of samples in a period
  inter1=0:rez:P;
  stem(inter1(1:400),s1)
  title('Square Signal x(t)'),
  xlabel('t[s]')
  ylabel('A')
  
  semnal=repmat(s1,1,5);%initial signal repeated 5 times
  figure
  plot(semnal)
  title('5 periods from the signal')
  xlabel('t[s]')
  ylabel('A')
  </code></pre>