Skip to content
Tactiverge

Open Lab investigation · OL-03

How Many Bits Are Enough?

Investigate how storing a sensor signal with fewer bits trades memory for accuracy, and where extra bits stop being worth it.

About 1.5 h · intermediate · 6 steps · Free

This is a learning investigation, not peer-reviewed research. Unexpected results are welcome: what matters is a clear hypothesis, honest data and careful interpretation.

The question

Research question

How does the number of bits used to store each sample of a sensor signal affect the error in the stored signal, and at what point do extra bits stop making a meaningful difference for a given task?

Why it matters

Small robots and sensors often run on microcontrollers with only a few kilobytes of memory and very little stored energy. Every byte stored or sent costs memory, energy and radio time. Engineers constantly choose how precisely to store numbers. Store too few bits and you lose information you needed; store too many and you waste resources that could have bought a longer running time or more history.

"Intelligent" behaviour on a small device is often less about clever algorithms and more about spending limited resources wisely. This investigation lets you measure one of those trade-offs directly, with a short Python script and no hardware.

This is a learning exercise, not peer-reviewed research. Unexpected results are welcome: a prediction that turns out wrong, honestly reported, is a good outcome.

You will learn to

  • Explain quantisation and predict its error from the step size.
  • Run a systematic numerical experiment and compare it with a theoretical prediction.
  • Judge 'enough' precision against a stated task rather than in the abstract.
  • Relate data representation to memory and energy on small devices.

Limits

  • C1Use the provided script and free Python with the standard library only.
  • C2Test every bit depth from 1 to 16.
  • C3State your task and tolerance before collecting data.
  • C4The signal is made up; do not present results as measurements of any real sensor.

Background

Quantisation

A sensor signal must be stored as numbers with a fixed number of bits. With b bits you have 2^b possible values. If the signal ranges from 0 to 1 and you use evenly spaced levels including both ends, the step between levels is 1 / (2^b − 1). Each sample is rounded to the nearest level. The difference between the true value and the stored value is the quantisation error.

For a signal that moves around a lot compared with the step, the error behaves roughly like a random value spread evenly between −step/2 and +step/2. The RMS of such a spread is step / √12. For 8 bits: step = 1 / 255 ≈ 0.00392, and 0.00392 / √12 ≈ 0.00113.

So each extra bit roughly halves the step, and should roughly halve the error. Whether the real signal behaves like this is something you can test.

The experiment environment

This script makes a made-up "sensor" signal, stores it at a chosen number of bits and measures the RMS error and the memory used for 200 samples.

import math

# A made-up "sensor" signal: 200 samples between 0.0 and 1.0
signal = [0.5 + 0.4 * math.sin(0.07 * k) + 0.05 * math.sin(1.3 * k) for k in range(200)]

def quantise(x, bits):
    levels = 2 ** bits - 1
    return round(x * levels) / levels

def rms_error(bits):
    sq = [(quantise(x, bits) - x) ** 2 for x in signal]
    return math.sqrt(sum(sq) / len(sq))

bits = 8
print(f"{bits} bits: rms error {rms_error(bits):.5f}, memory {len(signal) * bits // 8} bytes")

Run as written, it prints this, which confirms your copy works:

8 bits: rms error 0.00111, memory 200 bytes

The memory figure assumes bits are packed tightly, which real code sometimes does and sometimes does not: storing 12-bit values in 16-bit variables wastes a quarter of the space.

"Enough" depends on the task

An error is only too big compared with what you need. If the signal represents soil moisture and a plant needs watering below 0.30, an error of 0.01 hardly matters. If you are differentiating the signal to estimate speed, small steps can become large, jumpy errors. Before your experiment, choose a task and a tolerance.

How to approach it

  1. 01

    Choose a task and tolerance

    Imagine what the signal represents and what a device would do with it. Write down the task and the largest RMS error you could accept, with a reason. This is your yardstick for "enough".

  2. 02

    Write your hypothesis

    Before running the loop, predict how the RMS error will change with bit depth, and the smallest bit depth that meets your tolerance. Use the step / √12 idea to make a numerical prediction.

  3. 03

    Set up and pilot

    Run the script as written and check you get the exact output shown. Then try 2 and 12 bits by hand. Decide how you will present all 16 results, and whether to compare each with the step / √12 prediction.

  4. 04

    Collect data

    Write a loop for bits = 1 to 16 that prints the bit depth, RMS error, step / √12 and memory. Copy the full output into your data field.

  5. 05

    Interpret

    Where does the measured error agree with the prediction, and where does it not? Why might the smallest bit depths behave differently? Which bit depth would you choose for your task, and how much memory does it save compared with 16 bits?

  6. 06

    Limitations

    Real sensors add their own noise before quantisation. Think about what happens when the sensor's noise is bigger than the quantisation step. Would extra bits still help? Write down how you would test this by adding noise to the signal.

Your work

Everything above is free to read and use. To save drafts, submit versions and get feedback, sign in.

You can also work on paper: the prompts below are what a submission asks for.

  1. Hypothesis (written before you collect any data)
  2. Method
  3. Data and observations
  4. Interpretation
  5. Limitations

How it's judged

There is more than one good answer. This rubric describes what strong work looks like.

Question and hypothesis

Beginning
No clear hypothesis, or it was clearly written after seeing the data.
Developing
A hypothesis is stated before data but is vague, so almost any result would fit it.
Proficient
A specific, falsifiable hypothesis with a reason behind it, written before data collection.
Exemplary
As Proficient, plus a stated prediction of how big the effect should be and what result would count against it.

Method and control of variables

Beginning
The method is missing or too vague to repeat.
Developing
The changed variable is clear, but other variables drift between runs or repeats are missing.
Proficient
One variable is changed at a time, others are held fixed and listed, with repeats and a decision rule set in advance.
Exemplary
As Proficient, plus a pilot run that led to a documented change of method, and a check that the measurement itself is reliable.

Data quality and honesty

Beginning
Data are missing, unitless or only summarised, with no raw values.
Developing
Raw data are present but inconvenient runs are silently dropped or units are inconsistent.
Proficient
All runs are reported with units, including failed or surprising ones, with a note on each exclusion.
Exemplary
As Proficient, plus variability between repeats is quantified (for example a range or standard deviation) and used in the interpretation.

Interpretation and limitations

Beginning
Claims go beyond the data or ignore the hypothesis.
Developing
The result is described but not connected to the hypothesis, or limitations are generic.
Proficient
The conclusion follows from specific numbers, and the most important limitation is named with its likely effect.
Exemplary
As Proficient, plus alternative explanations are considered and the student says exactly what further test would distinguish them.

Reflect

  • Was there a point where adding bits stopped mattering for your task? How did you decide?
  • Why did choosing a task before collecting data make your conclusion stronger?
  • Where else on a robot might the same 'how much precision is enough?' question appear?

Go further

Add a simple decision to the script: 'needs attention' when the value is below 0.2. Count how many of the 200 decisions change between the original and the quantised signal at each bit depth, and compare that with the RMS error. Which measure better describes what matters for this task?