Skip to main content

crosscorrelation

Function crosscorrelation 

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

Normalised cross-correlation of a against b, written into out.

out[lag] receives sum_i a[i]*b[i+lag] divided by sqrt(energy(a) * energy(b)), giving a correlation coefficient in [-1, 1]. The peak lag is the shift at which b best aligns with a: if b is a delayed by d samples then out peaks at lag == d with value ~1.0. One value is written per element of out; lags with no overlap are written as 0.0.

Cost is O(min(|a|,|b|) * out.len()); no allocation.

ยงErrors