I would like to use a Kalman filter to estimate the height and vertical velocity of an object being moved up and down in an unknown way based on a noisy position measurement and a noisy acceleration measurement. The noise of each measurement is unrelated to the other measurement. I think/hope this sounds like a good use of a Kalman filter.
I am attempting to use the javascript library found here: https://github.com/itamarwe/kalman
I have read quite a bit about how Kalman filters work, I am just having issues trying to match matrices with what is in the library. Below is a list of the matrices used in the library that was posted to another question similar to this one along with my notes about what I think I should be using.
x - this is the vector that you try to estimate.
I think x will equal [position; velocity; acceleration]
P - is the covariance matrix of the estimation, meaning the uncertainty of the estimation. It is also estimated in each step of the Kalman filter along with x.
I would use [1,0,0 ; 0,1,0 ; 0,0,1], I probably know the starting positions and velocities really well though, so maybe these should be smaller.
F - describes how X develops according to the model. Generally, the model is x[k] = Fx[k-1]+w[k]. In your case, F might be the identity matrix, if you expect the angular acceleration to be relatively smooth, or the zero matrix, if you expect the angular acceleration to be completely unpredictable. In any case, w would represent how much you expect the acceleration to change from step to step.
I think F = [1,dt,dt2/2;0,1,dt;0,0,1] When you multiply x*F it would give you the next state if nothing changed. I am taking samples at 200hz, so I guess I would just substitute .005 in for dt.
w - describes the process noise, meaning, how much does the model diverge from the "perfect" model. It is defined as a zero mean multivariate normal distribution with covariance matrix Q.
I don't know what to use here. My model will be disturbed by an unknown external force moving the object. I have quite a bit of data on the range of accerlation/forces that will be applied. Is there a way that I should use that to make Q?
All the variables above define your model, meaning what you are trying to estimate. In the next part, we talk about the model of the observation - what you measure in order to estimate your model.
z - this is what you measure.
This would be [measured height, measured acceleration]. Quick question, if these measurements have different frequencies how that usually handled?
H - describes the relation between your model and the observation. z[k]=H[k]x[k]+v[k].
I think this should be [1,0,0 ; 0,0,1] because I measure position and acceleration.
v - is the measurement noise and is assumed to be zero mean Gaussian white noise with covariance R[k]. Here you need to measure how noisy are the accelerometers, and calculate the noise covariance matrix.
Not sure how to figure this out. I can find the standard deviation of each of my sensors, would R just be [stdevHeight,0 ; 0,stdevAccel] ? That is just a total guess on my part.
I hope that the very helpful ita is around to help out a bit.
Thanks a bunch,
Scott
Regarding your questions:
Q
- The process noise - Since the acceleration changes unpredictably from step to step, Q
should represent the standard deviation of the acceleration. I would use something like [0 0 0;0 0 0;0 0 sigma^2]
. You should try to use the data you have to estimate how much the acceleration changes from step to step.z
vectors, thus 2 different H
matrices to update your model. When an acceleration measurement arrives, you update your model with the H
matrix that relates to that measurement, and the same for the position measurement. In each step, dt
should represent the time since the last update of the model.R
seems right.