6363from .exception import ControlSlycot
6464from .frdata import FrequencyResponseData
6565from .lti import LTI , _process_frequency_response
66- from .namedio import common_timebase , isdtime
67- from . namedio import _process_namedio_keywords
66+ from .namedio import common_timebase , isdtime , _process_namedio_keywords , \
67+ _process_dt_keyword
6868from . import config
6969from copy import deepcopy
7070
@@ -357,9 +357,9 @@ def __init__(self, *args, init_namedio=True, **kwargs):
357357 states = states , dt = dt )
358358 elif kwargs :
359359 raise TypeError ("unrecognized keyword(s): " , str (kwargs ))
360-
360+
361361 # Reset shapes (may not be needed once np.matrix support is removed)
362- if 0 == self .nstates :
362+ if self ._isstatic () :
363363 # static gain
364364 # matrix's default "empty" shape is 1x0
365365 A .shape = (0 , 0 )
@@ -1298,7 +1298,8 @@ def __getitem__(self, indices):
12981298 return StateSpace (self .A , self .B [:, j ], self .C [i , :],
12991299 self .D [i , j ], self .dt )
13001300
1301- def sample (self , Ts , method = 'zoh' , alpha = None , prewarp_frequency = None ):
1301+ def sample (self , Ts , method = 'zoh' , alpha = None , prewarp_frequency = None ,
1302+ name = None , copy_names = True , ** kwargs ):
13021303 """Convert a continuous time system to discrete time
13031304
13041305 Creates a discrete-time system from a continuous-time system by
@@ -1317,22 +1318,44 @@ def sample(self, Ts, method='zoh', alpha=None, prewarp_frequency=None):
13171318 alpha=0)
13181319 * backward_diff: Backwards differencing ("gbt" with alpha=1.0)
13191320 * zoh: zero-order hold (default)
1320-
13211321 alpha : float within [0, 1]
13221322 The generalized bilinear transformation weighting parameter, which
13231323 should only be specified with method="gbt", and is ignored
13241324 otherwise
1325-
13261325 prewarp_frequency : float within [0, infinity)
13271326 The frequency [rad/s] at which to match with the input continuous-
13281327 time system's magnitude and phase (the gain=1 crossover frequency,
13291328 for example). Should only be specified with method='bilinear' or
13301329 'gbt' with alpha=0.5 and ignored otherwise.
1330+ copy_names : bool, Optional
1331+ If `copy_names` is True, copy the names of the input signals, output
1332+ signals, and states to the sampled system. If `name` is not
1333+ specified, the system name is set to the input system name with the
1334+ string '_sampled' appended.
1335+ name : string, optional
1336+ Set the name of the sampled system. If not specified and
1337+ if `copy` is `False`, a generic name <sys[id]> is generated
1338+ with a unique integer id. If `copy` is `True`, the new system
1339+ name is determined by adding the prefix and suffix strings in
1340+ config.defaults['namedio.sampled_system_name_prefix'] and
1341+ config.defaults['namedio.sampled_system_name_suffix'], with the
1342+ default being to add the suffix '$sampled'.
13311343
13321344 Returns
13331345 -------
13341346 sysd : StateSpace
1335- Discrete time system, with sampling rate Ts
1347+ Discrete-time system, with sampling rate Ts
1348+
1349+ Additional Parameters
1350+ ---------------------
1351+ inputs : int, list of str or None, optional
1352+ Description of the system inputs. If not specified, the origional
1353+ system inputs are used. See :class:`InputOutputSystem` for more
1354+ information.
1355+ outputs : int, list of str or None, optional
1356+ Description of the system outputs. Same format as `inputs`.
1357+ states : int, list of str, or None, optional
1358+ Description of the system states. Same format as `inputs`.
13361359
13371360 Notes
13381361 -----
@@ -1354,10 +1377,18 @@ def sample(self, Ts, method='zoh', alpha=None, prewarp_frequency=None):
13541377 Twarp = Ts
13551378 sys = (self .A , self .B , self .C , self .D )
13561379 Ad , Bd , C , D , _ = cont2discrete (sys , Twarp , method , alpha )
1357- # get and pass along same signal names
1358- _ , inputs , outputs , states , _ = _process_namedio_keywords (defaults = self )
1359- return StateSpace (Ad , Bd , C , D , Ts ,
1360- inputs = inputs , outputs = outputs , states = states )
1380+ sysd = StateSpace (Ad , Bd , C , D , Ts )
1381+ # copy over the system name, inputs, outputs, and states
1382+ if copy_names :
1383+ if name is None :
1384+ name = \
1385+ config .defaults ['namedio.sampled_system_name_prefix' ] + \
1386+ self .name + \
1387+ config .defaults ['namedio.sampled_system_name_suffix' ]
1388+ sysd ._copy_names (self , name = name )
1389+ # pass desired signal names if names were provided
1390+ sysd = StateSpace (sysd , ** kwargs )
1391+ return sysd
13611392
13621393 def dcgain (self , warn_infinite = False ):
13631394 """Return the zero-frequency gain
0 commit comments