Skip to content

Commit 8d9bd08

Browse files
committed
Added discrete time simulation capability
* Moved timebase functions to lti.py * Implemented time response using scipy.signal.dsim * First cut at unit tests (needs more work)
1 parent 69129fb commit 8d9bd08

9 files changed

Lines changed: 197 additions & 171 deletions

File tree

ChangeLog

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
2012-10-07 Richard Murray <murray@altura.local>
2+
3+
* src/timeresp.py (forced_response): added discrete time simulator,
4+
using dlsim from scipy.signal
5+
6+
2012-10-07 Richard Murray <murray@altura.local>
7+
8+
* doc/conf.py: fixed release number (0.6a instead of 0.6c)
9+
10+
* src/__init__.py: moved timebase functions from dtime to lti
11+
12+
* src/lti.py: moved isdtime, isctime, timebase, and timebaseEqual
13+
from dtime.py to lti.py. Moved initialization of dt to
14+
Lti.__init__().
15+
16+
* src/statesp.py (StateSpace.__init__): Moved dt
17+
initialization to Lti object initialization
18+
19+
* src/xferfcn.py (TransferFunction.__init__): Moved dt
20+
initialization to Lti object initialization
21+
122
2012-10-06 Richard Murray <murray@altura.local>
223

324
* tests/discrete_test.py: added additional tests for dt = True cases

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
# The short X.Y version.
6161
version = '0.6'
6262
# The full version, including alpha/beta/rc tags.
63-
release = '0.6c'
63+
release = '0.6a'
6464

6565
# The language for content autogenerated by Sphinx. Refer to documentation
6666
# for a list of supported languages.

src/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@
5959
#! Should probably only import the exact functions we use...
6060
from bdalg import series, parallel, negate, feedback
6161
from delay import pade
62-
from dtime import timebase, isdtime, isctime
6362
from freqplot import bode_plot, nyquist_plot, gangof4_plot
6463
from freqplot import bode, nyquist, gangof4
65-
from lti import timebaseEqual
64+
from lti import timebase, timebaseEqual, isdtime, isctime
6665
from margins import stability_margins, phase_crossover_frequencies
6766
from mateqn import lyap, dlyap, care, dare
6867
from modelsimp import hsvd, modred, balred, era, markov

src/dtime.py

Lines changed: 0 additions & 105 deletions
This file was deleted.

src/lti.py

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,32 @@
66
Routines in this module:
77
88
Lti.__init__
9-
9+
isdtime()
10+
isctime()
11+
timebase()
12+
timebaseEqual()
1013
"""
1114

1215
class 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
5288
def 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

src/statesp.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,13 @@ def __init__(self, *args):
144144
matrices[i] = matrix(matrices[i])
145145
[A, B, C, D] = matrices
146146

147+
Lti.__init__(self, B.shape[1], C.shape[0], dt)
147148
self.A = A
148149
self.B = B
149150
self.C = C
150151
self.D = D
151-
self.dt = dt
152152

153153
self.states = A.shape[0]
154-
Lti.__init__(self, B.shape[1], C.shape[0])
155154

156155
# Check that the matrix sizes are consistent.
157156
if self.states != A.shape[1]:

0 commit comments

Comments
 (0)