Personal tools

Difference between revisions of "Lagged correlation"

From MohidWiki

Jump to: navigation, search
m (1 revision)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
[[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]] or [[cross-correlation]] are similar operands that can be applied to any square-integrable real functions <math>f</math> and <math>g</math>.
  
 
==Convolution==
 
==Convolution==
  
: <mathtex> \left( f \, * \, g \right)(\tau) \equiv \int_{-\infty}^{\infty} f(t) \, g(\tau-t) \,dt  </mathtex>.
+
: <math> \left( f \, * \, g \right)(\tau) \equiv \int_{-\infty}^{\infty} f(t) \, g(\tau-t) \,dt  </math>.
  
 
==Cross-correlation==
 
==Cross-correlation==
  
: <mathtex> \left( f \, \star \, g \right)(\tau) \equiv \int_{-\infty}^{\infty} f^{*}(t) \, g(\tau+t) \,dt \equiv C_{fg}(\tau)</mathtex>.
+
: <math> \left( f \, \star \, g \right)(\tau) \equiv \int_{-\infty}^{\infty} f^{*}(t) \, g(\tau+t) \,dt \equiv C_{fg}(\tau)</math>.
  
: In particular <mathtex> f \, \star \, f </mathtex> is designated the [http://mathworld.wolfram.com/Autocorrelation.html autocorrelation].
+
: In particular <math> f \, \star \, f </math> is designated the [http://mathworld.wolfram.com/Autocorrelation.html autocorrelation].
  
 
===Normalized===
 
===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>.
+
: <math>\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></math>, where <math> F \equiv f - \overline{f} </math>. The idea is to remove the average and, optionally, other linear or physical trends from <math> f </math>.
  
 
: In particular we have  
 
: In particular we have  
  
: <mathtex>\widehat{C}_{fg}(0) = \left< \frac{F}{\|F\|} ,\, \frac{G}{\|G\|} \right></mathtex>.
+
: <math>\widehat{C}_{fg}(0) = \left< \frac{F}{\|F\|} ,\, \frac{G}{\|G\|} \right></math>.
  
: <mathtex>\widehat{C}_{ff}(0) = 1 </mathtex>.
+
: <math>\widehat{C}_{ff}(0) = 1 </math>.
  
 
===Discretized===
 
===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>.
+
: <math>\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} </math>, where <math>\sigma_f</math> is the variance of <math>f</math>.
  
: In particular <mathtex> \widehat{C}_{fg}(0) </mathtex> is the famous [http://en.wikipedia.org/wiki/Correlation correlation] coefficient.
+
: In particular <math> \widehat{C}_{fg}(0) </math> is the famous [http://en.wikipedia.org/wiki/Correlation correlation] coefficient.
  
 
==Example==
 
==Example==
  
When both <mathtex>f</mathtex> and <mathtex>g</mathtex> are [http://en.wikipedia.org/wiki/Even_and_odd_functions 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 [http://en.wikipedia.org/wiki/Even_and_odd_functions 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.
+
When both <math>f</math> and <math>g</math> are [http://en.wikipedia.org/wiki/Even_and_odd_functions 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 [http://en.wikipedia.org/wiki/Even_and_odd_functions even] functions. <math>f</math> is represented by the red line, <math>g</math> is represented by the blue line, the product <math>f(t) \, g(\tau - t)</math> is represented by the solid blue line. The solid blue area is the convolution product for lag-time <math>\tau</math> and the whole convolution product function (for all <math>\tau</math>) is represented by the green line.
  
 
http://mathworld.wolfram.com/images/gifs/convrect.gif http://mathworld.wolfram.com/images/gifs/convgaus.gif
 
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>.
+
The big conclusions we can make is that if <math>f</math> and <math>g</math> are the same functions, but with a lag of <math>\epsilon</math> between them, then the [[cross-correlation]] product is maximum when <math>\tau = \epsilon</math>.
  
 
==Matlab functions==
 
==Matlab functions==
Line 47: Line 47:
  
 
===cpsd===
 
===cpsd===
Calculates the cross power spectral density (PSD) function of signals <mathtex> x(t)</mathtex> and <mathtex> y(t)</mathtex>.
+
Calculates the cross power spectral density (PSD) function of signals <math> x(t)</math> and <math> y(t)</math>.
  
 
===periodogram or pwelch===
 
===periodogram or pwelch===
Calculates the power spectral density (PSD) function of signal <mathtex> x(t)</mathtex>. The [[#periodogram|periodogram]] may use several window functions as option. The [[#pwelch|pwelch]] will use the welch window.
+
Calculates the power spectral density (PSD) function of signal <math> x(t)</math>. The [[#periodogram|periodogram]] may use several window functions as option. The [[#pwelch|pwelch]] will use the welch window.
  
 
===mscoherence===
 
===mscoherence===

Latest revision as of 10:26, 8 March 2012

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

Convolution

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

Cross-correlation

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

Normalized

Failed to parse (unknown error): \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> , where  F \equiv f - \overline{f} . The idea is to remove the average and, optionally, other linear or physical trends from  f .
In particular we have
Failed to parse (unknown error): \widehat{C}_{fg}(0) = \left< \frac{F}{\|F\|} ,\, \frac{G}{\|G\|} \right> .
\widehat{C}_{ff}(0) = 1 .

Discretized

\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} , where \sigma_f is the variance of f.
In particular  \widehat{C}_{fg}(0) is the famous correlation coefficient.

Example

When both f and g 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. f is represented by the red line, g is represented by the blue line, the product f(t) \, g(\tau - t) is represented by the solid blue line. The solid blue area is the convolution product for lag-time \tau and the whole convolution product function (for all \tau) 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 f and g are the same functions, but with a lag of \epsilon between them, then the cross-correlation product is maximum when \tau = \epsilon.

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  x(t) and  y(t).

periodogram or pwelch

Calculates the power spectral density (PSD) function of signal  x(t). 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