A Sequence Detector
A Sequence Detector
A state machine is required which outputs a logic 1 whenever the input sequence 0101
is detected, and which outputs a otherwise. The input is supplied serially, one bit at a
time. The following is an example input sequence and output sequence:
input 0 0 1 0 1 0 1 1 0 0 0 1 0 1 0 0
output 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0
This state machine can be designed in a straightforward way. Assume that the
machine is initially in some state, say, state A. If a 0 is input, then this is may be the
start of the required sequence, so the machine should output a 0 and go to the next
state, state B. If a 1 is input, then this is certainly not the start of the required
sequence, so the machine should output a 0 and stay in state A. When the machine is
in state A, therefore, it has detected no digits of the required input sequence. When the
machine is in state B, it has detected exactly one digit (the first 0) of the required input
sequence.
If the machine is in state B and a 0 is input, then two consecutive 0's must have been
input; this input is clearly not the second digit of the required sequence, but it may be
the first digit of the sequence. Therefore, the machine should stay in state B and
output a 0. If a 1 is input while the machine is in state B, then the first two digits of
the required sequence have been detected, and the machine should go to the next state,
state C, and output a 0. When the machine is in state C, it has detected exactly two
digits (0 1) from the required sequence.
If the machine is in state C and a 0 is input, then three digits of the required sequence
have been input, so the machine should go to its next state, state D, and output a 0. If a
1 is input when the machine is in state C, then this input is clearly no part of the
required sequence, so the machine should start over in state A and output a 0.
If the machine is in state D and a 0 is input, then this is not the required input (the
input has been 0 1 0 0), but this may be the first digit of another sequence, so the
machine should go to state B and output a 0. If a 1 is input while the machine is in
state D, then the required sequence (0 1 0 1) has been detected, so a 1 should be
output. Moreover, the last two digits input may be the first two digits of another
sequence, so the machine should go to state C. This completes the state diagram, as
shown in the following figure:
The student should note that the decision on overlap does not affect designs for handling partial
results – only what to do when the final 1 in the sequence 1011 is detected.