0

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

Saira
  • 3

2 Answers2

2

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).

Penguino
  • 1,169
  • 6
  • 10
  • Thanks Penguino.. I have done as you said and posted in the question. Can you please take a look into it and say if I have done correctly – Saira Aug 12 '19 at 23:09
  • You can just add together the unit vectors and take the direction of the result. No need to insist on having the result inside the unit circle. – hmakholm left over Monica Aug 12 '19 at 23:17
  • My point was only that the average would always be in the unit circle. But yes, as long as you use normalized or unit vectors, you can just use the angle of the summed vectors. @Saira - that looks correct. – Penguino Aug 13 '19 at 00:06
  • 1
    This answer has a bias. For example if the angles (in degrees) are $15,30,60$, then the true average is $35$, but with your proposed method, you would get (approximately) $34.86780516$. – quasi Aug 13 '19 at 01:59
0

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.

Toby Mak
  • 16,827
  • 1
    No, the difference is due to the bias in the other method. For this example, your method gives the correct average. – quasi Aug 13 '19 at 00:57
  • However, your proposed method (i.e., your pseudocode) would fail (in the sense of returning an obviously incorect answer) for the angles $160,170,195$. – quasi Aug 13 '19 at 01:06
  • I guess you could change the ranges, such as changing to '0 < i AND i ≤ 360' and 'i > 360' if it doesn't work. I still suspect there will be a counterexample where neither the original range or the changed range will work. – Toby Mak Aug 13 '19 at 02:45