-
Notifications
You must be signed in to change notification settings - Fork 15
Refactor the parametric energy decay curve function #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,9 @@ | |||||
| such as Sabine's theory of sound in rooms. | ||||||
| """ | ||||||
| import numpy as np | ||||||
| from numpy.typing import NDArray | ||||||
| import pyfar as pf | ||||||
|
|
||||||
|
|
||||||
| def energy_decay_curve_analytic( | ||||||
| surfaces, alphas, volume, times, source=None, | ||||||
|
|
@@ -81,6 +84,64 @@ def energy_decay_curve_analytic( | |||||
| return energy_decay_curve | ||||||
|
|
||||||
|
|
||||||
| def energy_decay_curve( | ||||||
| times : np.ndarray[float], | ||||||
| reverberation_time : float | np.ndarray[float], | ||||||
| energy : float | np.ndarray[float] = 1, | ||||||
| ) -> pf.TimeData: | ||||||
| r"""Calculate the energy decay curve from the reverberation time and energy. | ||||||
|
|
||||||
| The energy decay curve is calculated as | ||||||
|
|
||||||
| .. math:: | ||||||
| E(t) = E_0 e^{-\frac{6 \ln(10)}{T_{60}} t} | ||||||
|
|
||||||
| where :math:`E_0` is the initial energy, :math:`T_{60}` the reverberation | ||||||
| time, and :math:`t` the time [#]_. | ||||||
|
|
||||||
| Parameters | ||||||
| ---------- | ||||||
| times : numpy.ndarray[float] | ||||||
| The times at which the energy decay curve is evaluated. | ||||||
| reverberation_time : float | numpy.ndarray[float] | ||||||
| The reverberation time in seconds. | ||||||
| energy : float | numpy.ndarray[float], optional | ||||||
| The initial energy of the sound field, by default 1 | ||||||
|
|
||||||
| Returns | ||||||
| ------- | ||||||
| pyfar.TimeData | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
in pyfar we usually state it like this. I see the point of redundany espacially in this case. |
||||||
| The energy decay curve. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hwo about return the timeData ofject of cshape broadcasted from |
||||||
|
|
||||||
| Example | ||||||
| ------- | ||||||
| Calculate and plot an energy decay curve with a reverberation time of | ||||||
| 2 seconds. | ||||||
|
|
||||||
| .. plot:: | ||||||
|
|
||||||
| >>> import numpy as np | ||||||
| >>> import pyrato | ||||||
| >>> import pyfar as pf | ||||||
| >>> | ||||||
| >>> times = np.linspace(0, 3, 50) | ||||||
| >>> T_60 = 2 | ||||||
| >>> edc = pyrato.parametric.energy_decay_curve(times, T_60) | ||||||
| >>> pf.plot.time(edc, log_prefix=10, dB=True) | ||||||
|
|
||||||
|
|
||||||
| References | ||||||
| ---------- | ||||||
| .. [#] H. Kuttruff, Room acoustics, 4th Ed. Taylor & Francis, 2009. | ||||||
|
|
||||||
| """ | ||||||
|
|
||||||
| damping_term = 3*np.log(10) / reverberation_time | ||||||
| edc = energy * np.exp(-2*damping_term*times) | ||||||
|
|
||||||
| return pf.TimeData(edc, times) | ||||||
|
|
||||||
|
|
||||||
| def air_attenuation_coefficient( | ||||||
| frequency, | ||||||
| temperature=20, | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.