Kalman icon indicating copy to clipboard operation
Kalman copied to clipboard

Why Q in Kalman-Filter-CA-Ball is not an allmost diagonal matrix

Open ruoyu0088 opened this issue 11 years ago • 1 comments

Hi, I am learning kalman filter from your notebooks. I have a question for the notebook Kalman-Filter-CA-Ball. The covariance matrix Q in the notebook is something like this:

[[  2.50e-09   2.50e-09   2.50e-09   5.00e-07   5.00e-07   5.00e-07   5.00e-05   5.00e-05   5.00e-05]
 [  2.50e-09   2.50e-09   2.50e-09   5.00e-07   5.00e-07   5.00e-07   5.00e-05   5.00e-05   5.00e-05]
 [  2.50e-09   2.50e-09   2.50e-09   5.00e-07   5.00e-07   5.00e-07   5.00e-05   5.00e-05   5.00e-05]
 [  5.00e-07   5.00e-07   5.00e-07   1.00e-04   1.00e-04   1.00e-04   1.00e-02   1.00e-02   1.00e-02]
 [  5.00e-07   5.00e-07   5.00e-07   1.00e-04   1.00e-04   1.00e-04   1.00e-02   1.00e-02   1.00e-02]
 [  5.00e-07   5.00e-07   5.00e-07   1.00e-04   1.00e-04   1.00e-04   1.00e-02   1.00e-02   1.00e-02]
 [  5.00e-05   5.00e-05   5.00e-05   1.00e-02   1.00e-02   1.00e-02   1.00e+00   1.00e+00   1.00e+00]
 [  5.00e-05   5.00e-05   5.00e-05   1.00e-02   1.00e-02   1.00e-02   1.00e+00   1.00e+00   1.00e+00]
 [  5.00e-05   5.00e-05   5.00e-05   1.00e-02   1.00e-02   1.00e-02   1.00e+00   1.00e+00   1.00e+00]]

since it's a covariance matrix, and the value between all the acceleration are 1.0, I think this means acc_x and acc_y and acc_z are not Independent. For example, the following code make some random values with an all one covariance matrix:

import numpy as np
np.random.multivariate_normal([0, 0, 0], np.ones((3, 3)), size=5)

the output is:

array([[-0.8903466 , -0.8903466 , -0.8903466 ],
       [-0.47167442, -0.47167442, -0.47167442],
       [ 0.54420125,  0.54420125,  0.54420125],
       [-0.41152627, -0.41152627, -0.41152627],
       [-1.10581353, -1.10581353, -1.10581353]])

All the columns are the same value.

I think x, v_x, acc_x are dependent, y, v_y, acc_y are dependent, and z, v_z, acc_z are dependent, all other pairs are Independent. So the matrix Q is something like this:

[[  2.5e-11         0         0     5e-09         0         0     5e-07         0         0]
 [        0   2.5e-11         0         0     5e-09         0         0     5e-07         0]
 [        0         0   2.5e-11         0         0     5e-09         0         0     5e-07]
 [    5e-09         0         0     1e-06         0         0    0.0001         0         0]
 [        0     5e-09         0         0     1e-06         0         0    0.0001         0]
 [        0         0     5e-09         0         0     1e-06         0         0    0.0001]
 [    5e-07         0         0    0.0001         0         0      0.01         0         0]
 [        0     5e-07         0         0    0.0001         0         0      0.01         0]
 [        0         0     5e-07         0         0    0.0001         0         0      0.01]]

I am not sure I am right or not, just create this issue to discuss about this.

ruoyu0088 avatar Aug 02 '14 13:08 ruoyu0088

Hi ruoyu0088, you can think about the process noise covariance matrix Q as an wrapper for everything, which is possible and is not modeled by the dynamic matrix. So, it estimates how bad things can get when the system is run open loop for a given period of time, without measurement (correction step). So I took into account, that the very light ball is influenced in every direction by air and nonlinear drag.

But theoretically your Q is correct! As you can see, after some filter steps, the Kalman filter itself, figured it out and estimated the uncertainty (P) in the same shape as you want to define it for Q:

bildschirmfoto 2014-08-02 um 20 48 34

balzer82 avatar Aug 02 '14 18:08 balzer82