Arithmetic mean

After a few runs with Ermis GR4 and the Cosm platform I found a little free time to make a small improvement at the computation of the measured battery voltage. Don’t expect anything complicated of sophisticated mathematical formulas. No, just an arithmetic mean!

With a sample space {ai, …, an}, the arithmetic mean will be:

Have in mind that the voltage is measured by the microcontroller with his internal 10bit ADC (yes, the LSBs are mostly noise and not valuable data at those voltage levels) by using a voltage divider. The voltage input of the divider (or the hot part as someone told me a few weeks ago) is the positive wire of the Li-Ion battery and the output is feeding the ADC. The circuit here is extremely simple. No OpAmp voltage followers (buffers), low pass filters of anything else.

At the firmware part the only things that changed since the previous version are a new function for the calculation of the arithmetic mean and the Cosm feed ID in order to post the data at a test section and not destroy the actual project that it is in progress now.

The arithmetic mean is calculated using five (second datastream), ten (third datastream) and twenty values (fourth datastream) of continuous voltage measurements. On top of that the first measured value is also posted at the beginning of the feed just for reference of what we supposed to have without the arithmetic mean.

And the results are like the above picture! At the points 1, 2 and 3 we are watching the transformation of the voltage graph by making use of this simple mathematical formula. At the point 4 we can see the elimination of the “noise” by measuring twenty values and computing the mean compared to just posting the first voltage read without any value manipulation.

And here is another interesting fact. Just look at the difference between the highest and the lowest voltage (the span in other words) for all of the four datastreams. I’ve also note with red color this difference for easy reference.

To be honest this screen capture is not showing the differences clearly. This is something at the middle of the gathered results. For example the 0.10V result is a little bit at the wrong side as it supposed to be smaller than the previous datastream. I happened to have just 0.05V at the last datastream and 0.190V at the first one. The theoretical voltage differences will drop as we increase the number of voltage values participating at our arithmetic mean, reaching to a flat value at something like 20+ values.

In other words if you want to use something so naïve as an arithmetic mean in order to “clean” a little bit your graphs do not waste your processor cycles (time and energy as well) by computing 20+ values. The results are not worth it.

Of course if you want a “correct” way to measure a voltage with accuracy then the hardware part should have at least a low pass filter together with OpAmps for impedance control or in general any good interface circuit between the voltage source (battery voltage, analog sensor output etc) and the ADC. At the software side a FIR filter will be just good enough…

And here is a screen capture showing a voltage discharge graph without an arithmetic mean at the left and with an arithmetic mean at the right. Pretty good results!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: