Worked Example: A Serial Pattern Detector
Serial pattern detection is a fundamental operation in digital communications. Communication protocols such as UART, USB, Ethernet, and HDLC identify frame boundaries and synchronization words using serial sequence detectors.
This article designs a sequence detector for the binary pattern 1011 with support for overlapping matches.
Functional Specification
- Input ($x$): Serial binary stream, sampled once per clock cycle.
- Output ($z$): Asserted high for one clock cycle when the four most recent input bits equal
1011. - Overlapping Matching: The system allows pattern overlap. For example, the input stream
...1011011...contains two valid patterns because the final bit of the first pattern serves as the prefix for the second.
Moore State Architecture
Define five states representing matched prefixes:
| State Identifier | Matched Bit Sequence | Output ($z$) |
|---|---|---|
| S0 | No prefix matched | 0 |
| S1 | Sequence 1 matched |
0 |
| S2 | Sequence 10 matched |
0 |
| S3 | Sequence 101 matched |
0 |
| S4 | Sequence 1011 matched |
1 |
To calculate next-state transitions, determine the longest matching prefix remaining after appending the incoming bit:
- From S0: Transition to
S1on input 1; remain inS0on input 0. - From S1 (prefix
1): Transition toS2on input 0; remain inS1on input 1. - From S2 (prefix
10): Transition toS3on input 1; return toS0on input 0. - From S3 (prefix
101): Transition toS4on input 1. On input 0, the sequence becomes1010. The suffix10matches the two-bit prefix. Transition toS2. - From S4 (sequence
1011, $z = 1$): On input 0, the suffix10matches the two-bit prefix. Transition toS2. On input 1, the suffix1matches the single-bit prefix. Transition toS1.
The transitions from S3 to S2, and from S4 to S2 and S1, preserve overlapping prefixes (Figure 1).
Mealy State Architecture
A Mealy machine eliminates state S4. The transition from S3 on input 1 asserts output $z = 1$ directly and routes back to S1 (Figure 2).
| Metric | Moore Implementation | Mealy Implementation |
|---|---|---|
| Total States | 5 states | 4 states |
| Flip-Flop Count (Binary) | 3 flip-flops | 2 flip-flops |
| Output Latency | Asserted in state S4 (one cycle after final bit) | Asserted during the cycle the final bit arrives |
| Output Stability | Clock-aligned, glitch-free | Combinational (sensitive to glitches on $x$) |
State Table and Binary Encoding
Assign binary codes to the Moore states:
S0 = 000, S1 = 001, S2 = 010, S3 = 011, and S4 = 100. Codes 101, 110, and 111 are unused don’t-care states.
| Present State ($Q_2 Q_1 Q_0$) | Input ($x$) | Next State ($D_2 D_1 D_0$) | Output ($z$) |
|---|---|---|---|
| 000 | 0 | 000 | 0 |
| 000 | 1 | 001 | 0 |
| 001 | 0 | 010 | 0 |
| 001 | 1 | 001 | 0 |
| 010 | 0 | 000 | 0 |
| 010 | 1 | 011 | 0 |
| 011 | 0 | 010 | 0 |
| 011 | 1 | 100 | 0 |
| 100 | 0 | 010 | 1 |
| 100 | 1 | 001 | 1 |
Minimized Logic Equations
Derive minimal sum-of-products equations using Karnaugh maps:
Next-State Bit $D_2$
$D_2$ asserts only when transitioning into S4 from S3 on $x = 1$. Using don’t-care state 111:
$$D_2 = Q_1 \cdot Q_0 \cdot x$$
Next-State Bit $D_1$
$D_1$ asserts when transitioning into S2 or S3:
$$D_1 = \overline{x},(Q_2 + Q_0) + x, Q_1, \overline{Q_0}$$
Next-State Bit $D_0$
$D_0$ asserts when transitioning into S1 or S3:
$$D_0 = x,(\overline{Q_1} + \overline{Q_0})$$
Output Bit $z$
Output $z$ asserts only in state S4 (100). Using don’t-cares 101, 110, and 111:
$$z = Q_2$$
To ensure safe operation without relying on unused don’t-care assumptions:
$$z = Q_2 \cdot \overline{Q_1} \cdot \overline{Q_0}$$
Timing Simulation
Trace the detector using input bit stream 1 0 1 1 0 1 0 1 1 (Figure 3):
| Clock Cycle | Input ($x$) | State | Output ($z$) | Detection Event |
|---|---|---|---|---|
| Reset | — | S0 | 0 | Initial state |
| 1 | 1 | S1 | 0 | Prefix 1 |
| 2 | 0 | S2 | 0 | Prefix 10 |
| 3 | 1 | S3 | 0 | Prefix 101 |
| 4 | 1 | S4 | 1 | First sequence 1011 detected |
| 5 | 0 | S2 | 0 | Suffix 10 preserved |
| 6 | 1 | S3 | 0 | Prefix 101 |
| 7 | 0 | S2 | 0 | Incomplete sequence |
| 8 | 1 | S3 | 0 | Prefix 101 |
| 9 | 1 | S4 | 1 | Second sequence 1011 detected |
Because cycle 5 transitions to state S2 instead of S0, the circuit maintains the valid prefix and detects the subsequent pattern correctly.
Practice Exercises
Problem 1
Design an overlapping Moore sequence detector for target pattern 1001. Determine next-state transitions for state S4 (pattern matched).
Solution
Define states:
S0: No prefixS1: Prefix1S2: Prefix10S3: Prefix100S4: Target1001detected ($z = 1$)
Transitions from S4:
- On input 0: Sequence ends in
...10010. The suffix10matches prefixS2. Transition toS2. - On input 1: Sequence ends in
...10011. The suffix1matches prefixS1. Transition toS1.
Problem 2
Construct the state transition table for the four-state Mealy implementation of the 1011 detector.
Solution
| Present State | Input ($x$) | Next State | Output ($z$) |
|---|---|---|---|
| M0 | 0 | M0 | 0 |
| M0 | 1 | M1 | 0 |
| M1 | 0 | M2 | 0 |
| M1 | 1 | M1 | 0 |
| M2 | 0 | M0 | 0 |
| M2 | 1 | M3 | 0 |
| M3 | 0 | M2 | 0 |
| M3 | 1 | M1 | 1 |
The target output asserts on the transition from M3 to M1 when input $x = 1$.
Problem 3
Apply input bit stream 1 1 0 1 1 to the Moore detector. Trace each state transition.
Solution
- Start in state
S0. - Input 1: Transition to
S1. - Input 1: Remain in
S1(trailing bit is 1). - Input 0: Transition to
S2(sequence10). - Input 1: Transition to
S3(sequence101). - Input 1: Transition to
S4(sequence1011detected, $z = 1$).
The machine detects one match spanning cycles 2 through 6.
The next article examines a vending machine controller and demonstrates why complex sequential systems use hybrid FSM-plus-datapath architectures.