Skip to content

Instantly share code, notes, and snippets.

@simekadam
Created November 5, 2011 09:41
Show Gist options
  • Save simekadam/1341325 to your computer and use it in GitHub Desktop.
Save simekadam/1341325 to your computer and use it in GitHub Desktop.
//ramp-speed - play with this value until satisfied
final float kFilteringFactor = 0.0f;
//last result storage - keep definition outside of this function, eg. in wrapping object
float accel[] = new float[3];
float result[] = new float[3];
//acceleration.x,.y,.z is the input from the sensor
//result.x,.y,.z is the filtered result
//high-pass filter to eleminate gravity
accel[0] = event.values[0] * kFilteringFactor + accel[0] * (1.0f - kFilteringFactor);
accel[1] = event.values[1] * kFilteringFactor + accel[1] * (1.0f - kFilteringFactor);
accel[2] = event.values[2] * kFilteringFactor + accel[2] * (1.0f - kFilteringFactor);
result[0] = event.values[0] - accel[0];
result[1] = event.values[1] - accel[1];
result[2] = event.values[2] - accel[2];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment