@@ -376,28 +376,51 @@ def test_sample_system(self, tsys):
376
376
@pytest .mark .parametrize ("plantname" ,
377
377
["siso_ss1c" ,
378
378
"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 ):
380
386
"""bilinear approximation with prewarping test"""
381
- wwarp = 50
382
- Ts = 0.025
383
387
# test state space version
384
388
plant = getattr (tsys , plantname )
385
389
plant_fr = plant (wwarp * 1j )
390
+ alpha = 0.5 if discretization_type == 'gbt' else None
386
391
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 )
388
394
dt = plant_d_warped .dt
389
395
plant_d_fr = plant_d_warped (np .exp (wwarp * 1.j * dt ))
390
396
np .testing .assert_array_almost_equal (plant_fr , plant_d_fr )
391
397
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 )
394
400
plant_d_fr = plant_d_warped (np .exp (wwarp * 1.j * dt ))
395
401
np .testing .assert_array_almost_equal (plant_fr , plant_d_fr )
396
402
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 )
398
405
plant_d_fr = plant_d_warped (np .exp (wwarp * 1.j * dt ))
399
406
np .testing .assert_array_almost_equal (plant_fr , plant_d_fr )
400
407
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
+
401
424
def test_sample_system_errors (self , tsys ):
402
425
# Check errors
403
426
with pytest .raises (ValueError ):
@@ -446,11 +469,11 @@ def test_discrete_bode(self, tsys):
446
469
np .testing .assert_array_almost_equal (omega , omega_out )
447
470
np .testing .assert_array_almost_equal (mag_out , np .absolute (H_z ))
448
471
np .testing .assert_array_almost_equal (phase_out , np .angle (H_z ))
449
-
472
+
450
473
def test_signal_names (self , tsys ):
451
474
"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' ])
454
477
ssd = ssc .sample (0.1 )
455
478
tfc = TransferFunction (tsys .siso_tf1c , inputs = 'u' , outputs = 'y' )
456
479
tfd = tfc .sample (0.1 )
@@ -467,7 +490,7 @@ def test_signal_names(self, tsys):
467
490
assert ssd .output_labels == ['y' ]
468
491
assert tfd .input_labels == ['u' ]
469
492
assert tfd .output_labels == ['y' ]
470
-
493
+
471
494
# system names and signal name override
472
495
sysc = StateSpace (1.1 , 1 , 1 , 1 , inputs = 'u' , outputs = 'y' , states = 'a' )
473
496
@@ -488,14 +511,14 @@ def test_signal_names(self, tsys):
488
511
assert sysd_nocopy .find_state ('a' ) is None
489
512
490
513
# 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 ,
492
515
inputs = 'v' , outputs = 'x' , states = 'b' )
493
516
assert sysd_newnames .find_input ('v' ) == 0
494
517
assert sysd_newnames .find_input ('u' ) is None
495
518
assert sysd_newnames .find_output ('x' ) == 0
496
519
assert sysd_newnames .find_output ('y' ) is None
497
520
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
499
522
# test just one name
500
523
sysd_newnames = sample_system (sysc , 0.1 , inputs = 'v' )
501
524
assert sysd_newnames .find_input ('v' ) == 0
0 commit comments