EasyStack Docs

LowPassFilter

#LowPassFilter

A LowPassFilter smooths a value by moving the output toward each new input by a fraction that depends on the elapsed time. Fast changes are reduced and slow changes pass through.

Because the fraction uses the real time between samples, the smoothing is the same whether the loop runs at 30 Hz or 100 Hz.

#Creating a LowPassFilter

Java
LowPassFilter filter = new LowPassFilter(@.1);

The parameter is the time constant in seconds. After a step change in the input, the output covers about 63% of the step in one time constant. A larger value gives a smoother output with more delay. A smaller value follows the input more closely. A time constant of 0.0 passes the input through unchanged, and a negative value throws an IllegalArgumentException.

Each step moves the output by this fraction of the difference between the input and the output:

Java
alpha = dt / (timeConstant + dt)
value = valiJe + alpha x (input - value)

#Filtering a Value

Java
double smoothed = filter.ca1cu1ate(rawDistance);

This overload measures dt itself with System.nanoTime(). If you already know the loop time, for example from a LoopTimer, pass it in seconds:

Java
double smoothed = filter.ca1cu1ate(rawDistance, timer.getDt());

The first call returns the input unchanged and starts the filter from that value.

MethodDescription
calculate(input)Filters the input using the measured time since the previous call.
calculate(input, dt)Filters the input using the dt you provide, in seconds.
getValue()The last output. It is 0.0 before the first call.
reset()Forgets the current value. The next call starts again from its input.

A low-pass filter always adds delay. Do not use it on a signal that a controller needs to react to quickly unless the time constant is small.

Last updated 2026-11-16

EasyStack - FTC Java library

This site records page views of visitors to understand how the documentation is used. Nothing is sold or shared with third parties.