def test_evalfr_siso(self): """Evaluate the frequency response of a SISO system at one frequency.""" sys = TransferFunction([1., 3., 5], [1., 6., 2., -1]) np.testing.assert_array_almost_equal(evalfr(sys, 1j), np.array([[-0.5 - 0.5j]])) np.testing.assert_array_almost_equal(evalfr(sys, 32j), np.array([[0.00281959302585077 - 0.030628473607392j]])) # Test call version as well np.testing.assert_almost_equal(sys(1.j), -0.5 - 0.5j) np.testing.assert_almost_equal(sys(32.j), 0.00281959302585077 - 0.030628473607392j) # Test internal version (with real argument) np.testing.assert_array_almost_equal(sys._evalfr(1.), np.array([[-0.5 - 0.5j]])) np.testing.assert_array_almost_equal(sys._evalfr(32.), np.array([[0.00281959302585077 - 0.030628473607392j]])) # Deprecated version of the call (should generate warning) import warnings with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") sys.evalfr(1.) assert len(w) == 1 assert issubclass(w[-1].category, PendingDeprecationWarning)
def test_squeeze_exceptions(self, fcn): if fcn == ct.frd: sys = fcn(ct.rss(2, 1, 1), [1e-2, 1e-1, 1, 1e1, 1e2]) else: sys = fcn(ct.rss(2, 1, 1)) with pytest.raises(ValueError, match="unknown squeeze value"): sys.frequency_response([1], squeeze=1) with pytest.raises(ValueError, match="unknown squeeze value"): sys([1j], squeeze='siso') with pytest.raises(ValueError, match="unknown squeeze value"): evalfr(sys, [1j], squeeze='siso') with pytest.raises(ValueError, match="must be 1D"): sys.frequency_response([[0.1, 1], [1, 10]]) with pytest.raises(ValueError, match="must be 1D"): sys([[0.1j, 1j], [1j, 10j]]) with pytest.raises(ValueError, match="must be 1D"): evalfr(sys, [[0.1j, 1j], [1j, 10j]]) with pytest.warns(DeprecationWarning, match="LTI `inputs`"): ninputs = sys.inputs assert ninputs == sys.ninputs with pytest.warns(DeprecationWarning, match="LTI `outputs`"): noutputs = sys.outputs assert noutputs == sys.noutputs if isinstance(sys, ct.StateSpace): with pytest.warns(DeprecationWarning, match="StateSpace `states`"): nstates = sys.states assert nstates == sys.nstates
def testEvalFrSISO(self): """Evaluate the frequency response of a SISO system at one frequency.""" sys = TransferFunction([1., 3., 5], [1., 6., 2., -1]) np.testing.assert_array_almost_equal(evalfr(sys, 1j), np.array([[-0.5 - 0.5j]])) np.testing.assert_array_almost_equal( evalfr(sys, 32j), np.array([[0.00281959302585077 - 0.030628473607392j]])) # Test call version as well np.testing.assert_almost_equal(sys(1.j), -0.5 - 0.5j) np.testing.assert_almost_equal( sys(32.j), 0.00281959302585077 - 0.030628473607392j) # Test internal version (with real argument) np.testing.assert_array_almost_equal(sys._evalfr(1.), np.array([[-0.5 - 0.5j]])) np.testing.assert_array_almost_equal( sys._evalfr(32.), np.array([[0.00281959302585077 - 0.030628473607392j]])) # Deprecated version of the call (should generate warning) import warnings with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") sys.evalfr(1.) assert len(w) == 1 assert issubclass(w[-1].category, PendingDeprecationWarning)
def test_evalfr(self): """Evaluate the frequency response at one frequency.""" A = [[-2, 0.5], [0.5, -0.3]] B = [[0.3, -1.3], [0.1, 0.]] C = [[0., 0.1], [-0.3, -0.2]] D = [[0., -0.8], [-0.3, 0.]] sys = StateSpace(A, B, C, D) resp = [[ 4.37636761487965e-05 - 0.0152297592997812j, -0.792603938730853 + 0.0261706783369803j ], [ -0.331544857768052 + 0.0576105032822757j, 0.128919037199125 - 0.143824945295405j ]] # Correct versions of the call np.testing.assert_almost_equal(evalfr(sys, 1j), resp) np.testing.assert_almost_equal(sys._evalfr(1.), resp) # Deprecated version of the call (should generate warning) import warnings with warnings.catch_warnings(record=True) as w: # Set up warnings filter to only show warnings in control module warnings.filterwarnings("ignore") warnings.filterwarnings("always", module="control") # Make sure that we get a pending deprecation warning sys.evalfr(1.) assert len(w) == 1 assert issubclass(w[-1].category, PendingDeprecationWarning)
def test_evalfr(self, dt, omega, resp): """Evaluate the frequency response at single frequencies""" A = [[-2, 0.5], [0.5, -0.3]] B = [[0.3, -1.3], [0.1, 0.]] C = [[0., 0.1], [-0.3, -0.2]] D = [[0., -0.8], [-0.3, 0.]] sys = StateSpace(A, B, C, D) if dt: sys = sample_system(sys, dt) s = np.exp(omega * 1j * dt) else: s = omega * 1j # Correct version of the call np.testing.assert_allclose(evalfr(sys, s), resp, atol=1e-3) # Deprecated version of the call (should generate warning) with pytest.deprecated_call(): np.testing.assert_allclose(sys.evalfr(omega), resp, atol=1e-3) # call above nyquist frequency if dt: with pytest.warns(UserWarning): np.testing.assert_allclose(sys._evalfr(omega + 2 * np.pi / dt), resp, atol=1e-3)
def test_evalfr(self): """Evaluate the frequency response at one frequency.""" A = [[-2, 0.5], [0.5, -0.3]] B = [[0.3, -1.3], [0.1, 0.]] C = [[0., 0.1], [-0.3, -0.2]] D = [[0., -0.8], [-0.3, 0.]] sys = StateSpace(A, B, C, D) resp = [[4.37636761487965e-05 - 0.0152297592997812j, -0.792603938730853 + 0.0261706783369803j], [-0.331544857768052 + 0.0576105032822757j, 0.128919037199125 - 0.143824945295405j]] # Correct versions of the call np.testing.assert_almost_equal(evalfr(sys, 1j), resp) np.testing.assert_almost_equal(sys._evalfr(1.), resp) # Deprecated version of the call (should generate warning) import warnings with warnings.catch_warnings(record=True) as w: # Set up warnings filter to only show warnings in control module warnings.filterwarnings("ignore") warnings.filterwarnings("always", module="control") # Make sure that we get a pending deprecation warning sys.evalfr(1.) assert len(w) == 1 assert issubclass(w[-1].category, PendingDeprecationWarning)
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_evalfr_siso(self): """Evaluate the frequency response of a SISO system at one frequency.""" sys = TransferFunction([1., 3., 5], [1., 6., 2., -1]) np.testing.assert_array_almost_equal(evalfr(sys, 1j), np.array([[-0.5 - 0.5j]])) np.testing.assert_array_almost_equal( evalfr(sys, 32j), np.array([[0.00281959302585077 - 0.030628473607392j]])) # Test call version as well np.testing.assert_almost_equal(sys(1.j), -0.5 - 0.5j) np.testing.assert_almost_equal( sys(32.j), 0.00281959302585077 - 0.030628473607392j) # Test internal version (with real argument) np.testing.assert_array_almost_equal(sys._evalfr(1.), np.array([[-0.5 - 0.5j]])) np.testing.assert_array_almost_equal( sys._evalfr(32.), np.array([[0.00281959302585077 - 0.030628473607392j]]))
def test_evalfr_siso(self): """Evaluate the frequency response of a SISO system at one frequency.""" sys = TransferFunction([1., 3., 5], [1., 6., 2., -1]) np.testing.assert_array_almost_equal(evalfr(sys, 1j), np.array([[-0.5 - 0.5j]])) np.testing.assert_array_almost_equal( evalfr(sys, 32j), np.array([[0.00281959302585077 - 0.030628473607392j]])) # Test call version as well np.testing.assert_almost_equal(sys(1.j), -0.5 - 0.5j) np.testing.assert_almost_equal( sys(32.j), 0.00281959302585077 - 0.030628473607392j) # Test internal version (with real argument) np.testing.assert_array_almost_equal( sys._evalfr(1.), np.array([[-0.5 - 0.5j]])) np.testing.assert_array_almost_equal( sys._evalfr(32.), np.array([[0.00281959302585077 - 0.030628473607392j]]))
def test_call_mimo(self): """Evaluate the frequency response of a MIMO system at one frequency.""" num = [[[1., 2.], [0., 3.], [2., -1.]], [[1.], [4., 0.], [1., -4., 3.]]] den = [[[-3., 2., 4.], [1., 0., 0.], [2., -1.]], [[3., 0., .0], [2., -1., -1.], [1.]]] sys = TransferFunction(num, den) resp = [[0.147058823529412 + 0.0882352941176471j, -0.75, 1.], [-0.083333333333333, -0.188235294117647 - 0.847058823529412j, -1. - 8.j]] np.testing.assert_array_almost_equal(evalfr(sys, 2j), resp) # Test call version as well np.testing.assert_array_almost_equal(sys(2.j), resp)
def test_call_siso(self, dt, omega, resp): """Evaluate the frequency response of a SISO system at one frequency.""" sys = TransferFunction([1., 3., 5], [1., 6., 2., -1]) if dt: sys = sample_system(sys, dt) s = np.exp(omega * 1j * dt) else: s = omega * 1j # Correct versions of the call np.testing.assert_allclose(evalfr(sys, s), resp, atol=1e-3) np.testing.assert_allclose(sys(s), resp, atol=1e-3) # Deprecated version of the call (should generate exception) with pytest.raises(AttributeError): np.testing.assert_allclose(sys.evalfr(omega), resp, atol=1e-3)
def test_call(self, dt, omega, resp): """Evaluate the frequency response at single frequencies""" A = [[-2, 0.5], [0.5, -0.3]] B = [[0.3, -1.3], [0.1, 0.]] C = [[0., 0.1], [-0.3, -0.2]] D = [[0., -0.8], [-0.3, 0.]] sys = StateSpace(A, B, C, D) if dt: sys = sample_system(sys, dt) s = np.exp(omega * 1j * dt) else: s = omega * 1j # Correct versions of the call np.testing.assert_allclose(evalfr(sys, s), resp, atol=1e-3) np.testing.assert_allclose(sys(s), resp, atol=1e-3) # Deprecated name of the call (should generate error) with pytest.raises(AttributeError): sys.evalfr(omega)
def test_evalfr_siso(self, dt, omega, resp): """Evaluate the frequency response at single frequencies""" sys = TransferFunction([1., 3., 5], [1., 6., 2., -1]) if dt: sys = sample_system(sys, dt) s = np.exp(omega * 1j * dt) else: s = omega * 1j # Correct versions of the call np.testing.assert_allclose(evalfr(sys, s), resp, atol=1e-3) np.testing.assert_allclose(sys(s), resp, atol=1e-3) # Deprecated version of the call (should generate warning) with pytest.deprecated_call(): np.testing.assert_allclose(sys.evalfr(omega), resp, atol=1e-3) # call above nyquist frequency if dt: with pytest.warns(UserWarning): np.testing.assert_allclose(sys._evalfr(omega + 2 * np.pi / dt), resp, atol=1e-3)