Permalink
Browse files

Use a simple low pass filter to filter out device acceleration noise

  • Loading branch information...
1 parent b464c56 commit 724d8e8c46144bdb958ca9d696cc79a1367dff27 @dougt dougt committed Jul 6, 2012
Showing with 10 additions and 0 deletions.
  1. +10 −0 js/plax.js
View
@@ -34,6 +34,9 @@
motionMax = 1,
motionAllowance = .05,
movementCycles = 0,
+ motionLowPassFilter= 0.2,
+ motionLastX = 1,
+ motionLastY = 1,
motionData = {
"xArray" : [0,0,0,0,0],
"yArray" : [0,0,0,0,0],
@@ -156,6 +159,13 @@
var accel= e.accelerationIncludingGravity,
x = accel.x,
y = accel.y
+
+ x = (x * motionLowPassFilter) + (motionLastX * (1.0 - motionLowPassFilter));
+ y = (y * motionLowPassFilter) + (motionLastY * (1.0 - motionLowPassFilter));
+
+ motionLastX = x;
+ motionLastY = y;
+
if(motionData.xArray.length >= 5){
motionData.xArray.shift()
}

0 comments on commit 724d8e8

Please sign in to comment.