Shift zerofrequency 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 zerofrequency component
to the center of the array. It is useful for visualizing a Fourier
transform with the zerofrequency 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 higherdimensional arrays, fftshift(X)
swaps
"halfspaces" of X
along each dimension.
Y = fftshift(X,dim)
applies
the fftshift
operation along the dimension dim
.
Note:

For any matrix X
Y = fft2(X)
has Y(1,1) = sum(sum(X))
; the zerofrequency
component of the signal is in the upperleft corner of the twodimensional
FFT. For
Z = fftshift(Y)
this zerofrequency component is near the center of the matrix.
The difference between fftshift
and ifftshift
is important for input sequences
of oddlength.
N = 5; X = 0:N1; Y = fftshift(fftshift(X)); Z = ifftshift(fftshift(X));
Notice that Z
is a correct replica of X
,
but Y
is not.
isequal(X,Y),isequal(X,Z) ans = 0 ans = 1