Cross-correlation explained

In signal processing, cross-correlation is a measure of similarity of two series as a function of the displacement of one relative to the other. This is also known as a sliding dot product or sliding inner-product. It is commonly used for searching a long signal for a shorter, known feature. It has applications in pattern recognition, single particle analysis, electron tomography, averaging, cryptanalysis, and neurophysiology. The cross-correlation is similar in nature to the convolution of two functions. In an autocorrelation, which is the cross-correlation of a signal with itself, there will always be a peak at a lag of zero, and its size will be the signal energy.

X

and

Y

, while the correlations of a random vector

X

are the correlations between the entries of

X

itself, those forming the correlation matrix of

X

. If each of

X

and

Y

is a scalar random variable which is realized repeatedly in a time series, then the correlations of the various temporal instances of

X

are known as autocorrelations of

X

, and the cross-correlations of

X

with

Y

across time are temporal cross-correlations. In probability and statistics, the definition of correlation always includes a standardising factor in such a way that correlations have values between −1 and +1.

If

X

and

Y

are two independent random variables with probability density functions

f

and

g

, respectively, then the probability density of the difference

Y-X

is formally given by the cross-correlation (in the signal-processing sense)

f\starg

; however, this terminology is not used in probability and statistics. In contrast, the convolution

f*g

(equivalent to the cross-correlation of

f(t)

and

g(-t)

) gives the probability density function of the sum

X+Y

.

Cross-correlation of deterministic signals

For continuous functions

f

and

g

, the cross-correlation is defined as:[1] [2] [3] (f \star g)(\tau)\ \triangleq \int_^ \overline g(t+\tau)\,dtwhich is equivalent to(f \star g)(\tau)\ \triangleq \int_^ \overline g(t)\,dtwhere

\overline{f(t)}

denotes the complex conjugate of

f(t)

, and

\tau

is called displacement or lag. For highly-correlated

f

and

g

which have a maximum cross-correlation at a particular

\tau

, a feature in

f

at

t

also occurs later in

g

at

t+\tau

, hence

g

could be described to lag

f

by

\tau

.

If

f

and

g

are both continuous periodic functions of period

T

, the integration from

-infty

to

infty

is replaced by integration over any interval

[t0,t0+T]

of length

T

:(f \star g)(\tau)\ \triangleq \int_^ \overline g(t + \tau)\,dtwhich is equivalent to(f \star g)(\tau)\ \triangleq \int_^ \overline g(t)\,dtSimilarly, for discrete functions, the cross-correlation is defined as:[4] [5] (f \star g)[n]\ \triangleq \sum_^ \overline g[m+n]which is equivalent to:(f \star g)[n]\ \triangleq \sum_^ \overline g[m]For finite discrete functions

f,g\inCN

, the (circular) cross-correlation is defined as:[6] (f \star g)[n]\ \triangleq \sum_^ \overline g[(m+n)_{\text{mod}~N}]which is equivalent to:(f \star g)[n]\ \triangleq \sum_^ \overline g[m]For finite discrete functions

f\inCN

,

g\inCM

, the kernel cross-correlation is defined as:[7] (f \star g)[n]\ \triangleq \sum_^ \overline K_g[(m+n)_{\text{mod}~N}]where

Kg=[k(g,T0(g)),k(g,T1(g)),...,k(g,TN-1(g))]

is a vector of kernel functions

k(,)\colonCM x CM\toR

and

Ti()\colonCM\toCM

is an affine transform.

Specifically,

Ti()

can be circular translation transform, rotation transform, or scale transform, etc. The kernel cross-correlation extends cross-correlation from linear space to kernel space. Cross-correlation is equivariant to translation; kernel cross-correlation is equivariant to any affine transforms, including translation, rotation, and scale, etc.

Explanation

As an example, consider two real valued functions

f

and

g

differing only by an unknown shift along the x-axis. One can use the cross-correlation to find how much

g

must be shifted along the x-axis to make it identical to

