unable to plot diagram in MATLAB
Mostrar comentarios más antiguos
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)
Respuestas (1)
Cris LaPierre
el 17 de Feb. de 2021
Editada: Cris LaPierre
el 17 de Feb. de 2021
1 voto
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 comentarios
Tina M
el 18 de Feb. de 2021
Cris LaPierre
el 18 de Feb. de 2021
Can you first create a sin wave with 0.05 amplitude and period of 2 seconds?
Tina M
el 20 de Feb. de 2021
Cris LaPierre
el 20 de Feb. de 2021
Editada: Cris LaPierre
el 20 de Feb. de 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
Categorías
Más información sobre Fourier Analysis and Filtering en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


