Fundamentals of Data Representation: Sampled sound

From Wikibooks, open books for an open world
Jump to: navigation, search

UNIT 1 - ⇑ Fundamentals of Data Representation ⇑

← Analogue and digital Sampled sound Sound compression →


So we should know by now that sound waves are continuous and computers can only store discrete data. How exactly does an Analogue to Digital Convert convert a continuous sound wave into discrete digital data? To do this we need to look at how computers sample sound.

Sampling rate[edit]

Sampling Rate - The number of samples taken per second


Hertz (Hz) - the SI unit of frequency defined as the number of cycles per second of a periodic phenomenon


To create digital music that sounds close to the real thing you need to look at the analogue sound waves and try to represent them digitally. This requires you to try to replicate the analogue (and continuous) waves as discrete values. The first step in doing this is deciding how often you should sample the sound wave, if you do it too little, the sample stored on a computer will sound very distant from the one being recorded. Sample too often and sound stored will resemble that being recorded but having to store each of the samples means you'll get very large file sizes. To decide how often you are going to sample the analogue signal is called the sampling rate. Take a look at the following example:

Original Sound High sample rate 1/2 high sample rate 1/3 high sample rate 1/4 high sample rate
CPT-Sound-SamplingRate.svg CPT-Sound-SamplingRate-1.svg CPT-Sound-SamplingRate-2.svg CPT-Sound-SamplingRate-3.svg CPT-Sound-SamplingRate-4.svg
original continuous sound wave digital looks like original digital loses sharpness loss of peaks poor resemblance to original!

To create digital sound as close to the real thing as possible you need to take as many samples per second as you can. When recording MP3s you'll normally use a sampling rate between 32,000, 44,100 and 48,000Hz (samples per second). That means that for a sampling rate of 44,100, sound waves will have been sampled 44,100 times per second! Recording the human voice requires a lower sampling rate, around 8,000Hz. If you speak to someone on the phone it may sound perfectly acceptable, but try playing music down a telephone wire and see how bad it sounds.

Comparison of the same sound sample recorded at 8kHz, 22kHz and 44kHz sample rate. Note the spacing of the data points for each sample. The higher the sample rate the more data points we'll need to store

Sampling resolution[edit]

Sampling resolution - the number of bits assigned to each sample


As you saw earlier, different sounds can have different volumes. The sampling resolution allows you to set the range of volumes storable for each sample. If you have a low sampling resolution then the range of volumes will be very limited, if you have a high sampling resolution then the file size may become unfeasible. The sampling resolution for a CD is 16 bits used per sample.

File sizes[edit]

Bit rate - the number of bits required to store 1 second of sound


To work out the size of a sound sample requires the following equation:

File Size = Sample Rate * Sample Resolution * Length of sound

This is the same as saying:

File Size = Bit Rate * Length of sound

Let's look at an example:

Example: Sound File Sizes

If you wanted to record a 30 second voice message on your mobile phone you would use the following:

Sample Rate = 8,000Hz
Sample Resolution = 16 bit
Length of Sound = 30 seconds

Therefore the total file size would be:

8,000 * 16 * 30 = 3 840 000 Bits = 480 000 Bytes
Extension: Sound Editing

If you are interested in sound editing you can start editing your own music using a program called Audacity. Using Audacity you can create your own sound samples with different sample rates and sample resolutions, listening to the difference between them and noting the different file sizes. Check out the following sound files recorded at different sampling rates:

Exercise: Sampled sound
Why might a digital representation of a sound struggle to be a perfect representation?

Answer :

A sound wave is continuous data, whilst digital data is discrete and the representation is an approximation of the original
Why might you choose to have a lower sampling rate than a higher one for storing a song on your computer?

Answer :

The higher the sampling rate the more data is needed to be stored, meaning the larger the file size.
What is the sampling resolution?

Answer :

the number of bits assigned to each sample, effecting the range of volumes that can be stored in a sample
What is the equation to work out the bit rate of a song

Answer :

Sampling Rate * Sampling Resolution
For the following sound sample work out its size:
Sample Rate = 16,000Hz
Sample Resolution = 8 bit
Length of Sound = 10 seconds

Answer :

16,000 * 8 * 10 = 1 280 000 Bits

Work out the sample rate of the following sound file:
Sound File = 100,000 bits
Sample Resolution = 10 bit
Length of Sound = 5 seconds

Answer :

100,000 / (10 * 5) = 2,000Hz

Why might a song recorded with the following settings:
Sample Rate = 22,000Hz
Sample Resolution = 16 bit
Length of Sound = 10 seconds

have a file size of 7,040,000 bits?

Answer :

The file might be recorded in stereo, meaning twice the amount of data would have to be stored

Using the grid below, plot the following sample points for a sample resolution of 3 bits per sample: 000001100101100011100110111101
CPT-sound-grid.svg

Answer :

CPT-sound-grid2.svg

Sample the sound wave below and convert it into binary form:

CPT-sound-grid3.svg

Answer :

101 101 101 011 001 000 001 001 100 100
Notice that you must approximate samples where the sample resolution doesn't allow for the needed level of detail