1

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?

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
MorganeMaPh
  • 113
  • 1
  • 5
  • why not just `fft(h)`? – Kami Kaze Oct 13 '16 at 11:57
  • it is not so clear how you are doing the Fourier Transform. To implement the Discrete Fourier Transform I should see at least some for loop (if you don't really want to use the fft(.) function)...anyway: can you give us some example? your input array? your impulse-response of the linear system? – Leos313 Oct 13 '16 at 12:55
  • Where is `f` defined in your code? You plot against it, but I don't see a definition of it anywhere. And `fth(k)` is not going to work in MATLAB because k is not an integer here. – reas0n Oct 13 '16 at 14:28

0 Answers0