acf
Builtin index · Signal processing
result = acf(x, [max_lag=])
Input: x, max_lag · Output: result
What it is
x: a length-N real vector. max_lag (optional number, default min(40, N-1), R's own acf() default): highest lag to compute.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = acf(x, [max_lag=]) | x vectorx: a length-N real vector.max_lag number, optionalmax_lag (optional number, default min(40, N-1), R's own acf() default): highest lag to compute. | max_lag+1 —lag 0 through max_lag | Returns a vector of length max_lag+1 (lag 0 through max_lag), the autocorrelation function. The first lag at which it falls below 1/e is the usual correlation-time estimate. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
fs = 1000
n = 0:1:511
t = n / fs
x = sin(2*pi*20*t) + 0.2*randn(512, seed=4)
r = acf(x, max_lag=50)
below = find_peaks(-abs(r - 1/e))
print("acf[0] = {r[0]}, acf drops below 1/e near lag {below[0]}")
h_tone = hurst_exponent(x)
h_walk = hurst_exponent(cumsum(randn(512, seed=5)))
print("hurst (periodic+noise) = {h_tone}, hurst (random walk) = {h_walk}")
output
acf[0] = 1, acf drops below 1/e near lag 9 hurst (periodic+noise) = 0.71599, hurst (random walk) = 0.998318
from signal-processing
How it works
acf(x, [max_lag=]) — see the free function's own doc comment. max_lag defaults to min(40, length(x)-1) — R's own acf() default, a reasonable "show the interesting part" cutoff for a series of any real length.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.