Documentation Center

  • Trial Software
  • Product Updates

xcov

Cross-covariance

Syntax

c = xcov(x,y)
c = xcov(x)
c = xcov(x,'option')
[c,lags] = xcov(x,y,maxlags)
[c,lags] = xcov(x,maxlags)
[c,lags] = xcov(x,maxlags)
[c,lags] = xcov(x,y,maxlags,'option')
[c,lags] = xcov(gpuArrayX,gpuArrayY,maxlags,'option')

Description

xcov estimates the cross-covariance sequence of random processes. Autocovariance is handled as a special case.

The true cross-covariance sequence is the cross-correlation of mean-removed sequences

where μx and μy are the mean values of the two stationary random processes, denotes the complex conjugate, and E{·} is the expected value operator. xcov estimates the sequence because, in practice, access is available to only a finite segment of the infinite-length random process.

c = xcov(x,y) returns the cross-covariance sequence in a length 2N-1 vector, where x and y are length N vectors. For information on how arrays are processed with xcov, see Multiple Channels.

c = xcov(x) is the autocovariance sequence for the vector x. Where x is an N-by-P array, c = xcov(x) returns an array with 2N-1 rows whose P2 columns contain the cross-covariance sequences for all combinations of the columns of x.

By default, xcov computes raw covariances with no normalization. For a length N vector

The output vector c has elements given by c(m) = cxy(m-N), = 1, ..., 2N-1.

The covariance function requires normalization to estimate the function properly.

c = xcov(x,'option') specifies a scaling option, where 'option' is

  • 'biased', for biased estimates of the cross-covariance function

  • 'unbiased', for unbiased estimates of the cross-covariance function

  • 'coeff', to normalize the sequence so the auto-covariances at zero lag are identically 1.0

  • 'none', to use the raw, unscaled cross-covariances (default)

See [1] for more information on the properties of biased and unbiased correlation and covariance estimates.

[c,lags] = xcov(x,y,maxlags) where x and y are length m vectors, returns the cross-covariance sequence in a length 2*maxlags+1 vector c. lags is a vector of the lag indices where c was estimated, that is, [-maxlags:maxlags].

[c,lags] = xcov(x,maxlags) is the autocovariance sequence over the range of lags [-maxlags:maxlags].

[c,lags] = xcov(x,maxlags) where x is an m-by-p array, returns array c with 2*maxlags+1 rows whose P2 columns contain the cross-covariance sequences for all combinations of the columns of x.

[c,lags] = xcov(x,y,maxlags,'option') specifies a scaling option, where 'option' is the last input argument.

[c,lags] = xcov(gpuArrayX,gpuArrayY,maxlags,'option') returns the autocovariance or cross-covariance sequence for input objects of class gpuArray. See Establish Arrays on a GPU for details on gpuArray objects. Using xcov with gpuArray objects requires Parallel Computing Toolbox™ software and a CUDA-enabled NVIDIA GPU with compute capability 1.3 or above. See http://www.mathworks.com/products/parallel-computing/requirements.html for details. The returned autocovariance or cross-covariance sequence, c, is a gpuArray object.

Autocovariance using the GPU shows you how to compute the autocovariance sequence on the GPU.

In all cases, xcov gives an output such that the zeroth lag of the covariance vector is in the middle of the sequence, at element or row maxlag+1 or at m.

Examples

The second output lags is useful when plotting. For example, the estimated autocovariance of white Gaussian noise cww(m) can be displayed for -10 ≤ m ≤ 10 using:

ww = randn(1000,1);     % White Gaussian noise
[cov_ww,lags] = xcov(ww,10,'coeff');
stem(lags,cov_ww)

Autocovariance using the GPU

The following example requires Parallel Computing Toolbox software and a CUDA-enabled NVIDIA GPU with compute capability 1.3 or above. See http://www.mathworks.com/products/parallel-computing/requirements.html for details.

Create a signal consisting of a 10-Hz sine wave in additive noise. Use gpuArray to create a gpuArray object stored on your computer's GPU.

t = 0:0.001:10-0.001;
x = cos(2*pi*10*t)+randn(size(t));
X = gpuArray(x);

Compute the autocovariance sequence to lag 200.

[xc,lags] = xcov(X,200);

The output, xc, is a gpuArray object. Use gather to transfer the data from the GPU to the MATLAB® workspace as a double-precision vector.

xc = gather(xc);

Diagnostics

xcov does not check for any errors other than the correct number of input arguments. Instead, it relies on the error checking in xcorr.

More About

expand all

Algorithms

xcov computes the mean of its inputs, subtracts the mean, and then calls xcorr. For more information on estimating covariance and correlation functions, see [1].

References

[1] Orfanidis, S. J. Optimum Signal Processing: An Introduction. 2nd Edition. Englewood Cliffs, NJ: Prentice-Hall, 1996.

See Also

| | | |

Was this topic helpful?