%% Plot IRF of Known AR(2) Model
% Create the AR(2) model
% {y_t} = 0.5{y_{t - 1}} - 0.7{y_{t - 2}} + {\varepsilon _t},
% where \varepsilon_t is a standard Gaussian process.

Mdl = arima('AR',{0.5,-0.7},'Constant',0)

% Plot the IRF of y_t.

impulse(Mdl)

% The IRF has length 26; it begins at period 0, during which impulse applies a unit shock to the innovation, and ends at period 25. impulse computes the IRF by inverting the underlying AR lag operator polynomial. The length of the IRF is 26 because the dynamic multipliers beyond period 25 are below the division algorithm tolerances.
% The model is stationary; the impulse response function decays with a sinusoidal pattern.
%
% You can change characteristics of the plot by adjusting the properties of the underlying stem plot. The axes handle object stores the stem plot handle in the Children property.
% Increase the line thickness (the default is 0.5). Also, change the color of the stem plot to red by using the RGB color value.

h = gca; % Current axes handle
stemh = h.Children;
stemh.LineWidth = 5;
stemh.Color = [1 0 0];

% Copyright 2020 The MathWorks, Inc.