# 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?

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 accelerometers 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! Commented 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.