The discrete Fourier transform (DFT) matrix for a given dimension n is calculated.

dftMatrix(n)

Arguments

n

Dimension for the DFT matrix.

Value

The n-by-n DFT matrix.

Details

The DFT matrix can be used for computing the discrete Fourier transform of a matrix or vector. dftMatrix(n) %*% testMatrix is the same as apply(testMatrix, MARGIN = 2, FUN = fft).

Examples

set.seed(987) testMatrix <- matrix(sample(1:10, size = 25, replace = TRUE), nrow = 5) D <- dftMatrix(5) # Discrete Fourier transform with matrix multiplication: D %*% testMatrix
#> [,1] [,2] [,3] [,4] #> [1,] 37.000000+0.000000i 29.0+0.000000i 14+0.0000000i 28.000000+ 0.000000i #> [2,] 0.354102-1.538842i -3.5+5.792096i -1-0.7265425i 1.190983+ 0.416272i #> [3,] -6.354102+0.363271i -3.5-2.991927i -1-3.0776835i 2.309017+12.086220i #> [4,] -6.354102-0.363271i -3.5+2.991927i -1+3.0776835i 2.309017-12.086220i #> [5,] 0.354102+1.538842i -3.5-5.792096i -1+0.7265425i 1.190983- 0.416272i #> [,5] #> [1,] 34.000000+0.000000i #> [2,] 4.854102+7.330938i #> [3,] -1.854102-3.355198i #> [4,] -1.854102+3.355198i #> [5,] 4.854102-7.330938i
# Discrete Fourier transform with function fft: apply(testMatrix, MARGIN = 2, FUN = fft)
#> [,1] [,2] [,3] [,4] #> [1,] 37.000000+0.000000i 29.0+0.000000i 14+0.0000000i 28.000000+ 0.000000i #> [2,] 0.354102-1.538842i -3.5+5.792096i -1-0.7265425i 1.190983+ 0.416272i #> [3,] -6.354102+0.363271i -3.5-2.991927i -1-3.0776835i 2.309017+12.086220i #> [4,] -6.354102-0.363271i -3.5+2.991927i -1+3.0776835i 2.309017-12.086220i #> [5,] 0.354102+1.538842i -3.5-5.792096i -1+0.7265425i 1.190983- 0.416272i #> [,5] #> [1,] 34.000000+0.000000i #> [2,] 4.854102+7.330938i #> [3,] -1.854102-3.355198i #> [4,] -1.854102+3.355198i #> [5,] 4.854102-7.330938i