%% Specify Additional Lags for Cross-Correlation Plot
% Specify the AR(1) model for the first series:
% y_{1t} = 2 + 0.3y_{1t-1}+\varepsilon_t,
% where \varepsilon_t is Gaussian with mean 0 and variance 1.

MdlY1 = arima('AR',0.3,'Constant',2,'Variance',1);

%
% Simulate data from Mdl.

rng(1);
T = 1000;
y1 = simulate(MdlY1,T);

%
% Simulate data for the second series by inducing correlation at lag 36.

y2 = [randn(36,1);y1(1:end-36)+randn(T-36,1)*0.1];

%
% Plot the XCF using the default settings.

figure
crosscorr(y1,y2,'NumSTD',3)

% The plot does not indicate significant cross-correlation between the two series.
%
% Plot the XCF for 60 lags on either side of lag 0.

figure
crosscorr(y1,y2,'NumLags',60,'NumSTD',3)

% The plot shows significant correlation at lag 36, as expected.
% Copyright 2015 The MathWorks, Inc.