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
, andfftn
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?
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.
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.
fft. fftshift. Shift the zero-frequency component to the center of the spectrum.
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.
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With