Created
December 3, 2014 12:16
-
-
Save KurtWM/d4f37b25ca75beb93e89 to your computer and use it in GitHub Desktop.
Example taken from: http://stackoverflow.com/questions/1638864/filtering-accelerometer-data-noise
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 accelFilter = function ( x, y, z ) { | |
//ramp-speed - play with this value until satisfied (value is a float number) | |
var kFilteringFactor = 0.1, | |
//last result storage - keep definition outside of this function, eg. in wrapping object (values are floats) | |
accel[3], | |
highPassFilter = function () { | |
//acceleration.x,.y,.z is the input from the sensor | |
//result.x,.y,.z is the filtered result | |
//high-pass filter to eliminate gravity | |
accel[0] = acceleration.x * kFilteringFactor + accel[0] * (1.0 - kFilteringFactor); | |
accel[1] = acceleration.y * kFilteringFactor + accel[1] * (1.0 - kFilteringFactor); | |
accel[2] = acceleration.z * kFilteringFactor + accel[2] * (1.0 - kFilteringFactor); | |
result.x = acceleration.x - accel[0]; | |
result.y = acceleration.y - accel[1]; | |
result.z = acceleration.z - accel[2]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment