MATLAB MEX Function Reference |

Fixed-interval smoothing is concerned with the smoothing of a finite set of data, i.e., with obtaining for fixed *T* and all *t* in the interval *t* = 1, ... , *T*.

**Syntax**

[sm, vsm] = kalcvs(data, a, F, b, H, var, pred, vpred) [sm, vsm] = kalcvs(data, a, F, b, H, var, pred, vpred, un, vun)

**Description**

`KALCVS`

uses backward recursions to compute the smoothed
estimate and its covariance matrix, ,
where *T* is the number of observations in the complete data set.

The inputs to the KALCVS function are as follows.

`data`

- is a
*N*×_{y}*T*matrix containing data (*y*_{1}, ... ,*y*_{T})'. `a`

- is an
*N*×1 vector for a time-invariant input vector in the transition equation, or a_{z}*N*×_{z}*T*vector containing input vectors in the transition equation. `F`

- is an
*N*×_{z}*N*matrix for a time-invariant transition matrix in the transition equation, or a_{z}*N*×_{z}*N*×_{z}*T*matrix containing*T*transition matrices. `b`

- is an
*N*×1 vector for a time-invariant input vector in the measurement equation, or a_{y}*N*×_{y}*T*vector containing input vectors in the measurement equation. `H`

- is an
*N*×_{y}*N*matrix for a time-invariant measurement matrix in the measurement equation, or a_{z}*N*×_{y}*N*×_{z}*T*matrix containing*T*time variant*H*_{t}matrices in the measurement equation. `var`

- is an (
*N*+_{y}*N*)×(_{z}*N*+_{y}*N*) covariance matrix for the errors in the transition and the measurement equations, or a (_{z}*N*+_{y}*N*)×(_{z}*N*+_{y}*N*)×_{z}*T*matrix containing covariance matrices in the transition equation and measurement equation noises, that is, . `pred`

- is a
*N*×_{z}*T*matrix containing one-step forecasts . `vpred`

- is a
*N*×_{z}*N*×_{z}*T*matrix containing mean square error matrices of predicted state vectors . `un`

- is an optional
*N*×1 vector containing_{z}. The returned value is**u**_{T}*u*_{0}. `vun`

- is an optional
*N*×_{z}*N*matrix containing_{z}. The returned value is**U**_{T}*U*_{0}.

`sm`

- is a
*N*×_{z}*T*matrix containing smoothed state vectors . `vsm`

- is a
*N*×_{z}*N*×_{z}*T*matrix containing covariance matrices of smoothed state vectors .

**Algorithm**

The smoothing algorithm uses one-step forecasts and their covariance matrices, which are obtained using KALCVF function. For notation, is the smoothed value of the state vector

When the SSM is specified using the alternative transition equation

You can use the KALCVS function regardless of the specification of the transition equation when

The KALCVS function is accompanied by the KALCVF function, as shown in the following code. Note that you do not need to specify UN and VUN.

[logl, pred, vpred] = kalcvf(y, 0, a, F, b, H, var); [sm, vsm] = kalcvs(y, a, F, b, H, var, pred, vpred);You can also compute the smoothed estimate and its covariance matrix on an observation-by-observation basis. When the SSM is time invariant, the following example performs smoothing. In this situation, you should initialize UN and VUN as matrices of value 0.

[logl, pred, vpred] = kalcvf(y, 0, a, F, b, H, var); n = size(y,2); nz = size(F,1); un = zeros(nz,1); vun = zeros(nz,nz); sm = zeros(nz,n); vsm = zeros(nz,nz,n); for i=n:-1:1 y_i = y(:,i); pred_i = pred(:,i); vpred_i = vpred(:,:,i); [sm_i, vsm_i] = kalcvs(y_i, a, F, b, H, var, pred_i, vpred_i, un, vun); sm(:,i) = sm_i; vsm(:,:,i) = vsm_i; end

**See also**

`KALCVF`

performs covariance filtering and prediction

`Getting Started with State Space Models`

`Kalman Filtering Example 1: Likelihood Function Evaluation`

`Kalman Filtering Example 2: Estimating an SSM Using the EM Algorithm`

**References**

[1] Harvey, A.C., *Forecasting, Structural Time Series Models and the Kalman Filter*, Cambridge: Cambridge University Press, 1991.

[2] Anderson, B.D.O., and J.B. Moore, *Optimal Filtering*, Englewood Cliffs, NJ: Prentice-Hall, 1979.

[3] Hamilton, J.D., *Time Series Analysis*, Princeton, 1994.