How do I average/smooth Noisy Inputs
Archiver
Posts: 46,084
On the BSII project I'm working on I'm reading a number of inputs
from analog sources. These inputs will give data that is somewhat
noisy/variable, (temp, water lever and such). The real items I'm
measuring will also fluctuate over short periods but it's the average
or trend that I need to keep track of. No value could change in a
real way in less than a minute or so.
I'm sure that with some math this can all be taken care of. What is
everyones favorite way of averaging/smoothing this type of input be?
Just to make it a little more complicated I have 8 sets of 3
different inputs, a total of 24 variables.
Thanks for your help
Mike
from analog sources. These inputs will give data that is somewhat
noisy/variable, (temp, water lever and such). The real items I'm
measuring will also fluctuate over short periods but it's the average
or trend that I need to keep track of. No value could change in a
real way in less than a minute or so.
I'm sure that with some math this can all be taken care of. What is
everyones favorite way of averaging/smoothing this type of input be?
Just to make it a little more complicated I have 8 sets of 3
different inputs, a total of 24 variables.
Thanks for your help
Mike
Comments
Try putting a 75 ohm resistor in series with a .1ufd cap between ADC sensor
input and ground. Works for me.
Sid
>from analog sources. These inputs will give data that is somewhat
>noisy/variable, (temp, water lever and such). The real items I'm
>measuring will also fluctuate over short periods but it's the average
>or trend that I need to keep track of. No value could change in a
>real way in less than a minute or so.
>
>I'm sure that with some math this can all be taken care of. What is
>everyones favorite way of averaging/smoothing this type of input be?
>
>Just to make it a little more complicated I have 8 sets of 3
>different inputs, a total of 24 variables.
>
>Thanks for your help
>Mike
I agree with Newzed that an RC filter at the analog input could be
the simplest solution.
What do you mean by "8 sets of 3 different inputs"? The stamp has a
total of 26 byte variables in RAM. Any kind of averaging or
filtering is going to take a word-size variable for each average,
plus a couple of others for counters etc. The scratchpad RAM on a
BS2e, sx, or p could help with the memory crunch.
Either a fixed-time average or a low pass filter can be implemented
in software with one word variable per channel. Other filters like
the boxcar average or the median filter are more memory intensive.
There are some filter suggestions at this URL:
http://www.emesystems.com/BS2math5.htm
-- regards,
Tracy Allen
electronically monitored ecosystems
mailto:tracy@e...
http://www.emesystems.com
>the simplest solution.
>
>What do you mean by "8 sets of 3 different inputs"? The stamp has a
>total of 26 byte variables in RAM. Any kind of averaging or
>filtering is going to take a word-size variable for each average,
>plus a couple of others for counters etc. The scratchpad RAM on a
>BS2e, sx, or p could help with the memory crunch.
I guess an explanation here may have helped. This is part of an
automation system for a fish farm. The BSII will be watching water
levels, temps, and ammonia levels (the three different inputs) on up
to 8 tanks. Each tank is a stand alone system and needs monitored
separately.
As an example, I'm using an LM335 temp sensor into a ADC0838. The
LM335 has a 230ohm res with it then wire run to the ADC0838, the wire
runs are from 20' to 60' in length Cat5 cable. When I make a set of
reading say 10 reading in a row I will get numbers like this:
44,45,43,43,44,43,46,44,46,45
Now I know the temp hasn't changed that much each number should be
about 0.5 degrees C. Is this about what I should expect or is
something amiss. What I really don't want is false alarms in the
middle of the night because one reading in 10,000 was high by a
degree.
My plan was to just take a set of 10 readings at one time and average
them. Then check to see if it is within the good range if so dump the
variable and go on to test the next tank reusing the variable. If the
value is good I really don't need to know what it was.
Thanks for the link to the great information on your site.
Mike
>
>Either a fixed-time average or a low pass filter can be implemented
>in software with one word variable per channel. Other filters like
>the boxcar average or the median filter are more memory intensive.
>There are some filter suggestions at this URL:
> http://www.emesystems.com/BS2math5.htm
>
> -- regards,
> Tracy Allen
> electronically monitored ecosystems
> mailto:tracy@e...
> http://www.emesystems.com
>
>
>To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
>from the same email address that you subscribed. Text in the
>Subject and Body of the message will be ignored.
>
>
>Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
> >On the BSII project I'm working on I'm reading a number of inputs
>>from analog sources. These inputs will give data that is somewhat
>>noisy/variable, (temp, water lever and such). The real items I'm
>>measuring will also fluctuate over short periods but it's the average
>>or trend that I need to keep track of. No value could change in a
>>real way in less than a minute or so.
>>
>>I'm sure that with some math this can all be taken care of. What is
>>everyones favorite way of averaging/smoothing this type of input be?
>>
>>Just to make it a little more complicated I have 8 sets of 3
>>different inputs, a total of 24 variables.
>>
>>Thanks for your help
>>Mike
>
--
Pisani Graphics Inc.
Kimberly WI 54136
920-730-0014
The fish farm could be very noise-prone, particularly 60 hz pickup
near electric pumps and power lines. . The water can act like a big
antenna. That may explain the noise you are seeing as fluctuations in
the readings. Ground potential will be two different things at the
pond and at the data logger.
Shielded cable could help, with the shield connected at one end only
and with the shield extended around the sensor. The best result
would come by sending the signal over a twisted pair in the shielded
cat5 cable, the power over another twisted pair. Use the differential
input capability of the ADC0838ADC.
230 ohm
;
shield
| + -/\/\
+ power
|LM335
+ input
| - ;
- input
| `
- power
`
shield
The LM34 is an alternative to the LM335, because it has a higher
output signal (10mV/degree F versus 10mV/Kelvin). Or, another
alternative, a current mode sensor like the LM334 or AD590 might work
better than the LM335 here. Current mode sensors tend to be more
resistant to noise pickup, and the wiring is simpler. The ground can
be referred directly back to the data logger.
230 ohm
;
shield
| +
power
|LM335
;
+ input 10mV/K
| `--/\/\-;- - input
| 10k `--common
`
shield
Sensors like pH and NH3 electrodes are especially problematic,
because they must be in direct contact with the water.
On the stamp end, the simple average will help with the sampling
noise. There have been a couple of threads on computing averages in
the past month or so. BASICally,
avg var word
x var byte
i var nib
average:
avg=0 ' accumulator starts at zero
for i=0 to 9
gosub getdata ' byte from ADC, not shown
debug dec x,tab ' show it
avg=avg+x ' add to accumulator
next
avg=avg/10 ' average of 10 samples
debug dec avg,cr
goto average
-- best regards
Tracy Allen
electronically monitored ecosystems
http://www.emesystems.com
mailto:tracy@e...
> >I agree with Newzed that an RC filter at the analog input could be
>>the simplest solution.
>>
>>What do you mean by "8 sets of 3 different inputs"? The stamp has a
>>total of 26 byte variables in RAM. Any kind of averaging or
>>filtering is going to take a word-size variable for each average,
>>plus a couple of others for counters etc. The scratchpad RAM on a
>>BS2e, sx, or p could help with the memory crunch.
>
>I guess an explanation here may have helped. This is part of an
>automation system for a fish farm. The BSII will be watching water
>levels, temps, and ammonia levels (the three different inputs) on up
>to 8 tanks. Each tank is a stand alone system and needs monitored
>separately.
>
>As an example, I'm using an LM335 temp sensor into a ADC0838. The
>LM335 has a 230ohm res with it then wire run to the ADC0838, the wire
>runs are from 20' to 60' in length Cat5 cable. When I make a set of
>reading say 10 reading in a row I will get numbers like this:
>
>44,45,43,43,44,43,46,44,46,45
>
>Now I know the temp hasn't changed that much each number should be
>about 0.5 degrees C. Is this about what I should expect or is
>something amiss. What I really don't want is false alarms in the
>middle of the night because one reading in 10,000 was high by a
>degree.
>
>My plan was to just take a set of 10 readings at one time and average
>them. Then check to see if it is within the good range if so dump the
>variable and go on to test the next tank reusing the variable. If the
>value is good I really don't need to know what it was.
>
>Thanks for the link to the great information on your site.
>
>Mike
>
>
>
>>
>>Either a fixed-time average or a low pass filter can be implemented
>>in software with one word variable per channel. Other filters like
>>the boxcar average or the median filter are more memory intensive.
>>There are some filter suggestions at this URL:
>> http://www.emesystems.com/BS2math5.htm
>>
>> -- regards,
>> Tracy Allen
>> electronically monitored ecosystems
>> mailto:tracy@e...
> > http://www.emesystems.com
> > >On the BSII project I'm working on I'm reading a number of inputs
>>>from analog sources. These inputs will give data that is somewhat
>>>noisy/variable, (temp, water lever and such). The real items I'm
>>>measuring will also fluctuate over short periods but it's the average
>>>or trend that I need to keep track of. No value could change in a
>>>real way in less than a minute or so.
>>>
>>>I'm sure that with some math this can all be taken care of. What is
>>>everyones favorite way of averaging/smoothing this type of input be?
>>>
>>>Just to make it a little more complicated I have 8 sets of 3
>>>different inputs, a total of 24 variables.
>>>
>>>Thanks for your help
>>>Mike
>>
>--
>Pisani Graphics Inc.
>Kimberly WI 54136
>920-730-0014