# Kalman Filtering: Part 2

By , 9 Oct 2012

## Introduction

This is a sequel to the previous article on Kalman filtering, and can be thought of as a more elaborate and more useful example. Kalman filters do a particularly good job of adaptively removing noise from a signal with as little distortion as possible. This example is for 2D navigation using a GPS and an inexpensive accelerometer.

Suppose you wanted to mow the lawn, or have a robot drop off a letter, or navigate very accurately off road. GPS provides inaccurate position and velocities (2.5 m rms, 10 cm rms, respectively) and using position and velocity a 2D Kalman filter will improve things.

Using only GPS means at best the signal to noise improves by averaging (sqrt(1/n)) and at 5 to 10 Hz the accuracy degrades rapidly with course changes. GPS also will “jump” in location as different satellites are periodically chosen to be added / removed from the solution. This jump is sometimes 10-15 meters. The velocity from GPS (computed from Doppler) has less noise, and “jumps” less when the satellite constellation changes.

The solution is to add another data source. There are several accelerometers available that can measure the linear acceleration. Simply put, they provide the rate of change in velocity, and after a coordinate transform, an do so in the same coordinate space as the GPS. In addition to a linear accelerometer, an angular with a second GPS would provide the course and further refine the solution, but for this example a linear accelerometer should be sufficient for a dramatic improvement. Relying only on the accelerometer causes a drift as noise and round off integrate.

The ideal thing about the accelerometer is the noise is small (0.002 m rms), it can be measured rapidly (1Hz – 5kHz), the errors are Gaussian (average out) and the error sources are completely different than GPS. Because there is no connection in noise source, the accelerometer and GPS error sources tend to cancel out.

## Requirements

Assuming we can get decent HW (below are very available HW specs at reasonable prices).

```GPS                2.5 m rms, 10 Hz
Accelerometer      2 mm rms, 1 kHz```

Operational goal:

`Goal               <25 cm rms for low dynamic movements`

## Design

The source code could have used a 3D Kalman filter (position, velocity, acceleration) but there is no real correlation between the GPS and the acceleration. It is simpler to use two filters and optimize each separately. One filter computes the velocity as a 2D Kalman (velocity, acceleration) such that the GPS Doppler is smoothed / corrected by the acceleration measurements. A second filter takes the highly accurate velocity information and filters in position. To get this to work in the horizontal plane, two filters for X (position, velocity) and two for Y (position and velocity) were used.

The test scenario is accelerating from a stop, cruising, slowing down, rotating, slow to stop, then start up and cruise back.

## Conclusion

The stock coefficients provided yield good accuracy balanced with good responsiveness: once acceleration is detected it immediately helps shift the position, the GPS slowly corrects against drift. I’m hoping to use this for a robots project in the future, and I’m hoping it helps others out there.

## About the Author

 HoshiKata Software Developer (Senior) KMC Systems United States Member
Phil is a Principal Software developer focusing on weird yet practical algorithms that run the gamut of embedded and desktop (PID loops, Kalman filters, FFTs, client-server SOAP bindings, ASIC design, communication protocols, game engines, robotics).

In his personal life he is a part time mad scientist, full time dad, and studies small circle jujitsu, plays guitar and piano.

Add a reason or comment to your vote: x
Votes of 3 or less require a comment

## Comments and Discussions

Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
 Search this forum Profile popups    Spacing RelaxedCompactTight   Noise Very HighHighMediumLowVery Low   Layout Open AllThread ViewNo JavascriptPreview   Per page 102550
 First Prev Next
 Awesome Article - Thankyou David Shields 11 May '13 - 23:50
 Re: Awesome Article - Thankyou HoshiKata 12 May '13 - 4:10
 Re: Awesome Article - Thankyou David Shields 12 May '13 - 15:17
 Re: Awesome Article - Thankyou HoshiKata 12 May '13 - 16:39
 Re: Awesome Article - Thankyou David Shields 13 May '13 - 0:47
 Re: Awesome Article - Thankyou David Shields 14 May '13 - 23:58
 Filtering without accerelometer Member 2601513 19 Dec '12 - 6:30
 Re: Filtering without accerelometer HoshiKata 19 Dec '12 - 6:41
 Re: Filtering without accerelometer HoshiKata 22 Apr '13 - 11:49
 real example Stephan Brunner 20 Nov '12 - 9:19
 Hi HoshiKata!   Great work. I would give this definitly a try. Can you post an example. How this can be used with real data. The code is very complex.   Thx   Stephan   P.S.: Precondition:   accelerometer values and gps values have 1 hz Sign In·View Thread·Permalink
 Demo with Kalman3D ? x893 5 Nov '12 - 0:02
 Re: Demo with Kalman3D ? HoshiKata 7 Nov '12 - 13:48
 Re: Demo with Kalman3D ? HoshiKata 22 Apr '13 - 11:50
 Can't download the zip file either ? BigAlBuchanan 8 Oct '12 - 14:23
 Re: Can't download the zip file either ? HoshiKata 9 Oct '12 - 6:15
 The zip file cannot be downloaded wvd_vegt 3 Oct '12 - 0:41
 Re: The zip file cannot be downloaded HoshiKata 9 Oct '12 - 6:15
 Last Visit: 31 Dec '99 - 18:00     Last Update: 21 May '13 - 15:24 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Rant    Admin

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 9 Oct 2012
Article Copyright 2012 by HoshiKata