Skip to content

Commit dfee484

Browse files
committed
Improved the intersection_time_lundeby function according to the suggestion in the PR #154 by @f-brinkmann
1 parent d3792fc commit dfee484

2 files changed

Lines changed: 16 additions & 22 deletions

File tree

pyrato/dsp.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,9 @@ def _smooth_rir(
155155
The time vector fitting the original data.
156156
157157
"""
158-
cshape = data.shape[:-1]
159-
data = np.atleast_2d(data)
160-
smooth_block_length = np.atleast_1d(smooth_block_length)
161158
n_samples = data.shape[-1]
162159
data = data.reshape(-1, n_samples)
163-
smooth_block_length = smooth_block_length.flatten()
160+
smooth_block_length = (np.atleast_1d(smooth_block_length)).flatten()
164161
n_channels = len(smooth_block_length)
165162
n_samples_nan = np.count_nonzero(np.isnan(data), axis=-1)
166163

pyrato/edc.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -954,15 +954,19 @@ def intersection_time_lundeby(
954954
sampling_rate = np.round(1/np.diff(data.times).mean(), decimals=4)
955955
energy_data = energy_data.time
956956

957+
# number of frequency bands given by first channel axis
958+
n_bands = np.prod(data.cshape)
957959
if smoothing_parameter == "broadband":
958960
# broadband: use 30 ms windows sizes
959-
freq_dependent_window_time = 0.03
961+
freq_dependent_window_time = np.atleast_1d([0.03] * n_bands)
960962
elif isinstance(smoothing_parameter, (int, list, tuple, np.ndarray)):
961-
smoothing_parameter = np.asarray(smoothing_parameter)
962-
if (smoothing_parameter.ndim > 0) and (
963-
smoothing_parameter.size != np.prod(data.cshape)):
963+
smoothing_parameter = np.atleast_1d(smoothing_parameter)
964+
if smoothing_parameter.size == 1:
965+
smoothing_parameter = np.tile(smoothing_parameter, n_bands)
966+
elif smoothing_parameter.size != n_bands:
964967
raise ValueError(
965-
"The size of smoothing_parameter must match data.csize.")
968+
"The size of smoothing_parameter must match the number of "
969+
"frequency bands.")
966970
freq_dependent_window_time = (800 / smoothing_parameter + 10) / 1000
967971
else:
968972
raise TypeError(
@@ -986,19 +990,12 @@ def intersection_time_lundeby(
986990
noise_peak_level = np.zeros(data.cshape, data.time.dtype)
987991

988992
for ch in np.ndindex(data.cshape):
989-
if len(np.atleast_1d(smoothing_parameter)) > 1:
990-
output = _intersection_time_lundby(
991-
time_window_data[ch], noise_estimation[ch], energy_data[ch],
992-
np.squeeze(np.atleast_2d(time_vector_window)[ch, :]),
993-
dB_above_noise, n_intervals_per_10dB,
994-
use_dyn_range_for_regression, sampling_rate,
995-
ch, failure_policy)
996-
else:
997-
output = _intersection_time_lundby(
998-
time_window_data[ch], noise_estimation[ch], energy_data[ch],
999-
time_vector_window, dB_above_noise, n_intervals_per_10dB,
1000-
use_dyn_range_for_regression, sampling_rate, ch, failure_policy)
1001-
993+
output = _intersection_time_lundby(
994+
time_window_data[ch], noise_estimation[ch], energy_data[ch],
995+
np.squeeze(np.atleast_2d(time_vector_window)[ch, :]),
996+
dB_above_noise, n_intervals_per_10dB,
997+
use_dyn_range_for_regression, sampling_rate,
998+
ch, failure_policy)
1002999
if output is None:
10031000
reverberation_time[ch] = np.nan
10041001
noise_level[ch] = np.nan

0 commit comments

Comments
 (0)