Main Content

Sample Times in 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 amultirate 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.

Thefundamental sample timeof 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.

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 (usingSimulink 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离散传递FcnblockSample timeis set to[1 0.1][], which gives it an offset of0.1。TheSample timeof the DTF2离散传递Fcnblock is set to0.7, with no offset. The solver is set to a variable-step discrete solver.

Running the simulation and plotting the outputs using thestairsfunction

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.

(For information on thesimcommand. seeRun Simulations Programmatically。)

As the figure demonstrates, because theDTF1block has a0.1offset, theDTF1block has no output untilt = 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 systemscontain 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, seeModeling 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 anUpdate Diagramwith Sample Time DisplayColorsturned 'on'. As an example, consider the following model that contains an atomic subsystem, “Discrete Cruise Controller”, and a virtual subsystem, “Car Dynamics”. (Seeex_execution_order。)

Car Model

With theSample Timeoption set toAll, anUpdate Diagramturns 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

Car Dynamics Subsystem after an Update Diagram

Now consider a multirate subsystem that contains threeSine Wavesource blocks, each of which has a unique sample time — 0.2, 0.3, and 0.4, respectively.

Multirate Subsystem after an Update Diagram

AnUpdate Diagramturns the subsystem yellow because the subsystem contains more than one sample time. As shown in the block diagram, theSine Waveblocks 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.

See Also

|