Skip to main content

autocorrelation

Function autocorrelation 

Source
pub fn autocorrelation(x: &[f32], out: &mut [f32]) -> Result<usize, AudioError>
Expand description

Normalised autocorrelation of x written into out.

out[lag] receives the biased autocorrelation sum_{i=0}^{N-lag-1} x[i]*x[i+lag] divided by the zero-lag energy sum x[i]^2, so out[0] == 1.0. One value is written per element of out; lags >= N (no overlap) are written as 0.0. For a periodic signal of period P the strongest lag > 0 sits at P (and its multiples).

Cost is O(N * out.len()) — bounded by the caller’s chosen lag count; no allocation.

§Errors