%% Plot XCF of Two Time Series
% Generate 100 random deviates from a Gaussian distribution with mean 0 and variance 1.

rng(1); % For reproducibility
x = randn(100,1);

%
% Create a 4-period delayed version of x.

y = lagmatrix(x,4);

%
% Compute and plot the XCF.

y(isnan(y)) = 0; % crosscorr does not accept NaNs
[XCF,lags,bounds] = crosscorr(x,y);
bounds

crosscorr(x,y)

% bounds displays the upper and lower confidence bounds, which are the horizontal lines in the XCF plot. As you should expect, XCF peaks at lag 4.
% Copyright 2015 The MathWorks, Inc.