Efficient FIR realtime filter
Project description
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.
Installation
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
Usage
Realtime filtering
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:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for fir1-1.5.0.0-py3.9-macosx-10.15-x86_64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b3cd1be4a88a991090f37b5b2e0e92f9ef5346f1a13a9e6829f71712e5de3f3 |
|
MD5 | 0aff4527bff0d31df680d63656f59975 |
|
BLAKE2b-256 | 6e11dd147621afef0237b9220b9bdeca2691b42c24e771b30005b678be248e8b |
Hashes for fir1-1.5.0.0-py3.8-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 824984949b6237f89777a898f273a0fbb8644216efb675b0b4eeaa9071041321 |
|
MD5 | bc22b02260afd9b533f87672c6bbdf29 |
|
BLAKE2b-256 | 807237f75ae36086bcb2f0d11bfde2d69daf77eab78a7021ea98c80311fbe6a2 |
Hashes for fir1-1.5.0.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df821d9c0ddd753b90a965eb82bdf81153b9da08e99cd62173cedfc26f3374e3 |
|
MD5 | 7143c5df7122247f3b902764f0ddbd55 |
|
BLAKE2b-256 | ef066a764a16f872240c13b1c1e09401188a918a248b3f37be5d869e3000cbb9 |
Hashes for fir1-1.5.0.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7290ba8408fee063e70cc6e64e0ca073b06a39814c3a3bec4c7a970c5783e3a8 |
|
MD5 | fbe1ef3840498c224bf03c9e2cedd0af |
|
BLAKE2b-256 | b66cc1551ceb21f8b309553a955aee831faf45f403145437dfd05061f583f3c6 |