Modeling and Analyzing System Behavior: February 25, 2013
Modeling and Analyzing System Behavior: February 25, 2013
Modeling and Analyzing System Behavior: February 25, 2013
desiredDistance currentDistance
Demo: consider two possible wall nder behaviors.
Check Yourself
Which behavior is better? 1. 2. 3. 4. Behavior Behavior Both are Both are 1 2 good bad
Check Yourself
Which behavior is better? Behavior 1 seems unneccessarily sluggish. Behavior 2 overshoots. Performance metrics: How long does it take for the output signal to reach its nal value? Does the output signal overshoot? If so, how much?
State Machines
State machines are convenient abstractions for organizing computations that evolve with time.
input in
state sn
output on
On the nth step, the system gets input in generates output on and moves to a new state sn+1 Output and next state depend on input and current state
State Machines
Example: accumulator On each step, an input is added to the already accumulated inputs, and the result becomes the new output.
Accumulator
Assume state is initially zero.
s0 = 0
Accumulator
Assume state is initially zero.
input i0 = 1
s0 = 0 s1 = 1
output o0 = 1
Accumulator
Assume state is initially zero.
input
s1 = 1
output
Accumulator
Assume state is initially zero.
input i1 = 2
s1 = 1 s2 = 3
output o1 = 3
Accumulator
Assume state is initially zero.
input
s2 = 3
output
Accumulator
Assume state is initially zero.
input i2 = 3
s2 = 3 s3 = 6
output o2 = 6
Accumulator
Assume state is initially zero.
input
s3 = 6
output
Accumulator
Assume state is initially zero.
input i3 = 4
s3 = 6 s4 = 10
output o3 = 10
Accumulator
Assume state is initially zero.
input
s4 = 10
output
Accumulator
Assume state is initially zero.
input i4 = 5
s4 = 10 s5 = 15
output o4 = 15
SM Class
The generic methods of the SM class use startState to initialize the instance variable state. Then getNextValues is used to process inputs, so that step can update state.
class SM: startState= None def getStartState(self): return self.startState def start(self): self.state = self.getStartState() def step(self, inp): (s, o) = self.getNextValues(self.state, inp) self.state = s return o def transduce(self, inputs): self.start() return [self.step(inp) for inp in inputs]
Note that getNextValues should not change state. The state is managed by start and step.
Accumulator
class Accumulator(SM): startState = 0 def getNextValues(self, state, inp): return (state + inp, state + inp)
Check Yourself
5 (18, 18) (23, 23) 5 (21, 21) (21, 21) 15 (18, 18) (23, 23) 15 (21, 21) (21, 21)
none of the above
Check Yourself
5 (18, 18) (23, 23) 5 (21, 21) (21, 21) 15 (18, 18) (23, 23) 15 (21, 21) (21, 21)
none of the above
State Machines
The state machine representation for controlling processes is simple and concise separates system specication from looping structures over time is modular We will use this approach in controlling our robots and in simulating the resulting behavior.
signal in
system
signal out
Check Yourself
desiredDistance currentDistance
1. 2.
3.
4.
Check Yourself
2.
desiredDistance currentDistance
1. 2.
3.
4.
Performance Analysis
Quantify performance by characterizing input and output signals.
desiredDistance
n
wallFinder
system
currentDistance
n
signal in
system
signal out
Dierence Equations
We can represent the transformation from input to output signal by a dierence equation. Dierence equations are mathematically precise and compact. Example: y [n] = x[n] x[n 1] Let x[n] equal the unit sample signal [n], [ n] = 1, 0, if n = 0; otherwise. x[ n] = [ n]
n 1 0 1 2 3 4
Dierence Equations
Convenient for step-by-step analysis.
y [n] = x[n] x[n 1] y [1] = x[1] x[2] y [0] = x[0] x[1] y [1] = x[1] x[0] y [2] = x[2] x[1] y [3] = x[3] x[2] ... =00=0 =10=1 = 0 1 = 1 =00=0 =00=0
x[ n] = [ n]
y [ n]
n 1 0 1 2 3 4 1 0 1 2 3 4
Dierence Equations
Convenient for step-by-step analysis.
y [n] = x[n] x[n 1] y [1] = x[1] x[2] y [0] = x[0] x[1] y [1] = x[1] x[0] y [2] = x[2] x[1] y [3] = x[3] x[2] ... =00=0 =10=1 = 0 1 = 1 =00=0 =00=0
x[ n] = [ n]
y [ n]
n 1 0 1 2 3 4 1 0 1 2 3 4
Dierence Equations
Convenient for step-by-step analysis.
y [n] = x[n] x[n 1] y [1] = x[1] x[2] y [0] = x[0] x[1] y [1] = x[1] x[0] y [2] = x[2] x[1] y [3] = x[3] x[2] ... =00=0 =10=1 = 0 1 = 1 =00=0 =00=0
x[ n] = [ n]
y [ n]
n 1 0 1 2 3 4 1 0 1 2 3 4
Dierence Equations
Convenient for step-by-step analysis.
y [n] = x[n] x[n 1] y [1] = x[1] x[2] y [0] = x[0] x[1] y [1] = x[1] x[0] y [2] = x[2] x[1] y [3] = x[3] x[2] ... =00=0 =10=1 = 0 1 = 1 =00=0 =00=0
x[ n] = [ n]
y [ n]
n 1 0 1 2 3 4 1 0 1 2 3 4
Dierence Equations
Convenient for step-by-step analysis.
y [n] = x[n] x[n 1] y [1] = x[1] x[2] y [0] = x[0] x[1] y [1] = x[1] x[0] y [2] = x[2] x[1] y [3] = x[3] x[2] ... =00=0 =10=1 = 0 1 = 1 =00=0 =00=0
x[ n] = [ n]
y [ n]
n 1 0 1 2 3 4 1 0 1 2 3 4
Dierence Equations
Convenient for step-by-step analysis.
y [n] = x[n] x[n 1] y [1] = x[1] x[2] y [0] = x[0] x[1] y [1] = x[1] x[0] y [2] = x[2] x[1] y [3] = x[3] x[2] ... =00=0 =10=1 = 0 1 = 1 =00=0 =00=0
x[ n] = [ n]
y [ n]
n 1 0 1 2 3 4 1 0 1 2 3 4
Dierence Equations
Convenient for step-by-step analysis.
y [n] = x[n] x[n 1] y [1] = x[1] x[2] y [0] = x[0] x[1] y [1] = x[1] x[0] y [2] = x[2] x[1] y [3] = x[3] x[2] ... =00=0 =10=1 = 0 1 = 1 =00=0 =00=0
x[ n] = [ n]
y [ n]
n 1 0 1 2 3 4 1 0 1 2 3 4
Block Diagrams
Graphic representation of the dierence equation. Represent y [n] = x[n] x[n 1] with a block diagram:
x[ n ] 1
Delay
y [ n]
x[ n] = [ n]
y [ n]
n 1 0 1 2 3 4 1 0 1 2 3 4
Step-By-Step Solutions
Block diagrams are also useful for step-by-step analysis. Represent y [n] = x[n] x[n 1] with a block diagram: start at rest
x[ n ] 1
Delay
+ 0
y [ n]
x[ n] = [ n]
y [ n]
n 1 0 1 2 3 4 1 0 1 2 3 4
Step-By-Step Solutions
Block diagrams are also useful for step-by-step analysis. Represent y [n] = x[n] x[n 1] with a block diagram: start at rest
1 1 1
Delay
+ 0
x[ n] = [ n]
y [ n]
n 1 0 1 2 3 4 1 0 1 2 3 4
Step-By-Step Solutions
Block diagrams are also useful for step-by-step analysis. Represent y [n] = x[n] x[n 1] with a block diagram: start at rest
10 1 1
Delay
+ 0 1
x[ n] = [ n]
y [ n]
n 1 0 1 2 3 4 1 0 1 2 3 4
Step-By-Step Solutions
Block diagrams are also useful for step-by-step analysis. Represent y [n] = x[n] x[n 1] with a block diagram: start at rest
10 1 0
Delay
1 0 1
x[ n] = [ n]
y [ n]
n 1 0 1 2 3 4 1 0 1 2 3 4
Step-By-Step Solutions
Block diagrams are also useful for step-by-step analysis. Represent y [n] = x[n] x[n 1] with a block diagram: start at rest
0 1 0
Delay
+ 1
x[ n] = [ n]
y [ n]
n 1 0 1 2 3 4 1 0 1 2 3 4
Step-By-Step Solutions
Block diagrams are also useful for step-by-step analysis. Represent y [n] = x[n] x[n 1] with a block diagram: start at rest
0 1 0
Delay
1 1 0
x[ n] = [ n]
y [ n]
n 1 0 1 2 3 4 1 0 1 2 3 4
Step-By-Step Solutions
Block diagrams are also useful for step-by-step analysis. Represent y [n] = x[n] x[n 1] with a block diagram: start at rest
0 1 0
Delay
0 1 0
x[ n] = [ n]
y [ n]
n 1 0 1 2 3 4 1 0 1 2 3 4
Step-By-Step Solutions
Block diagrams are also useful for step-by-step analysis. Represent y [n] = x[n] x[n 1] with a block diagram: start at rest
0 1 0
Delay
+ 0
x[ n] = [ n]
y [ n]
n 1 0 1 2 3 4 1 0 1 2 3 4
Step-By-Step Solutions
Block diagrams are also useful for step-by-step analysis. Represent y [n] = x[n] x[n 1] with a block diagram: start at rest
0 1 0
Delay
+ 0
x[ n] = [ n]
y [ n]
n 1 0 1 2 3 4 1 0 1 2 3 4
Step-By-Step Solutions
Block diagrams are also useful for step-by-step analysis. Represent y [n] = x[n] x[n 1] with a block diagram: start at rest
0 1 0
Delay
+ 0
x[ n] = [ n]
y [ n]
n 1 0 1 2 3 4 1 0 1 2 3 4
+ 1
Delay
y [ n]
Same input-output behavior, dierent strengths/weaknesses: dierence equations are mathematically compact block diagrams illustrate signal ow paths
X 1
Delay
Nodes represent whole signals (e.g., X and Y ). The boxes operate on those signals: Delay = shift whole signal to right 1 time step Add = sum two signals 1: multiply by 1
Operator Notation
Symbols can now compactly represent diagrams. Let R represent the right-shift operator: Y = R{X } RX where X represents the whole input signal (x[n] for all n) and Y represents the whole output signal (y [n] for all n)
Operator Notation
Systems are concisely represented with operators. Dierence machine:
X 1
Delay
1. y [n] = x[n] for all n 2. y [n + 1] = x[n] for all n 3. y [n] = x[n + 1] for all n 4. y [n 1] = x[n] for all n 5. none of the above
2.
1. y [n] = x[n] for all n 2. y [n + 1] = x[n] for all n 3. y [n] = x[n + 1] for all n 4. y [n 1] = x[n] for all n 5. none of the above
X 1
Delay
Y1
+ 1
Delay
Y2
Operator Algebra
Operator expressions expand and reduce like polynomials.
X 1
Delay
Y1
+ 1
Delay
Y2
Using dierence equations: y2 [n] = y1 [n] y1 [n 1] = (x[n] x[n 1]) (x[n 1] x[n 2]) = x[n] 2x[n 1] + x[n 2] Using operator notation: Y2 = (1 R) Y1 = (1 R)(1 R) X = (1 R)2 X = (1 2R + R2 ) X
Operator Approach
Applies your existing expertise with polynomials to understand block diagrams, and thereby understand systems.
Operator Algebra
Operator notation facilitates seeing relations among systems. Equivalent block diagrams (assuming both initially at rest):
X 1
Delay
Y1
+ 1
Delay
Y2
X
Delay
+ 2
Delay
Operator Algebra
Operator notation prescribes operations on signals, not samples: e.g., start with X , subtract 2 times a right-shifted version of X , and add a double-right-shifted version of X !
X:
n 1 0 1 2 3 4 5 6
2RX :
n 1 0 1 2 3 4 5 6
+ R2 X :
n 1 0 1 2 3 4 5 6
y = X 2 RX + R2 X :
n 1 0 1 2 3 4 5 6
Operator Algebra
Expressions involving R obey many familiar laws of algebra, e.g., commutativity. R(1 R) X = (1 R)RX This is easily proved by the denition of R, and it implies that cascaded systems commute (assuming initial rest)
X 1
is equivalent to Delay
Delay
Delay
+ 1
Delay
Operator Algebra
Multiplication distributes over addition. Equivalent systems
X 1
Delay
Delay
X 1
Operator Algebra
The associative property similarly holds for operator expressions. Equivalent systems
X 1
+ 1
2
Delay
X 1
Delay
+ 1
2
Delay
Delay Delay
Check Yourself
Delay
Delay
Delay
Delay
Delay
Delay
Check Yourself
Delay
Delay
Delay
Delay
Delay
Delay
Feedback
Feedback complicates relation between input and output signals.
X 1
Delay
Y
Y = (1 R) X
Without feedback, output signal is linear combination of shifted versions of input signal.
+
Delay
Y
Y = RY + X (1 R) Y = X
Feedback introduces a similar constraint, but now the input signal is a linear combination of shifted versions of the output signal. But how do we nd Y ?
Example: Accumulator
Try step-by-step analysis: it always works. Start at rest.
x[ n]
+
Delay
y [ n]
y [n] = x[n] + y [n 1] y [0] = x[0] + y [1] = 1 + 0 = 1 y [1] = x[1] + y [0] y [2] = x[2] + y [1] ... y [ n] =0+1=1 =0+1=1
x[ n] = [ n]
n 1 0 1 2 3 4
Persistent response to a transient input!
n 1 0 1 2 3 4
Example: Accumulator
Try step-by-step analysis: it always works. Start at rest.
x[ n]
+
Delay
y [ n]
y [n] = x[n] + y [n 1] y [0] = x[0] + y [1] = 1 + 0 = 1 y [1] = x[1] + y [0] y [2] = x[2] + y [1] ... y [ n] =0+1=1 =0+1=1
x[ n] = [ n]
n 1 0 1 2 3 4
Persistent response to a transient input!
n 1 0 1 2 3 4
Example: Accumulator
Try step-by-step analysis: it always works. Start at rest.
x[ n]
+
Delay
y [ n]
y [n] = x[n] + y [n 1] y [0] = x[0] + y [1] = 1 + 0 = 1 y [1] = x[1] + y [0] y [2] = x[2] + y [1] ... y [ n] =0+1=1 =0+1=1
x[ n] = [ n]
n 1 0 1 2 3 4
Persistent response to a transient input!
n 1 0 1 2 3 4
Example: Accumulator
Try step-by-step analysis: it always works. Start at rest.
x[ n]
+
Delay
y [ n]
y [n] = x[n] + y [n 1] y [0] = x[0] + y [1] = 1 + 0 = 1 y [1] = x[1] + y [0] y [2] = x[2] + y [1] ... y [ n] =0+1=1 =0+1=1
x[ n] = [ n]
n 1 0 1 2 3 4
Persistent response to a transient input!
n 1 0 1 2 3 4
Example: Accumulator
Try step-by-step analysis: it always works. Start at rest.
x[ n]
+
Delay
y [ n]
y [n] = x[n] + y [n 1] y [0] = x[0] + y [1] = 1 + 0 = 1 y [1] = x[1] + y [0] y [2] = x[2] + y [1] ... y [ n] =0+1=1 =0+1=1
x[ n] = [ n]
n 1 0 1 2 3 4
Persistent response to a transient input!
n 1 0 1 2 3 4
Example: Accumulator
Try step-by-step analysis: it always works. Start at rest.
x[ n]
+
Delay
y [ n]
y [n] = x[n] + y [n 1] y [0] = x[0] + y [1] = 1 + 0 = 1 y [1] = x[1] + y [0] y [2] = x[2] + y [1] ... y [ n] =0+1=1 =0+1=1
x[ n] = [ n]
n 1 0 1 2 3 4
Persistent response to a transient input!
n 1 0 1 2 3 4
Example: Accumulator
The response of the accumulator system could also be generated by a system with innitely many paths from input to output, each with one unit of delay more than the previous.
X
Delay Delay Delay Delay Delay Delay
...
Y = (1 + R + R2 + R3 + ) X
...
Example: Accumulator
These systems are equivalent in the sense that if each is initially at rest, they will produce identical outputs from the same input. Y2 = (1 + R + R2 + R3 + ) X2
(1 R) Y1 = X1
Example: Accumulator
The system functional for the accumulator is the reciprocal of a polynomial in R. + X Y Delay (1 R) Y = X
The product (1 R) (1 + R + R2 + R3 + ) equals 1. Therefore the terms (1 R) and (1 + R + R2 + R3 + ) are reciprocals. Thus we can write Y 1 = = 1 + R + R2 + R3 + R4 + X 1R
Example: Accumulator
The reciprocal of 1 R can also be evaluated using synthetic division.
1 +R +R2 +R3 + 1R 1 1 R R 2 R2 R2 3 R3 R3 4
Therefore 1 = 1 + R + R2 + R3 + R4 + 1R
Check Yourself
A system is described by the following operator expression: Y 1 = . X 1 + 2R Determine the output of the system when the input is a unit sample.
Check Yourself
Evaluate the system function using synthetic division.
1 2R +4R2 8R3 + 1 + 2R 1 1 +2R 2R 2R 4R2 4R2 4R2 +8R3 8R3 8R3 16R4
Therefore the system function can be written as Y 1 = = 1 2R + 4R2 8R3 + 16R4 + X 1 + 2R
Check Yourself
Now nd Y given that X is a delta function. x[ n] = [ n] Think about the sample representation of the system function: Y = 1 2R + 4R2 8R3 + 16R4 + X y [n] = 1 2R + 4R2 8R3 + 16R4 + [n] y [n] = [n] 2 [n 1] + 4 [n 2] 8 [n 3] + 16 [n 4] +
Check Yourself
A system is described by the following operator expression: 1 Y = . X 1 + 2R Determine the output of the system when the input is a unit sample.
y [n] = [n] 2 [n 1] + 4 [n 2] 8 [n 3] + 16 [n 4] +
y [ n]
Check Yourself
x[ n]
Delay Delay
y [ n]
1. 2. 3. 4. 5.
y [n] = x[n 1] + y [n 1] y [n] = x[n 1] + y [n 2] y [n] = x[n 1] + y [n 1] + y [n 2] y [n] = x[n 1] + y [n 1] y [n 2] none of the above
Check Yourself
Determine a dierence equation that relates x[] and y [] below.
x[ n]
Delay Delay
y [ n]
E W
R R
Y = RE = R(X + W ) = R(X + RY )
y [n] = x[n 1] + y [n 2]
Check Yourself
x[ n]
Delay Delay
y [ n]
1. 2. 3. 4. 5.
y [n] = x[n 1] + y [n 1] y [n] = x[n 1] + y [n 2] y [n] = x[n 1] + y [n 1] + y [n 2] y [n] = x[n 1] + y [n 1] y [n 2] none of the above
Dierence equations: mathematically compact. y [n] = x[n] x[n 1] Block diagrams: illustrate signal ow paths.
x[ n] 1
Delay
y [ n]
output
This Week
Software lab: Representing systems with state machines. Design lab: Modeling the wall nder behavior.