Skip to content

[FEATURE] add pytta.response with quality factor, cutoffs and step metrics - #74

Open
aguirreSL wants to merge 2 commits into
PyTTaMaster:developmentfrom
aguirreSL:dev-response
Open

aguirreSL wants to merge 2 commits into
PyTTaMaster:developmentfrom
aguirreSL:dev-response

Conversation

@aguirreSL

@aguirreSL aguirreSL commented Oct 31, 2026 •

Copy link
Copy Markdown

Adds the module pytta.response, with measures of the response of a linear system asked for in #33. They use the first channel of the SignalObj.

  1. resonance(signalObj, fmin=0, fmax=None): resonance frequency, quality factor and -3 dB bandwidth of the highest peak of the magnitude response, with Q = f0 / bandwidth and the half-power points interpolated on the squared magnitude.
  2. q_from_decay(signalObj, f0): quality factor from the decay, Q = pi f0 tau, with tau the time constant of the Hilbert envelope fitted between -5 and -35 dB.
  3. cutoff_frequencies(signalObj): lower and upper -3 dB frequencies around the maximum (nan for a side that does not fall by 3 dB).
  4. passband_ripple(signalObj, fmin, fmax): peak-to-valley variation in dB.
  5. step_metrics(signalObj, final=None, tolerance=0.02): rise time from 10 % to 90 %, overshoot, and settling time within the tolerance, of a step response (nan when the signal does not reach or does not settle).
  6. bifurcation(params, recordings, freq=None, rise=20): for recordings along a sweep of a control parameter (gain, blowing pressure), first up and then down, the amplitude of the oscillation in each (the spectral peak within 5 % of freq, or the rms), the onset going up, the extinction going down and the hysteresis between them. A recording oscillates when its amplitude is rise dB above the quietest one.

The tests in tests/test_response.py use systems with exact values:

System Expected Measured
Resonator, 1 kHz, Q = 10 Q = 10 by both definitions 10.000 (bandwidth), 9.998 (decay)
Resonator, 250 Hz, Q = 30 Q = 30 by both definitions 30.000, 30.000
Butterworth band-pass, 500 to 2000 Hz -3 dB at the design edges within 0.2 %
Chebyshev type I low-pass, rp = 1 dB 1 dB ripple within 0.02 dB
First-order step, tau = 10 ms rise tau ln 9, settling (2 %) tau ln 50, no overshoot within 2 samples
Second-order step, zeta = 0.2 and 0.5 overshoot exp(-pi zeta / sqrt(1 - zeta^2)) 0.5266 and 0.1630, as expected
Subcritical sweep, onset 1.0 up, extinction 0.6 down hysteresis 0.4 1.0, 0.6, 0.4

Checked with Python 3.12, numpy 1.26 and scipy 1.17. The existing tests behave as on development: the 7 failures there (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

aguirreSL and others added 2 commits October 31, 2026 21:26
…trics

Resonance frequency and quality factor from the -3 dB bandwidth of the
magnitude response and from the decay of the envelope (Q = pi f0 tau),
-3 dB cutoff frequencies, passband ripple, and the rise time, overshoot
and settling time of a step response.

Tests use systems with exact values: second-order resonators of known Q
for both definitions, a Butterworth band-pass and a Chebyshev low-pass,
a first-order step (rise tau ln 9, settling tau ln 50) and second-order
steps (overshoot exp(-pi zeta / sqrt(1 - zeta^2))).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
response.bifurcation takes recordings along a sweep of a control
parameter, up and then down, measures the amplitude of the oscillation
in each (spectral peak near a given frequency, or rms), and returns the
onset going up, the extinction going down and the hysteresis between
them. The test uses a synthetic subcritical sweep with known thresholds.

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