Sampling and Quantization of Signals
Sampling and Quantization of Signals
Activity #4
Sampling and Quantization
Introduction:
In this lab you will investigate the influence of the sampling rate and the number of quantization levels on
the quality of digitized sound.
The sampling rate standard for audio CD is 44,100 samples per second so the highest frequency that can be
sampled without aliasing, 22,050 Hz, is above the audible range of frequencies.Also, the standard of 16- ‐bit
quantization yields quantization noise below the threshold of hearing. Thus any ill effects of the limited
sampling rate and finite number of quantization levels are largely inaudible to humans. In this lab you will use
a digital recording and manipulation program (Audacity) and Matlab on the PC audio workstations. Audacity
will enable you to record and save digital audio as a ".wav "file as well as to convert the sampling rate.
Audacity does not have much flexibility for converting the number of quantization levels so we will use a
furnished Matlab file “Quantlevels.m” for this purpose. Sample rate manipulation is just the "tip of the
iceberg" of the capabilities of Audacity and this lab serves as a simple introduction to using this program.
Set up a microphone and use Audacity to record a few seconds of speech at 44,100 Hz and 16 bits, which are
the default settings for Audacity. To obtain the highest quality recording adjust the recording level to achieve
nearly full-‐scale for the loudest part of the recording; avoid overloads and distortion. You may also use any of
the prerecorded sounds on the computer for the remainder of the laboratory.
2. Sampling rate
After you record a short sound file you may use Audacity to change the sampling rate. This may be
accomplished by going to the “Project Rate” area in the lower left hand corner of the project window. You are
shown a pop up menu in which you may choose among fixed sample rate options or you can type in any
sample rate value you want.
Make sure that you start with sound files that are in 44.1kHz -‐ 16 bit format.
Convert your files to 22,050 kHz, 11 kHz, 5.5 kHz, 2 kHz, and 1 kHz and comment on the audible
artifacts of reducing the sampling rate.
Answer 4.2:_____________________________________________________________
In this part of the lab you can use the furnished Matlab program below ‘Quantlevels.m’ to manipulate the
number of quantization levels of an audio file (as determined by the number of bits). Here are the first few
lines of that program.
1
% M-file to convert number of quantization levels of a wav file
clear
close all
Nsec = 3; % Number of seconds of the sound file to process
bits = 12; % Number of bits for requantization
[x,R, nbits] = wavread('dsp.wav'); % Read in wave file, use any file you like
The number of quantization levels may be adjusted by changing the value of ‘bits’. On the following line put
in the name of the wav file that you want to manipulate, dsp.wav is a guitar recording. This is a good
recording with which to experiment because there are many “quiet” intervals between the notes. Also
experiment with your recording of yourself speaking. Reduce the number of bits by 1 or 2 bit increments all
the way down to 1-‐bit.
For both recorded speech and the music files -‐ at what bit resolution do the quantization effects
become audible? Describe the audible effects inboth the spoken and music files at the different bit- ‐
resolution levels. Can you still recognize the sound at 4-‐bit and 2-‐bit (even 1-‐bit) quantization?
Answer 4.3:_____________________________________________________________
In the final part of this lab you will investigate the maximum extent that you can compress a speech sound file
and maintain its intelligibility. Note that the total size (number of bytes) of a sound file is determined by the
sampling rate AND the bit resolution. Determine the tradeoff of sampling rate and bit resolution that best
maintains intelligibility, i.e., is it better to use a high sample rate and small number of bits or a low sample rate
and a greater number of bits. What isthe greatest data compression factor compared to 44,100 Hz 16-‐
bit sound that you can achieve?
Answer 4.4:_____________________________________________________________
Write-‐up
Your write-‐up should answer all questions in red bold posed above and well as to furnish qualitative
descriptions of what you heard in the various tests.
Listing of Quantlevels.m
% M-file to convert number of quantization levels of a wav file
clear
close all
subplot(211)
plot(x(start:stop), 'k.')
hold on
plot(x(start:stop),'r')
axis([0 len -2^(nbits-1) 2^(nbits-1)])
grid on
title('Original audio')
xlabel('Sample Number')
ylabel('Level')
subplot(212)
plot(xq(start:stop), 'k.')
hold on
plot(xq(start:stop))
axis([0 len -2^(bits-1) 2^(bits-1)])
grid on
title('Re-quantized audio')
xlabel('Sample Number')
ylabel('Level')