Plotting 1MHz sine wave

6 views (last 30 days)
Maty Blanc
Maty Blanc on 25 Jan 2016
Commented: Maty Blanc on 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);

Accepted Answer

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

Sign in to comment.

More Answers (1)

Chad Greene
Chad Greene on 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);

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!