Kalman filter revisited

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all:

Today my company had released my first fully developed project, an ultrasonic level controller.

While I was developing the firmware for this project (with an ATmega64), I was looking for a filter that could discriminate false echoes. First I thought to develop some kind of 'prediction' about where it should be, and if the measured echoes go out for a certain amount, then discard them.

Later, I found the Kalman filter, and I liked it, since it seems to lay about similar concepts: there is still no 'teletransportation', so anything that has some mass can move too far from it's later position. Also, under usual circumstances, it's speed also can change too much (rockets and crashes included), depending on sample rate.

For certain timing constraints I couldn't try Kalman filter, so I only implemented my original idea. But this week, I tried it, retrieving data at 2Hz rate from one of my prototypes in a noisy environment. It lays over my desk, looking towards the wall, aobut 4.90 m away, and with cold air from the air conditioner blowing trhough the 'ultrasonic beam'. This gives me a big amount of noise that dissapear if I shut off the air conditioner.

To simplify my first test, I modeled the 'process' (the wall position) as a constant one, giving me a pretty simple Kalman filter (black line). Also I use the same FIR filter (32 points low pass) that I use in the final product (red line), while the prototipe only gives me 'real readings' (blue line). Then I feed the output of the filter to itself, obtaining the 2* FIR filter (green line). Also I add a simple 5 points IIR filter (dark green) just to test.

Initialization of all filters is not well done, but results are evaluated much later.

At the bottom text boxes (all data is processed by a C# application) it writes the mean on the top one (except the true readings), and on the bottom one, it writtes the standard deviation of the last 128 points. FIR filters give a nice line, but its stadistical results are not the best, and also are slow for small movements.

Also I attached the C# code for this Kalman filters. Only 4 variables (can be reduced to 3), 3 adds, 2 substractions, 2 mult's and 1 division. Not too much job. :shock:

private float Kalamar(int val)
{
float aux;

K = P/(P + 64); //1 es sa variança estimada d'es renou de lectura
aux = Lestim + K*(val-Lestim); //correció 'meas update' a partir d'es nou valor
P = (1 - K)*P; //Correció d'es renou de predicció

Lestim = aux; //Predicció 'a priori estimate' per 'time update'
P = P + 0.1f; //Predicció d'es renou de procés. 25 es sa variança estimada de procés.

return aux;
}

Compare to the resources needed by a 32 points FIR filter. Seems that Kalman filter had passed this first round. Next one will be try to model a 'second order' one with speed in the state space to see if step response is faster. Right now, step response is fast only for steps within standar deviation, for steps bigger, response lays between 32 point FIR and 2* 32 point FIR.

If somebody has some experience, I will be glad to know.

Guillem.

Attachment(s): 

Guillem.
"Common sense is the least common of the senses" Anonymous.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yow. They all look like they're all over the place. How about synthesizing an input signal consisting of a tri wave with noise, and seeing how close these filters can bring back the tri wave? (known input signal).

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, in fact I thought what you say, and I will try also when I would have time. Probably next week. Anyway, as I could see, seems that if Kalman filter is modelled for a constant voltage, then it will be slow. Then probably I will try first to model one for constant plus linear moving (ie. filling the tank at a constant rate) and then test all filters (also constant and linear Kalman ones) under trhee or four waveforms: step, ramp, single sinusoid and complex sinusoid.

Also I have planned a nice experiment: put the ultrasonic transducer on my balcony, aiming my swimming pool, and then going to swim a little. If it doesn't work, at last I wouldn't be hot...

I will post results when I have them and try to figure more accurately how Kalman filter works. Also will be interesting trying to use it with inertial platforms (like the ones Bob had made) and/or positioning system for some small robot. But right now this will be future plans only.

Guillem.

Guillem.
"Common sense is the least common of the senses" Anonymous.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi:

After a while, I could spend few minutes more to try Kalman Filters, but not too much. This time I only tested step response with not too much noise on the system (air conditioner turned off). I had tested the system with exactly the same conditions of the first post, but in this case, I had changed only one value in the kalman filter between both step tests. This is the measurement noise variance. In the first one is 64 (K=P/(P+64) while in the last one is 1. See the results how the 'slew rate' changes.

Changing this value, makes the filter to trust more the measurement, so the noise inmunity gets worse with its figure setted to 1. So, to improve the speed of response, the filter should have modeled some kind of it, while the actual model 'looks' for a fixed value.

I will try to see this response with some noise added (not as much as before, but more than now), and also with senoidal waves also. I hope to do tomorrow.

Guillem.

Attachment(s): 

Guillem.
"Common sense is the least common of the senses" Anonymous.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now 2010 :lol:

Dear, Guillem, what initial values for variables:
K, P, Lestim ?