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.3.0.12-py3.6-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 568a0a06de3fb7e0805f24ec4cb1da57c25a62e68610f271ac9cee103edb1cf7 |
|
MD5 | 1d8011d366a711f6b593576733750ce7 |
|
BLAKE2b-256 | 836e3a83b9856c698de1629ae17b86493d7da2ab3794ade76bf6e2866b881d2d |
Hashes for fir1-1.3.0.12-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f164d0c680eb731007c7301bf980d60a1444b5058df00f00ff76ab56322d8ac1 |
|
MD5 | 2d847c391774f0b2ef35fd31e42e878e |
|
BLAKE2b-256 | 8c4d988baf7747eba3f1c54236afcb46706d3f068161e714dc9ff4da4b54053b |