Average and Variance of a periodic angles



I'm trying to compute the average of an array of angles, and the
variance of that array. The problem is the data in an array of angles
and the data is periodic in 2.0 pi radians.

I think I can compute the average of an array of angles by converting
to a retangular coordinate system and computing the average like this:

sumx = 0.0f;
sumy = 0.0f;
for (i = 0; i < size; i++) {
x = cos(data[i]);
y = sin(data[i]);
sumx += x;
sumy += y;
}
avgx = sumx/size;
avgy = sumy/size;
avg = atan2(avgy, avgx);

Now my problem comes in when trying to calculate the variance. The
same trick does not seem to work.

sumx2 = 0.0f;
sumy2 = 0.0f;
for (i = 0; i < size; i++) {
x = cos(data[i]);
y = sin(data[i]);
sumx2 += (x - avgx) * (x - avgx);
sumy2 += (y - avgy) * (y - avgy);
}
var = atan2(sumy2/size, sumx2/size);

The average calculation seems to work. The variance, not so much.
Does anybody know how I can fix this?

Jeff Stout
.



Relevant Pages

  • Re: Average and Variance of a periodic angles
    ... The problem is the data in an array of angles ... and the data is periodic in 2.0 pi radians. ... One way is to use the iterative formulae for mean and variance ...
    (sci.math.num-analysis)
  • Re: Data in table, may need to convert to columns with OFFSET?
    ... I should have known that array formulae were ... I used that to then create a pivot table from my data to find max, min, ... Biff Wrote: ... A2:A7 for the angles and B1:F1 for the energies. ...
    (microsoft.public.excel.misc)
  • Re: mean ans std dev of an array?
    ... Do I need to import it into a Numeric Array to do this? ... If you build an air liner or a ocean liner with this and the wings fall off at thirty thousand feet or it turns upside down in the middle of an ocean, respectively of course, I expect a bunch of contingency lawers lining up at my door wanting to sue you on my behalf.) ... Takes a sequence and returns mean, variance and standard deviation. ...
    (comp.lang.python)
  • Re: Presence of logical ones around a pixel in a certain direction and distance
    ... relative indices and access the array at those locations" ... That would be true for the angles as well, ...
    (comp.soft-sys.matlab)
  • Re: averaging based on multiple criteria
    ... #1 as an array ... this spreadsheet is populated with new data weekly where there is ... a variance between how many rows will contain data, ... > What are the exact formulas you have used ...
    (microsoft.public.excel)