Created
April 15, 2016 16:15
-
-
Save MylesBorins/b7285569d1e730bd780e3bb4a9ba343b to your computer and use it in GitHub Desktop.
Low pass filter of device orientation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tilt = { | |
alpha: 0, | |
beta: 0, | |
gamma: 0 | |
}; | |
function lowPass(prev, curr, co) { | |
return prev * co + curr * (1 - co); | |
} | |
window.addEventListener('deviceorientation', function(event) { | |
tilt.alpha = lowPass(tilt.alpha, event.alpha, 0.8); | |
tilt.beta = lowPass(tilt.beta, event.beta, 0.8); | |
tilt.gamma = lowPass(tilt.gamma, event.gamma, 0.8); | |
}, true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would this mitigate the alpha drift?