%% Cross-Covariance of Two Random Vectors
% Create a vector of random numbers x and a vector y that is equal to x shifted by 3 elements to the right. Compute and plot the estimated cross-covariance of x and y. The largest spike occurs at the lag value when the elements of x and y match exactly (-3).

rng default
x = rand(20,1);
y = circshift(x,3);
[c,lags] = xcov(x,y);
stem(lags,c)

%
% Copyright 2018 The MathWorks, Inc.