Name | adafilt JSON |
Version |
0.1.0
JSON |
| download |
home_page | None |
Summary | Adaptive filters for 🐍 |
upload_time | 2024-11-23 23:03:42 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | MIT License
Copyright (c) [2018] [Franz M. Heuchel]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
|
keywords |
adaptive-filters
dsp
signal-processing
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
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 sequences
- `adafilt.FIRFilter`: finite-impulse response filter
- `adafilt.Delay`: a simple delay
- `adafilt.LMSFilter`: a sample-wise Least-Mean-Square adaptive filter
- `adafult.FastBlockLMSFilter`: fast, block-wise LMS adaptive filter based on overlap-save sectioning
- `adafilt.MultiChannelBlockLMS`: same for multi-channel case
- `adafilt.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 control
- `adafilt.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](examples), the source code or the following example to get an idea what is possible.
```python
"""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](https://github.com/fhchl/adafilt/blob/master/examples/fxLMS.py).
Happy coding!
Raw data
{
"_id": null,
"home_page": null,
"name": "adafilt",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "adaptive-filters, dsp, signal-processing",
"author": null,
"author_email": "\"Franz M. Heuchel\" <franz.heuchel@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/44/49/ccb8ba4f6c43659541cd5c7a0d992ae0eeb87213a695a48d6a6592d5fda2/adafilt-0.1.0.tar.gz",
"platform": null,
"description": "adafilt\n========\n\nThis package implements some common (adaptive) filtering operations in Python, that I use mostly for prototyping system identification and active noise control systems.\n\n- `adafilt.olafilt`: an efficient multichannel overlap-add algorithm for long sequences\n- `adafilt.FIRFilter`: finite-impulse response filter\n- `adafilt.Delay`: a simple delay\n- `adafilt.LMSFilter`: a sample-wise Least-Mean-Square adaptive filter\n- `adafult.FastBlockLMSFilter`: fast, block-wise LMS adaptive filter based on overlap-save sectioning\n- `adafilt.MultiChannelBlockLMS`: same for multi-channel case\n- `adafilt.RLSFilter`: a recursive Least-Squares filter\n\nThe following procedures compute optimal Wiener-filters from time-series:\n\n- `adafilt.optimal.wiener_filter`: compute optimal (causally constrained) Wiener filter for single-channel control\n- `adafilt.optimal.multi_channel_wiener_filter`: compute optimal wiener filter for multi-channel control\n\nAdditionally, `adafilt.io.FakeInterface` can be used to simulate a multichannel plant.\n\nHave a look at the [examples](examples), the source code or the following example to get an idea what is possible.\n\n```python\n\"\"\"A filtered-reference Least-Mean-Square (FxLMS) filter.\"\"\"\n\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nfrom adafilt import FastBlockLMSFilter, FIRFilter, olafilt\nfrom adafilt.io import FakeInterface\nfrom adafilt.utils import wgn\n\nlength = 8 # number of adaptive FIR filter taps\nblocklength = 2 # length of I/O buffer and blocksize of filter\nn_buffers = 150 # size of simulation\n\n# primary and secondary paths\nh_pri = [0, 0, 0, 0, 0, 0, 0, 0.5]\nh_sec = [0, 0, 0, 1, 0, 0, 0, 0]\n\n# white noise signal\nsignal = np.random.normal(0, 1, size=n_buffers * blocklength)\n\n# the adaptive filter\nfilt = FastBlockLMSFilter(length, blocklength, stepsize=0.1, leakage=0.9999)\n\n# secondary path estimate has to account for block size\nplant_model = FIRFilter(np.concatenate((np.zeros(blocklength), h_sec)))\n\n# simulates an audio interface with primary and secondary paths and 40 dB SNR noise\n# at the error sensor\nsim = FakeInterface(\n blocklength,\n signal,\n h_pri=h_pri,\n h_sec=h_sec,\n noise=wgn(olafilt(h_pri, signal), 40, \"dB\"),\n)\n\nelog = []\ny = np.zeros(blocklength) # control signal is zero for first block\nfor i in range(n_buffers):\n # record reference signal x and error signal e while playing back y\n x, e, _, _ = sim.playrec(-y)\n # filter the reference signal\n fx = plant_model(x)\n # adapt filter\n filt.adapt(fx, e)\n # filter\n y = filt.filt(x)\n # log error\n elog.append(e)\n\nplt.plot(np.concatenate(elog), label=\"e\", alpha=0.7)\nplt.xlabel(\"Sample\")\nplt.ylabel(\"Error Signal\")\nplt.show()\n\n```\n\nFind the full example [here](https://github.com/fhchl/adafilt/blob/master/examples/fxLMS.py).\n\nHappy coding!\n",
"bugtrack_url": null,
"license": "MIT License\n \n Copyright (c) [2018] [Franz M. Heuchel]\n \n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n \n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n \n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n ",
"summary": "Adaptive filters for \ud83d\udc0d",
"version": "0.1.0",
"project_urls": {
"repository": "https://github.com/fhchl/adafilt"
},
"split_keywords": [
"adaptive-filters",
" dsp",
" signal-processing"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "0f6c39e0a0e8378004dc9dbf4b6b00591b07aae301764061e6e144772a7b3646",
"md5": "01001f4809d9c5908c2a8c9905f1f4cb",
"sha256": "a76d62df5cc5cf69b50ecd58f5be91097fb0162a883a9d796ce2199c2e0cd2c6"
},
"downloads": -1,
"filename": "adafilt-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "01001f4809d9c5908c2a8c9905f1f4cb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 14162,
"upload_time": "2024-11-23T23:03:40",
"upload_time_iso_8601": "2024-11-23T23:03:40.564511Z",
"url": "https://files.pythonhosted.org/packages/0f/6c/39e0a0e8378004dc9dbf4b6b00591b07aae301764061e6e144772a7b3646/adafilt-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "4449ccb8ba4f6c43659541cd5c7a0d992ae0eeb87213a695a48d6a6592d5fda2",
"md5": "40a6af9a186985f4ddb946ce5ac80e7b",
"sha256": "a41b2cb062df0c91b95ce237ae4f486ff4253ffbaf7e27fbc7d91c4b46604a9b"
},
"downloads": -1,
"filename": "adafilt-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "40a6af9a186985f4ddb946ce5ac80e7b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 12397,
"upload_time": "2024-11-23T23:03:42",
"upload_time_iso_8601": "2024-11-23T23:03:42.505119Z",
"url": "https://files.pythonhosted.org/packages/44/49/ccb8ba4f6c43659541cd5c7a0d992ae0eeb87213a695a48d6a6592d5fda2/adafilt-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-23 23:03:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "fhchl",
"github_project": "adafilt",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "adafilt"
}