kblomqvist / kblom.py

My Python library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

kblom.py

Python3 license

Installation (editable)

git clone https://github.com/kblomqvist/kblom.py.git
pip3 install -e kblom.py

Update library

cd kblom.py
git pull

Timeseries

Rolling window (aka sliding window)

Built-in rolling window filters: RollingMean, RollingMedian, RollingRootMeanSquare, RollingMax

You can create your own rolling window by inheriting from RollingWindow, e.g. rolling median filter has been implemented like this

from kblom.dsp import timeseries as ts

class RollingMedian(ts.RollingWindow):

    def window_operation(self, window):
        return np.median(window)

and it would be used like this

m = RollingMedian(window_len=0.1, fs=175)  # window_len is in seconds and fs in Hz
x = range(100)
y = list(m.roll(x, end=True))              # roll() returns a generator thus list()

Window length can also be given in integer instead of seconds. Just omit the fs, but make sure that your window length is an odd number. That's because the output signal will be delayled by (N-1)/2. Additionally, if you like to use the rolling window for real-time signals you can make consecutive calls to roll().

About

My Python library

License:MIT License


Languages

Language:Python 100.0%