Sound


A Magic Trick

There's nothing up by sleeves, nothing in my head ...

Goal

By the end of today, you should:

  1. understand differences between analog and digital signals

  2. understand sampling rate, bit resolution, bit rate and calculating file size

  3. think about the basics of Copyright law

Analog and Digital

Our ears interact with an analog world of sound waves, but music and other sounds are all being done digitally now. Why? How?

  • Analog signals always degrade with time, distance and other factors.
  • With an analog signal, you can't be entirely sure of what the original sound was supposed to be out of the literally infinite number of possibilities.
  • Digital signals are only transmitting one of two possible values (zero and one). Each is a bit.
  • Therefore, when the receiver gets a degraded signal, it can make an informed guess about which of the two possibilities was actually transmitted. This allows the signal to be cleaned-up.

Quiz Question Nr. 1

Sound travels faster in:

  1. vacuum

  2. water

  3. air

  4. speed doesn't depend on the medium

Quiz Question Nr. 2

A little yappy dog's barking is:

  1. Low amplitude, low pitch

  2. Low amplitude, high pitch

  3. High amplitude, low pitch

  4. High amplitude, high pitch

Quiz Question Nr. 3

Analog signals are superior to digital signals.

  1. True

  2. False

  3. There is no difference between the two.

Parity bits

Furthermore, by adding redundant information in the form of parity bits, errors can be detected. By using additional parity bits, the receiver can figure out which bit is erroneous and, since there are only two possible values, errors can be corrected. Thus, it is possible, using digital representations, to have perfect transmission.

Quiz Question Nr. 3b

Digital signals are superior to analog because

  1. Errors can be avoided

  2. Errors can be detected

  3. Errors can be corrected

  4. Signals can be compressed

Quiz Question Nr. 4

When will the parity bit NOT be able to detect an error:

  1. When there is an odd number of bits in the transmission.

  2. When there is an even number of bits in the transmission.

  3. When the number of changed bits is even.

  4. When the number of changed bits is odd.

Quiz Question Nr. 5

Assume that the even parity bit indicates that there has been an error in transmission, what is our best option?

  1. There is nothing we can do about it, noise is part of every transmission.

  2. We can use the parity bit to identify the error and fix it.

  3. We can use error correction algorithms to reconstruct the original signal.

  4. We will have to request for the signal to be retransmitted.

Limitations in Hearing

Test yourself with this Online tone generator or this hearing test.

Digital Sound Representation

Have I convinced you? Good. So, how do we do it? How do we represent sound digitally?

  • Imagine drawing the analog signal on graph paper. Make two crucial decisions:
    • The resolution on the vertical axis, and
    • the resolution on the horizonal axis.
  • Sample the analog signal at each vertical line (each moment in time), rounding it off at the nearest horizontal line. Write this down as a number.
  • The sequence of numbers is then the digitized signal.
  • The resolution of the vertical axis (how close together the horizontal lines are) determines the number of bits per sample. Usually, this is some nice round number like 8, 16 or 32 bits per sample.
  • The resolution of the horizontal axis (how close together the vertical lines are) determines the sampling rate.
  • The product of these two gives the bit-rate.
  • The greater the bit rate, the better the receiver can reconstruct the original signal.
  • The Nyquist theorem tells us how high the sampling rate has to be in order to capture sounds up to a given maximum frequency (pitch).

Quiz Question Nr. 6

The bit resolution is:

  1. The sampling rate.

  2. A multiple of the fundamental frequency.

  3. The number of bits to represent frequency values.

  4. The number of bits to represent amplitude values.

Quiz Question Nr. 7

If the whales can produce sound in the range 10 Hz - 30 KHz, at what frequency we would have to sample to produce a digital recording?

  1. 15 KHz

  2. 20 KHz

  3. 30 KHz

  4. 45 Khz

  5. 60 KHz

Task 1: File Size by Hand

Compute the bit rate in bits per second and the approximate file size in KB given the following information:

  • Pitches up to 50KHz
  • 16 bit resolution
  • 10 seconds of sound

You might get the following:

Sampling rate is 100 KHz (double)

Bit rate is 100,000 * 16 bits or 1,600,000 bits per second

File size is 10 * 1,600,000 / (8 * 1000) = 10 * 200 = 2000 KB

Task 2: File Size by JS

Knowing that the bit rate is the number of bits to represent one second of digital sound, write jQuery/Javascript code that will perform the calculations for the form shown below.

The statements for reading the content from the fields is already given, you need to write two functions that take paremeters and return values and invoke them. Read comments in the execution box.

<form>
<p>Bit Resolution: <input name="resolution"></p>
<p>Sampling Rate: <input name="sampling"></p>
<p>Time (in seconds): <input name="seconds"></p>
<p>The Bit Rate is: <span id="bitrate"></span></p>
<p>The File Size is: <span id="filesize"></span></p>
</form>

Bit Resolution (in bits):

Sampling Rate (in Hz):

Time (in seconds):

The Bit Rate is: bits/second.

The File Size is: KB.

Your solution might look like this:

function calculate_bitrate(bRes, sRate){
  return bRes * sRate;
}
$("#bitrate").text(calculate_bitrate(bitRes, sampling));

function calculate_filesize(bRes, sRate, seconds){
  var bitrate = calculate_bitrate(bRes, sRate);
  return bitrate * seconds / (8*1000); // convert in KB
}
$("#filesize").text(calculate_filesize(bitRes, sampling, seconds));

Summary

We hope that after these activities you can:

  • understand digital signals and how they are transmitted
  • sampling for conversion between analog and digital signals
  • think of copyright law and fair use

Solutions

Will be posted later, visit again after .

© Wellesley College Computer Science Staff. This work is licensed under a Creative Commons License. Date Modified: Friday, 29-Apr-2016 09:18:08 EDT