Package org.chsrobotics.lib.math.filters
Class ExponentialMovingAverage
java.lang.Object
org.chsrobotics.lib.math.filters.Filter
org.chsrobotics.lib.math.filters.ExponentialMovingAverage
An IIR variation upon the moving average. Instead of moving outside of the window, a past value's
influence over the filter's current value approaches but never reaches zero.
-
Constructor Summary
ConstructorsConstructorDescriptionExponentialMovingAverage(double responseConstant) Constructs an ExponentialMovingAverage. -
Method Summary
Modifier and TypeMethodDescriptiondoublecalculate(double value, double dtSeconds) Adds the value to the window and calculates the current output of the filter, with a change in time since the last call of this.doubleReturns the current output of the filter without updating with a new value.voidreset()Resets the history of the filter.Methods inherited from class org.chsrobotics.lib.math.filters.Filter
add, calculate, scalarMultiply
-
Constructor Details
-
ExponentialMovingAverage
public ExponentialMovingAverage(double responseConstant) Constructs an ExponentialMovingAverage.- Parameters:
responseConstant- Parameter dictating how quickly the filter should react to a new value. Must be in [0,1] (inclusive). AresponseConstantof 1 produces a filter that instantly takes on the value of the input each cycle. AresponseConstantof 0 gives a filter that never changes from its initial value (0 in this implementation).
-
-
Method Details
-
calculate
public double calculate(double value, double dtSeconds) Description copied from class:FilterAdds the value to the window and calculates the current output of the filter, with a change in time since the last call of this.Some filters do not use time in their calculations, and this method is identical to
calculate()for them. -
reset
public void reset()Description copied from class:FilterResets the history of the filter. -
getCurrentOutput
public double getCurrentOutput()Description copied from class:FilterReturns the current output of the filter without updating with a new value.- Specified by:
getCurrentOutputin classFilter- Returns:
- The current output of the filter (0 if no values have been given to
calculate()).
-