def testMIMO(self): sys = StateSpace([[-0.5, 0.0], [0.0, -1.0]], [[1.0, 0.0], [0.0, 1.0]], [[1.0, 0.0], [0.0, 1.0]], [[0.0, 0.0], [0.0, 0.0]]) omega = np.logspace(-1, 2, 10) f1 = FRD(sys, omega) np.testing.assert_array_almost_equal( sys.freqresp([0.1, 1.0, 10])[0], f1.freqresp([0.1, 1.0, 10])[0]) np.testing.assert_array_almost_equal( sys.freqresp([0.1, 1.0, 10])[1], f1.freqresp([0.1, 1.0, 10])[1])
def testAgainstOctave(self): # with data from octave: #sys = ss([-2 0 0; 0 -1 1; 0 0 -3], [1 0; 0 0; 0 1], eye(3), zeros(3,2)) #bfr = frd(bsys, [1]) sys = StateSpace(np.matrix('-2.0 0 0; 0 -1 1; 0 0 -3'), np.matrix('1.0 0; 0 0; 0 1'), np.eye(3), np.zeros((3,2))) omega = np.logspace(-1, 2, 10) f1 = FRD(sys, omega) np.testing.assert_array_almost_equal( (f1.freqresp([1.0])[0] * np.exp(1j*f1.freqresp([1.0])[1])).reshape(3,2), np.matrix('0.4-0.2j 0; 0 0.1-0.2j; 0 0.3-0.1j'))
def testMIMO(self): sys = StateSpace([[-0.5, 0.0], [0.0, -1.0]], [[1.0, 0.0], [0.0, 1.0]], [[1.0, 0.0], [0.0, 1.0]], [[0.0, 0.0], [0.0, 0.0]]) omega = np.logspace(-1, 2, 10) f1 = FRD(sys, omega) np.testing.assert_array_almost_equal( sys.freqresp([0.1, 1.0, 10])[0], f1.freqresp([0.1, 1.0, 10])[0]) np.testing.assert_array_almost_equal( sys.freqresp([0.1, 1.0, 10])[1], f1.freqresp([0.1, 1.0, 10])[1])
def testAgainstOctave(self): # with data from octave: #sys = ss([-2 0 0; 0 -1 1; 0 0 -3], [1 0; 0 0; 0 1], eye(3), zeros(3,2)) #bfr = frd(bsys, [1]) sys = StateSpace(np.matrix('-2.0 0 0; 0 -1 1; 0 0 -3'), np.matrix('1.0 0; 0 0; 0 1'), np.eye(3), np.zeros((3, 2))) omega = np.logspace(-1, 2, 10) f1 = FRD(sys, omega) np.testing.assert_array_almost_equal( (f1.freqresp([1.0])[0] * np.exp(1j * f1.freqresp([1.0])[1])).reshape(3, 2), np.matrix('0.4-0.2j 0; 0 0.1-0.2j; 0 0.3-0.1j'))
def testMIMOfb2(self): sys = StateSpace(np.matrix('-2.0 0 0; 0 -1 1; 0 0 -3'), np.matrix('1.0 0; 0 0; 0 1'), np.eye(3), np.zeros((3,2))) omega = np.logspace(-1, 2, 10) K = np.matrix('1 0.3 0; 0.1 0 0') f1 = FRD(sys, omega).feedback(K) f2 = FRD(sys.feedback(K), omega) np.testing.assert_array_almost_equal( f1.freqresp([0.1, 1.0, 10])[0], f2.freqresp([0.1, 1.0, 10])[0]) np.testing.assert_array_almost_equal( f1.freqresp([0.1, 1.0, 10])[1], f2.freqresp([0.1, 1.0, 10])[1])
def testMIMOfb2(self): sys = StateSpace(np.array([[-2.0, 0, 0], [0, -1, 1], [0, 0, -3]]), np.array([[1.0, 0], [0, 0], [0, 1]]), np.eye(3), np.zeros((3, 2))) omega = np.logspace(-1, 2, 10) K = np.array([[1, 0.3, 0], [0.1, 0, 0]]) f1 = FRD(sys, omega).feedback(K) f2 = FRD(sys.feedback(K), omega) np.testing.assert_array_almost_equal( f1.freqresp([0.1, 1.0, 10])[0], f2.freqresp([0.1, 1.0, 10])[0]) np.testing.assert_array_almost_equal( f1.freqresp([0.1, 1.0, 10])[1], f2.freqresp([0.1, 1.0, 10])[1])
def testMIMOfb2(self): sys = StateSpace(np.matrix('-2.0 0 0; 0 -1 1; 0 0 -3'), np.matrix('1.0 0; 0 0; 0 1'), np.eye(3), np.zeros((3, 2))) omega = np.logspace(-1, 2, 10) K = np.matrix('1 0.3 0; 0.1 0 0') f1 = FRD(sys, omega).feedback(K) f2 = FRD(sys.feedback(K), omega) np.testing.assert_array_almost_equal( f1.freqresp([0.1, 1.0, 10])[0], f2.freqresp([0.1, 1.0, 10])[0]) np.testing.assert_array_almost_equal( f1.freqresp([0.1, 1.0, 10])[1], f2.freqresp([0.1, 1.0, 10])[1])
def testSISOtf(self): # get a SISO transfer function h = TransferFunction([1], [1, 2, 2]) omega = np.logspace(-1, 2, 10) frd = FRD(h, omega) assert isinstance(frd, FRD) np.testing.assert_array_almost_equal( frd.freqresp([1.0]), h.freqresp([1.0]))
def testSISOtf(self): # get a SISO transfer function h = TransferFunction([1], [1, 2, 2]) omega = np.logspace(-1, 2, 10) frd = FRD(h, omega) assert isinstance(frd, FRD) np.testing.assert_array_almost_equal(frd.freqresp([1.0]), h.freqresp([1.0]))
def testSISOtf(self): # get a SISO transfer function h = TransferFunction([1], [1, 2, 2]) omega = np.logspace(-1, 2, 10) frd = FRD(h, omega) assert isinstance(frd, FRD) mag1, phase1, omega1 = frd.freqresp([1.0]) mag2, phase2, omega2 = h.freqresp([1.0]) np.testing.assert_array_almost_equal(mag1, mag2) np.testing.assert_array_almost_equal(phase1, phase2) np.testing.assert_array_almost_equal(omega1, omega2)
def test_freqresp_deprecated(self): sys_tf = ct.tf([1], [1, 2, 1]) frd_tf = FRD(sys_tf, np.logspace(-1, 1, 3)) with pytest.warns(DeprecationWarning): frd_tf.freqresp(1.)