`(y)=fftshift(x)`

Inputs | |

`x` |
A two-dimensional array or a vector, typically the output of `fft` of `fft2` . |

Outputs | |

`y` |
An array of the same size as the input. The output contains the same elements but in a different order as described below. |

For a one-dimensional array, the element

`x[k+1]`

of
the output `x`

of `fft`

is the transform of the
input at the frequencey `exp(2*pi*i*k/N), k=0,1,...N-1`

where `N`

is the
size of `x`

. Likewise, the element `z[j+1,k+1]`

of the output `z`

of `fft2`

is the transform of the input at the frequencies
`exp(2*pi*i*j/M), exp(2*pi*i*k/N)`

with `j=0,1,...M-1`

, and `k=0,1,...N-1`

.
Here `M`

and `N`

are the row and column dimensions of `y`

.
`fftshift`

rearranges the outputs of `fft`

and `fft2`

so that the zero frequency is at the center
of the spectrum.
If the input is a vector, `fftshift`

swaps the upper
and lower half of the vector.
If the input is a matrix, the first and third quadrants
as well as the second and fourth quadrants are swapped.
>>y=rand(1024,1);>>z=fft(y)>>subplot(2,1,1)>>plot(abs(z))>>title("FFT")>>w=fftshift(z)>>subplot(2,1,2)>>plot(abs(w))>>title("FFTHIFT")