ECE140 Lab #2 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. NOTE: If you have an equivalent computer sound recording program on your home computer you may do this lab using your own software. Audacity may be downloaded for free from http://audacity.sourceforge.net/. 1. CD quality Hard Disk recording: 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. The lab TA will show you how to set up the microphone and record if you have difficulty. 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 lab or you may even record a few seconds of sound from an audio CD. 2. Sampling rate After you record (or otherwise obtain) 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. 3. Quantization levels and distortion In this part of the lab you can use the furnished Matlab program ‘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 ECE140 % Lab #2 M-file to convert number of quantization levels of a wav file clear close all Nsec = 3; bits = 12; % Number of seconds of the sound file to process % Number of bits for requantization [x,R, nbits] = wavread('salinas.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, salinas.wav is a guitar recording I posted on the website. 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 in both 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? Construct a table of the Signal to Noise Ratio (in decibels) for bit resolutions from 1 bit to 16 bits. (each additional bit is a 6 dB increase of signal to quantization noise ratio) Keeping in mind that a perceived loudness increase of a factor of two corresponds to approximately 9 dB increase, comment on your perception of the signal to noise ratio at the various bit resolution levels. For example, referring to the table, how many bits of resolution would give a quantization noise that is "twice" as loud as it is at 12 bits? Prepare sound files to check your perception against the table predictions. Keep in mind that this is subjective. 4. Maximum compression and intelligibility of speech 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 is the greatest data compression factor compared to 44,100 Hz 16-­‐bit sound that you can achieve? Write-­‐up Your write-­‐up should answer all questions in bold posed above and well as to furnish qualitative descriptions of what you heard in the various tests. 2 ECE140 Lab #2 Listing of Quantlevels.m (available for download from the ECE140 website) % % M-file to convert number of quantization levels of a wav file MB 9/27/2011 clear close all Nsec = 3; bits = 12; % Number of seconds of the sound file to process % Number of bits for requantization [x,R, nbits] = wavread('salinas.wav'); you like % Read in a wave file, use any file % .........You do not have to change anything below this line ............ R, nbits nbits % Print out the sample rate R and the number of quantization levels x = x(1:Nsec*R)*2^(nbits-1); normalize to integer levels soundsc(x,R) pause(Nsec + 0.5) % Just keep the first Nsec of the file and % Play back the original xq = round(x/2^(nbits-bits)); % Scale wave file up to +- 2^nbits soundsc(xq,R) % listen to the requantized sound start = 1; stop = length(x); len = stop-start; % Select the part of the file to plot % If stop = length(x) the entire file is plotted 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') 3