Skip to content
Tutorials Center
My learning

Topics

Lesson 16 of 36 ยท Continuous and Discrete Systems

Simulink Discrete-Time Systems, Sample Times and Rate Transitions

Model digital controllers in Simulink: Unit Delay, Discrete-Time Integrator, Discrete Transfer Fcn, sample time settings, color coding, zero-order hold and Rate Transition blocks.

Real controllers run on computers, and computers act at discrete moments: read sensors, compute, write outputs, wait for the next tick. Simulink models this with blocks that have a sample time Ts. A discrete block updates only at multiples of Ts and holds its output in between. Mixing continuous plants with discrete controllers (a sampled-data system) is the usual way to simulate embedded control.

Simulink is not available on this site, so the block settings are described from the product, and Python stand-ins reproduce the difference equations and multirate scheduling.

Sample time basics

Most blocks have a Sample time parameter:

Value Meaning
0 Continuous: updated at every solver step, including minor steps
Ts (e.g. 0.01) Discrete: updates at 0, Ts, 2Ts, ...
[Ts offset] Discrete with an offset, e.g. [0.01 0.005]
-1 Inherited from the input or the parent system (the default for many blocks)
inf Constant: computed once at start

Show sample times in the diagram with Debug > Information Overlays > Sample Time Colors (labels appear after updating the diagram with Ctrl+D). The color convention: black continuous, red the fastest discrete rate, green the second fastest, blue the third, then other colors; blocks with several rates may be yellow or orange. A constant signal has magenta lines; a triggered block uses another color.

Sample time values

0 Continuous
Ts > 0 Discrete, held between ticks
-1 Inherited
inf Constant

Check colors with Ctrl+D.

1 / 2

The discrete library

  • Unit Delay: y[k] = u[k-1], shown as 1/z. Has an initial condition and a sample time. The most basic memory block.
  • Memory: like a Unit Delay but at the solver step instead of a fixed sample time.
  • Zero-Order Hold: samples the input at Ts and holds it. The way a continuous signal becomes a discrete one (an ADC).
  • Discrete-Time Integrator: accumulates u with a method: Forward Euler (y[k+1] = y[k] + Ts*u[k]), Backward Euler (y[k] = y[k-1] + Ts*u[k], direct feedthrough) or Trapezoidal. It can saturate and reset.
  • Discrete Transfer Fcn: coefficients in z, written in descending powers or in z^-1: numerator [1], denominator [1 -0.9] is 1/(z - 0.9).
  • Discrete Filter, Discrete PID Controller, Discrete Derivative, Discrete State-Space, Discrete FIR Filter.

Converting a continuous transfer function: use c2d(tf(1,[1 1]), 0.1, 'zoh') from the Control System Toolbox (read-only MATLAB; the stand-in below does the same for a first-order lag by hand).

Difference equations

A discrete system is a recipe for the next value in terms of old ones. A first-order low-pass filter y[k] = a*y[k-1] + (1-a)*u[k] with a = 0.9 is, in transfer function form, (1 - a) / (z - a). Its pole is at z = a = 0.9. For discrete systems stable means all poles inside the unit circle (|z| < 1).

Python Stand-in: a discrete low-pass filter with Unit Delay (Python)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Integration methods

The Discrete-Time Integrator offers several methods that behave differently. Compare them with an input of 1 and Ts = 0.5:

Python Stand-in: Forward Euler, Backward Euler and Trapezoidal (Python)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Forward Euler has no direct feedthrough (output uses the previous input), which is why it can sit inside a feedback loop without an algebraic loop; Backward Euler and Trapezoidal do have direct feedthrough.

Multirate systems and Rate Transition

A model can contain blocks at several rates, for example a 1 ms current loop and a 10 ms speed loop. A slow-to-fast transfer is easy (the fast block just sees the held value). A fast-to-slow transfer can drop or tear data. The Rate Transition block (Signal Attributes) handles crossings safely: it holds data, and can add a delay to maintain data integrity.

Options: Ensure data integrity during data transfer (on by default), Ensure deterministic data transfer, Output port sample time (-1 inherits from the destination). In a multitasking real-time target the Rate Transition prevents two tasks from reading and writing the same data at the same time; with integrity and determinism on, the transfer from slow to fast takes a one-slow-period delay.

Python Stand-in: a fast loop reading a slow controller output (Python)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The fast loop sees a staircase: the held value from the last slow update. That is zero-order hold behavior.

Common issues

  • "Sample time mismatch" warnings when two different discrete rates meet without a Rate Transition.
  • Controller too slow: a discrete controller with Ts large relative to plant dynamics loses phase margin; rule of thumb is a sample time of about 1/10 to 1/20 of the closed-loop time constant or faster.
  • Using Memory in generated code: it behaves at the solver step; prefer Unit Delay with an explicit sample time.
  • Setting everything to -1 hides the actual rates. Give the top-level discrete blocks an explicit Ts variable defined in one place.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What sample time value means continuous?

    0 means continuous; -1 means inherited; inf means constant.
  2. 2. What does the Unit Delay block compute?

    It outputs the input from the previous sample, shown as 1/z.
  3. 3. Which blocks are safe for crossing between different sample rates?

    Rate Transition handles data integrity and determinism at rate boundaries.
  4. 4. A discrete system has a pole at z = 1.1. Is it stable?

    |1.1| > 1, so the response grows.

Summary

  • Discrete blocks update at multiples of Ts and hold between ticks; 0 is continuous and -1 is inherited.
  • Unit Delay, Zero-Order Hold, Discrete-Time Integrator and Discrete Transfer Fcn are the core blocks.
  • Discrete stability means poles inside the unit circle; integrator methods differ in feedthrough.
  • Rate Transition blocks protect data crossing between rates; use sample time colors to inspect rates.

Next: Zero-Crossings and Hybrid Systems