Islamic University of Gaza Faculty of Engineering Electrical Engineering Department Spring-2012 ___________________________________________________________________________________________ _ DSP Laboratory (EELE 4110) Lab#2 Sampling and Quantization OBJECTIVES: When you have completed this assignment, you will: − understand the concept of sampling, aliasing, quantization and reconstruction. − demonstrate the effect of aliasing on the reconstruction process. INTRODUCTION: Digital communications has proved to be a very efficient means of transporting speech, music, video, and data over different kinds of media. These media include satellite, microwave, fiber-optic, coaxial, and cellular channels. One special advantage that digital communication holds over analog communication is in the superior handling of noise in the channel. Baseband signals such as speech, music, and video are naturally occurring analog signals. Hence, the processes of analog to digital (A/D) conversion at the transmitter and digital to analog conversion (D/A) at the receiver are integral sections of the entire communication. THEORETICAL PART: (1) Sampling . In order to store, transmit or process analog signals using digital hardware, we must first convert them into discrete-time signals by sampling. The processed discrete-time signal is usually converted back to analog form by interpolation, resulting in a reconstructed analog signal xr(t). The sampler reads the values of the analog signal xa(t) at equally spaced sampling instants. The time interval Ts between adjacent samples is known as the sampling period (or sampling interval). The sampling rate, measured in samples per second, is fs =1/Ts. x[n]= xa(nTs) , n=…, - 1, 0, 1, 2, …. Also it possible to reconstruct xa(t) from its samples: xa(t) = x[tFs].
15
Embed
(1) Sampling . - الصفحات الشخصية | الجامعة الإسلامية ...site.iugaza.edu.ps/sqalaja/files/2016/09/Lab2-dsp1-1.pdfFigure 2.1: Sampling and Reconstruction
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Islamic University of Gaza
Faculty of Engineering Electrical Engineering Department
b) Use subplot to plot x(t) for 𝐹𝑜=300 Hz, 700 Hz, 1100 Hz and 1500 Hz.
Fs=10000; t=0:0.0001:50/Fs; Fo=[300,700,1100,1500]; for i=1:4; subplot(4,1,i) xt=sin(2*pi*Fo(i)*t) plot(t,xt)
end
Comment on the following words for the result figure in (b):
(a) The period: .
(b) The rate of oscillation: .
c) Use subplot to plot x[n] for 𝐹𝑜=300 Hz, 700 Hz, 1100 Hz and 1500 Hz.
Fs=10000;
n=0:50; Fo=[300,700,1100,1500]; for i=1:4; subplot(4,1,i) xn=sin(2*pi*(Fo(i)/Fs)*n) stem(xn) end
Comment on the following words for the result figure in (c):
(a) Aliasing: : .
(b) The period: .
(c) The rate of oscillation: .
(d) Fill in the table below with appropriate values:
Fo=300 Hz Fo=700 Hz Fo=1100 Hz Fo=1500 Hz
Faliased
T=1/F
Fbase
faliased
fbase
N
d) Repeat (b) and (c) for 𝐹𝑜=8500 Hz, 8900 Hz, 9300 Hz and 9700 Hz.
e) Repeat (b) and (c) for 𝐹𝑜=10300 Hz, 10700 Hz, 11100 Hz and 11500 Hz.
Consider an analog signal x(t) consisting of three sinusoids
x(t)= cos(2πt)+cos(8πt)+cos(12πt) Using Matlab,
(a) Show that if this signal is sampled at a rate of Fs = 5 Hz, it will be aliased with the following
signal, in the sense that their sample values will be the same:
xa(t)= 3cos(2πt)
(b) Repeat part (a) with Fs = 10 Hz. In this case, determine the signal x(t) with which xa(t) is
aliased. Plot both x(t) and xa(t) on the same graph over the range 0 ≤ t ≤ 1 sec. Verify again that
the signals intersect at the sampling instants.
Exercise 1
Part 2: Aliasing in Frequency Domain:
a) Construct the simulink model shown in Figure 4.6.
b) Input a sine wave of Fo=5 Hz frequency from the signal generator. Choose a sampling time of 0.01 sec for the pulse generator with pulse duration of 50 % of the sampling
period. Choose the cut-off frequency of 120π for the Butterworth low-pass filter.
c) Start the simulation for 1sec and notice all visualizers(included them in your report).
d) Repeat steps 2 and 3 for a sine wave with Fo = 95 Hz. Comment.
e) Repeat steps 2 and 3 for a sine wave with Fo = 105 Hz. Comment.
Figure 2.6: Simulink model to implement aliasing in frequency domain
Part 3: Downsampling:
a) Using MATLAB, generate a sine wave with frequency Fo of 1300 Hz, and sampling frequency Fs of
8000 Hz. b) Save the data of the sine wave as a sound file, named as 8000.wav. c) Listen to the tone of the 1300 Hz sine wave. d) Downsample the data of the sine wave by 2. This will result in a sine wave with a sampling rate of
4000 Hz. Repeat steps b, c and compare the sounds. e) Generate a sine wave with frequency Fo of 1300 Hz, and sampling frequency Fs of 4000Hz. f) Repeat steps b and c and compare the sounds.
clc clear all n=0:1:5000; Fo=1300; Fs=8000; x=sin(2*pi*Fo*n/Fs); sound (x);
pause clear all n=0:2:5000; Fo=1300; Fs=8000; x=sin(2*pi*Fo*n/Fs); sound (x);
pause clear all n=0:1:5000; Fo=1300; Fs=4000; x=sin(2*pi*Fo*n/Fs); sound(x(1:2500));
Part 4: Quantization:
a) Write a Matlab function Y = uquant(X,L) which will uniformly quantize an input array X (either a
vector or a matrix) to L discrete levels.
function y=uquant(x,n) del=((max(max(x))-(min(min(x)))))/(n-1); r=(x-min(min(x)))/del; r=round(r); y=r*del+min(min(x));
Example: Quantized x=2sin (2pi*t) using 16 levels.
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
0 20 40 60 80 100 1200
5
10
15
0 20 40 60 80 100 1200
5
10
15
0 20 40 60 80 100 120-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
0 20 40 60 80 100 1200
0.5
1
1.5
2
2.5
3
3.5
4
0 20 40 60 80 100 1200
0.5
1
1.5
2
2.5
3
3.5
4
15
0
Mapping to
[ 0 to 15 ]
Round to the
nearest level.
Re-mapping to
[ -2 to 2 ]
Shift to
+ve region
[ o to 4]
x-min(min(x))
Divide by del
b) Use this function to quantize an analog sinusoidal signal with L=4 and 32 levels. Compute the SQR
c) Audio quantization, use uquant function to quntize an audio signal at different levels and compare
the result quantized signals by hearing them.
clc clear all [y,fs]=wavread('speech_dft.wav'); sound(y,fs)
for b=1:7; L=2.^b; yQ=uquant(y,L); pause b sound(yQ,fs) end
f) Construct the simulink model shown in Figure 4.6.
Input a sine wave of Fo=1 Hz frequency from the signal generator. Choose a sampling time of 0.1 sec for the pulse generator with pulse duration of 50 % of the sampling
period. Choose the quantization interval of 0.5 for the Quantizer.
Start the simulation and notice all visualizers(included them in your report).
Figure 2.7: Simulink model for sampling and quantization
(1) Image Quantization Use uquant function to quantize the office_4.jpg image (you can found it in the direction
to 7, 4, 2 and 1 b/pel. Observe and print the output images for each level.
Note you must first convert the image from RGB to gray image.
(2) Audio Quantization Form results in part 4(c) answer the following questions:
(a) Describe the change in quality as the number of b/sample is reduced? (b) Do you think 4 b/sample is acceptable for telephone systems? (c) Plot the SQNR versus number of bits .Generate this curve by computing the SQNR for 7,
6, 5,..., 1 bits/sample. Also display this curve in semi-log(dB). (d) Plot the distortion versus number of bits in linear and semi-log scales.
Exercise 2
Given a sinusoidal waveform with a frequency of 100 Hz,
(a) Write a MATLAB program to quantize the x(t) using 4-bit quantizers to obtain the
quantized signal xq, assuming that the signal range is from -5 to 5 volts.
(b) Plot the original signal, quantized signal, and quantization error, respectively.
(c) Calculate the SQNR due to quantization using the MATLAB program.
Check for your answer with equation (1.4.32) in Proakis's Book.
Note:
Your report should include the following:
1- All Matlab program and its results with a short comment on each result. 2- Answer any internal questions in practical parts. 3- Solve all lab exercises.