Skip to content

Add prony and invfreqz, IIR fits in the time and frequency domains - #110

Open
aguirreSL wants to merge 1 commit into
PyTTaMaster:developmentfrom
aguirreSL:dev-prony
Open

aguirreSL wants to merge 1 commit into
PyTTaMaster:developmentfrom
aguirreSL:dev-prony

Conversation

@aguirreSL

Copy link
Copy Markdown

Adds to pytta.functions the two fits of ita_prony_analysis of the ITA-Toolbox, which give the coefficients of an IIR filter from a measured response:

  1. prony(h, nb, na): Prony's method in the time domain (Parks and Burrus, Digital Filter Design, 1987). The denominator fits the samples after nb by least squares, and the numerator then matches the first nb + 1 samples exactly.
  2. invfreqz(H, w, nb, na, weights=None): the linear equation error fit in the frequency domain of Levi, "Complex curve fitting", IRE Trans. Automatic Control 4(1), 1959, which minimizes Σ weights |B(w) - H(w) A(w)|², as MATLAB's invfreqz without iterations. SciPy has no such function.

Both return b and a with a[0] = 1; scipy.signal.tf2zpk(b, a) gives the zeros and poles that ita_prony_analysis returns. The ITA-Toolbox calls MATLAB's invfreqz and, for the time domain, pdi_prony, a copy of MATLAB's prony; neither was ported, and both functions here are written from the references.

The tests in tests/test_prony.py recover known filters and print the largest relative difference of the coefficients:

  1. prony recovers a filter with three zeros and the five poles of a Chebyshev type I filter from 200 samples of its impulse response (9.0e-14).
  2. invfreqz recovers a fourth-order Butterworth filter from its response at 512 frequencies (1.2e-14).

Checked with Python 3.12, numpy 1.26 and scipy 1.17. The 7 failures of development (3 in test_h5io.py, 4 in test_pyttasave.py) are the same with and without this change.

Co-Authored-By: Claude Fable 5.1 noreply@anthropic.com

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant