Math help - rolling average Wind Direction
Hi Members,
I need some advice on how to create a rolling 3 second average of wind direction.
So far: a sample is taken each second (AD count) and added/averaged until an interrupt causes the value to be sent serially at which time the values are reset and the cycle continues.
Basic enough but the problem arises where prevailing conditions see the wind coming from a Northerly aspect where one sample may be less than 359 degrees while the next (or previous) is greater than 0. Normal averaging would see two consecutive samples (say 350 and 10 degrees) as 180 but this is obviously incorrect, it should be 0 (360) degrees.
I've pulled a great deal of hair out trying to nail this but have hit a brick wall - any suggestions or advice would be most welcome. PIC of choice is F88 so codespace isn't an issue at this stage.
Regards,
Bill
Wind is a vector, not a scalar, quantity
I had to deal with aspects of this when I was working with weather and water instrumentation back in 1976. At the time, I was with the Wyoming Water Resources Research Institute. We dealt with an enormous volume of meteorological and hydrological data.
A side note for/about the "Boys from Berkeley"--there's no reason for a "dead band" on a weather vane and hasn't been for several decades. (That isn't "bashing", is it, Melanie?)
For clarity, let's agree that a vane tells us direction and an anemometer tells us that air is moving, and how fast--that there is in fact wind!
A wind direction change of exactly 180 degrees in that short a period (3 seconds) is frankly unlikely unless the vane is spinning wildly and sampled at the wrong instant, or just turning lazily, moving almost at random. Most occurrences will be in very light, almost insignificant breezes (hence little or no wind speed), so direction doesn't really obtain.
I would "trap" such a condition by looking at the absolute (i.e., unsigned) value of the difference of every successive pair of readings. If it is 180, it's a null (i.e., useless and/or anomalous); discard the earliest value and use the second against the incoming third, and so forth--truly "rolling" the values through:
If |oldest - next| = 180, then oldest = next and next = newest, then start over; else, average the data and continue. (Melanie can probably write the code in about 15 seconds!)
What is overlooked in this discussion is the fact that wind "direction" means nothing if there is no air movement, i.e., no wind speed. Much more important than a possible but unlikely 180-degree anomaly is if the vane is simply sitting there in absolutely still air. It will continue to report a direction! This would be like your television weather reporter saying, "The wind is coming from the east at zero miles per hour." Huh?