Calculating an average value of the wind direction


I tried some examples using your eigen-vector method and using the method I proposed:

atan2(sum of sines, sum of cosines)

and I got the same answer. Can you give a simple example where the eigen-vector method gives a different result from mine? (See my posting above in this thread).

Robert Scott
Real-Time Specialties
Embedded Systems Consulting
I am working on the effectiveness of windbreaks, and accurate wind direction is very important to me. I have a huge data set collected at 15 s, 30 s or 1 min interval, and I want to calculate hourly averages. I went through the posting, and looks like it will take me a lot of time if I follow the steps, and I didn't find any definite solution.

Is there a difference in methods for real-time processing (while the data is collected) and post-processing (after the data is collected) to calculate average? I checked the sensor documentation and it says it uses vector components to calculate real-time averages? What about using software that come with the weather station? I know it will generate average too. Any suggestion will be highly appreciated.

Robert Scott

If your sensor or weather station software uses vector components to calculate real-time averages, then it is doing it correctly. If you can get the sensor or the weather station software to create the hourly averages for you, then do so. If you need to process the raw data yourself, then just do the same thing. Break every individual reading (which is a vector) into North and East components. Form the averages of the North and East components. The hourly average is the vector created from the average North and average East components. It does not matter if the data is being analyzed in real-time or after the fact. The calculation is the same.

Robert Scott
Real-Time Specialties
Embedded Systems Consulting
>First convert for Degrees to Radians.
>Then take the SIN of the Radians.
>Next Average the SINs.
>Now Take the inverse sin of the
>Finally convert back to degrees.

The solution is again so simple, only to figure it out... thanks!

