4

Please, see the the description of both fftshift and ifftshift. I would like to understand how to call the above two functions in relationship with fft and fftn in Matlab.

Let say that my signal has a certain frequency content; now, the frequency array can generally be stored as:

f = (-N/2:N/2-1)*df;

f = (1:N)*(df/2);

f = [(0:N/2-1) (-N/2:-1)];

What is the best way to call fft, coupled with fftshift and ifftshift, for the 3 study cases early mentioned?

What is the effect on the standard deviation of the signal of calling the sequence of commands or the wrong one?

Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
fpe
  • 2,700
  • 2
  • 23
  • 47
  • This question encouraged me to ask an extensive question about the topic here: http://stackoverflow.com/questions/19901519/shifting-indexes-similar-to-fftshift-in-matlab-for-own-range – Léo Léopold Hertz 준영 Nov 11 '13 at 08:06

2 Answers2

7

The result of fft is (in your notation) indices (0:N-1). fftshift simply converts that to [(N/2:N-1) (0:(N/2-1))].* ifftshift simply restores the original indexing.

As this is simply reordering samples, it does nothing to the standard deviation.


* Note that due to periodicity, sample k is equivalent to sample k+N, or k-N, etc.
Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
1

Matlab documentation is just killing about it. But experiments show that

ifftshift([1 2 3 4 5])

ans =

 3     4     5     1     2

fftshift([1 2 3 4 5])

ans =

 4     5     1     2     3

It is just swapping around the magic DFT position [N/2]. FFT implemented in matlab use usual indexing (0:N-1). As I understand this is extra functions to prepare your input to DFT if your setup is dicrete function not in (0:N-1)...

Konstantin Burlachenko
  • 5,233
  • 2
  • 41
  • 40