From 78884cbbe2c3bf1a5c31942bb999db24a0badc8d Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - ASCEE" Date: Tue, 21 Jan 2020 11:09:52 +0100 Subject: [PATCH 1/3] Merged typex feature from slm --- lasp/filter/filterbank_design.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lasp/filter/filterbank_design.py b/lasp/filter/filterbank_design.py index 16387b8..83a86d3 100644 --- a/lasp/filter/filterbank_design.py +++ b/lasp/filter/filterbank_design.py @@ -73,6 +73,9 @@ class FilterBankDesigner: Args: x: Midband designator """ + if type(x) == list: + x = np.asarray(x) + # Exact midband frequency return self.G**(x/self.b)*self.fr From 183404338e339bfc7f6f79807c3d90d014f754b7 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - ASCEE" Date: Tue, 21 Jan 2020 13:25:14 +0100 Subject: [PATCH 2/3] Merged improvements on SPL filter --- lasp/filter/soundpressureweighting.py | 48 +++++++++++++++++++++------ 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/lasp/filter/soundpressureweighting.py b/lasp/filter/soundpressureweighting.py index 93a4dd0..cdff299 100644 --- a/lasp/filter/soundpressureweighting.py +++ b/lasp/filter/soundpressureweighting.py @@ -33,6 +33,14 @@ class SPLFilterDesigner: f4 = np.sqrt((-b+np.sqrt(b**2-4*c))/2) f4sq = f4**2 + def __init__(self, fs): + """Initialize a filter bank designer. + + Args: + fs: Sampling frequency [Hz] + """ + self.fs = fs + def _A_uncor(self, f): """ Computes the uncorrected frequency response of the A-filter @@ -88,7 +96,9 @@ class SPLFilterDesigner: return Cuncor/C1000 - def A_fir_design(self, fs): + def A_fir_design(self): + + fs = self.fs assert int(fs) == 48000 freq_design = np.linspace(0, 17e3, 3000) @@ -102,7 +112,8 @@ class SPLFilterDesigner: return fir - def C_fir_design(self, fs): + def C_fir_design(self): + fs = self.fs assert int(fs) == 48000 fs = 48000. freq_design = np.linspace(0, 17e3, 3000) @@ -115,29 +126,46 @@ class SPLFilterDesigner: window='rectangular') return fir - def C_Sos_design(self, fs): + def C_Sos_design(self): """ Create filter coefficients of the C-weighting filter. Uses the bilinear transform to convert the analog filter to a digital one. - Args: - fs: Sampling frequency [Hz] - Returns: Sos: Second order sections """ - + fs = self.fs p1 = 2*np.pi*self.f1 p4 = 2*np.pi*self.f4 zeros_analog = [0,0] - poles_analog = [p1, p1, p4, p4] + poles_analog = [-p1, -p1, -p4, -p4] k_analog = p4**2/self._C_uncor(self.fr) z, p, k = bilinear_zpk(zeros_analog, poles_analog, k_analog, fs) sos = zpk2sos(z, p, k) return sos - # return z, p, k - # return zeros_analog, poles_analog, k_analog + + def A_Sos_design(self): + """ + Create filter coefficients of the A-weighting filter. Uses the bilinear + transform to convert the analog filter to a digital one. + + Returns: + Sos: Second order sections + """ + fs = self.fs + p1 = 2*np.pi*self.f1 + p2 = 2*np.pi*self.f2 + p3 = 2*np.pi*self.f3 + p4 = 2*np.pi*self.f4 + zeros_analog = [0,0,0,0] + poles_analog = [-p1,-p1,-p2,-p3,-p4,-p4] + k_analog = p4**2/self._A_uncor(self.fr) + + z, p, k = bilinear_zpk(zeros_analog, poles_analog, k_analog, fs) + sos = zpk2sos(z, p, k) + return sos + def show_Afir(): from asceefig.plot import Figure From 0bbfe22d83f9b4ad5ddab91ed204c19283c07bba Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - ASCEE" Date: Thu, 23 Jan 2020 17:23:13 +0100 Subject: [PATCH 3/3] Bugfix for lowest frequency point in converting octave band to narrow band --- lasp/filter/filterbank_design.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lasp/filter/filterbank_design.py b/lasp/filter/filterbank_design.py index 83a86d3..dabbaf9 100644 --- a/lasp/filter/filterbank_design.py +++ b/lasp/filter/filterbank_design.py @@ -256,7 +256,7 @@ class FilterBankDesigner: for x in self.xs: xl = x fl = self.fl(x) - if self.fl(x+1) > freq[0]: + if fl >= freq[0]: break # Find upper frequency xu