Skip to content

Commit

Permalink
Fixes call to deprecated scipy.integrate.trapz function. (#363)
Browse files Browse the repository at this point in the history
Fixes issues #362
  • Loading branch information
fakufaku authored Sep 9, 2024
1 parent daa2833 commit 5d2538d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Bugfix
- Fixes a bug when plotting an anechoic room
- Fixes a buggy assert from ``rir_build.cpp``
- Makes the build system consistent for all source files in ``pyroomacoustics/libroom_src``
- Fixes a call to a deprecated function of scipy.integrate in ``pyroomacoustics/denoise/iterative_wiener`` (issue #362)

`0.7.6`_ - 2024-08-05
---------------------
Expand Down
9 changes: 8 additions & 1 deletion pyroomacoustics/denoise/iterative_wiener.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,14 @@ def _lpc_all_pole(omega):
d_omega = 2 * np.pi / 1000
omega_vals = np.arange(-np.pi, np.pi, d_omega)
vec_integrand = np.vectorize(_lpc_all_pole)
integral = integrate.trapz(vec_integrand(omega_vals), omega_vals)

try:
integral = integrate.trapezoid(vec_integrand(omega_vals), omega_vals)
except AttributeError:
# older versions of scipy do not have the function 'trapezoid'
# fall back to the legacy function name
integral = integrate.trapz(vec_integrand(omega_vals), omega_vals)

return rhs * 2 * np.pi / N / integral


Expand Down
38 changes: 38 additions & 0 deletions pyroomacoustics/denoise/tests/test_iterative_wiener.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import numpy as np

import pyroomacoustics as pra


def test_iterative_wiener():
"""
A simple functional test that the call does not produce any errors.
"""
# parameters
num_blocks = 20
nfft = 512
hop = nfft // 2

# create a dummy signal
blocks = np.random.randn(num_blocks, hop)

# initialize STFT and IterativeWiener objects
stft = pra.transform.STFT(nfft, hop=hop, analysis_window=pra.hann(nfft))
scnr = pra.denoise.IterativeWiener(
frame_len=nfft, lpc_order=20, iterations=2, alpha=0.8, thresh=0.01
)

# apply block-by-block
processed_blocks = []
for n in range(num_blocks):

# go to frequency domain, 50% overlap
stft.analysis(blocks[n])

# compute wiener output
X = scnr.compute_filtered_output(
current_frame=stft.fft_in_buffer, frame_dft=stft.X
)

# back to time domain
mono_denoised = stft.synthesis(X)
processed_blocks.append(mono_denoised)

0 comments on commit 5d2538d

Please sign in to comment.