[Numpy-discussion] FFT usage / consistency

Felix Richter felix@physik3.uni-rostock...
Fri Jul 25 10:26:15 CDT 2008


Hi all,

I found myself busy today trying to understand what went wrong in my FFT code. 
I wrote a minimal example/testing code to check the FFT output against an 
analytic result and also tried to reverse the transformation to get the 
original function back. Most curiously, the results depend on whether I first 
do the fft and then the ifft or the other way round.

For the test function, I use the Lorentz function 1/(x^2+1). The exact FT is 
exp(-|t|)*sqrt(pi/2), the IFT yields the same.

1) First FFT and then IFFT: The real part of FFT oscillates, the imaginary 
part is not zero, and the magnitudes do not match. All this should not be, 
but the IFFT reproduces the original function just fine.

2) First IFFT and then FFT: The IFFT is perfect, but the FFT does not 
reproduce the original function.

Could someone please have a look and tell me what I am doing wrong? 
The code is attached, it also plots the results nicely. 

Maybe the (corrected) code could be used as an example in the documentation 
(correct use of (i)fftshift and (i)fftfreq is not trivial!) or as an 
additional test case. The existing test cases for numpy only seem to check 
that the fft function can be called, but they do not check consistency of 
results.

I'm using NumPy versions 1.0.4 and 1.1.0 on Linux with fftpack_lite.so (even 
though fftw3 is installed and configured, but I'll probably ask for that 
later...)

Thanks a lot,
	Felix
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_fft.py
Type: application/x-python
Size: 3334 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080725/8671f81a/attachment-0001.bin 


More information about the Numpy-discussion mailing list