Main Content

Types of Sample Time

Discrete Sample Time

Given a block with a discrete sample time, Simulink®executes the block output or update method at times

t n = n T s + | T o |

where the sample time period T s is always greater than zero and less than the simulation time, T s i m . The number of periods ( n ) is an integer that must satisfy:

0 n T s i m T s

As simulation progresses, Simulink computes block outputs only once at each of these fixed time intervals of t n . These simulation times, at which Simulink executes the output method of a block for a given sample time, are referred to assample time hits. Discrete sample times are the only type for which sample time hits are knowna priori.

If you need to delay the initial sample hit time, you can define an offset, T o .

TheUnit Delay块是一个块离散山姆ple time.

Continuous Sample Time

Unlike the discrete sample time, continuous sample hit times are divided into major time steps and minor time steps, where the minor steps represent subdivisions of the major steps. The solver produces a result at each major time step. It uses results at the minor time steps to improve the accuracy of the result at the major time step.

The ODE solver you choose integrates all continuous states from the simulation start time to a given major or minor time step. The solver determines the times of the minor steps and uses the results at the minor time steps to improve the accuracy of the results at the major time steps. However, you see the block output only at the major time steps.

To specify that a block, such as theDerivativeblock, is continuous, enter[0, 0]or0in theSample timefield of the block dialog.

Fixed-in-Minor-Step

If the sample time of a block is set to [0, 1], the block becomesfixed-in-minor-step. For this setting, Simulink does not execute the block at the minor time steps; updates occur only at the major time steps. This process eliminates unnecessary computations of blocks whose output cannot change between major steps.

While you can explicitly set a block to be fixed-in-minor-step, more typically Simulink sets this condition as either an inherited sample time or as an alteration to a user specification of0(continuous). This setting is equivalent to, and therefore converted to, the fastest discrete rate when you use a fixed-step solver.

Inherited Sample Time

If a block sample time is set to[–1, 0]or–1, the sample time isinheritedand Simulink determines the best sample time for the block based on the block context within the model. Simulink performs this task during the compilation stage; the original inherited setting never appears in a compiled model. Therefore, you never see inherited ([–1, 0]) in the Sample Time Legend. (SeeView Sample Time Information.)

There are some blocks in which the sample time is inherited (-1) by default. For these blocks, the parameter is not visible on the block dialog box unless it is set to a noninherited value. Examples of these blocks include theGainandRounding Functionblocks. As a good modeling practice, do not change theSample timeparameter for these blocks. For more information, seeBlocks for Which Sample Time Is Not Recommended.

All inherited blocks are subject to the process of sample time propagation, as discussed inHow Propagation Affects Inherited Sample Times

Constant Sample Time

In Simulink, a constant is a symbolic name or expression whose value you can change only outside the algorithm or through supervisory control. Blocks, like the constant block, whose outputs do not change during normal execution of the model, are always considered to be constant.

Simulink assigns constant sample time to these blocks. They run their block output method:

  • At the start of a simulation.

  • In response to runtime changes in the environment, such as tuning a parameter.

For constant sample time, the block sample time assignment is[inf,0]or[inf].

For a block to allow constant sample time, these conditions hold:

  • The block has no continuous or discrete states.

  • The block does not drive an output port of a conditionally executed subsystem (seeUsing Enabled Subsystems).

S-Function Blocks

The Simulink block library includes several blocks, such as theMATLAB S-Functionblock, theLevel-2 MATLAB S-Functionblock, and theC S-Functionblock, whose ports can produce outputs at different sample rates. It is possible for some of the ports of these blocks to have a constant sample time.

Variable Sample Time

Blocks that use a variable sample time have an implicitSampleTimeparameter that the block specifies; the block tells Simulink when to run it. The compiled sample time is [–2,Tvo] whereTvois a unique variable offset.

ThePulse Generatorblock is an example of a block that has a variable sample time. Since Simulink supports variable sample times for variable-step solvers only, thePulse Generatorblock specifies a discrete sample time if you use a fixed-step solver.

To learn how to write your own block that uses a variable sample time, seeC MEX S-Function Examples.

Controllable Sample Time

A block can be configured to use a controllable sample time with a resolutionTbase.Tbaseis the smallest allowable time interval between block executions. To setTbasein your own C S-Function block, usessSetControllableSampleTime.

A block using controllable sample time can be dynamically set to execute atnmultiples ofTbase. The time of the block's next execution is

Tnext=nTbase+T

You can setnin your C S-Function block usingssSetNumTicksToNextHitForControllableSampleTime.

Triggered Sample Time

如果一个块内triggered-type(例如,傅nction-call, enabled and triggered, or iterator) subsystem, the block may be constant or have a triggered sample time. You cannot specify the triggered sample time type explicitly. However, to achieve a triggered type during compilation, you must set the block sample time to inherited (–1). Simulink then determines the specific times at which the block computes its output during simulation. One exception is if the subsystem is an asynchronous function call, as discussed in the following section.

Asynchronous Sample Time

An asynchronous sample time is similar to a triggered sample time. In both cases, it is necessary to specify an inherited sample time because the Simulink engine does not regularly execute the block. Instead, a run-time condition determines when the block executes. For the case of an asynchronous sample time, an S-function makes an asynchronous function call.

The differences between these sample time types are:

  • Only a function-call subsystem can have an asynchronous sample time. (SeeUsing Function-Call Subsystems.)

  • The source of the function-call signal is an S-function having the option SS_OPTION_ASYNCHRONOUS.

  • The asynchronous sample time can also occur when a virtual block is connected to an asynchronous S-function or an asynchronous function-call subsystem.

  • The asynchronous sample time is important to certain code-generation applications. (SeeAsynchronous Events(Simulink Coder).)

  • The sample time is [ 1 , n ] .

For an explanation of how to use blocks to model and generate code for asynchronous event handling, seeRate Transitions and Asynchronous Blocks(Simulink Coder).

See Also

||