Main Content

filter

Apply lag operator polynomial to filter time series

Syntax

[Y,times] = filter(A,X)
[Y,times] = filter(A,X,'Initial',X0)

Description

Given a lag operator polynomial A(L), [Y,times] = filter(A,X)applies A(L) to time series data X(t). This is equivalent to applying a linear filter to X(t), producing the filtered output series Y(t) = A(L)X(t).

[Y,times] = filter(A,X,'Initial',X0) applies A(L) to time series data X(t) with specified presample values of the input time series X(t).

Input Arguments

A

Lag operator polynomial object, as produced by LagOp.

X

numObs-by-numDims matrix of time series data to which the lag operator polynomial A is applied. The last observation is assumed to be the most recent. numDims is the dimension of A, unless X is a row vector, in which case X is treated as a univariate series. For univariate X, the orientation of the output Y is determined by the orientation of the input X.

'Initial'

Presample values of the input time series X(t). If 'Initial' is unspecified, or if the number of presample values is insufficient to initialize filtering, values are taken from the beginning of X, reducing the effective sample size of the output Y. For convenience, scalar presample values are expanded to provide all numPresampleObs-by-numDims presample values, and data is not taken from X. If more presample values are specified than necessary, only the most recent values are used. For univariate X, presample values can be a row or a column vector.

Output Arguments

Y

Filtered input time series, Y(t) = A(L)X(t).

times

Vector of relative time indices the same length as Y. Times are expressed relative to, or as an offset from, observations times 0, 1, 2,...,numObs–1 for the input series X(t). For a polynomial of degree p, Y(0) is a linear combination of X(t) for times t = 0, –1, –2,...,–p (presample data). Y(t) for t > 0 is a linear combination of X(t) for times t = t, t–1, t–2,...,tp.

Examples

expand all

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 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])
     4     0     2
     5     1     3
     6     2     4
     7     3     5
     8     4     6
     9     5     7

Algorithms

Filtering is limited to single paths, so matrix data are assumed to be a single path of a multidimensional process, and 3-D data (multiple paths of a multidimensional process) are not allowed.

See Also