%% Karplus-Strong Algorithm by Using Moore Charts
%
% This example shows a simple implementation of the Karplus-Strong
% algorithm for string synthesis by using Stateflow(R) charts with Moore
% semantics. For more information, see <docid:stateflow_ug#bqtohav>.

% Copyright 2015-2018 The MathWorks, Inc.

%% Principle
% The initial burst of white noise is produced by a Uniform Random Number
% block. It is fed back into a delay line of the same length. The moving
% average smooth the signal at each cycle, while the gain less than 1
% maintains the stability of the feedback loop. They both model the string
% losses over each cycle.

%% Nondirect Feedthrough
% This example illustrates the benefits of Moore Charts in loops. Moore
% semantics guarantees that outputs only depend on the current state, but
% neither on inputs nor the next state. Hence a Moore Chart has nondirect
% feedthrough and can safely be used in feedback loops. For more
% information, see <docid:simulink_ug#f7-19688>.
%
% On the contrary, Classic or Mealy Charts provide direct feedthrough.
% These charts do not prevent algebraic loops, unless an external Delay
% block breaks cyclic dependencies. Simulation would issue an error if both
% charts were Classic or Mealy charts.

mdl = 'sf_karplus_strong';
open_system(mdl);
evalc('sim(mdl)');
