Module for filter generation and signal processing in sparrowpy.
This module provides functions to synthesize a room impulse response (IR)
from an energy time curve (ETC), e.g. obtained from a sparrowpy radiosity
simulation. This method follows [1].
Examples
Synthesize an impulse response from an ETC for the 500Hz, 1kHz and 2kHz octave
bands.
signal (pyfar.Signal) – Input broad-spectrum signal.
frequencies (np.ndarray) – Frequencies in which to filter the signal of shape (n_frequencies)
in Hz. The user may input an arbitrary array of frequencies in
which to filter the signal. The closest fractional octave bands
to the input frequencies will be returned in the same order.
num_fractions (int) – The number of bands an octave is divided into. E.g., 1 refers to
octave bands and 3 to third octave bands.
All positive integers are allowed.
order (int, optional) – Butterworth filter order for the signal filtering. By default 4.
Returns:
band_filtered_signal (pyfar.Signal) – Band-filtered signal of cshape (signal.cshape+(len(freqs))
bandwidth (np.ndarray) – Array of bandwidth values in Hz of the fractional octave bands
corresponding to the input frequencies of shape (n_frequencies).
with z being a random number in the range of \(z \in (0, 1]\)
and \(\mu\) being the reflection_density over time.
Each dirac has an amplitude of 1 or -1, which is chosen
randomly with equal probability.
The dirac sequence generation starts after \(t_\text{start}\).
Parameters:
reflection_density (pyfar.TimeData) – reflection density \(\mu\) in \(1/s^2\) over time.
An error is raised if the reflection sensitivity is greater than
sampling_rate/2. Schröder suggested a maximum reflection density of
sampling_rate/4 \(1/s^2\).
n_samples (int) – The length of the dirac sequence in samples.
t_start (float) – The dirac sequence generation starts after \(t_\text{start}\)
in seconds. The default is 0.
sampling_rate (int, optional) – The sampling rate of the dirac sequence in Hz.
The default is 44100 Hz.
seed (int, None, optional) – The seed for the random generator. Pass a seed to obtain identical
results for multiple calls. The default is None, which will yield
different results with every call.
See numpy.random.default_rng for more information.
Returns:
dirac_sequence – Signal of the generated dirac impulse sequence.
where \(g(k)=floor(k \cdot f_s \cdot \Delta t)\) representing the
range of each energy window with length \(\Delta t\) and
\(h(i)\) is the impulse response signal. \(BW\) is the bandwidth
of the energy time curve, which is set to half the sampling rate
by default.
Parameters:
signal (pyfar.Signal) – The impulse responses from which the energy time curve is
calculated. The cshape should be (...,n_bands).
delta_time (float, optional) – The time resolution of the energy time curve,
by default 0.01 seconds.
bandwidth (float, array_like, optional) – Bandwidth for each signal channel, by default None, which means its
assumed for the full bandwidth \(BW = f_s/2\).
The shape should be (n_bands,).
Returns:
etc – The energy time curve of the impulse responses.
Calculates the reflection density and starting time in a diffuse room.
The reflection density and starting time based on the chapter
5.3.4 of [3].
The starting time \(t_\text{start}\) can be calculated based on:
\[t_\text{start} = \left(\frac{2 V \cdot \ln(2)}{4 \pi c^3}\right)^{1/3}\]
where \(V\) is the room volume in \(m^3\) and \(c\) is the
speed of sound in the room. The reflection density \(\mu\)
is calculated based on the following equation:
where \(h_i\) and \(\nu_i\) represent respectively the
weighted output signal and the input signal at a given time sample
\(i\). \(g(k)=\lfloor k \cdot f_s \cdot \Delta t \rfloor\)
represents the range of each energy window with given length
\(\Delta t\) of the ETC entry \(E(k)\) with index \(k\).
\(BW\) is the bandwidth
of the energy time curve.
Parameters:
energy_time_curve (pyfar.TimeData) – Energy time curve of a sound propagation simulation of cshape
(...,n_freq_bands) and broadcastable to signal.
The ETC entries must be equally spaced in time.
signal (pyfar.Signal) – signal to be weighted by the etc of cshape
(...,n_freq_bands) and broadcastable to energy_time_curve.
bandwidth (np.ndarray) – Bandwidth for the frequency band in Hz of shape
(n_freq_bands). By default, signal will be processed
as full spectrum sampling_rate/2.
Returns:
weighted_signal – signal weighted by the energy_time_curve.
The cshape matches the cshape of the etc.