Android Acceleration Sensor: Low-Pass Filter

A low-pass filter is a type of electronics filter that attempts to pass low-frequency signals through the filter unchanged while reducing the amplitude of signals with a frequency above what is known as the cutoff frequency. They are used for all sorts of things including audio, images, signal processing and digital filters.

The concept of a low-pass filter comes from electrical engineering. It is simply a resistor in series with the load and a capacitor in parallel with the load. The capacitor essentially acts a load spring, absorbing high-frequencies, but blocking low-frequencies and forcing them through the load instead. This is because at low-frequencies the capacitor has time to charge so it is equal to in the input voltage forcing the signal to the output. At high frequencies, the capacitor does not have enough time to charge, allowing the signal to go to ground instead of through the output.

The resistance and the capacitance define the time constant (T = RC) which then determines the cut-off frequency (the frequency at which the filter attenuates the signal).

The Low-Pass Filter has an advantage over the Mean Filter in that it has a memory and computational complexity factor that is an order of magnitude less than the Mean Filter.

Introduction to Applications:

One of the most common ways of filtering accelerometer data is by using a low-pass filter to smooth data or to help isolate components of the signal. The Android Developer documentation provides an example of a low-pass filter that isolates the force of gravity which can then be used to estimate linear acceleration. Once the low pass filter has an estimation of gravity, a high-pass filter can be applied to isolate the linear acceleration of the device by subtracting gravity (the low-pass portion of the signal) from the signal, effectively giving you only the high-pass portion of the signal which is the linear acceleration of the device.


If you application requires a low-pass filter, FSensor has already done the hard work for you. FSensor implements an IIR single-pole low-pass filter. The coefficient (alpha) can be adjusted based on the sample period of the sensor to produce the desired time constant that the filter will act on. It takes a simple form of output[0] = alpha * output[0] + (1 – alpha) * input[0]. Alpha is defined as alpha = timeConstant / (timeConstant + dt) where the time constant is the length of signals the filter should act on and dt is the sample period (1/frequency) of the sensor. Computationally efficient versus a mean or median filter (constant time vs linear time).


Filter Coefficient/Alpha: A value 0 < a < 1 that determines how much weight should be applied to the high-pass and sometimes the low-pass portion of the signal.

Time Constant/T: The time constant, T, is the relative duration of the signal that the filter will act on. That means that on a low-pass filter, signals that are much longer than the time constant will pass through unaltered, but signals that are shorter than the time constant with be ignored.

A Pseudo Implementation:

for i from 1 to n
  y[i] = α * y[i] + (1-α) * x[i]
return y

A Java Implementation:

static final float alpha = 0.05f;

public float[] lowPass(float[] output, float[] input)
  output[0] = output[0] + alpha * (input[0] - output[0]);
  output[1] = output[1] + alpha * (input[1] - output[1]);
  output[2] = output[2] + alpha * (input[2] - output[2]);

  return output;


The device has been placed on a flat surface. As Alpha is decreased, the filter becomes much more “stiff” to change. While the signal noise is reduced significantly, the filter is also very slow to respond to change.

We can see that the smoothing effect is not visible until alpha is smaller than 0.1. Note that alpha = dt/(T+dt) where T is the time constant of the filter and dt is the sample period (time between updates). If alpha is much less than 0.5, then T is much larger than the sample period (time between updates). As alpha becomes smaller, the time constant becomes larger and the filter performs more smoothing on the signal. As the signal becomes smoother, it also becomes more latent.



Leave a Reply

Your email address will not be published. Required fields are marked *