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?
5 次查看(过去 30 天)
显示 更早的评论
采纳的回答
Chaya N
2016-10-19
编辑:Chaya N
2016-10-19
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 个评论
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!