# Make the average of some cyclic numbers

This topic is 4864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 23
• 12
• 12
• 11
• ### Forum Statistics

• Total Topics
634779
• Total Posts
3019240
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!