Plotting a train pulse

2 次查看(过去 30 天)
Nicolas
Nicolas 2012-3-15
Hello!!
I need to plot differents square waves changing the frecuency for later on compute the fft and see how it changes. The problem is that I dont know how to plot a function that from 0-Tc/2 is 1 and from Tc/2-Tc is -1. One that I clear that, I need to compute another function that is 1 for 0-Tc/4, -1 for Tc/4-Tc/2 , 1 for Tc/2-3Tc/4 , -1 for 3Tc/4-Tc
and then so on, to see how the frecuency change affect to the fft. So I have to be able to compute the fft of the function, so I think that I cant define just vector and plot them. I am a little bit lost, I will appreciate any help Thanks in advance, Nicolas

回答(3 个)

Masoud Ghanbari
Masoud Ghanbari 2012-3-15
Hi Nic I think i've got your mean.you need a plot which has a clamp just like unit step.you can plot it by vectors.here is a code of unit step.you can change it into what you want just by changing numbers
u=[ 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 ]; t=[-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 0 2 3 4 5 6 7 8 9 10]; plot(t,u); axis([-10 10 -1 2])
the point is that we have 2 values in t=0 and it is a clamp. Hope it works

Nicolas
Nicolas 2012-3-15
thanks Masoud...yes, it works but i have to write it in a way that I can change easily and not doing manually.... I think that I have to define by pieces the function.But I dont know why thanks

Masoud Ghanbari
Masoud Ghanbari 2012-3-15
Lets see...
for t=(-10:.01:10)
if t<0
plot(t,0,'linewidth',5);
hold on;
else t>=0;
plot(t,1,'linewidth',5)
hold on
end
end
axis([-10 10 -2 2])

Community Treasure Hunt

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

Start Hunting!

Translated by