Digital Control and Sampling

Sample time, aliasing, delay, the Z-transform, discrete PID and choosing a sample rate.

From continuous to sampled

Almost every controller today is a program: a PLC, a microcontroller, a drive. It reads the sensor at regular instants (every Ts), computes the control law and holds the output constant until the next instant with a zero-order hold (ZOH). Between samples the loop is open. The analysis of the earlier pages (Laplace Transforms and Transfer Functions to Stability: Routh, Root Locus and Margins) still applies if Ts is short compared with the dynamics, but it shows up in two new ways: aliasing and an additional delay of about Ts ÷ 2.

Sampling and aliasing

The Nyquist–Shannon theorem says a signal can be reconstructed from its samples only if it is sampled at more than twice its highest frequency (fs > 2 fmax). A component at frequency f above half the sampling rate aliases, appearing in the samples as a false low-frequency component at |f − k fs| for the integer k that brings it into the range 0 to fs ÷ 2. The cure is an analog anti-aliasing filter before the converter, or sampling much faster than needed and filtering digitally.

SignalSample rateAppears asComment
50 Hz mains pick-up40 Hz10 Hza slow wobble on the measurement
50 Hz mains pick-up100 Hz50 Hzexactly at the Nyquist frequency: unreliable
60 Hz pick-up100 Hz40 Hzaliases into the passband
vibration of 130 Hz100 Hz30 Hza low-frequency ghost in a slow loop
1 Hz ripple1 000 Hz1 Hzrecorded correctly

Choosing the sample time

Each sample adds a delay: the ZOH holds the output for Ts, which on average is a delay of Ts ÷ 2, and the measurement is up to Ts old. This erodes the phase margin by ωgc Ts ÷ 2 (see Frequency Response and Bode Plots). Rules of thumb: sample at least 10 times per closed-loop rise time, or 4 to 10 times per dead time, and at 10 to 30 times the closed-loop bandwidth for a servo. Typical rates:

LoopSample time
Temperature, level, slow chemical processes0.5 to 5 s
Flow and pressure0.05 to 0.5 s
Motor speed loop0.5 to 2 ms
Position loop in a servo0.25 to 1 ms
Motor current loop50 to 100 µs (10 to 20 kHz)
Power converter control10 to 50 µs

Worked example: sample time on the oven loop

Worked example: the Ziegler–Nichols PID at different sample times

  • The oven has a dead time of 15 s and the closed-loop rise time is about 46 s, so the rules give Ts ≤ 3.75 s (a quarter of the dead time) and ≤ 4.6 s (a tenth of the rise): 1 to 2 s is comfortable.
  • The ZN PID has a continuous phase margin of 37° at ωgc = 0.081 rad/s. Each sample time costs ωgc Ts ÷ 2 in phase; at Ts = 10 s this is 23°:
Sample timePhase margin (estimated)Overshoot (simulated)IAE
1 s35°15 %689
2 s33°17 %705
5 s26°14 %778
10 s14°26 %1 237
15 s2°57 %2 681
20 s-9°69 %2 886
The effect of sample time on the oven loop0100200300400-200204060time (s)oven temperature rise (°C)sample time 1 s: overshoot 15 %sample time 10 s: overshoot 26 %sample time 20 s: overshoot 69 %Each sample of delay adds to the dead time: on average a sampled loop behaves as if it had an extra half a sampleperiod of delay.
The same PID sampled every 1, 10 and 20 seconds.

At 1 s the loop behaves like the continuous design. By 10 s the loop rings noticeably, and at 20 s (more than the dead time) the response is badly oscillatory: the controller no longer sees what is happening between samples, and the extra delay has used up the margin. The slower the sample, the more conservative the tuning must be.

Discretizing a controller and a plant

