Sample Times in Systems and Subsystems - MATLAB & Simulink (2024)

Sample Times in Systems and Subsystems

Purely Discrete Systems

A purely discrete system is composed solely of discrete blocks and can be modeled using either a fixed-step or a variable-step solver. Simulating a discrete system requires that the simulator take a simulation step at every sample time hit. For a multirate discrete system—a system whose blocks Simulink® samples at different rates—the steps must occur at integer multiples of each of the system sample times. Otherwise, the simulator might miss key transitions in the states of the system. The step size that the Simulink software chooses depends on the type of solver you use to simulate the multirate system and on the fundamental sample time.

The fundamental sample time of a multirate discrete system is the largest double that is an integer divisor of the actual sample times of the system. For example, suppose that a system has sample times of 0.25 and 0.50 seconds. The fundamental sample time in this case is 0.25 seconds. Suppose, instead, the sample times are 0.50 and 0.75 seconds. The fundamental sample time is again 0.25 seconds.

The importance of the fundamental sample time directly relates to whether you direct the Simulink software to use a fixed-step or a variable-step discrete solver to solve your multirate discrete system. A fixed-step solver sets the simulation step size equal to the fundamental sample time of the discrete system. In contrast, a variable-step solver varies the step size to equal the distance between actual sample time hits.

The following diagram illustrates the difference between a fixed-step and a variable-step solver.

Sample Times in Systems and Subsystems- MATLAB & Simulink (1)

In the diagram, the arrows indicate simulation steps and circles represent sample time hits. As the diagram illustrates, a variable-step solver requires fewer simulation steps to simulate a system, if the fundamental sample time is less than any of the actual sample times of the system being simulated. On the other hand, a fixed-step solver requires less memory to implement and is faster if one of the system sample times is fundamental. This can be an advantage in applications that entail generating code from a Simulink model (using Simulink Coder™). In either case, the discrete solver provided by Simulink is optimized for discrete systems; however, you can simulate a purely discrete system with any one of the solvers and obtain equivalent results.

Consider the following example of a simple multirate system. For this example, the DTF1 Discrete Transfer Fcn block Sample time is set to [1 0.1] [], which gives it an offset of 0.1. The Sample time of the DTF2 Discrete Transfer Fcn block is set to 0.7 , with no offset. The solver is set to a variable-step discrete solver.

Sample Times in Systems and Subsystems- MATLAB & Simulink (2)

Running the simulation and plotting the outputs using the stairs function

set_param(bdroot,'SolverType','Variable-Step','SolverName','VariableStepDiscrete','SaveFormat','Array');simOut = sim(bdroot,'Stoptime','3');stairs(simOut.tout,simOut.yout,'-*','LineWidth',1.2);xlabel('Time (t)');ylabel('Outputs (out1,out2)');legend('t_s = [1, 0.1]','t_s = 0.7','location','best')

produces the following plot.

Sample Times in Systems and Subsystems- MATLAB & Simulink (3)

(For information on the sim command. see Run Simulations Programmatically. )

As the figure demonstrates, because the DTF1 block has a 0.1 offset, the DTF1 block has no output until t = 0.1. Similarly, the initial conditions of the transfer functions are zero; therefore, the output of DTF1, y(1), is zero before this time.

Hybrid Systems

Hybrid systems contain both discrete and continuous blocks and thus have both discrete and continuous states. However, Simulink solvers treat any system that has both continuous and discrete sample times as a hybrid system. For information on modeling hybrid systems, see Modeling Hybrid Systems.

In block diagrams, the term hybrid applies to both hybrid systems (mixed continuous-discrete systems) and systems with multiple sample times (multirate systems). Such systems turn yellow in color when you perform an Update Diagram with Sample Time Display Colors turned 'on'. As an example, consider the following model that contains an atomic subsystem, “Discrete Cruise Controller”, and a virtual subsystem, “Car Dynamics”.

