Skip to content

Commit a22febb

Browse files
committed
enable edc calculation of signals with cdim > 1
1 parent 3fb1352 commit a22febb

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

pyrato/edc.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ def energy_decay_curve_truncation(
263263
>>> ax.legend()
264264
265265
"""
266+
# flatten to allow signals with cdim > 1
267+
shape = data.time.shape
268+
data = data.flatten()
269+
266270
energy_data = dsp.preprocess_rir(
267271
data,
268272
is_energy=is_energy,
@@ -309,7 +313,7 @@ def energy_decay_curve_truncation(
309313
energy_decay_curve /= max_start_value
310314

311315
edc = pf.TimeData(
312-
energy_decay_curve, data.times, comment=data.comment)
316+
energy_decay_curve.reshape(shape), data.times, comment=data.comment)
313317

314318
if plot:
315319
ax = pf.plot.time(data, dB=True, label='RIR')
@@ -401,6 +405,9 @@ def energy_decay_curve_lundeby(
401405
>>> ax.legend()
402406
403407
"""
408+
# flatten to allow signals with cdim > 1
409+
shape = data.time.shape
410+
data = data.flatten()
404411

405412
energy_data = dsp.preprocess_rir(
406413
data,
@@ -455,7 +462,7 @@ def energy_decay_curve_lundeby(
455462
energy_decay_curve /= max_start_value
456463

457464
edc = pf.TimeData(
458-
energy_decay_curve, data.times, comment=data.comment)
465+
energy_decay_curve.reshape(shape), data.times, comment=data.comment)
459466

460467
if plot:
461468
ax = pf.plot.time(data, dB=True, label='RIR')
@@ -548,6 +555,10 @@ def energy_decay_curve_chu(
548555
>>> ax.legend()
549556
550557
"""
558+
# flatten to allow signals with cdim > 1
559+
shape = data.cshape
560+
data = data.flatten()
561+
551562
energy_data = dsp.preprocess_rir(
552563
data,
553564
is_energy=is_energy,
@@ -582,6 +593,8 @@ def energy_decay_curve_chu(
582593
trunc_levels = 10*np.log10((psnr)) - threshold
583594
edc = truncate_energy_decay_curve(edc, trunc_levels)
584595

596+
edc = edc.reshape(shape)
597+
585598
if plot:
586599
plt.figure(figsize=(15, 3))
587600
pf.plot.use('light')
@@ -687,6 +700,9 @@ def energy_decay_curve_chu_lundeby(
687700
>>> ax.legend()
688701
689702
"""
703+
# flatten to allow signals with cdim > 1
704+
shape = data.time.shape
705+
data = data.flatten()
690706

691707
energy_data = dsp.preprocess_rir(
692708
data,
@@ -746,7 +762,7 @@ def energy_decay_curve_chu_lundeby(
746762
energy_decay_curve /= max_start_value
747763

748764
edc = pf.TimeData(
749-
energy_decay_curve, data.times, comment=data.comment)
765+
energy_decay_curve.reshape(shape), data.times, comment=data.comment)
750766

751767
if plot:
752768
ax = pf.plot.time(data, dB=True, label='RIR')

tests/test_edc.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,24 @@ def test_edc_sabine():
9696
6.37107964e-04, 5.46555336e-04,
9797
])
9898
npt.assert_almost_equal(edc, truth)
99+
100+
101+
@pytest.mark.parametrize(
102+
"edc_function",
103+
[ra.edc.energy_decay_curve_chu,
104+
ra.edc.energy_decay_curve_lundeby,
105+
ra.edc.energy_decay_curve_chu_lundeby,
106+
ra.energy_decay_curve_lundeby],
107+
)
108+
def test_multidim_edc(edc_function):
109+
"""
110+
Test if edcs from multidimenstional signals can be calculated.
111+
Check if first 0.4 s contain NaNs.
112+
"""
113+
rir = pf.signals.files.room_impulse_response()
114+
rir_oct = pf.dsp.filter.fractional_octave_bands(rir, 1)
115+
edc = edc_function(rir_oct)
116+
117+
npt.assert_array_equal(
118+
np.isfinite(edc.time[..., :int(rir.sampling_rate*0.4)]), True)
119+

0 commit comments

Comments
 (0)