Bugfixes and improvements in Filters
This commit is contained in:
parent
1748daab4c
commit
2270a297cc
@ -30,7 +30,7 @@ class FilterBankDesigner:
|
|||||||
fs: Sampling frequency [Hz]
|
fs: Sampling frequency [Hz]
|
||||||
"""
|
"""
|
||||||
# Default FIR filter length
|
# Default FIR filter length
|
||||||
firFilterLength = 256 # Filter order
|
self.firFilterLength = 256 # Filter order
|
||||||
self.fs = fs
|
self.fs = fs
|
||||||
|
|
||||||
# Constant G, according to standard
|
# Constant G, according to standard
|
||||||
@ -99,8 +99,8 @@ class FilterBankDesigner:
|
|||||||
Returns:
|
Returns:
|
||||||
filter: 1D ndarray with FIR filter coefficients
|
filter: 1D ndarray with FIR filter coefficients
|
||||||
"""
|
"""
|
||||||
assert np.isclose(fs, self.fs), "Invalid sampling frequency"
|
assert np.isclose(self.fs, 48000), "Invalid sampling frequency"
|
||||||
fd = fs / np.prod(self.firDecimation(x))
|
fd = self.fs / np.prod(self.firDecimation(x))
|
||||||
|
|
||||||
# For designing the filter, the lower and upper frequencies need to be
|
# For designing the filter, the lower and upper frequencies need to be
|
||||||
# slightly adjusted to fall within the limits for a class 1 filter.
|
# slightly adjusted to fall within the limits for a class 1 filter.
|
||||||
|
@ -60,6 +60,8 @@ class AvStream:
|
|||||||
# Determine highest input channel number
|
# Determine highest input channel number
|
||||||
channelconfigs = daqconfig.en_input_channels
|
channelconfigs = daqconfig.en_input_channels
|
||||||
|
|
||||||
|
self.channel_names = []
|
||||||
|
|
||||||
self.sensitivity = self.daqconfig.getSensitivities()
|
self.sensitivity = self.daqconfig.getSensitivities()
|
||||||
|
|
||||||
rtaudio_inputparams = None
|
rtaudio_inputparams = None
|
||||||
@ -79,6 +81,7 @@ class AvStream:
|
|||||||
for i, channelconfig in enumerate(channelconfigs):
|
for i, channelconfig in enumerate(channelconfigs):
|
||||||
if channelconfig.channel_enabled:
|
if channelconfig.channel_enabled:
|
||||||
self.nchannels = i+1
|
self.nchannels = i+1
|
||||||
|
self.channel_names.append(channelconfig.channel_name)
|
||||||
rtaudio_inputparams = {'deviceid': device.index,
|
rtaudio_inputparams = {'deviceid': device.index,
|
||||||
'nchannels': self.nchannels,
|
'nchannels': self.nchannels,
|
||||||
'firstchannel': 0}
|
'firstchannel': 0}
|
||||||
|
@ -82,9 +82,9 @@ class TimeWeighting:
|
|||||||
fast = (0.125, 'Fast (0.125 s)')
|
fast = (0.125, 'Fast (0.125 s)')
|
||||||
slow = (1.0, 'Slow (1.0 s)')
|
slow = (1.0, 'Slow (1.0 s)')
|
||||||
tens = (10, '10 s')
|
tens = (10, '10 s')
|
||||||
infinite = (np.Inf, 'Infinite')
|
infinite = (np.Inf, 'Infinite (Leq)')
|
||||||
types = (none, uufast, ufast, fast, slow, tens, infinite)
|
types = (none, uufast, ufast, fast, slow, tens, infinite)
|
||||||
default = 2
|
default = 3
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fillComboBox(cb):
|
def fillComboBox(cb):
|
||||||
|
@ -115,7 +115,7 @@ class FirFilterBank:
|
|||||||
# These are the filters that do not require lasp_decimation
|
# These are the filters that do not require lasp_decimation
|
||||||
# prior to filtering
|
# prior to filtering
|
||||||
nominals_txt.append(self.designer.nominal_txt(x))
|
nominals_txt.append(self.designer.nominal_txt(x))
|
||||||
firs[:, i] = self.designer.createFirFilter(fs, x)
|
firs[:, i] = self.designer.createFirFilter(x)
|
||||||
filterbank = {'fb': pyxFilterBank(firs, 1024),
|
filterbank = {'fb': pyxFilterBank(firs, 1024),
|
||||||
'xs': xs,
|
'xs': xs,
|
||||||
'nominals': nominals_txt}
|
'nominals': nominals_txt}
|
||||||
@ -203,7 +203,7 @@ class FirOctaveFilterBank(FirFilterBank):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, fs, xmin, xmax):
|
def __init__(self, fs, xmin, xmax):
|
||||||
self.designer = OctaveBankDesigner()
|
self.designer = OctaveBankDesigner(fs)
|
||||||
FirFilterBank.__init__(self, fs, xmin, xmax)
|
FirFilterBank.__init__(self, fs, xmin, xmax)
|
||||||
|
|
||||||
|
|
||||||
@ -231,6 +231,7 @@ class SosFilterBank:
|
|||||||
self.fs = fs
|
self.fs = fs
|
||||||
self.xs = list(range(xmin, xmax + 1))
|
self.xs = list(range(xmin, xmax + 1))
|
||||||
nfilt = len(self.xs)
|
nfilt = len(self.xs)
|
||||||
|
self.nfilt = nfilt
|
||||||
self._fb = pyxSosFilterBank(nfilt, 5)
|
self._fb = pyxSosFilterBank(nfilt, 5)
|
||||||
for i, x in enumerate(self.xs):
|
for i, x in enumerate(self.xs):
|
||||||
sos = self.designer.createSOSFilter(x)
|
sos = self.designer.createSOSFilter(x)
|
||||||
@ -279,7 +280,7 @@ class SosThirdOctaveFilterBank(SosFilterBank):
|
|||||||
band.
|
band.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, fs, xmin, xmax):
|
def __init__(self, fs, xmin=None, xmax=None):
|
||||||
"""
|
"""
|
||||||
Initialize a second order sections filterbank.
|
Initialize a second order sections filterbank.
|
||||||
|
|
||||||
@ -289,6 +290,10 @@ class SosThirdOctaveFilterBank(SosFilterBank):
|
|||||||
xmax: Maximum value for the bands
|
xmax: Maximum value for the bands
|
||||||
"""
|
"""
|
||||||
self.designer = ThirdOctaveBankDesigner(fs)
|
self.designer = ThirdOctaveBankDesigner(fs)
|
||||||
|
if xmin is None:
|
||||||
|
xmin = self.designer.xs[0]
|
||||||
|
if xmax is None:
|
||||||
|
xmax = self.designer.xs[-1]
|
||||||
SosFilterBank.__init__(self, fs, xmin, xmax)
|
SosFilterBank.__init__(self, fs, xmin, xmax)
|
||||||
|
|
||||||
|
|
||||||
@ -298,16 +303,20 @@ class SosOctaveFilterBank(SosFilterBank):
|
|||||||
band.
|
band.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, fs, xmin, xmax):
|
def __init__(self, fs, xmin=None, xmax=None):
|
||||||
"""
|
"""
|
||||||
Initialize a second order sections filterbank.
|
Initialize a second order sections filterbank.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
fs: Sampling frequency [Hz]
|
fs: Sampling frequency [Hz]
|
||||||
xmin: Minimum value for the bands
|
xmin: Minimum value for the bands, if not specified, use minimum
|
||||||
xmax: Maximum value for the bands
|
xmax: Maximum value for the bands, if not specified, use maximum
|
||||||
"""
|
"""
|
||||||
self.designer = OctaveBankDesigner(fs)
|
self.designer = OctaveBankDesigner(fs)
|
||||||
|
if xmin is None:
|
||||||
|
xmin = self.designer.xs[0]
|
||||||
|
if xmax is None:
|
||||||
|
xmax = self.designer.xs[-1]
|
||||||
SosFilterBank.__init__(self, fs, xmin, xmax)
|
SosFilterBank.__init__(self, fs, xmin, xmax)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user