Skip to main content

COFRE: Complex-Pole Filter Representation for spectral estimation

Project description

cofre-spectrum

COFRE — Complex-Pole Filter Representation for spectral Estimation.

A Python implementation of the algorithm described in:

Pinto Orellana, Mirtaheri & Hammer (2021). COFRE: A complex-pole filter for spectral estimation. arXiv:2105.13476

COFRE estimates the power spectral density (PSD) at arbitrary target frequencies using a bank of first-order complex-pole IIR filters — each tuned to a single frequency. It is particularly effective for non-stationary or short signals where classical FFT-based methods struggle.

Installation

pip install cofre-spectrum

Quick start

from cofre_spectrum import cofre_estimate
import numpy as np

fs = 20.0                        # sampling rate (Hz)
signal = np.random.randn(10_000)

freqs, psd = cofre_estimate(signal, fs=fs)

Full API

One-liner

freqs, psd = cofre_estimate(
    x,
    fs=20.0,           # sampling rate (Hz)
    freq_min_hz=0.003, # lowest frequency of interest
    freq_max_hz=2.0,   # highest frequency of interest
    n_filters=200,     # number of log-spaced filters
    tau=8.65,          # bandwidth parameter
)

Filter bank with full control

from cofre_spectrum import COFREBank, COFREConfig

cfg = COFREConfig(
    fs=20.0,
    freq_min_hz=0.003,
    freq_max_hz=2.0,
    n_filters=200,
    tau=8.65,          # set τ directly …
    # delta_omega_hz=0.05  # … or derive τ from desired Hz resolution
)

bank = COFREBank(cfg)
bank.process_vectorized(signal)   # batch mode (faster)
freqs, psd = bank.get_spectrum()  # Hz, PSD

bank.summary()  # print configuration table

Single filter (online / streaming)

from cofre_spectrum import COFREFilter

filt = COFREFilter(freq_hz=0.1, fs=20.0, tau=8.65)
for sample in stream:
    filt.update(sample)
print(filt.spectrum_estimate)   # PSD at 0.1 Hz

Choosing τ from a desired resolution

from cofre_spectrum import optimal_tau_for_frequency

# τ that gives 0.05 Hz resolution at α = 0.5
tau = optimal_tau_for_frequency(delta_omega=0.05 / 20.0, alpha=0.5)

Parameter guide

Parameter Effect
tau (τ) Higher τ → narrower bandwidth, finer frequency resolution, longer rise time
n_filters More filters → denser spectral grid
log_spacing Log-spaced frequencies (default) suit logarithmic spectral analysis
alpha (α) Cut-off fraction for frequency resolution definition (Eq. 18)
beta (β) Cut-off fraction for rise-time definition (Eq. 20)

Reference

Pinto Orellana, A., Mirtaheri, P., & Hammer, H. L. (2021). Complex-Pole Filter Representation for Spectral Estimation (COFRE). arXiv:2105.13476

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cofre_spectrum-0.1.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cofre_spectrum-0.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file cofre_spectrum-0.1.0.tar.gz.

File metadata

  • Download URL: cofre_spectrum-0.1.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for cofre_spectrum-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1e4317e773dd3b7073aa3cdc137e80d475e6b0c447415e92232f811405819341
MD5 7d8e8fcd2fa77c24c5f60662739cc08a
BLAKE2b-256 5dd28f1f9b2be35d6f2644257a78b166e95f0db4a279d1f6760b11712e543d0a

See more details on using hashes here.

File details

Details for the file cofre_spectrum-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cofre_spectrum-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for cofre_spectrum-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 91f2af2675cb8814ab2d614be80417ef669c84bcc8481fd3ba4520c1fc2a4642
MD5 1264220bdbcbb01ebe665eff95ef98a5
BLAKE2b-256 1341f25ae8be5897c60be93fe9fb50363cb527dea634be2fc3c564d5b09685f8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page