Make the average of some cyclic numbers

Started by
0 comments, last by nmi 18 years, 5 months ago
Hello, I have following problem: I am receiving data that varies between 0 and 4095. Ideally that data goes from 0 up to 4095 and then directly to 0 again or into the opposite direction. The signal is basically a saw. I use that signal to count the number of turns of a motor (the motor can turn in both directions and I have to keep track about the absolute position with number of turns). Now that problem is trivial. However my signal is outputted every 20 us (doing that on a microcontroller) and can be very noisy (but still ranging from 0 to 4095). When noise gets too much I loose track on the number of turns and that is bad. So I want to use some kind of average for my signal. The problem is I cannot do a straightforward average like I would do with normal numbers, since 1 and 4095 are very close positions and the average would theoretically be 0. (0,1,2,...,4094,4095,0,1,2,...) What I do now I take values pairwise, compute the shortest distance between them (there are 2 directions the distance can be measured) and select the value in the middle. Now I am looking for some simpler way of doing that, without having to take values pairwise. Also the algorithm should be very fast. Any good ideas? Thanks :)
Advertisement
Read here:
http://de.wikipedia.org/wiki/Exponentielle_Gl%C3%A4ttung

Although it is in german, the formulas should give you an idea how to smooth the data.

Another idea you might want to try is to smooth the first derivative of your data (i.e. the difference between two consecutive pairs of values). With some threasholding you can detect the jump between 0<->4095. Here you will get a big positive value for a jump 0->4095, a big negative value for a jump 4095->0 and almost zero for linear rotation.

This topic is closed to new replies.

Advertisement