Real-Time Workshop User's Guide | ![]() ![]() |
Creating an S-Function Block from a Subsystem
This section demonstrates how to extract a subsystem from a model and generate a reusable S-function component from it.
Figure 10-1 illustrates SourceModel
, a simple model that inputs signals to a subsystem. Figure 10-2 illustrates the subsystem, SourceSubsys
. The signals, which have different widths and sample times, are:
Our objective is to extract SourceSubsys
from the model and build an S-Function block from it, using the S-function target. We want the S-Function block to perform identically to the subsystem from which it was generated.
Note that in this model, SourceSubsys
inherits sample times and signal widths from its input signals. If an S-Function block is built from SourceSubsys
, without explicitly setting input widths and sample times, the new block will inherit its sample times and signal widths from the model in which it is placed.
In this example, however, we want the S-Function block to retain the properties of SourceSubsys
as it exists in SourceModel
. Before building the subsystem as a separate S-function component, the inport sample times and widths must be set explicitly. In addition, the solver parameters of the S-function component must be the same as those of the original model. This ensures that the generated S-function component will operate identically to the original subsystem.
To build SourceSubsys
as an S-function component:
SourceSubsys
into the empty window.
SourceSubsys
such that they match those of the signals in the original model. Inport 1, Filter
, has a width of 1 and a a sample time of 1. Inport 2, Xferfcn
, has a width of 1 and a sample time of 0.5. Inport 3, offsets
, has a width of 2 and an inherited sample time of 1.
SourceSubsys
, as shown below.
Note that the correct signal widths and sample times propagate to these ports.
When this option is selected, the build process creates a new model after it builds the S-function component. The new model contains an S-Function block, linked to the S-function component.
Figure 10-3: Generated S-Function Plugged into SourceModel
Note that the speed at which the S-Function block executes is typically faster than the original model. This difference in speed is more pronounced for larger and more complicated models. By using generated S-functions, you can increase the efficiency of your modeling process.
![]() | Intellectual Property Protection | Tunable Parameters in Generated S-Functions | ![]() |