%% Infer Residuals
% Infer residuals from an AR model.
% Specify an AR(2) model using known parameters.

Mdl = arima('AR',{0.5,-0.8},'Constant',0.002,...
	'Variance',0.8);

%
% Simulate response data with 102 observations.

rng 'default';
Y = simulate(Mdl,102);

%
% Use the first two responses as presample data, and infer residuals for the remaining 100 observations.

E = infer(Mdl,Y(3:end),'Y0',Y(1:2));
figure;
plot(E);
title 'Inferred Residuals';

% Copyright 2015 The MathWorks, Inc.