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

XandYor, ifYis omitted, estimate autocorrelation R_xx(k) of vectorX, for a range of lags k specified by argument "maxlag". IfXis a matrix, each column ofXis 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=1where 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

Xis a matrix (not a vector),Ymust be omitted.Ymay be omitted ifXis a vector; in this case xcorr estimates the autocorrelation ofX.maxlag- [integer scalar] maximum correlation lag If omitted, the default value is N-1, where N is the greater of the lengths of
XandYor, ifXis a matrix, the number of rows inX.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 unbiassed 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". IfYis supplied but does not have the same length asX, 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

XandYare vectors.(2) Autocorrelation estimate if is a vector and

Yis omitted.(3) If

Xis 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 inX.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