@@ -120,39 +120,62 @@ def test_mimo():
120120 tf (sysMIMO )
121121
122122
123- def test_bode_margin ():
123+ @pytest .mark .parametrize (
124+ "Hz, Wcp, Wcg" ,
125+ [pytest .param (False , 6.0782869 , 10. , id = "omega" ),
126+ pytest .param (True , 0.9673894 , 1.591549 , id = "Hz" )])
127+ @pytest .mark .parametrize (
128+ "deg, p0, pm" ,
129+ [pytest .param (False , - np .pi , - 2.748266 , id = "rad" ),
130+ pytest .param (True , - 180 , - 157.46405841 , id = "deg" )])
131+ @pytest .mark .parametrize (
132+ "dB, maginfty1, maginfty2, gminv" ,
133+ [pytest .param (False , 1 , 1e-8 , 0.4 , id = "mag" ),
134+ pytest .param (True , 0 , - 1e+5 , - 7.9588 , id = "dB" )])
135+ def test_bode_margin (dB , maginfty1 , maginfty2 , gminv ,
136+ deg , p0 , pm ,
137+ Hz , Wcp , Wcg ):
124138 """Test bode margins"""
125139 num = [1000 ]
126140 den = [1 , 25 , 100 , 0 ]
127141 sys = ctrl .tf (num , den )
128142 plt .figure ()
129- ctrl .bode_plot (sys , margins = True , dB = False , deg = True , Hz = False )
143+ ctrl .bode_plot (sys , margins = True , dB = dB , deg = deg , Hz = Hz )
130144 fig = plt .gcf ()
131145 allaxes = fig .get_axes ()
132146
133- mag_to_infinity = (np .array ([6.07828691 , 6.07828691 ]),
134- np .array ([1. , 1e-8 ]))
135- assert_allclose (mag_to_infinity , allaxes [0 ].lines [2 ].get_data ())
136-
137- gm_to_infinty = (np .array ([10. , 10. ]),
138- np .array ([4e-1 , 1e-8 ]))
139- assert_allclose (gm_to_infinty , allaxes [0 ].lines [3 ].get_data ())
140-
141- one_to_gm = (np .array ([10. , 10. ]),
142- np .array ([1. , 0.4 ]))
143- assert_allclose (one_to_gm , allaxes [0 ].lines [4 ].get_data ())
144-
145- pm_to_infinity = (np .array ([6.07828691 , 6.07828691 ]),
146- np .array ([100000. , - 157.46405841 ]))
147- assert_allclose (pm_to_infinity , allaxes [1 ].lines [2 ].get_data ())
148-
149- pm_to_phase = (np .array ([6.07828691 , 6.07828691 ]),
150- np .array ([- 157.46405841 , - 180. ]))
151- assert_allclose (pm_to_phase , allaxes [1 ].lines [3 ].get_data ())
152-
153- phase_to_infinity = (np .array ([10. , 10. ]),
154- np .array ([1e-8 , - 1.8e2 ]))
155- assert_allclose (phase_to_infinity , allaxes [1 ].lines [4 ].get_data ())
147+ mag_to_infinity = (np .array ([Wcp , Wcp ]),
148+ np .array ([maginfty1 , maginfty2 ]))
149+ assert_allclose (mag_to_infinity ,
150+ allaxes [0 ].lines [2 ].get_data (),
151+ rtol = 1e-5 )
152+
153+ gm_to_infinty = (np .array ([Wcg , Wcg ]),
154+ np .array ([gminv , maginfty2 ]))
155+ assert_allclose (gm_to_infinty ,
156+ allaxes [0 ].lines [3 ].get_data (),
157+ rtol = 1e-5 )
158+
159+ one_to_gm = (np .array ([Wcg , Wcg ]),
160+ np .array ([maginfty1 , gminv ]))
161+ assert_allclose (one_to_gm , allaxes [0 ].lines [4 ].get_data (),
162+ rtol = 1e-5 )
163+
164+ pm_to_infinity = (np .array ([Wcp , Wcp ]),
165+ np .array ([1e5 , pm ]))
166+ assert_allclose (pm_to_infinity ,
167+ allaxes [1 ].lines [2 ].get_data (),
168+ rtol = 1e-5 )
169+
170+ pm_to_phase = (np .array ([Wcp , Wcp ]),
171+ np .array ([pm , p0 ]))
172+ assert_allclose (pm_to_phase , allaxes [1 ].lines [3 ].get_data (),
173+ rtol = 1e-5 )
174+
175+ phase_to_infinity = (np .array ([Wcg , Wcg ]),
176+ np .array ([1e-8 , p0 ]))
177+ assert_allclose (phase_to_infinity , allaxes [1 ].lines [4 ].get_data (),
178+ rtol = 1e-5 )
156179
157180
158181@pytest .fixture
0 commit comments