How to Create A Triangle waveform in MATLAB

Thread Starter

Willson Toh

Joined Oct 1, 2011
1
Does anyone have an idea to create a Triangle waveform?

The reason i require this is because i require to compare a Sinewave and a Triangle to create a SPWM.

In another i need the MATLAB assistant to calculate the duty cycle in order to create a lookup table.

Your help is very important for my understanding

Regard
Willson
 

panic mode

Joined Oct 10, 2011
1,783
derivative of sine is another sine function (cos).
try this

clear;

ymax=3.5;
xmin=-10;
xmax= 10;
x0=0;
T=4;
step=0.03;
n=(xmax-xmin)/step;
y=1:n;
x=1:n;

for i=1:n
x(i)=xmin+i*step;
y(i)=ymax*abs(((mod(x(i),T))*2/T-1));
end

plot(x,y);
 
Last edited:
Top