Skip to content

Instantly share code, notes, and snippets.

@MylesBorins
Created April 15, 2016 16:15
Show Gist options
  • Save MylesBorins/b7285569d1e730bd780e3bb4a9ba343b to your computer and use it in GitHub Desktop.
Save MylesBorins/b7285569d1e730bd780e3bb4a9ba343b to your computer and use it in GitHub Desktop.
Low pass filter of device orientation
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);
@jasan-s
Copy link

jasan-s commented Oct 29, 2016

Would this mitigate the alpha drift?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment