proprioception stateEstimation
A recursive algorithm used to estimate the state of a linear system based on noisy measurements.

Setup
There’s a ton of variables to keep track of:
- is the state vector at time
- is the state transition matrix, how state changes overtime on its own (irrespective of the input)
- is the control input matrix, maps control input to its effect on the state5
- is the control input
- is the measurement vector
- is the measurement matrix, maps the true state to what the sensor should measure (without noise)
- is the process noise
- is the measurement noise
The goal of the Kalman Filter is to estimate a hidden state of a linear system from the noisy measurements that we get.
This is telling us how the hidden state of a linear system can be modeled as a function of how the linear system evolves without control input + how the system evolves with control input + process noise.
This is telling us how the measurement of our states is modeled as a function of our hidden state mapped to our sensor measurements + some measurement noise.
Hidden state refers to the "underlying" state of the system. It is the true state of the system. We never have a direct understanding of this state in real life, we only have noisey measurements that get us there.
Two-steps
Because we will never know the true hidden state , we are stuck with making our best guess . The Kalman filter is just a way to try to get a nice .
A Kalmann Filter has two main steps:
Predict Step
First we predict the current hidden state, and its covariance from the previous state and its covariance. These are priors they arent the final form of and its covariance
This is telling us that to compute the state prior, we take the sum of how the system evolves naturally without the control input (called the state transition matrix) and how the state evolves with the control input.
This is telling us that to compute the state covariance prior, we take the product of the previous state covariance and the state transition matrix squared, then sum it with the covariance of our process noise.
Update Step
Here we take into account our measurements and try to reconciliate them with our predicted state and state covariance priors.
We first compute something called the Kalman Gain
The Kalman Gain tells us how much we trust our prediction over our trust in our measurement.
We use the computed Kalman gain to do a final update on our state and covariance
This is telling us that the updated state is given by the predicted state plus the error between our real measurement and our measurement should we have gotten it from our prior, multiplied by the Kalman Gain
We also use the Kalman Gain to update the state covariance
This is telling us that the updated state covariance (our certainty in the state estimate), is given by our confidence in the measurement. If confidence is high, state covariance goes to 0. If its low, state covariance remains as the prior covariance we computed (which could bloat)
EXAMPLE (FULL CONFIDENCE IN MEASUREMENT) Kalman Gain is interesting, intuitively, if we assume that our measurement noise is tiny, then that means
Which, as you will see, tells our update step to completely trust the entire measurement (because its noise is 0).
If we assumed that our measurement is perfectly accurate, no noise. Then
Which means that we are just correcting our prior by the error it had with our measurement. Essentially making the state derived from the measurement, the state of the system.
Likewise, for covariance.
What this is telling us is that when we are fully confident in our measurement, we end up with no state covariance (uncertainty) at all. And our final state estimate is just our measurement.
EXAMPLE (NO CONFIDENCE IN MEASUREMENT) Here, our Kalman Gain goes to 0.
Lets see how this affects our update.
So our state measurement just becomes our predicted state.
So if we have no confidence in our measurement, then we just take the predicted state and its covariance at face value.
Note:
If our process noise is non-zero, then will continue to bloat. If our state transition matrix is non-zero, then will continue to bloat.
This means that the uncertainty of a Kalman filter will continue to bloat from its state transition matrix and process noise until a measurement of high-enough certainty is obtained.
EXAMPLE (DECENT CONFIDENCE IN MEASUREMENT) Here, I’m just going to walk through the whole step so that I remember how to write this.
Predict Step:
Update Step:
The introduction of a measurement can only make this better. Even a really shit measurement of high uncertainty could help with our measurement (marginally)
So this means that the Kalman gain directly affects how much we want our measurement to affect our state estimate. It can range from no effect at all (0), or full correction effect.
EXAMPLE (PROCESS NOISE) Process noise tells us how much we should trust the model, based on how noisy our environment can be. Higher process noise means that we will bloat our uncertainty faster the longer we wait for a new measurement.
Predict Step
Update Step
If we have infinite process noise, then the whole system collapses lol.
The increase of process noise will result in our system become more uncertain faster. This means that we need more measurements to counteract the rate at which the state covariance is increasing.
