??? 08/27/08 12:13 Read: times Msg Score: +1 +1 Good Answer/Helpful |
#157793 - For your application... Responding to: ???'s previous message |
For your application it sounds like a rolling average filter is just what you need.
In rolling average filter you keep last N samples in an array and an index to the array pointing to the oldest value. You also keep a variable that is the running sum of all the sample values in the array. Using a nice uniform time spacing (I use a timer interrupt) you take an A/D reading and perform the following steps. - Subtract oldest reading in array from running sum value. - Add newest sample value into running sum value. - Place newest sample value into array over oldest value. - Advance the index of array to next oldest array element taking wrap around into account. - obtain running average by dividing the running sum by the number of elements in the array. Things to keep in mind with this scheme. o Make sure the running sum variable has enough bits to hold the sum without overflow. o Make the array an even power of two number of elements so the process of obtaining the running average is a simple right shift. o With a power of two array size the index overflow management can be handled with a simple AND of the index with a (2^N)-1) mask. To use this to be more favorable to filtering noise versus smoothing the longer term average of the signal make the number of samples on the array a smaller amount OR change the timer interrupt rate. I have seen applications where noise filtering is done in a somewhat simpler manner. At the timer interrupt, instead of using the filter array simply take four or eight A/D readings in a fast loop and add then together and divide by 4 or 8. This scheme filters noise that is of the "digital noise" variety that rides on your analogue value. In all of these schemes you have to be aware of the effects of anti-aliasing that can occur if you sample the signal too slow compared to the time rate of change of the signal (i.e. the signal frequency). Most often I design systems with discrete components in the circuit selected to perform signal anti-alias filtering. Michael Karas |
Topic | Author | Date |
Integrate decimate... | 01/01/70 00:00 | |
Strength reduction | 01/01/70 00:00 | |
>> = Divide and << = Multiply | 01/01/70 00:00 | |
Decimating | 01/01/70 00:00 | |
I have also used this approach | 01/01/70 00:00 | |
Thought process in frequency domain.. | 01/01/70 00:00 | |
Low-pass filter | 01/01/70 00:00 | |
Low pass filter selection... | 01/01/70 00:00 | |
Sample a longer run at high frequency and analyse | 01/01/70 00:00 | |
Good suggestion | 01/01/70 00:00 | |
For your application... | 01/01/70 00:00 | |
Rooling average concept... | 01/01/70 00:00 | |
Moving Average Filter = Rolling Average Filter | 01/01/70 00:00 | |
General concept vs. specific algorithm. | 01/01/70 00:00 | |
Correlated and uncorrelated noise | 01/01/70 00:00 | |
Your language ... | 01/01/70 00:00 | |
'Synchronous'? | 01/01/70 00:00 | |
Similar but not identical meaning | 01/01/70 00:00 | |
Yes, sounds waayyy better...![]() | 01/01/70 00:00 |