I am having some trouble debugging an application of a linear discreet Kalman Filter. From time to time, I find that there are diagonal elements of the covariance matrix that become negative. This is clearly erroneous and causes the whole filter to blow up.

What are the possible causes and remedies for this problem? I know there is a known issue with rounding errors if the error measurement update is expressed as

$P^t = (I – K_tH_t)P^{t-1} $

and so I have implemented this, as suggested in several sources, as

$P^t = (I – K_tH_t)P^{t-1}(I-K_tH_t)^T + K_tR_tK_t^T $

which is supposed to be the sum of two positive definite matrices, ensuring that $P^t$ is positive definite. In my case, this isn’t so. The elements go negative not by small, rounding errorish values, but by comparable values to the positive elements.

My Kalman Filter implementation has been pretty battle hardened by this point so I don’t think there are any glaring bugs. I haven’t encountered this problem before. I am playing around with a new dataset which is causing these errors.

The main suspect at this point that I can come up with is that fact that at times, entire columns of the $H_t$ matrix can be zero. Recall that $H$ is defined as

$z_t = H_tx_{t-1}$

where $z$ are the measurements and $X$ the state vector. As I say, sometimes whole columns of $H$ are zero, meaning that there are no measurements that contain any information about some particular state in the measurements for the given timestep. This may be an issue, but on the other hand I would hope that the filter would simply leave that state unchanged, and add a bit of process noise to its variance, without having any major dramas. I feel like this situation must have happened before with some other datasets without any ill effect.

Where else could I look to see where the problem is emerging? The $H$ matrix contains negative values, but that should not be an issue. $K$ also is negative at times, however following through the logic of the Filter construction, the negative elements in $H$ that led to negatives in $K$ should cancel back out in the error measurement update step. Clearly that isn’t happening though.

Are there any standard approaches to ensuring the robustness of a Kalman Filter that I need to employ here, or any other suggestions on where to look to find the cause?

**Answer**

**Attribution***Source : Link , Question Author : Bogdanovist , Answer Author : Community*