Circuit Bytes · Episode 47 · Electronics · Analog to digital
"Analog to digital"
A microphone turns sound into a smoothly varying analog voltage. An analog-to-digital converter (ADC) measures that voltage over and over, music CDs 44,100 times a second, and snaps each measurement to the nearest step. Many chips split 0 to 5 V into 1,024 steps, so 2.5 V, halfway up, is stored as 512.
Analog: a smooth voltage
A microphone turns sound into a voltage that rises and falls smoothly as the air pressure changes. A signal like that, which can take any value in between, is called analog. (A real microphone's voltage is tiny, so it's amplified first, as in episode 43.)
Sampling: measure, measure, measure
A chip can only store numbers, so a converter measures the voltage at regular moments and writes each measurement down. How often it measures is the sampling rate. Music CDs take 44,100 measurements every second for each channel, fast enough to capture everything people can hear.
Steps: snap to the nearest one
Each measurement can't be stored with endless precision. Instead the converter has a fixed ladder of steps and records the step closest to the voltage it measured. Many hobby chips, such as the one on an Arduino Uno, split 0 to 5 V into 1,024 steps, numbered 0 to 1023, so each step is about 4.9 millivolts.
The ideal step number is:
step = voltage × 1,024 ÷ 5 V
So 2.5 V, exactly halfway up, gives 2.5 × 1,024 ÷ 5 = 512.
Rebuilding the wave
Line up the stored numbers in order and you have the wave written in digits. Play them back through a digital-to-analog converter and you get the sound again. That whole job, turning a smooth voltage into a list of numbers, is done by an analog-to-digital converter, or ADC.
Try it yourself
Use step = voltage × 1,024 ÷ 5 V. A reading of 3.75 V gives 3.75 × 1,024 ÷ 5 = 768. Now try 0.5 V and check that you land on step 102 (the exact answer is 102.4, which snaps to the nearest step, 102).
Good to know
- A CD's own ladder is much finer than 1,024 steps: 16-bit CD audio has 65,536 steps. The 1,024 figure is for common hobby microcontrollers.
- Some tutorials divide by 1,023 instead of 1,024 (2.5 V comes out as 511.5); the difference is less than one step.
- Real converters round or truncate depending on their design, and electrical noise can move a reading by a step or two.
- The video draws fewer, bigger steps than 1,024 so you can see the snapping.
- Where do those numbers go next? Episode 48 turns them into bits.
- Battery or low-voltage supplies only; leave wall wiring to a licensed electrician.
Answer to the comment question
A converter splits zero to five volts into one thousand twenty-four steps. Which step does one point two five volts land on? Step 256. 1.25 V is one quarter of 5 V, and one quarter of 1,024 steps is 1,024 ÷ 4 = 256 (or 1.25 × 1,024 ÷ 5 = 256).
Test your knowledge
Quick quiz: "Analog to digital"
4 multiple-choice questions. Pick one answer for each, then check how you did.
Sources
- Arduino language reference, "analogRead()": 10-bit ADC maps 0 to 5 V onto 0-1023, about 4.9 mV per unit
- SparkFun Learn, "Analog to Digital Conversion": sampling, resolution, relating ADC value to voltage
- Wikipedia, "Compact Disc Digital Audio": 16-bit samples at 44,100 per second per channel (cross-check)
- US National Archives, "Audio: Digital (CD)": CD audio 44.1 kHz, 16-bit
Video transcript
How does a smooth sound wave become numbers?
A microphone turns sound into a voltage that rises and falls smoothly. That's an analog signal.
A chip stores numbers, so a converter measures that voltage over and over. Music CDs take forty-four thousand one hundred measurements every second.
Each measurement snaps to the nearest step. Many chips split zero to five volts into one thousand twenty-four steps.
Two point five volts is halfway up, so it's stored as five hundred twelve.
Line up the numbers and you've rebuilt the wave in digits. That's an analog-to-digital converter, or ADC.
A converter splits zero to five volts into one thousand twenty-four steps. Which step does one point two five volts land on? Comment your answer below!
That's your byte.