Bird
Raised Fist0
Simulinkdata~10 mins

Sample time configuration in Simulink - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Sample time configuration
Start Simulation
↓
Check Sample Time
↓
Continuous
↓
Integrate
↓
Output Signal
↓
End Simulation
Simulation starts, checks if block uses continuous or discrete sample time, then processes accordingly before output.
Execution Sample
Simulink
sampleTime = 0.1
t = 0.0
while t <= 1.0:
    output = f"Output at {t}"
    print(f"Time {t}: Output {output}")
    t += sampleTime
Simulates discrete sample time steps of 0.1 seconds, outputs signal value at each step.
Execution Table
StepTime (t)Sample Time CheckActionOutput
10.0t % 0.1 == 0Calculate outputOutput at 0.0
20.1t % 0.1 == 0Calculate outputOutput at 0.1
30.2t % 0.1 == 0Calculate outputOutput at 0.2
40.3t % 0.1 == 0Calculate outputOutput at 0.3
50.4t % 0.1 == 0Calculate outputOutput at 0.4
60.5t % 0.1 == 0Calculate outputOutput at 0.5
70.6t % 0.1 == 0Calculate outputOutput at 0.6
80.7t % 0.1 == 0Calculate outputOutput at 0.7
90.8t % 0.1 == 0Calculate outputOutput at 0.8
100.9t % 0.1 == 0Calculate outputOutput at 0.9
111.0t % 0.1 == 0Calculate outputOutput at 1.0
121.1t > 1.0Stop simulationNo output
💡 Time exceeds simulation stop time, simulation ends.
Variable Tracker
VariableStartAfter 1After 2After 3After 4After 5After 6After 7After 8After 9After 10Final
t0.00.10.20.30.40.50.60.70.80.91.01.1
outputOutput at 0.0Output at 0.1Output at 0.2Output at 0.3Output at 0.4Output at 0.5Output at 0.6Output at 0.7Output at 0.8Output at 0.9Output at 1.0N/A
Key Moments - 2 Insights
Why does the output only update at multiples of the sample time?
Because the simulation checks if the current time is a multiple of the sample time (see execution_table rows 1-11), output updates only at these discrete times.
What happens if the time is not a multiple of the sample time?
The simulation does not calculate output and stops or waits (see execution_table row 12), because discrete sample time blocks only update at defined intervals.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the output at step 5?
AOutput at 0.4
BOutput at 0.5
CNo output
DOutput at 0.3
💡 Hint
Check the 'Output' column at step 5 in the execution_table.
At which step does the simulation stop due to time exceeding the limit?
AStep 10
BStep 12
CStep 11
DStep 9
💡 Hint
Look at the 'Action' column for the stop simulation note in execution_table.
If sample time changed to 0.2, how would the output update steps change?
AOutput updates every 0.05 seconds
BOutput updates every 0.1 seconds
COutput updates every 0.2 seconds
DOutput updates continuously
💡 Hint
Sample time controls how often output updates, see concept_flow and execution_table.
Concept Snapshot
Sample time controls when blocks update in Simulink.
Continuous sample time updates constantly.
Discrete sample time updates at fixed intervals.
Set sample time to control simulation steps.
Output updates only at multiples of sample time.
Full Transcript
This visual execution shows how sample time configuration works in Simulink. The simulation starts and checks the sample time. If the block uses discrete sample time, it updates output only at multiples of that sample time, for example every 0.1 seconds. The execution table traces each time step, showing output calculation at each multiple of 0.1 seconds. When time exceeds the simulation stop time, the simulation ends. Variables like time and output change step by step. Key moments clarify why output updates only at sample times and what happens otherwise. The quiz tests understanding of output timing and simulation stopping. The snapshot summarizes sample time behavior simply.

Practice

(1/5)
1. What does the sample time in Simulink control?
easy
A. The color of the block in the model
B. How often a block executes during simulation
C. The size of the block on the screen
D. The type of data the block processes

Solution

  1. Step 1: Understand sample time meaning

    Sample time defines the frequency at which a block runs during simulation.
  2. Step 2: Match sample time to options

    Only How often a block executes during simulation describes execution frequency, others describe unrelated features.
  3. Final Answer:

    How often a block executes during simulation -> Option B
  4. Quick Check:

    Sample time = execution frequency [OK]
