Navigation

Operators and Keywords

Function List:

C++ API

Function File: [R, lag] = xcorr ( X )
Function File: … = xcorr ( X, Y )
Function File: … = xcorr ( …, maxlag)
Function File: … = xcorr ( …, scale)

Estimates the cross-correlation.

Estimate the cross correlation R_xy(k) of vector arguments X and Y or, if Y is omitted, estimate autocorrelation R_xx(k) of vector X, for a range of lags k specified by argument "maxlag". If X is a matrix, each column of X is correlated with itself and every other column.

The cross-correlation estimate between vectors "x" and "y" (of length N) for lag "k" is given by

 
            N
 R_xy(k) = sum x_{i+k} conj(y_i),
           i=1
 
 

where data not provided (for example x(-1), y(N+1)) is zero. Note the definition of cross-correlation given above. To compute a cross-correlation consistent with the field of statistics, see xcov.

ARGUMENTS

X

[non-empty; real or complex; vector or matrix] data

Y

[real or complex vector] data

If X is a matrix (not a vector), Y must be omitted. Y may be omitted if X is a vector; in this case xcorr estimates the autocorrelation of X.

maxlag

[integer scalar] maximum correlation lag If omitted, the default value is N-1, where N is the greater of the lengths of X and Y or, if X is a matrix, the number of rows in X.

scale

[character string] specifies the type of scaling applied to the correlation vector (or matrix). is one of:

none

return the unscaled correlation, R,

biased

return the biased average, R/N,

unbiased

return the unbiased average, R(k)/(N-|k|),

coeff

return the correlation coefficient, R/(rms(x).rms(y)), where "k" is the lag, and "N" is the length of X. If omitted, the default value is "none". If Y is supplied but does not have the same length as X, scale must be "none".

RETURNED VARIABLES

R

array of correlation estimates

lag

row vector of correlation lags [-maxlag:maxlag]

The array of correlation estimates has one of the following forms: (1) Cross-correlation estimate if X and Y are vectors.

(2) Autocorrelation estimate if is a vector and Y is omitted.

(3) If X is a matrix, R is an matrix containing the cross-correlation estimate of each column with every other column. Lag varies with the first index so that R has 2*maxlag+1 rows and P^2 columns where P is the number of columns in X.

If Rij(k) is the correlation between columns i and j of X

R(k+maxlag+1,P*(i-1)+j) == Rij(k)

for lag k in [-maxlag:maxlag], or

R(:,P*(i-1)+j) == xcorr(X(:,i),X(:,j)).

reshape(R(k,:),P,P) is the cross-correlation matrix for X(k,:).

See also: xcov.

Package: signal