Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to call fftshift before calling fft or ifft?

Tags:

matlab

fft

In the book "Computational Fourier Optics, A Matlab Tutorial" by David Voelz, it is written that a call to fftshift is needed before a call to fft or ifft, but in the MATLAB documentation of fftshift it's only written that this command

rearranges the outputs of fft, fft2, and fftn by moving the zero-frequency component to the center of the array.

There is no mention in documentation that this command should be called before the call to fft, and I saw some examples that call fft without a call to fftshift beforehand.

My question is: Whether or not fftshift needed to be called before a call to fft or ifft?

If fftshift doesn't need to be called before a call to fft, and only after a call to fft, then when should we use (if at all) the command ifftshift with relation to a calculation of the fft of a data set?

like image 638
user4861528 Avatar asked Aug 23 '15 12:08

user4861528


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.

What is the use of FFT and IFFT?

FFT (Fast Fourier Transform) is able to convert a signal from the time domain to the frequency domain. IFFT (Inverse FFT) converts a signal from the frequency domain to the time domain.


1 Answers

Given the title of the book you are studying, I assume you are working with images. Then the proper way is to call both fftshift and ifftshift before and after you call [i]fft.

Your code should look like

spectrum = fftshift(fft2(ifftshift(myimage))

It is quite the same when applying the inverse Fourier transform

myimage = fftshift(ifft2(ifftshift(spectrum))
like image 181
Amel Alhassan Avatar answered Sep 21 '22 15:09

Amel Alhassan