Skip to content

[FIX] find_delay and corr_coef, with an example of pytta.functions - #63

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

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

Conversation

@aguirreSL

@aguirreSL aguirreSL commented Oct 31, 2026 •

Copy link
Copy Markdown

Adds examples/functions_module.py, asked for in #13. It shows each function of pytta.functions in turn: list_devices, merge and split, fft_convolve, find_delay, corr_coef, resample, peak_time, SPL, wave and HDF5 files, and the plots.

Writing it showed that two of these functions did not work:

  1. find_delay read signal1.N, which SignalObj does not have, so it always raised AttributeError. It also multiplied a half spectrum by a full one. It now takes the peak of scipy.signal.correlate of the first channels and returns the delay in samples, positive when the second signal comes later, for signals of any length.
  2. corr_coef passed (samples, 1) arrays to numpy.corrcoef, which takes each row as a variable. It built a matrix with twice as many rows and columns as samples (73 GB for one second at 48 kHz) and returned the correlation between two single samples, which is nan. It now correlates the first channels.

The tests in tests/test_delay_and_correlation.py check a delay of 100 samples in both directions with signals of different lengths, and a correlation of 1 with itself and -1 with its negative.

The example needs #52 and #53 to run as a script on Python 3.12 (for pytta.generate and pytta.resample). With them, it runs to the end. The index of the module docstring also had pytta.slipt, now pytta.split.

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

find_delay read signal1.N, which SignalObj does not have, so it always
raised AttributeError; it also multiplied a half spectrum by a full one.
It now takes the peak of scipy.signal.correlate of the first channels and
returns the delay in samples, positive when the second signal comes
later, for signals of any length.

corr_coef passed (samples, 1) arrays to numpy.corrcoef, which takes each
row as a variable: it built a matrix of twice the number of samples on
each side (73 GB for one second at 48 kHz) and returned the correlation
of two samples. It now correlates the first channels.

examples/functions_module.py shows each function of the module.

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