LASP
1.0
Library for Acoustic Signal Processing
Loading...
Searching...
No Matches
lasp_reverb.py
Go to the documentation of this file.
1
# -*- coding: utf-8 -*-
2
"""!
3
Author: J.A. de Jong - ASCEE
4
5
Description:
6
Reverberation time estimation tool using least squares
7
"""
8
from
.lasp_common
import
getTime
9
import
numpy
as
np
10
11
12
class
ReverbTime
:
13
"""
14
Tool to estimate the reverberation time
15
"""
16
17
def
__init__
(self, fs, level, channel=0):
18
"""
19
Initialize Reverberation time computer.
20
21
Args:
22
fs: Sampling frequency [Hz]
23
level: (Optionally weighted) level values as a function of time, in
24
dB.
25
channel: Channel index to compute from
26
27
"""
28
assert
level.ndim == 2,
'Invalid number of dimensions in level'
29
30
self.
_level
= level[:, channel][:, np.newaxis]
31
# Number of time samples
32
self.
_channel
= channel
33
self.
_N
= self.
_level
.shape[0]
34
self.
_t
= getTime(fs, self.
_N
, 0)
35
print(f
't: {self._t}'
)
36
37
def
compute
(self, istart, istop):
38
"""
39
Compute the reverberation time using a least-squares solver
40
41
Args:
42
istart: Start time index reverberation interval
43
istop: Stop time index of reverberation interval
44
45
Returns:
46
dictionary with result values, contains:
47
- istart: start index of reberberation interval
48
- istop: stop index of reverb. interval
49
- T60: Reverberation time
50
- const: Constant value
51
- derivative: rate of change of the level in dB/s.
52
"""
53
54
55
points = self.
_level
[istart:istop]
56
x = self.
_t
[istart:istop][:, np.newaxis]
57
58
# Solve the least-squares problem, by creating a matrix of
59
A = np.hstack([x, np.ones(x.shape)])
60
61
# print(A.shape)
62
# print(points.shape)
63
64
# derivative is dB/s of increase/decrease
65
sol, residuals, rank, s = np.linalg.lstsq(A, points)
66
67
68
# print(f'sol: {sol}')
69
# Derivative of the decay in dB/s
70
derivative = sol[0][0]
71
72
# Start level in dB
73
const = sol[1][0]
74
75
# Time to reach a decay of 60 dB (reverb. time)
76
T60 = -60./derivative
77
res = {
'istart'
: istart,
78
'istop'
: istop,
79
'const'
: const,
80
'derivative'
: derivative,
81
'T60'
: T60}
82
# print(res)
83
return
res
lasp.lasp_reverb.ReverbTime
Tool to estimate the reverberation time.
Definition
lasp_reverb.py:12
lasp.lasp_reverb.ReverbTime._channel
_channel
Definition
lasp_reverb.py:32
lasp.lasp_reverb.ReverbTime._N
_N
Definition
lasp_reverb.py:33
lasp.lasp_reverb.ReverbTime.__init__
__init__(self, fs, level, channel=0)
Initialize Reverberation time computer.
Definition
lasp_reverb.py:17
lasp.lasp_reverb.ReverbTime.compute
compute(self, istart, istop)
Compute the reverberation time using a least-squares solver.
Definition
lasp_reverb.py:37
lasp.lasp_reverb.ReverbTime._level
_level
Definition
lasp_reverb.py:30
lasp.lasp_reverb.ReverbTime._t
_t
Definition
lasp_reverb.py:34
src
lasp
lasp_reverb.py
Generated by
1.9.8