Car Model

Sample Times in Systems and Subsystems- MATLAB & Simulink (4)

With the Sample Time option set to All, an Update Diagram turns the virtual subsystem yellow, indicating that it is a hybrid subsystem. In this case, the subsystem is a true hybrid system since it has both continuous and discrete sample times. As shown below, the discrete input signal, D1, combines with the continuous velocity signal, v, to produce a continuous input to the integrator.

Car Model after an Update Diagram

Sample Times in Systems and Subsystems- MATLAB & Simulink (5)

Car Dynamics Subsystem after an Update Diagram

Sample Times in Systems and Subsystems- MATLAB & Simulink (6)

Now consider a multirate subsystem that contains three Sine Wave source blocks, each of which has a unique sample time — 0.2, 0.3, and 0.4, respectively.

Multirate Subsystem after an Update Diagram

Sample Times in Systems and Subsystems- MATLAB & Simulink (7)

An Update Diagram turns the subsystem yellow because the subsystem contains more than one sample time. As shown in the block diagram, the Sine Wave blocks have discrete sample times D1, D2, and D3 and the output signal is fixed in minor step.

In assessing a system for multiple sample times, Simulink does not consider either constant [inf, 0] or asynchronous [–1, –n] sample times. Thus a subsystem consisting of one block that outputs constant value and one block with a discrete sample time will not be designated as hybrid.

The hybrid annotation and coloring are very useful for evaluating whether or not the subsystems in your model have inherited the correct or expected sample times.

Sample Time in Subsystems

Subsystems fall into two categories: triggered and non-triggered. For triggered subsystems, in general, the subsystem gets its sample time from the triggering signal. One exception occurs when you use a Trigger block to create a triggered subsystem. If you set the block Trigger type to function-call and the Sample time type to periodic, the SampleTime parameter becomes active. In this case, you specify the sample time of the Trigger block, which in turn, establishes the sample time of the subsystem.

There are four non-triggered subsystems:

  • Virtual

  • Enabled

  • Atomic

  • Action

Simulink calculates the sample times of virtual and enabled subsystems based on the respective sample times of their contents.

The atomic subsystem is a special case in that the subsystem block has a SystemSampleTime parameter. Moreover, for a sample time other than the default value of –1, the blocks inside the atomic subsystem can have only a value of Inf, –1, or the identical (discrete) value of the subsystem SampleTime parameter. If the atomic subsystem is left as inherited, Simulink calculates the block sample time in the same manner as the virtual and enabled subsystems. However, the main purpose of the subsystem SampleTime parameter is to allow for the simultaneous specification of a large number of blocks, within an atomic subsystem, that are all set to inherited. To obtain the sample time set on an atomic subsystem, use this command at the command prompt:

get_param(AtomicSubsystemBlock,‘SystemSampleTime’);

Finally, the sample time of the action subsystem is set by the If block or the Switch Case block.

For non-triggered subsystems where blocks have different sample rates, Simulink returns the Compiled Sample Time for the subsystem as a cell array of all the sample rates present in the subsystem. To see this, use the get_param command at MATLAB prompt.

get_param(subsystemBlock,'CompiledSampleTime')

Related Topics

  • View Sample Time Information
  • Specify Execution Domain

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Sample Times in Systems and Subsystems- MATLAB & Simulink (8)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

Contact your local office

Sample Times in Systems and Subsystems
- MATLAB & Simulink (2024)

FAQs

What is the sample time of Simulink Solver? ›

The fundamental sample time is again 0.25 seconds. The importance of the fundamental sample time directly relates to whether you direct the Simulink software to use a fixed-step or a variable-step discrete solver to solve your multirate discrete system.

How to calculate sample time in Simulink? ›

Simulink provides a way to do this by allowing you to set the sample time for discrete, continuous, and multi-rate components. This model of a fuel control system has sample times set to control when the discrete, continuous, and multi-rate components are updated. Sample time is set as a parameter in the block dialog.

