In a Fortran program I am using the Fourier Transform of a given function the user can choose. But the user already has to write the Fourier transform of the function.
So I wanted to extend the program in a way the user only have to give the original function. In this case a Gauss-function. To do this I Need then to do an FFT.
If we have:
h(x)=exp(-t^2)
then by Hand the Fourier transform is given by
fth(k)=sqrt(pi)*exp(-k.^2/4)
Now if I do fft of h(x) I should get fth(k) right? Here is my code:
Fs=10;
x=-10:1/Fs:10;
L=length(x);
Nk=2^nextpow2(L);
h=exp(-x.^2);
k=Fs*(1:Nk/2)/Nk;
fth(k)=sqrt(pi)*exp(-k.^2/4);
ffth=fft(h,Nk);
ffth=abs(ffth);
figure
plot(f,ffth(1:Nk/2+1),'r');
hold on
plot(f,fth(1:Nk/2+1),'b');
But why do I get something completely different?