unable to plot diagram in MATLAB
Ältere Kommentare anzeigen
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)
Antworten (1)
Cris LaPierre
am 17 Feb. 2021
Bearbeitet: Cris LaPierre
am 17 Feb. 2021
1 Stimme
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 Kommentare
Tina M
am 18 Feb. 2021
Cris LaPierre
am 18 Feb. 2021
Can you first create a sin wave with 0.05 amplitude and period of 2 seconds?
Tina M
am 20 Feb. 2021
Cris LaPierre
am 20 Feb. 2021
Bearbeitet: Cris LaPierre
am 20 Feb. 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
Kategorien
Mehr zu Fourier Analysis and Filtering finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


