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 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.
In the Moore chart, the outputs depend only on the current state of the chart. This chart computes its output values in the state actions. At each time step, the chart executes the actions for the current state, evaluates the input u
, and makes the transition to a new state.
In the Mealy chart, the outputs depend on the current state of the chart and the input. This chart computes its output values in the condition actions of its transitions. At each time step, the chart evaluates the input u
, makes the transition to a new state, and executes the corresponding condition actions.
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.
Katz, Bruce F. Digital Design: From Gates to Intelligent Machines, 2006.