fftshift {imagefx}R Documentation

Shift Zero Frequency to Center

Description

Rearranges matrix such that the first quadrant is swapped with the third and the second quadrant is swapped with the fourth.

Usage

fftshift(x)

Arguments

x

matrix whose quadrants should be shifted.

Details

This function is generally used after applying an fft to force the zero-frequency to the middle of the matrix.

Note that if the matrix x has even dimensions, the zero frequency will be 1 unit from the center.

Value

Shifted matrix with same dimensions as x

Author(s)

Alex J.C. Witsil

See Also

fft

Examples


## build the four components of a matrix with four values (i.e. 1:4)
x1 <- matrix(1,nrow=1,ncol=1)
x2 <- x1+1
x3 <- x2+1
x4 <- x3+1

## combine all components together
x <- rbind(cbind(x1,x2),cbind(x3,x4))

## shift the matrix
x.shift <- fftshift(x)

## note the difference of the shifted and original
print(x)
print(x.shift)

################
### PLOTTING ###
################
## note the difference of the shifted and original graphically

close.screen(all.screens=TRUE)
split.screen(c(1,2))
screen(1)
image(x,main='Original',col=rainbow(4))
screen(2)
image(x.shift,main='FFT Shifted', col=rainbow(4))

## close screens
close.screen(all.screens=TRUE)


[Package imagefx version 0.4.1 Index]