S9 · Lesson 42 · Discrete-time design and implementation
Specifications in the z-plane, choosing the sample rate from the phase it costs, the velocity form of PI, coefficient precision near z = 1, and the delays a computer adds
Lesson 41 turned continuous plants into discrete ones and continuous controllers into difference equations. Running a controller on a microcontroller raises the questions that come next. How fast must it sample? Where in the z-plane should the poles go to meet a time-domain specification? How should the PI law be written so that saturation and mode switches don't upset it? And how many bits does a coefficient need when the pole it sets sits a hair inside the unit circle?
- The curve is the phase lost at a loop's crossover to a zero-order hold plus one sample of computation delay, , against the ratio of sample rate to crossover frequency, .
- Sampling 20 times faster than crossover costs 27°; 100 times, 5.4°.
- That's why the usual advice samples 10 to 40 times the closed-loop bandwidth, and why fast loops push for computation in under one sample.
Predict
A loop crosses over at 50 rad/s. Its controller computes for one full sample before updating the output. What sample rate keeps the lost phase under 10°?
The hold costs about T/2 of delay and the computation another T: 1.5T in all, so rad gives T ≤ 2.3 ms, a sample rate of at least 430 Hz, about 54 times the 8 Hz crossover. Updating the output right after the measurement, rather than a sample later, would cut the requirement to a third.
Name it
Specifications in the z-plane
A continuous pole s maps to . So a decay rate σ becomes a circle of radius (a 2% settling time needs every pole inside radius ), a damped frequency becomes an angle , and a damping ratio ζ becomes a logarithmic spiral from z = 1 toward the origin. A desired pair gives the discrete polynomial
and pole placement, Ackermann's formula and the root locus all work on the discrete model just as they do in s.
Choosing the sample rate
The hold delays the signal by about T/2, and a controller that updates its output one sample after measuring adds T more. At crossover these cost and radians of phase margin. Sampling 10 to 40 times the closed-loop bandwidth keeps the loss acceptable; anti-aliasing filters ahead of the converter add their own lag on top.
The velocity form of PI
Instead of computing , compute the change:
then clamp to the actuator's limits. Because is the clamped value actually applied, there's no hidden integral to wind up, and switching from manual to automatic is bumpless: the controller starts from whatever output was applied.
Precision near z = 1
A slow pole sampled fast sits close to 1: . Storing z with a step of changes by up to half a step, a relative error in τ of about , which grows as the sample rate rises. Writing the filter in terms of , or using more bits, fixes it.
Worked example
A continuous design wants ζ = 0.7 and = 10 rad/s. With T = 20 ms, where should the discrete poles go?
Show the solution
- Continuous poles.
- Map them to z. so .
- Characteristic polynomial.
- What it reproduces. Placing the sampled plant's poles there reproduces the continuous response at the sampling instants, though the hold's lag shows up as slightly more overshoot unless T is short.
Answer at , the roots of .
Worked example
A filter pole for a 1 s time constant runs at 1 kHz. Its coefficient is stored with 10 fractional bits. What time constant does the filter really have?
Show the solution
- Exact coefficient.
- Quantize to 10 bits. The nearest multiple of 1/1024 is
- Resulting time constant. 2.3% long.
- With 16 bits. It's 0.9925 s, still 0.75% off, because the pole is only one part in a thousand from 1.
- The fix. Storing instead, or sampling the slow filter at a lower rate, solves it.
Answer about 1.0235 s, 2.3% longer than the intended 1 s.
Worked example
A PI controller ( = 0.5, = 0.1 per sample) runs against a limit of ±1. The error is +1 for 50 samples, then becomes −1. What does each form do at the switch?
Show the solution
- Position form. Its integral climbs during the 50 samples to
- After the switch. Its output stays clamped at +1 until the integral unwinds to 1.5: about 35 more samples of full drive in the wrong direction.
- Velocity form. At the first sample after the switch it computes
- Why it reverses at once. It never stored more than the clamped output.
Answer the position form keeps driving +1 for about 35 more samples, while the velocity form reverses at once, to −0.1.
Check
A continuous design has ζ = 0.7, = 5 rad/s, and the controller samples every 50 ms.
(a)
What radius should the discrete poles have?
(b)
At what angle?
Write units the way you normally would: 1.5 rad and 1500 mrad are the same answer.
Check
A loop crosses over at 100 rad/s and samples at 0.2 kHz, updating its output one sample after each measurement.
(a)
How much phase do the hold and the computation delay cost at crossover?
Check
A loop crosses over at 100 rad/s and may lose at most 5° to a hold plus one sample of computation.
(a)
What is the lowest sample rate?
Write units the way you normally would: 1.5 kHz, 1500 Hz and 0.0015 MHz are the same answer.
Check
A first-order filter with τ = 1 s runs at 1 kHz, its pole stored with 24 fractional bits.
(a)
How far from 1 is the exact pole?
(b)
What's the worst relative error in τ from rounding?
Check
A velocity-form PI ( = 0.5, = 0.05 per sample) applied 0.8 last sample with error 2; now the error is −1.
(a)
What output does it compute before clamping?
Check
A loop must settle within 0.5 s (2%) and samples every 1 ms.
(a)
Inside what radius must every closed-loop pole lie?
Check
Why does the velocity form of a PI controller avoid integrator windup when its output is clamped?
Check
Continuous poles with damping z and natural frequency w are sampled every T.
Step 1
What is minus the coefficient of z in the discrete polynomial?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
What is its constant term?
Check
Write pi_position(errors, Kp, KiT, umin, umax) (integral summed separately, output clamped) and pi_velocity(errors, Kp, KiT, umin, umax) (each output the clamped previous output plus the change), both starting from zero output, zero integral and zero previous error, returning the list of outputs.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why does a digital controller's sample rate need to be many times its loop's crossover frequency, not just twice it?
The sampling theorem only says how fast to sample to reconstruct a signal, but a control loop also cares about delay. The zero-order hold that turns samples back into a continuous input delays them by about half a sample, and a controller that updates its output one sample after measuring adds a whole sample more. Delay costs phase margin in proportion to frequency, so at the crossover these delays eat roughly one and a half times the crossover frequency times the sample period in radians. Keeping that loss to a few degrees requires sampling tens of times faster than the crossover, and anti-aliasing filters add further lag, which is why the usual rule is 10 to 40 times the closed-loop bandwidth.
Practice
Keep practicing
9 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.