Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use fftshift(fft(fftshift(x))) and when fft(x)?

Tags:

python

fft

I am trying to implement an algorithm in python, but I am not sure when I should use fftshift(fft(fftshift(x))) and when only fft(x) (from numpy). Is there a rule of thumb based on the shape of input data?
I am using fftshift instead of ifftshift due to the even number of values in the vector x.

like image 467
arc_lupus Avatar asked Nov 21 '15 17:11

arc_lupus


People also ask

When should I use Fftshift?

It is useful for visualizing a Fourier transform with the zero-frequency component in the middle of the spectrum. For vectors, fftshift(X) swaps the left and right halves of X . For matrices, fftshift(X) swaps quadrants one and three of X with quadrants two and four.

What is the difference between FFT and Fftshift in Matlab?

fft computes the discrete Fourier transform and by definition the output is complex. fftshift doesn't compute anything except swaping the position of the samples, so if your input is real, you get real output.

What does NP FFT Fftshift do?

fft. fftshift. Shift the zero-frequency component to the center of the spectrum.


2 Answers

It really just depends on what you want. The DFT (and hence the FFT) is periodic in the frequency domain with period equal to 2pi.

The fft() function will return the approximation of the DFT with omega (radians/s) from 0 to pi (i.e. 0 to fs, where fs is the sampling frequency). All fftshift() does is swap the output vector of the fft() right down the middle. So the output of fftshift(fft()) is now from -pi/2 to pi/2.

Usually, people like to plot a good approximation of the DTFT (or maybe even the CTFT) using the FFT, so they zero-pad the input with a huge amount of zeros (the function fft() does this on it's own) and then they use the fftshift() function to plot between -pi and pi.

In other words, use fftshift(fft()) for plotting, and fft() for the math!

like image 164
Daniel Severo Avatar answered Sep 19 '22 22:09

Daniel Severo


fft(fftshift(x)) rotates the input vector so the the phase of the complex FFT result is relative to the center of the original data window. If the input waveform is not exactly integer periodic in the FFT width, phase relative to the center of the original window of data may make more sense than the phase relative to some averaging between the discontinuous beginning and end. fft(fftshift(x)) also has the property that the imaginary component of a result will always be positive for a positive zero crossing at the center of the window of any antisymmetric waveform component.

fftshift(fft(y)) rotates the FFT results so that the DC bin is in the center of the result, halfway between -Fs/2 and Fs/2, which is a common spectrum display format.

like image 37
hotpaw2 Avatar answered Sep 20 '22 22:09

hotpaw2