Help to generate periodic triangular pulse and vary its duty cycle.

3 views (last 30 days)
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.

Answers (1)

Mathieu NOE
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 ?
  1 Comment
Rafael Ortiz
Rafael Ortiz on 7 Mar 2022
Hi @Mathieu NOE, thanks for your reply, ahh, I see, you are right.
Although the exercise asks me to show only one pulse and vary the duty cycle in percentage.Although the exercise asks me to show only one pulse and vary the duty cycle in percentage.

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!