unable to plot diagram in MATLAB
Afficher commentaires plus anciens
can anybody help me plotting the diagram below in Matlab (just one of them; the colorful one)?

I wrote the code below but the result isn't same.
clc;clear;close all;
t=linspace(0,5,100);
for i=1:length(t)
if (i>=0) && (i<0.5) ;
zp1(i)=0;
else if (i>=0.5) && (i<2.5);
zp1(i)=0.05*sin(2*pi*i);
else if i>=2.5 ;
zp1(i)=0;
end
end
end
end
plot(t,zp1)
Réponses (1)
Cris LaPierre
le 17 Fév 2021
Modifié(e) : Cris LaPierre
le 17 Fév 2021
1 vote
Work on creating a sin wave that generates the amplitude and frequency you need first. Once you have that, set all y values corresponding to t<0.5 and t>2.5 to zero.
4 commentaires
Tina M
le 18 Fév 2021
Cris LaPierre
le 18 Fév 2021
Can you first create a sin wave with 0.05 amplitude and period of 2 seconds?
Tina M
le 20 Fév 2021
Cris LaPierre
le 20 Fév 2021
Modifié(e) : Cris LaPierre
le 20 Fév 2021
Let's work with sin only. You are on to something here.
y2=@(t) -0.05*sin(2*pi*t);
Have you realized that a sine wave repeats every
seconds? If I want it to repeat every 2 seconds, I can just multiply t by π, making t at 2 seconds
.
seconds? If I want it to repeat every 2 seconds, I can just multiply t by π, making t at 2 seconds
.t=linspace(0,5,100);
y = 0.05*sin(t*pi);
plot(t,y)
A sin wave crosses the x axis at sin(0). You want that to haen at t=0.5. You can adjust the zero crossing by adding or subtracting to t. For example, x=t+0.5 will now move sin(0) to x=0.5.
Put that all together and you get
plot(t+0.5,y)
grid on
Catégories
En savoir plus sur Fourier Analysis and Filtering dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


