fft of sin(pi*x/5)./(pi*x) returns NaN

12 ビュー (過去 30 日間)
SYML2nd
SYML2nd 2019 年 7 月 11 日
回答済み: Star Strider 2019 年 7 月 11 日
Hi,
I don't know why, if I do the G=sin(pi*x/5)./(pi*x), it returns NaN, can you help me?
Thanks
x=-100:0.1:100
G=sin(pi*x/5)./(pi*x)
H= abs(fft(G))
Tinc=0.01
Fs=1/Tinc;
freq =transpose( -Fs/2:Fs/length(G):Fs/2-(Fs/length(G)));
figure()
plot(x,G)
figure()
plot(freq,H)

採用された回答

Star Strider
Star Strider 2019 年 7 月 11 日
When ‘x’ is 0, ‘G’ becomes 0/0, and the IEEE standard defines that as NaN. Any NaN in a vector will propagate through all calculations involving it to result in the entire vector being NaN.
You can get around that by creating a version of L’Hospital’s rule by addint eps to ‘x’:
G=sin(pi*(x+eps)/5)./(pi*(x+eps))
Thar results in the entire vector — and its fft — being defined and not NaN.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by