Skip to content

Rename and improve freq parameter in the edc module#152

Open
h-chmeruk wants to merge 7 commits into
developfrom
fix/rename_freq_parameter
Open

Rename and improve freq parameter in the edc module#152
h-chmeruk wants to merge 7 commits into
developfrom
fix/rename_freq_parameter

Conversation

@h-chmeruk
Copy link
Copy Markdown
Contributor

Which issue(s) are closed by this pull request?

Closes #123

Changes proposed in this pull request:

  • Renamed the freq parameter to smoothing_parameter everywhere in the code, including in the files examples/energy_decay_curves_and_reverberation_time.ipynb and tests/test_data/test_notebook.ipynb
  • Improved the docstring describing the smoothing_parameter
  • Modified the function dsp._smooth_rir(data, sampling_rate, smooth_block_length=0.075) so that smooth_block_length can be an array-like value.
  • Added two new test functions: test_intersection_time_smoothing_parameter_error() and test_intersection_time_smoothing_parameter_array_like()

@h-chmeruk h-chmeruk added this to the v1.0.0 milestone Mar 13, 2026
@h-chmeruk h-chmeruk added the enhancement New feature or request label Mar 13, 2026
Comment thread pyrato/dsp.py
Comment on lines +449 to +459
if n_channels > 1:
for ch in range(n_channels):
reshaped_array = np.reshape(
data[ch, :n_samples_actual[ch]],
(n_blocks_min, n_samples_per_block[ch]))
time_window_data[ch, :] = np.mean(reshaped_array, axis=-1)
time_vector_window = (
(0.5+np.arange(0, n_blocks_min)).reshape(1, -1) * (
n_samples_per_block/sampling_rate).reshape(-1, 1))
else:
reshaped_array = np.reshape(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely satisfied with this cumbersome if statement, so I would appreciate a suggestion for improvement

Comment thread pyrato/edc.py Outdated
Comment on lines +947 to +955
if len(np.atleast_1d(smoothing_parameter)) > 1:
output = _intersection_time_lundby(
time_window_data[ch], noise_estimation[ch], energy_data[ch],
np.squeeze(np.atleast_2d(time_vector_window)[ch, :]),
dB_above_noise, n_intervals_per_10dB,
use_dyn_range_for_regression, sampling_rate,
ch, failure_policy)
else:
output = _intersection_time_lundby(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not satisfied with this if statement either, so feel free to suggest something else :)

@h-chmeruk h-chmeruk changed the title Rename and improve freq paramter in the edc module Rename and improve freq parameter in the edc module Mar 13, 2026
@mberz mberz removed this from the v1.0.0 milestone Mar 18, 2026
@h-chmeruk h-chmeruk added this to the v1.1.0 milestone Mar 20, 2026
@f-brinkmann f-brinkmann moved this from Backlog to Agenda in Weekly Planning Apr 24, 2026
@mberz mberz moved this from Agenda to Require review in Weekly Planning Apr 24, 2026
@h-chmeruk h-chmeruk force-pushed the fix/rename_freq_parameter branch from 81bd8a1 to c4769ff Compare May 5, 2026 14:12
Copy link
Copy Markdown
Member

@f-brinkmann f-brinkmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When testing, I found a use case that breaks the code. A Signal with cshape (2, 2) that contains two bands (first dimension) and two channels (second dimension)

import pyfar as pf
import pyrato

cdim = 2

rir = pf.signals.files.room_impulse_response(crop_noise_tail=False)

if cdim >= 1:
    rirs = rir.copy()
    rirs = pf.utils.concatenate_channels((rirs, rirs, rirs, rirs), 0)
if cdim == 2:
    rirs = rirs.reshape((2, 2))

print(rirs)

pyrato.edc.intersection_time_lundeby(rirs, smoothing_paramter=[1e3, 4e3])

I am not sure if the current solution where _smooth_rir is used outside the for-loop can work, because the shape of time_window_data and time_vector_window depends on the smoothing_parameter. Maybe it should be moved inside the for-loop. But I did not check this in detail.

Comment thread pyrato/edc.py
smoothing_parameter : int or array_like of int or {'broadband'}
Used to determine the smoothing time window in the Lundeby
algorithm. It should represent the center frequency (in Hz) of the
frequency band(s) in which the RIR data was computed.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to mention that length must match data.cshape[0] if it is an array like

Comment thread pyrato/edc.py
The frequency band. If set to 'broadband',
the time window of the Lundeby-algorithm will not be set in dependence
of frequency.
smoothing_parameter : int or array_like of int or {'broadband'}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this require integer values? We can maybe also write

Suggested change
smoothing_parameter : int or array_like of int or {'broadband'}
smoothing_parameter : scalar, array_like, or {'broadband'}

Comment thread pyrato/edc.py
else:
freq_dependent_window_time = (800/freq+10) / 1000
raise TypeError(
"smoothing_parameter must be an int or array_like of int "
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, would suggest

Suggested change
"smoothing_parameter must be an int or array_like of int "
"smoothing_parameter must be a scaler, array_like, "

Comment thread pyrato/edc.py

if freq == "broadband":
# number of frequency bands given by first channel axis
n_bands = np.prod(data.cshape)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be

Suggested change
n_bands = np.prod(data.cshape)
n_bands = data.cshape[0]

because our filter routines will prepend a dimension containing the bands. This means we force the user to always provide the bands in the first dimension.

Comment thread pyrato/edc.py
freq_dependent_window_time = (800/freq+10) / 1000
raise TypeError(
"smoothing_parameter must be an int or array_like of int "
"or {'broadband'}")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"or {'broadband'}")
"or 'broadband'")

Comment thread pyrato/edc.py
def energy_decay_curve_truncation(
data,
freq='broadband',
smoothing_parameter='broadband',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to deprecate the freq parameter for backwards compatability. This can be done with the pyfar._utils.rename_arg decorator. You can search pyfar for example use cases of this :)

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

Labels

enhancement New feature or request

Projects

Status: Require review

Development

Successfully merging this pull request may close these issues.

3 participants