What is the sample time in MATLAB system? ›

The sample time of a block is a parameter that indicates when the block produces an output, and eventually updates its internal state. To specify sample time for a MATLAB System block, implement the getSampleTimeImpl method with a call to createSampleTime .

How to choose sampling time? ›

Best Practice: Sample time should be 10 times per process time constant or faster (T ≤ 0.1Tp). How performance is affected when we sample a process at different rates during a bump test and then complete the controller design and tuning using this same T.

What is sample time 0 1 in Simulink? ›

If the sample time of a block is [ 0 1 ], the block has fixed-in-minor-step sample time. For this sample time, the block does not execute at the minor time steps. The block executes only at major time steps.

What is constant sample time in Simulink? ›

Simulink assigns Constant blocks a sample time of infinity, also referred to as a constant sample time. Other blocks have constant sample time if they receive their input from a Constant block and do not inherit the sample time of another block.

What is the difference between sample time and simulation time? ›

Sample time should be smaller then the simulation time. Because sample time represents the sampling period after which MATLAB will fetch the data for reading. If your simulation time is lesser then the sampling time then there is no data fetched for the simulation.

What is the sample time of the Simulink scope in MATLAB? ›

The Simulink Scope uses block-based sample time, which resolves to a FDR sample time for the block as a whole during the initialization phase of the simulation. During the simulation phase, the Scope block processes all inputs at the FDR sample rate. This sample rate can cause oversampling of some inputs.

What is the formula for sampling time? ›

The sampling frequency or sampling rate, fs, is the average number of samples obtained in one second, thus fs = 1/T, with the unit samples per second, sometimes referred to as hertz, for example 48 kHz is 48,000 samples per second.

How to set simulation time in Simulink? ›

Simulation Time

You can change the start time and stop time for the simulation by entering new values in the Start time and Stop time fields. The default start time is 0.0 seconds and the default stop time is 10.0 seconds. Simulation time and actual clock time are not the same.

How to get system time in MATLAB? ›

To return the current time as a datetime value, call datetime . You can call it without any input arguments, or with "now" as the input argument. To return the current time as a date vector, split it apart using the datevec function.

What is step size in Simulink? ›

If the model specifies one or more periodic sample times, Simulink chooses a step size equal to the greatest common divisor of the specified sample times. This step size, known as the fundamental sample time of the model, ensures that the solver will take a step at every sample time defined by the model.

What is the difference between discrete and continuous in Simulink? ›

Continuous solvers rely on the individual blocks to compute the values of the model's discrete states at each time step. Discrete solvers exist primarily to solve purely discrete models.

What is the sample time of the Simulink scope? ›

The Simulink Scope uses block-based sample time, which resolves to a FDR sample time for the block as a whole during the initialization phase of the simulation. During the simulation phase, the Scope block processes all inputs at the FDR sample rate. This sample rate can cause oversampling of some inputs.

What is the time interval for Simulink simulation? ›

Simulation Time

You can change the start time and stop time for the simulation by entering new values in the Start time and Stop time fields. The default start time is 0.0 seconds and the default stop time is 10.0 seconds. Simulation time and actual clock time are not the same.

References

Top Articles
Latest Posts
Article information

Author: Kerri Lueilwitz

Last Updated:

Views: 6724

Rating: 4.7 / 5 (67 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Kerri Lueilwitz

Birthday: 1992-10-31

Address: Suite 878 3699 Chantelle Roads, Colebury, NC 68599

Phone: +6111989609516

Job: Chief Farming Manager

Hobby: Mycology, Stone skipping, Dowsing, Whittling, Taxidermy, Sand art, Roller skating

Introduction: My name is Kerri Lueilwitz, I am a courageous, gentle, quaint, thankful, outstanding, brave, vast person who loves writing and wants to share my knowledge and understanding with you.