> PTM: Q&D solution:
> TEMP = (TEMP + NW)/2
> This needs 8 bit + carry to handle 0..255 values.
> This function works if the sloshing makes small differences to both sides
> of the right one and the time period is rather short, about 1/20 sek.
>
> If this still give odd values, you can make even:
> TEMP = (TEMP + NV - TEMP/D)
> VAL =TEMP / D
> There TEMP is a 16 bit register for the summ
> NV = nev measured value (0..255)
> D is 2,4,8,16... (2^n) static
> VAL is the value that is shown in the display.
> This gives you totally wrong values from the first D*5 times (I tried
> this) but after that you get every time a bit better approximation.
> D is selected as a 2^n to get the program easier.
>
> You can even make a try with QBasic:
>
> '--------------------------------------------------
> '
PTMUSTA
spam_OUTUTU.FI
> 'Demonstrating running averages
> 'shareware ;)
> '--------------------------------------------------
> CLS
> NV = 3
> D = 4
> FOR i = 1 TO D * 6
> 'here we simulate random slosh
> NVU = NV + (RND(1) - .5) / 10
> 'running average value
> TEMP = (TEMP + NVU - TEMP / D)
> DISPLAY = TEMP / D
> PRINT i;"New=";NVU;"Displ=";DISPLAY;"err=";(DISPLAY-NV)/NV;"%"
> NEXT