# Mean value for wind direction

(deleted)

May I suggest that you put away your Arduino for a little while and figure out how you would do what you want in a spreadsheet where it is much easier to play with maths.

One option (assuming you collect several values into an array) might be to get the mean of all the numbers (including the outliers) and then get the difference between each number and the mean. That should allow you to identify the outliers and exclude them. Then you can get the mean of the remaining numbers.

This may not be the best approach and some study of a statistics textbook may be a good idea.

A big complication will arise when the wind is varying from, say 367 to 003 degrees.

...R

to address the 357 / 003, you could invert the compass ?

I would try to run the last 10 readings and average by 10, then let the oldest fall off the calculations.
You could note the standard deviation and if above some value, report that reading is not reliable.

(deleted)

If you don't mind using the mode instead of the mean, you can just generate a histogram of values over the last minute and pick the one with the highest value. To do this you map the raw wind value into one of eight directions (or however many you want). At the beginning of the minute you zero the histogram array and then with each reading, increment the appropriate element of the array. When you have read and processed the last reading in the minute, find which index in the array contains the highest number of readings and use that as the direction.
There is still the possibility that two or more directions will have the same number of values. In this case the correct statistical procedure is to average the readings, but it will probably occur so infrequently that you can safely use whichever one is found first (or last).

Pete

Suppose you have this data wsw w n w n w n w n w. How would you intepret it?. The maximum count favours w but it seems to me the predominant direction is nw and the trend is from south to north. That's why I would prefer to use numbers that can be manipulated with maths.

You need to be careful not to adopt an interesting algorithm that gives useless results.

I would need a good reason to average the direction over a period shorter than 10 minutes.

...R

Suppose you have this data wsw w n w n w n w n w. How would you intepret it?.

I'd say that it is either totally unrealistic that the wind would shift through about 90 degrees every 5 seconds, or the vane is not up in the open. And BTW, wsw would not be valid since the OP has indicated using only eight directions.

The result would be "w" or "n" depending upon whether you code it to pick the first most frequent reading or the last. Re-read what I posted.

You need to be careful not to adopt an interesting algorithm that gives useless results.

That process (but sampling every minute and reporting every half-hour) has been implemented in a system that has been running in the real world for the last two years. The results aren't useless.

Pete

el_supremo:

You need to be careful not to adopt an interesting algorithm that gives useless results.

That process (but sampling every minute and reporting every half-hour) has been implemented in a system that has been running in the real world for the last two years. The results aren't useless.

I was not commenting on your post. I have no doubt there are many valid algorithms - I started my working life in the Met Office. I was/am concerned that the OP might choose an inappropriate algorithm.

I'd say that it is either totally unrealistic that the wind would shift through about 90 degrees every 5 seconds,

You are taking me too literally and missing the point which is that the most frequent instantaneous wind direction in a bunch of samples might not represent the typical direction in that period.

And I did say that I see little point in sampling the direction so frequently.

...R

I didn't miss your point. You missed mine, which is that in the real world the kind of pathological readings you posit would rarely occur, if ever. Furthermore, even if they do occur, who cares if a couple of reported values per month, or however often, are wrong?

And I did say that I see little point in sampling the direction so frequently.

And I wholeheartedly agree.

Perhaps the OP could tell us just how accurate the results should be and what use is going to be made of them.

Pete

Robin2:
A big complication will arise when the wind is varying from, say 367 to 003 degrees.

I didn't think of that. 359 - 0 would be what would mess me up. How to tell that they are adjacent to each other?

-jim lee

el_supremo:
I didn't miss your point. You missed mine, which is that in the real world the kind of pathological readings you posit would rarely occur, if ever.

I like my program to be able to deal with the pathological readings - then it will probably work OK with the sensible ones. The problems arise when the designer never bothers to think of the pathological cases and as a consequence neglects to take account of some feature of the sensible cases.

Furthermore, even if they do occur, who cares if a couple of reported values per month, or however often, are wrong?

I am inclined to agree with you on this - but really we must await the OPs opinion. If it was going to drive his sailboat onto rocks he might care.

...R

(deleted)

How about some damping of the wind vane?

Here's a patent on the matter: US20120156036A1 - System And Method For Damping A Wind Vane - Google Patents

(deleted)

As a dilettant.

I do agree with R..

The raw data may contain spurious one that can be detected and, then, neglected by software. May be that a mechanical damp helps "viewers" to make a quick idea of where wind is blowing from, but a computerized system, I think, is powerful enough as to virtually "damp" the vane (by the way, I didn't know how to say "veleta" in english up to now) and, as a complement, detect a "turbulent" situation.

Regards.

(deleted)