Episode 1.2 – Analog vs. Digital

Welcome to the Geek Author series on Computer Organization and Design Fundamentals. I’m David Tarnoff, and if you’ve been hanging out with us, you know that I teach Computer Organization, Computer Architecture, Digital Design, and Embedded System Design. If you’re interested in the inner workings of a computer, you’re in the right place. The only background you’ll need for this series is an understanding of integer math. A little experience with a programming language such as Java would be helpful, as we’ll be using some generic code to help describe the theory.

In this episode, we’re going to discuss the differences between analog and digital, the benefits that come along with digitizing our information, and the typical system that might be used to read an analog value into our digital machines.

The real world is analog. What does that mean? Well, an analog value is equivalent to a decimal value with an infinite number of digits to the right of the decimal point. For example, real world temperatures do not take on discrete values such as 75°, 76°, 77°, 78°, and so on. They take values like 75.439535… and on and on and on. In fact, between the temperatures 75.435° and 75.436°, there are an infinite number of possible values. A particular Galapagos penguin doesn’t weigh exactly five and a half pounds. Add an atom, and its weight changes.

The real world is also continuous. A temperature doesn’t simply change from 75° to 76° – it passes through every possible value on its way to 76°. And when I say every possible value, I mean the infinite number of them. Most of us studied continuous functions in high school algebra, right? When values such as temperature or weight change over time, they follow what is called a continuous curve. Between any two values on the curve, an infinite number of values take place over an infinite number of points in time.

Okay, so these are ridiculous examples. We can get by without knowing the weight of a penguin plus or minus an atom. Heck, if we measured to that level of accuracy, its weight could be changing every second. (By the way, time is also an analog value.) It is sufficient to say that analog values represent a continuous signal with infinitesimal resolution.

Computers have a terrible time with infinite. Everything about the processes of a computer is finite. Oh, you may think that a terabyte of memory is a lot, but it’s just an infinitesimal drop in the bucket compared to infinite. Furthermore, the closer we get to processing infinite, the slower our computer gets. We simply need to have enough information to do what is needed. For example, does the thermostat controlling the air conditioning in our office need to measure temperature to the millionth decimal place? Probably not. A tenth of a degree if that should be sufficient.

There is such a thing as an analog computer, a computer that processes information using analog levels of electricity or the analog positions of a mechanical device in order to generate an analog result. These machines are capable of doing all manner of mathematical operations ranging from simple addition to complex integrals. The overwhelming majority of today’s machines do not do this, however. Instead, they represent an analog value by first capturing it, and then converting it to a number with a fixed resolution, in other words, a fixed number of digits to the right of the decimal point. This measurement, often referred to as a sample, is stored as a digital value. If the value is changing with respect to time, then a sequence of these samples can be captured, converted, and stored. Typically, the rate at which these samples are taken remains fixed and is referred to as the sampling rate.

So when a computer wants to record an analog value over time such as a sound wave, it stores the series of samples to memory in the order that they were captured. To play the sound back, the computer generates a outputs corresponding to each of the sample values in order and at the same rate as they were sampled. The accuracy needed in both time and magnitude depends on the what the samples are being used for, which in the case of sound would be the capabilities of the human ear. More accuracy than that would be wasted, unless of course we were recording for dogs.

There are potential problems with this process. First, it is possible to lose information between the samples. If the analog input is changing faster than the sampling rate can capture, details of the signal could be missed. As an example, if the sampling rate of a sound wave is too slow, the playback may sound muffled. This is why the audio of a phone call doesn’t sound quite as good as the audio from a downloaded song – the phone conversation has been sampled at a slower rate.

Second, if the computer does not record each sample with enough accuracy, sometimes referred to as bit depth, an inaccuracy may exist between the original value and the recorded value. The rounding error from a bit depth that is too low will add a noise called quantization noise. In the case of audio, this quantization noise may range anywhere from an added hiss to a harsher distortion of the signal.

