Skip to content

[FIX] make weighting work and evaluate it at the frequencies of IEC 61672-1 - #130

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

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

Conversation

@aguirreSL

Copy link
Copy Markdown

Summary

pytta.weighting, which is exported at the top level of the package, fails on every call, and when its curves are evaluated by hand at the nominal frequencies they differ from IEC 61672-1:2013, Table 3, by up to 0.13 dB. This pull request makes it work and evaluates it at the exact frequencies that Table 3 uses.

What was found

Each way of calling the function raised an error:

  1. pytta.weighting('A', nth=1) and the call with freqs ended in np.asarray(out, ndmin=2), and numpy.asarray has no ndmin argument (numpy.array has).
  2. pytta.weighting('A', nth=3) evaluated A(...) through eval, a name that does not exist (the curves are __A, __C, ...).
  3. freqs had to be given as strings, since each value was pasted into the string passed to eval.

The curves themselves, __A, __B, __C and __D, are right: they are the analytical expressions of Annex E with the constants that the 2013 text gives (20.60 Hz, 107.7 Hz, 737.9 Hz and 12 194 Hz). The function evaluated them at the nominal frequencies (31.5 Hz, 16 kHz). Table 3 gives them at the exact frequencies f = 1000 × 10^(0.1(n − 30)), as its note says. Evaluated at the nominal frequencies, A is −39.53 dB at 31.5 Hz where Table 3 gives −39.4 dB, and −6.71 dB at 16 kHz where it gives −6.6 dB.

The change

weighting(kind, nth, freqs) now computes the chosen curve directly. With nth=3 it gives the one-third octave bands from 20 Hz to 20 kHz and with nth=1 the octave bands from 31.5 Hz to 16 kHz, both at the exact frequencies of Table 3. freqs takes numbers and uses them as they are. The result keeps its former shape, one row per frequency, and an unknown kind or a call without nth or freqs raises ValueError. The constants and the curves are unchanged.

Tests

The tests in tests/test_weighting.py compare with Table 3:

  1. A and C in the 31 one-third octave bands from 20 Hz to 20 kHz lie within 0.05 dB of the table, which is what its rounding to 0.1 dB allows. For example, A at 160 Hz is −13.35 dB, which the table rounds to −13.4 dB.
  2. The octave bands are every third one-third octave band from 31.5 Hz, given frequencies are used as they are (C at 31.5 Hz is −3.03 dB), and an unknown kind raises ValueError.

Both fail without this change. 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

…1672-1

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