Cross-correlation is useful for determining the lag at which the maximum correlation between two processes lies.
Formally, it is
\[\rho\left(\ell\right) = \frac{E\left[U_{0}V_{\ell}\right] - E\left[U_{0}\right]E\left[V_{0}\right]}{\operatorname{std}\left(U_{0}\right) \operatorname{std}\left(V_{0}\right)}\]
where \(U_{k}\) and \(V_{k}\) are binary time series and \(k,\ell\in\mathbb{Z}\) [1]. This module provides functions to compute \(\rho\left(\ell\right)\) in an efficient manner by using the identity
\[\operatorname{xcorr}\left(\mathbf{x}, \mathbf{y}\right) = \operatorname{ifft}\left(\operatorname{fft}\left(\mathbf{x}\right) \cdot\operatorname{fft}\left(\mathbf{y}\right)^{*}\right)\]
where \(\operatorname{ifft}\left(\mathbf{x}\right)\) is the inverse Fourier transform of a vector, \(\operatorname{fft}\left(\mathbf{x}\right)\) is the Fourier transform of a vector, \(\mathbf{x}\) and \(\mathbf{y}\) are vectors, and \(*\) is the complex conjugate.
[1] | Amarasingham et. al (2012), in press |
See any signal processing text for a presentation of cross-correlation in a more general setting.