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
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 个评论
Chad Greene
2021-4-20
Set nwid to some number larger than 2 to loop through a range of values from nn=2 to nn=nwid.
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!