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

조회 수: 11 (최근 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 CenterFile Exchange에서 Fourier 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