# Why do I need a Kalman filter?

I am designing an unmanned aerial vehicle, which will include several types of sensors:

• 3-axis accelerometer
• 3-axis gyroscope
• 3-axis magnetometer
• horizon sensor
• GPS
• downward facing ultrasound.

A friend of mine told me that I will need to put all of this sensor data through a Kalman filter, but I don't understand why. Why can't I just put this straight into my micro controller. How does the Kalman filter help me about my sensor data?

## 5 Answers

You do connect all these sensors directly to a microcontroller. The Kalman filter is not an electronic filter like a LRC filter that goes between the sensors and the microcontroller. The Kalman filter is a mathematical filter implemented as software routine inside the microcontroller.

The sensors you have listed give the microcontroller 14 or 15 raw numbers each time they are all updated.

When I fly a little aircraft, what I really want to know is its position and orientation and how far it is above the ground -- 7 numbers.

I need something that gives me those 7 numbers.

Ideally I want a new estimate of those 7 numbers every time through my control loop. The once-per-second updates I get from my cheap GPS aren't nearly fast enough. (People at What frequency does my quadcopter output-sense-calculate-output update loop need to stay stable? are telling me even 50-times-per-second isn't going to be fast enough).

Somehow I'm going to have to reduce those 14 or 15 raw numbers that I have, some of which only occasionally get updated, into (estimates of) the 7 numbers that I really want.

As Josh pointed out, there are many ad-hoc ways to convert those raw numbers into usable data. Any routine that converts 15 numbers into 7 numbers can be described as a "filter".

You don't have to use the optimum filter. But you will use some kind of filter -- i.e., something that converts from the 15 numbers of raw data you have into (estimates of) the 7 numbers you really want.

The Kalman Filter is, in some conditions, the "optimum" filter, the best way of converting that raw data into the 7 numbers I really want.

It may take less work on your part to use a Kalman filter that someone else has already written and debugged, than to write some other filter from scratch, debug it, and keep adding stuff to it until it is usable -- a filter that will inevitably turn out to be sub-optimum.

The short, snide answer is "try it without one." The better answer is an example: When your accellerometers say you are 10 degrees from vertical, but your gyro says you haven't rotated away from vertical, and your magnetometers are reporting a 30 deg offset from north but your gyro says 32 degree ... what is the current heading and tilt?

You'll probably come up with a million ad-hoc ways which seem to work in one example, but fail in others. The Kalman Filter (Extended Kalman Filter (EKF) for this task!) will provide for you a rigorous way to answer these questions. The quality of the answers is still being researched--though the EKF's track record is very good--but at least everyone will agree what the answers are.

• Exactly the answer I was looking for. "What would happen if I don't use Kalman Filter". Thanks! Mar 29, 2014 at 0:04

Sensor data is noisy. If you do not filter it, then your vehicle would at least act erratically if it were even stable enough to fly. Filtering, via a Kalman filter or otherwise, can reduce the noise when done correctly, improving stability in turn.

A Kalman filter is a particularly powerful filter. It takes a model of the system and noise models for both the system and your sensors. It then estimates the state of the vehicle based on a provided state estimate and the controls applied at any moment in time. This estimated state will be more accurate than what the sensors report.

You could use particle filters as well. For the basic intro to Particle Filters, you could have a look at Professor Thrun's videos in Programming a Robotic Car.

http://www.youtube.com/watch?v=H0G1yslM5rc

http://www.youtube.com/watch?v=QgOUu2sUDzg

Particle filters are more robust and have a far lesser probability of the loop closure error, which commonly occurs while implementing an EKF.

The videos describe the functioning of a particle filter.

• Generally, answers which contain not more than a link aren't preferred. If you could write a paragraph or two on the gist of the video, that would be nice.. Nov 20, 2012 at 6:52
• speak for yourself. I see little gain by restating information in another link. The link may contain information I was not aware of and someone does not need to retype it to make me aware of it. I can click and read very easily, thank you. Nov 24, 2012 at 6:08

A Kalman Filter is an algorithm that is commonly used in UAVs to fuse multiple sensor measurements together to provide an "optimal" estimate of the position and/or orientation of the UAV. For example, a Kalman Filter can fuse accelerometer, gyro and magnetometer measurements with a velocity estimate to estimate the UAV's yaw, pitch and roll.

For more information on the sensors and algorithms used in UAV state estimation, try the stand-alone article Fundamentals of Small Unmanned Aircraft Flight.

The article also links to accompanying Matlab code implementing the described Kalman Filter UAV state estimation algorithms.