Borrar filtros
Borrar filtros

Plotting 1MHz sine wave

4 visualizaciones (últimos 30 días)
Maty Blanc
Maty Blanc el 25 de En. de 2016
Comentada: Maty Blanc el 25 de En. de 2016
Hi, so the title summarizes what I am trying to do. My MATLAB knowledge is minimal, I only know some C++ which at this point is saving me. I am trying to play around with the 't' variable but I keep getting the value extremely small to the point MATLAB thinks it's is value 0. The sample size is what it is confusing me. Can anyone help me code this please? I am just trying to get a pretty plot, that's all. Thank you.
clear all;
figure(1);
N = 64;
apl = 2;
freq = 1e6;
shift = pi/3;
T = 1/freq;
S = 3*T;
t = 0:1/N:S;
x = apl * sin(2*pi*freq*t + shift);
plot(t,x);

Respuesta aceptada

jgg
jgg el 25 de En. de 2016
Just change this line:
t = 0:1/N:S;
to this
t = 0:(1/N)*S:S;
The issue was that you are telling Matlab to create t as a vector of values from 0 to 3/1e6 in steps of 1/64. You want to to take 64 steps, not steps of SIZE 1/64. This correction should fix it.
  1 comentario
Maty Blanc
Maty Blanc el 25 de En. de 2016
That's perfect. Thank you very much.

Iniciar sesión para comentar.

Más respuestas (1)

Chad Greene
Chad Greene el 25 de En. de 2016
I see the problem. 1/N is 1/64 and you're trying to populate a vector in steps of 1/N from 0 to 3e-6 when you do
t = 0:1/N:S;
Do you want 64 steps from 0 to S? If so use
t = linspace(0,S,64);

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by