fftshift: Shift Zero Frequency to Center

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/fftshift.r

Description

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

Usage

1

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
## 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)

imagefx documentation built on Feb. 14, 2020, 1:07 a.m.