Electronics / Analog-to-digital conversion

Analog-to-digital conversion

A smooth voltage goes in, a list of binary numbers comes out. Follow eight samples through a 3-bit converter, see what bit depth and sampling rate buy, then turn the numbers back.

Beginner7 steps~6 min
Signal — the smooth analog voltage
Sample — one measurement at one instant
Band — a 1 V slice of the range, with a number
Code — the band number in 3 bits
// THE SHORT VERSION

In 30 seconds

The real world is smooth: a microphone voltage can take any value at any instant. A computer only stores numbers. An analog-to-digital converter bridges the two.

It does two things. Sampling measures the voltage at regular ticks of a clock. Quantisation rounds each measurement to the nearest of a fixed set of levels and writes that level in binary.

More bits per sample mean finer levels; more samples per second mean higher frequencies can be captured. A digital-to-analog converter turns the numbers back into a voltage.

Analog-to-digital conversion, step by step

STEPS01 / 07

Simplified: real converters put a filter before the sampler to remove frequencies that are too high, and real signals usually swing both above and below zero.

STEP 01 / 07 A smooth signal
THE MATH
voltage: any value, 0 to 8 V time: a value at every instant
  1. Step 1: A smooth signal. A microphone turns sound into a voltage that rises and falls smoothly. This is an analog signal: it has a value at every instant, and that value can be anything in its range, here 0 to 8 volts. A computer stores only whole numbers, so the curve has to be turned into a list of them.
  2. Step 2: Sampling: measure on a clock. First cut time into pieces. The converter measures the voltage at regular instants, here once every millisecond, and ignores what happens in between. Each measurement is a sample. Eight milliseconds of signal become eight readings: 4.4, 6.3, 7.2, 5.6, 3.5, 1.4, 0.7 and 2.6 volts.
  3. Step 3: Quantisation: round to a level. Next cut the voltage into pieces. With 3 bits there are only eight codes, 000 to 111, so the 8 volt range is split into eight bands, each 1 volt wide. A sample gets the number of the band it lands in: 4.4 V is in band 4, written 100 in binary. 1.4 V becomes 001 and 2.6 V becomes 010.
  4. Step 4: Out comes a stream of bits. Do the same for every sample and the curve has become eight codes: 100, 110, 111, 101, 011, 001, 000, 010. That is 24 bits for 8 milliseconds, or 3000 bits per second. These numbers are all the computer keeps; the smooth curve itself is gone.
  5. Step 5: Bit depth sets the resolution. The number of bits per sample is the bit depth. Every extra bit doubles the number of levels and halves the step between them, so the rounded value sits closer to the true one. Over the same 8 volts, 3 bits give 1 V steps, 5 bits give 0.25 V, 8 bits about 31 mV, and the 16 bits of CD audio about 0.12 mV.
  6. Step 6: Sample fast enough. The Nyquist rule: sample more than twice as fast as the highest frequency in the signal. At 1000 samples a second that means below 500 Hz. Feed in an 875 Hz tone and the dots trace a false 125 Hz wave instead, called an alias. CD audio samples 44,100 times a second to cover hearing up to about 20 kHz.
  7. Step 7: And back again: the DAC. A digital-to-analog converter (DAC) runs the trip in reverse, for a loudspeaker for example. Each code becomes a voltage, the middle of its band, held until the next code: a staircase. A smoothing filter then rounds off the steps. The result is close to the original but not identical: what rounding threw away stays lost.
VALUES SO FAR
range0 to 8 Vinput
rate····sampling
depth····choice
levels····result
step····result
stream····result
f max····Nyquist
error····rounding

Spotted a mistake on this page?