This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Shift zero-frequency component to center of spectrum


Y = fftshift(X)
Y = fftshift(X,dim)


Y = fftshift(X) rearranges the outputs of fft, fft2, and fftn by moving the zero-frequency component to the center of the array. 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 the first quadrant with the third and the second quadrant with the fourth.

For higher-dimensional arrays, fftshift(X) swaps "half-spaces" of X along each dimension.

Y = fftshift(X,dim) applies the fftshift operation along the dimension dim.

    Note:   ifftshift will undo the results of fftshift. If the matrix X contains an odd number of elements, ifftshift(fftshift(X)) must be done to obtain the original X. Simply performing fftshift(X) twice will not produce X.


For any matrix X

Y = fft2(X)

has Y(1,1) = sum(sum(X)); the zero-frequency component of the signal is in the upper-left corner of the two-dimensional FFT. For

Z = fftshift(Y)

this zero-frequency component is near the center of the matrix.

The difference between fftshift and ifftshift is important for input sequences of odd-length.

N = 5;
X = 0:N-1;
Y = fftshift(fftshift(X));
Z = ifftshift(fftshift(X));

Notice that Z is a correct replica of X, but Y is not.


ans =


ans =


See Also

| | | |

Introduced before R2006a

Was this topic helpful?