How do I make this square wave graph?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens

I don't know how to make the cycle repeat itself.
0 commentaires
Réponse acceptée
Adam Danz
le 8 Avr 2021
Modifié(e) : Adam Danz
le 8 Avr 2021
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Switches and Breakers dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
