# Plotting 1MHz sine wave

7 visualizaciones (últimos 30 días)
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);
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuesta aceptada

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 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
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 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);
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Annotations en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by