Efficient FIR realtime filter
An efficient Finite Impulse Response (FIR) filter class written in C++ with python wrapper.
Adaptive filtering is also implemented using the Least Mean Square (LMS) or Normalised Least Mean Square (NLMS) algorithm.
Install the python package with pip:
pip3 install fir1
You can also install from source:
git clone https://github.com/berndporr/fir1 cd fir1 python3 setup.py install
The filter is a realtime filter which receives samples one by one so it can process data as it arrives from an ADC converter. This is simulated here with the for loop:
import fir1 b = signal.firwin(999,0.1) f = fir1.Fir1(b) for i in range(len(noisy_signal)): clean_signal[i] = f.filter(noisy_signal[i])
The constructor Fir1() receives the filter coefficients (= impulse response) and then filtering is performed with the method filter().
LMS adaptive filter
The file lms_50Hz_ecg_filter.py removes 50Hz from an ECG with the help of the lms filter. The filter learns its own frequency response from a reference 50Hz sine wave:
f = fir1.Fir1(NTAPS) f.setLearningRate(LEARNING_RATE); y= np.empty(len(ecg)) for i in range(len(ecg)): ref_noise = np.sin(2.0 * np.pi / 20.0 * i); canceller = f.filter(ref_noise) output_signal = ecg[i] - canceller f.lms_update(output_signal) y[i] = output_signal
Both the demo file and an explanation how the LMS filter works can be found on the homepage of the project:
Release history Release notifications
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size & hash||File type||Python version||Upload date|
|fir1-126.96.36.199-cp36-cp36m-win_amd64.whl (28.6 kB) View hashes||Wheel||3.6|
|fir1-188.8.131.52-py3.6-win-amd64.egg (31.7 kB) View hashes||Egg||3.6|
|fir1-184.108.40.206.tar.gz (18.7 kB) View hashes||Source||None|
Hashes for fir1-220.127.116.11-cp36-cp36m-win_amd64.whl
Hashes for fir1-18.104.22.168-py3.6-win-amd64.egg