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

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

%
% Simulate 1000 observations from Mdl.

y = simulate(Mdl,1000);

%
% Compute the PACF.

[partialACF,lags,bounds] = parcorr(y,'NumAR',2);
bounds

% bounds displays (-0.0633, 0.0633), which are the upper and lower confidence bounds.
%
% Plot the PACF.

parcorr(y)

% The PACF cuts off after the second lag. This behavior indicates an AR(2) process.
% Copyright 2015 The MathWorks, Inc.