0

I have another question. Quite similar to the other that i already asked (and got great help - thanks again). Unfortunately the solution from the other thread does not work here: (http://stackoverflow.com/questions/8680909/fft-in-matlab-and-numpy-scipy-give-different-results)

now it is about the ifft:

  # i have an array 'aaa' of shape (6,) such as:
  for i in aaa:  print i
  ...

 (1.22474487139+0j)
 (-0.612372435696-1.06066017178j)
 (-0.612372435696+1.06066017178j)
 (1.22474487139+0j)
 (-0.612372435696-1.06066017178j)
 (-0.612372435696+1.06066017178j)

  #when i perform np.ifft the result is:
 np.fft.ifft(aaa)

 array([  1.48029737e-16 +1.48029737e-16j,
    -8.26024733e-17 -1.72464044e-16j,
     1.22474487e+00 -3.94508649e-16j,
     3.70074342e-17 -2.96059473e-16j,
    -2.22044605e-16 +2.46478913e-16j,   4.55950391e-17 +4.68523518e-16j])

  ###################################################################
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  % BUT IN MATLAB 
  % the same array...

  aaa =

  1.2247          
 -0.6124 - 1.0607i
 -0.6124 + 1.0607i
  1.2247          
 -0.6124 - 1.0607i
 -0.6124 + 1.0607i

 % ...gives the result:
 ifft(aaa)

 ans =

  -0.0000
        0
   1.2247
        0
        0
        0

i did experiments with real numbers like range(1,6). then the results are the same. Could it be a problem of precision? But then - why the results differ so significantly? maybe someone has an idea how to solve the problem?

Chris
  • 570
  • 2
  • 9
  • 19
  • possible duplicate of [FFT in Matlab and numpy / scipy give different results](http://stackoverflow.com/questions/8680909/fft-in-matlab-and-numpy-scipy-give-different-results) – Paul R Jan 03 '12 at 18:52
  • Did you notice that the two questions were asked by the same user? ;) – Bi Rico Jan 04 '12 at 03:10
  • this is not a duplicate. as i said in the introduction-the solution from that thread does not apply here. – Chris Jan 04 '12 at 08:07

2 Answers2

6

If you look at your values coming from your numpy evaluation, they are very small (less than 10^-15). I would suggest that this is a problem of precision, and your results are not as different as they appear at first glance.

Nzbuu
  • 5,241
  • 1
  • 29
  • 51
aganders3
  • 5,838
  • 26
  • 30
3

X.XXe-16 is essentially zero when compared to 1.2247. The print statement likely rounds off all the numbers by a much much larger amount.

So your results are not different, for all practical purposes.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153