Lite / Engineering Complex Systems / Week 27
Signals meet hardware: the cycle budget
A 48 MHz microcontroller sounds fast. Can it filter a 48 kHz audio signal in real time? It depends on one division.
Why should I care?
This lesson joins the two halves of the term. A real-time signal system has to finish its work on every sample before the next one arrives. Getting the budget wrong means dropped samples, glitches or a control loop that goes unstable.
- Connect a full pipeline: sensor, anti-aliasing filter, ADC, digital filter, processor.
- Compute a processor's cycle budget per sample and its load at a given sample rate.
- Choose sample rate, bit depth and filter to meet a cycle budget.
Predict
A 48 MHz processor samples audio at 48 kHz. How many clock cycles does it have per sample?
- 48
- 1000
- 48,000
- 2304
Guess first, then reveal
48,000,000 / 48,000 = 1000 cycles per sample, shared between reading the ADC, filtering, output and everything else. A moving average costs a few cycles per tap; a big FIR filter can eat the whole budget.
Discover
In the Code Lab, simulate the pipeline: generate a 50 Hz sine plus noise sampled at 1 kHz, quantise it to 10 bits, then filter it with a moving average and with a first-order IIR. Count the arithmetic operations per sample for each and compare the outputs.
What the interactive shows (text version)
In the simulated pipeline, the noisy 50 Hz sine sampled at 1 kHz and quantised to 10 bits is smoothed by both filters. A moving average with a running sum costs about one add and one subtract per sample; the first-order IIR costs two multiplies and one add, and gives a smoother output with a small delay.
Understand
The pipeline
Sensor → analog anti-aliasing filter → ADC (sample rate fs, N bits) → digital filter → decision or output. Each stage has a requirement from this term: fs > 2 × the highest wanted frequency with margin; N bits for the SNR you need; a filter whose response keeps the band and rejects noise; and a processor that keeps up.
The cycle budget
Cycles available per sample = f_clk / fs. Processor load = fs × (cycles per sample) / f_clk. Keep it well under 100 %, because interrupts, communication and the rest of the program need cycles too. A first-order IIR needs about two multiplies and an add per sample; an M-point moving average can be done with a running sum in constant time.
Trading between stages
A better analog filter lets you sample more slowly, saving cycles. More bits cost ADC time and memory but not filter cycles. An IIR filter gives strong smoothing for a handful of cycles but with phase lag; a long FIR filter has linear phase but costs a multiply per tap. Systems engineering is choosing these together, not one at a time.
Explain it another way
Intuitive
Samples arrive like items on a conveyor belt. You must finish with each one before the next arrives, or they pile up and fall off.
Technical
Hard real-time systems guarantee the worst-case execution time per sample, not the average. DMA can move samples from the ADC to memory without using the processor's cycles.
Mathematical
Budget B = f_clk/fs. 16 MHz at 8 kHz: B = 2000 cycles. A 64-tap FIR at 4 cycles per tap uses 256 cycles: 12.8 % load.
Applied
Digital hearing aids run filter banks on tiny, low-power processors; their designers balance sample rate, filter length and clock frequency so the battery lasts days, using exactly the P = αCV²f and cycle-budget arithmetic from this term.
Worked example 1
An 80 MHz processor filters a 44.1 kHz signal with a 128-tap FIR at 3 cycles per tap plus 100 cycles of overhead. What is the load?
Cycles per sample = 128 × 3 + 100 = 484. Load = 44,100 × 484 / 80,000,000 ≈ 26.7 %.
Common mix-ups
If the average load is under 100 %, the system is real-time.
✓ Real-time needs the worst case to fit in every sample period, with margin for everything else.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Term synthesis: specify a vibration monitor for a 0–500 Hz band on a 48 MHz processor. Choose fs, ADC bits (with SNR), an anti-aliasing filter cut-off, a digital filter and its cycle cost, and show the processor load. One page, every number justified.
Reflect
Which decision in your synthesis constrained all the others most?
Write your answer on paper or in your own notes. Lite never stores what you write.