Can someone help me with the square wave plot here?

I've outlined most of my code below, but I'm having issues getting my plot to display the correct time scale.
Any help would be appreciated!
function funPulseTrainPlot(N,T,D,A)
clc
t = linspace(0,T,N*T);% create time vector
x = A*square(t/T*2*pi, D);% create pulse train signal
plot(t, x);
%xlim([0 40]);
xlabel('Time (sec)');
ylabel('Amplitude');
title(['Pulse Train with N = ' num2str(N) ', D = ' num2str(D) ', A = ' num2str(A) ', T = ' num2str(T) ' sec']);
end

Réponses (1)

T=12;
N=3;
D=25;
A=3;
t= 0:0.001:1;
x = A*((1+square(2*pi*N*t,D))/2);
t2=t*T*N;
plot(t2, x);

1 commentaire

Thank you, this was very close to what I was trying to do!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with MATLAB dans Centre d'aide et File Exchange

Produits

Version

R2018a

Question posée :

le 19 Jan 2023

Commenté :

le 19 Jan 2023

Community Treasure Hunt

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

Start Hunting!

Translated by