Hi Folks,
Darrel, am I doing something wrong here with your math example?
When I substitute 350 for Direction and 20 for Sample (a compass difference of 30 resulting in an average of 5) I get:
Direction VAR WORD ; Holds the Averaged wind direction
Sample VAR WORD
AvgCount CON 3 ; Number of samples to average
; Get New Sample here 0-359
If (Direction > 270) AND (Sample < 90) then
Sample = Sample + 360
; so Sample now 380
else
if (Direction < 90) AND (Sample > 270) then
Direction = Direction + 360
endif
endif
Direction = ((Direction * (AvgCount-1) + Sample) / AvgCount) // 360
; becomes
= ((350*(3-1)+380)/3)//360
= ((350*2+380)/3)//360
= (700+380/3)//360
= (1080/3)//360
= 360//360
= 1
; and if swapped so Direction is 20 and Sample is 350
; then Direction now 380
; becomes
= ((380*(3-1)+350)/3)//360
= ((380*2+350)/3)//360
= (760+350/3)//360
= (1110/3)//360
= 370//360
= 1
Or am I missing something obvious..? Math is not my strong point
Cheers,
Bill
Bookmarks