Main Content

Blocks for Which Sample Time Is Not Recommended

Some blocks do not enable you to set the Sample time parameter by default. However, you can see and set the Sample time parameter for these blocks in an existing model if the sample time is set to a value other than the default of -1 (inherited sample time). The Sample time parameter is not available on certain blocks because specifying a sample time that is not -1 on blocks such as the Gain, Sum, n-D Lookup Table, Discrete Filter, Discrete FIR Filter, and Discrete Transfer Fcn causes sample rate transition to be implicitly mixed with block algorithms. This mixing can often lead to ambiguity and confusion in Simulink® models.

In most modeling applications, you specify rates for a model on the boundary of your system instead of on a block within the subsystem. You specify the system rate from incoming signals or the rate of sampling the output. You can also decide rates for events you are modeling that enter the subsystem as trigger, function-call, or enable/disable signals. Some global variables (such as Data Store Memory blocks) might need additional sample time specification. If you want to change rate within a system, use a Rate Transition block, which is designed specifically to model rate transitions.

In a future release, you might not be able see or set this parameter on blocks where it is not appropriate.

Best Practice to Model Sample Times

Use these approaches instead of setting the Sample time parameter in the blocks where it is not appropriate:

  • Adjust your model by specifying Sample time only in the blocks listed in Appropriate Blocks for the Sample Time Parameter, and set Sample time to -1 for all other blocks. To change the sample time for multiple blocks simultaneously, use Model Explorer. For more information, see Model Explorer.

  • Use the Rate Transition block to model rate transitions in your model.

  • Use the Signal Specification block to specify sample time in models that don’t have source blocks, such as algebraic loops.

  • Specify the simulation rate independently from the block sample times, using the Model Parameter dialog box.

Once you have completed these changes, verify whether your model gives the same outputs as before.

Appropriate Blocks for the Sample Time Parameter

Specify sample time on the boundary of a model or subsystem, or in blocks designed to model rate transitions. Examples include:

  • Blocks in the Sources library

  • Blocks in the Sinks library

  • Trigger ports (if Trigger type is set to function-call) and Enable ports

  • Data Store Read and Data Store Write blocks, as the Data Store Memory block they link to might be outside the boundary of the subsystem

  • Rate Transition block

  • Signal Specification block

  • Blocks in the Discrete library other than the Discrete Filter, Discrete FIR Filter, and Discrete Transfer Fcn blocks

  • Message Receive block

  • Function Caller block

Specify Sample Time in Blocks Where Hidden

You can specify sample time in the blocks that do not display the parameter on the block dialog box. If you specify value other than -1 in these blocks, no error occurs when you simulate the model. However, a message appears on the block dialog box advising to set this parameter to -1 (inherited sample time). If you promote the sample time block parameter to a mask, this parameter is always visible on the mask dialog box.

To change the sample time in this case, use the set_param command. For example, select a block in the Simulink Editor and, at the command prompt, enter:

set_param(gcb,'SampleTime','2');

Related Topics