# Autocorrelation technique

The autocorrelation technique is a method for estimating the dominating frequency in a complex signal, as well as its variance. Specifically, it calculates the first two moments of the power spectrum, namely the mean and variance. It is also known as the pulse-pair algorithm in radar theory.

The algorithm is both computationally faster and significantly more accurate compared to the Fourier transform, since the resolution is not limited by the number of samples used.

## Derivation

The autocorrelation of lag 1 can be expressed using the inverse Fourier transform of the power spectrum $S(\omega)$:

$R(1) = \frac{1}{2\pi} \int_{-\pi}^{\pi} S(\omega) e^{i\,\omega\,1} d\omega.$

If we model the power spectrum as a single frequency $S(\omega) \ \stackrel{\mathrm{def}}{=}\ \delta(\omega - \omega_0)$, this becomes:

$R(1) = \frac{1}{2\pi} \int_{-\pi}^{\pi} \delta(\omega - \omega_0) e^{i\,\omega} d\omega$
$R(1) = \frac{1}{2\pi} e^{i\,\omega_0}$

where it is apparent that the phase of $R(1)$ equals the signal frequency.

## Implementation

The mean frequency is calculated based on the autocorrelation with lag one, evaluated over a signal consisting of N samples:

$\omega = \angle R_N(1) = \tan^{-1}\frac{im\{ R_N(1) \}}{re\{ R_N(1) \}}.$

The spectral variance is calculated as follows:

$var\{ \omega \} = \frac{2}{N} \left( 1 - \frac{|R_N(1)|}{R_N(0)} \right).$