Main Content

Sequence Recognition by Using Mealy and Moore Charts

This example shows how to use Mealy and Moore machines for a sequence recognition application in signal processing. For more information, see Overview of Mealy and Moore Machines.

In this model, two Stateflow® charts use a different set of semantics to find the sequence 1, 2, 1, 3 in the input signal from a Signal Editor (Simulink) block.

Each chart contains an input data u and two output data:

  • seqFound indicates when the chart finds the sequence. A value of false means that the chart is still searching for the sequence. A value of true means that the chart has found the sequence.

  • status records the status of the sequence recognition. This value ranges from 0 to 4 and indicates the number of symbols detected by the chart.

The Moore chart outputs seqFound and status based on the current state of the chart. At each time step, the chart executes the actions for the current state, evaluates the input u, and transitions to a new state. For example, when the chart receives the sequence of input values 1, 2, 1, 3 from the Signal Editor block, it transitions from state s0 to state s1 to state s12 to state s121 to state s1213 in four time steps. The chart sets the value of seqFound to true in a state action after state s1213 becomes active.

The Mealy chart outputs seqFound and status based on the current state of the chart and the value of the input. At each time step, the chart evaluates the input u, makes the transition to a new state, and executes the corresponding condition actions. Because this chart computes its output values in the condition actions of its transitions, these actions are taken before the state becomes active. For example, when the chart receives the sequence of input values 1, 2, 1, 3 from the Signal Editor block, it transitions from state s0 to state s1 to state s12 to state s121 to state s1213 in four time steps. The chart sets the value of seqFound to true in a condition action in the same time step that state s1213 becomes active.

When you simulate the model, the seqFound scope shows that the output of the Moore chart lags one time step behind the output of the Mealy chart. The delay is a result of the Moore semantics, in which the output is based on the state of the chart at the start of each time step and not on the current input.

Reference

Katz, Bruce F. Digital Design: From Gates to Intelligent Machines, 2006.

See Also

(Simulink)

Related Topics