MATLAB Examples

Karplus-Strong Algorithm Using Stateflow®

This example shows a simple implementation of the Karplus-Strong algorithm for string synthesis, using Stateflow®. The Stateflow® charts use Moore semantics.

Contents

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.

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.