adafilt
This package implements some common (adaptive) filtering operations in Python, that I use mostly for prototyping system identification and active noise control systems.
adafilt.olafilt: an efficient multichannel overlap-add algorithm for long sequencesadafilt.FIRFilter: finite-impulse response filteradafilt.Delay: a simple delayadafilt.LMSFilter: a sample-wise Least-Mean-Square adaptive filteradafult.FastBlockLMSFilter: fast, block-wise LMS adaptive filter based on overlap-save sectioningadafilt.MultiChannelBlockLMS: same for multi-channel caseadafilt.RLSFilter: a recursive Least-Squares filter
The following procedures compute optimal Wiener-filters from time-series:
adafilt.optimal.wiener_filter: compute optimal (causally constrained) Wiener filter for single-channel controladafilt.optimal.multi_channel_wiener_filter: compute optimal wiener filter for multi-channel control
Additionally, adafilt.io.FakeInterface can be used to simulate a multichannel plant.
Have a look at the examples, the source code or the following example to get an idea what is possible.
"""A filtered-reference Least-Mean-Square (FxLMS) filter."""
import numpy as np
import matplotlib.pyplot as plt
from adafilt import FastBlockLMSFilter, FIRFilter, olafilt
from adafilt.io import FakeInterface
from adafilt.utils import wgn
length = 8 # number of adaptive FIR filter taps
blocklength = 2 # length of I/O buffer and blocksize of filter
n_buffers = 150 # size of simulation
# primary and secondary paths
h_pri = [0, 0, 0, 0, 0, 0, 0, 0.5]
h_sec = [0, 0, 0, 1, 0, 0, 0, 0]
# white noise signal
signal = np.random.normal(0, 1, size=n_buffers * blocklength)
# the adaptive filter
filt = FastBlockLMSFilter(length, blocklength, stepsize=0.1, leakage=0.9999)
# secondary path estimate has to account for block size
plant_model = FIRFilter(np.concatenate((np.zeros(blocklength), h_sec)))
# simulates an audio interface with primary and secondary paths and 40 dB SNR noise
# at the error sensor
sim = FakeInterface(
blocklength,
signal,
h_pri=h_pri,
h_sec=h_sec,
noise=wgn(olafilt(h_pri, signal), 40, "dB"),
)
elog = []
y = np.zeros(blocklength) # control signal is zero for first block
for i in range(n_buffers):
# record reference signal x and error signal e while playing back y
x, e, _, _ = sim.playrec(-y)
# filter the reference signal
fx = plant_model(x)
# adapt filter
filt.adapt(fx, e)
# filter
y = filt.filt(x)
# log error
elog.append(e)
plt.plot(np.concatenate(elog), label="e", alpha=0.7)
plt.xlabel("Sample")
plt.ylabel("Error Signal")
plt.show()
Find the full example here.
Happy coding!
Metadata
Release files for adafilt 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| adafilt-0.1.0.tar.gz | 12.4 kB | Without provenance | Details for adafilt-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| adafilt-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for adafilt-0.1.0-py3-none-any.whl |
Total release size: 26.6 kB
Release files / adafilt-0.1.0.tar.gz
| Download URL | adafilt-0.1.0.tar.gz |
|---|---|
| Size | 12.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a41b2cb062df0c91b95ce237ae4f486ff4253ffbaf7e27fbc7d91c4b46604a9b
|
|
BLAKE2b-256 checksum How to use checksums |
4449ccb8ba4f6c43659541cd5c7a0d992ae0eeb87213a695a48d6a6592d5fda2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.27.2
|
Release files / adafilt-0.1.0-py3-none-any.whl
| Download URL | adafilt-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a76d62df5cc5cf69b50ecd58f5be91097fb0162a883a9d796ce2199c2e0cd2c6
|
|
BLAKE2b-256 checksum How to use checksums |
0f6c39e0a0e8378004dc9dbf4b6b00591b07aae301764061e6e144772a7b3646
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.27.2
|
Security for adafilt 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.