How to generate correct sine wave
111 次查看(过去 30 天)
显示 更早的评论
hello, I want to make the sine wave
when I execute below code at frequency 2, It is success.
but when I change the frequency to 10, It is not Sine wave..
What's wrong my code??
== correct ==
fs = 50;
t = 0:1/fs:1-1/fs;
x = sin(2*pi*2*t);
plot(t,x)
== non-correct
fs = 50;
t = 0:1/fs:1-1/fs;
x = sin(2*pi*10*t);
plot(t,x)
0 个评论
回答(2 个)
Kevin Holly
2022-3-17
编辑:Kevin Holly
2022-3-17
== correct ==
fs = 50;
t = 0:1/fs:1-1/fs;
x = sin(2*pi*2*t);
plot(t,x)
== non-correct
fs = 50;
t = 0:1/fs:1-1/fs;
x = sin(2*pi*10*t);
plot(t,x)
Corrected
fs = 500;
t = 0:1/fs:1-1/fs; %Increase the sample rate
x = sin(2*pi*10*t);
plot(t,x)
Your sampling freqency needs to be twice the size of the highest frequency you are detecting. See Nyquist Theorem.
6 个评论
Kevin Holly
2022-3-18
Sorry about that, I missed the 2*pi.
subplot(2,1,1)
fs = 20;
t = 0:1/fs:1-1/fs;
x = sin(2*pi*10*t);
plot(t,x)
subplot(2,1,2)
fs = 2*pi*20;
t = 0:1/fs:1-1/fs;
x = sin(2*pi*10*t);
plot(t,x)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Signal Generation and Preprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!