Quote Originally Posted by HankMcSpank View Post
It must be cos I suck at maths, but I've read that a few times & it's not sinking in. Can I use an example here to how that works in practise. Let's say six AtoD Samples are taken....

100
99
100
101
499
100

You said that your weighted average stops a spurious reading skewing the overall average...can you illustrate using those six samples how the 499 would be ignored?

Many thanks!
It will affect it, but only at 1/sample rate.
so, for a 10 sample example, assume the running average = 100
100 *10 (sample rate) = 1000 = sum of the samples

new value 101
101+1000 - 100 = 1001
ave = 1001/sample rate = 100.1 0r 100 for PBP (rounds down)

new value 99
99+1001 - 100 = 1000
ave = 1000/sample rate = 100.0 0r 100 for PBP (rounds down)

new value 499
499+1000 - 100 = 1400
ave = 1400/sample rate = 140

new value 101
101+1400 - 140 = 1361
ave = 1361/sample rate = 136.1 0r 136 for PBP (rounds down)

far less than a (499 +100)/2 = 300

to filter the 1st bad sample add the lines (or similar)
if incoming > ave*10/9 AND if incoming < ave*10/9 then bad_count = 0
if (incoming < ave*10/9 OR if incoming > ave*10/9) AND bad_count = 0 then bad_count = 1
if (incoming < ave*10/9 OR if incoming > ave*10/9) AND bad_count = 1 then bad_count = 0

if bad_count = 0 then gosub average
if bad_count = 1 then Skip average routine

This (or similar) should skip the 1st out of whack signal