Digital control: sampling and its cost
Introduced
6:36
System Dynamics and Control
The cooling loop needs one more part - a valve that sets the flow, moved by a small motor and a controller. This course builds the models, reads their…
English narration · English and 中文 subtitles you can switch
In this lesson
| English | Meaning |
|---|---|
| phase margin/feɪz ˈmɑːdʒɪn/ | How much extra phase lag at the gain crossover frequency would make a feedback loop unstable. |
| ADC/ˌeɪ diː ˈsiː/ | An analogue-to-digital converter: it samples a voltage and turns it into a number. |
| zero-order hold/ˈzɪərəʊ ˈɔːdə həʊld/ | A converter that holds each sample's value constant until the next sample. |
| aliasing/ˈeɪlɪəsɪŋ/ | When a signal is sampled too slowly, so high frequencies appear as false lower frequencies. |
| Nyquist frequency/ˈnaɪkwɪst ˈfriːkwənsi/ | Half the sampling frequency, the highest frequency a sampled signal can represent. |
| bandwidth/ˈbændwɪdθ/ | The frequency range carried by a signal or channel; in networking, often used for its data transfer capacity. |
| encoder | |
| conditional integration | |
| anti-alias filter/ˈænti ˈeɪlɪəs ˈfɪltə/ | A low-pass filter used before sampling to remove frequencies above half the sampling rate. |
The loop runs on a microcontroller
- The controller runs in discrete time. Sampling, word length and computing time each cost phase margin 相位裕度. We can afford them only if we count them.
- An ADC 模数转换器 samples every $T$ seconds, and a zero-order hold 零阶保持 keeps the output constant until the next sample. On average that is a delay of $T/2$, which costs $\omega T/2$ of phase.

Tustin and aliasing
- Tustin's method replaces $s$ by $\tfrac{2}{T}\tfrac{z - 1}{z + 1}$. For the integral this is the trapezium rule: $I_k = I_{k-1} + \tfrac T2(e_k + e_{k-1})$.
- Any signal above the Nyquist frequency 奈奎斯特频率, half the sample rate, folds back into the band. This is aliasing 混叠, so filter it out before the ADC.
Which digital cost?
Name the digital effect behind each number.
Nyquist frequency at a 1 kHz sample rate (Hz)?
Difficulty 2/5 · 140 coins + a small bonus on first completion today
Half the sample rate.
The anti-alias filter goes:
Difficulty 1/5 · 100 coins + a small bonus on first completion today
Once sampled, an alias cannot be separated.
Choosing the sample rate
- At $\omega_n = 74.4$ rad/s the hold costs $74.4T/2$: 2.1° at 1 kHz but 21° at 100 Hz.
- At the 48.2 rad/s crossover it costs 1.4° at 1 kHz, so the phase margin falls from 65.2° to 63.8°. At 100 Hz it falls to 51.3°.
- Choose 1 kHz: about 85 samples per cycle of the 11.8 Hz bandwidth 带宽.
Hold phase at 74.4 rad/s, T = 1 ms (one decimal, degrees)?
Difficulty 2/5 · 140 coins + a small bonus on first completion today
omega T / 2 in degrees.
At T = 10 ms (degrees, whole number)?
Difficulty 2/5 · 140 coins + a small bonus on first completion today
Ten times larger.
Quantisation and delay
- The encoder 编码器 gives 100 000 counts per valve turn: 0.0036° per count, far below the 0.5° specification.
- Counting at 1 kHz gives the motor speed only in steps of 3.14 rad/s, one more reason to avoid derivative action. A 0.2 ms computing delay adds 0.6° of lag.
Degrees per count with 100 000 counts per turn (four decimals)?
Difficulty 2/5 · 140 coins + a small bonus on first completion today
360 over 100 000.
A computation delay costs phase margin.
Difficulty 1/5 · 100 coins + a small bonus on first completion today
0.6 degrees for 0.2 ms at crossover.
The integral in code
- Tustin's integral at $T = 1$ ms is one line per sample: $I_k = I_{k-1} + 0.4965(e_k + e_{k-1})$, since $K_iT/2 = 993 \times 0.0005$. Then $u_k = 134e_k + I_k$, clamped to ±12 V.
- Use conditional integration 条件积分 for anti-windup: when the output is saturated, suppress an integral update that would drive it further into saturation, but allow an update that drives it back toward the permitted range.
Tustin integral with $K_i = 993$ and $T = 1$ ms: the coefficient on $(e_k + e_{k-1})$ (four decimals)?
Difficulty 2/5 · 140 coins + a small bonus on first completion today
$K_iT/2 = 993 \times 0.0005 = 0.4965$.
Worked example: mains hum in the temperature
- Sample the tank temperature at 10 Hz. 50 Hz hum picked up by the sensor wires is exactly five times the sample rate, so every sample catches the hum at the same point. It aliases to 0 Hz and looks like a constant offset.
- No later filter can remove it. An RC filter at 1 Hz before the ADC 模数转换器 passes the slow temperature and cuts the 50 Hz hum to $1/\sqrt{1 + 50^2} = 0.020$ of its size.
First-order filter with a 1 Hz corner: gain at 50 Hz (three decimals)?
Difficulty 2/5 · 140 coins + a small bonus on first completion today
$1/\sqrt{1 + (50/1)^2} = 0.020$.
Hum aliased into the band can be filtered out digitally after sampling.
Difficulty 1/5 · 100 coins + a small bonus on first completion today
Once aliased it sits at the same frequency as the real signal; the filter must act before the ADC.
Three common mistakes
- Leaving out the anti-alias filter 抗混叠滤波器. High frequencies fold into the band.
- Ignoring the computing delay. It costs phase, like the hold.
- Differentiating a stepped position signal. The steps become noise.
Recap
- The hold costs $\omega T/2$ of phase. At 74.4 rad/s:
| Sampling | Phase lost |
|---|---|
| 1 kHz | 2.1° |
| 100 Hz | 21° |
- Sample at 20 to 30 times the bandwidth 带宽 or more; use Tustin's method for the controller.
- 0.0036° per count; 3.14 rad/s speed steps; 0.6° for a 0.2 ms delay.
What went wrong? Only the site team sees this.