I studied Kalman filters some time ago, and recently came to realize I do not understand some parts on them. Specifically related to the difference between
- using a static Kalman-gain, found by solving the Riccati Equations
- Using a recursively updated/dynmamic Kalman-gain, by applying this scheme
I have some questions about this, which I put in italic-bold.
I often see the recursively method used in various applications, but to me the static method seems easier to implement. In what situations is the recursive method chosen over the static method?
Convergence
I always thought these would result in the same gain, once the recursive method had converged. However, I wrote a Matlab script to compare the two methods, and to see how the recurrent method converges.
I used the following system:
$dt = 0.1 \\ x(k+1) = \begin{bmatrix} 1 & dt \\ 0 & 1 \end{bmatrix} x(k) + \begin{bmatrix} 0 \\ dt \end{bmatrix} u(k) \\ y(k) = C\;x(k)$
I tried this with $ C = \begin{bmatrix} 1 & 0 \end{bmatrix}$ to see how the kalman gain would converge. The kalman gain is here a $2\times 1$ matrix.
Running both idare to obtain a static gain: (It IS correct that the $A$ and $C$ matrices are transposed here.)
Q = diag([0.01 0.01]);
R = 0.01;
[~,Kstat,~,~] = idare(A',C',Q,R,[],[]);
Kstat = Kstat';
and the recursive method:
P = zeros(2,2);
for i = 2:60
P = A*P*A' + Q;
S = C*P*C' + R;
Kdyn = P*C'*inv(S); %#ok<MINV>
P = (eye(2) - Kdyn*C)*P;
end
Now if I plot the recursive method over each iteration, and the found static kalman gain of idare, I obtain the following plot.
What is wrong with my code; why does $K_1$ not converge to the solution found by using the Riccati Equations? Running the recursive method for longer does not solve the problem.
Observability
In Observability for Kalman Filtering? it is stated that "A Kalman Filter build around a system with unobservable state will simply not work." This is also what I was taught. The Riccati equations don't have a solution for an unobservable system, so that made sense to me.
I ran two versions of the filter with the system above and some bogus data: One for the observable one ($ C = \begin{bmatrix} 1 & 0 \end{bmatrix}$) and an observable one ($ C = \begin{bmatrix} 0 & 1 \end{bmatrix}$). Indeed the idare function does not give a solution for the unobservable case, so I set the static-kalman gain to [0;0] for the unobservable case, so I at least could run something.
However, running the recursive method seemed to work just fine in the unobservable case. Below are two plots, one with the C matrix $ C = \begin{bmatrix} 1 & 0 \end{bmatrix}$ and the other with $ C = \begin{bmatrix} 0 & 1 \end{bmatrix}$. In the first, both filters work fine. In the second, only the dynamic one works well.
What is going on here, is this correct? Why is the Kalman filter for the unobservable system working seemly very well? Is it NOT needed for a system to be observable in order to use a Kalman Filter?
Matlab Files Here are the Matlab Files, in case these are needed: https://anonymous.4open.science/r/Kalman-Comparison-D657/