How to mathematically describe lag measured from cross correlation

72 Views Asked by At

In MATLAB, this is the function used to measure lag using cross-correlation:

[acor,lag] = xcorr(s2,s1);
[~,I] = max(abs(acor));
lagDiff = lag(I)
timeDiff = lagDiff/Fs

where $s1$ and $s2$ are the signals, $acor$ is the cross-correlation coefficent $r$, $I$ is the coordination of $lag$ at which the maximum cross correlation occurs

Can somebody help me to explain $lagDiff$ in mathematical form?

1

There are 1 best solutions below

2
On BEST ANSWER

Let $X = \langle x_1, \cdots x_n\rangle$ be the vector of cross correlations, where the subscript indicates the lag - you may suitable turn this into a time value if you know the time step of your original data. We can define the lag vector much more simply: $L = \langle 1, 2, ..., n \rangle$, and let $L_i$ be the $i^{th}$ component.

Then $I = \underset{i}{\operatorname{argmax}}X$

Your "lagDiff" is just $L_{I}$.

EDIT: Explaining some notation in general

The "argmax" operation is related to finding a maximum. Using our above example,

$M = \underset{i}{\operatorname{max}}X$ means: "search through all of the $x_i$ components of $X$, and find the biggest one". Literally: find the maximum of $X$. $M$ will be the maximum value we've found.

Then $I = \underset{i}{\operatorname{argmax}}X$ means "search through all of the $x_i$ components of $X$, and find the biggest one. We aren't interested in knowing what that is. Instead, we want to know the index at which it occurs." That index is stored in I.