- Define y as the step value at each step (row vector).
- Define dx as the x-interval (scalar).
- Define x0 as the starting x-coordinate (scalar).
I want to create a square wave shows in the Picture
1 view (last 30 days)
Show older comments
Hi All,
I would like to create a square wave as shown in the figure, which start at 1 ends at 0, has opposite polarity at same peroid. Frequency is 32 Hz and sample rate is 32768.
0 Comments
Answers (2)
Adam Danz
on 9 Jun 2021
Inputs:
% inputs
y = [1 0 -1 0];
dx = 1;
x0 = 0;
% Create step function
x = x0 + cumsum(dx*ones(size(y)));
xr = [x(1),repelem(x(2:end),1,2)]; % X is row vec
yr = [repelem(y(1:end-1),1,2),y(end)]; % Y is row vec
% Plot results
plot(xr,yr)
axis padded
grid on
0 Comments
Steven Lord
on 9 Jun 2021
Looking at the Plots tab of the Toolstrip, the thumbnail that looks closest to the picture that you posted is the stairs function. Take a look at the documentation page for that function and see if it suits your needs.
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!