plot3 gives strange plot

2 visualizaciones (últimos 30 días)
Raady
Raady el 16 de En. de 2017
Comentada: Walter Roberson el 16 de En. de 2017
I want to plot 3 signal for comparision as in 3d view, so that I can clearly observe the change in different signals.
For an example I want to plot 3 sin signals with different frequencies.
t = [0:0.1:20];
A = 1;
f = 10000;
y1 = A*sin(1000*t);
y2 = A*sin(1250*t);
y3 = A*sin(1500*t);
plot3(y1,y2,y3);
the plot is very strange. where have I gone wrong ?
If i do as plot3(y1,y2,y3,t); it gives error as no enough arguments. Please suggest me how can i plot as the first figure

Respuesta aceptada

Raady
Raady el 16 de En. de 2017
John thanks for your reply, but I was concerning about plot as first figure not the second ones i misunderstood the plot3, here is my code and what i wanted to plot that as
t = 1:100;
x1 = ones(1,100);
x2 = 2*x1;
x3 = 4*x1;
s1 = sin(t);
s2 = sin(2*t);
s3 = sin(4*t);
figure(1);
hold on;
plot3(t,x1,s1);
plot3(t,x2,s2);
plot3(t,x3,s3);
hold off;
  2 comentarios
John BG
John BG el 16 de En. de 2017
Raady
thanks for your fast response.
The reason why you get quirky signals is: Alias
Your are not sampling enough samples per cycle, so the 3 plots miss some peaks and some valleys.
Use the values I have given you:
1.
Shorter time window: from what you have shown there is not need for more than the few cycles you show in the first image. 2 seconds is excessive.
2.
Higher sampling frequency: Is same as smaller time step.
Replace
t = [0:0.1:20];
with
t = [0:0.00001:0.1];
The 3D plotting is nice but, correct me if wrong, the reason why you posted the question is that your plot doesn't look as smooth as the one you show in the question, and the one show by other contributors to your question.
The reason is: not enough samples
Once you have enough samples per cycle, any plot you choose will resemble sin(wt) cos(wt), as expected.
This is why I kindly ask you to consider marking my answer as the accepted answer.
Regards
Walter Roberson
Walter Roberson el 16 de En. de 2017
No, the problem is not to do with aliasing. Raady was trying to plot three separate plots with a single plot3() call, thinking that each component would get drawn as a separate 2D layer.

Iniciar sesión para comentar.

Más respuestas (2)

John BG
John BG el 16 de En. de 2017
refine, your plot is suffering alias.
What about this
format long;t = [0:0.00001:0.1];
A = 1;
y1 = A*sin(1000*t);
y2 = A*sin(1250*t);
y3 = A*sin(1500*t);
plot3(y1,y2,y3);
.
.
It doesn't seem you are using this line
f = 10000;
would you please be so kind to consider marking my answer as Accepted Answer?
thanks for time and attention, awaiting answer

Star Strider
Star Strider el 16 de En. de 2017
The ribbon plot may do what you want.
The Code
t = [0:0.1:20];
A = 1;
f = 10000;
y1 = A*sin(1000*t);
y2 = A*sin(1250*t);
y3 = A*sin(1500*t);
figure(1)
hr = ribbon(t, [y1; y2; y3]', 0.1)
grid on
set(hr, 'EdgeColor','none')
axis([xlim ylim [-2 2]])
view([-50 45])
The Plot
Experiment to get the result you want.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by