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.4.0.0-py3.8-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25483448d3db673821c4174357ff3a1fef50807e4adc7afa0b047370c5684409 |
|
MD5 | 2a1c396287b6cb3fc1f2661bda9b49de |
|
BLAKE2b-256 | 727fa6de6bda6d3ec60308514388c61d934c2d5ae07db72830173b1f4fe47737 |
Hashes for fir1-1.4.0.0-py3.6-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51bdaa962356d5f681fa3948d3bce1376ea25c44fa25d9440f8c36f9fee3f3f8 |
|
MD5 | 77376e6ff32252d9e9a65e4820a6dc71 |
|
BLAKE2b-256 | 2a9d9fea731c0233de9bc4dd17f46ae211d75ca2bdcd7d43d75e4cefd0925c5d |
Hashes for fir1-1.4.0.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9724667f1fb111ebb9262b7d2281137ffa115178d0764b689867463c979cbdf |
|
MD5 | a846e1924deea6724117d7882e7e214e |
|
BLAKE2b-256 | 0f1aa44dd2d7e68195c403aa82a49cd195e1c49999ee82f1d0df7056b4240767 |
Hashes for fir1-1.4.0.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 561aa23830e08ecaed645ec8584aeb05e5f6700aca24b5afb39dbc0becff46f5 |
|
MD5 | a97ca1f6180a8be24026b4ac3255302f |
|
BLAKE2b-256 | f2e81e41711c6441d6d4c974d7152ddfac4f4a4f1182c2f3e881e070a60476e9 |