# Fundamentals of data representation: Sampled sound

 ← 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 Converter convert a continuous sound wave into discrete digital data? To do this we need to look at how computers sample sound.

## Sampling rate

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     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,000 Hz (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,000 Hz. 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

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

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,000 Hz 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,000 Hz 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,000 Hz Why might a song recorded with the following settings: ```Sample Rate = 22,000 Hz 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 Sample the sound wave below and convert it into binary form: 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