# How to model unpredictable noise in Kalman Filter?

Background:

I am implementing a simple Kalman Filter that estimates the heading direction of a robot. The robot is equipped with a compass and a gyroscope.

My Understanding:

I am thinking about representing my state as a 2D vector $(x, \dot{x})$, where $x$ is the current heading direction and $\dot{x}$ is the rotation rate reported by the gyroscope.

Questions:

1. If my understanding is correct, there will be no control term, $u$ in my filter. Is it true? What if I take the state as a 1D vector $(x)$? Then does my $\dot{x}$becomes the control term $u$? Will these two methods yield different results?
2. As we know, the main noise source comes from the compass when the compass is in a distorted magnetic field. Here, I suppose the Gaussian noise is less significant. But the magnetic distortion is totally unpredictable. How do we model it in the Kalman Filter?
3. In Kalman Filter, is the assumption that "all the noises are white" necessary? Say, if my noise distribution is actually a Laplacian distribution, can I still use a Kalman Filter? Or I have to switch to another filter, like Extended Kalman Filter?

1. I would model this as a one-state system (x), with the gyro as the control input. The gyro noise becomes state input noise, the compass noise becomes measurement noise. So your system model becomes $$\hat{\dot \theta} = \omega_{gyro} + w$$ $$\hat y = \hat x$$ where $\hat y$ is the filter's estimate of direction, which you compare to the compass direction to get your Kalman update.
2. The magnetic distortion is going to be difficult, because if you sit in any one place it will appear as a constant offset term -- the Kalman filter won't deal with this well. I'm pretty sure you'll either need to map the distortion, get some second absolute direction reference, or just accept the distortion.
3. You are confusing spectral content with probability distribution. If the noise is white, then each sample in perfectly independent of any other sample. If the noise is Laplacian, each sample obeys the Laplace distribution. Kalman filters don't like colored noise (but you can deal with that by adding states). A Kalman filter is only the overall optimal filter when the noise is of Gaussian distribution and the cost function is sum-of-squares. For any other noise and cost function, the optimal filter is probably nonlinear. But for any zero-mean, white noise and sum-of-squares cost function, the Kalman filter is the best linear filter to be found.

(Note that the system model I gave ends up with a pretty trivial Kalman filter -- you may be better off, if you can't find some other means of estimating compass offset, using a complimentary filter to combine these two sensor inputs. Doing all the Kalman computations will just end up coughing up a complimentary filter anyway, and chances are that you'll have enough guesses for your constants that you may as well just guess at the crossover point in a complimentary filter and be done with it).

(Note, too, that if you have some absolute position reference, and some means estimating speed, and a vehicle that always goes in the direction you point it, that you can use an extended Kalman filter very profitably to correct the compass distortion by using the direction it actually moves to correct for the compass direction).

Optimal State Estimation by Dan Simon, Wiley 2006, is -- in my opinion -- a very rich and clear treatment of the subject of Kalman filtering and its more sophisticated brethren (H-infinity, extended Kalman, unscented Kalman, and even a bit on Baysian and particle filtering). It won't tell you how to apply that to navigation problems like this, but where would be the fun in life if all the problems were solved?. If you can't follow the math in Simon's book, then you should probably be asking yourself if you're going to be able to apply a Kalman filter in any sort of intelligent way.

• +1 For complementary filter for this application seems more suitable. Also the Dan Simon book is very good. This article is a good introduction to the Kalman filter (by the same author) masys.url.tw/AU/2013SP/OpenCV/0513/kalman-dan-simon.pdf – ddevaz Aug 20 '13 at 19:14
• @ddevaz Yeah, I am actually NOW implementing a complementary filter. But the problem is that it does not yield very good results. So I am thinking about switching to another "more sophisticated" filter... – Sibbs Gambling Aug 21 '13 at 1:40
• I see. I've edited my answer to include some reference material on Kalman filter implementation with gyros, accelerometers, and a magnetometer. – ddevaz Aug 21 '13 at 15:51
1. There will be no control input term. You should take (x, xdot) as your state vector to formulate the Kalman filter properly.

2. The primary sources of noise are the compass and the gyroscope. The gyroscope noise and drift are significant. It is pretty challenging to overcome magnetic distortion in general but there are compensation techniques.

3. The assumption of zero mean multivariate normal distribution noise is necessary however white noise is only a special case of this. For the extended Kalman filter, this assumption still needs to be true. You can look into other types of filters (particle filter, unscented Kalman filter).

Kalman Filter Design/Implementation Paper:

Implementing a Sensor Fusion Algorithm for 3D Orientation Detection with Inertial/Magnetic Sensors

• So I cannot leave the KF to handle the unpredictable magnetic distortion right? I should sort of discard the distorted values first and then leave the KF to deal with the sensor noise. Right? – Sibbs Gambling Aug 21 '13 at 1:44
• Yes. The Kalman filter won't be able to accurately compensate for the magnetic distortion because the changes could be drastic. I would try and implement some magnetic compensation first then implement the Kalman filter. – ddevaz Aug 21 '13 at 15:45