def test_size_mismatch(self): sys1 = ss2tf(rss(2, 2, 2)) # Different number of inputs sys2 = ss2tf(rss(3, 1, 2)) self.assertRaises(ValueError, TransferFunction.__add__, sys1, sys2) # Different number of outputs sys2 = ss2tf(rss(3, 2, 1)) self.assertRaises(ValueError, TransferFunction.__add__, sys1, sys2) # Inputs and outputs don't match self.assertRaises(ValueError, TransferFunction.__mul__, sys2, sys1) # Feedback mismatch (MIMO not implemented) self.assertRaises(NotImplementedError, TransferFunction.feedback, sys2, sys1)
def test_ss2tf(self): A = np.array([[-4, -1], [-1, -4]]) B = np.array([[1], [3]]) C = np.array([[3, 1]]) D = 0 sys = ss2tf(A, B, C, D) true_sys = TransferFunction([6., 14.], [1., 8., 15.]) np.testing.assert_almost_equal(sys.num, true_sys.num) np.testing.assert_almost_equal(sys.den, true_sys.den)
def test_printing(self): """Print SISO""" sys = ss2tf(rss(4, 1, 1)) assert isinstance(str(sys), str) assert isinstance(sys._repr_latex_(), str) # SISO, discrete time sys = sample_system(sys, 1) assert isinstance(str(sys), str) assert isinstance(sys._repr_latex_(), str)
def test_printing(self): # SISO, continuous time sys = ss2tf(rss(4, 1, 1)) self.assertTrue(isinstance(str(sys), str)) self.assertTrue(isinstance(sys._repr_latex_(), str)) # SISO, discrete time sys = sample_system(sys, 1) self.assertTrue(isinstance(str(sys), str)) self.assertTrue(isinstance(sys._repr_latex_(), str))
def test_size_mismatch(self): """Test size mismacht""" sys1 = ss2tf(rss(2, 2, 2)) # Different number of inputs sys2 = ss2tf(rss(3, 1, 2)) with pytest.raises(ValueError): TransferFunction.__add__(sys1, sys2) # Different number of outputs sys2 = ss2tf(rss(3, 2, 1)) with pytest.raises(ValueError): TransferFunction.__add__(sys1, sys2) # Inputs and outputs don't match with pytest.raises(ValueError): TransferFunction.__mul__(sys2, sys1) # Feedback mismatch (MIMO not implemented) with pytest.raises(NotImplementedError): TransferFunction.feedback(sys2, sys1)
def test_zero_siso(self): """Evaluate the zeros of a SISO system.""" # extract only first input / first output system of sys222. This system is denoted sys111 # or tf111 tf111 = ss2tf(self.sys222) sys111 = tf2ss(tf111[0, 0]) # compute zeros as root of the characteristic polynomial at the numerator of tf111 # this method is simple and assumed as valid in this test true_z = np.sort(tf111[0, 0].zero()) # Compute the zeros through ab08nd, which is tested here z = np.sort(sys111.zero()) np.testing.assert_almost_equal(true_z, z)
def test_indexing(self): tm = ss2tf(rss(5, 3, 3)) # scalar indexing sys01 = tm[0, 1] np.testing.assert_array_almost_equal(sys01.num[0][0], tm.num[0][1]) np.testing.assert_array_almost_equal(sys01.den[0][0], tm.den[0][1]) # slice indexing sys = tm[:2, 1:3] np.testing.assert_array_almost_equal(sys.num[0][0], tm.num[0][1]) np.testing.assert_array_almost_equal(sys.den[0][0], tm.den[0][1]) np.testing.assert_array_almost_equal(sys.num[0][1], tm.num[0][2]) np.testing.assert_array_almost_equal(sys.den[0][1], tm.den[0][2]) np.testing.assert_array_almost_equal(sys.num[1][0], tm.num[1][1]) np.testing.assert_array_almost_equal(sys.den[1][0], tm.den[1][1]) np.testing.assert_array_almost_equal(sys.num[1][1], tm.num[1][2]) np.testing.assert_array_almost_equal(sys.den[1][1], tm.den[1][2])
def test_sample_system_prewarping(self): """test that prewarping works when converting from cont to discrete time system""" A = np.array([ [ 0.00000000e+00, 1.00000000e+00, 0.00000000e+00, 0.00000000e+00], [-3.81097561e+01, -1.12500000e+00, 0.00000000e+00, 0.00000000e+00], [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.00000000e+00], [ 0.00000000e+00, 0.00000000e+00, -1.66356135e+04, -1.34748470e+01]]) B = np.array([ [ 0. ], [ 38.1097561 ],[ 0. ],[16635.61352143]]) C = np.array([[0.90909091, 0. , 0.09090909, 0. ],]) wwarp = 50 Ts = 0.025 plant = StateSpace(A,B,C,0) plant = ss2tf(plant) plant_d_warped = plant.sample(Ts, 'bilinear', prewarp_frequency=wwarp) np.testing.assert_array_almost_equal( evalfr(plant, wwarp*1j), evalfr(plant_d_warped, np.exp(wwarp*1j*Ts)), decimal=4)
def test_printing_mimo(self): """Print MIMO, continuous time""" sys = ss2tf(rss(4, 2, 3)) assert isinstance(str(sys), str) assert isinstance(sys._repr_latex_(), str)
def test_printing_mimo(self): # MIMO, continuous time sys = ss2tf(rss(4, 2, 3)) self.assertTrue(isinstance(str(sys), str)) self.assertTrue(isinstance(sys._repr_latex_(), str))