Math help - rolling average Wind Direction


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Exclamation 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?
    Last edited by RussMartin; - 14th July 2007 at 09:34.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  2. #2
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    For the curious, wind data is often expressed graphically, in the form of a wind rose.

    The compass is divided into 8, 16, 32, or sometimes more, equal segments. 16 is the most common.

    <IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1857&d=1184480481">
    Attached Images Attached Images  
    Last edited by RussMartin; - 15th July 2007 at 07:29.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  3. #3
    Join Date
    Jun 2005
    Location
    West Australia
    Posts
    116


    Did you find this post helpful? Yes | No

    Default

    Hi Folks,

    Thanks to all for comments and suggestions, I'm still trying various ways to come up with one solution for all.

    Russ, you make good points with your Direction without Wind speed comments. I also have a long history of Oceanographic and Meteorological experience - but as a hardware guy. My venture into writing code has only been recent by comparison so I have the problem of putting the hardware experience into the Black Art... For the record, Tracey ("Boys from Berkeley") Allen's website has been a mine of useful information for me particularly with the math side of things and would encourage anyone regardless of their qualifications to spend some time reading some of his writings.

    What I didn't mention in my opening question was that I am also measuring Wind Gust, which by definition, is the highest successive wind speed in a 3 second window - hence my need to also measure the direction over 3 seconds (my opening question). You can read between the lines here to see I am also deriving Highest wind speed, Average wind speed, Wind Gust direction, Average direction and Direction deviation (Sigma Theta) - so I have a number of things to juggle and think about, all within a continuously sliding 3 second window which is moving every 1 second.

    I'm making progress but it isn't pretty code! If anyone has some more to input it will be warmly welcomed otherwise I'll keep banging away to streamline things.

    Kind regards to all,
    Bill

  4. #4
    Join Date
    Jun 2005
    Location
    West Australia
    Posts
    116


    Did you find this post helpful? Yes | No

    Default

    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

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Missed the Modulas.

    360 // 360 = 0

    and

    370 // 360 = 10

    Also, keep in mind it's using a 3 sample running average.
    So starting at 350, and a sample of 20, the difference is 30 and it will move 1/3 of that, or 10.
    So it ends up at 360(0) after 1 sample.
    <br>
    DT

  6. #6
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Just curious a bit ... Bill, what are you using to measure this direction 0 - 360?
    Thanks
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  7. #7
    Join Date
    Jun 2005
    Location
    West Australia
    Posts
    116


    Did you find this post helpful? Yes | No

    Default

    Thanks Darrel, I'll take another look later (time for my beauty sleep).

    Paul, it's a 360 degree precision linearity potentiometer fed with a regulated voltage. I use the PIC A2D to derive a count and then process the count for degrees.

    Cheers,
    Bill

Similar Threads

  1. Replies: 10
    Last Post: - 8th April 2008, 21:07
  2. Math help please!!!
    By jbirnsch in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 10th August 2007, 14:45

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts