# Analog and Digital 2

## Digital Technology -- Digitization

• Horizontal zero line, down the middle
• "Sample" (look at) the signal +- vs. the zero line
• Sample very quickly, e.g. 44,000 times per second audio CD
• Each sample records the height of the signal from 0 as a number
• CD audio, each sample is in the range -32767..32768 (2 bytes)
• Reduce signal to a series of "sample" numbers: 1003, 1720, 1939, ...
• Small problem: signal is between 1002 and 1003 .. have to pick one or the other
• Audio-Digital converter chip does this (A/D converter)

The way an analog signal is brought into the computer is "digitization". The computer "samples" the signal very rapidly over time, noting the value (the height basically) of the curve each time, and recording that value as a number. CD quality audio samples the sound signal 44000 times per second, noting the "height" of the sound signal once for sample. Each sample is a whole number in the range -32768 .. 32767 (this is the range of number that can be stored in 2 bytes, 256 squared).

Audio CD digitization is very good, but not perfect. The signal might have a little wiggle that happens so fast, the 44000 samples/second are not fast enough to quite capture the wiggle perfectly. In reality, 44000 samples per second captures almost everything the human ear can hear anyway. There can also be a sort of rounding error -- the signal value might be in between 1452 and 1453, and the digitization has to pick just one value to represent it. As a practical matter, the 44000 samples per second is extremely good at capturing the level of detail that humans can hear.

So in essence, digitization translates a sound signal into just a series of numbers: 12000, 12002, 12006, 12007, 12010, 12005, 12006, ... and so on. Playing back the digital sound is just the reverse: a chip takes in the stream of numbers, say representing 44000 samples/second, and constructs an electrical signal that matches those numbers over time. In effect, this reconstructs the original sound signal from the numbers.

## Digital Playback

• Have a series of digital sample numbers (CD, MP3) .. how get sound back?
• Playback = recreate signal from the numbers
• Look at each number, plot that height above/below zero line
• Repeat for next number
• Connect the dots .. draw the signal between the dots
• Digital-to-Analog chip does this ("D/A converter")

## Digital vs. Errors

• Samples are recorded as 0's/1's on, say, an audio CD
• What does that signal look like for playback?
• What does that signal look like for playback with noise?
• Notice that, even with noise, the 0's/1's are obvious
• This is why digital playback reliably sounds good compared to analog

Read back digital signal, ideal, 0/1:

Read back digital signal in reality, with noise:

For CD audio, each sample number (12000, 12002, 12006, 12007, 12010, 12005, 12006, ...), is coded as a series of 0's and 1's on the disk. (A single number can recorded as a pattern of 0's and 1's, but we have not gone into the detail of how it's done.) Say, a dark spot on the disk is a "1", a light spot is a "0". Now to play the CD, the player reads back this signal with the 0/1 information on it. As above, reading back a signal, you tend to get noise/hiss. In this case, even with lots of noise on the signal, the player can almost always distinguish the 0's from the 1's. It assembles the 0/1 values, from that gets back the sample values (12000, 12002, 12006, ...) and from that reconstructs the sound signal. The key step here, recording the samples as 0's and 1's, is that the read-back process is very resistant to noise. In contrast, with the analog system, the noise is mixed in with the signal we want. With digitization, we screen the noise out.

As a second layer of error-correction, the CD stores in a sense, redundant copies of the sample data. So if one section has errors, detected with a checksum scheme, the CD player can switch to use an alternate copy. This is how, even with a small hole drilled in it, in theory a CD player can still play back perfectly. This is another example of an advantage we get by moving the sound data to the digital domain of just numbers.

## Digital -- Compression

• "Compression" adjusts how data is stored to take up fewer bytes
• "Lossless" compression.. keeps all the original detail, "Lossy" sheds some detail
• Suppose we have this series of samples:
• 12000, 12002, 12006, 12007, 12010, 12005, 12006
• The numbers are quite near to each other -- a typical result
• What if we just record the first number
• Then record the differences, one sample to the next (aka delta)
• 12000, +2, +4, +1, +3, -5, +1
• The numbers to record are much smaller (fewer bytes to store)
• This is an example of lossless compression
• Compression = apply cleverness to change the data to use fewer bytes
• Another scheme:
--Drop every other number. On playback, guess the missing samples as the average of the surrounding numbers.
--This saves 2x space
--This is a "lossy" strategy .. sound is not coming back quite perfect
• MP3 audio compression .. very effective, about 10x less space, but it's lossy

With this picture of a signal digitized into a series of sample numbers, you can understand a bit how compression works. For audio, the samples tend to look like this: 12000, 12002, 12006, 12007, 12010, 12005, 12006.

As a practical matter, each sample number tends to be very close to the sample numbers that come just before and just after it in time. So one way to "compress" the audio, so it takes up less space, is to record just the changes -- for each sample, record how much change it is from the previous sample. So the above looks like 12000, +2, +4, +1, +3, -5, +1. These change numbers tend to be small, so it turns out they can be recorded more compactly (requiring fewer 0's and 1's). This is nice example of digital compression -- recording the data in a way which takes up less space, but you can still recreate the original signal. In this case, the compression is lossless.

Having translated the audio into the digital domain -- a series of sample numbers -- we open the data up to all sorts of computer manipulations, since computers are cheap and effective at manipulating numbers. MP3 is another example of audio compression. MP3 is complicated, reducing the space required by 10x, and also it is lossy, so it discards little bits of the original signal in a way which the human auditory system tends not to notice.