Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFTshift causes oscillations - why? (numpy)

my original problem was the following:

I have a pulse-envelope in an array a (0-element = time 0, last element = time T). I want to fourier spectrum of the pulse. So what I did was np.fft.fftshift(np.fft.fft(a)). All good.

But then I was told to do a shift beforehand, too: np.fft.fftshift(np.fft.fft(np.fft.fftshift(a))). Then oscillations arised.

Now I wonder why one would do 2 shifts as shown above and why oscillations arise...

Here the example: I have the following code

x = np.arange(100)
a =np.sin(np.pi*x**2/1000)

a: a(x)

a_fft = np.fft.fft(a)

a_fft: enter image description here

 a_fft_shift = np.fft.fftshift(a_fft)

a_fft_shift: enter image description here

    a_shift = np.fft.fftshift(a)
    a_shift_fft = np.fft.fft(a_shift)

a_shift_fft: enter image description here

    a_shift_fft_shift = np.fft.fftshift(a_shift_fft)

a_shift_fft_shift: enter image description here

like image 381
refle Avatar asked Apr 17 '26 14:04

refle


1 Answers

Your line

a_shift = np.fft.fftshift(a)

reorders your original time-domain signal. That means in terms of FFT that you are altering the phases. Note also that there is a discontinuity in your signal. By the line above, this discontinuity is shifted to the center of the signal, which causes the FFT to produce an infinite amount of high frequency cosine components. If you shift it to another place, the energy will be distributed accordingly. The other problem is that you are only considering the real part of the spectrum, i. e., the cosine components. Always look at the imaginary part, too! Take also a look at the magnitude spectrum to see that the position of the discontinuity only affects the phase. The total energy remains always the same.

comparison

like image 178
MaxPowers Avatar answered Apr 19 '26 05:04

MaxPowers