Discrete¶
Unit Delay¶
discrete.unit_delay · Discrete
Delays its input by one sample period:

Like an Integrator in continuous time, a Unit Delay breaks algebraic loops in discrete-time feedback.
Parameters¶
| Name | Default | Unit | Description |
|---|---|---|---|
initial |
0.0 |
Initial output | |
sample_time |
-1 (inherited) | s | Sample period (-1 = inherit from input) |
Direct feedthrough: no
Zero-Order Hold¶
discrete.zero_order_hold · Discrete
Samples its input every sample_time seconds and holds the value until the next sample:

This is how a continuous signal (e.g. a sensor) enters a discrete controller.
Parameters¶
| Name | Default | Unit | Description |
|---|---|---|---|
sample_time |
1.0 |
s | Sample period (-1 = inherit from input) |
Direct feedthrough: yes
Discrete-Time Integrator¶
discrete.integrator · Discrete
Discrete-time integrator (accumulator).

forward_euler (no direct feedthrough):
backward_euler:
The state is limited to [lower, upper].
external_reset adds a second input, reset. When it fires, the state goes back to initial before the
output of that step is computed: rising (reset goes from ≤ 0 to > 0), falling (> 0 to ≤ 0),
either, or level (every step while reset ≠ 0). Typical use: clear an accumulated error or an
on-time counter when a mode changes.
Parameters¶
| Name | Default | Unit | Description |
|---|---|---|---|
gain |
1.0 |
Gain K | |
initial |
0.0 |
Initial condition | |
method |
'forward_euler' |
Integration method — one of forward_euler, backward_euler |
|
upper |
inf | Upper limit | |
lower |
-inf | Lower limit | |
external_reset |
'none' |
Add a reset input that sets the state back to the initial value — one of none, rising, falling, either, level |
|
sample_time |
1.0 |
s | Sample period (-1 = inherit from input) |
Direct feedthrough: depends on parameters
Discrete Transfer Fcn¶
discrete.transfer_function · Discrete
Discrete SISO transfer function
Coefficients are in descending powers of z. For example [1] / [1, -0.9] is a first-order low-pass.
Parameters¶
| Name | Default | Unit | Description |
|---|---|---|---|
numerator |
[1.0] |
Numerator coefficients (descending powers of z) | |
denominator |
[1.0, 0.5] |
Denominator coefficients (descending powers of z) | |
sample_time |
1.0 |
s | Sample period (-1 = inherit from input) |
Direct feedthrough: depends on parameters
Integer Delay¶
discrete.integer_delay · Discrete
Delays its input by delay samples: y[k] = u[k - N]. The first N outputs are initial.
Use it to model communication or processing delays, e.g. a CAN message that arrives one 10 ms frame late.
Parameters¶
| Name | Default | Unit | Description |
|---|---|---|---|
delay |
2 |
Number of samples N | |
initial |
0.0 |
Output during the first N samples | |
sample_time |
-1 (inherited) | s | Sample period (-1 = inherit from input) |
Direct feedthrough: no
Counter¶
discrete.counter · Discrete
Counts samples while the input is non-zero (true).

At limit the counter either wraps to 0 or saturates (stays at the limit). Connect a Constant 1
for a free-running counter, e.g. to schedule something every N task periods.
Parameters¶
| Name | Default | Unit | Description |
|---|---|---|---|
limit |
255.0 |
Largest value | |
at_limit |
'wrap' |
What happens at the limit — one of wrap, saturate |
|
initial |
0.0 |
Initial count | |
sample_time |
-1 (inherited) | s | Sample period (-1 = inherit from input) |
Direct feedthrough: no
Edge Detect¶
discrete.edge_detect · Discrete
Outputs 1 for one sample when the (boolean) input changes, otherwise 0.

direction: rising (false → true), falling (true → false) or either. The input counts as
true when it is non-zero. Typical use: react once when a switch is pressed or a fault appears.
Parameters¶
| Name | Default | Unit | Description |
|---|---|---|---|
direction |
'rising' |
Which edge — one of rising, falling, either |
|
initial |
0.0 |
Previous input before the first sample (0 or 1) | |
sample_time |
-1 (inherited) | s | Sample period (-1 = inherit from input) |
Direct feedthrough: yes
Debounce¶
discrete.debounce · Discrete
Debounces a boolean input: the output turns on only after the input has been true for on_samples consecutive samples, and off after it has been false for off_samples samples.

This is how ECUs filter switch bounce and confirm faults before setting a diagnostic trouble code.
Parameters¶
| Name | Default | Unit | Description |
|---|---|---|---|
on_samples |
3 |
Samples the input must be true to switch on | |
off_samples |
3 |
Samples the input must be false to switch off | |
sample_time |
-1 (inherited) | s | Sample period (-1 = inherit from input) |
Direct feedthrough: yes
Discrete Filter (PT1)¶
discrete.filter · Discrete
First-order low-pass filter, the workhorse for smoothing sensor signals in ECU software.

with time constant τ and sample period T. Larger τ gives a smoother but slower signal.
Parameters¶
| Name | Default | Unit | Description |
|---|---|---|---|
time_constant |
0.1 |
s | Filter time constant τ |
initial |
0.0 |
Initial output | |
sample_time |
-1 (inherited) | s | Sample period (-1 = inherit from input) |
Direct feedthrough: yes
Moving Average¶
discrete.moving_average · Discrete
Average of the last length samples (including the current one).
Before N samples exist, the missing ones count as initial.
Parameters¶
| Name | Default | Unit | Description |
|---|---|---|---|
length |
4 |
Number of samples N | |
initial |
0.0 |
Value of samples before the start | |
sample_time |
-1 (inherited) | s | Sample period (-1 = inherit from input) |
Direct feedthrough: yes