Cross-correlation

From testwiki
Revision as of 13:19, 11 January 2025 by 151.37.157.108 (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision β†’ (diff)
Jump to navigation Jump to search

Template:Short description Template:Correlation and covariance

Visual comparison of convolution, cross-correlation and autocorrelation. For the operations involving function Template:Mvar, and assuming the height of Template:Mvar is 1.0, the value of the result at 5 different points is indicated by the shaded area below each point. Also, the vertical symmetry of Template:Mvar is the reason f*g and fg are identical in this example.

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.

In probability and statistics, the term cross-correlations refers to the correlations between the entries of two random vectors 𝐗 and 𝐘, while the correlations of a random vector 𝐗 are the correlations between the entries of 𝐗 itself, those forming the correlation matrix of 𝐗. If each of 𝐗 and 𝐘 is a scalar random variable which is realized repeatedly in a time series, then the correlations of the various temporal instances of 𝐗 are known as autocorrelations of 𝐗, and the cross-correlations of 𝐗 with 𝐘 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 YX is formally given by the cross-correlation (in the signal-processing sense) fg; 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](fg)(τ) f(t)g(t+τ)dtwhich is equivalent to(fg)(τ) f(tτ)g(t)dtwhere f(t) denotes the complex conjugate of f(t), and τ is called displacement or lag.

For highly-correlated f and g which have a maximum cross-correlation at a particular τ, a feature in f at t also occurs later in g at t+τ, hence g could be described to lag f by τ.

If f and g are both continuous periodic functions of period T, the integration from to is replaced by integration over any interval [t0,t0+T] of length T:(fg)(τ) t0t0+Tf(t)g(t+τ)dtwhich is equivalent to(fg)(τ) t0t0+Tf(tτ)g(t)dtSimilarly, for discrete functions, the cross-correlation is defined as:[4][5](fg)[n] m=f[m]g[m+n]which is equivalent to:(fg)[n] m=f[mn]g[m]For finite discrete functions f,gβ„‚N, the (circular) cross-correlation is defined as:[6](fg)[n] m=0N1f[m]g[(m+n)modN]which is equivalent to:(fg)[n] m=0N1f[(mn)modN]g[m]For finite discrete functions fβ„‚N, gβ„‚M, the kernel cross-correlation is defined as:[7](fg)[n] m=0N1f[m]Kg[(m+n)modN]where Kg=[k(g,T0(g)),k(g,T1(g)),,k(g,TN1(g))] is a vector of kernel functions k(,):β„‚M×β„‚Mℝ and Ti():β„‚Mβ„‚M 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 (fg) 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.

Animation of how cross-correlation is calculated. The left graph shows a green function G that is phase-shifted relative to function F by a time displacement of 𝜏. The middle graph shows the function F and the phase-shifted G represented together as a Lissajous curve. Integrating F multiplied by the phase-shifted G produces the right graph, the cross-correlation across all values of 𝜏.

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]Template:Rp

Properties

Template:Unordered list

Cross-correlation of random vectors

Template:Main

Definition

For random vectors 𝐗=(X1,,Xm) and 𝐘=(Y1,,Yn), each containing random elements whose expected value and variance exist, the cross-correlation matrix of 𝐗 and 𝐘 is defined by[9]Template:RpRπ—π˜ E[π—π˜]and has dimensions m×n. Written component-wise:Rπ—π˜=[E[X1Y1]E[X1Y2]E[X1Yn]E[X2Y1]E[X2Y2]E[X2Yn]E[XmY1]E[XmY2]E[XmYn]]The random vectors 𝐗 and 𝐘 need not have the same dimension, and either might be a scalar value. Where E is the expectation value.

Example

For example, if 𝐗=(X1,X2,X3) and 𝐘=(Y1,Y2) are random vectors, then Rπ—π˜ is a 3×2 matrix whose (i,j)-th entry is E[XiYj].

Definition for complex random vectors

If 𝐙=(Z1,,Zm) and 𝐖=(W1,,Wn) are complex random vectors, each containing random variables whose expected value and variance exist, the cross-correlation matrix of 𝐙 and 𝐖 is defined byR𝐙𝐖 E[𝐙𝐖H]where H 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 μX(t) and μY(t) and variances σX2(t) and σY2(t) at time t, for each t. Then the definition of the cross-correlation between times t1 and t2 is[9]Template:RpRXY(t1,t2) E[Xt1Yt2]where 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]Template:RpKXY(t1,t2) E[(Xt1μX(t1))(Yt2μY(t2))]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

RXY(τ) E[XtYt+τ] or equivalently RXY(τ)=E[XtτYt]

Cross-covariance function

KXY(τ) E[(XtμX)(Yt+τμY)] or equivalently KXY(τ)=E[(XtτμX)(YtμY)]where μX and σX are the mean and standard deviation of the process (Xt), which are constant over time due to stationarity; and similarly for (Yt), respectively. 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-samplingTemplate:Which 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ρXX(t1,t2)=KXX(t1,t2)σX(t1)σX(t2)=E[(Xt1μt1)(Xt2μt2)]σX(t1)σX(t2)If the function ρXX 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ρXY(τ)=KXY(τ)σXσY=E[(XtμX)(Yt+τμY)]σXσYThe 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]Template:RpRXY(t1,t2)=RYX(t2,t1)Respectively for jointly WSS processes:RXY(τ)=RYX(τ)

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]Template:Clarify 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τdelay=argmaxtℝ((fg)(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

1nx,y1σfσt(f(x,y)μf)(t(x,y)μt)

where n is the number of pixels in t(x,y) and f(x,y), μf is the average of f and σf 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)μfandT(x,y)=t(x,y)μtthen the above sum is equal toFF,TTwhere , 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:1nx,y1σfσtf(x,y)t(x,y)

Nonlinear systems

Caution must be applied when using cross correlation function which assumes Gaussian variance 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

Template:Div col

Template:Div col end

References

Template:Reflist

Further reading

Template:Statistics

  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. ↑ Template:Cite book
  5. ↑ Template:Cite book
  6. ↑ Template:Cite thesis
  7. ↑ Template:Cite journal
  8. ↑ Template:Cite book
  9. ↑ 9.0 9.1 9.2 Template:Cite book
  10. ↑ Kun Il Park, Fundamentals of Probability and Stochastic Processes with Applications to Communications, Springer, 2018, 978-3-319-68074-3
  11. ↑ Template:Cite conference
  12. ↑ Template:Cite thesis
  13. ↑ Template:Cite book