Input of filterbank API improvements

This commit is contained in:
Anne de Jong 2020-08-22 11:00:55 +02:00
parent 4dd95cb80c
commit 0b5a94be4c
2 changed files with 51 additions and 29 deletions

View File

@ -70,14 +70,57 @@ class FilterBankDesigner:
def band_limits(self, x, filter_class):
raise NotImplementedError()
def nominal_txt_tox(self, nom_txt: str):
"""Returns the x-value corresponding to a certain nominal txt: '1k' ->
0.
Args:
nom_txt: Text-representation of midband frequency
"""
for x in self.xs:
if self.nominal_txt(x) == nom_txt:
return x
raise ValueError(
f'Could not find an x-value corresponding to {nom_txt}.')
def sanitize_input(self, input_):
if isinstance(input_, int):
return input_
elif isinstance(input_, str):
return self.nominal_txt_tox(input_)
elif isinstance(input_, list):
if len(input_) == 3 and input_[1] is None:
# This is the "code" to create an array
xl = self.sanitize_input(input_[0])
xu = self.sanitize_input(input_[2])
return np.asarray(list(range(xl, xu+1)))
else:
x = [self.sanitize_input(xi) for xi in input_]
return np.asarray(x)
def getxs(self, nom_txt_start, nom_txt_end):
"""Returns a list of all filter designators, for given start end end
nominal frequencies.
Args:
nom_txt_start: Start frequency band, i.e. '31.5'
nom_txt_end: End frequency band, i.e. '10k'
Returns:
[x0, x1, ..]
"""
xstart = self.nominal_txt_tox(nom_txt_start)
xend = self.nominal_txt_tox(nom_txt_end)
return list(range(xstart, xend+1))
def fm(self, x):
"""Returns the exact midband frequency of the bandpass filter.
Args:
x: Midband designator
"""
if type(x) == list:
x = np.asarray(x)
x = self.sanitize_input(x)
# Exact midband frequency
return self.G**(x/self.b)*self.fr
@ -88,6 +131,7 @@ class FilterBankDesigner:
Args:
x: Midband designator
"""
x = self.sanitize_input(x)
return self.fm(x)*self.G**(-1/(2*self.b))
def fu(self, x):
@ -96,6 +140,7 @@ class FilterBankDesigner:
Args:
x: Midband designator
"""
x = self.sanitize_input(x)
return self.fm(x)*self.G**(1/(2*self.b))
def createFirFilter(self, x):
@ -133,6 +178,7 @@ class FilterBankDesigner:
# Normalized upper and lower frequencies of the bandpass
fl_n = fl/fnyq
x = self.sanitize_input(x)
fu_n = fu/fnyq
return butter(SOS_ORDER, [fl_n, fu_n], output='sos', btype='band')
@ -154,33 +200,6 @@ class FilterBankDesigner:
return firFreqResponse(fd, freq, fir)
def nominal_txt_tox(self, nom_txt: str):
"""Returns the x-value corresponding to a certain nominal txt: '1k' ->
0.
Args:
nom_txt: Text-representation of midband frequency
"""
for x in self.xs:
if self.nominal_txt(x) == nom_txt:
return x
raise ValueError(
f'Could not find an x-value corresponding to {nom_txt}.')
def getxs(self, nom_txt_start, nom_txt_end):
"""Returns a list of all filter designators, for given start end end
nominal frequencies.
Args:
nom_txt_start: Start frequency band, i.e. '31.5'
nom_txt_end: End frequency band, i.e. '10k'
Returns:
[x0, x1, ..]
"""
xstart = self.nominal_txt_tox(nom_txt_start)
xend = self.nominal_txt_tox(nom_txt_end)
return list(range(xstart, xend+1))
def getNarrowBandFromOctaveBand(self, xl, xu,
levels_in_bands, npoints=500,

View File

@ -47,6 +47,9 @@ from scipy.io import wavfile
import os
import time
import wave
from .lasp_common import SIQtys, Qty
from .device import DAQChannel
import logging
class BlockIter: