How does the Kalman Filter Works?

Hello Guys,

I've seen a lot of codes and videos, applying the Kalman filter. But I did not find an easy, and well explained text on this subject yet.

I got one question about this, as far I see people use accelerometer + gyros... Is there an way to apply Kalman's filter on a single 3 axis accelerometer?

Thanks in Advance,

Tony

Hello Antonio,

I have done a lot of research about Kalman filters recently and found many publications and papers on the Internet which I have downloaded.

Here is the link to the zipped documents. It´s about 43 MB:

http://dl.getdropbox.com/u/697605/Kalman.zip

Maybe there is a text that is interesting for you.

Paul

Hello Dude!

thanks for your reply... I tried the link but its broken...

thanks again,

Tony

Link works for me ....

wow, it works now... I guess it was bad luck... maybe site on maintenance or something....

thanks!

I also would like to say thanks. Even geman papers within. That helps a lot :smiley:

Need some weekends...

Hi - I will say right up - I really suck at maths :slight_smile: Also - I don't have anywhere near the grasp of Kalman that some of the other guys working on the Nunchuk/MP integration have.

But, from my lucid understanding.. if you want to smooth just an accelerometer, then... "This is not the filter you are looking for ".... :slight_smile:
It can work with just one input - but its a lot of work and Im not sure how much benefit it would bring to a single input versus iterative integrations of two.

This is all very lay terminology - so forgive me maths geniuses :slight_smile: Kalman smooths 'noisy' samples, and does that by integrating another set of samples from a sensor that is 'more accurate' over shorter times based on 'weighting' the results between the two.

The best example I can give is with the accelerometers and the gyro.

The accelerometers suffer very little drift over time compared to the gyro but are very sensitive, even at rest. Small movements can be lost. The Gyro's are very accurate in short bursts, but rapidly (compared to accelerometer drift) get distorted by drift... One could say the two sensors exhibit the complimentary behavior of each other.

So by using Kalman, we can predict an accurate result and cancel out noisy (i.e, not fitting within the prediction matrix for that particular sample ), thus smoothing the input from each and then combine the results to produce a set of very accurate numbers - using one sensor to cancel out the other sensors issues. In this instance, the Kalman wants to 'prefer' the gyro in the first instance, but as sampling continues, it wants to shift that weight to preferring the now more accurate accelerometer data. This produces a "smooth" plot of movement, without confusing plots based on 'noise' or 'drift' within each particular sensor. The hard part is tweaking those 'weightings' to produce smooth data - thats all the tuning that people refer to with Kalman. Not only the weighting of the integration, but also the weighting of the first stage of 'smoothing'..

One could also modify GPS data to interpolate with the accelerometers - I say modify because to the best of my knowledge, you need everything in the same "units of measure", thus you need to compute the acceleration between two GPS sample points and the Heading as discreet values and then use them to integrate in Kalman (i.e, you can't just plonk in the lat/lng and use that as an Int :slight_smile: )

If you haven't seen Tom Pykes excelent MAV-blog, then thats probably one of the more comprehensive explanations of how to apply Kalman filters to IMU's.. MAV-blog : Kalman filtering of IMU data

I'd love to have a better understanding of the actual Maths... but like I said originally.. I suck at maths ;D My apologies if I have really butchered this explanation....

Adr1an,

this is the best explanation so far... Thanks for taking your time and sharing this with us. =)

I think after reading and reading and reading... and going thru all the math, this is the most simple, and most compreensive text on Kalman filters I ever read.... and some times thats all we need :wink:

thanks for posting,

Tony

If you are looking for an intro to Kalman filters, this might also be useful (see also the entries on accelerometers and gyros):

http://tom.pycke.be/mav/71/kalman-filtering-of-imu-data

ive read your wonderful reply on kalman filter operation but one thing still bugs me though. from my understanding both the accel and gyro outputs should be converted to angles in order for them to be able 'smooth' each other out? the gyroscope is able to measure rate of rotation with respect to the 3 axes so from that you can get 3 'angles' of tilt. but from what ive read accels can only measure tilt in 2 axes. how will i be able to smoothen out the single remaining gyro axis?

It seems that interesting link is again down... Does anyone have a copy?
http://dl.dropbox.com/u/697605/Kalman.zip

Yikes scary maths!

I have successfully used the following algorithm to smooth a pulse monitor signal from a phototransistor connected to an analog pin, prior to determining the local max and mins to get the pulse rate.

I took it from the Apple iPhone example code for using the accelerometer, so I guess it might do the trick for you.

I believe its called lossy integration.

Adjust alpha for the level of smoothing.

#define alpha 0.8

void loop()
{
static double lastX = 0;
double newX = readAccelerometerX();
double smoothX = alpha * lastX + (1 - alpha) * newX;
lastX = newX;
// ditto for the other 2 axes
}

I found it to be very effective and within my limited mathematical grasp. I tried it all out in a spreadsheet first, then used captured data from the serial monitor to get the right value of alpha.

Hello Dude!

I tried the link but its broken...
M working on the 2 wheel balancing robot.. Please help in Kalman Filter Equations..

I found a nice Kalman Filter training software named 'Visual Kalman Filter'. Maybe it's helpful for you.

Good luck!