Engee documentation

xcorr

The cross-correlation function.

Library

EngeeDSP

Syntax

Function call

  • r = xcorr(x,y) — returns cross-correlation of two discrete sequences. The cross-correlation function measures the similarity between a vector x and shifted (delayed) copies of the vector y as a function of the delay. If x and y they have different lengths. The function adds zeros to the end of the shorter vector so that it has the same length as the other one.

  • r = xcorr(x) — returns the autocorrelation sequence x. If x — the matrix, then r is a matrix whose columns contain autocorrelation and cross-correlation sequences for all combinations of matrix columns x.

  • r = xcorr(___,scaleopt) — also sets the normalization parameter for cross-correlation or autocorrelation, respectively. Any argument value scaleopt, other than 'none' (by default), requires that x and y they had the same length.

Arguments

Input arguments

# x — input array

+ vector | the matrix | multidimensional array

Details

An input array specified as a vector, matrix, or multidimensional array. If x is a multidimensional array, then the function xcorr It works in columns across all dimensions and returns each autocorrelation and cross-correlation as columns of a matrix.

Data types

Float32, Float64

Support for complex numbers

Yes

# y — input array

+ vector

Details

The input array specified as a vector.

Data types

Float32, Float64

Support for complex numbers

Yes

# maxlag — maximum lag

+ an integer scalar

Details

The maximum lag set by an integer scalar. If the argument is maxlag set, the returned cross-correlation sequence ranges from -maxlag before maxlag. If the argument is maxlag not specified, the lag range is , where — the larger of the values x and y.

Data types

Float32, Float64

# scaleopt — normalization parameter

+ 'none' (default) | 'biased' | 'unbiased' | 'normalized' | 'coeff'

Details

A normalization parameter specified using one of the following methods:

  • 'none' — raw, unscaled cross-correlation. 'none' — the only acceptable option is if x and y they have different lengths.

  • 'biased' — biased cross-correlation estimation:

  • 'unbiased' — unbiased cross-correlation estimation:

  • 'normalized' or 'coeff' — normalizes the sequence so that the autocorrelation at zero delay is equal to 1:

Output arguments

# r is a cross— correlation or autocorrelation function

+ vector | the matrix

Details

A cross-correlation or autocorrelation function returned as a vector or matrix.

If x — matrix size Then xcorr(x) returns a matrix of size with autocorrelations and cross-correlations of columns x. If specified maxlag Then r has a size of .

For example, if S it has three columns: , then the result of the operation R = xcorr(S) It will be organized as

Additional Info

Cross-correlation and autocorrelation

The result of the function xcorr It can be interpreted as an estimate of the correlation between two random sequences or as a deterministic correlation between two deterministic signals.

A true cross-correlation sequence of two jointly stationary random processes and defined by the expression

where , the asterisk denotes a complex conjugation, — the mathematical expectation operator. Function xcorr It can only evaluate the sequence, since in practice only a finite segment of a single implementation of a random process of infinite length is available.

The default function is xcorr calculates raw correlations without normalization:

Output vector c it has elements specified by the formula

In general, the correlation function requires normalization to obtain an accurate estimate. You can control the normalization of the correlation using the input argument scaleopt.

Literature

  1. Stoica, Petre, and Randolph Moses. Spectral Analysis of Signals. Upper Saddle River, NJ: Prentice Hall, 2005.