fft function seemingly not evaluating correctly

I have a function defined as an inverse fourier transform of a complicated weighting function. Normally I'd go to integral or trapz for such a task but I remembered that fourier transforms can famously be computed fast, so why not give that a shot. Since I've never used fft before, I thought to check how the results were scaled: there's always the confusion over the factor of \sqrt{2\pi}. So I ran a test on a standard normal and got this:
What am I not understanding here? Those should be the same line, right?

 採用された回答

Sebastian
Sebastian 2025 年 7 月 22 日

0 投票

That took a lot longer for me to understand that I expected. Technically all the info I neede was in the Matlab documentation, but I really don't think it was clear what the function is actually doing.
If on the off-chance that someone else runs into this page from a complete misunderstanding of FFTs, this Desmos graph I made should help.

その他の回答 (2 件)

Torsten
Torsten 2025 年 7 月 18 日
編集済み: Torsten 2025 年 7 月 18 日

0 投票

syms x
f = 1/(2*sym(pi))*exp(-0.5*x^2);
fourier(f)
ans = 
The Gaussian Pulse example under
might help to understand the difference to fft.
Matt J
Matt J 2025 年 7 月 18 日
編集済み: Matt J 2025 年 7 月 19 日

0 投票

Pretty close. There are several issues with how you set up your axes, both in the original domain and the Fourier domain. For one thing, you need to sample on a wider time interval than [-5,5] to get good frequency-domain sampling. Also, you need to scale G by dt/sqrt(s*pi).
N=2^14;
T=100; %time sample on [-100,100]
AX=-ceil((N-1)/2):+floor((N-1)/2); %normalized axis
%Non-Fourier (time) domain
x=-AX*T/AX(1);
dt=(x(2)-x(1)); %time sampling interval
g = 1/(2*pi)*exp(-0.5*x.^2);
%Fourier domain
X=AX*pi/T; %frequency axis points (radians/sec)
G=fftshift(abs(fft(g)))*dt/sqrt(2*pi);
%Compare
skip=round(N/2^10);
h=plot(x(1:skip:end),g(1:skip:end),'ro', X,G,'-b');
xlim([-5,5]);
legend g G

カテゴリ

ヘルプ センター および File ExchangeFourier Analysis and Filtering についてさらに検索

製品

リリース

R2024b

質問済み:

2025 年 7 月 18 日

回答済み:

2025 年 7 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by