[SciPy-user] FFT troubles

Gary pajer at iname.com
Fri Dec 9 13:33:04 CST 2005


Rob Managan wrote:

>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.
>  
>
WinXP, python 2.3, binary installed scipy_core and scipy:
I keep looking for  a mistake in your code, but I don't see one.
(Looks like you found a bug??)

In [87]: n=16

In [88]: x=arange(n)*2*pi/n

In [89]: sx=sin(x)

In [90]: sfx = fft(sx)

In [91]: ifft(sfx)
Out[91]:
array([  0.00000000e+00 +0.00000000e+00j,
         3.82683432e-01 +0.00000000e+00j,
         7.07106781e-01 -5.55111512e-17j,
         9.23879533e-01 -8.32667268e-17j,
         1.00000000e+00 +0.00000000e+00j,
         9.23879533e-01 -2.77555756e-17j,
         7.07106781e-01 -5.55111512e-17j,
         3.82683432e-01 -5.55111512e-17j,
         1.22460635e-16 +0.00000000e+00j,
        -3.82683432e-01 +0.00000000e+00j,
        -7.07106781e-01 +5.55111512e-17j,
        -9.23879533e-01 +8.32667268e-17j,
        -1.00000000e+00 +0.00000000e+00j,
        -9.23879533e-01 +2.77555756e-17j,
        -7.07106781e-01 +5.55111512e-17j,  -3.82683432e-01 
+5.55111512e-17j])

>  
>
>>>> 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.
>  
>




More information about the SciPy-user mailing list