Shop OBEX P1 Docs P2 Docs Learn Events
Analog sensor filtering algorithms — Parallax Forums

Analog sensor filtering algorithms

Joshua SiegelJoshua Siegel Posts: 51
edited 2006-10-21 00:43 in General Discussion
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

Comments

  • pjvpjv Posts: 1,903
    edited 2006-10-19 02:49
    Joshua;

    It all depends on impedances and frequencies.

    Why not filter in software ?

    Cheers,

    Peter (pjv)
  • Joshua SiegelJoshua Siegel Posts: 51
    edited 2006-10-19 23:09
    I guess that's really what I'm asking - what are some simple, but effective, measures to improve accuracy of ADC readings?
  • pjvpjv Posts: 1,903
    edited 2006-10-19 23:34
    Hi Josh;

    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)
  • Joshua SiegelJoshua Siegel Posts: 51
    edited 2006-10-20 22:55
    Thank you Peter,
    I implimented a quick version of this and so far, it seems to do a lovely job of stabalizing my results.
  • Steve JoblinSteve Joblin Posts: 784
    edited 2006-10-21 00:43
    One idea is to take a bunch of readings and apply a bubble sort filter (a simple comparison based algorithm, that compares each item with adjacent one, swapping their orders if required. This causes larger values to "bubble" to end of the list) where you can then eliminate the top and bottom values, then average the remainders.
Sign In or Register to comment.