Added offset_t option to SLM(); removed trailing spaces
This commit is contained in:
parent
e405ab8eea
commit
fbb14f475c
@ -27,35 +27,35 @@ class SLM:
|
||||
Multi-channel Sound Level Meter. Input data: time data with a certain
|
||||
sampling frequency. Output: time-weighted (fast/slow) sound pressure
|
||||
levels in dB(A/C/Z). Possibly in octave bands.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
fs,
|
||||
fbdesigner=None,
|
||||
fbdesigner=None,
|
||||
tw: TimeWeighting =TimeWeighting.fast,
|
||||
fw: FreqWeighting =FreqWeighting.A,
|
||||
xmin = None,
|
||||
xmax = None,
|
||||
include_overall=True,
|
||||
level_ref_value=P_REF):
|
||||
level_ref_value=P_REF,
|
||||
offset_t=0):
|
||||
"""
|
||||
Initialize a sound level meter object.
|
||||
|
||||
Args:
|
||||
fs: Sampling frequency of input data [Hz]
|
||||
fbdesigner: FilterBankDesigner to use for creating the
|
||||
fbdesigner: FilterBankDesigner to use for creating the
|
||||
(fractional) octave bank filters. Set this one to None to only do
|
||||
overalls
|
||||
fs: Sampling frequency [Hz]
|
||||
tw: Time Weighting to apply
|
||||
fw: Frequency weighting to apply
|
||||
xmin: Filter designator of lowest band.
|
||||
xmin: Filter designator of lowest band.
|
||||
xmax: Filter designator of highest band
|
||||
include_overall: If true, a non-functioning filter is added which
|
||||
is used to compute the overall level.
|
||||
level_ref_value: Reference value for computing the levels in dB
|
||||
|
||||
offset_t: Offset to be added to output time data [s]
|
||||
"""
|
||||
|
||||
self.fbdesigner = fbdesigner
|
||||
@ -63,8 +63,8 @@ class SLM:
|
||||
xmin = fbdesigner.xs[0]
|
||||
elif fbdesigner is None:
|
||||
xmin = 0
|
||||
|
||||
if xmax is None and self.fbdesigner is not None:
|
||||
|
||||
if xmax is None and self.fbdesigner is not None:
|
||||
xmax = fbdesigner.xs[-1]
|
||||
elif fbdesigner is None:
|
||||
xmax = 0
|
||||
@ -74,7 +74,8 @@ class SLM:
|
||||
nfilters = len(self.xs)
|
||||
if include_overall: nfilters +=1
|
||||
self.include_overall = include_overall
|
||||
|
||||
self.offset_t = offset_t
|
||||
|
||||
spld = SPLFilterDesigner(fs)
|
||||
if fw == FreqWeighting.A:
|
||||
prefilter = spld.A_Sos_design().flatten()
|
||||
@ -104,7 +105,7 @@ class SLM:
|
||||
self.nom_txt.append(fbdesigner.nominal_txt(x))
|
||||
|
||||
if include_overall:
|
||||
# Create a unit impulse response filter, every third index equals
|
||||
# Create a unit impulse response filter, every third index equals
|
||||
# 1, so b0 = 1 and a0 is 1 (by definition)
|
||||
# a0 = 1, b0 = 1, rest is zero
|
||||
sos[:,-1] = sos_overall
|
||||
@ -119,7 +120,7 @@ class SLM:
|
||||
|
||||
# Downsampling factor, determine from single pole low pass filter time
|
||||
# constant, such that aliasing is ~ allowed at 20 dB lower value
|
||||
# and
|
||||
# and
|
||||
dsfac = cppSLM.suggestedDownSamplingFac(fs, tw[0])
|
||||
|
||||
if prefilter is not None:
|
||||
@ -153,14 +154,14 @@ class SLM:
|
||||
Ncur = levels.shape[0]
|
||||
tend = tstart + Ncur / self.fs_slm
|
||||
|
||||
t = np.linspace(tstart, tend, Ncur, endpoint=False)
|
||||
t = np.linspace(tstart, tend, Ncur, endpoint=False) + self.offset_t
|
||||
self.N += Ncur
|
||||
|
||||
output = {}
|
||||
|
||||
for i, x in enumerate(self.xs):
|
||||
# '31.5' to '16k'
|
||||
output[self.nom_txt[i]] = {'t': t,
|
||||
output[self.nom_txt[i]] = {'t': t,
|
||||
'data': levels[:, [i]],
|
||||
'x': x}
|
||||
if self.include_overall and self.fbdesigner is not None:
|
||||
|
Loading…
Reference in New Issue
Block a user