How do I plot a periodic square-wave for 10 cycles, 5 cycles in advance of t=0 and 5 cycles to the right of t=0 using a unit step function?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gretchen
am 19 Okt. 2016
Bearbeitet: Chaya N
am 19 Okt. 2016
I am trying to plot a square wave using a unit step function.
0 Kommentare
Akzeptierte Antwort
Chaya N
am 19 Okt. 2016
Bearbeitet: Chaya N
am 19 Okt. 2016
A square wave is more accurately an impulse function (that is also periodic), which is the first derivative of a step function. To define the function, you need a time index for the rising edge and another time index for the falling edge.
For example, to plot one cycle of a square wave with a rising edge at t = 0 and a falling edge at t = 0.5, the function would be f[t] = u[t] - u[t-0.5].
Below I am including a very simple code to show two full cycles of your square wave for (-1 < t <= 0) and (0 < t <= 1). Please note the format and sign of the time stamps and how the individual cycles are grouped inside the square brackets (which are not required in the code but only meant as illustration for the grouping here). You can expand upon this and hopefully construct your required wave.
t = linspace(-2, 2, 1000); % This defines the time scale in the plot
f = @(t) [(t > 0) - (t > 0.5)] + [(t > -1) - (t > -0.5)];
stairs(t, f(t));
The plot from the above function looks like the figure below.
Good luck!
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!