pyrato.analytic#

Analytic functions for room acoustics.

Functions:

eigenfrequencies_rectangular_room_impedance(L, ...)

Estimates the complex eigenvalues in the wavenumber domain for a rectangular room with arbitrary uniform impedances on the boundary by numerically solving for the roots of the transcendental equation.

eigenfrequencies_rectangular_room_rigid(...)

Calculate the eigenfrequencies of a rectangular room with rigid walls [1].

rectangular_room_impedance(L, r_S, r_R, ...)

Calculate the room impulse response and room transfer function for a rectangular room with arbitrary boundary impedances.

rectangular_room_rigid_walls(dimensions, ...)

Calculate the transfer function of a rectangular room based on the analytic model.

pyrato.analytic.eigenfrequencies_rectangular_room_impedance(L, ks, k_max, zeta, only_normal=False)[source]#

Estimates the complex eigenvalues in the wavenumber domain for a rectangular room with arbitrary uniform impedances on the boundary by numerically solving for the roots of the transcendental equation. A initial approximation to the zeroth order mode is applied to improve the conditioning of the problem. The eigenvalues corresponding to tangential and oblique modes are calculated from the eigenvalues of the respective axial modes. Resulting eigenvalues with a real part larger than k_max will be discarded.

Parameters:
  • L (array, double) – The dimensions in m

  • ks (array, double) – The wave numbers for which the eigenvalues are to be solved.

  • k_max (double) – The real part of the largest eigenvalue. This solves as a stopping criterion independent from the real wave number k.

  • zeta (array, double) – The normalized specific impedance on the boundaries.

  • only_normal (boolean, optional (False)) – Only return the eigenvalues corresponding to the axial modes. The mode indices will still contain the indices for all modes in the defined frequency range. The complete set of eigenvalues can be calculated as \(k_n = \sqrt{ k_{n,x}^2+k_{n,y}^2+k_{n,z}^2 }\).

Returns:

  • k_ns (array, complex) – The complex eigenvalues for each wavenumber

  • mode_indices (array, integer) – The wave number indices of respective eigenvalues.

Note

Eigenvalues smaller for a wave number \(k < 0.02\) will be replaced by the value for the closest larger wave number to ensure finding the root.

pyrato.analytic.eigenfrequencies_rectangular_room_rigid(dimensions, max_freq, speed_of_sound=343.9, sort=True)[source]#

Calculate the eigenfrequencies of a rectangular room with rigid walls [1].

Parameters:
  • dimensions (float, numpy.ndarray) – The dimensions of the room in the form [L_x, L_y, L_z]

  • max_freq (float) – The maximum frequency to consider for the calculation of the eigenfrequencies.

  • speed_of_sound (double, optional) – The speed of sound in meters per second. The default is 343.9

  • sort (bool, optional) – If True, the return values will be sorted with ascending frequencies. By default this is True.

Returns:

  • f_n (double, ndarray) – The eigenfrequencies of the room

  • n (int, ndarray) – The modal index

References

Examples

Calculate the eigenfrequencies under 75 Hz of a small room and plot.

>>> import numpy as np
>>> import pyrato as ra
>>> import matplotlib.pyplot as plt
>>> from pyrato.analytic import eigenfrequencies_rectangular_room_rigid
...
>>> L = [4, 5, 2.6]
>>> f_n, n = eigenfrequencies_rectangular_room_rigid(
...     L, max_freq=75, speed_of_sound=343.6, sort=True)
...
>>> ax = plt.axes()
>>> ax.semilogx(f_n, np.arange(f_n.size), linestyle='', marker='o')
>>> labels = [str(nn) for nn in n.T]
>>> ax.set_yticks(np.arange(f_n.size))
>>> ax.set_yticklabels(labels)
>>> ax.set_xticks([30,  40, 50, 60, 70, 80])
>>> ax.set_xticklabels(['30', '40', '50', '60', '70', '80'])
>>> ax.set_xlabel('Frequency (Hz)')
>>> ax.set_ylabel('Eigenfrequency index [$n_x, n_y, n_z$]')
>>> plt.tight_layout()

