@@ -376,28 +376,51 @@ def test_sample_system(self, tsys):
376376 @pytest .mark .parametrize ("plantname" ,
377377 ["siso_ss1c" ,
378378 "siso_tf1c" ])
379- def test_sample_system_prewarp (self , tsys , plantname ):
379+ @pytest .mark .parametrize ("wwarp" ,
380+ [.1 , 1 , 3 ])
381+ @pytest .mark .parametrize ("Ts" ,
382+ [.1 , 1 ])
383+ @pytest .mark .parametrize ("discretization_type" ,
384+ ['bilinear' , 'tustin' , 'gbt' ])
385+ def test_sample_system_prewarp (self , tsys , plantname , discretization_type , wwarp , Ts ):
380386 """bilinear approximation with prewarping test"""
381- wwarp = 50
382- Ts = 0.025
383387 # test state space version
384388 plant = getattr (tsys , plantname )
385389 plant_fr = plant (wwarp * 1j )
390+ alpha = 0.5 if discretization_type == 'gbt' else None
386391
387- plant_d_warped = plant .sample (Ts , 'bilinear' , prewarp_frequency = wwarp )
392+ plant_d_warped = plant .sample (Ts , discretization_type ,
393+ prewarp_frequency = wwarp , alpha = alpha )
388394 dt = plant_d_warped .dt
389395 plant_d_fr = plant_d_warped (np .exp (wwarp * 1.j * dt ))
390396 np .testing .assert_array_almost_equal (plant_fr , plant_d_fr )
391397
392- plant_d_warped = sample_system (plant , Ts , 'bilinear' ,
393- prewarp_frequency = wwarp )
398+ plant_d_warped = sample_system (plant , Ts , discretization_type ,
399+ prewarp_frequency = wwarp , alpha = alpha )
394400 plant_d_fr = plant_d_warped (np .exp (wwarp * 1.j * dt ))
395401 np .testing .assert_array_almost_equal (plant_fr , plant_d_fr )
396402
397- plant_d_warped = c2d (plant , Ts , 'bilinear' , prewarp_frequency = wwarp )
403+ plant_d_warped = c2d (plant , Ts , discretization_type ,
404+ prewarp_frequency = wwarp , alpha = alpha )
398405 plant_d_fr = plant_d_warped (np .exp (wwarp * 1.j * dt ))
399406 np .testing .assert_array_almost_equal (plant_fr , plant_d_fr )
400407
408+ @pytest .mark .parametrize ("plantname" ,
409+ ["siso_ss1c" ,
410+ "siso_tf1c" ])
411+ @pytest .mark .parametrize ("discretization_type" ,
412+ ['euler' , 'backward_diff' , 'zoh' ])
413+ def test_sample_system_prewarp_warning (self , tsys , plantname , discretization_type ):
414+ plant = getattr (tsys , plantname )
415+ wwarp = 1
416+ Ts = 0.1
417+ with pytest .warns (UserWarning , match = "prewarp_frequency ignored: incompatible conversion" ):
418+ plant_d_warped = plant .sample (Ts , discretization_type , prewarp_frequency = wwarp )
419+ with pytest .warns (UserWarning , match = "prewarp_frequency ignored: incompatible conversion" ):
420+ plant_d_warped = sample_system (plant , Ts , discretization_type , prewarp_frequency = wwarp )
421+ with pytest .warns (UserWarning , match = "prewarp_frequency ignored: incompatible conversion" ):
422+ plant_d_warped = c2d (plant , Ts , discretization_type , prewarp_frequency = wwarp )
423+
401424 def test_sample_system_errors (self , tsys ):
402425 # Check errors
403426 with pytest .raises (ValueError ):
@@ -446,11 +469,11 @@ def test_discrete_bode(self, tsys):
446469 np .testing .assert_array_almost_equal (omega , omega_out )
447470 np .testing .assert_array_almost_equal (mag_out , np .absolute (H_z ))
448471 np .testing .assert_array_almost_equal (phase_out , np .angle (H_z ))
449-
472+
450473 def test_signal_names (self , tsys ):
451474 "test that signal names are preserved in conversion to discrete-time"
452- ssc = StateSpace (tsys .siso_ss1c ,
453- inputs = 'u' , outputs = 'y' , states = ['a' , 'b' , 'c' ])
475+ ssc = StateSpace (tsys .siso_ss1c ,
476+ inputs = 'u' , outputs = 'y' , states = ['a' , 'b' , 'c' ])
454477 ssd = ssc .sample (0.1 )
455478 tfc = TransferFunction (tsys .siso_tf1c , inputs = 'u' , outputs = 'y' )
456479 tfd = tfc .sample (0.1 )
@@ -467,7 +490,7 @@ def test_signal_names(self, tsys):
467490 assert ssd .output_labels == ['y' ]
468491 assert tfd .input_labels == ['u' ]
469492 assert tfd .output_labels == ['y' ]
470-
493+
471494 # system names and signal name override
472495 sysc = StateSpace (1.1 , 1 , 1 , 1 , inputs = 'u' , outputs = 'y' , states = 'a' )
473496
@@ -488,14 +511,14 @@ def test_signal_names(self, tsys):
488511 assert sysd_nocopy .find_state ('a' ) is None
489512
490513 # if signal names are provided, they should override those of sysc
491- sysd_newnames = sample_system (sysc , 0.1 ,
514+ sysd_newnames = sample_system (sysc , 0.1 ,
492515 inputs = 'v' , outputs = 'x' , states = 'b' )
493516 assert sysd_newnames .find_input ('v' ) == 0
494517 assert sysd_newnames .find_input ('u' ) is None
495518 assert sysd_newnames .find_output ('x' ) == 0
496519 assert sysd_newnames .find_output ('y' ) is None
497520 assert sysd_newnames .find_state ('b' ) == 0
498- assert sysd_newnames .find_state ('a' ) is None
521+ assert sysd_newnames .find_state ('a' ) is None
499522 # test just one name
500523 sysd_newnames = sample_system (sysc , 0.1 , inputs = 'v' )
501524 assert sysd_newnames .find_input ('v' ) == 0
0 commit comments