def test_buttord_2(self): # Test case for highpass filter self.assertTrue( np.all( IIRDesign.buttord(self.f2, self.f1, self.Rp, self.Rs) == signal.buttord( self.f2, self.f1, self.Rp, self.Rs, analog=False, fs=2)))
def test_polystab(self): # test case x = [1, -2, -3] v = np.roots(x) vs = 0.5 * (np.sign(np.abs(v) - 1) + 1) v = (1 - vs) * v + vs / np.conj(v) b = x[0] * np.poly(v) self.assertTrue(np.all(IIRDesign.polystab(self.a) == b))
def test_impz_4(self): # Test case for IIR filter with n fil = IIRDesign.butter(6, self.fc / (self.fs / 2)) dl = signal.dlti(fil[0], fil[1], dt=1 / self.fs) i_d = signal.dimpulse(dl, n=self.n) T = i_d[0] yout = i_d[1][0] tt, y = FilterSpec.impz(fil, n=self.n, fs=self.fs) self.assertTrue(np.all(tt == T) and np.all(y == yout))
def test_ellipord_3(self): # Test case for bandpass filter ORD = IIRDesign.ellipord(self.f3, self.f4, self.Rp, self.Rs) ord = signal.ellipord(self.f3, self.f4, self.Rp, self.Rs, analog=False, fs=2) self.assertTrue((ORD[0] == ord[0]) and np.all(ORD[1] == ord[1]))
def test_buttord_4(self): # Test case for bandstop filter ORD = IIRDesign.buttord(self.f4, self.f3, self.Rp, self.Rs) ord = signal.buttord(self.f4, self.f3, self.Rp, self.Rs, analog=False, fs=2) self.assertTrue((ORD[0] == ord[0]) and (ORD[1] == ord[1]).all())
def test_cheb1ord_9(self): # Test case for Exception 4 with self.assertRaises(ValueError): IIRDesign.cheb1ord(self.f3, [0.1, 0.6, 0.7], self.Rp, self.Rs)
def test_cheb1ord_7(self): # Test case for Exception 2 with self.assertRaises(ValueError): IIRDesign.cheb1ord(0.2, 75, self.Rp, self.Rs)
def test_cheb1ord_5(self): # Test case for analog filter self.assertTrue(np.all(IIRDesign.cheb1ord(60, 75, self.Rp, self.Rs, zs='s') == signal.cheb1ord(60, 75, self.Rp, self.Rs, analog=True, fs=None)))
def test_ellip_16(self): # test case for Exception 9 with self.assertRaises(ValueError): IIRDesign.ellip(self.n, self.Rp, self.Rs, self.Wp1, ftype='bandpass')
def test_ellip_14(self): # test case for Exception 7 with self.assertRaises(ValueError): IIRDesign.ellip(self.n, self.Rp, self.Rs, self.Wp2, ftype='high')
def test_ellip_11(self): # test case for Exception 4 with self.assertRaises(ValueError): IIRDesign.ellip(self.n, self.Rp, self.Rs, 1.4, zs='z')
def test_cheby1_15(self): # Test case for exception 8 with self.assertRaises(ValueError): IIRDesign.cheby1(self.n, self.Rp, self.Wp1, ftype='stop')
def test_cheby1_14(self): # Test case for exception 7 with self.assertRaises(ValueError): IIRDesign.cheby1(self.n, self.Rp, self.Wp2, ftype='high')
def test_cheby1_11(self): # Test case for exception 4 with self.assertRaises(ValueError): IIRDesign.cheby1(self.n, self.Rp, self.Wps, ftype='low')
def test_cheby1_10(self): # Test case for exception 3 with self.assertRaises(ValueError): IIRDesign.cheby1(2.5, self.Rp, self.Wp2, ftype='bandpass')
def test_ellip_8(self): # test case for Exception 1 with self.assertRaises(ValueError): IIRDesign.ellip(self.n, self.Rp, self.Rs, self.Wps, zs='x')
def test_ellip_9(self): # test case for Exception 2 with self.assertRaises(ValueError): IIRDesign.ellip(2.5, self.Rp, self.Rs, self.Wp1)
def test_cheby1_16(self): # Test case for exception 9 with self.assertRaises(ValueError): IIRDesign.cheby1(self.n, self.Rp, self.Wp1, ftype='bandpass')
def test_ellip_12(self): # test case for Exception 5 with self.assertRaises(ValueError): IIRDesign.ellip(self.n, self.Rp, self.Rs, [0.5, 1.5], zs='z')
def test_polyscale(self): # Test case self.assertTrue( np.all( IIRDesign.polyscale(self.a, self.alpha) == (self.alpha * np.roots(self.a))))
def test_ellip_15(self): # test case for Exception 8 with self.assertRaises(ValueError): IIRDesign.ellip(self.n, self.Rp, self.Rs, self.Wp1, ftype='stop')
def test_ellip_1(self): # Test case for lowpass filter with default IIR = IIRDesign.ellip(self.n, self.Rp, self.Rs, self.Wp1) iir = signal.ellip(self.n, self.Rp, self.Rs, self.Wp1, btype='lowpass', fs=2) self.assertTrue((IIR[0] == iir[0]).all() and (IIR[1] == iir[1]).all())
def test_cheb1ord_1(self): # Test case for lowpass filter self.assertTrue(np.all(IIRDesign.cheb1ord(self.f1, self.f2, self.Rp, self.Rs) == signal.cheb1ord(self.f1, self.f2, self.Rp, self.Rs, analog=False, fs=2)))
def test_ellip_3(self): # Test case for highpass filter IIR = IIRDesign.ellip(self.n, self.Rp, self.Rs, self.Wp1, ftype='high') iir = signal.ellip(self.n, self.Rp, self.Rs, self.Wp1, btype='highpass', fs=2) self.assertTrue((IIR[0] == iir[0]).all() and (IIR[1] == iir[1]).all())
def test_cheb1ord_6(self): # Test case for Exception 1 with self.assertRaises(ValueError): IIRDesign.cheb1ord(60, 75, self.Rp, self.Rs, zs='x')
def test_ellip_5(self): # Test case for bandpass filter without default IIR = IIRDesign.ellip(self.n, self.Rp, self.Rs, self.Wp2, ftype='bandpass') iir = signal.ellip(self.n, self.Rp, self.Rs, self.Wp2, btype='bandpass', fs=2) self.assertTrue((IIR[0] == iir[0]).all() and (IIR[1] == iir[1]).all())
def test_cheb1ord_8(self): # Test case for Exception 3 with self.assertRaises(ValueError): IIRDesign.cheb1ord(self.f3, [1, 6], self.Rp, self.Rs)
def test_ellip_6(self): # Test case for bandstop filter IIR = IIRDesign.ellip(self.n, self.Rp, self.Rs, self.Wp2, ftype='stop') iir = signal.ellip(self.n, self.Rp, self.Rs, self.Wp2, btype='bandstop', fs=2) self.assertTrue((IIR[0] == iir[0]).all() and (IIR[1] == iir[1]).all())
def test_cheb1ord_11(self): # Test case for Exception 6 with self.assertRaises(ValueError): IIRDesign.cheb1ord(self.f1, self.f2, self.Rp, 'x')
def test_ellip_7(self): # Test case for analog filter IIR = IIRDesign.ellip(self.n, self.Rp, self.Rs, self.Wps, zs='s') iir = signal.ellip(self.n, self.Rp, self.Rs, self.Wps, btype='lowpass', analog=True) self.assertTrue((IIR[0] == iir[0]).all() and (IIR[1] == iir[1]).all())