f

. The formula essentially slides the

g

function along the x-axis, calculating the integral of their product at each position. When the functions match, the value of

(f\starg)

is maximized. This is because when peaks (positive areas) are aligned, they make a large contribution to the integral. Similarly, when troughs (negative areas) align, they also make a positive contribution to the integral because the product of two negative numbers is positive.

With complex-valued functions

f

and

g

, taking the conjugate of

f

ensures that aligned peaks (or aligned troughs) with imaginary components will contribute positively to the integral.

In econometrics, lagged cross-correlation is sometimes referred to as cross-autocorrelation.[8]

Properties

Cross-correlation of random vectors

See main article: Cross-correlation matrix.

Definition

For random vectors

X=(X1,\ldots,Xm)

and

Y=(Y1,\ldots,Yn)

, each containing random elements whose expected value and variance exist, the cross-correlation matrix of

X

and

Y

is defined by[9] \operatorname_ \triangleq\ \operatorname\left[\mathbf{X} \mathbf{Y}\right]and has dimensions

m x n

. Written component-wise:\operatorname_ =\begin\operatorname[X_1 Y_1] & \operatorname[X_1 Y_2] & \cdots & \operatorname[X_1 Y_n] \\ \\\operatorname[X_2 Y_1] & \operatorname[X_2 Y_2] & \cdots & \operatorname[X_2 Y_n] \\ \\ \vdots & \vdots & \ddots & \vdots \\ \\\operatorname[X_m Y_1] & \operatorname[X_m Y_2] & \cdots & \operatorname[X_m Y_n]\endThe random vectors

X

and

Y

need not have the same dimension, and either might be a scalar value.Where

\operatorname{E}

is the expectation value.

Example

For example, if

X=\left(X1,X2,X3\right)

and

Y=\left(Y1,Y2\right)

are random vectors, then

\operatorname{R}XY

is a

3 x 2

matrix whose

(i,j)

-th entry is

\operatorname{E}[XiYj]

.

Definition for complex random vectors

If

Z=(Z1,\ldots,Zm)

and

W=(W1,\ldots,Wn)

are complex random vectors, each containing random variables whose expected value and variance exist, the cross-correlation matrix of

Z

and

W

is defined by\operatorname_ \triangleq\ \operatorname[\mathbf{Z} \mathbf{W}^{\rm H}]where

{}\rm

denotes Hermitian transposition.

Cross-correlation of stochastic processes

In time series analysis and statistics, the cross-correlation of a pair of random process is the correlation between values of the processes at different times, as a function of the two times. Let

(Xt,Yt)

be a pair of random processes, and

t

be any point in time (

t

may be an integer for a discrete-time process or a real number for a continuous-time process). Then

Xt

is the value (or realization) produced by a given run of the process at time

t

.

Cross-correlation function

Suppose that the process has means

\muX(t)

and

\muY(t)

and variances
2(t)
\sigma
X
and
2(t)
\sigma
Y
at time

t

, for each

t

. Then the definition of the cross-correlation between times

t1

and

t2

is[9] \operatorname_(t_1, t_2) \triangleq\ \operatorname\left[X_{t_1} \overline{Y_{t_2}}\right]where

\operatorname{E}

is the expected value operator. Note that this expression may be not defined.

Cross-covariance function

Subtracting the mean before multiplication yields the cross-covariance between times

t1

and

t2

:[9] \operatorname_(t_1, t_2) \triangleq\ \operatorname\left[\left(X_{t_1} - \mu_X(t_1)\right)\overline{(Y_{t_2} - \mu_Y(t_2))}\right]Note that this expression is not well-defined for all time series or processes, because the mean or variance may not exist.

Definition for wide-sense stationary stochastic process

Let

(Xt,Yt)

represent a pair of stochastic processes that are jointly wide-sense stationary. Then the cross-covariance function and the cross-correlation function are given as follows.

Cross-correlation function

