Plotting 1MHz sine wave
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
jgg
2016-1-25
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 个)
Chad Greene
2016-1-25
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!