Average and Variance of a periodic angles
- From: jstout@xxxxxxxx
- Date: Fri, 7 Mar 2008 13:01:12 -0800 (PST)
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
.
- Follow-Ups:
- Re: Average and Variance of a periodic angles
- From: Duncan Muirhead
- Re: Average and Variance of a periodic angles
- From: junoexpress
- Re: Average and Variance of a periodic angles
- Prev by Date: Re: How to solve Helmholtz equation using Maple or Mathematica
- Next by Date: Re: Average and Variance of a periodic angles
- Previous by thread: Placing objects in density field, appropriate newsgroup.
- Next by thread: Re: Average and Variance of a periodic angles
- Index(es):
Relevant Pages
|