Main Content

Difference Between Time- and Sample-Based Pulse Generation

This example shows the difference in behavior of the Pulse Generator block in time-based and sample-based modes.

Consider this model, with two Pulse Generator blocks. One block has the Pulse type parameter set to Time based, and the other to Sample based. Both blocks are configured to output a pulse with an amplitude of one that is on for five seconds, followed by off for five seconds. The simulation time runs from three seconds to a stop time of 18 seconds. Notice the time offset notice in the lower right corner.

ans = 

  Simulink.SimulationOutput:
                   tout: [16x1 double] 

     SimulationMetadata: [1x1 Simulink.SimulationMetadata] 
           ErrorMessage: [0x0 char] 

Notice that the time-based Pulse Generator produces an on signal for only two seconds and then switches to off. This is due to the block starting to compute the output from t=0 even though it does not output the simulation until t=3. The sample-based block outputs a pulse of five seconds on followed by five seconds off. In this case, the block output does not depend on simulation time and starts only when the simulation starts.