Analog and Digital (2024)

Signals

When sound is transmitted or stored it may need tochange form, hopefully without being destroyed.

Analog and Digital (1)

Sound moves fast: in air, at 340 m/sec = 750 miles per hour. Its twoimportant characteristics are Frequency (aka pitch) andAmplitude (aka loudness). Frequency is measured in Hz orcycles per second. Humans can hear frequencies between 20 Hz and 20,000Hz (20 KHz). Amplitude is measured in deciBels (we will see later that itis approximated with "bit-resolution").

Consider music:

  1. Sound is simply pressure waves in air, caused by drums, guitar strings or vocal cords
  2. Converted to electrical signals by a microphone
  3. Converted to magnetism when it's put on a master tape and edited
  4. Converted to spots on a CD when the CD is manufactured
  5. Converted to laser light, then electricity when played by a CD player
  6. Converted back to sound by a speaker

A similar kind of story can be told about visual images(sequences of static images) stored on videotape or DVD and played on your home VCR or DVD player.

Degradation

Any time signals are transmitted, there will be some degrading of quality:

  1. signals may fade with time and distance
  2. signals may get combined with interference from other sources (static)
  3. signals may be chopped up or lost

When we continue to transmit and transform signals, the effect is compounded. Think of the children's game of "telephone." Or think about photocopies of photocopies of photocopies...

Example

This is the transmitted signal:

Analog and Digital (2)

and this is the received signal (dashed) compared to the transmittedsignal:

Analog and Digital (3)

The horizontal axis here is time. The vertical axis is some physicalproperty of the signal, such as electrical voltage, pressure of a soundwave, or intensity of light.

The degradation may not be immediately obvious, but there is a generallessening of strength and there is some noise added near the secondpeak.

There doesn't have to be much degradation for it to have a noticeableand unpleasant cumulative effect!

Analog Signals

The pictures we saw above are examples of analog signals:

An analog signal varies some physical property, such asvoltage, in proportion to the information that we are trying totransmit.

Examples of analog technology:

  1. photocopiers
  2. old land-line telephones
  3. audio tapes
  4. old televisions (intensity and color information per scan line)
  5. VCRs (same as TV)

Analog technology always suffers from degradation when copied.

Digital Signals

With a digital signal, we are using an analog signal to transmit numbers, which we convert into bits and then transmit thebits.

A digital signal uses some physical property, such as voltage,to transmit a single bit of information.

Suppose we want to transmit the number 6. In binary, that number is110. We first decide that, say, "high" means a 1 and "low" means a0. Thus, 6 might look like:

Analog and Digital (4)

The heavy black line is the signal, which rises to the maximum toindicate a 1 and falls to the minimum to indicate a 0.

Degradation and Restoration of Digital Signals

The signals used to transmit bits degrade, too, because any physicalprocess degrades. However, and this is the really cool part, thedegraded signal can be "cleaned up," because we know that each bit iseither 0 or 1. Thus, the previous signal might be degraded to thefollowing:

Analog and Digital (5)

Despite the general erosion of the signal, we can still figure outwhich are the 0s and which are the 1s, and restore it to:

Analog and Digital (6)

This restoration isn't possible with analog signals, because withanalog there aren't just two possibilities. Compare a photocopy of aphotocopy ... with a copy of a copy of a copy of a computer file. Thecomputer files are (very probably) perfect copies of the originalfile.

The actual implementation of digital transmission is somewhat morecomplex than this, but the general technique is the same: two signals thatare easily distinguishable even when they are degraded.

Error Detection

