# How to model the noise in Kalman Filter?

Background:

I am a newbie in DSP. 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?

## 2 Answers

1. You are most likely not having a control vector $u$. Maybe you can somehow model it into the filter, but it is not required in your case and uncommon. Furthermore $\overset{.}{x}$ is not your gyro input but it is the Kalman filtered rotation rate calculated after using all your measurements.

2. Usually, the main effects on a magnetometer are hard iron and soft iron effects. There is a lot of articles out there that describe the cause and how to mitigate those. I would probably do this in a preprocessing step and leave it out of the Kalman filter entirely. Furthermore, if you have some means to detect if you are in a strongly distorted field (e.g. because the absolute strength is going up), you can increase the measurement noise you report to the Kalman filter for those measurements. This will indicate to the filter to not trust the values coming from the magnetometer anymore. So if you know the total strength of the earth's magnetic field and you suddenly measure a much stronger field, you could use this technique. This is also commonly done with accelerometers to put less trust on values measured when the vehicle is actually accelerating and hence, the measurement is not pointing "down". See here for an example

3. Your noise has to be white and it has to be Gaussian or near Gaussian. You can only have correlation between the different measurements of one time step but not between multiple time steps. If you search around in the academic world, there are many papers presenting adapted Kalman filters for other noise types that work more or less well (see here for example, haven't tested this, though). EKF and UKF approaches don't help here, either. You use those, when you have a nonlinear system model. As already said, if your noise is very non-white and non-gaussian that you get big estimation errors, then a particle filter is an option.

• The noise need not be Gaussian. It must be Gaussian to be optimal in the MSE sense, but it is the optimal linear filter for non-Gaussian distributions. The Kalman filter only propagates the first and second moments which follow linearity for uncorrelated distributions which is why the linear assumption suffices. Better nonlinear estimators may exist (as you mentioned, particle filter). UKF also can accommodate non-additive noise into its framework. – Bryan Aug 20 '13 at 19:20
• Thanks for the answer. But 1. My measurements are simply gyro readings and compass readings. So how can I "calculate" the gyro input out of them. I mean what I measure is already the gyro input. How do I time-update it since the movement of the robot is completely UNPREDICTABLE? 2. So the magnetic distortions are not to be filtered by the KF. It is the sensor noise that is to be filtered by KF, right? 3. Could yu please illustrate some more details on particle filter? How do I build the movement model and observation model here? Thanks again! – Sibbs Gambling Aug 21 '13 at 1:32
• 1. There is a difference between gyro input and true rotation rate. The first is a noisy measurement of the latter. The rotation rate in the model is a result of fusing the gyro input and the magnetometer input (i.e. it makes sure that not only the gyro measures rotation rate but that these are also reflected in your magnetometer measurements), given a well modelled system. 2. It is up to you whether you model those distortions into the Kalman filter or not. However, they need to go to the model since they are not noise. I found it easier to mitigate them before the Kalman. – jan Aug 21 '13 at 8:46

Some quick answers:

1. You are correct; there would be no control term in your filter, unless you have some component on your robot (e.g. a motor) that is attempting to apply some known change to the robot's orientation. If you do have something like this, then you can add its contribution to your robot's orientation into the Kalman filter model pretty simply, and you should get better state estimates.

I would recommend reading the simple example on the Wikipedia page for Kalman filters, if you haven't already. It is a similar problem to yours, with a body undergoing one-dimensional motion (although it is linear), with the goal being to estimate the body's position and velocity versus time while only measuring its position. Yours is slightly different since you can measure the angular velocity also using the gyroscope, but it's a good starting point.

2. I'm not familiar with the physics underlying the effects of magnetic distortion on your compass, so I'm not sure what to recommend for that aspect of your problem.

3. Nitpick: it's possible to have non-white Gaussian noise. "White" noise just refers to a noise process whose realizations are all independent of one another. You could have non-Gaussian white noise, for example. Additive Gaussian white noise (AWGN) is a very common assumption, which is why you might think they go together.

Kalman filters inherently make the assumption that all noise processes are Gaussian, which often is a good assumption even when it's not strictly true. If your system is sufficiently non-Gaussian for KFs to not be a good approach, then something like a particle filter (which I have no real expertise with) might be able to help you.

• Just be wary: depending on how you obtain your bearing, $x$, the example on Wikipedia might not quite work. The main issue is that bearing is generally only valid between 0 and 360 degrees (or -180 to 180). The Wikipedia example assumes no such limitation. – Peter K. Aug 20 '13 at 20:56