(Source code, png, hires.png, pdf)

../_images/analytic-1.png
pyrato.analytic.rectangular_room_impedance(L, r_S, r_R, normalized_impedance, max_freq, samplingrate=44100, c=343.9, n_samples=4096, remove_cavity_mode=False)[source]#

Calculate the room impulse response and room transfer function for a rectangular room with arbitrary boundary impedances.

Parameters:
  • L (ndarray, double, (3,)) – The room dimensions in meters

  • r_S (ndarray, double, (3)) – The source position in Cartesian coordinates

  • r_R (ndarray, double, (3, n_receivers)) – The receiver positions in Cartesian coordinates

  • normalized_impedance (ndarray, double, (3, 2)) – The normalized impedance \(\zeta_i = \frac{Z_i}{\rho_o c}\) for each wall.

  • max_freq (double) – The highest frequency to be considered for the estimation of the eigenfrequencies.

  • samplingrate (int, 44100) – The samplingrate

  • c (float, 343.9) – The speed of sound in m/s

  • n_samples (int, 2**12) – The number of samples for which the RIR is calculated

  • remove_cavity_mode (boolean, False) – When true, the cavity mode (0, 0, 0) will be removed before summation of all modes

Returns:

  • rir (ndarray, double, (n_receivers, n_samples)) – The room impulse response

  • rtf (ndarray, double, (n_receivers, n_bins)) – The room transfer function in the frequency domain

  • eigenvalues (ndarray, complex) – The complex eigenvalues in the form \(k_n = \omega_n / c + i \delta_n\)

pyrato.analytic.rectangular_room_rigid_walls(dimensions, source, receiver, reverberation_time, max_freq, samplingrate=44100, speed_of_sound=343.9, n_samples=262144)[source]#

Calculate the transfer function of a rectangular room based on the analytic model.

Implementation as given in [2] . The model is based on the solution for a room with rigid walls. The damping of the modes is included as a damping in the medium, not as a damping caused by the boundary. Consequently, all modes share the same damping factor calculated from the reverberation time as \(\delta = \frac{3\log(10)}{T_{60}}\).

Parameters:
  • dimensions (double, ndarray) – The dimensions of the room in the form [L_x, L_y, L_z]

  • source (double, array) – The source position in Cartesian coordinates [x, y, z]

  • receiver (double, ndarray) – The receiver position in Cartesian coordinates [x, y, z]

  • reverberation_time (double) – The reverberation time of the room in seconds.

  • max_freq (double) – The maximum frequency to consider for the calculation of the eigenfrequencies of the room

  • samplingrate (int) – The sampling rate

  • speed_of_sound (double, optional (343.9)) – The speed of sound

  • n_samples (int) – number of samples for the calculation

Returns:

  • rir (pyfar.Signal) – The room impulse response

  • eigenfrequencies (ndarray, double) – The eigenfrequencies for which the room impulse response was calculated

References

Example

Calculate the sound field in a rectangular room with 1 s reverberation time for a given source and receiver combination.

>>> import numpy as np
>>> import pyfar as pf
>>> from pyrato.analytic import rectangular_room_rigid_walls
...
>>> L = np.array([8, 5, 3])/10
>>> source_pos = np.array([5, 3, 1.2])/10
>>> receiver_pos = np.array([1, 1, 1.2])/10
>>> rir, _ = rectangular_room_rigid_walls(
>>>     L, source_pos, receiver_pos,
>>>     reverberation_time=1, max_freq=1e3, n_samples=2**16,
>>>     speed_of_sound=343.9)
>>> pf.plot.time_freq(rir)

(Source code, png, hires.png, pdf)

../_images/analytic-2.png