66Routines in this module:
77
88Lti.__init__
9-
9+ isdtime()
10+ isctime()
11+ timebase()
12+ timebaseEqual()
1013"""
1114
1215class Lti :
1316
1417 """Lti is a parent class to linear time invariant control (LTI) objects.
1518
16- Lti is the parent to the StateSpace and TransferFunction child classes. It
17- contains the number of inputs and outputs, but this can be expanded in the
18- future.
19+ Lti is the parent to the StateSpace and TransferFunction child
20+ classes. It contains the number of inputs and outputs, and the
21+ timebase (dt) for the system.
22+
23+ The timebase for the system, dt, is used to specify whether the
24+ system is operating in continuous or discrete time. It can have
25+ the following values:
26+
27+ * dt = None No timebase specified
28+ * dt = 0 Continuous time system
29+ * dt > 0 Discrete time system with sampling time dt
30+ * dt = True Discrete time system with unspecified sampling time
31+
32+ When to Lti systems are combined, there timebases much match. A system
33+ with timebase None can be combined with a system having a specified
34+ timebase, and the result will have the timebase of the latter system.
1935
2036 The StateSpace and TransferFunction child classes contain several common
2137 "virtual" functions. These are:
@@ -41,12 +57,32 @@ class Lti:
4157
4258 """
4359
44- def __init__ (self , inputs = 1 , outputs = 1 ):
60+ def __init__ (self , inputs = 1 , outputs = 1 , dt = None ):
4561 """Assign the LTI object's numbers of inputs and ouputs."""
4662
4763 # Data members common to StateSpace and TransferFunction.
4864 self .inputs = inputs
4965 self .outputs = outputs
66+ self .dt = dt
67+
68+ # Return the timebase of a system
69+ def timebase (sys ):
70+ # TODO: add docstring
71+ # If we get passed a constant, timebase is None
72+ if isinstance (sys , (int , float , long , complex )):
73+ return None
74+
75+ # Check for a transfer fucntion or state space object
76+ if isinstance (sys , Lti ):
77+ if sys .dt > 0 or sys .dt == True :
78+ return 'dtime' ;
79+ elif sys .dt == 0 :
80+ return 'ctime' ;
81+ elif sys .dt == None :
82+ return None
83+
84+ # Got pased something we don't recognize or bad timebase
85+ return False ;
5086
5187# Check to see if two timebases are equal
5288def timebaseEqual (dt1 , dt2 ):
@@ -59,3 +95,36 @@ def timebaseEqual(dt1, dt2):
5995 return True
6096 else :
6197 return dt1 == dt2
98+
99+ # Check to see if a system is a discrete time system
100+ def isdtime (sys , strict = False ):
101+ # TODO: add docstring
102+ # Check to see if this is a constant
103+ if isinstance (sys , (int , float , long , complex )):
104+ # OK as long as strict checking is off
105+ return True if not strict else False
106+
107+ # Check for a transfer fucntion or state space object
108+ if isinstance (sys , Lti ):
109+ # Look for dt > 0 or dt == None (if not strict)
110+ # Note that dt = True will be checked by dt > 0
111+ return sys .dt > 0 or (not strict and sys .dt == None )
112+
113+ # Got possed something we don't recognize
114+ return False
115+
116+ # Check to see if a system is a continuous time system
117+ def isctime (sys , strict = False ):
118+ # TODO: add docstring
119+ # Check to see if this is a constant
120+ if isinstance (sys , (int , float , long , complex )):
121+ # OK as long as strict checking is off
122+ return True if not strict else False
123+
124+ # Check for a transfer fucntion or state space object
125+ if isinstance (sys , Lti ):
126+ # Look for dt == 0 or dt == None (if not strict)
127+ return sys .dt == 0 or (not strict and sys .dt == None )
128+
129+ # Got possed something we don't recognize
130+ return False
0 commit comments