>> This sounds like a problem I faced a while back, averaging compass >> headings. >> 90,89,91 averages to 90, no problem, but 359,0,1 averages to 180 which is >> dead wrong. It's actually NOT "wrong" - it's just not the interpretation that you wanted to place on the data :-) Imagine that the same data related not to compass headings but instead to a (fast) vehicle speedometer. The answer of 180 would be correct for some purposes. For a 360 degres 360 kph speedo the data would correspond to both vehicle speed AND speedo pointer angle, but the summing method would work for one and not the other. >> What I did, was to convert the polar coordinates to rectangulars, then >> add them, then convert back to polar. >> >> I had to do 7200 of these every second, while dealing with a ton of >> serial traffic as well, on nine ports. > I would suggest the following process: > > 1. add a huge constant to each number before averaging > 2. calculate the average > 3. subtract the said constant from the result This also doesn't work. For his example, if K is added each time, the average = (0 + 1 + 360 + 3k - 3k) /3 = 180 Good for speedo. Bad for angle. What is needed is a strict definition of the problem in this particular instance so that the data can then be described in terms of the problem structure. (Echoes of Jackson structured programming - and no doubt much since then). In the case of eg wind direction the polar system works IF the amounts added are vectors corresponding to distance travelled during each measurement period ie the integral wrt time of the direction vector. If the sampling is at constant rate then the vectors may be polar summed correctly. What you are really calculating is not the mean heading but the resultant distance vector. The heading that generated this is an implicit part of it. The method needs to be re-evaluated each time the fundamental nature of the data measured varies. RM _______________________________________________ http://www.piclist.com View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist