Analog and Digital

< CS101

The words analog and digital are used a lot, but what do they mean? Here we'll look at those two worlds which you use every day.

Analog

A signal is a varying wave, typically carrying information we care about. Sound is a great example of a signal, and we'll use that as a running example today.

Signal varying over time

How Does Sound Work?


Violin sound waves, to air, then to eardrum

Sound is vibrations in the air over time -- essentially small changes in air pressure over time. When a violin plays, the wood top and back of the instrument flex in and out, producing little ripples of air pressure which flow out from the violin, like ripples in a pond. When the ripples hit an ear drum, it vibrates back and forth with the pressure changes, translating them into something your brain can sense. Your brain can easily distinguish the sound of a violin or voice or pipe organ playing the same note, but it is hard to put the differences into words. This is a very analog sequence -- the signal goes from one medium to the next, keeping its basic shape.

Oscilloscope

An oscilloscope really embodies the idea of analog. An oscilloscope connects to wires, looks at the electrical signal varying over time, and draws that signal on its screen in real time. Voltage is on the vertical axis, and time is the horizontal axis. So the oscilloscope takes in something pretty abstract -- signal varying over time -- and makes it visual.

oscilloscope draws electrical signal

Sound Demo -- Synthesizer and Oscilloscope

For this demo, I have a music synthesizer hooked up to speakers, and also hooked up to an oscilloscope so we can see the signal at the same time that we hear it. Demo: musical synthesizer, oscilloscope, notes, frequency, amplitude, timbre.

Frequency, Amplitude, Timbre

Below are oscilloscope screenshots for various notes. The width of the oscilloscope screen here is 1/100th of a second. The little random jags are just random noise from the cheesy, duct-tape way I wired this all together. The horizontal green line in the screenshots is an unimportant artifact of the oscilloscope. It represents a height value for which the oscilloscope tries to freeze the wave, hitting the y axis right at that value.

Low C note, sine wave:
low C note, sine wave

C note, one octave higher (double the cycles per second):
C note, one octave higher (double the cycles)

Same C note as above, but now a flute timbre (shape) instead of sine wave:
Same C note as above, but now a flute timbre

Very often the sound -- or "signal" -- has a repetitive up/down pattern, with the peaks of the curves hitting at a regular interval, such as every 400th of a second. We hear a regular, repeating cycle like this as a musical "note". If the repeating pattern is a mathematically smooth sine wave, we hear it as a very pure, bell-like sound.

Frequency -- suppose a signal repeats 100 times per second, also known as 100 "cycles" per second, that's a frequency of 100. If the signal repeats more rapidly, we hear that as a "higher" note. An "octave" in music corresponds exactly to a doubling in frequency (i.e. twice as many up/down cycles in the same amount of time). The musical tuning standard is that A above middle C on a piano keyboard is 440 cycles per second. Going up to the next higher A note (about one hand's width on the piano) is 880 cycles per second (double the frequency). These two "A" notes sound similar to us, but one is higher. And of course there's next higher A at 1760 cycles, and higher still .. each time doubling the frequency.

Amplitude is the word for the height and depth that the signal makes on each cycle, corresponding to loudness. Big vertical swings are loud, small vertical swings are quiet. Or phrased as air pressure, bigger changes in air pressure sound louder. The timbre of the sound is the fine pattern of shapes and wiggles that can seen on the signal. So a flute "A" note has a timbre, varying a little around the basic 440 cycle pattern, and a trumpet playing that same note has a different timbre on the basic 440 cycle pattern.

There's Just One Air

There is just one body of air that fills a room. All of our ears are in it. A sound (vibrations) in this body of air, travels out to all our ears almost instantaneously at about 1000 feet/second. So what happens when multiple sounds are going into the air at once? The sound signals add, making a "sum" signal. The sum signal goes to your ears, and somehow your ear and brain are able to pull out and hear the component sounds.

Here again is the low-C note:
low C note, sine wave

Here is a high-C note, 3 octaves above the low-C. You can see that the frequency is much higher .. many more cycles per second.
C 3 octaves higher

What happens to the air if the low-C and high-C sounds are playing at the same time? The two signals add together in the air. Here is the combination of low-c and high-c playing simultaneously. You can see how the high note is added on top of the more slow changing low note. Your ear takes in this signal, and pulls it apart so you hear both the low note and the high note. It's impressive that the ear can take in this jumbled signal, and pull out and hear the constituents.
Sum signal of low-c and high-c

As another example, here is low-C and the C note one octave higher:
low C note

What does the sum of the above two look like? To convince yourself of the sum behavior, you can draw the two signals on graph paper, manually measure the heights and do the addition, to verify that the sum indeed looks like this:
Sum of low-C and C one octave higher

Sum Facts

When two musical notes play at frequencies where the peaks and valleys do not match up well .. that sounds like discord -- e.g. one note at 100 cycles per second, and a second note at 101 cycles per second. When the frequencies divide evenly so the peaks and valleys match up perfectly -- e.g. note at 100 cycles plus a note at 200 cycles per second --that's a nice sounding chord.

This "sum" idea is how noise-cancelling headphones work -- detecting the ambient sound and creating an exactly opposite sound to feed into your ear, so they cancel out leaving silence.

Analog Technology

Analog is the pre-digital way of transmitting or storing a signal. Examples:

Analog: Original Phone System

The first telephone was very analog, and in fact the wired phone in your house still works this way (an example of network effect inertia). Follow the trail of the sound signal.


analog phone system

Analog - LP Records

The old LP record format is totally analog. The sound signal is recorded as little hills and valleys in the plastic groove that runs around the record. For playback, a needle sits in the groove, the record spins, and the hills and valleys make tiny up and down movements of the needle. The needle is hooked up, in essence, to a microphone-like device which translates the up-down movement of the needle to an electrical signal, which eventually is sent to the speakers to translate the signal back into sound.

Analog and Noise -- Hiss

Pure signal, e.g. put into one end of the phone
pure signal

Signal + noise as it comes out of the other end of the phone
signal with noise

What do "errors" look like in an analog system? The signal you care about is translated from sound to electricity and so on. With each translation step, little errors creep in. The microphone has a little stiffness, the wires don't carry the signal perfectly, and so on. The errors are called "noise" -- you can imagine the pure sound signal you wanted but it's been distorted by little up/down errors -- like fuzzy variations around the true signal.

This is the "hiss" you hear on the phone line or an AM radio or a cassette tape .. all analog technologies. Why do digital translations of music sound so much better?