rlabbe / Kalman-and-Bayesian-Filters-in-Python

Kalman Filter book using Jupyter Notebook. Focuses on building intuition and experience, not formal proofs. Includes Kalman filters,extended Kalman filters, unscented Kalman filters, particle filters, and more. All exercises include solutions.
Other
16.83k stars 4.2k forks source link

Finding value for Q in Extended Kalman Filter Chapter should be completed by substituting in values for w #9

Closed oxinabox closed 8 years ago

oxinabox commented 9 years ago

Hi (again), In http://nbviewer.ipython.org/github/rlabbe/Kalman-and-Bayesian-Filters-in-Python/blob/master/09_Extended_Kalman_Filters/Extended_Kalman_Filters.ipynb#Designing-Q We get some details on how to find Q, It would be great if this concluded by substiting in values for $w_alt$ and $w_vel$, to produce the final $Q$.

To may knowledge it goes: $w{vel}^2=5$, $v{vel}^2=10$, and $w{alt} w{vel}=0$ (as they are independent and thus uncorrelated)

This gives a final matrix of:

Q=
[ 0.000208333  0.00625  0.0
 0.00625      0.25     0.0
 0.0          0.0      0.5]

However that produces awful results, so i think I must have got the math wrong. It would be great to have this section more complete so I can better understand my mistake.

PS: Is it ok if I raise issues like this? If you would prefer not to receive such feedback at this stage, I can be quiet (and come back when you are, if you would like. :-) )

rlabbe commented 9 years ago

First, I absolutely want to hear things like this. This is one of the biggest benefits of open source books - we can make changes in days, collaboratively, rather than waiting years, or never, for a new edition to be released.

With that said, the EKF chapter is still not just in early draft, but quite unfinished, and the section on designing Q is quite bad. Even the wording is incorrect. This radar problem is actually a very difficult one - getting position from slant range only is extremely difficult, and for the most part this is an unnatural formation since radar will give you slant range and angle. I will probably be completely reformulating this problem.

I looked at the code and the amount of noise I was injecting into the process noise is absurd. 5m/s every 1/20 of a second is a huge change in velocity (this is supposed to be noise due to buffeting wind or maneuvers we are not modelling), as is 10m every 1/20sec in altitude. Hence the output is terrible. All of this needs to be redesigned. Arbitrarily setting the variance in both to .1^2 gives what seems to be good output. Plus, the radar simulation itself is incorrect. I claimed to be modifying the process noise, but I was not modifying self.vel or self.alt by incorporating the noise into it. So the plane was not doing a random walk like it should have been.

In short, the chapter is not ready for prime time, and I should voice the initial author's note much more strongly. So you know, the plan is to add another simulation after the 'designing Q' section with Q fully/correctly filled out so that we have a concrete example rather than the abstraction of the matrix math.

If you just have a question you can email me directly; bad code like this definitely deserves an issue being raised on github.

rlabbe commented 9 years ago

I've pushed a change to the chapter - basically the wording of the warnings is much stronger. I did fix the radar simulation, and made the plots more readable by plotting the actual track against the filtered estimate. To be honest I'm thinking of pulling the code and examples completely into a branch until this stuff is more developed, because it is probably more misleading than helpful at the moment.

oxinabox commented 9 years ago

Seems to be working alot better now. (with the smaller noise) I look forward to more stuff in the Q section. Til then I may have to find another book (It always good to cross read, in any case).

rlabbe commented 8 years ago

I don't think there is anything actionable remaining. I've heavily revised the math on designing Q.