[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-10-30 19:43:34 +00:00
parent 1f1c1b073c
commit 2e1193507b

View File

@ -7,11 +7,12 @@ https://en.wikipedia.org/wiki/Moving_average
import numpy as np
from typing import List
class EMAFilter:
"""
A class for applying an Exponential Moving Average (EMA) filter
to audio data.
Attributes:
alpha (float): Smoothing factor where 0 < alpha <= 1.
ema_value (float): Stores the most recent EMA value
@ -24,7 +25,7 @@ class EMAFilter:
Parameters:
alpha (float): Smoothing factor where 0 < alpha <= 1.
Raises:
ValueError: If alpha is not within the range (0, 1].
"""
@ -47,7 +48,7 @@ class EMAFilter:
Example:
>>> ema_filter = EMAFilter(0.2)
>>> np.allclose(ema_filter.apply([0.1, 0.5, 0.8, 0.6, 0.3, 0.9, 0.4]),
>>> np.allclose(ema_filter.apply([0.1, 0.5, 0.8, 0.6, 0.3, 0.9, 0.4]),
... [0.1, 0.18, 0.304, 0.3632, 0.35056, 0.460448, 0.4483584])
True
"""
@ -62,6 +63,8 @@ class EMAFilter:
ema_signal.append(self.ema_value)
return np.array(ema_signal)
if __name__ == "__main__":
import doctest
doctest.testmod()