Correlation
Cross - Correlation¶
For two continuous functions $a(t)$ and $b(t)$, the correlation is defined with the shift operator $\tau$ as:
$$ a(t) \star b(t) = \int_{-\infty}^{\infty} a(t + \tau) b(\tau) d \tau$$
In the discrete case: $$ a[n] \star b[n] = \sum_{m=-\infty}^{\infty} a[n + m] b[m]$$
Note the similarity to the convolution - only the sign of the shift operator $\tau$ has changed. This flip also means that the cross correlation is not commutative:
$$ a(t) \star b(t) \neq b(t) \star a(t)$$
Cross correlation can give information on the similarity of two signals and is thus frequently used in audio DSP.
Example: Correlation of Random Signals¶
The below example shows the result of a cross correlation between to different random sequences $b(t)$ and $b(t)$. As with convolution, the length of the signal is the lenght of both input signals combined -1. Although the signals are not identical, the cross correlation function has its maximum in the center.
Comparison with Convolution¶
The following example shows how correlation and convolution work differently for two input signals. $a(t)$ is a sine wave and $b(t)$ a cosine wave, both with the same amplitude and frequency.
Correlation:
To inspect the commutative properties, both $a \star b$ and '$b \star a$ ar calculated and plotted. The results of both correlations are not equal:
Convolution:
As for the correlation, both $a * b$ and '$b * a$ ar calculated and plotted. The results of both correlations are identical:
<matplotlib.legend.Legend at 0x7af26851b620>