if true
% code
%to generate all different waveforms
clc;
a=5;b=6;c=7;d=8;
t=0:0.01:1;
f=2;
r=0;
w=2.*pi.*f;
alpha=50;
beta=70;
m=0.5;
k=1;
X=a*sin(w*t+r);
Y=c*cos(w*t+r);
Z=c*square(w*t,alpha);
T=d*square(w*t,beta);
U=d*sawtooth(w*t,m);
N=d*sawtooth(w*t,k);
figure;
subplot(321);
plot(t,X) *bold*
title('continuous sine waveform')
xlabel('time');
ylabel('amplitude');
subplot(322);
stem(t,Y);
title('continuous cosine waveform');
xlabel('time');
ylabel('amplitude');
subplot(323);
stem(t,Z);
title('continuous square waveform');
xlabel('time');
ylabel('amplitude');
subplot(324);
stem(t,T);
title('continuous rectangular waveform');
xlabel('time');
ylabel('amplitude');
subplot(325);
stem(t,U);
title('continuous triangular waveform');
xlabel('time');
ylabel('amplitude');
subplot(326);
stem(t,N);
title('sawtooth waveform');
xlabel('time');
ylabel('amplitude');
end

Réponses (1)

KSSV
KSSV le 16 Jan 2022
It is working fine. Copy and run like shown below:
%to generate all different waveforms
clc;
a=5;b=6;c=7;d=8;
t=0:0.01:1;
f=2; r=0;
w=2.*pi.*f;
alpha=50;
beta=70; m=0.5; k=1;
X=a*sin(w*t+r);
Y=c*cos(w*t+r);
Z=c*square(w*t,alpha);
T=d*square(w*t,beta);
U=d*sawtooth(w*t,m);
N=d*sawtooth(w*t,k);
figure;
subplot(321);
plot(t,X)
title('continuous sine waveform')
xlabel('time');
ylabel('amplitude');
subplot(322);
stem(t,Y);
title('continuous cosine waveform');
xlabel('time');
ylabel('amplitude');
subplot(323);
stem(t,Z);
title('continuous square waveform');
xlabel('time');
ylabel('amplitude');
subplot(324);
stem(t,T);
title('continuous rectangular waveform');
xlabel('time');
ylabel('amplitude');
subplot(325);
stem(t,U);
title('continuous triangular waveform');
xlabel('time');
ylabel('amplitude');
subplot(326);
stem(t,N);
title('sawtooth waveform');
xlabel('time');
ylabel('amplitude');

Catégories

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

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by