The Kalman filter object is designed for tracking. You can use it to predict a physical object's future location, to reduce noise in the detected location, or to help associate multiple physical objects with their corresponding tracks. A Kalman filter object can be configured for each physical object for multiple object tracking. To use the Kalman filter, the object must be moving at constant velocity or constant acceleration.
The Kalman filter algorithm involves two steps, prediction and correction (also known as the update step). The first step uses previous states to predict the current state. The second step uses the current measurement, such as object location, to correct the state. The Kalman filter implements a discrete time, linear StateSpace System.
Note:
To make configuring a Kalman filter easier, you can use the 
obj = vision.KalmanFilter
returns a Kalman
filter object for a discrete time, constant velocity system. In this StateSpace System, the state transition
model, A, and the measurement model, H,
are set as follows:
Variable  Value 

A  [1 0 1 0; 0 1 0 1; 0 0 1 0; 0 0 0 1] 
H  [1 0 0 0; 0 1 0 0] 
obj = vision.KalmanFilter(
configures
the state transition model, A, and the measurement
model, H.StateTransitionModel
,MeasurementModel
)
obj = vision.KalmanFilter(
additionally
configures the control model, B.StateTransitionModel
,MeasurementModel
,ControlModel
)
)
configures the Kalman filter object properties, specified as one or
more obj
= vision.KalmanFilter(StateTransitionModel
,MeasurementModel
,ControlModel
,Name,Value
)Name,Value
pair arguments. Unspecified properties
have default values.
Code Generation Support 

Supports MATLAB^{®} Function block: Yes 
Code Generation Support, Usage Notes, and Limitations. 
Use the predict
and correct
methods
based on detection results.
When the tracked object is detected, use the predict
and correct
methods
with the Kalman filter object and the detection measurement. Call
the methods in the following order:
[...] = predict(obj
); [...] = correct(obj
,measurement);
When the tracked object is not detected, call the predict
method,
but not the correct
method. When the tracked object
is missing or occluded, no measurement is available. Set the methods
up with the following logic:
[...] = predict(obj
); If measurement exists [...] = correct(obj
,measurement); end
If the tracked object becomes available after missing
for the past t1 contiguous time steps, you can
call the predict
method t times.
This syntax is particularly useful to process asynchronous video..
For example,
for i = 1:k [...] = predict(obj); end [...] = correct(obj,measurement)
Use the distance
method
to find the best matches. The computed distance values describe how
a set of measurements matches the Kalman filter. You can thus select
a measurement that best fits the filter. This strategy can be used
for matching object detections against object tracks in a multiobject
tracking problem. This distance computation takes into account the
covariance of the predicted state and the process noise. The distance
method
can only be called after the predict
method.
d = distance(obj, z_matrix)
computes a
distance between the location of a detected object and the predicted
location by the Kalman filter object. Each row of the Ncolumn z_matrix
input
matrix contains a measurement vector. The distance
method
returns a row vector where each distance element corresponds to the
measurement input.
This object implements a discrete time, linear statespace system, described by the following equations.
State equation:  $$x(k)=Ax(k1)+Bu(k1)+w(k1)$$ 
Measurement equation:  $$z(k)=Hx(k)+v(k)$$ 

Model describing state transition between time steps (A) Specify the transition of state between times as an MbyM matrix. After the object is constructed, this property cannot be changed. This property relates to the A variable in the StateSpace System. Default: 

Model describing state to measurement transformation (H) Specify the transition from state to measurement as an NbyM matrix. After the object is constructed, this property cannot be changed. This property relates to the H variable in the StateSpace System. Default: 

Model describing control input to state transformation (B) Specify the transition from control input to state as an MbyL matrix. After the object is constructed, this property cannot be changed. This property relates to the B variable in the StateSpace System. Default: [] 

State (x) Specify the state as a scalar or an Melement vector. If you specify it as a scalar it will be extended to an Melement vector. This property relates to the x variable in the StateSpace System. Default: [ 

State estimation error covariance (P) Specify the covariance of the state estimation error as a scalar or an MbyM matrix. If you specify it as a scalar it will be extended to an MbyM diagonal matrix. This property relates to the P variable in the StateSpace System. Default: [ 

Process noise covariance (Q) Specify the covariance of process noise as a scalar or an MbyM matrix. If you specify it as a scalar it will be extended to an MbyM diagonal matrix. This property relates to the Q variable in the StateSpace System. Default: [ 

Measurement noise covariance (R) Specify the covariance of measurement noise as a scalar or an NbyN matrix. If you specify it as a scalar it will be extended to an NbyN diagonal matrix. This property relates to the R variable in the StateSpace System. Default: [ 
clone  Create Kalman filter object with same property values 
correct  Correction of measurement, state, and state estimation error covariance 
distance  Confidence value of measurement 
predict  Prediction of measurement 
Welch, Greg, and Gary Bishop, An Introduction to the Kalman Filter, TR 95–041. University of North Carolina at Chapel Hill, Department of Computer Science.