Suppose we have a really bad bit of static, so a 1 turns into a 0 orvice versa. Then what? We can detect errors by transmitting someadditional, redundant information. Usually, we transmit a "parity" bit:this is an extra bit that is 1 if the original binary data has an oddnumber of 1s. Therefore, the transmitted bytes always have an even numberof 1s. This is called "even" parity. (There's also "odd" parity.)

How does this help? If the receiver gets a byte with an odd number of1s, there must have been an error, so we ask for a re-transmission. Thus,we can detect errors in transmission.

You can see some examples of parity using the following form. Theparity bit is the last (rightmost) one.

Exercise on Parity

Assuming even parity, what is the parity bit for each of the following:

  1. 000010112 1, because there are 3 ones in the number
  2. 010010112 0, because there are 4 ones in the number
  3. 2316 1, because there are 3 ones total in the number (convert it from hex to binary)
  4. FF16 0, because there are 8 ones total in the number (convert it from hex to binary)
  5. DEADBEEF16 0, because the ones 33233334, for a total of 24, which is even

Error Correction

With some additional mathematical tricks, we can not only detect that abit is wrong, but which bit is wrong, which means we cancorrect the value. Thus, we don't even have to ask forre-transmission, we can just fix the problem and go on.

Try it with the following JavaScript form. Type in a number, and it willtell you the binary code to transmit. Then, take the bits and add anysingle-bit error you want. (In other words, change any 1 to 0 or any 0 to1.) If you click on "receive," it will tell you which bit is wrong andcorrect it. If you think I'm cheating, you can type the bits into anotherbrowser!

Note: for technical reasons, the parity bits are interspersed with thedata bits. In our example, the parity bits are bits 1, 2, 4 and 8,numbering from the left starting at 1. (Notice that those bit positionnumbers are all powers of two.) So, that means the seven data bits arebits 3, 5, 6, 7, 9, 10, and 11.

Exercise on Error Correction

  • Type in a number and click on the transmit button
  • Change one of the bits (either a data bit or a parity bit).
  • Click on the receive button.
  • Gasp in amazement that it figures out what bit you modified
  • Repeat

What if more than one bit is wrong? What if a whole burst of errorscomes along? There are mathematical tricks involving larger chunks of bitsto check whether the transmission was correct. If not, re-transmission isoften possible.

Summary of Digital Communication

The main point here is that digital transmission and storage ofinformation offers the possibility of perfect (undegraded)copies, because we are only trying to distinguish 1s from 0s, and becauseof mathematical error checking and error correcting.

Converting Analog to Digital

Analog and Digital (7)If digital is so much better, can we use digital for music and pictures?Of course! To do that, we must convert analog to digital, which is done bysampling.

Sampling measures the analog signal at different moments in time,recording the physical property of the signal (such as voltage) as anumber. We then transmit the stream of numbers. Here's how wemight sample the analog signal we saw earlier:

Analog and Digital (8)

Reading off the vertical scale on the left, we would transmit thenumbers 0, 5, 3, 3, -4, ... (The number of bits we need to represent thesenumbers is the so-called bit-resoluton. In some sense it is the soundequivalent to images' bit-depth.)

Converting Digital to Analog

Of course, at the other end of the process, we have to convert back toanalog, also called "reconstructing" the signal. This is essentially doneby drawing a curve through the points. In the following picture, thereconstructed curve is dashed

Analog and Digital (9)

In the example, you can see that the first part of the curve is fine,but there are some mistakes in the later parts.

The solution to this has two parts:

  1. the vertical axis must be fine enough resolution, so that we don't have to round off by too much, and
  2. the horizontal axis must be fine enough, so that we sample often enough.

In the example above, it's clear that we didn't sample often enough toget the detail in the intervals. If we double it, we get the following,which is much better.

Analog and Digital (10)

In general, finer resolution (bits on the vertical axis) and fastersampling, gets you better quality (reproduction of the original signal)but the size of the file increases accordingly.

The Nyquist Sampling Theorem

How often must we sample? The answer is actually known, and it's calledthe Nyquist Sampling Theorem (first articulated by Nyquist and laterproven by Shannon). Roughly, the theorem says:

Sample twice as often as the highest frequency you want tocapture.

For example, the highest sound frequency that most people canhear is about 20 KHz (20,000 cycles per second), with some sharp ears ableto hear up to 22 KHz. (Test yourself with this hearing test.)So we can capture music by sampling at 44 KHz (44,000 times per second). That's how fast music is sampled for CD-quality music (actually, 44.1 KHz).

Exercise on the Nyquist Theorem

  1. If the highest frequency you want to capture is middle C on the piano, at what frequency do you have to sample? 2*261.626 Hz
  2. If you want to record piano music (the highest key on a piano is C8, at what frequency do you have to sample? 2*4186 Hz
  3. If you want to record Whale sounds, at what frequency do you have to sample? 2*10,000, or 20KHz
  4. If you want to record sounds that bats can hear, at what frequency do you have to sample? 2*100,000 Hz, or 200 KHz

File Size

The size of an uncompressed audio file depends on the number of bitsper second, called the bit rate and the length of the sound (inseconds).

We've seen that there are two important contributions to the bit rate, namely:

  • sampling rate (horizontal axis), and
  • bit resolution (vertical axis)

As the sampling rate is doubled, say from 11KHz to 22KHz to 44KHz, thefile size doubles each time. Similarly, doubling the bit resolution, sayfrom 8 bits to 16 bits doubles the file size.

As we've seen, the sampling rate for CD-quality music is 44KHz. Thebit-resolution of CD-quality music is 16: that is, 16-bit numbers are usedon the vertical axis, giving us 216=65,536 distinct levels fromlowest to highest. Using this, we can actually calculate the bit rate andthe file size:

bit rate (bits per second) = bit-resolution * sampling rate

file size (in bits) = bit rate * recording time

For example, how many bits is 1 second of monophonic CD music?

16 bits per sample * 44000 samples per second * 1 second = 704,000
Therefore, 704,000 / 8 bits per byte = 88,000 bytes ≈ 88 KB

That's 88 KB for one second of music! (Note that there are 1000 bytesin 1KB, so 88000/1000 is 88KB.)

Channels

And that's not even stereo music! To get stereo, you have to addanother 88KB for the second channel for a total bit-rate of176KB/second.

An hour of CD-quality stereo music would be:

176 KB/sec * 3600 seconds/hour = 633,600 KB ≈ 634 MB

634 MB is about the size of a CD. In fact, it is not accidental that aCD can hold about 1 hour of music; it was designed that way.

Exercise on Bit Rate and File Size

  1. If you record an hour of piano music (the highest key on a piano is C8) in mono at 16 bits, what is the bit rate and file size? bit-rate is 16*2*4186, and file size is bit-rate*3600
  2. If you record an hour of bat-audible sounds in stereo at 32 bits, what is the bit-rate and file size? bit-rate is 32*2*2*100,000, and file size is bit-rate*3600

Exercise with Form for Bit-Rate and File Size

Consider the following form to compute bit-rate and file size. Fill in the missing function definitions.

Choices

What are the practical implications of various choices of sampling rateand bit-resolution?

  • If you're recording full-quality music, you'd want to use the 44 KHzand 16-bit choices that we've done some calculations with.Check out this comparisonof a sound clip at various resolutions and sampling rates.
  • If you're recording speech in your native tongue (when yourbrain can fill in lots of missing information), you can cut many corners.Even a high-pitched woman's voice will not have the high frequencies of apiccolo, so you can probably reduce the numbers to 11KHz and 8-bit.Furthermore, you will only need one channel (monophonic sound) not twochannels (stereo). Thus, you've already saved yourself a factor of 16 inbit-rate.
  • Speech in a foreign language is harder to understand, so itmight make sense to use 22KHz and 16-bit resolution. Of course, you wouldstill use one channel not two. This is still a factor a 4 decrease in thebit-rate.
  • Music before about 1956 wasn't recorded in stereo, so you would onlyneed one channel for that.

Compression

Bandwidth over the internet cannot compete with the playback speed of aCD. Think of how long it would take for that to be downloaded over a slowmodem.

So, is it impossible to have sound and movies on your web pages? No,thanks to sound compression techniques. We have seen how GIF and JPGmanage to compress images to a fraction of what they would otherwiserequire. In the case of sound and video, we have some very powerfulcompression file formats suchas Quicktime, AVI,RealAudio and MP3. Read more aboutthe historyof MP3 (or history of MP3).

The tradeoffs among different compression formats and differentbit rates are explained well in this article on audio formats from the New York Times. (This article isavailable only on-campus or with a password.)

A discussion of the technology behind these compression schemes isbeyond the scope of this course. They are similar in spirit to the JPEGcompression algorithm, in that they are lossy compressionschemes. That is, they discard bits, but hopefully the bits that leastdegrade the quality of the music?

Some compression algorithms take advantage of the similarity betweentwo channels of stereo, so adding a second channel might only add 20-30%.

What do you think?

Discussion Topics

  1. Modems
  2. Does vinyl sound better than CD? (see this and this)
  3. CD versus MP3
  4. DVD audio representation that samples at 192 Khz with 24 bits per sample (see this Wikipedia description, this page, and this debunking)
  5. Digital TV
  6. Digital cell phones

Summary

  • Music, video, voice, pictures, data and so forth are all examples of signals to be transmitted and stored.
  • Signals inevitably degrade when transmitted or stored.
  • With analog signals, there's no way to tell whether the received signal is accurate or not, or how it has been degraded.
  • With digital signals, we can, at least in principle, restore the original signal and thereby attain perfect transmission and storage of information.
  • We can convert analog signals to digital signals by sampling.
  • We can convert digital signals back to analog signals by reconstructing the original signal. If the original sampling was good enough, the reconstruction can be essentially perfect.
  • Wellesley's LTS has a nice page on digital audio

A condensed version of these notes can be found here.

Further Information and Examples

Note that beyond here is information that we think you might findinteresting and useful, but which you will not be responsible for. It'sfor the intellectually curious student.

How Hamming Codes work

The error correcting code we saw above may seem a bit magical. And, indeed, the algorithm is pretty clever. But once you see it work, it becomes somewhat mechanical.

Here's the basic idea of this error-correcting code. (This particular code is a Hamming code. The Hamming (7,4) code sends 7 bits, 4 of which are data. The (7,4) code is easy to visualize using Venn diagrams. The general idea is this:

  • If we have 11 bit positions total, number them from left to right as 1-11.
  • Write down the 11 numbers for the bit positions in binary. For example, position 5 (which is a data bit, since 5 is not a power of 2) is expressed as 0101.
  • The bits that are "true" in the binary number expressing the position define which parity bits check that position. For example, position 5 (0101) is checked by the parity bit at position 1 and the one at position 4.
  • The positions of the parity bits that are "wrong" add up to the position of the wrong bit. So if the parity bits at positions 1 and 4 are wrong, that means bit 5 is the one that is wrong.

For more detail, see this general algorithm

Solution to Exercise with Form for Bit-Rate and File Size

Solution to the Exercise with Form for Bit-Rate and File Size is here.

[an error occurred while processing this directive]
Analog and Digital (2024)
Top Articles
Latest Posts
Article information

Author: Carmelo Roob

Last Updated:

Views: 6100

Rating: 4.4 / 5 (65 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Carmelo Roob

Birthday: 1995-01-09

Address: Apt. 915 481 Sipes Cliff, New Gonzalobury, CO 80176

Phone: +6773780339780

Job: Sales Executive

Hobby: Gaming, Jogging, Rugby, Video gaming, Handball, Ice skating, Web surfing

Introduction: My name is Carmelo Roob, I am a modern, handsome, delightful, comfortable, attractive, vast, good person who loves writing and wants to share my knowledge and understanding with you.