Plotting a square pulse periodic function
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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');

0 comentarios
Respuestas (1)
Star Strider
el 13 de Nov. de 2020
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.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!