Controversy in calculating the Fourier transform of a function numerically and analytically
Afficher commentaires plus anciens
Hey,
I am trying to calculate the inverse fourier transform of a complex function numerically. And I am trying to start with calculating the fourier transform of a simple gaussian to make sure my code is correct for simple case. The issue is for a Gaussian function (F = exp(-t^2 / 2*(c^2))), the analytical result for the fourier transform is F.F = 2^(1/2)*pi^(1/2)*exp(-2*c^2*f.^2*pi^2)*abs(c). And it is a real function. But when I calculate the fourier transform numerically using trapz function, the result has both real and imaginary parts (although the imaginary part is too small) but the abs value of the result give the same result as the analytical fourier transform. But for a Gaussian centered at zero there is not an imaginary part in the fourier transform. I don't know why I get this imaginary part when I use the definition of fourier transform directly to calculate fourier transform numerically. Can anyone help why there is a controvercy? I need to know to make sure for my general function it works correctly.
I have copied my code and the imaginary part of the fourier transform plot here.
t=-2:.001:2;
c= 0.5;
x = exp(-t.^2/(2*c^2));
% analytical result of fourier transform
% f=-5:.01:5;
% fourierfunc = 2^(1/2)*pi^(1/2)*exp(-2*c^2*f.^2*pi^2)*abs(c);
% plot(f,fourierfunc)
% numerical result of fourier transform
k=0;
for f=-5:.001:5
k=k+1;
fourierx(k)=trapz(t,x.*exp(-1i*2*pi*f*t));
end
f=-5:.001:5;
plot(f,real(fourierx))

Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Numerical Integration and Differentiation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!