Plotting a square pulse periodic function

6 次查看(过去 30 天)
Hi,
could you please help me with the issue
I wrote a code to generate a periodic square pulse function. I am getting different output if i change the limits, which looks quite weird to me
here is my code and the output
the pulses start missing if i change the limits
clc
clear all
close all
syms t;
T=5;
x =@(t)piecewise((t-T*round(t/T))<-0.5,0,(t-T*round(t/T))>0.5,0,-0.5<=(t-T*round(t/T))<=0.5,1);
figure()
subplot(2,1,1)
fplot(t,x(t),[-21 21]);title('input signal x(t)');xlabel('time in s -->');ylabel('value');
subplot(2,1,2)
%Here I am just changing the limits of the x axis but getting different plot
fplot(t,x(t),[-25 25]);title('input signal x(t)');xlabel('time in s -->');ylabel('value');

回答(1 个)

Star Strider
Star Strider 2020-11-13
I am not certain what you are doing, or what you want.
There are several ways to create square wave pulse trains. Probably the easiest is:
sqrwav = @(t,TL,f) sign(sin(2*pi*t*f)-TL); % Create Square Wave, Threshold = TL, Frequency = f
t = linspace(0, 25, 500);
freq = 0.5;
ThrshLim = 0.9;
figure
plot(t, sqrwav(t,ThrshLim,freq))
grid
ylim(ylim*1.1)
freq = 0.25;
ThrshLim = -0.5;
figure
plot(t, sqrwav(t,ThrshLim,freq))
grid
ylim(ylim*1.1)
If you want regular repeating pulses with at 50% duty cycle, use TL=0.
Experiment to get the result you want.
  1 个评论
Saurabh Kumar
Saurabh Kumar 2020-11-13
My main doubt is, look at the difference between subplot(2,1,1) and subplot(2,1,2). I have just changed the limits on the X-axis but i am getting a different plot.In subplot(2,1,2), Concentrate on x=-10,-15,10,15, the pulses are missing from there when compared to the other figure. Why is it happening, i am just plotting x(t) in both cases, the ony difference is change in limits, why is it generating different plots.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by