Skip to content

komm.acorr

Computes the autocorrelation $R[\ell]$ of a real or complex sequence $x[n]$. This is defined as $$ R[\ell] = \sum_{n \in \mathbb{Z}} x[n] x^*_\ell[n], $$ where $x^*_\ell[n] = x^*[n - \ell]$ is the complex conjugate of $x[n]$ shifted by $\ell$ positions. The autocorrelation $R[\ell]$ is even symmetric and satisfies $R[\ell] = 0$ for $|\ell| \geq L$, where $L$ is the length of the sequence.

Parameters:

  • seq (Array1D[float | complex])

    A 1D-array containing the sequence $x[n]$, of length $L$.

  • shifts (Optional[Array1D[int]])

    A 1D-array containing the values of $\ell$ for which the autocorrelation will be computed. The default value is range(len(seq)), that is, $[0 : L)$.

  • normalized (Optional[bool])

    If True, returns the autocorrelation divided by the sequence energy, so that $R[0] = 1$. The default value is False.

Returns:

  • acorr (SameAsInput)

    The autocorrelation $R[\ell]$ of the sequence.

Examples:

>>> komm.acorr([1.0, 2.0, 3.0, 4.0], shifts=[-2, -1, 0, 1, 2])
array([11., 20., 30., 20., 11.])