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.6.0.0-py3.9-macosx-10.15-x86_64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06e6e8267e90ba35b337fba9fa762d497b5b9f505b867dd08e75da9d04efd899 |
|
MD5 | 74177fe19df999c3f9a243e1005369ea |
|
BLAKE2b-256 | 185592653a9f54fd32cee4319f90e73e751cfc2c9bcd71dd414089e5d5399ed6 |
Hashes for fir1-1.6.0.0-py3.8-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7067319b1d26bf9f89449296262f5d94aac25d1fdeccff904689e3ab9e3cdb5b |
|
MD5 | 6e10903539027f524ec4643f6341c504 |
|
BLAKE2b-256 | 59c2b57642216d4d3fc286027fa7628d02a39dbd235bd14c5249265614ca70ef |
Hashes for fir1-1.6.0.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64922c3553bcb0b7ab343dbfb65c3d27b9de78f2d205a81f17ecba11b59e7e85 |
|
MD5 | a505b7474c4f249bf605cab76bb36ed1 |
|
BLAKE2b-256 | 943a47d2683e96b33eefab4ee566e0f691e3a68d5c8ddf5a7980966241b59279 |
Hashes for fir1-1.6.0.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e528ea2a13f9495f9f0a514616ea9430adaf42a9d43e35232b87da004d6000ec |
|
MD5 | be6e2eb90232c8e384984b091c4931a1 |
|
BLAKE2b-256 | a2c0b66ae8970f45cc96e0673a565c8c4c4d5ac4791600e29a18fbafa6491034 |