User`s guide

Introduction
1-9
S-Function Concepts
Understanding these key concepts should enable you to build S-functions
correctly:
Direct feedthrough
Dynamica lly sized inputs
Setting sample ti m es and offset s
Direct Feedthrough
Direct f eedthrough means that the output o r the variable sample time is
controlled dir ect ly by the value of an input port. A good rule of thumb is that
an S-function input port has direct f eedthr ough if:
The output function (
mdlOutputs or flag==3) is a function of the input u.
That is, there is direct feedthroughif the input
u isused inequationsdefined
in
mdlOutputs. Out puts ma y a lso include graphical outputs, as in the case of
an XY Graph scope.
It is a variable sample time S-function (calls
mdlGetTimeOfNextVarHit or
flag==4
) and the computation of the next sample hit requires the input u.
An example o f a s ystem that requires its inputs ( i.e ., has direct fe edthrough) is
the operati on , w h ere u is the input, k is the gain, and y is the out p u t.
An example of a system that does not require its inputs (i.e., does not have
direct feedthro ugh) i s t his simple integrat io n algorithm
Outputs:
Derivative:
wherex isthe state, is the state der iv ativ e withrespect to t ime,u istheinput
and y is the output. No te that is the variable that Simulink integrates. It is
veryimportant to setthe direct feedthroughflag correctlyb ecause itaffects the
executionorderof theblocksin yourmodelandis usedtodetect algebraicloops.
Dynamically Sized Inputs
S-functions can be written to support arbitrary input widths. In this case, the
actual input width is determined dynamically when a simulation is started by
evaluating the width of the input vector driving the S-function. The input
yku
×=
yx
=
x
·
u=
x
·
x
·