# Alternatives to Kalmam Filter

I am currently working on a self balancing robot project. I am going to use a MPU6050 to get data from both the accelerometer and the gyroscope. Since I need to get accurate data in a very small amount of data I need to filter the raw data I get. So many people have suggested me to use the Kalman Filter but I could not comprehend it (the maths behind it). Are there any other types of filters I can use in my project?

• A complementary filter can sometimes be used in these situations.
– Paul
Feb 15, 2017 at 22:14
• So you've giving up one of the best filters (i.e. it is an optimal filter ) that ever been invented just because you don't understand its math?! I don't agree with your logic yet the math of Kalman is trivial. You don't need to understand its derivation though. Feb 16, 2017 at 14:23
• @CroCo you are right. But I just could not find a source that explains it well for me to comprehend. I have checked many websites. All I want to know is what I should do with the data I get from mpu.
– Huzo
Feb 16, 2017 at 14:25
• Applied Optimal Estimation by Gelb is a good practical book. Feb 16, 2017 at 14:26
• You don't need any sensor fusion algorithm if you have already the attitude from a sensor fusion library. The Kalman filter could be used, if you want to get (Yaw, Pitch, Roll) from (GyroX, GyroY, GyroZ, AccX, AccY, AccZ). Feb 19, 2017 at 9:49

A good choice for sensor fusion with the MPU6050 is a second order complementary filter, which I used for the orientation estimation in a project. The complementary filter is computational cheap and so a good choice for a microcontroller. A paper about the implementation you can find here:

Particle filters (epecially in Monte Carlo localization) always seemed easy to intuitively understand to me. You basically simulate bunch of possible states of your robot, rank them with probabilities and occasionally you throw away the improbable ones.

There's obviously more to it (and more math), but this should be enough to make a small working test.

• Will check it out!
– Huzo
Feb 16, 2017 at 9:52
• are you saying that a particle filter should be used to estimate the pitch of the robot? Feb 20, 2017 at 0:49
• Should? No. It's just another tool. Particle filters could be used to estimate it. They would likely end up slower than comparable Kalman filter, but they can handle more complicated inputs and are really dead simple to visualize.
– cube
Feb 20, 2017 at 21:04

Check this website pratical approach to kalman filter it will give you a comprehensive description of kalman filter for a balancing robot (like yours) both theoritical and pratical (you have the code as well). And it runs on an Arduino !

Want to get orientations from accelerometers and gyroscopes?

Use the Madgwick filter.

From the paper, "Results indicate the filter achieves levels of accuracy exceeding that of the Kalman-based algorithm."

As @CroCo mentioned, the Kalman filter is the optimal estimator.... for a linear system signal in the presence of zero-mean, Gaussian noise. Accelerometers and gyroscopes have a non-zero bias, and they also experience bias drift which means that, even if you could measure and offset the bias, the bias isn't stable and changes over time.

The Madgwick filter is free, and even better, there are already efficient implementations of the filter already written in C, C#, and Matlab. You can learn the math if you want, but again the math has already been done and the finished product - the filter - is free to download and use.

There is an alternative to the Kalman filter that allows you to specify the performance of the filter using traditional filter specifications like the bandwidth (instead of covariance matrices).

It has the same structure as a Kalman filter, but in place of an static gain $$K$$, it uses a full filter $$F(s)$$.

The link implements it in an interactive jupyter notebook while explaining its properties, so even if you don't understand the math, if you can read Python, you'll get the grasp of it.

New contributor
PidTuner is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.