Skip to content
Tactiverge

School/✦ Research Engineer/Week 24

Reduced precision: range, resolution and error

Your filter works perfectly in Python floats. On the 16-bit chip, it slowly drifts and then explodes. What went wrong?

About 45 min · 3 goals · Checked by automated tests

1.Why should I care?

Reduced precision saves memory, time and energy, but every bit you remove costs either range (you overflow) or resolution (you round). The art is spending bits where the signal needs them, and proving with a measurement that the result still meets the requirement.

  • ◇ Choose a fixed-point format (Qm.n) from a signal's range and the resolution needed.
  • ◇ Explain overflow, rounding and accumulation of error in reduced-precision arithmetic.
  • ◇ Measure accuracy loss from reduced precision or sample rate against a stated requirement.

2.Discover

On the 4-bit register, show the largest and smallest values, then add 1 to 1111 and watch the carry fall off. Now imagine those 4 bits as Q1.3 fixed point (one integer bit, three fraction bits): what are its range and step size?

Can't use the interactive? Read a description instead

The 4-bit register shows 0000 to 1111. In two's complement, 0111 is 7 and adding 1 gives 1000, which is −8: the value wraps. Read as Q1.3, the same bits cover −1 to 0.875 in steps of 0.125.

3.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

Practice 1

What is the step size (resolution) of a signed Q4.12 number?

4.Apply it

Start the term project: pick your algorithm, write the accuracy requirement and decision rule, and choose Q formats for a 16-bit and an 8-bit version with the range and resolution reasoning written out. Do not run anything yet.

Open BUILD 008: Create a Virtual Computer →

5.Understand

Qm.n formats

A signed Qm.n number has m integer bits (including sign) and n fraction bits: value = integer / 2ⁿ. Range ≈ [−2^(m−1), 2^(m−1)), step 2^(−n). Q1.15 in 16 bits covers [−1, 1) in steps of about 3×10⁻⁵. Choose m from the largest value the signal (and every intermediate result) can reach, then give the rest to n.

Where precision is lost

Rounding each result loses up to half a step. Multiplication doubles the fraction bits (Q1.15 × Q1.15 = Q2.30), so results are shifted back and rounded. Accumulation of many products needs extra headroom bits. Feedback (recursive filters, integrators) can accumulate rounding errors or sustain small oscillations (limit cycles).

Precision is a measured requirement

State the requirement first (for example, 'error under 0.5% of full scale'), then implement at candidate precisions on identical inputs, measure the error and pick the smallest that meets it with margin. The same applies to sample rate: lower rates save energy until aliasing or lag breaks the requirement. This is the method of the term project.

Explain it another way

A ruler marked only in centimetres can't measure a hair, and a 30 cm ruler can't measure a room. Fixed point makes you pick your ruler before you start.

Worked example 1

A gyro reads ±250 °/s and you need 0.01 °/s resolution. Pick a 16-bit signed format.

Range needs 2^(m−1) ≥ 250, so m − 1 = 8 integer bits plus sign: m = 9. That leaves n = 7 fraction bits: step 1/128 ≈ 0.0078 °/s < 0.01 ✓. Q9.7.

Common mix-ups

  • More fraction bits are always better.
    ✓ In a fixed word, every fraction bit is taken from range: you trade overflow risk for resolution.
  • If the inputs fit, the result fits.
    ✓ Sums and products need more bits than their inputs; size every intermediate, or use a wide accumulator.

6.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 2

What is the largest value a signed Q4.12 (16-bit) number can hold? (Give it to 4 decimal places.)

Practice 3

Multiplying two Q1.15 numbers gives a 32-bit result in which format?

Practice 4 · a fresh version every time

A neural network has 120000 weights stored at 8 bits each. How many kilobytes (1 KB = 1024 bytes) do the weights occupy?

KB

Practice 5

Why write the accuracy requirement before testing precisions?

7.Predict

A signed 4-bit register holds 7 (0111). You add 1. What does it hold?

Guess first. Being wrong here is how the surprise works.

8.Reflect

Concepts: Units, scaling and fixed-point arithmetic · Fixed-width integers, bits and registers · Measurement error and uncertainty