%% Plot an Impulse Response Function
% Specify the following regression model with ARMA(2,1) errors:
% \begin{array}{*{20}{l}}
% \begin{array}{c}
% {y_t} = {X_t}\left[ {\begin{array}{*{20}{c}}
% {0.1}\\
% { - 0.2}
% \end{array}} \right] + {u_t}\\
% {u_t} = 0.5{u_{t - 1}} - 0.8{u_{t - 2}} + {\varepsilon _t} - 0.5{\varepsilon _{t - 1}},
% \end{array}
% \end{array}
% where \varepsilon_{t} is Gaussian with variance 0.1.

Mdl = regARIMA('Intercept',0, 'AR', {0.5 -0.8}, ...
    'MA',-0.5,'Beta',[0.1 -0.2], 'Variance',0.1);

%
% Time the calculation of and plot the impulse response function without specifying the number of observations.

tic
impulse(Mdl)
toc

% The model is stationary; the impulse response function decays in a sinusoidal pattern.
%
% Time the calculation of and plot the impulse response function using 45 observations.

tic
impulse(Mdl,45)
toc

% There are more observations represented in this plot than the one generated in the previous step. However, the impulse response function and the plot took less time to generate in this step than the previous. This is because the software did not calculate the impulse response function using an infinite-degree moving average as in the previous step.
% Copyright 2015 The MathWorks, Inc.