# State-dependent Covariance in the Kalman Filter

When using a Kalman filter, one of the variables that must be defined is a matrix representing the covariance of the observation noise. In the implementations I have seen, this matrix is defined once, and that same matrix is then used throughout the algorithm, each time an update step is taken.

However, in my particular problem, I am able to get a state-dependent covariance of the observation noise. This is because instead of using the raw observation, I actually use the observation to predict the state (using some machine learning), and this prediction itself comes with a known uncertainty. This is effectively equivalent to treating the state prediction as my "observation", and the uncertainty from this prediction as the covariance of the observation noise.

So, in the update step of the Kalman filter, could I use this state-dependent noise covariance, such that each update would use a different covariance matrix? Or does this invalidate all the maths, and I really do need to use a fixed covariance matrix for the entire algorithm?

The math is generally only done out for a fixed covariance matrix, so yes you would be invalidating the math. If you had an analytic solution, or at least bounds, for how your covariance changes it might be possible to redo the math to either prove the normal equations still have the same guarantees or give updated equations.

That said, in practice the covariance matrix is often treated as a tuning variable rather than real observation covariance. Even worse, nonlinear Kalman filters also invalidate the math. Both situations are very common, though, and have proved to work well when experimentally tuned. Generally all you are loosing is optimality and perhaps a narrower operation window.

• This would not be invalidating the math. The kalman filter update equation consumes a state estimate, a state uncertainty, a measurement,and a measurement uncertainty. These terms are used to calculate the new stare estimate and state uncertainty. It has no explicit reliance on the previous measurements or measurement uncertainties. Jan 5 '20 at 1:12
• The update equations are fine as is but all the properties associated with them are invalidated; things like optimality and general convergence. The proofs that Kalman Filters have those properties assume a static covariance matrix. Jan 5 '20 at 15:00
• The update equations will optimally incorporate the new information with it's inherent uncertainty. Jan 5 '20 at 16:19
• The update equations generate a new, unbiased estimate with a new covariance. Any properties you are referring to are the result of the assumption of a static measurement noise, this assumption is made to develop intuition about the kalman filter in a classroom, it is not necessary for the kalman filter to be optimal in the unbiased, least squares way. Jan 5 '20 at 16:27

The maths of the Kalman filter depend on a dynamic Ricatti equation. Under some assumtions about the covariance matrices, this dynamic equiation is stable and converges to a solution. The Kalman filter implementation that you must likely know, obtains the filter gain (also known as Kalman gain) by using the solution of the Ricatti equation for the (user) given convariance matrices.Ths produces a simpified steady state filter implementation which is the most widely used version of the Kalman filter.

As @ryan0279 mentioned, the simplified steady state solution has certain mathematical properties that make the filter have some very nice stability and performace characteristics. If you implement the filter differently, these characteristics might no longer hold. You might end up with an unstable filter.

Nevertheless, this does not mean that you cannot implement the filter using a time-varying model or covariance matrices. Heck, the widely used version of the nonlinear version of the Kalman Filter (Extended Kalman Filter kind of does that. Of course stability is not guaranteed for these kind of implementations, but people use them any way because in many use cases they just work.

A way to implement what you want is to solve the dynamic ricatti equation of the Kamlan filter along with your filter dynamics, similar to how the Hybrid Kalman Filter is implemented. Then on each iteration of the ricatti equation solution, update your convariance matrices however you like. Just beware that you are entering the nonlinear domain and you might endup getting weird results and unstable estimates. But maybe after some tuning and testing all your operating conditions you are able to make it work fine.

• Is a normal Kalman filter not appropriate here? This seems like a textbook case for filtering. Jan 5 '20 at 1:22
• Which specific Kalman filter version you mean with "normal"? Most people understand "normal" KF as the linear, steady state solution with fixed Kalman gain, in which case no, the steady state KF is not appropriate for time varying covariance matrices. Jan 8 '20 at 13:50
• I meant a textbook, linear kalman filter. Jan 8 '20 at 13:58
• I that case no, because as I understand the question refers to state-dependent (time varying) covariance matrices (en.wikipedia.org/wiki/…). And the "normal" Kalman filter assumes static matrices to compute the solution to the Ricatti eq in order to obtain the fixed Kalman gain. Jan 8 '20 at 14:10