#### Archived

This topic is now archived and is closed to further replies.

# Smoothing a value over time

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

## Recommended Posts

I''m working on a VR game app, and I''ve finally got head orientation data coming from my HMD in terms of rotation about the X,Y and Z axes. The data coming in is fairly noisy: If I hold my head as still as possible, the image before me is "shaky" - it moves around in small apparently random "jumps". I used to have a magazine article that described a function that took samples over time and returned an approximated, smoothed value - but I think I tossed out the magazine. Can someone please post a code snippet that accomplishes this?

##### Share on other sites
Progressive averaging? Maintain an accumulator and a value count, and use the result of accumulator/count as your heading value. You''ll have to reset both every once in a while, to guard against overflow.

##### Share on other sites
1. Take the mean of the last n samples?

(Off the top of my head I can see several ways of optimising this; for small values of n possibly unnecessary)

2. Take the weighted mean of the last sample and the result from the previous cycle''s calculation:

V'' = (V * (1-c)) + (n*c);

V is the value to display and n is the input value?

Where c is some constant between 0 and 1 (probably closer to 0)

Essentially the effect of a given reading falls off exponentially or something. There is probably a name for this but I don''t know what it is.

Mark

##### Share on other sites
Perfect. Exactly what I needed! I will check out both methods!

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 22
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631766
• Total Posts
3002218
×