def __init__(self,source,cf,fc,gain,order): nch = len(cf) TWOPI = 2*pi self.samplerate = source.samplerate c = 2.0 * self.samplerate c1LP = ( c/Hz - TWOPI*fc ) b_temp = np.array([1,1])/ ( c/Hz + TWOPI*fc ) a_temp = np.array([1,-c1LP/ ( c/Hz + TWOPI*fc )]) filt_b = np.tile(b_temp.reshape([2,1]),[nch,1,order]) filt_a = np.tile(a_temp.reshape([2,1]),[nch,1,order]) filt_b[:,:,order-1] = filt_b[:,:,order-1]*gain LinearFilterbank.__init__(self, source, filt_b, filt_a)
def __init__(self, source, gain=1, **kwds): # Automatically duplicate mono input to fit the desired output shape gain = np.atleast_1d(gain) if len(gain) != source.nchannels and len(gain) != 1: if source.nchannels != 1: raise ValueError('Can only automatically duplicate source ' 'channels for mono sources, use ' 'RestructureFilterbank.') source = RestructureFilterbank(source, len(gain)) samplerate = source.samplerate zeros = np.array([-200, -200]) poles = np.array([-250 + 400j, -250 - 400j, -2000 + 6000j, -2000 - 6000j]) # use an arbitrary gain here, will be normalized afterwards b, a = signal.zpk2tf(zeros, poles * 2 * np.pi, 1.5e9) # normalize the response at 1000Hz (of the analog filter) resp = np.abs(signal.freqs(b, a, [1000*2*np.pi])[1]) # response magnitude b /= resp bd, ad = signal.bilinear(b, a, samplerate) bd = (np.tile(bd, (source.nchannels, 1)).T * gain).T ad = np.tile(ad, (source.nchannels, 1)) LinearFilterbank.__init__(self, source, bd, ad, **kwds)