6

I am trying to understand how the fft and ifft functions work in python. I made a simple example of an imaginary odd function to compute the inverse Fourier transform in the hopes of getting a real odd function (as should be the case). Below is my code:

v = np.array([-1,-2,0,2,1]) * 1j
t = [-2,-1,0,1,2]
V = ifft(fftshift(v))

Clearly, the function sampled by v is an odd imaginary function, so when I compute the inverse Fourier Transform and after shifting, I should get a real odd function. But this is not the case. What am I misunderstanding about the Fourier Transform? Thanks!

busybear
  • 10,194
  • 1
  • 25
  • 42
Solarflare0
  • 269
  • 2
  • 5

1 Answers1

4

You need ifftshift where you use fftshift and fftshift at the very end:

>>> w = fftshift(ifft(ifftshift(v)))
>>> 
>>> np.allclose(w, w.real)
True
>>> np.allclose(w, -w[::-1])
True
Paul Panzer
  • 51,835
  • 3
  • 54
  • 99