### 5.25.1 Cross-correlation of two signals : cross_correlation

cross_correlation takes two arguments, a complex vector v of length n and a complex vector w of length m . The returned value is the complex vector z=v⋆w of length N=n+m−1 which is the cross-correlation of the two input vectors, i.e. such that the following holds :

z_{k}= | | | w_{i}^{∗}, k=0,1,…,N−1, |

where

v^{∗}=[v_{0},v_{1},…,v_{n−1}, | | ] and w^{∗}=[ | | ,w_{0},w_{1},…,w_{m−1}]. |

Cross-correlation is typically used for measuring similarity between signals.

For example, input :

cross_correlation([1,2],[3,4,5])

Output :

[6.0,11.0,14.0,5.0]

Input :

v:=[2,1,3,2]:; w:=[1,-1,1,2,2,1,3,2,1]:;
round(cross_correlation(v,w))

Output :

[2,1,0,8,9,12,15,18,13,11,5,2]

Observe that the cross-correlation of v and w is peaking at position 8 with the value 18, indicating that the two signals are best correlated when the last sample in v is aligned with the eighth sample in w. Indeed, there is an occurrence of v in w precisely at that point.