%% Plot Autocorrelation Function of Time Series
% Specify the MA(2) model:
% y_t = \varepsilon_t-0.5\varepsilon_{t-1}+0.4\varepsilon_{t-2},
% where \varepsilon_t is Gaussian with mean 0 and variance 1.

rng(1); % For reproducibility
Mdl = arima('MA',{-0.5 0.4},'Constant',0,'Variance',1)

%
% Simulate 1000 observations from Mdl.

y = simulate(Mdl,1000);

%
% Compute the ACF for 20 lags.  Specify that y_t is an MA(2) model, that is, the ACF is effectively 0 after the second lag.

[acf,lags,bounds] = autocorr(y,'NumMA',2);
bounds

% bounds is (-0.0843, 0.0843), which are the upper and lower confidence bounds.
%
% Plot the ACF.

autocorr(y)

% The ACF cuts off after the second lag. This behavior is indicative of an MA(2) process.
% Copyright 2015 The MathWorks, Inc.