Plotting a square pulse periodic function

조회 수: 6 (최근 30일)
Saurabh Kumar
Saurabh Kumar 2020년 11월 13일
댓글: Saurabh Kumar 2020년 11월 13일
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