optcutfreq
Automatic search of optimal filter cutoff frequency based on residual analysis
The ‘optimal’ cutoff frequency (in the sense that a filter with such cutoff frequency removes as much noise as possible without considerably affecting the signal) is found by performing a residual analysis of the difference between filtered and unfiltered signals over a range of cutoff frequencies.
The optimal cutoff frequency is the one where the residual starts to change very little because it is considered that from this point, it’s being filtered mostly noise and minimally signal, ideally.
Installation
pip install optcutfreq
The plots (parameter show=True) require matplotlib, which can be installed together with:
pip install "optcutfreq[plot]"
Or
conda install -c duartexyz optcutfreq
Examples
>>> import numpy as np
>>> from optcutfreq import optcutfreq
>>> y = np.cumsum(np.random.randn(1000))
>>> # optimal cutoff frequency based on residual analysis and plot:
>>> fc_opt = optcutfreq(y, freq=1000, show=True)
>>> # sane analysis but specifying the frequency limits and plot:
>>> optcutfreq(y, freq=1000, fclim=[200,400], show=True)
>>> # It's not always possible to find an optimal cutoff frequency
>>> # or the one found can be wrong (run this example many times):
>>> y = np.random.randn(100)
>>> optcutfreq(y, freq=100, show=True)
Explore Winter’s benchmark data in your browser, no installation needed:
- optcutfreq · saved outputs ·
·
Or run it locally:
uvx marimo edit --sandbox docs/optcutfreq_notebook.py
How to cite this work
Here is a suggestion to cite this software, with its concept DOI, which always resolves to the latest version (to cite a specific version, use its DOI listed on Zenodo):
Marcos Duarte. (2021). optcutfreq: A Python module for automatic search of optimal filter cutoff frequency based on residual analysis. Zenodo. https://doi.org/10.5281/zenodo.4599113
And a possible BibTeX entry:
@software{duarte_optcutfreq,
author = {Marcos Duarte},
title = ,
year = 2021,
publisher = {Zenodo},
doi = {10.5281/zenodo.4599113},
url = {https://doi.org/10.5281/zenodo.4599113}
}
License
The non-software content of this project is licensed under a Creative Commons Attribution 4.0 International License, and the software code is licensed under the MIT license.