[SciPy-user] FFT troubles

Rob Managan managan at llnl.gov
Fri Dec 9 12:24:18 CST 2005


I am wondering if anyone can help me figure out where my FFts are 
going bad with the latest svn version of scipy. This has been going 
on for a few weeks.
Mac OSX 10.3.9, python 2.4.1

I have fftw-2.1.5 installed and 'make check' reports no problems.

>>>  from scipy.fftpack import fft,ifft
Importing test to scipy
...
Importing stats to scipy
>>>  from scipy.base import arange, sin, cos, pi
>>>  n=16
>>>  x = arange(n)*2*pi/n
>>>  cx = cos(x)
>>>  sx = sin(x)
>>>  print 'sx',sx
sx [  0.00000000e+00   3.82683432e-01   7.07106781e-01   9.23879533e-01
    1.00000000e+00   9.23879533e-01   7.07106781e-01   3.82683432e-01
    1.22464680e-16  -3.82683432e-01  -7.07106781e-01  -9.23879533e-01
   -1.00000000e+00  -9.23879533e-01  -7.07106781e-01  -3.82683432e-01]
>>>  sfx = fft(sx)
>>>  print 'sfx=fft(sx)',sfx
sfx=fft(sx) [  1.77975831e-16 +0.00000000e+00j  -1.35945820e-15 
-8.00000000e+00j
   -3.87815369e-16 -8.43346956e-16j   5.48376387e-17 -5.45964141e-16j
    1.14423775e-17 -4.99600361e-16j   4.98926849e-16 -5.45964141e-16j
    6.32744729e-16 -1.77213142e-16j   3.15834992e-16 +0.00000000e+00j
    2.88998134e-16 +0.00000000e+00j   3.15834992e-16 -0.00000000e+00j
    6.32744729e-16 +1.77213142e-16j   4.98926849e-16 +5.45964141e-16j
    1.14423775e-17 +4.99600361e-16j   5.48376387e-17 +5.45964141e-16j
   -3.87815369e-16 +8.43346956e-16j  -1.35945820e-15 +8.00000000e+00j]
>>>  sfix = ifft(sfx)
>>>  print 'ifft(sfx)',sfix
ifft(sfx) [  0.00000000e+00 +0.00000000e+00j  -3.11858849e-16 -3.26510369e-33j
   -1.13434883e-16 +0.00000000e+00j   5.44139747e-17 -2.17540312e-32j
    0.00000000e+00 -0.00000000e+00j   1.12119479e-16 -2.89787214e-33j
    1.68946034e-16 -0.00000000e+00j   1.17569819e-16 +1.55910553e-32j
    1.22464680e-16 +0.00000000e+00j   1.17569819e-16 -1.55910553e-32j
    1.68946034e-16 +0.00000000e+00j   1.12119479e-16 +2.89787214e-33j
    0.00000000e+00 +0.00000000e+00j   5.44139747e-17 +2.17540312e-32j
   -1.13434883e-16 -0.00000000e+00j  -3.11858849e-16 +3.26510369e-33j]
>>>

Basically ifft(fft(sin(x))) != sin(x), instead it is 0 to round off.
But ifft(fft(cos(x))) == cos(x)

Why does one fail and the other not! The only difference is that 
fft(cos(x)) is a real valued result and fft(sin(x)) is imaginary.
-- 
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
Rob Managan               email managan at llnl.gov
LLNL                      phone: 925-423-0903
P.O. Box 808, L-095       FAX:   925-422-3389
Livermore, CA  94551-0808



More information about the SciPy-user mailing list