fftshift before calculating fourier transform: Matlab

Luca

I am looking at some FFT code in a matlab project and the FFT and inverse FFT is computed this way:

% Here image is a 2D image.
image_fft = fftshift(image,1);
image_fft = fftshift(image_fft,2);

image_fft = fft(image_fft,[],1);
image_fft = fft(image_fft,[],2);

image_fft = fftshift(image_fft,1);
image_fft = fftshift(image_fft,2);

% Some processing and then same sequence of fftshift, ifft and fftshift to move to
% time domain

I tried to find some information online but am having trouble wondering why the fftshift needs to be done before computing the FFT.

Another question I have is whether this is something really Matlab specific. For example, I am planning to port this code to C++ and use KISS FFT. Do I need to be vary of this?

AnonSubmitter85

The reason why people like to swap prior to the DFT is because it makes the center pixel of the image the one with zero-phase shift. It often makes algorithms that depend on phase easier to think about and implement. It is not matlab specific and if you want to port an exact version of the code to another language, you'll need to perform the quadswap beforehand too.

EDIT:

Let me give an example that I hope will clear things up. Let's say that our image is the sum of a bunch of sinc functions with varying locations throughout the image. In the frequency domain, each of these sinc functions is a rect function with the same amplitude but with a different linear phase component that determines the location of the sinc in the image domain. By swapping the image prior to taking the DFT, we make the linear phase component of the frequency domain representation of the center pixel be zero. Moreover, the linear phase components of the other sinc functions will now be a function of their distance from the center pixel. If we didn't swap the image beforehand, then the linear phase components of the rect functions would be a function of their distance from the pixel in the top-left of the image. This would be non-intutive and would involve the same kind of phase wrapping considerations that one sees with equating the frequencies in the range (pi,2pi) rad/sample with more the intuitive (-pi,0) rad/sample.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Fourier Transform with Matlab

From Dev

Fourier transform and LTI filter and frequency response in Matlab

From Dev

Fourier transform and FFT for an arbitrary plot using MATLAB

From Dev

Matlab fftshift not working correctly

From Dev

Error in calculating perspective transform for opencv in Matlab

From Dev

Issues Translating Custom Discrete Fourier Transform from MATLAB to Python

From Dev

2D Discrete Fourier Transform implementation in MATLAB

From Dev

why image is rotated when i get Fourier transform of image in matlab

From Dev

2D Discrete Fourier Transform implementation in MATLAB

From Dev

why image is rotated when i get Fourier transform of image in matlab

From Dev

Matlab/Octave 2D Discrete Fourier Transform

From Dev

Calculating Fourier series in SciPy

From Dev

Fourier Transform in Python

From Dev

Fourier transform of multiple rows

From Dev

Fourier Transform and Image Compression

From Dev

Fourier transform for fiber alignment

From Dev

Fast Fourier Transform in Python

From Dev

Fourier transform for fiber alignment

From Dev

Shifting indexes similar to fftshift in Matlab for own range

From Dev

2-Dimensional Fast Fourier Transform 3-D plot in Matlab

From Dev

2-Dimensional Fast Fourier Transform 3-D plot in Matlab

From Dev

MATLAB fourier image filtering

From Dev

Fourier series - Plot in Matlab

From Dev

Fourier Analysis - MATLAB

From Java

Plotting a fast Fourier transform in Python

From Dev

Fourier transform floating point issues

From Dev

Discretized continuous Fourier transform with numpy

From Dev

Maximum value of a direct fourier transform

From Dev

How to compute Discrete Fourier Transform?

Related Related

HotTag

Archive