Skip to content

pyFRI.tools.filters

Chris Mower edited this page Jul 24, 2023 · 1 revision

The pyFRI.tools.filters module provides a set of filters to smooth state signals.

StateFilter

Abstract state filter class that provides functionality for a filter implementation.

A sub-class must provide an implementation for the filter method. E.g.

class MyFilter(StateFilter):

    def filter(self, x):
        # ..filter implementation..

StateFilter.__init__(window_size)

Constructor for the StateFilter class.

Parameters

  • window_size [int]: The size of the data window used in the filtering process. The filter will operate on the most recent window_size joint states.

StateFilter.reset()

Reset the internal data buffer. This method clears the data buffer, removing all previously stored states.

StateFilter.append(x)

Update the internal data buffer with new state.

This method maintains the buffer's size to the specified window_size, discarding older states when the buffer size exceeds window_size.

Parameters

  • x [numpy.ndarray]: array containing the most recent state to be added to the data buffer.

xf = StateFilter.filter(x)

Abstract method to be implemented by subclasses. This method applies the specific filtering algorithm to the given state.

Parameters:

  • x [numpy.ndarray]: The state to be filtered.

Returns:

  • xf [numpy.ndarray]: The filtered states based on the specific filtering algorithm.

ExponentialStateFilter(StateFilter)

The ExponentialStateFilter implements the exponential smoothing algorithm.

ExponentialStateFilter.__init__(smooth=0.02)

Constructor for the ExponentialStateFilter class.

Parameters

  • smooth [float]: The smoothing factor used in the filter update. The value must be a float in the range [0, 1].

MovingAverageFilter

The MovingAverageFilter implements the simple moving average algorithm.