A continuous plant sampled with a ZOH has an exact discrete equivalent. For the first-order oven part (ignoring its dead time) with Ts seconds: yk+1 = a yk + K (1 − a) uk with a = e−Ts ÷ τ. At Ts = 1 s, a = 0.99170 and the gain factor K (1 − a) = 0.01660; at 20 s, a = 0.8465. The pole of the discrete system lies at z = a inside the unit circle, so the plant is stable; the z-plane is the sampled counterpart of the s-plane: the left half-plane maps to the inside of the unit circle (z = es Ts), and stability requires all poles inside it.

To turn a continuous controller into a program, replace the derivative and integral by approximations: forward Euler (s ≈ (z − 1) ÷ Ts, simple but it can be unstable if Ts is large: the first-order lag above is stable only for Ts < 2 τ = 240 s), backward Euler (always stable, slightly damped) and the Tustin (bilinear) transform s ≈ (2 ÷ Ts)(z − 1) ÷ (z + 1) (a good match to the frequency response, preserving stability; the factor is 2 ÷ s at Ts = 1 s). For a digital design the more accurate method is to design directly in the z-domain.

The discrete PID algorithm

A typical positional implementation, executed every Ts:

  1. ek = rk − yk
  2. Pk = Kp ek
  3. Ik = Ik−1 + Kp (Ts ÷ Ti) ek   (with anti-windup: skip the update when the output is saturated, see Practical Control: Windup, Feedforward and Cascade)
  4. Dk = α Dk−1 − Kp Td (1 − α) (yk − yk−1) ÷ Ts   with α = Td ÷ (Td + N Ts) (derivative on the measurement, filtered)
  5. uk = clamp(Pk + Ik + Dk)

For the lambda PI of the oven with Ts = 1 s the integral increment per sample is Kp Ts ÷ Ti × e = 2 × 1 ÷ 120 = 0.0167 per °C of error per second. The velocity (incremental) form computes the change Δuk and adds it to the previous output; it needs no integral state and handles bumpless switching and saturation naturally. Execution must be regular (a fixed-period task or interrupt): a PLC that runs the loop in a cyclic task with jitter violates the sample-time assumption.

Quantization and word length

The analog-to-digital converter (ADC) has finite resolution: an N-bit converter over a range R has a step q = R ÷ 2N. The error is not a problem for P and I terms but is amplified by the derivative:

ADCStep over 0 to 400 °CDerivative term jitter (Z–N PID, no filter, Ts = 1 s)
10 bit0.3906 °C14.06 %
12 bit0.0977 °C3.52 %
16 bit0.0061 °C0.22 %

A 10-bit input makes the heater output jump by 14 percent per one-step change of the reading: the derivative must be filtered or the resolution increased. In a fixed-point controller, scaling and overflow also matter; in a 16-bit integer integral term a small Ts ÷ Ti may round to zero (the integral never grows): use 32-bit or floating-point for the integral.

Related

FAQ

How fast should I sample?

At least 10 samples per closed-loop rise time, and not slower than a quarter of the dead time. Faster than that costs processor time and amplifies noise without improving control.

What is aliasing?

A frequency above half the sample rate appears in the samples as a false lower frequency. Prevent it with an analog low-pass filter before the converter.

Why does my loop get worse when the PLC scan time grows?

Each sample is extra delay. If the loop is in a program with a variable scan time (or an uneven task period) the effective sample time and the delay both change.

Z-transform or just program it?

For most PID work you can program the discrete equations directly. The Z-transform is for designing and analyzing sampled loops, such as a dead-beat controller or a filter.

References

  • Franklin, G. F., Powell, J. D., Workman, M. L., Digital Control of Dynamic Systems, Addison-Wesley; Åström, K. J., Wittenmark, B., Computer-Controlled Systems, Prentice Hall.
  • Ogata, K., Discrete-Time Control Systems, Pearson; Phillips, C. L., Nagle, H. T., Digital Control System Analysis and Design.
  • IEC 61131-3 (PLC programming languages, including the PID function block) and PLCopen motion-control specifications.

Last reviewed: October 2026. Sample-time rules are rules of thumb; the oven results are simulated.