
Help to generate periodic triangular pulse and vary its duty cycle.
3 views (last 30 days)
Show older comments
Hi guys, I am trying to generate a periodic triangular pulse Ac, with a frequency of 2khz and an amplitude of 8, i am also struggling to find a way to vary the cycle.
This is my script:
f = 2000;
T = 10*(1/f);
Fs = 4*f;
t = 0:1/Fs:T-1/Fs;
x = 8*sawtooth(2*pi*400*t);
plot(t,x)
Thanks in advance.
0 Comments
Answers (1)
Mathieu NOE
on 7 Mar 2022
hello
your code generates a 400 sawtooth signal , not a 2 kHz triangular wave
I made a few mods in your code to get the correct result

f_signal = 2000;
periods = 10;
T = periods*(1/f_signal);
Fs = 4*f_signal;
dt = 1/Fs;
t = 0:dt:T-dt;
x = 8*sawtooth(2*pi*f_signal*t,0.5);
plot(t,x)
what do you mean by "vary the cycle" ? are you referring to the width parameter of sawtooth function ?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!