embedded software boot camp

Modulo Means (reprised)

Sunday, November 30th, 2008 by Nigel Jones

In my previous post I had asked for some input on how to compute the mean of a phase comparator. Bruno Santiago suggested converting the phase readings to their Cartesian co-ordinates and averaging the resulting (X, Y) data, and then converting the means of X & Y back into a phase angle. Well kudos to Bruno because this is exactly what I ended up doing. However, as Bruno observed, it’s not exactly an efficient process. It is however robust, and in my application, the robustness counts for a lot.

The suggestion that I average the inputs to the phase comparator has its merits. However for reasons that would take too long to explain, I’m not really able to do this in my application.

Finally, I’d like to mention the second solution that Kyle had proposed. First a caveat. I haven’t fully thought through this solution, and I most certainly have not implemented and tested it. With that in mind, here’s another approach to contemplate.

You’ll remember that we can compute the average of the phase angle by using the simple arithmetic mean, provided that we do not cross back and fore across the zero phase line. Well Kyle’s insight was that as well as computing the arithmetic mean of the phase angle, we also do the same for the quadrature angle. The idea is that while it is possible that the phase could alternate across the zero degree line, it would not simultaneously alternate across the 90 degree line (or indeed the 180 degree line). Thus, the method then becomes one of computing two means and choosing the correct one. If I get the time I’ll develop this into a fully fledged algorithm and publish it for you all to, ahem, enjoy. I’m fairly sure that this method is not as robust as the Cartesian method. However, it is dramatically more efficient and thus is deserving of greater investigation. Bruno – perhaps you’d care to do the analysis in your CFT (Copious Free Time)?

Home

4 Responses to “Modulo Means (reprised)”

  1. Bruno Santiago says:

    To get the best method you have to analyse two things.How many inputs you will average? 4? 10? 500? 10000?What´s the max noise? 10 degrees? 30? 70? 90? 180?If it´s over 90 your measurement is probably useless.With that information and looking to the unit circle and the four quadrants for a couple of hours you will probably find a efficient and robust method.The magic will probably on analysing the inputs before averaging. Something like my second suggestion but without restrictions for the number of inputs, but with restrictions about the maximum noise.

  2. Bruno Santiago says:

    I tried not to think before you gave more information, but I couldn´t and I thought about your problem a bit more.******If your noise(peak to peak) is below 90 degrees peak to peak, I can imagine a method similar to Kyle´s that is efficient.If your first sample is from the second or third quadrant(90 to 270 degrees), then it´s simple arithmetic meanIf your first sample is from the first quadrant(0 to 90 degrees), it´s simple arithmetic mean but the samples of the fourth quadrant that may appear need to be preprocessed(330 becames -30 and so on) before entering summing. And If your final value is negative, add 360.And If your first sample is from the fourth quadrant(270 to 360 degrees), you have to a simple arithimethic mean and preprocessed one(330 becames -30 and so on) until a sample from the third or the first quadrant appears. If it is from the third you continue with the simple one, else you continue with preprocessed one.******And if your noise is below 45 degrees peak to peak, It´s even simpler!If the first sample is over 45 degrees and smaller than 315, then it´s simple arithmetic mean.Else, the samples from the fourth quadrant need to be preprocessed like I said before.******Hope it helps, if it is confused try drawing what I say on the unit circle.

  3. Nigel Jones says:

    Your comments are prescient Bruno. I’m averaging 32 readings. The maximum phase noise is 90 degrees, although the typical noise is 45 degrees. Kyle’s algorithm is very close to what you suggested. As you observed however, if the noise exceeds 90 degrees, then things get a little more difficult. It’s for this reason that I went with the computationally less efficient, but more robust algorithm that translates the data into cartesian coordinates, processes the data, and then translates back. As and when I get some free time (Hah!) I will investigate this further. The reason is that this is on a battery powered device, and so computational efficiency results in extended battery life.

  4. Tom Evans says:

    Am I missing something here? Just modulo subtract the first value from all the others, and now you're averaging the differences. I think that gets you plus and minus 180 degrees (from the initial value) with no quadrants. Or start by subtracting the previous average (if you can assume it hasn't moved all that much).

Leave a Reply

You must be logged in to post a comment.