Averaging values(they are angles) which are wrapping in o to 360

713 Views Asked by At

I have a dataset which are angles and I need to average them to smooth out the noise. Dataset - > [354,357,355,2,352,4,352] -- mean is 253.7143 ,which is wrong

Since there is a roll-off (I have 2 and 4 degrees in the dataset), how can I properly average these values so that I don't get wrong mean value?

As per penguino's answer ,

  1. degrees to polar with r=1 and theta is degrees

    x=[0.9945 0.9986 0.9962 0.9994 0.9903 0.9976 0.9903]

    y=[-0.1045 -0.0523 -0.0872 0.0349 -0.1392 0.0698 -0.1392]

  2. Avg'ed Value of x and y is [mean_x,mean_y]=[0.9953,-0.0597]

  3. Transforming back from cartesian to polar

       [theta,rho] = cart2pol(0.9953,-0.0597)
    

    theta -> -0.0599 and rho -> 0.9971

  4. theta is in radians so, radtodeg(-0.0599) is -3.4320

  5. Since angle is in negative , subtract from 360 i.e 360 - 3.4320 = 356.5680

  6. 356.5680 is the mean value of the dataset

2

There are 2 best solutions below

4
On BEST ANSWER

The simplest solution is:

  1. convert each angle from polar (r=1,theta) to Cartesian coordinates (x,y).
  2. average the set of coordinates to find a point within the unit circle.
  3. convert back to polar coordinates (discarding r).

The returned value of theta is the averaged angle (in your example that would be 356.833).

3
On

To calculate the mean correctly, all your angles need to be in the range $[-180, 180)$. For example, the average of $1, 359, 3$ is $121$, but the average of $1, -1, 3$ is $1$.

Here is some pseudocode that can help you do this:

var angles = [354, 357, 355, 2, 352, 4, 352]
for(i = 0; i < 7; i++) {
     if (-180 < i AND i ≤ 180) {
          angles[i] = angles[i]
     }

     if (i > 180}
          angles[i] = angles[i] - 360 * ceil(angles[i]/360)

     }  else {
          angles[i] = angles[i] + 360 * ceil(angles[i]/360)
     }
} 

and then you can calculate the mean as usual.

Doing this with your dataset gives ${-6, -3, -5, 2, -8, 4, -8}$, and the mean gives $356.5714$. I suspect the difference is because you are rounding your figures to 4 decimal places during the computation.