def octave_filters_oneoctave(total_band_count, bands_per_octave): # Bandpass Filter Generation pbrip = .5 # Pass band ripple sbrip = 50 # Stop band rejection # Filter order order = 2 fi, f_low, f_high = octave_frequencies(total_band_count, bands_per_octave) fi = fi[-bands_per_octave:] f_low = f_low[-bands_per_octave:] f_high = f_high[-bands_per_octave:] fs = SAMPLING_RATE wi = fi / (fs / 2.) # normalized frequencies w_low = f_low / (fs / 2.) w_high = f_high / (fs / 2.) w_high = (w_high < 1.) * w_high + (w_high >= 1.) * 1. B = [] A = [] # For each band for w, wl, wh in zip(wi, w_low, w_high): # normalized frequency vector freq = [wl, wh] # could be another IIR filter [b, a] = ellip(order, pbrip, sbrip, freq, btype='bandpass') B += [b.tolist()] A += [a.tolist()] return [B, A, fi, f_low, f_high]
def octave_filters(total_band_count, bands_per_octave): # Bandpass Filter Generation pbrip = .5 # Pass band ripple sbrip = 50 # Stop band rejection # Filter order order = 2 fi, f_low, f_high = octave_frequencies(total_band_count, bands_per_octave) fs = SAMPLING_RATE wi = fi / (fs / 2.) # normalized frequencies w_low = f_low / (fs / 2.) w_high = f_high / (fs / 2.) w_high = (w_high < 1.) * w_high + (w_high >= 1.) * 1. B = [] A = [] # For each band for w, wl, wh in zip(wi, w_low, w_high): # normalized frequency vector freq = [wl, wh] # could be another IIR filter [b, a] = ellip(order, pbrip, sbrip, freq, btype='bandpass') B += [b] A += [a] return [B, A, fi, f_low, f_high]
def setbandsperoctave(self, bandsperoctave): self.bandsperoctave = bandsperoctave self.nbands = NOCTAVE * self.bandsperoctave self.fi, self.flow, self.fhigh = octave_frequencies( self.nbands, self.bandsperoctave) [self.boct, self.aoct, fi, flow, fhigh] = generated_filters.params['%d' % bandsperoctave] #z, p, k = tf2zpk(self.bdec, self.adec) #print "poles", p, abs(p)**2 #print "zeros", z, abs(z)**2 #for b, a in zip(self.boct, self.aoct): #z, p, k = tf2zpk(b, a) #print "poles", p, abs(p)**2 #print "zeros", z, abs(z)**2 #[self.b_nodec, self.a_nodec, fi, fl, fh] = octave_filters(self.nbands, self.bandsperoctave) f = self.fi Rc = 12200.**2 * f**2 / ((f**2 + 20.6**2) * (f**2 + 12200.**2)) Rb = 12200.**2 * f**3 / ((f**2 + 20.6**2) * (f**2 + 12200.**2) * ((f**2 + 158.5**2)**0.5)) Ra = 12200.**2 * f**4 / ((f**2 + 20.6**2) * (f**2 + 12200.**2) * ((f**2 + 107.7**2)**0.5) * ((f**2 + 737.9**2)**0.5)) self.C = 0.06 + 20. * log10(Rc) self.B = 0.17 + 20. * log10(Rb) self.A = 2.0 + 20. * log10(Ra) #self.zfs = None self.zfs = octave_filter_bank_decimation_filtic( self.bdec, self.adec, self.boct, self.aoct)
def setbandsperoctave(self, bandsperoctave): self.bandsperoctave = bandsperoctave self.nbands = NOCTAVE*self.bandsperoctave self.fi, self.flow, self.fhigh = octave_frequencies(self.nbands, self.bandsperoctave) [self.boct, self.aoct, fi, flow, fhigh] = generated_filters.params['%d' %bandsperoctave] #z, p, k = tf2zpk(self.bdec, self.adec) #print "poles", p, abs(p)**2 #print "zeros", z, abs(z)**2 #for b, a in zip(self.boct, self.aoct): #z, p, k = tf2zpk(b, a) #print "poles", p, abs(p)**2 #print "zeros", z, abs(z)**2 #[self.b_nodec, self.a_nodec, fi, fl, fh] = octave_filters(self.nbands, self.bandsperoctave) f = self.fi Rc = 12200.**2*f**2 / ((f**2 + 20.6**2)*(f**2 + 12200.**2)) Rb = 12200.**2*f**3 / ((f**2 + 20.6**2)*(f**2 + 12200.**2)*((f**2 + 158.5**2)**0.5)) Ra = 12200.**2*f**4 / ((f**2 + 20.6**2)*(f**2 + 12200.**2)*((f**2 + 107.7**2)**0.5) * ((f**2 + 737.9**2)**0.5)) self.C = 0.06 + 20.*log10(Rc) self.B = 0.17 + 20.*log10(Rb) self.A = 2.0 + 20.*log10(Ra) #self.zfs = None self.zfs = octave_filter_bank_decimation_filtic(self.bdec, self.adec, self.boct, self.aoct)
def octave_filters(Nbands, BandsPerOctave): # Bandpass Filter Generation pbrip = .5 # Pass band ripple sbrip = 50 # Stop band rejection #Filter order order = 2 fi, f_low, f_high = octave_frequencies(Nbands, BandsPerOctave) fs = 44100 # sampling rate wi = fi/(fs/2.) # normalized frequencies w_low = f_low/(fs/2.) w_high = f_high/(fs/2.) B = [] A = [] # For each band for w, wl, wh in zip(wi, w_low, w_high): # normalized frequency vector freq = [wl, wh] # could be another IIR filter [b, a] = ellip(order, pbrip, sbrip, freq, btype='bandpass') B += [b] A += [a] return [B, A, fi, f_low, f_high]
def octave_filters(Nbands, BandsPerOctave): # Bandpass Filter Generation pbrip = .5 # Pass band ripple sbrip = 50 # Stop band rejection #Filter order order = 2 fi, f_low, f_high = octave_frequencies(Nbands, BandsPerOctave) fs = 44100 # sampling rate wi = fi / (fs / 2.) # normalized frequencies w_low = f_low / (fs / 2.) w_high = f_high / (fs / 2.) B = [] A = [] # For each band for w, wl, wh in zip(wi, w_low, w_high): # normalized frequency vector freq = [wl, wh] # could be another IIR filter [b, a] = ellip(order, pbrip, sbrip, freq, btype='bandpass') B += [b] A += [a] return [B, A, fi, f_low, f_high]
def setbandsperoctave(self, bandsperoctave): self.bandsperoctave = bandsperoctave self.nbands = NOCTAVE * self.bandsperoctave self.fi, self.flow, self.fhigh = octave_frequencies( self.nbands, self.bandsperoctave) [self.boct, self.aoct, fi, flow, fhigh] = generated_filters.PARAMS['%d' % bandsperoctave] self.boct = [array(f) for f in self.boct] self.aoct = [array(f) for f in self.aoct] # [self.b_nodec, self.a_nodec, fi, fl, fh] = octave_filters(self.nbands, self.bandsperoctave) f = self.fi Rc = 12200.**2 * f**2 / ((f**2 + 20.6**2) * (f**2 + 12200.**2)) Rb = 12200.**2 * f**3 / ((f**2 + 20.6**2) * (f**2 + 12200.**2) * ((f**2 + 158.5**2)**0.5)) Ra = 12200.**2 * f**4 / ((f**2 + 20.6**2) * (f**2 + 12200.**2) * ((f**2 + 107.7**2)**0.5) * ((f**2 + 737.9**2)**0.5)) self.C = 0.06 + 20. * log10(Rc) self.B = 0.17 + 20. * log10(Rb) self.A = 2.0 + 20. * log10(Ra) self.zfs = octave_filter_bank_decimation_filtic( self.bdec, self.adec, self.boct, self.aoct) if bandsperoctave == 1: basis = renard.R5 elif bandsperoctave == 3: basis = renard.R10 elif bandsperoctave == 6: basis = renard.R20 elif bandsperoctave == 12: basis = renard.R40 elif bandsperoctave == 24: basis = renard.R80 else: raise Exception("Unknown bandsperoctave: %d" % (bandsperoctave)) # search the index of 1 kHz, the reference i = where(self.fi == 1000.)[0][0] # build the frequency scale self.f_nominal = [] k = 0 while len(self.f_nominal) < len(self.fi) - i: self.f_nominal += [ "{0:.{width}f}k".format(10**k * f, width=2 - k) for f in basis ] k += 1 self.f_nominal = self.f_nominal[:len(self.fi) - i] k = 0 while len(self.f_nominal) < len(self.fi): self.f_nominal = ["%d" % (10**(2 - k) * f) for f in basis] + self.f_nominal k += 1 self.f_nominal = self.f_nominal[-len(self.fi):]
def setbandsperoctave(self, bandsperoctave): self.bandsperoctave = bandsperoctave self.nbands = NOCTAVE*self.bandsperoctave self.fi, self.flow, self.fhigh = octave_frequencies(self.nbands, self.bandsperoctave) [self.boct, self.aoct, fi, flow, fhigh] = generated_filters.params['%d' %bandsperoctave] #z, p, k = tf2zpk(self.bdec, self.adec) #print "poles", p, abs(p)**2 #print "zeros", z, abs(z)**2 #for b, a in zip(self.boct, self.aoct): #z, p, k = tf2zpk(b, a) #print "poles", p, abs(p)**2 #print "zeros", z, abs(z)**2 #[self.b_nodec, self.a_nodec, fi, fl, fh] = octave_filters(self.nbands, self.bandsperoctave) f = self.fi Rc = 12200.**2*f**2 / ((f**2 + 20.6**2)*(f**2 + 12200.**2)) Rb = 12200.**2*f**3 / ((f**2 + 20.6**2)*(f**2 + 12200.**2)*((f**2 + 158.5**2)**0.5)) Ra = 12200.**2*f**4 / ((f**2 + 20.6**2)*(f**2 + 12200.**2)*((f**2 + 107.7**2)**0.5) * ((f**2 + 737.9**2)**0.5)) self.C = 0.06 + 20.*log10(Rc) self.B = 0.17 + 20.*log10(Rb) self.A = 2.0 + 20.*log10(Ra) #self.zfs = None self.zfs = octave_filter_bank_decimation_filtic(self.bdec, self.adec, self.boct, self.aoct) if bandsperoctave == 1: basis = renard.R5 elif bandsperoctave == 3: basis = renard.R10 elif bandsperoctave == 6: basis = renard.R20 elif bandsperoctave == 12: basis = renard.R40 elif bandsperoctave == 24: basis = renard.R80 else: raise Exception("Unknown bandsperoctave: %d" %(bandsperoctave)) # search the index of 1 kHz, the reference i = where(self.fi == 1000.)[0][0] # build the frequency scale self.f_nominal = [] k = 0 while len(self.f_nominal) < len(self.fi) - i: self.f_nominal += ["{0:.{width}f}k".format(10**k*f, width=2-k) for f in basis] k += 1 self.f_nominal = self.f_nominal[:len(self.fi) - i] k = 0 while len(self.f_nominal) < len(self.fi): self.f_nominal = ["%d" %(10**(2-k)*f) for f in basis] + self.f_nominal k += 1 self.f_nominal = self.f_nominal[-len(self.fi):]
def setbandsperoctave(self, bandsperoctave): self.bandsperoctave = bandsperoctave self.nbands = NOCTAVE * self.bandsperoctave self.fi, self.flow, self.fhigh = octave_frequencies( self.nbands, self.bandsperoctave) [self.boct, self.aoct, fi, flow, fhigh] = generated_filters.PARAMS['%d' % bandsperoctave] self.boct = [array(f) for f in self.boct] self.aoct = [array(f) for f in self.aoct] # [self.b_nodec, self.a_nodec, fi, fl, fh] = octave_filters(self.nbands, self.bandsperoctave) f = self.fi Rc = 12200.**2 * f**2 / ((f**2 + 20.6**2) * (f**2 + 12200.**2)) Rb = 12200.**2 * f**3 / ((f**2 + 20.6**2) * (f**2 + 12200.**2) * ((f**2 + 158.5**2)**0.5)) Ra = 12200.**2 * f**4 / ((f**2 + 20.6**2) * (f**2 + 12200.**2) * ((f**2 + 107.7**2)**0.5) * ((f**2 + 737.9**2)**0.5)) self.C = 0.06 + 20. * log10(Rc) self.B = 0.17 + 20. * log10(Rb) self.A = 2.0 + 20. * log10(Ra) self.zfs = octave_filter_bank_decimation_filtic( self.bdec, self.adec, self.boct, self.aoct) if bandsperoctave == 1: # with 1 band per octave, we would need the "R3.33" Renard series, but it does not exist. # However, that is not really a problem, since the numbers simply round up. self.f_nominal = [ "%.1fk" % (f / 1000) if f >= 10000 else "%.2fk" % (f / 1000) if f >= 1000 else "%d" % (f) for f in self.fi ] else: # with more than 1 band per octave, use the preferred numbers from the Renard series if bandsperoctave == 3: basis = renard.R10 elif bandsperoctave == 6: basis = renard.R20 elif bandsperoctave == 12: basis = renard.R40 elif bandsperoctave == 24: basis = renard.R80 else: raise Exception("Unknown bandsperoctave: %d" % (bandsperoctave)) # search the index of 1 kHz, the reference i = where(self.fi == 1000.)[0][0] # build the frequency scale self.f_nominal = [] k = 0 while len(self.f_nominal) < len(self.fi) - i: self.f_nominal += [ "{0:.{width}f}k".format(10**k * f, width=2 - k) for f in basis ] k += 1 self.f_nominal = self.f_nominal[:len(self.fi) - i] k = 0 while len(self.f_nominal) < len(self.fi): self.f_nominal = ["%d" % (10**(2 - k) * f) for f in basis] + self.f_nominal k += 1 self.f_nominal = self.f_nominal[-len(self.fi):]