def add_LPF(self, fc, Q): """ Add a lowpass filter to the EQ Parameters ---------- fc : float Cutoff frequency Q : float Q factor """ string = 'LPF, Freq: {}, Q: {}'.format(fc, Q) filter = adsp.Filter(2, self.fs, type=string) b, a = adsp.design_LPF2(fc, Q, self.fs) filter.set_coefs(b, a) self.add_filter(filter)
def test_eq_LPF2_design(self): b, a = adsp.design_LPF2(_fs_ / 2, 0.707, _fs_) checkCoefs(self, b, a, [1, 2, 1], [1, 2, 1])
def processSample (self, x): # Direct-Form II, transposed y = self.z[1] + self.b[0]*x self.z[1] = self.z[2] + self.b[1]*x - self.fb_lambda (self.a[1],y) self.z[2] = self.b[2]*x - self.fb_lambda (self.a[2],y) return y def process_block (self, block): for n in range (len (block)): block[n] = self.processSample (block[n]) return block #%% fs = 44100 b, a = adsp.design_LPF2 (1000, 10, fs) sweep = adsp.sweep_log (20, 22000, 1, fs) legend = [] freqs = np.logspace (1, 3.4, num=1000, base=20) for g in [0.00001, 0.04, 0.2, 1.0]: cur_sweep = np.copy (sweep) * g y = np.copy (cur_sweep) filter = NLFeedback() filter.setCoefs (b, a) filter.fb_lambda = lambda a,x : a*np.tanh (x) y = filter.process_block (y) h = adsp.normalize (adsp.sweep2ir (cur_sweep, y))
root2 = pole_mag * np.exp(-1j * pole_angle) poly = np.poly((root1, root2)) yTP = np.zeros(np.shape(x)) yTP[:, 0] = signal.lfilter([1], [1, poly[1], poly[2]], x[:, 0]) yTP[:, 1] = signal.lfilter([1], [1, poly[1], poly[2]], x[:, 1]) modelTP = Model() fb = FB2() fb.pole_mag = pole_mag fb.pole_angle = pole_angle modelTP.elements.append(fb) add_to_tests(modelTP, 'Two-pole-test', yTP, ys, names, models) # Lowpass filter b, a = adsp.design_LPF2(1000, 0.7071, fs) yLPF = np.zeros(np.shape(x)) yLPF[:, 0] = signal.lfilter(b, a, x[:, 0]) yLPF[:, 1] = signal.lfilter(b, a, x[:, 1]) modelLPF = Model('DF2_Test') modelLPF.elements.append( Feedback([Split([[Gain(a[1])], [UnitDelay(), Gain(a[2])]]), Gain(-1.0)])) modelLPF.elements.append( Split([[Gain(b[0])], [UnitDelay(), Gain(b[1])], [UnitDelay(), UnitDelay(), Gain(b[2])]])) add_to_tests(modelLPF, 'test_DF2', yLPF, ys, names, models) for n in range(len(models)): print(f'Generating Faust for: {names[n]}')
def time_LPF2_filter(self): for _ in range(_num_): adsp.design_LPF2(_fc_, _Q_, _fs_)
def design_SKLPF(R, C, R1, R2, fs, age=1, temp=300, ageRs=True, ageCs=True, failCs=True): fc = 1.0 / (2 * np.pi * getResVal(R, age if ageRs else 1, temp) * getCapVal(C, age if ageCs else 1, temp, fail=failCs)) Q = 1.0 / (2 - (getResVal(R2, age if ageRs else 1, temp) / getResVal(R1, age if ageRs else 1, temp))) return adsp.design_LPF2(fc, Q, fs)
#%% def design_allpole(pole_mags, pole_freqs, fs): poles = [] for n in range(len(pole_mags)): w_p = pole_freqs[n] / fs * (2 * np.pi) poles.append(pole_mags[n] * np.exp(1j * w_p)) a = np.poly(np.asarray(poles)) return np.array([1]), a mags = np.array([q2damp(1000, 10, 44100), q2damp(1000, 10, 44100)]) poles = np.array([1000, -1000]) b, a = design_allpole(mags, poles, 44100) btest, atest = adsp.design_LPF2(1000, 10, 44100) btest = np.array([1, 0, 0]) roots = np.roots(atest) print(np.abs(roots[0])) adsp.plot_magnitude_response(b, a, fs=44100) adsp.plot_magnitude_response(btest, atest, fs=44100) plt.axvline(1000, color='r') #%% class AllPole: def __init__(self):
def design_SKLPF(R, C, R1, R2): fc = 1.0 / (2 * np.pi * R * C) Q = 1.0 / (2 - (R2 / R1)) return adsp.design_LPF2(fc, Q, fs)
def design_SKLPF2(R, C, R1, R2, fs, tol=0): fc = 1.0 / (2 * np.pi * getCompVal2(R, tol/2, tol) * getCompVal2(C, tol/2, tol)) Q = 1.0 / (2 - (getCompVal2(R2, tol/2, tol) / getCompVal2(R1, tol/2, tol))) return adsp.design_LPF2(fc, Q, fs)
def design_SKLPF(R, C, R1, R2, fs, age=1, temp=300): fc = 1.0 / (2 * np.pi * R * C) Q = 1.0 / (2 - (R2 / R1)) return adsp.design_LPF2(fc, Q, fs)