Matlab/Octave fftshift utility
Matlab and Octave have a simple utility called fftshift that performs this bin rotation. Consider the following example:
octave:4> fftshift([1 2 3 4]) ans = 3 4 1 2 octave:5>If the vector [1 2 3 4] is the output of a length 4 FFT, then the first element (1) is the dc term, and the third element (3) is the point at half the sampling rate (






Another reasonable result would be fftshift([1 2 3 4]) == [4 1
2 3], which defines half the sampling rate as a positive frequency.
However, giving
to the negative frequencies balances giving dc
to the positive frequencies, and the number of samples on both sides
is then the same. For an odd-length DFT, there is no point at
, so the result
octave:4> fftshift([1 2 3]) ans = 3 1 2 octave:5>is the only reasonable answer, corresponding to frequencies

Next Section:
Index Ranges for Zero-Phase Zero-Padding
Previous Section:
Zero-Padding for Interpolating Spectral Peaks