You are on page 1of 33

Week 2/3

1. System interconnections (block diagrams)


2. Finite State Machines (Chapter 3)

Recall

A system S is a function : InputSignals OutputSignals


with
InputSignals = [D R],
OutputSignals = [D R]

x InputSignals

y = S(x) OutputSignals

10Evans: [Ints+ {enter, leave}] [Ints+ Integers+ ]


OutputSignals

InputSignals

u = (e,l,l,e,e, )

10Evans
5

y = (6,5,4,5,6, )

initial number in room

The system 10Evans can be specified as follows:


y = 10Evans (u), and for all n Ints+ , y(n) is given by

where

u Speeds

y=S(u) Positions
y(0)

initial position
Speeds = [[0,5] Reals], Positions = [[0,5] Reals]
How do you give S?

Other examples: TopicNotes/Systems/DTMF

Sounds
KeypadSequences

DTMF
DTMF: [Nats KeypadSymbols] [Time Pressure]

Interconnecting Systems:
Block Diagrams

v1

Voice

Microphone

MicOutput
Volume

AGC

AGCSound Volume
Sensor

v2

Voice [Time Pressure]; MicOutput [Time Volts]


Microphone: [Time Pressure] [Time Volts];
AGCSound [Time Pressure]; Volume [Time Volts]
VolumeSensor: [Time Pressure] [Time Volts];
Output [Time Volts]
AGC: [Time Volts] x [Time Volts] [Time Pressure]

v1 = Microphone (u)
s = AGC (v1, v2)
v2 = VolumeSensor(s)
y = v2

4 equations
4 unknowns

Output

Finite State Machines

x = (x(0), x(1), x(2), )

x InputSignals

Recognizer

y = (y(0), y(1), y(2), )


y OutputSignals

x InputSignals = [Nats0 {0,1}]

y OutputSignals = [Nats0 {t,f}]

Recognizer(x)(n) = t, if (x(n-2),x(n-1),x(n)) = (0,0,0)


= f, else
Recognizer((0,1,0,0,0,0,1,1, )) =
(f,f,f,f,t,t,f,f, )

0/f

x InputSignals

init

1/f

x = (0,
1, 0,
s = (init, a, init,
y = (f,
f,
f,

0/f

1/f

1/f

0,
a,
f,

yOutputSignals

0/t

0,
b,
t,

0,
b,
t,

1, 1, )
b, init, )
f, f, )

s(0) = init
(s(n+1), y(n)) = update (s(n), x(n)), n = 0,1,

{0}/f

x[Nats0 {0,1,2}]

guard

init

{1,2}/f

x = (0,
2, 0,
s = (init, a, init,
y = (f,
f,
f,

a
{1,2}/f

{1,2}/f

{0}/f
y[Nats0 {t,f}]

{0}/t

0, 0, 0, 1, 2, )
a, b, b, b, init, )
f, f, t, t, f, )

s(0) = init
(s(n+1), y(n)) = update (s(n), x(n)), n = 0,1,

What does this machine with 4 states do?


{0}/f

init
{1,2}/f

x[Nats0 {0,1,2}]

{0}/f

1,2

{1,2}/f

0
{1,2}/f

{1,2}/f

{0}/f

00

y[Nats0 {t,f}]

{0}/t

It also implements Recognizer


Can a machine with 2 states implement Recognizer?

Formal definition of state machine


1. Sets and functions
2. Bubble and arcs
3. Tabular

Sets and function


A state machine is a 5-tuple

StateMachine = (States, Inputs, Outputs, update, initialState)


States is the state space
Inputs is the input alphabet
Outputs is the output alphabet
initialState States is the initial state
update: States x Inputs States x Outputs is the
update function

For Recognizer
States = {init, a, b}
Inputs = {0,1}
Outputs = {t, f}
initialState = init
update: States x Inputs States x Outputs
is given by:
update(init, 0) = (0, f)
update(init, 1) = (init, f)

current current
state
input

next
state

(s(n+1), y(n)) =
update(s(n), x(n))
current
output

It is useful sometimes to express the update function as


two functions:
update = (nextState, output),
nextState: States x Inputs States
output: States x Inputs Outputs
so that
update(s(n), x(n)) = (s(n+1), y(n))
nextState(s(n), x(n)) = s(n+1)
output(s(n), x(n)) = y(n)

Operation of state machine


Given S = (States, Inputs, Outputs, update, initialState)
InputSignals = [Nats0 Inputs]
OutputSignals = [Nats0 Outputs]
An input signal x = (x(0), x(1), , x(n), ) determines the
state response s: Nats0 States and the
output signal y: Nats0 Outputs
by the recursion, s(0) = initState, and n 0,
(s(n+1), y(n)) = update (s(n), x(n))
Thus S determines an input-output function (system)
F: InputSignals OutputSignals

For Recognizer
InputSignals = [Nats0 {0,1}]
OutputSignals = [Nats0 {t,f}]
The input-output function (system) is F:

x InputSignals, n Nats0
y(n) = F(x)(n) = t, if (x(n-2), x(n-1)), x(0)) = (0,0,0)
= f, else

Stuttering

It is useful to introduce a stuttering symbol


absent
We insist that
absent Inputs and absent Outputs
We require that for all states s States
update(s, absent) = (s, absent)

A modified Recognizer

0/abs

x InputSignals

init

1/abs

a
1/abs

1/abs

0/abs
yOutputSignals

0/t

x = (0,
1, 0, 0, 0, 0, 1, 1, )
s = (init, a, init, a, b, b, b, init, )
y = (abs, abs, abs, abs, t, t, abs, abs, )

Bubbles and arcs

Shorthand: the else loop

{0}/abs

x[Nats0
{0,1,2, absent}]

init
else

a
else
else

{0}/abs
y[Nats0

{t,absent}]
0/t

Shorthand: the implicit else self loop

{0}/abs

x[Nats0
{0,1,2, absent}]

init
else

a
else
else

{0}/abs
y[Nats0

{t,absent}]
0/t

Shorthand: the implicit absent

{0}/abs

x[Nats0
{0,1,2, absent}]

init
else

a
else
else

{0}/abs
y[Nats0

{t,absent}]
0/t

The guards are subsets of Inputs

guards on different arcs from same state are


disjoint (determinism)
union of all guards (from same state) = Inputs;
(reactive system)
guard on else is complement of remaining guards
guards may be defined using convenient notation,
eg. if Inputs = {a, b, c}, a = {b,c}

Tabular Representation

All information about a state machine is given its


update function. If States and Inputs are finite,
update can be given as a table
current
state

(next state, output) if input is


0
1
absent

init

(a, f)

(init, f)

(init, abs)

(b, f)

(init, f)

(a, abs)

(b, t)

(init, f)

(b, abs)

State machine design process

System requirements in English


System specification as
F: InputSignals OutputSignals
System implementation as state machine
Described by set-and-functions 5-tuple,
transition diagram, or table

Parking meter
{tick, coin5,
coin25, absent}

60-min
Parking meter
{coin25}/safe

{tick}/
expired

{coin5}/safe

{tick}/expired

{safe, expired,
absent}

{coin25}/safe

{coin5}/safe

...

{tick}/safe

{coin5} {coin25}/
/safe
safe

{coin5}/
safe

...

25

...

{tick}/safe

topics/state/parking meter

60

{tick}/safe

{coin5,
coin25}/
safe

Answering machine

topics/state/answering machine
table

You might also like