Plotting 1MHz sine wave

6 vues (au cours des 30 derniers jours)
Maty Blanc
Maty Blanc le 25 Jan 2016
Commenté : Maty Blanc le 25 Jan 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);

Réponse acceptée

jgg
jgg le 25 Jan 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 commentaire
Maty Blanc
Maty Blanc le 25 Jan 2016
That's perfect. Thank you very much.

Connectez-vous pour commenter.

Plus de réponses (1)

Chad Greene
Chad Greene le 25 Jan 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);

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by