Permalink
Browse files

Merge pull request #27 from dougt/low_pass_filter

Use a simple low pass filter to filter out device acceleration noise
  • Loading branch information...
2 parents b464c56 + 724d8e8 commit 4df76cc2a6b0907fb31b65475a1187721296d6cc Cameron McEfee committed Jul 20, 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 4df76cc

Please sign in to comment.