Multi-Variable Kalman Filter
Kalman FIlter but better?
State-Space Model:
The Multivariable Kalman Filter works on a "state-space model", which shows the system's dynamic behavior using a set of state variables and state transition equations. In a general form, the state-space model can be represented as follows:
State Vector (n x 1): x[k] = [x₁[k], x₂[k], ..., xₙ[k]]ᵀ Represents the system's state at time step k. It includes all the variables needed to describe the system's behavior, such as position, velocity, orientation, etc.
State Transition Matrix (n x n): A Describes how the state evolves over time. It represents the dynamics of the system and is used to predict the state at the next time step.
Control Input Vector (optional) Represents external inputs or controls that affect the system's behavior.
Control Input Matrix (n x m): B (optional) Describes how the control inputs affect the state transition.
Process Noise Vector (n x 1): w[k] Represents the uncertainty or disturbances in the state transition model. It is assumed to be a zero-mean Gaussian noise with a known covariance matrix.
State Transition Equation: x[k+1] = A * x[k] + B * u[k] + w[k]
Measurement Model:
In addition to the state-space model, the Multivariable Kalman Filter also uses a measurement model to relate sensor measurements to the system's state. The measurement model can be represented as follows:
Measurement Vector (m x 1): z[k] = [z₁[k], z₂[k], ..., zₘ[k]]ᵀ Represents the sensor measurements at time step k.
Measurement Matrix (m x n): C Describes how the state variables are related to the sensor measurements.
Measurement Noise Vector (m x 1): v[k] Represents the measurement noise or errors, assumed to be a zero-mean Gaussian noise with a known covariance matrix.
Measurement Equation: z[k] = C * x[k] + v[k]
Kalman Filter Equations:
The Kalman Filter operates in two main steps: the prediction step (time update) and the correction step (measurement update).
Prediction Step:
State Prediction: x̂[k|k-1] = A * x̂[k-1|k-1] + B * u[k]
is the predicted state at time k based on the previous estimate.
is the previous state estimate at time k-1.
Error Covariance Prediction: P[k|k-1] = A * P[k-1|k-1] * Aᵀ + Q
is the predicted error covariance matrix at time k based on the previous estimate.
is the error covariance matrix of the previous estimate at time k-1.
Q is the process noise covariance matrix.
Correction Step:
Kalman Gain Calculation: K[k] = P[k|k-1] * Cᵀ * (C * P[k|k-1] * Cᵀ + R)⁻¹
is the Kalman Gain at time k.
R is the measurement noise covariance matrix.
State Update: x̂[k|k] = x̂[k|k-1] + K[k] * (z[k] - C * x̂[k|k-1])
is the updated state estimate at time k.
is the actual sensor measurement at time k.
Error Covariance Update: P[k|k] = (I - K[k] * C) * P[k|k-1]
is the updated error covariance matrix at time k.
I is the identity matrix.
5. Iterative Process:
The Kalman Filter operates in an iterative process (updates itself again and again...), where the prediction and correction steps are repeated for each time step (k) using the updated state estimate and error covariance matrix from the previous time step.
Advantages:
Optimal Estimation: The Kalman Filter provides the best linear unbiased estimate of the system state given the measurements and process model.
Real-Time Capability: It operates in real-time, continuously updating the state estimate based on new measurements.
Noise Robustness: The filter handles sensor noise and disturbances effectively, providing a stable and accurate state estimation.
Challenges:
Computational Complexity: Implementing the Kalman Filter, especially for high-dimensional systems, can be computationally intensive.
Modeling Errors: The filter assumes linearity and Gaussian noise, which may not hold true for all systems.
Lets first download the API! NOTE : MVKF can be used many other ways and methods for different reasons what is stated here doesn't mean you are limited to this...
this API has a dependency of
to import it into your build.dependencies.gradle file do this
then rebuild your project
this creates all the basic variables that we talked about above. In this project we are going to be implementing a Kalman filter of 2 different distance sensors simultaneously.
here we create a new instance of our API and give in our parameters in this order
This has a loop where it measures the values of both sensors and updates the Kalman filter and then gets the values and this will happen until we stop the opmode. The output should look something like this.
Last updated