# How can I use imprecise accelerometer data for controls?

I want to rotate an object with respect to the phone's position. I use the accelerometer output to detect orientation:

float roll = Gdx.input.getRoll();
float pitch = Gdx.input.getPitch();
float azimuth = Gdx.input.getAzimuth();

Vector3 accel=new Vector3(accelX, accelY, accelZ);
bat.transform.setToRotation(0f, -1f, 0f, pitch);

bat.transform.setFromEulerAngles(azimuth, -pitch, -roll);


However, the accelerometer data fluctuates so strongly that the object jitters.

How can I deal with this?

Low Pass Filter - This works by only allowing a value to change by a percentage(alpha) of the difference between the previous value and the new value. Simply output = previousValue + alpha * (newValue - previousValue) This works well, but might require some tweaking of the alpha to find a value that works well for your needs. A low alpha will give you a consistent value while the device is idle, and a very fluid motion reading, however it will cut down any sharp peaks in movement. A higher alpha will give a more responsive feedback but will not remove all the noise.
Infinite Impulse Response filter (IIR) - It works by combining a percentage(alpha) of the previous value with the opposite percentage of the new value. ouput = previousValue * alpha + (1.0f - alpha) * newValue. This can produce similar results as a low pass filter, however the alpha value is just the opposite. In this case, a higher alpha will give you a smoother response and a flatter line, while a lower value will give you a more more responsive result, but also might still have a bit of noise.