xcorr
The cross-correlation function.
| Library |
|
Syntax
Function call
-
r = xcorr(x,y)— returns cross-correlation of two discrete sequences. The cross-correlation function measures the similarity between a vectorxand shifted (delayed) copies of the vectoryas a function of the delay. Ifxandythey 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.
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 |
|
| Support for complex numbers |
Yes |
# y — input array
+
vector
Details
The input array specified as a vector.
| Data types |
|
| Support for complex numbers |
Yes |
# maxlag — maximum lag
+
an integer scalar
# 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 ifxandythey 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 to1:
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.