How to plot a sequence of rectangular pulses with a period of 2 seconds, amplitude 1 unit, duty cycle 50%, and the pulses run for 10 seconds.

15 次查看(过去 30 天)
Fs = 0.5;
t = 0:1/Fs:10;
pulsewidth = 1e-6;
pulseperiods = 0:10;
x = pulstran(t,pulseperiods,@rectpuls,pulsewidth);
plot(t,x)
axis([0 10 0 1])
nwid = 1;
for nn = 2:nwid
x = pulstran(t,pulseperiods,@rectpuls,nn*pulsewidth);
subplot(nwid,1,nn)
plot(t,x)
axis([0 10 0 1])
D = dutycycle(x,Fs);
title(['Duty cycle is ' num2str(mean(D))])
end

回答(1 个)

Chad Greene
Chad Greene 2017-9-10
You have these lines
nwid = 1;
for nn = 2:nwid
...
end
which effectively says for nn = 2:1, so nothing in the loop will run.
  3 个评论
Ayush singhal
Ayush singhal 2021-4-21
yes got it.
One more question.
I want to generate rectangular stripes as black white pattern. And width of the stripes should be half of the period of stripes.
Can you give any direction for this code?

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by