IMO, Bob Peterson has the best solution (and it's one of the simplest approaches, too).

But I would probably tweak his approach...

Because the only problem with his solution is that 1/2 hour of wind due north at 50 mph followed by 1/2 hour of wind due south at 50 mph would yield an average wind velocity of 0 mph. I'm guessing you would probably prefer the average value to equal 50 mph.

What I would do is this...

To computer average direction, convert each direction sample into a UNITY vector and add them up and divide by the number of samples.

To obtain the average velocity, add together the absolute value of all the velocity samples and divide by the number of samples.

Hope this helps!

Averaging unity direction vectors can also be misleading. Suppose the wind is nearly calm for much of the day, but when it blows hard, it always blows from the West (270 degrees). But when the wind is nearly calm, it is mostly from the East (090 degrees). All those easterly unity vectors will overwhelm the westerly ones. I'm not sure you want to give such weight to vectors that were nearly zero in magnitude.


The website you cited:

confirms the method that I outlined in my 20 May 2005 posting above.

Robert Scott
Real-Time Specialties
Embedded Systems Consulting
I've written the following program in C.
Can you tell me if it works correctly for your problem?

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

static float angle_0to360(float theta)
int k = (int)(theta / 360);

theta = theta - k * 360;
if (theta < 0) {
theta = theta + 360;
return theta;

static float new_angle_mean(float old_theta, float new_theta, int old_num)
float mean_theta;
float dtheta;

if (old_theta == new_theta) {
return old_theta;

dtheta = fabsf(old_theta - new_theta);
if (dtheta > 180) {
old_theta = (old_theta > 180) ? old_theta - 360: old_theta;
new_theta = (new_theta > 180) ? new_theta - 360: new_theta;

mean_theta = (old_theta*old_num + new_theta) / (old_num + 1.);

return angle_0to360(mean_theta);

int main()
int i, num;
float *theta;
float mean_theta = 0.;

printf("give number of angles: ");
scanf("%d", &num);

theta = malloc(num * sizeof(float));

printf("give %d angles: ", num);

for (i = 0; i < num; i++) {
scanf("%f", &#952;);
theta = angle_0to360(theta);
mean_theta = new_angle_mean(mean_theta, theta, i);

printf("\nmean_theta = %f\n\n", mean_theta);

Sorry, alex001, your C program does not solve the problem. To see that it does not work, just feed the following list of angles into your program:

angle______"mean" so far
4 _____ 4
180 _____ 92
270 _____ 151.3
340 _____ 108.5
270 _____ 140.8
330 _____ 112.3
300 _____ 87.7
260 _____ 109.2
300 _____ 90.4

If you plot these angles, you will agree that the average ought to be somewhere around 270 degrees, not 90.4. I can clearly keep extending the list using angles that are all close to 270 and still make your "average" stay around 90. As I and several others have said earlier, you have to average the sines and cosines and then take are arctangent.

Robert Scott
Real-Time Specialties
Embedded Systems Consulting

Randy Jakosalem

Hi Ville!

Try to trap 360 value and output it as 0 so to make your average correct. Just add the following logic :

value = X "data acquired"

If value = 360 then value = 0 else value = X

"Then use "value" as your data element for the degrees or wind direction then you're OK.


Julian Hernandez

Hello Robert,

I´m following your example mentioned above (20 May 2005). In the case we would work with the negative values (359 = -1; 358 = -2, etc) where could we find the limit to this negative values? I mean that if we have 179 and -179 for example (in the situation that South=180 were the limit) the average is 0=N when should be 180=S.

So where could we find the limit to estimate the real average? Have you got some suggestion?

Thank you very much.
Uppsala Universitet
Julian of Uppsala Universitet asks:

>...So where could we find the limit to estimate the real average? Have you got some suggestion?<

My suggestion is the same as before (see my earlier postings). Stop trying to average the angles directly and average the sines and cosines instead. It is the only way that actually works in all situations.

Robert Scott
Real-Time Specialties
Embedded Systems Consulting
I had to resolve this problem a few months back. I came up with a very simple solution that was mentioned a few posts up (Convert to vectors and average the vector). Here is the Matlab syntax...

% Develop a total wind vector to determine average heading. This eliminates any problems with averaging values like [5,355,-180,180]
N = sum(MG .* cosd(HD));
E = sum(MG .* sind(HD));

Ave_MG = mean(MG);
Ave_HD = atan2(E,N) * cR2D;
Try this with excel:

For realvector averaging:

Put windspeed and winddirection data in column A and B.
Then calculate the components of wind (u and v are in column C and D):


In column E and F (for example,if you have 60 data in one hour) calculate the average of the components of wind:


Column G is the average value of the windspeed:

Column H is the average value of the winddirection:

For unitvector averaging:

column C and D:


column E and F:


column G:


column H:


Hope this helps.

Meteorology Specialist (M.Sc)
Tehran University

Here's an different but very easy solution. I searched for myself a way to have daily averages of my hourly measured wind direction data. I found that there is no excellent and %100 correct solution. Therefore I make my own method to have a most represanting daily direction. My way will give you not the exact average value of the measured degrees, but you will have the most dominated daily wind direction.

1) Convert you degree data to direction codes. Here is the formula for excel:

1= N, 2=NE, 3=E, 4=SE, 5=S, 6=SW, 7=W, 8=NW

2)Calculate the most frequent value (in excel: MODE) for each day.

That's all.

Cemil Seyis
Hi, I'm getting a syntax error (for if statement) when I use the statement

Minor corrections:

> Minor corrections:

> =IF(e1=0,(IF(f1=0,"n/a",IF(f1>0;360;0))),IF(e1>0,(270-180/PI()*ATAN(f1/e1)),(90-180/PI()*ATAN(f1/e1))))

This is a very simple mathematical and meteorological issue (actually page 2 of "Meteorology for Scientists and Engineers" by Roland B Stull..

Note: time period can be any time period (this example is hourly)

*** Matlab code below

For each ten minute wind speed measurement the u- and the v-component of the wind need to be calculated in order to average wind direction.<pre>
u-comp ws = -1 * (ws*sin(wd*PI/180))
v-comp ws = -1 * (ws*cos(wd*PI/180))

where PI = 3.1415926535897

assuming six 10-minute values in an hour

average the six u-comp WS and six v-comp WS to get an average u-comp and v-comp for the hour

if average u-comp > 0
hourly average WD = (90-180/PI*atan(average v-comp/average u-comp)+180)
elseif average u-comp < 0
hourly average WD = (90-180/PI*atan(average v-comp/average u-comp))
elseif average u-comp = 0
if average v-comp < 0
hourly average WD = 360
elseif average v-comp > 0
hourly average WD = 180
hourly average WD = 0

Example Calculation:

Six WS measurements: [2.3, 2.7, 4.5, 5.2, 10.3, 8.1]
Six WD measurements: [220, 174, 43, 356, 99, 67]


Average u-comp = -3.18989225
Average v-comp = -0.930826755
Hourly Average WD = 73.73 degrees
Hourly Average WS = 5.5167 m/s</pre>