Do I need to call fftshift before calling fft or i

2020-06-03 06:37发布

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 k, 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?

标签: matlab fft
4条回答
来,给爷笑一个
2楼-- · 2020-06-03 07:09

If you read onwards in the documentation on fftshift: "It is useful for visualizing a Fourier transform with the zero-frequency component in the middle of the spectrum."

The shift is not necessary to perform the fft, but it is handy to visualise the Fourier transform. Whether to use fftshift or not is thus dependent upon whether you want to visualise your transform or not.

查看更多
够拽才男人
3楼-- · 2020-06-03 07:12

The matlab fft only computes half of the frequency spectrum (positive frequencies and the null frequency if your number of samples is odd) in order to save computation time.

Then, the second half of the frequency spectrum (which is the complex conjugate of the first half) is just added at the end of this vector.

So what you get after a fft is:

0 1 2 3... (freq bins > 0) ... Fs/2 -Fs/2... (freq bins < 0) ... -3 -2 -1

Fs is the frequency sample.

Now, what fftshift does is just shifting the negative frequency bins (2nd part of the frequency spectrum) at the beginning of your vector so that you can display a nice frequency spectrum starting at -Fs/2 and ending at +Fs/2.

So, to answer your question, no you don't need to use fftshift after of before a call to fft or ifft. But if you used a fftshift on your vector, you should undo it by applying an ifftshift or fftshift (I think both calls are equivalent).

查看更多
forever°为你锁心
4楼-- · 2020-06-03 07:18

The simple answer is call to fftshift not needed before a call to fft. fftshift does not influence the calculation of Fast fourier transform. fftshift rearranges values inside a matrix. For eg:

cameraman = imread('cameraman.tif');
fftshifted_cameraman = fftshift(cameraman);
subplot(1,2,1); imshow(cameraman); title('Cameraman');
subplot(1,2,2); imshow(fftshifted_cameraman); title('FFTShifted Cameraman');
查看更多
甜甜的少女心
5楼-- · 2020-06-03 07:24

Note that ifftshift is different than fftshift because it shifts the negative back to the positive. Assume a simple 3 bin unit impulse in frequency domain before fftshift

[0, exp(-jw1), exp(-(jw1-pi)=exp(-jw1+pi)];

fftshift gives

[exp(-jw1+pi)], 0, exp(-jw1)];

you can see the discontinuity in phase. If you perform ifftshift, negative freq is shifted back to positive:

[0, exp(-jw1), exp(-jw1+pi)];

whereas, fftshift again gives:

[exp(-jw1), exp(-jw1+pi), 0];

one can see the phase monotonicity is not the same, (aka, fftshift-ifftshift case gives [decrease, increase] and fftshift-fftshift case gives [increase, decrease] in phase).

查看更多
登录 后发表回答