gov.sandia.cognition.math.signals
Class MovingAverageFilter

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.evaluator.AbstractStatefulEvaluator<Double,Double,FiniteCapacityBuffer<Double>>
          extended by gov.sandia.cognition.math.signals.MovingAverageFilter
All Implemented Interfaces:
Evaluator<Double,Double>, StatefulEvaluator<Double,Double,FiniteCapacityBuffer<Double>>, Vectorizable, DiscreteTimeFilter<FiniteCapacityBuffer<Double>>, CloneableSerializable, Serializable, Cloneable

@PublicationReference(author="Wikipedia",
                      title="Finite impulse response",
                      type=WebPage,
                      year=2009,
                      url="http://en.wikipedia.org/wiki/Finite_impulse_response")
public class MovingAverageFilter
extends AbstractStatefulEvaluator<Double,Double,FiniteCapacityBuffer<Double>>
implements DiscreteTimeFilter<FiniteCapacityBuffer<Double>>

A type of filter using a moving-average calculation. That is, a finite window of inputs are scaled by a (possibly) unique coefficient and then summed together. In other words, y(n) = b(0)x(n) + b(1)x(n-1) + ... + b(m)x(n-m).

Since:
3.0
Author:
Kevin R. Dixon
See Also:
Serialized Form

Constructor Summary
MovingAverageFilter(double... coefficients)
          Creates a new instance of MovingAverageFilter
MovingAverageFilter(int numCoefficients)
          Creates a new instance of MovingAverageFilter
MovingAverageFilter(Vector movingAverageCoefficients)
          Creates a new instance of MovingAverageFilter
 
Method Summary
 MovingAverageFilter clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 void convertFromVector(Vector parameters)
          Converts the object from a Vector of parameters.
 Vector convertToVector()
          Converts the object to a vector.
 FiniteCapacityBuffer<Double> createDefaultState()
          Creates a new default state object.
 Double evaluate(Double input)
          Evaluates the object using the given input and current state objects, returning the output.
 Vector getMovingAverageCoefficients()
          Setter for movingAverageCoefficients
 int getNumMovingAverageCoefficients()
          Returns the number of coefficients in the moving-average filter.
 void setMovingAverageCoefficients(Vector movingAverageCoefficients)
          Setter for movingAverageCoefficients
 
Methods inherited from class gov.sandia.cognition.evaluator.AbstractStatefulEvaluator
evaluate, getState, resetState, setState
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.evaluator.StatefulEvaluator
evaluate, getState, resetState, setState
 

Constructor Detail

MovingAverageFilter

public MovingAverageFilter(int numCoefficients)
Creates a new instance of MovingAverageFilter

Parameters:
numCoefficients - Number of coefficients in the filter, with each coefficient having a value of 1.0/numCoefficients.

MovingAverageFilter

public MovingAverageFilter(double... coefficients)
Creates a new instance of MovingAverageFilter

Parameters:
coefficients - Coefficients of the moving-average filter. Element 0 is applied to the most-recent input, Element 1 is applied to the second-most-recent, and so forth.

MovingAverageFilter

public MovingAverageFilter(Vector movingAverageCoefficients)
Creates a new instance of MovingAverageFilter

Parameters:
movingAverageCoefficients - Coefficients of the moving-average filter. Element 0 is applied to the most-recent input, Element 1 is applied to the second-most-recent, and so forth. The dimensionality of the Vector is the order of the filter.
Method Detail

createDefaultState

public FiniteCapacityBuffer<Double> createDefaultState()
Description copied from interface: StatefulEvaluator
Creates a new default state object.

Specified by:
createDefaultState in interface StatefulEvaluator<Double,Double,FiniteCapacityBuffer<Double>>
Returns:
A new default state object.

evaluate

public Double evaluate(Double input)
Description copied from interface: StatefulEvaluator
Evaluates the object using the given input and current state objects, returning the output. The current state may be modified by side effect.

Specified by:
evaluate in interface Evaluator<Double,Double>
Specified by:
evaluate in interface StatefulEvaluator<Double,Double,FiniteCapacityBuffer<Double>>
Parameters:
input - The input to evaluate.
Returns:
output that results from the evaluation, state is modified by side effect

clone

public MovingAverageFilter clone()
Description copied from class: AbstractCloneableSerializable
This makes public the clone method on the Object class and removes the exception that it throws. Its default behavior is to automatically create a clone of the exact type of object that the clone is called on and to copy all primitives but to keep all references, which means it is a shallow copy. Extensions of this class may want to override this method (but call super.clone() to implement a "smart copy". That is, to target the most common use case for creating a copy of the object. Because of the default behavior being a shallow copy, extending classes only need to handle fields that need to have a deeper copy (or those that need to be reset). Some of the methods in ObjectUtil may be helpful in implementing a custom clone method. Note: The contract of this method is that you must use super.clone() as the basis for your implementation.

Specified by:
clone in interface Vectorizable
Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractStatefulEvaluator<Double,Double,FiniteCapacityBuffer<Double>>
Returns:
A clone of this object.

convertToVector

public Vector convertToVector()
Description copied from interface: Vectorizable
Converts the object to a vector.

Specified by:
convertToVector in interface Vectorizable
Returns:
The Vector form of the object.

convertFromVector

public void convertFromVector(Vector parameters)
Description copied from interface: Vectorizable
Converts the object from a Vector of parameters.

Specified by:
convertFromVector in interface Vectorizable
Parameters:
parameters - The parameters to incorporate.

getNumMovingAverageCoefficients

public int getNumMovingAverageCoefficients()
Returns the number of coefficients in the moving-average filter.

Returns:
Number of coefficients in the moving-average filter.

getMovingAverageCoefficients

public Vector getMovingAverageCoefficients()
Setter for movingAverageCoefficients

Returns:
Coefficients of the moving-average filter. Element 0 is applied to the most-recent input, Element 1 is applied to the second-most-recent, and so forth. The dimensionality of the Vector is the order of the filter.

setMovingAverageCoefficients

public void setMovingAverageCoefficients(Vector movingAverageCoefficients)
Setter for movingAverageCoefficients

Parameters:
movingAverageCoefficients - Coefficients of the moving-average filter. Element 0 is applied to the most-recent input, Element 1 is applied to the second-most-recent, and so forth. The dimensionality of the Vector is the order of the filter.