1

I'm having a really frustrating problem using numpy's inverse fast fourier transform function. I know the fft function works well based on my other results. Error seems to be introduced after calling ifft. The following should be printing zeros for example:

temp = Eta[50:55] 
print(temp) 
print(temp-np.fft.fft(np.fft.ifft(temp)))

Output:

[ -4.70429130e+13 -3.15161484e+12j -2.45515846e+13 +5.43230842e+12j -2.96326088e+13 -4.55029496e+12j 2.99158889e+13 -3.00718375e+13j -3.87978563e+13 +9.98287428e+12j]

[ 0.00781250+0.00390625j -0.02734375+0.01757812j 0.05078125-0.02441406j 0.01171875-0.01171875j -0.01562500+0.015625j ]

Please help!

Leb
  • 15,483
  • 10
  • 56
  • 75
  • Seems to be due to numerical errors. If you make your input smaller by some orders of magnitudes you come much closer to 0. – cel Oct 04 '15 at 04:10

1 Answers1

1

You are seeing normal floating point imprecision. Here's what I get with your data:

In [58]: temp = np.array([ -4.70429130e+13 -3.15161484e+12j, -2.45515846e+13 +5.43230842e+12j, -2.96326088e+13 -4.55029496e+12j, 2.99158889e+13 -3.00718375e+13j, -3.87978563e+13 +9.98287428e+12j])

In [59]: delta = temp - np.fft.fft(np.fft.ifft(temp))

In [60]: delta
Out[60]: 
array([ 0.0000000+0.00390625j, -0.0312500+0.01953125j,
        0.0390625-0.02539062j,  0.0078125-0.015625j  , -0.0156250+0.015625j  ])

Relative to the input, those values are, in fact, "small", and reasonable for 64 bit floating point calculations:

In [61]: np.abs(delta)/np.abs(temp)
Out[61]: 
array([  8.28501685e-17,   1.46553699e-15,   1.55401584e-15,
         4.11837758e-16,   5.51577805e-16])
Warren Weckesser
  • 110,654
  • 19
  • 194
  • 214