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 Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by