There is actually a third issue that needs to be addressed when it comes to sampling a signal. Frequencies that are too high to be captured by the sampling rate will actually appear in the recorded samples as lower, unwanted frequencies. This is called aliasing. Have you ever watched the wheel of fast moving car under the street lights at night. Sometimes it looks like the wheel is either moving much slower or looks like it has stopped or is going backwards. This is because the “flicker” of the street lights are sampling the car’s wheel for you. The flicker is happening fast enough that you cannot detect it, but too slow to give you an accurate view of the wheel’s rotation. That, by the way, is why it’s a bad idea to use fluorescent lights in a saw mill – it could make the blades look like they’re standing still.

There are ways to reduce the effects described here. For example, to capture more frequencies in an audio signal and make it sound clearer, the sampling rate can be increased. The effects of quantization can be reduced by increasing the bit-depth, i.e., the accuracy of our measurements. Aliasing can be reduced by filtering out any frequencies that are faster than we can capture with our sampling rate. We will be going into more detail on these topics in the Chapter 2 section titled, “Sampling Theory.”

Now that we’ve covered the problems with digitizing analog information, let’s talk about the benefits.

Back in the old days, before digital telephone networks and well before caller ID, the moment you answered the phone, you could tell whether the caller was local or long distance. The further away the caller was, the more background static or “hiss” was present on the line. This was due to the circuitry necessary to combat a phenomenon known as “attenuation”. Attenuation is the reduction of the strength of a signal, in this case an electrical signal, due to conditions such as distance or time.

As the electrical signal carrying the caller’s voice traveled along the conductor, it would lose its strength and have to be amplified in order to continue its journey. The problem is that the electrical wire also acted as an antenna picking up both natural and artificial electro-magnetic waves in the air surrounding it. These waves would create an electrical current which was then added to the original signal. This somewhat random additional signal is referred to as noise, and in an audio signal, typically sounds like a soft hiss. Noise can also occur inside the conductor itself due to the intrinsic motion of electrons.

Each time the signal had to be amplified, the noise that had attached itself to the signal was amplified along with it. The longer the signal traveled, the more noise it picked up and the more times that noise was amplified until…

“I’m going to have to call you back. This line is terrible.”

Noise cannot attach itself to a digital signal. Once an analog signal has been converted to a sequence of numbers, the signal’s characteristics remain unchanged as long as the numbers themselves don’t change. Therefore, digital systems such as the contemporary long-distance phone system do not suffer from degradation over long distances.

A second benefit is that once a signal is turned into a sequence of numbers, mathematical algorithms can be used to operate on the data.

As an example, who doesn’t dislike the sound of their own voice? Chances are that unless you’re Jeremy Irons or Beyoncé, you winced the first time you heard audio of yourself. (And even Jeremy and Beyoncé might have had their doubts.) But you can change that. Using mathematical algorithms, you can modify the frequencies of your voice to boost the highs or boost the lows. Other mathematical algorithms can be used to identify the unique frequencies of your voice for identification. Disciplines such as Digital Signal Processing (DSP) and the study of wavelets allow for much more accurate processing of signals than analog systems were ever able to achieve.

A sequence of digital numbers can also be stored more compactly than an analog signal. The data compression behind file formats such as MP3 is not possible with analog technology. Digital storage also allows for supplementary data to be stored along with the samples to provide things such as digital watermarking for security or codes for error checking or error correction.

Digital data is also more accurately copied and distributed. Gone are the days when music was passed from one friend to another through the use of a dual cassette deck where one deck was used for playback while the other copied the audio. With each duplication, the recording would become more muted and filled with noise until it was finally unuseable. Like our phone example, digital copies are as accurate as the original as long as the numbers don’t change.

Additional hardware is needed to sample and store an analog signal. Details of such a system are beyond the scope of this series, but the process is quite straightforward. First, you need a sensor of some sort to convert the environmental condition such as a temperature, weight, or sound wave, into an electrical signal readable by analog electronics. Often, this signal is weak and easily distorted by noise, so the second stage is to clean and amplify it. Once the signal is strong enough, it is sent to a device called an Analog-to-Digital Converter, or ADC. The ADC is what converts the strength of the electrical signal to a numeric value.

Now that we know how important digital signals are, it’s time to start examining them. In our next episode, we will start defining some of the terminology we use when it comes to the representation of digital signals. Until then remember that while the scope of what makes a computer is immense, it’s all just ones and zeros.