def test_margin_3input(tsys): sys, refout, refoutall = tsys """Test margin() function with mag, phase, omega input""" omega = np.logspace(-2, 2, 2000) mag, phase, omega_ = sys.frequency_response(omega) out = margin((mag, phase * 180 / np.pi, omega_)) assert_allclose(out, np.array(refout)[[0, 1, 3, 4]], atol=1.5e-3)
def test_zmore_margin(tsys_zmore): """Test margins for more tricky systems Note ---- Matlab gives gain margin 0 for system `type2`, python-control gives inf Difficult to argue which is right? Special case or different approach? Edge cases, like `type0` which approaches a gain of 1 for w -> 0, are also not identically indicated, Matlab gives phase margin -180, at w = 0. For higher or lower gains, results match. """ res = margin(tsys_zmore['sys'] * tsys_zmore['K']) assert_allclose(res, tsys_zmore['result'], atol=tsys_zmore['atol'])
def test_margin_sys(tsys): sys, refout, refoutall = tsys """Test margin() function with system input""" out = margin(sys) assert_allclose(out, np.array(refout)[[0, 1, 3, 4]], atol=1.5e-3)
def test_zmore_margin(tmargin): """Test margins for more tricky systems""" res = margin(tzmore_sys[tmargin['sys']] * tmargin['K']) assert_allclose(res, tmargin['result'], atol=tmargin['atol'])