6

I am trying to develop motion detection application for Android. App should be able to track motion of phone in space and map it to motion on computer screen. I am using 3-axis accelerometer and since data is very noisy I am using Kalman filter.

Internal state is 6 component vector [speed-x, speed-y, speed-z, accel-x, accel-y, accel-z] and measured state is 3 component vector [accel-x, accel-y, accel-z].

Filter works very well on measured values, but speed is still very noisy.

Plotted values

Now I am wondering if this is normal behavior or am I doing something wrong, since my understanding of Kalman filter is very basic. I am using JKalman library and following state-transition matrix (dt is 1/15 which is approximate sensor refresh rate)

double[][] A = { { 1, 0, 0, dt, 0, 0 }, { 0, 1, 0, 0, dt, 0 }, { 0, 0, 1, 0, 0, dt }, { 0, 0, 0, 1, 0, 0 }, { 0, 0, 0, 0, 1, 0 }, { 0, 0, 0, 0, 0, 1 } };

I have also set up my own covariance matrices with covariances calculated from test data. This improved acceleration signal a bit, but had no effect on speed.

Currently I am able to achieve stdvar

[0,0632041857 0,0607274545 0,0886326602] for speed [x, y, z]

[0,0041689678 0,004423822 0,0074808552] for acceleration [x, y, z].

I am quite happy with acceleration signal and I guess i cannot improve it much more, but I would love to improve quality of speed signal.

Andraz
  • 709
  • 2
  • 7
  • 16

2 Answers2

3

Won't work.

No matter what you do, the velocity will become extemely inaccurate in seconds. Although the answer at the above link is about position, the same holds for velocity. As for the Kalman filter see also here.

You should either try the GPS to get velocity or (if applicable) just use orientation of the phone in your app and give up on getting the velocity.

Community
  • 1
  • 1
Ali
  • 56,466
  • 29
  • 168
  • 265
  • Well, actually it is working pretty well, only problem are really slow and really fast movements (as expected). I need only relative movement (so I know it went left, right, up, down) and possibly magnitude of it. For speed problem I am using speed dumping (if there is zero acceleration applied, speed is multiplied by factor < 1.0 at each timestep, so it goes to zero pretty quickly). Anyway, thanks for the material, I will take a look at it ASAP, seems interesting. – Andraz Feb 11 '12 at 19:29
  • @Andraz Interesting. So you do not need accurate velocity. Then what you describe can work. Well, good luck anyhow! – Ali Feb 11 '12 at 21:22
2

I don't know much about Kalman filters except what I just read on Wikipedia, but I would say you are trying to apply Kalman filters in an inappropriate way.

The stdvars should represent only the noise, but I doubt that is what you computed. But more fundamentally, I think you lack some input data: Kalman filters are used when you have many different inputs, e.g. accelerometer + GPS.

It seems impossible --with Kalman or anything else-- that you could read in noisy accelerometer input and somehow get a smooth accurate trajectory. You could always do some kind of time-averaging of the accelerometer data, which would give you a smooth trajectory, but the trajectory would be different from the actual one. (If you want to try time-averaging: for example, a_smooth{i} = 0.6 a{i} + 0.3 a{i-1} + 0.1 a{i-2}.)

And there is the bigger problem that the precision of the accelerometer is very poor and you probably can't do much with it, especially keeping track of position, as answered by @Ali.

EDIT: I found some references on the web that have similar equations to yours, however those were for a Kalman filter used on a model with constant acceleration, which is obviously not what you want.

toto2
  • 5,306
  • 21
  • 24