Personal tools

Lagged correlation

From MohidWiki

Revision as of 10:25, 28 August 2008 by 192.168.20.177 (talk) (Matlab functions)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Convolution or cross-correlation are similar operands that can be applied to any square-integrable real functions <mathtex>f</mathtex> and <mathtex>g</mathtex>.

Convolution

<mathtex> \left( f \, * \, g \right)(\tau) \equiv \int_{-\infty}^{\infty} f(t) \, g(\tau-t) \,dt </mathtex>.

Cross-correlation

<mathtex> \left( f \, \star \, g \right)(\tau) \equiv \int_{-\infty}^{\infty} f^{*}(t) \, g(\tau+t) \,dt \equiv C_{fg}(\tau)</mathtex>.
In particular <mathtex> f \, \star \, f </mathtex> is designated the autocorrelation.

Normalized

<mathtex>\widehat{C}_{fg}(\tau) \equiv \frac{\int_{-\infty}^{\infty} F^{*}(t) \, G(\tau+t) \,dt}{\int_{-\infty}^{\infty} F^{*}(t) \, F(t) \,dt \, \int_{-\infty}^{\infty} G^{*}(t) \, G(t) \,dt} = \left< \frac{F(t)}{\|F\|} ,\, \frac{G(\tau+t)}{\|G\|} \right></mathtex>, where <mathtex> F \equiv f - \overline{f} </mathtex>. The idea is to remove the average and, optionally, other linear or physical trends from <mathtex> f </mathtex>.
In particular we have
<mathtex>\widehat{C}_{fg}(0) = \left< \frac{F}{\|F\|} ,\, \frac{G}{\|G\|} \right></mathtex>.
<mathtex>\widehat{C}_{ff}(0) = 1 </mathtex>.

Discretized

<mathtex>\widehat{C}_{fg}(k) \equiv \frac{1}{n-1} \sum_{i} \frac{ \left( f_i - \overline{f} \right)^{*} \left( g_{k+i} - \overline{g} \right) }{\sigma_f \sigma_g} </mathtex>, where <mathtex>\sigma_f</mathtex> is the variance of <mathtex>f</mathtex>.
In particular <mathtex> \widehat{C}_{fg}(0) </mathtex> is the famous correlation coefficient.

Example

When both <mathtex>f</mathtex> and <mathtex>g</mathtex> are even functions then the convolution and cross-correlation products are rigorously equivalent. Below, we show these products when applied to box functions (left figure) and to gaussian functions (right figure). In both cases, they are even functions. <mathtex>f</mathtex> is represented by the red line, <mathtex>g</mathtex> is represented by the blue line, the product <mathtex>f(t) \, g(\tau - t)</mathtex> is represented by the solid blue line. The solid blue area is the convolution product for lag-time <mathtex>\tau</mathtex> and the whole convolution product function (for all <mathtex>\tau</mathtex>) is represented by the green line.

http://mathworld.wolfram.com/images/gifs/convrect.gif http://mathworld.wolfram.com/images/gifs/convgaus.gif

The big conclusions we can make is that if <mathtex>f</mathtex> and <mathtex>g</mathtex> are the same functions, but with a lag of <mathtex>\epsilon</mathtex> between them, then the cross-correlation product is maximum when <mathtex>\tau = \epsilon</mathtex>.

Matlab functions

xcorr

Calculates the cross correlation from two signals.

%Consider arrays t, y1(t), y2(t)
N=length(t);
tlag = linspace(-t(N/2), t(N/2), N+1);
crosscorr = xcorr( y1, y2, N/2, 'coeff');
plot(tlag,crosscorr); xlabel('Phase in time units');ylabel('coefficient');

cpsd

Calculates the cross power spectral density (PSD) function of signals <mathtex> x(t)</mathtex> and <mathtex> y(t)</mathtex>.

periodogram or pwelch

Calculates the power spectral density (PSD) function of signal <mathtex> x(t)</mathtex>. The periodogram may use several window functions as option. The pwelch will use the welch window.

mscoherence

Calculates the coherence-squared spectrum function. If you apply an inverse Fourier transform (IFT), then you get the cross-correlation function in a very efficient way.

See also