Cross covariance, computed over a range of lags.


Rxy = xcov(x)

Rxy = xcov(x,y)

Rxy = xcov(...,maxlag)

Rxy = xcov(...,maxlag,scale)

[Rxy,lags] = xcov(...)


As a vector, x is the first or only signal.
As a matrix, x is a set of signals stored as column vectors.
Type: double
Dimension: vector | matrix
The second signal, for cross-covariance.
Type: double
Dimension: vector
The maximum covariance lag. Use [] or omit to default to N-1, where N is the number of rows in a matrix x, or the greater length of vectors x and y. Each vector of covariances has length 2*maxlag+1.
Type: integer
Dimension: scalar
The normalization type.
Type: string
The available options are as follows:
The unscaled covariance (default).
This is the only option for the corr(x,y,...) case if x and y have different lengths.
The biased average, dividing each covariance value by N.
The unbiased average, dividing each covariance value by the number products in its summation.
Normalizes covariances by RMS values.


The cross covariances.
Type: vector | matrix
The lag for each correlation.
Type: vector


Vector example:

x = [2,3,4,5,6];
y = [4,6,7,8];
Rxy = xcov(x,y)
Rxy = [Matrix] 1 x 8
0.00000  16.00000  38.00000  65.00000  94.00000  119.00000  88.00000  56.00000  24.00000
Matrix example:
z = [1,2;3,4;5,6;7,8];
Rxy = xcov(z)
Rxy = [Matrix] 7 x 4
 7.00000    8.00000   14.00000   16.00000
26.00000   30.00000   38.00000   44.00000
53.00000   62.00000   68.00000   80.00000
84.00000  100.00000  100.00000  120.00000
53.00000   68.00000   62.00000   80.00000
26.00000   38.00000   30.00000   44.00000
 7.00000   14.00000    8.00000   16.00000


When x is a vector and y is omitted, the auto-covariance of x is computed.

When x is a matrix with N columns, y must be omitted and Rxy is a matrix with N^2 columns. The covariance of columns i and j of x is stored in column (i-1)*N + j of Rxy.

For the cross-covariance, corr(x,y,...), if the lengths of the vectors are unequal, the shorter vector will be padded, producing additional zeros in the output.