State Machines
Counters remember a number; state machines remember a situation. An FSM is the standard way to express "what happens next depends on what has already happened" — protocol handling, controllers, sequencers are all FSMs at heart.
This one watches a serial bit stream and pulses detected whenever the
last four bits were 1011, with overlap (in 1011011 the pattern
occurs twice; the middle 1 does double duty). Each state encodes how
much of the pattern has been seen so far:
IDLE nothing useful yet
S1 seen 1
S10 seen 10
S101 seen 101 -- a 1 now completes the pattern
The interesting transitions are the failure ones: from S101 on a 1
we output detected but go to S1 (that 1 may start the next match),
not IDLE. Getting these right by hand is fiddly — which is exactly why
the structure is rigid boilerplate: one register process, one
combinational next-state case, defaults everywhere (the
FSM generator writes this skeleton for you, and
its DOT output draws the state diagram).
In the waveform the testbench feeds 1 0 1 1 0 1 1 1 0 1 1 — predict
where detected should pulse before you look (bits 4 and 7... check
yourself).
Experiment: change the pattern to 1101, or make the detector
non-overlapping and compare the pulse positions on the same input.