Documentation |
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 State-Space System.
Note: To make configuring a Kalman filter easier, you can use the configureKalmanFilter object to configure a Kalman filter. It sets up the filter for tracking a physical object in a Cartesian coordinate system, moving with constant velocity or constant acceleration. The statistics are the same along all dimensions. If you need to configure a Kalman filter with different assumptions, do not use the function, use this object directly. |
obj = vision.KalmanFilter returns a Kalman filter object for a discrete time, constant velocity system. In this State-Space 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(StateTransitionModel,MeasurementModel) configures the state transition model, A, and the measurement model, H.
obj = vision.KalmanFilter(StateTransitionModel,MeasurementModel,ControlModel) additionally configures the control model, B.
obj = vision.KalmanFilter(StateTransitionModel,MeasurementModel,ControlModel,Name,Value) ) configures the Kalman filter object properties, specified as one or more Name,Value pair arguments. Unspecified properties have default values.
Code Generation Support |
---|
Supports MATLAB^{®} Function block: Yes |
System Objects in MATLAB Code Generation. |
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 t-1 consecutive time steps, you can call the predict method with the time input syntax. This syntax is particularly useful when processing asynchronous video. For example,
[...] = predict(obj,t); [...] = correct(obj,measurement); If t=1, predict(obj,t) is the same as predict(obj).
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 N-column 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 state-space system, described by the following equations.
State equation: | $$x(k)=Ax(k-1)+Bu(k-1)+w(k-1)$$ |
Measurement equation: | $$z(k)=Hx(k)+v(k)$$ |
StateTransitionModel |
Model describing state transition between time steps (A) Specify the transition of state between times as an M-by-M matrix. After the object is constructed, this property cannot be changed. This property relates to the A variable in the State-Space System. Default: [1 0 1 0; 0 1 0 1; 0 0 1 0; 0 0 0 1] |
MeasurementModel |
Model describing state to measurement transformation (H) Specify the transition from state to measurement as an N-by-M matrix. After the object is constructed, this property cannot be changed. This property relates to the H variable in the State-Space System. Default: [1 0 0 0; 0 1 0 0] |
ControlModel |
Model describing control input to state transformation (B) Specify the transition from control input to state as an M-by-L matrix. After the object is constructed, this property cannot be changed. This property relates to the B variable in the State-Space System. Default: [] |
State |
State (x) Specify the state as a scalar or an M-element vector. If you specify it as a scalar it will be extended to an M-element vector. This property relates to the x variable in the State-Space System. Default: [0] |
StateCovariance |
State estimation error covariance (P) Specify the covariance of the state estimation error as a scalar or an M-by-M matrix. If you specify it as a scalar it will be extended to an M-by-M diagonal matrix. This property relates to the P variable in the State-Space System. Default: [1] |
ProcessNoise |
Process noise covariance (Q) Specify the covariance of process noise as a scalar or an M-by-M matrix. If you specify it as a scalar it will be extended to an M-by-M diagonal matrix. This property relates to the Q variable in the State-Space System. Default: [1] |
MeasurementNoise |
Measurement noise covariance (R) Specify the covariance of measurement noise as a scalar or an N-by-N matrix. If you specify it as a scalar it will be extended to an N-by-N diagonal matrix. This property relates to the R variable in the State-Space System. Default: [1] |
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.