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
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
Tina M le 18 Fév 2021
tnx , can you plz tell me how I can write the code in MATLAB?
Cris LaPierre
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
Tina M le 20 Fév 2021
yes, I could plot the first diagram(the colorful one) .
but I had problem in plotting second one. second one follows the same trajectory as the first one with a delay of t=0.1407 s . I wrote the code bellow ,But the result is not the same as the problem's diagram.
clc;clear;close all;
y1=@(t) 0*t.^0 ;
y2=@(t) -0.05*sin(2*pi*t);
y3=@(t) 0*t.^0;
t1=0:0.01:0.6407;
t2=0.6407:0.01:2.6407;
t3=2.6407:0.01:5;
t=[t1 t2 t3];
Zp2=[y1(t1) y2(t2) y3(t3)];
plot(t,Zp2)
axis([0 5 -0.06 0.06]);
grid on
the result is :
Cris LaPierre
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 .
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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Fourier Analysis and Filtering dans Centre d'aide et File Exchange

Question posée :

le 17 Fév 2021

Modifié(e) :

le 20 Fév 2021

Community Treasure Hunt

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

Start Hunting!

Translated by