What is process noise? Consider the motion of a thrown ball. In a vacuum and with constant gravitational force it moves in a parabola. However, if you throw the ball on the surface of the earth you will also need to model factors like rotation and air drag. However, even when you have done all of that there is usually things you cannot account for. For example, consider wind. On a windy day the ball’s trajectory will differ from the computed trajectory, perhaps by a significant amount. Without wind sensors, we may have no way to model the wind. The Kalman filter models this as process noise, and calls it Q.
Astute readers will realize that we can inspect the ball’s path and extract wind as an unobserved state variable, but the point to grasp here is there will always be some unmodeled noise in our process, and the Kalman filter gives us a way to model it.
Designing the process noise matrix can be quite demanding, and we will put it off until the Kalman math chapter. In this chapter we will focus on building an intuitive understanding on how modifying this matrix alters the behavior of the filter.
We think of the the underlying system as behaving as f (x) = Fx + w
where Fx is the state transition and w is the process noise. In other words Fx is the ‘true’ behavior of the process as we understand it, and w is things like winds, control surface fluctuations, maybe circuit noise - whatever affects our process that is not modeled.
Recall what happened to our variance when we performed the predict step in the Discrete Bayes chapter and the Kalman Filter chapter. Because we are predicting forward in time we lose some certainty about the state. In the Discrete Bayes chapter we used this code to implement that:
sigma = sigma + movement_sigma
That equation did not take the loss of knowledge due to the process noise into account. We can model the process noise as additional uncertainty, so we could write
In pseudocode we might express this equation as: sigma = sigma + movement_sigma + process_noise
In this chapter we do not have multiple state variables, so we have to use linear algebra to perform this computation.
In pseudocode we might express this equation as: P = project_forward(P) + process_noise
where P is the covariance matrix. The Kalman filter equation corresponding to this pseudocode is P = FPFT+ Q
In this equation FPFTis just some linear algebra ‘magic’ that projects P forward to the next time step, and Q is the process noise matrix. We are just adding matrices, so hopefully it is clear that each element in Q specifies how much uncertainty is added to the system due to the process noise.
We have not given the math for computing the elements of Q yet, but if you suspect the math is sometimes difficult you would be correct. One of the problems is that we are usually modeling a continuous system - the behavior of the system is changing at every instant, but the Kalman filter is discrete. That means that we have to somehow convert the continuous noise of the system into a discrete value, which usually involves calculus. There are other difficulties I will not mention now.
However, for the class of problems we are solving in this chapter (discretized continuous-time kinematic filters), where we can directly compute the state equations for moving objects by using Newton’s equations. For these kinds of problems we can rely on precomputed forms for Q. We will learn how to derive these matrices in the next chapter. For now I present them without proof. If we assume that for each time period the acceleration due to process noise is constant and uncorrelated, we get the following.
For constant velocity the form is
1 4∆t 4 1 2∆t 3 1 2∆t 3 ∆t2 σ2 and for constant acceleration we have
1 4∆t 4 1 2∆t 3 1 2∆t 2 1 2∆t 3 ∆t2 ∆t 1 2∆t 2 ∆t 1 σ 2
It general it is not true that acceleration will be constant and uncorrelated, but this is still a useful approximation for moderate time period, and will suffice for this chapter. Fortunately you can get a long way with approximations and simulation. Let’s think about what these matrices are implying. We are trying to model the effects of process noise, such as the wind buffeting the flight of a thrown ball. Variations in wind will cause changes in acceleration, and so the effect on the acceleration is large. However, the effects on velocity and position are proportionally smaller. In the matrices, the acceleration term is in the lower right, and this is the largest value. A good rule of thumb is to set σ somewhere from 12∆a to ∆a, where ∆a is the maximum amount that the acceleration will change between sample periods. In practice we pick a number, run simulations on data, and choose a value that works well.
The filtered result will not be optimal, but in my opinion the promise of optimal results from Kalman filters is mostly wishful thinking. Consider, for example, tracking a car. In that problem the process noise would include things like potholes, wind gusts, changing drag due to turning, rolling down windows, and many more factors. We cannot realistically model that analytically, and so in practice we work out a simplified model, compute Q based on that simplified model, and then add a bit more to Q in hopes of taking the incalculable factors into account. Then we use a lot of simulations and trial runs to see if the filter behaves well; if it doesn’t we adjust Q until the filter performs well. In this chapter we will focus on forming an intuitive understanding on how adjusting Q affects the output of the filter. In the Kalman Filter Math chapter we will discuss the analytic computation of Q, and also provide code that will compute it automatically for you.
For now we will just import the code from the FilterPy module, where it is already implemented. I will import it and call help on it so you can see the documentation for it.
In [37]: from filterpy.common import Q_discrete_white_noise help(Q_discrete_white_noise)