Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Estimate system measurements and states using Kalman filter

The `dsp.KalmanFilter`

System
object™ is an estimator used to recursively obtain a solution for linear optimal
filtering. This estimation is made without precise knowledge of the underlying dynamic system.
The Kalman filter implements the following linear discrete-time process with state,
*x*, at the *k*^{th} time-step: $$x(k)=Ax(k-1)+Bu(k-1)+w(k-1)$$ (state equation). This measurement, *z*, is given as: $$z(k)=Hx(k)+v(k)$$ (measurement equation).

The Kalman filter algorithm computes the following two steps recursively:

Prediction: Process parameters x (state) and P (state error covariance) are estimated using the previous state.

Correction: The state and error covariance are corrected using the current measurement.

To filter each channel of the input:

Create the

`dsp.KalmanFilter`

object and set its properties.Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects? (MATLAB).

`kalman = dsp.KalmanFilter`

```
kalman = dsp.KalmanFilter(STMatrix, MMatrix, PNCovariance,
MNCovariance, CIMatrix)
```

`kalman = dsp.KalmanFilter(Name,Value)`

returns the Kalman
filter System
object, `kalman`

= dsp.KalmanFilter`kalman`

, with default values for the parameters.

returns a Kalman filter System
object, `kalman`

= dsp.KalmanFilter(`STMatrix`

, `MMatrix`

, `PNCovariance`

,
`MNCovariance`

, `CIMatrix`

)`kalman`

. The `StateTransitionMatrix`

property is set to `STMatrix`

, the `MeasurementMatrix`

property is set to `MMatrix`

, the
`ProcessNoiseCovariance`

property is set to
`PNCovariance`

, the `MeasurementNoiseCovariance`

property is set to `MNCovariance`

, and the
`ControlInputMatrix`

property is set to
`CIMatrix`

.

returns an Kalman filter System
object, `kalman`

= dsp.KalmanFilter(`Name,Value`

)`kalman`

, with each property set to the specified value.
Enclose each property name in single quotes. Unspecified properties have default
values.

**For versions earlier than R2016b, use the step
function to run the System object algorithm. The arguments to
step are the object you created, followed by
the arguments shown in this section.**

**For example, y = step(obj,x) and y = obj(x) perform equivalent operations.**

`[zEst, xEst, MSE_Est, zPred, xPred, MSE_Pred] = kalman(z,u)`

`[`

carries out the iterative Kalman filter algorithm over measurements `zEst`

, `xEst`

, `MSE_Est`

, `zPred`

, `xPred`

, `MSE_Pred`

] = kalman(`z`

,`u`

)`z`

and control inputs `u`

. The columns in `z`

and
`u`

are treated as inputs to separate parallel filters, whose
correction (or update) step can be disabled by the `DisableCorrection`

property. The values returned are estimated measurements `zEst`

,
estimated states `xEst`

, MSE of estimated states
`MSE_Est`

, predicted measurements `zPred`

,
predicted states `xPred`

, and MSE of predicted states
`MSE_Pred`

.

To use an object function, specify the
System
object as the first input argument. For
example, to release system resources of a System
object named `obj`

, use
this syntax:

release(obj)

This object implements the algorithm, inputs, and outputs described on the Kalman Filter block reference page. The object properties correspond to the block parameters.

[1] Greg Welch and Gary Bishop, *An
Introduction to the Kalman Filter*, Technical Report TR95
041. University of North Carolina at Chapel Hill: Chapel Hill, NC.,
1995.