How do I make this square wave graph?

조회 수: 16 (최근 30일)
JayP
JayP 2021년 4월 8일
편집: Adam Danz 2021년 4월 8일
I don't know how to make the cycle repeat itself.

채택된 답변

Adam Danz
Adam Danz 2021년 4월 8일
편집: Adam Danz 2021년 4월 8일
Set the parameters at the top.
% Parameters
period = 2*pi; % Period
xrange = [0, 6*pi]; % [start,end] x values
amplitude = 2; % peak-trough amplitude
verticalShift = 0; % Vertical shift, negative shifts downward
phaseShift = 0; % Phase shift, negative shifts rightward
% create step fcn
th = linspace(xrange(1), xrange(2), 1000);
y = amplitude*(sin(2*pi/period*th+phaseShift)>0)-amplitude/2+verticalShift;
% Plot it
plot(th, y)
ylim([-2,2])
grid on

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Switches and Breakers에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by