Unexpected result for sin()

4 ビュー (過去 30 日間)
Lorenzo
Lorenzo 2012 年 12 月 1 日
Dear all;
I think I'm getting crazy or something. Fact is that Matlab is giving me some strange results for a simple sin function.
If I try and run the following:
f=30;
x=0:0.01:1;
y=0.7*sin(2*pi*f*x);
plot(x,y)
I get a simple wave plot.
Now, if I change f to 50, then I get this strange plot:
How is that possible?
Thank you!

回答 (4 件)

Wayne King
Wayne King 2012 年 12 月 1 日
編集済み: Wayne King 2012 年 12 月 1 日
Because you are evaluating sin() at multiples of pi
2*pi*k/2
Each one of your steps in x is a multiple of 1/100, then you are multiplying that by 50 when f=50 so you are evaluating sin() at multiples of 2*pi*k/2 and they will all be essentially zero. Look at the y-axis of your plot. Those numbers are all essentially zero.
Actually even your 30-Hz sine does not look that good because you are sampling your x-vector too coarsely, compare for example
x = 0:0.01:1;
xprime = 0:0.001:1;
y = sin(2*pi*30*x);
yprime = sin(2*pi*30*xprime);
subplot(211)
plot(x,y)
subplot(212)
plot(xprime,yprime)

Matt Fig
Matt Fig 2012 年 12 月 1 日
編集済み: Matt Fig 2012 年 12 月 1 日
In general, you need to make your sample frequency sensitive to the signal frequency... (Nyquist)
f = 50;
x = 0:0.1/(2*f):1; % Sample frequency
y = 0.7*sin(2*pi*f*x);
plot(x,y)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 12 月 1 日
編集済み: Azzi Abdelmalek 2012 年 12 月 1 日
f=50;
np=5 % number of period
t1=np/f % final time
ns=20 % number of sample per period
ts=1/(ns*f) % sample time
x=0:ts:t1;
y=0.7*sin(2*pi*f*x);
plot(x,y)

Lorenzo
Lorenzo 2012 年 12 月 1 日
Thank you very much everybody! I figured that out eventually!

カテゴリ

Help Center および File ExchangeAudio Processing Algorithm Design についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by