ADCMACDACa0.9b0.1y[n−1]–0101010101010101−1½¼⅛1/161/321/641/1281A, B = 115, 13 # Q72y = 03for x in X:4 y = (A*y + B*x + 64) >> 7x
02040608000.10.20.30.40.5n (sample number)yOUTPUT y[n]idealQ7Q7 stops at 60 = 0.469stuck at 4 = 0.031-2-1012-1-0.500.51true sum (in units of 1)stored8-BIT SUMwrapsaturate150 → −0.828
Coloured parts: what the current step is about; everything else rests in whiteBlocks: converters (ADC, DAC), the multiply-accumulate unit, memory for a, b and y[n−1], an 8-bit register and a Python code cardPlots: the ideal and the Q7 filter output, and what an 8-bit word stores for a sum (wrap or saturate)The sample token moves in slow motion; the pill over the MAC shows the integer arithmeticThe smoother y[n] = 0.9·y[n−1] + 0.1·x[n] runs in Q7 integers: coefficients 115 and 13, one tick (A·y + B·x + 64) >> 7 every 125 µs. Rounding here is "add half, then shift right", which rounds halves upward, as in the Q-format and Oppenheim & Schafer examples. Truncation toward zero (magnitude truncation) instead removes zero-input limit cycles in a first-order filter, at the cost of a larger error.

Real time

  1. A filter runs in real time when each output is ready before the next input arrives. Here samples come 8000 times a second, one every 125 µs. A 16 MHz processor then has 2000 clock cycles per sample.

Numbers as integers

One filter tick

What rounding does

Code and budget

The working

# step 1/10 · realtime

fs = 8000 samples per second
Ts = 1 / fs = 125 µs

clock 16 MHz:
  16 000 000 × 0.000125 = 2000 cycles per sample

read x[n] -> compute y[n] -> write y[n]
all inside one Ts, every Ts, forever
late once = a lost or repeated sample

The sample rate 8000 per second and the 16 MHz clock are example values; the filter, the Q7 rounding rule and every output value are computed from this model. An 8-bit word is used so the rounding effects are big enough to see. The motion is slowed down a great deal: in the real system one sample passes every 125 µs.