www.gusucode.com > econ 案例源码程序 matlab代码 > econ/FilterASeriesThroughALagPolynomialExample.m

    %% Filter a Series Through a Lag Polynomial
%% 
% Create a |LagOp| polynomial and a random time series:

% Copyright 2015 The MathWorks, Inc.

rng('default')                % Make output reproducible

A = LagOp({1 -0.6 0.08 0.2}, 'Lags', [0 1 2 4]);
X = randn(10, A.Dimension);
%%
% Filter the input time series with no explicit initial observations,
% allowing the |filter| method to automatically strip all
% required initial data from the beginning of the input time series
% $X(t)$.
[Y1,T1] = filter(A, X);
%%
% Manually strip all required presample observations directly from the
% beginning of $X(t)$, then pass in the reduced-length $X(t)$ and the
% stripped presample observations directly to the |filter| method. In this
% case, the first 4 observations of $X(t)$ are stripped because the degree
% of the lag operator polynomial created below is 4.
[Y2,T2] = filter(A, X((A.Degree + 1):end,:), ...
     'Initial', X(1:A.Degree,:));
%%
% Manually strip part of the required presample observations from the
% beginning of $X(t)$ and let the |filter| method automatically strip the
% remaining observations from $X(t)$.
[Y3,T3] = filter(A, X((A.Degree - 1):end,:), ...
     'Initial', X(1:A.Degree - 2,:));
%%
% The filtered output series are all the same. However, the associated time
% vectors are not.
disp([T1 T2 T3])