Sensors & Signal Processing
How oversampling adds resolution to an ADC
Oversampling reads a sensor many times and averages, and the average is finer than one count of the converter. Average N readings and random error shrinks by √N: 4 readings buy one extra bit, 16 buy two, 256 buy four, so a 10-bit converter behaves like a 14-bit one. It only works if a little noise, called dither, makes the readings scatter, and only for signals slow enough to wait for all those readings.
How an average sees fractions
A 10-bit converter only says whole counts: 499, 500, 501. Suppose the true value is 500.3 and the readings carry a count or two of random noise. Most readings come out 500, quite a few 501, the odd one 499. The average of many of them closes in on 500.3, a value no single reading could give.
It needs the noise
Take the noise away and every reading is the truth rounded: 500, 500, 500. The average of a thousand of them is still exactly 500. The noise is what carries the fraction, which is why some converters add noise on purpose before converting.
The square-root price
| Readings averaged | Average error | Extra bits |
|---|---|---|
| 1 | 0.99 counts | 0 |
| 4 | 0.51 counts | 1 |
| 16 | 0.25 counts | 2 |
| 64 | 0.11 counts | 3 |
| 256 | 0.058 counts | 4 |
Each halving of the error costs four times the readings, and four times the time.
Live experiment
Average your way past a count
A 10-bit converter reads a value creeping from 500.0 to 501.0 counts, with up to two counts of noise. Average 1, 4, 16, 64 or 256 readings: the error falls from 0.99 counts to 0.51, 0.25, 0.11 and 0.058. Then switch the noise off and watch averaging stop helping.
“Oversampling” is lesson 3 of 5 in Dither Delta, Sensors & Signal Processing World 2. Free with an account. Lessons unlock in order, so you’ll do the 9 before it first.
In code
long total = 0;
for (int i = 0; i < 64; i++) total += analogRead(A0);
float value = total / 64.0; // keep the fraction
Limits
- Slow signals only. 256 readings per answer divide the sample rate by 256: fine for a temperature or a weight, useless for audio.
- Random errors only. An offset or gain error is the same in every reading, so averaging keeps it. That needs calibration.
- Enough noise. With less than about a count of random noise, readings stick to one value and the average stops improving.
Kitchen scales that read to a gram, precision thermometers and the converter behind your phone's microphone all lean on oversampling. Audio converters push it furthest: delta-sigma converters sample millions of times a second at very low resolution and average their way to 24-bit sound.
Free lesson
Now build it yourself
Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.
“Oversampling” is lesson 3 of 5 in Dither Delta, Sensors & Signal Processing World 2. Free with an account. Lessons unlock in order, so you’ll do the 9 before it first.
Or start from the very first lesson, no account neededPractice questions
Three quick questions from the lessons. Pick an answer to check it.
Show the answer
Answer: 8 times smaller: √64. Error shrinks with the square root of the number of readings: √64 = 8. The harness measured 0.99 → 0.11.
- Why not “Twice as small”? Twice as small takes only four readings. Sixty-four gives √64 = 8 times smaller.
- Why not “The same”? With noise to dither the readings, averaging does shrink the error, by √64.
- Why not “64 times smaller”? Random errors only partly cancel, so the error falls with the square root of the count: √64 = 8, not 64.
Show the answer
Answer: Four times as many readings. One bit halves the smallest step. Halving the error takes four times the readings, because of the square root.
- Why not “Nothing”? Every extra bit costs four times the conversions, and four times the time.
- Why not “Twice as many”? Doubling the readings shrinks the error by √2, only half a bit. A whole bit needs four times.
- Why not “One more reading”? One reading barely changes an average of many. Each bit needs the count multiplied by four.
Show the answer
Answer: 256 readings near 500 add up to 128,000, past what a 16-bit int holds. On a real Arduino an int stops at 32,767. Totals of many readings need a long.
- Why not “longs are faster”? A long is usually slower on an 8-bit chip. It's chosen because the total needs the room.
- Why not “floats can't add”? Floats can add perfectly well. The point is that a 16-bit int overflows past 32,767.
- Why not “No reason”? There is one: 256 readings of about 500 total 128,000, far past an int's 32,767 on an Uno.
“Oversampling” is lesson 3 of 5 in Dither Delta, Sensors & Signal Processing World 2. Free with an account. Lessons unlock in order, so you’ll do the 9 before it first.
Questions people ask
How many samples do I need for one extra bit of resolution?
Four. Averaging N readings shrinks random error by √N, and one extra bit halves the step size, so it takes four times the readings. Two extra bits take 16, four extra bits 256.
Why does oversampling need noise?
Without noise, a steady input reads the same whole count every time, and the average of identical numbers is that same number. A count or two of random noise makes the readings scatter around the true value, so their average can land between counts.
Can oversampling fix an inaccurate ADC?
No. It improves resolution against random noise only. An offset, a gain error or a reference that's off by 1 % is the same in every reading, so averaging keeps it. Those need calibration.
Related topics
- How Arduino analogRead worksHow analogRead turns 0–5 V into 0–1023, and how to scale it for analogWrite.
- How a moving average filter smooths a noisy sensorAverage 16 readings for a quarter of the noise, and know what it costs.
- How an exponential moving average filter worksNudge a running value a fraction of the way toward each reading.
- What is aliasing, and what is the Nyquist rate?Sample too slowly and a fast wheel seems to crawl backwards.