| acf_fft | R Documentation |
Analogous to acf, but based on the Fast Fourier
Transform (Wiener-Khinchin theorem) and 5-10 times faster, especially for
long input vectors.
acf_fft(x, center = TRUE, padToMult = 2)
x |
numeric vector |
center |
if TRUE (default), x is centered before padding with 0 |
padToMult |
pad with 0 to the smallest power of 2 above
|
Numeric vector that is usually longer than input because it is padded with zeros to the next power of two. Constant and zero inputs return NA.
len = 200
x = sin(2 * pi * 100 * (1:len) / 1000) + rnorm(len, 0, .5)
plot(x, type = 'l')
aut = acf(x, lag.max = len/2)
aut2 = acf_fft(x)
points(0:100, aut2[1:(len/2+1)], type = 'l', col = 'blue')
aut$acf[1:10]
aut2[1:10]
# compare execution time
system.time(for (i in 1:100) acf(x, lag.max = len/2, plot = FALSE))
system.time(for (i in 1:100) acf_fft(x))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.