Hint: Sample time means block run frequency [OK]
Common Mistakes:
  • Confusing sample time with block appearance
  • Thinking sample time controls data type
  • Assuming sample time affects block size
2. Which of the following is the correct way to set a fixed sample time of 0.1 seconds in a Simulink block?
easy
A. Set Sample time to 'inf'
B. Set Sample time to '-1'
C. Set Sample time to '0.1'
D. Set Sample time to 'triggered'

Solution

  1. Step 1: Identify fixed sample time syntax

    Fixed sample time is set by a positive number representing seconds, e.g., 0.1.
  2. Step 2: Evaluate options

    '-1' means inherited, 'inf' means continuous, 'triggered' is not a numeric value.
  3. Final Answer:

    Set Sample time to '0.1' -> Option C
  4. Quick Check:

    Fixed sample time = positive number [OK]
Hint: Fixed sample time is a positive number [OK]
Common Mistakes:
  • Using '-1' for fixed sample time
  • Confusing 'inf' with fixed sample time
  • Entering non-numeric values for sample time
3. Consider a Simulink model with two blocks: Block A has a sample time of 0.05 seconds, and Block B has a sample time of 0.1 seconds. If the simulation runs for 0.2 seconds, how many times will Block A execute?
medium
A. 4 times
B. 3 times
C. 5 times
D. 2 times

Solution

  1. Step 1: Calculate executions for Block A

    Block A runs every 0.05 seconds. Total simulation time is 0.2 seconds. Executions occur at t=0, 0.05, 0.1, 0.15 (not at 0.20 since simulation ends at 0.2).
  2. Step 2: Divide total time by sample time

    Number of executions = (0.2 / 0.05) = 4 (executions at 0, 0.05, 0.1, 0.15).
  3. Final Answer:

    4 times -> Option A
  4. Quick Check:

    Executions at t=0, 0.05, 0.1, 0.15 = 4 times [OK]
Hint: Number of executions = floor(total time / sample time) + 1 [OK]
Common Mistakes:
  • Forgetting the initial execution at t=0
  • Confusing Block A's sample time with Block B's
  • Counting execution at simulation end time incorrectly
4. You set a block's sample time to '-1' but the block does not inherit the sample time as expected. What is the most likely cause?
medium
A. The block has a fixed sample time set elsewhere
B. The sample time value '-1' is invalid
C. The block is set to continuous sample time
D. The block is inside a triggered subsystem

Solution

  1. Step 1: Understand '-1' sample time meaning

    Sample time '-1' means inherit from parent or driving block.
  2. Step 2: Identify why inheritance fails

    If block is inside a triggered subsystem, inheritance may not work because triggered subsystems have their own timing.
  3. Final Answer:

    The block is inside a triggered subsystem -> Option D
  4. Quick Check:

    Triggered subsystem blocks may block inheritance [OK]
Hint: Triggered subsystems block sample time inheritance [OK]
Common Mistakes:
  • Thinking '-1' is invalid
  • Ignoring subsystem context
  • Assuming continuous sample time causes issue
5. You want to speed up your simulation by reducing the number of block executions but keep accuracy high. Which sample time configuration strategy is best?
hard
A. Use a larger fixed sample time for less critical blocks and smaller for critical ones
B. Set all blocks to continuous sample time
C. Set all blocks to inherited sample time '-1'
D. Use triggered sample time for all blocks

Solution

  1. Step 1: Understand trade-off between speed and accuracy

    Larger sample times reduce executions but may reduce accuracy; smaller sample times increase accuracy but slow simulation.
  2. Step 2: Apply selective sample time setting

    Assign larger sample times to less critical blocks and smaller to critical blocks to balance speed and accuracy.
  3. Final Answer:

    Use a larger fixed sample time for less critical blocks and smaller for critical ones -> Option A
  4. Quick Check:

    Selective sample time balances speed and accuracy [OK]
Hint: Adjust sample times by block importance [OK]
Common Mistakes:
  • Setting all blocks to continuous slows simulation
  • Using inherited sample time everywhere loses control
  • Triggering all blocks may cause unnecessary executions
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard