28 b = (1/(1-D))*(frsq+fLsq*fHsq/frsq-D*(fLsq+fHsq))
30 f2 = (3-np.sqrt(5.))/2*fA
31 f3 = (3+np.sqrt(5.))/2*fA
32 f1 = np.sqrt((-b-np.sqrt(b**2-4*c))/2)
33 f4 = np.sqrt((-b+np.sqrt(b**2-4*c))/2)
37 """Initialize a filter bank designer.
40 fs: Sampling frequency [Hz]
46 Computes the uncorrected frequency response of the A-filter
49 f: Frequency (array, float)
52 Linear filter transfer function
55 num = self.
f4sq*fsq**2
56 denom1 = (fsq+self.
f1**2)
57 denom2 = np.sqrt((fsq+self.
f2**2)*(fsq+self.
f3**2))*(fsq+self.
f4sq)
59 return (num/(denom1*denom2))
64 Computes the linear A-weighting freqency response. Hence, to obtain
65 A-weighted values, the *amplitude* need to be multiplied with this value.
66 Hence, to correct dB levels, the value of 20*log(A) needs to be added to
70 f: Frequency array to compute values for
72 A(f) for each frequency
81 Computes the uncorrected frequency response of the C-filter
85 denom1 = (fsq+self.
f1**2)
86 denom2 = (fsq+self.
f4**2)
87 return num/(denom1*denom2)
92 Computes the linear A-weighting freqency response
103 assert int(fs) == 48000
104 freq_design = np.linspace(0, 17e3, 3000)
105 freq_design[-1] = fs/2
106 amp_design = self.
A(freq_design)
110 fir = arbitrary_fir_design(fs, L, freq_design, amp_design,
111 window=
'rectangular')
117 assert int(fs) == 48000
119 freq_design = np.linspace(0, 17e3, 3000)
120 freq_design[-1] = fs/2
121 amp_design =
C(freq_design)
125 fir = arbitrary_fir_design(fs, L, freq_design, amp_design,
126 window=
'rectangular')
131 Create filter coefficients of the C-weighting filter. Uses the bilinear
132 transform to convert the analog filter to a digital one.
135 Sos: Second order sections
141 poles_analog = [-p1, -p1, -p4, -p4]
144 z, p, k = bilinear_zpk(zeros_analog, poles_analog, k_analog, fs)
145 sos = zpk2sos(z, p, k)
150 Create filter coefficients of the A-weighting filter. Uses the bilinear
151 transform to convert the analog filter to a digital one.
154 Sos: Second order sections
161 zeros_analog = [0,0,0,0]
162 poles_analog = [-p1,-p1,-p2,-p3,-p4,-p4]
165 z, p, k = bilinear_zpk(zeros_analog, poles_analog, k_analog, fs)
166 sos = zpk2sos(z, p, k)
171 from asceefig.plot
import Figure
174 freq_design = np.linspace(0, 17e3, 3000)
175 freq_design[-1] = fs/2
176 amp_design = A(freq_design)
182 firs.append(A_fir_design())
185 freq_check = np.logspace(0, np.log10(fs/2), 5000)
188 f.semilogx(freq_check, 20*np.log10(A(freq_check)))
190 H = freqResponse(fs, freq_check, fir)
191 f.plot(freq_check, 20*np.log10(np.abs(H)))
193 f.fig.get_axes()[0].set_ylim(-75, 3)
197 from asceefig.plot
import Figure
200 freq_design = np.linspace(0, 17e3, 3000)
201 freq_design[-1] = fs/2
202 amp_design = C(freq_design)
208 firs.append(C_fir_design())
211 freq_check = np.logspace(0, np.log10(fs/2), 5000)
214 f.semilogx(freq_check, 20*np.log10(C(freq_check)))
216 H = freqResponse(fs, freq_check, fir)
217 f.plot(freq_check, 20*np.log10(np.abs(H)))
219 f.fig.get_axes()[0].set_ylim(-30, 1)