fft() and mvfft() in R (2019-10-31)

In R stats::fft() is a function to perform the discrete Fourier transform (DFT) for a given array by a fast Fourier transform (FFT). It can also do the (unnormalized) inverse if given inverse = TRUE. In fact,

x <- runif(100)
all.equal(as.complex(x), fft(fft(x), inverse = TRUE)/length(x))

returns TRUE.

There is another useful variant called stats::mvfft(). This function accepts a matrix and just applies fft() to each column of it (but in a more efficient way). In other words,

y <- matrix(runif(1000), nrow = 100)
all(mvfft(y) == apply(y, 2, fft))

returns TRUE.

© 2006-2020