www.gusucode.com > econ 案例源码程序 matlab代码 > econ/FilterTimeSeriesExample.m
%% Filter Time Series % Copyright 2015 The MathWorks, Inc. %% % Create a |LagOp| polynomial and a random time series: 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 fromX(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])