Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

The cross-correlation sequence for two wide-sense stationary
random process, * x(n)* and

$${R}_{xy}(m)=E\{x(n+m){y}^{*}(n)\},$$

where the asterisk denotes the complex conjugate and the expectation is over the ensemble of realizations that constitute the random processes.

Note that cross-correlation is not commutative, but a Hermitian (conjugate) symmetry property holds such that:

$${R}_{xy}(m)={R}_{yx}^{*}(-m).$$

The cross-covariance between * x(n)* and

$${C}_{xy}(m)=E\{(x(n+m)-{\mu}_{x})\text{\hspace{0.17em}}{(y(n)-{\mu}_{y})}^{*}\}={R}_{xy}(m)-{\mu}_{x}{\mu}_{y}{}^{*}.$$

For zero-mean wide-sense stationary random processes, the cross-correlation and cross-covariance are equivalent.

In practice, you must estimate these sequences, because it is
possible to access only a finite segment of the infinite-length random
processes. Further, it is often necessary to estimate ensemble moments
based on time averages because only a single realization of the random
processes are available. A common estimate based on * N* samples
of

$${\widehat{R}}_{xy}(m)=\{\begin{array}{ll}{\displaystyle \sum _{n=0}^{N-m-1}x}(n+m){y}^{*}(n),\hfill & m\ge 0,\hfill \\ {\widehat{R}}_{yx}^{*}(-m),\hfill & m<0.\hfill \end{array}$$

where we assume for this discussion that * x(n)* and

The functions `xcorr`

and `xcov`

estimate the cross-correlation and
cross-covariance sequences of random processes. They also handle autocorrelation
and autocovariance as special cases. The `xcorr`

function
evaluates the sum shown above with an efficient FFT-based algorithm,
given inputs * x(n)* and

`x`

and `y`

. Its operation is equivalent to convolution with one of the two subsequences reversed
in time. For example:

x = [1 1 1 1 1]'; y = x; xyc = xcorr(x,y)

Notice that the resulting sequence length is one less than twice
the length of the input sequence. Thus, the *N*th
element is the correlation at lag 0. Also notice
the triangular pulse of the output that results when convolving two
square pulses.

The `xcov`

function estimates autocovariance
and cross-covariance sequences. This function has the same options
and evaluates the same sum as `xcorr`

, but first
removes the means of `x`

and `y`

.

An estimate of a quantity is *biased* if its expected value is
not equal to the quantity it estimates. The expected value of the
output of `xcorr`

is

$$E\{{\widehat{R}}_{xy}(m)\}=(N-\left|m\right|){R}_{xy}(m).$$

`xcorr`

provides the unbiased estimate, dividing
by * N – |m|* when you specify
an

`'unbiased'`

flag after the input sequences.```
xcorr(x,y,'unbiased')
```

Although this estimate is unbiased, the end points (near
–(* N* – 1)
and

`xcorr`

computes
them using only a few data points. A possible trade-off is to simply
divide by `'biased'`

flag:```
xcorr(x,y,'biased')
```

With this scheme, only the sample of the correlation at zero
lag (the * N*th output element) is unbiased. This
estimate is often more desirable than the unbiased one because it
avoids random large variations at the end points of the correlation
sequence.

`xcorr`

provides one other normalization scheme.
The syntax

```
xcorr(x,y,'coeff')
```

divides the output by `norm(x)*norm(y)`

so
that, for autocorrelations, the sample at zero lag is 1.

For a multichannel signal, `xcorr`

and `xcov`

estimate
the autocorrelation and cross-correlation and covariance sequences
for all of the channels at once. If `S`

is an * M*-by-

`xcorr(S)`

returns
a (2`S`

in
its `S`

is
a three-channel signalS = [s1 s2 s3]

then the result of `xcorr(S)`

is organized
as

R = [Rs1s1 Rs1s2 Rs1s3 Rs2s1 Rs2s2 Rs2s3 Rs3s1 Rs3s2 Rs3s3]

Two related functions, `cov`

and `corrcoef`

, are available in the standard MATLAB^{®} environment.
They estimate covariance and normalized covariance respectively between
the different channels at lag 0 and arrange them in a square matrix.

Was this topic helpful?