\operatorname_(\tau) \triangleq\ \operatorname\left[X_t \overline{Y_{t+\tau}}\right] or equivalently \operatorname_(\tau) = \operatorname\left[X_{t-\tau} \overline{Y_{t}}\right]

Cross-covariance function

\operatorname_(\tau) \triangleq\ \operatorname\left[\left(X_t - \mu_X\right)\overline{\left(Y_{t+\tau} - \mu_Y\right)}\right] or equivalently \operatorname_(\tau) = \operatorname\left[\left(X_{t-\tau} - \mu_X\right)\overline{\left(Y_{t} - \mu_Y\right)}\right]where

\muX

and

\sigmaX

are the mean and standard deviation of the process

(Xt)

, which are constant over time due to stationarity; and similarly for

(Yt)

, respectively.

\operatorname{E}[]

indicates the expected value. That the cross-covariance and cross-correlation are independent of

t

is precisely the additional information (beyond being individually wide-sense stationary) conveyed by the requirement that

(Xt,Yt)

are jointly wide-sense stationary.

The cross-correlation of a pair of jointly wide sense stationary stochastic processes can be estimated by averaging the product of samples measured from one process and samples measured from the other (and its time shifts). The samples included in the average can be an arbitrary subset of all the samples in the signal (e.g., samples within a finite time window or a sub-sampling of one of the signals). For a large number of samples, the average converges to the true cross-correlation.

Normalization

It is common practice in some disciplines (e.g. statistics and time series analysis) to normalize the cross-correlation function to get a time-dependent Pearson correlation coefficient. However, in other disciplines (e.g. engineering) the normalization is usually dropped and the terms "cross-correlation" and "cross-covariance" are used interchangeably.

The definition of the normalized cross-correlation of a stochastic process is \rho_(t_1, t_2) = \frac = \fracIf the function

\rhoXX

is well-defined, its value must lie in the range

[-1,1]

, with 1 indicating perfect correlation and −1 indicating perfect anti-correlation.

For jointly wide-sense stationary stochastic processes, the definition is \rho_(\tau) = \frac = \fracThe normalization is important both because the interpretation of the autocorrelation as a correlation provides a scale-free measure of the strength of statistical dependence, and because the normalization has an effect on the statistical properties of the estimated autocorrelations.

Properties

Symmetry property

For jointly wide-sense stationary stochastic processes, the cross-correlation function has the following symmetry property:[10] \operatorname_(t_1, t_2) = \overlineRespectively for jointly WSS processes:\operatorname_(\tau) = \overline

Time delay analysis

Cross-correlations are useful for determining the time delay between two signals, e.g., for determining time delays for the propagation of acoustic signals across a microphone array.[11] [12] After calculating the cross-correlation between the two signals, the maximum (or minimum if the signals are negatively correlated) of the cross-correlation function indicates the point in time where the signals are best aligned; i.e., the time delay between the two signals is determined by the argument of the maximum, or arg max of the cross-correlation, as in\tau_\mathrm=\underset((f \star g)(t))Terminology in image processing

Zero-normalized cross-correlation (ZNCC)

For image-processing applications in which the brightness of the image and template can vary due to lighting and exposure conditions, the images can be first normalized. This is typically done at every step by subtracting the mean and dividing by the standard deviation. That is, the cross-correlation of a template

t(x,y)

with a subimage

f(x,y)

is

\frac \sum_\frac\left(f(x,y) - \mu_f \right)\left(t(x,y) - \mu_t \right)

where

n

is the number of pixels in

t(x,y)

and

f(x,y)

,

\muf

is the average of

f

and

\sigmaf

is standard deviation of

f

.

In functional analysis terms, this can be thought of as the dot product of two normalized vectors. That is, ifF(x,y) = f(x,y) - \mu_fandT(x,y) = t(x,y) - \mu_tthen the above sum is equal to\left\langle\frac,\frac\right\ranglewhere

\langle,\rangle

