My smartphone have only accelerometer sensor. I need to get data close to (0,0,0) in hold in my own application. I did use some app from Google Play and data was very close to it (some like 0.1 and tend to zero in long time). I have tried apply code from documentation (all other web sources just copy past this code)

In my case update rate is 100Hz.

public void onSensorChanged(SensorEvent event){
    // In this example, alpha is calculated as t / (t + dT),
    // where t is the low-pass filter's time-constant and
    // dT is the event delivery rate.

    final float alpha = 0.8;

    // Isolate the force of gravity with the low-pass filter.
    gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
    gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
    gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];

    // Remove the gravity contribution with the high-pass filter.
    linear_acceleration[0] = event.values[0] - gravity[0];
    linear_acceleration[1] = event.values[1] - gravity[1];
    linear_acceleration[2] = event.values[2] - gravity[2];

In high alpha value (~0.2-0.5) data stuck in 3-5 g line, instead 9.8 without any filter. But I want to get 0.

With low alpha value (0.01-0.03) I have data close to zero but amplitude of signal is very reduced from -1 to +1 instead -20 to + 20

What should I do?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.