Skip to content

Moving Average

eitprocessing.features.moving_average.MovingAverage dataclass

MovingAverage(
    window_size: int,
    window_function: Callable | None = None,
    padding_type: str = "edge",
)

Algorithm for calculating the moving average of the data.

This class provides a method for calculating of the moving average of a 1D signal by convolution with a window with a given size. If not window function is provided, all samples within that window contribute equally to the moving average. If a window function is provided, the samples are weighed according to the values in the window function.

Before convolution the data is padded. The padding type is 'edge' by default. See np.pad() for more information. Padding adds values at the start and end with the first/last value, to more accurately determine the average at the boundaries of the data.

PARAMETER DESCRIPTION
window_size

the number of data points in the averaging window. Should be odd; is increased by 1 if even.

TYPE: int

window_function

window function, e.g. np.blackman.

TYPE: Callable | None DEFAULT: None

padding_type

see np.pad().

TYPE: str DEFAULT: 'edge'

RETURNS DESCRIPTION

np.ndarray: moving average of data with the same shape as data.

apply

apply(data: ndarray) -> ndarray

Apply the moving average on the data.

PARAMETER DESCRIPTION
data

input data as 1D array

TYPE: NDArray