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.7.0.0-py3.8-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76836ae3556bc9abe5fac90c1281451a95cb27065fdba19b871f045927006c6e |
|
MD5 | bb1418a0449bd0d3e5ee291274c60558 |
|
BLAKE2b-256 | 247a5f6dd59b22617519d73ddaea7903e7f5128aaf0396b837f68e6196c65ca5 |
Hashes for fir1-1.7.0.0-py3.8-macosx-10.14.6-x86_64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3888abf383c706dcae14cd719da3171e4cc8bc0b47b3dcb294df5f8caae65b0 |
|
MD5 | 036de9ebf53b083ca4fac5ec2a56502d |
|
BLAKE2b-256 | 04581d7853dfefc685995f451988ce92601b620a2dca63af0ddb71cf5f2bab33 |
Hashes for fir1-1.7.0.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 856ee20c78dfe2c08ded209d741ef33c10aff252ecc54d9e6783b24d88615cd2 |
|
MD5 | bc7693966b3f525e0c3fbc5461565257 |
|
BLAKE2b-256 | e5e686b4ba2e74ff0470ca125b43aa18a63de5b5da3174d49fce6452b0b37320 |