Analog sensor filtering algorithms
Joshua Siegel
Posts: 51
Hi,
I have a robot I am working on with a large number of analog sensors (sonar) onboard. They fire simulatenously, and are read once per loop.
The simultaneous firing seems to eliminate a good deal of noise picked up by the sensors, but the speed of reading seems to throw off the data I capture. I was thinking I could capture every other loop, but I'd still like to have some sort of filtering algorithm. Here is what I have considered:
Average two loops into one reading
Check to see if two consecutive values are within a certain distance from each other. If so, keep it, otherwise, sample until two consecutive samples are.
Would a low-uF capacitor be suitable to filter a bit of the noise? We're talking about 10-bit ADC's, but I only need accuracy to about .01V @ 10Hz.
Thanks,
Josh
I have a robot I am working on with a large number of analog sensors (sonar) onboard. They fire simulatenously, and are read once per loop.
The simultaneous firing seems to eliminate a good deal of noise picked up by the sensors, but the speed of reading seems to throw off the data I capture. I was thinking I could capture every other loop, but I'd still like to have some sort of filtering algorithm. Here is what I have considered:
Average two loops into one reading
Check to see if two consecutive values are within a certain distance from each other. If so, keep it, otherwise, sample until two consecutive samples are.
Would a low-uF capacitor be suitable to filter a bit of the noise? We're talking about 10-bit ADC's, but I only need accuracy to about .01V @ 10Hz.
Thanks,
Josh
Comments
It all depends on impedances and frequencies.
Why not filter in software ?
Cheers,
Peter (pjv)
A concept that I use (don't know if it has an official name) is a long term software averager. It works well for slow signals. Here is how it works;
Compare the new A/D reading to the Average.
Increment a counter if New is greater than Ave; decrement the counter if New is less than Ave.
When the counter rolls over (becomes zero) in a forward direction, increment Ave; if it rolls over in a negative direction, decrement Ave.
On any roll over, preload the counter to 128 ($80 hex, or "half full").
The result of all this is that a bouncing New reading will not be reflected in the Ave, and Ave only changes when it has averaged 128 more readings in one direction versus the other direction.
So the fastest Ave can change is if 128 consecutive increases or decreases occur. Hence an average of 128 readings.
If this is a little too slow, then make the counter smaller than 8 bits, and preload accordingly.
I use this method to measure fractions of millivolts directly (no amplifier used) off a 100 ohm RTD using a software 8 bit virtual A/D, and the results are rock stable. In fact, observing the value in the counter gives me the increasing/decreasing trend before the roll-over even happens.
Works great.
Cheers,
Peter (pjv)
I implimented a quick version of this and so far, it seems to do a lovely job of stabalizing my results.