I'm having some trouble implementing a Kalman filter in MATLAB. I have an Android phone connected sending data from accelerometer for 10 seconds. After i have the data I take out the x-axis vector. What I want after that is to get better readings using the Kalman filter.

The output I am looking for is both the acceleration and the velocity of the phone. When I run the code I get almost no change in acceleration (is between -0.5 and 0.5 m/s^2) and way to much change in velocity (increasing to very high numbers). The tests I have been running are when the phone is laying still on a table. So the correct values in acceleration and velocity should be 0.

The problem is that since i'm only measuring acceleration my state vector will be the same vector as the measurement vector with the only difference that i also have velocity in the state vector. Both the control input is the acceleration and the measurement is the acceleration.

So when I update my state vector the difference that is going to be multiplied with the Kalman gain is always zero.

So my question is: Should the measurement noise / the process noise be added to the measured acceleration "z" or should the noise be added to the state prediction vector?


If there is any offset in the acceleration measurement, then a Kalman filter won't help without the addition of some velocity and/or position reference measurements. Double integration of random-walk noise in the acceleration measurement will eventually lead to a reported position of your device outside the solar system.

  • $\begingroup$ So what you are saying is that i need some other way (other sensor(s)) to measure the velocity/position? How can i do that with an android phone. I only want to measure small movements so GPS can probably not be used. Is there any other sensor I can use: magnetometer, gyroscope etc. I only want to measure velocity in x and y axis and the accelerometer gives a noisy measurement going between about -0.5 and 0.5 m/s^2 when it is laying still on a table. Is Kalman filtering the way to go for correct measurements? $\endgroup$ – Kersch Apr 5 '14 at 1:16
  • $\begingroup$ You can see plots of the data and code here: stackoverflow.com/questions/22672256/… $\endgroup$ – Kersch Apr 5 '14 at 1:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.