is the inner product and

\|\|

is the L² norm. Cauchy–Schwarz then implies that ZNCC has a range of

[-1,1]

.

Thus, if

f

and

t

are real matrices, their normalized cross-correlation equals the cosine of the angle between the unit vectors

F

and

T

, being thus

1

if and only if

F

equals

T

multiplied by a positive scalar.

Normalized correlation is one of the methods used for template matching, a process used for finding instances of a pattern or object within an image. It is also the 2-dimensional version of Pearson product-moment correlation coefficient.

Normalized cross-correlation (NCC)

NCC is similar to ZNCC with the only difference of not subtracting the local mean value of intensities:\frac \sum_\frac f(x,y) t(x,y)

Nonlinear systems

Caution must be applied when using cross correlation for nonlinear systems. In certain circumstances, which depend on the properties of the input, cross correlation between the input and output of a system with nonlinear dynamics can be completely blind to certain nonlinear effects.[13] This problem arises because some quadratic moments can equal zero and this can incorrectly suggest that there is little "correlation" (in the sense of statistical dependence) between two signals, when in fact the two signals are strongly related by nonlinear dynamics.

See also

Further reading

External links

Notes and References

  1. Bracewell, R. "Pentagram Notation for Cross Correlation." The Fourier Transform and Its Applications. New York: McGraw-Hill, pp. 46 and 243, 1965.
  2. Papoulis, A. The Fourier Integral and Its Applications. New York: McGraw-Hill, pp. 244–245 and 252-253, 1962.
  3. Weisstein, Eric W. "Cross-Correlation." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Cross-Correlation.html
  4. Book: Rabiner . L.R. . Schafer . R.W. . Digital Processing of Speech Signals . Prentice Hall . Signal Processing Series . 1978 . Upper Saddle River, NJ . 147–148 . 0132136031 . registration .
  5. Book: Rabiner . Lawrence R. . Gold . Bernard . Theory and Application of Digital Signal Processing . Prentice-Hall . 1975 . Englewood Cliffs, NJ . 401 . 0139141014 . registration .
  6. Wang . Chen . Kernel learning for visual perception, Chapter 2.2.1 . Nanyang Technological University, Singapore . Doctoral thesis . 2019 . 17–18 . 10.32657/10220/47835 . 10356/105527 . free . free .
  7. Wang . Chen . Zhang . Le . Yuan . Junsong . Xie . Lihua . Kernel Cross-Correlator . Proceedings of the AAAI Conference on Artificial Intelligence . Association for the Advancement of Artificial Intelligence . The Thirty-second AAAI Conference On Artificial Intelligence . 2018 . 32 . 4179–4186 . 10.1609/aaai.v32i1.11710 . 3544911 . free .
  8. Book: Campbell . Lo . MacKinlay . 1996 . The Econometrics of Financial Markets . NJ . Princeton University Press . 0691043019 .
  9. Book: Gubner, John A. . 2006 . Probability and Random Processes for Electrical and Computer Engineers . Cambridge University Press . 978-0-521-86470-1.
  10. Kun Il Park, Fundamentals of Probability and Stochastic Processes with Applications to Communications, Springer, 2018, 978-3-319-68074-3
  11. Rhudy. Matthew. Brian Bucci . Jeffrey Vipperman . Jeffrey Allanach . Bruce Abraham . Microphone Array Analysis Methods Using Cross-Correlations. Proceedings of 2009 ASME International Mechanical Engineering Congress, Lake Buena Vista, FL. 281–288. November 2009 . 10.1115/IMECE2009-10798. 978-0-7918-4388-8.
  12. Rhudy. Matthew. Real Time Implementation of a Military Impulse Classifier . MS thesis . University of Pittsburgh . November 2009.
  13. Book: Billings, S. A. . Nonlinear System Identification: NARMAX Methods in the Time, Frequency, and Spatio-Temporal Domains . Wiley . 2013 . 978-1-118-53556-1 .