Objectives Introductionsite.iugaza.edu.ps/.../10/lab1_Sampling-and-Quantization.pdfCommunication II...

16
Islamic University of Gaza Faculty of Engineering Electrical Engineering Department Fall-2011 Communication II Lab (EELE 4170) Lab#3 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. Theory (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).

Transcript of Objectives Introductionsite.iugaza.edu.ps/.../10/lab1_Sampling-and-Quantization.pdfCommunication II...

Page 1: Objectives Introductionsite.iugaza.edu.ps/.../10/lab1_Sampling-and-Quantization.pdfCommunication II Lab (EELE 4170) Lab#3 Sampling and Quantization Objectives When you have completed

Islamic University of Gaza

Faculty of Engineering Electrical Engineering Department

Fall-2011

Communication II Lab (EELE 4170)

Lab#3 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.

Theory

(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).

Page 2: Objectives Introductionsite.iugaza.edu.ps/.../10/lab1_Sampling-and-Quantization.pdfCommunication II Lab (EELE 4170) Lab#3 Sampling and Quantization Objectives When you have completed

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.

๐‘ฅ[๐‘›] = ๐‘ฅ๐‘Ž(๐‘›๐‘‡๐‘†) , n=โ€ฆ, -1, 0, 1, 2, โ€ฆ.

Also it possible to reconstruct ๐‘ฅ๐‘Ž(๐‘ก) from its samples: ๐‘ฅ๐‘Ž(๐‘ก)= ๐‘ฅ(t๐น๐‘†)

Figure 3.1 Sampling and Reconstruction process

Sampling Theorem

The uniform sampling theorem states that a bandlimited signal having no spectral

components above fm hetez can be determined uniquely by values sampled at uniform

intervals of : ๐‘‡๐‘  โ‰ค1

2๐‘“๐‘š

The upper limit on Ts can be expressed in terms of sampling rate, denoted fs=1/Ts. The

restriction, stated in term of the sampling rate, is known as the Nyquist criterion. The

statement is: ๐‘“๐‘  โ‰ฅ 2๐‘“๐‘š

The sampling rate ๐‘“๐‘  = 2๐‘“๐‘š is also called Nyquist rate .The allow Nyquist criterion is a

theoretically sufficient condition to allow an analog signal to be reconstructed completely

from a set of a uniformly spaced discrete-time samples.

Impulse Sampling

Assume an analog waveform x(t) ,as shown in figure 3.2(a), with a Fourier transform,

X(f) which is zero outside the interval (โˆ’ fm < f < fm ) ,as shown in figure 3.2(b). The

sampling of x(t) can be viewed as the product of x(t) with a periodic train of unit impulse

function xฮด(t), shown in figure 3.2(c) and defined as

Page 3: Objectives Introductionsite.iugaza.edu.ps/.../10/lab1_Sampling-and-Quantization.pdfCommunication II Lab (EELE 4170) Lab#3 Sampling and Quantization Objectives When you have completed

๐‘ฅ๐›ฟ ๐‘ก = ๐›ฟ(

โˆž

๐‘›=โˆ’โˆž

๐‘ก โˆ’ ๐‘›๐‘‡๐‘ )

where ๐‘‡๐‘  is the sampling period and ฮด(t) is the unit impulse or Dirac delta function .Let us

choose ๐‘‡๐‘  = 1/2๐‘“๐‘š , so that the Nyquist criterion is just satisfied. The sifting property

of the impulse function states that

๐‘ฅ ๐‘ก ๐›ฟ ๐‘ก โˆ’ ๐‘ก๐‘œ = ๐‘ฅ ๐‘ก๐‘œ ๐›ฟ ๐‘ก โˆ’ ๐‘ก๐‘œ

Using this property, we can see that ๐‘ฅ๐‘† ๐‘ก , the sampled version of x(t) shown in figure

3.2(e), is given by

๐‘ฅ๐‘† ๐‘ก = ๐‘ฅ(๐‘ก)๐‘ฅ๐›ฟ (๐‘ก) = ๐‘ฅ(๐‘ก)๐›ฟ(

โˆž

๐‘›=โˆ’โˆž

๐‘ก โˆ’ ๐‘›๐‘‡๐‘ ) = ๐‘ฅ(๐‘›๐‘‡๐‘ )๐›ฟ(

โˆž

๐‘›=โˆ’โˆž

๐‘ก โˆ’ ๐‘›๐‘‡๐‘ )

Using the frequency convolution property of the Fourier transform we can transform the

time-domain product ๐‘ฅ(๐‘ก)๐‘ฅ๐›ฟ (๐‘ก) to the frequency-domain convolution ๐‘“ โˆ— ๐‘‹๐›ฟ ๐‘“ ,

๐‘‹๐›ฟ ๐‘“ =1

๐‘‡๐‘  ๐›ฟ(

โˆž

๐‘›=โˆ’โˆž

๐‘“ โˆ’ ๐‘›๐‘“๐‘ )

where ๐‘‹๐›ฟ ๐‘“ is the Fourier transform of the impulse train ๐‘ฅ๐›ฟ (๐‘ก) . Notice that the Fourier

transform of an impulse train is another impulse train; the values of the periods of the two

trains are reciprocally related to one another. Figure 3.2(c) and (d) illustrate the impulse

train ๐‘ฅ๐›ฟ (๐‘ก) and its Fourier transform ๐‘‹๐›ฟ ๐‘“ , respectively.

We can solve for the transform ๐‘‹๐‘† ๐‘“ of the sampled waveform:

๐‘‹๐‘† ๐‘“ = ๐‘‹ ๐‘“ โˆ— ๐‘‹๐›ฟ ๐‘“ = ๐‘‹ ๐‘“ * 1

๐‘‡๐‘  ๐›ฟ(โˆž

๐‘›=โˆ’โˆž ๐‘“ โˆ’ ๐‘›๐‘“๐‘ )

๐‘‹๐‘† ๐‘“ =1

๐‘‡๐‘  ๐›ฟ(

โˆž

๐‘›=โˆ’โˆž

๐‘“ โˆ’ ๐‘›๐‘“๐‘ )

USER
Highlight
USER
Highlight
USER
Pencil
Page 4: Objectives Introductionsite.iugaza.edu.ps/.../10/lab1_Sampling-and-Quantization.pdfCommunication II Lab (EELE 4170) Lab#3 Sampling and Quantization Objectives When you have completed

Figure 3.2 Sampling theorem using the frequency convolution property of the Fourier

transform

We therefore conclude that within the original bandwidth, the spectrum ๐‘‹๐‘† ๐‘“ is, to within

a constant factor (1/Ts) , exactly the same as that of x(t) in addition, the spectrum repeats

itself periodically in frequency every fs hertz.

Aliasing

Aliasing in Frequency Domain

If fs does not satisfy the Nyquist rate, ๐‘“๐‘  < 2๐‘“๐‘š , the different components of ๐‘‹๐‘† ๐‘“

overlap and will not be able to recover x(t) exactly as shown in figure 3.3(b). This is

referred to as aliasing in frequency domain.

Page 5: Objectives Introductionsite.iugaza.edu.ps/.../10/lab1_Sampling-and-Quantization.pdfCommunication II Lab (EELE 4170) Lab#3 Sampling and Quantization Objectives When you have completed

Figure 3.3 Spectra for various sampling rates. (a) Sampled spectrum fs > 2๐‘“m

(b) Sampled spectrum fs < 2๐‘“m

Aliasing in time domain

As we shall presently see, the frequency content of the analog signal xa(t) has to be

limited before attempting to sample it. This means that xa(t) cannot change too fast;

consequently, the average value over the interval nTs โˆ’ฮ” to nTs+ฮ” is a good approximation

of the ideally sampled value xa(t) of nTs .

๐‘ก = ๐‘›๐‘‡๐‘† , 1

๐น=

1

๐‘“

1

๐น๐‘† , ๐น = ๐‘“๐น๐‘† , ฮฉ = ฯ‰๐น๐‘†

where, F : is the frequency of x(t) , f : is the frequency of x[n]

Note that the range of the frequency variable F for continuous-time sinusoids are

โˆ’โˆž < ๐น < โˆž , โˆ’ โˆž < ฮฉ < โˆž

Page 6: Objectives Introductionsite.iugaza.edu.ps/.../10/lab1_Sampling-and-Quantization.pdfCommunication II Lab (EELE 4170) Lab#3 Sampling and Quantization Objectives When you have completed

However, the situation is different for discrete-time sinusoids

โˆ’1

2< ๐‘“ <

1

2 , โˆ’ ๐œ‹ < ฯ‰ < ๐œ‹

Discrete- time sinusoid whose radian frequencies are separated by integer multiples of 2ฯ€

are identical. Sequence that result from a sinusoid with a frequency |w| > ฯ€ is identical to a

sequence obtained from a sinusoidal with frequency : -ฯ€ โ‰ค w โ‰ค ฯ€ .

But for continuous-time sinusoids result in distinct signals for ฮฉ or F in the range :

-โˆž< F <โˆž or -โˆž< ฮฉ <โˆž

Figure 3.4 shows a simple example .The solid line describes a 0.5Hz continuous-time

sinusoidal signal and the dash-dot line describes a 1.5 Hz continuous time sinusoidal signal.

When both signals are sampled at the rate of Fs =2 samples/sec, their samples coincide, as

indicated by the circles. This means that x1[nTs] is equal to x2[nTs] and there is no way to

distinguish the two signals apart from their sampled versions. This phenomenon is known

as aliasing.

Figure 3.4 Two sinusoidal signals are indistinguishable from their sampled versions

๐‘ฅ1 ๐‘›๐‘‡๐‘† = cos 2๐œ‹๐น1๐‘›๐‘‡๐‘† = cos 2๐œ‹ ร—1

2 ร— ๐‘› ร—

1

2 = cos 0.5๐œ‹๐‘›

๐‘ฅ2 ๐‘›๐‘‡๐‘† = cos 2๐œ‹๐น2๐‘›๐‘‡๐‘† = cos 2๐œ‹ ร—3

2 ร— ๐‘› ร—

1

2 cos 1.5๐œ‹๐‘› = cos 1.5๐œ‹๐‘› โˆ’ 2๐œ‹๐‘›

= cos โˆ’0.5๐œ‹๐‘› = cos โˆ’0.5๐œ‹๐‘› = cos 0.5๐œ‹๐‘› ๐‘ฅ1 ๐‘›๐‘‡๐‘† = ๐‘ฅ2 ๐‘›๐‘‡๐‘†

Page 7: Objectives Introductionsite.iugaza.edu.ps/.../10/lab1_Sampling-and-Quantization.pdfCommunication II Lab (EELE 4170) Lab#3 Sampling and Quantization Objectives When you have completed

Reconstruct ๐‘ฅ1 ๐‘ก ๐‘Ž๐‘›๐‘‘ ๐‘ฅ2 ๐‘ก

๐‘ฅ1 ๐‘ก = ๐‘ฅ ๐‘ก๐น๐‘† = cos 0.5๐œ‹ ๐‘ก๐น๐‘† = cos 0.5๐œ‹ ๐‘ก ร— 2 = cos 2๐œ‹ ร— 0.5 ร— ๐‘ก = ๐‘ฅ2 ๐‘ก

On the other hand,

๐‘ญ๐’‚๐’๐’Š๐’‚๐’”๐’†๐’… = ๐‘ญ๐’ƒ๐’‚๐’”๐’† + ๐’Œ ๐‘ญ๐‘บ , ๐’Œ = ยฑ๐Ÿ, ยฑ๐Ÿ, โ€ฆ.

๐’‡๐’‚๐’๐’Š๐’‚๐’”๐’†๐’… = ๐’‡๐’ƒ๐’‚๐’”๐’† + ๐’Œ , ๐’Œ = ยฑ๐Ÿ, ยฑ๐Ÿ, โ€ฆ.

where ๐น๐‘Ž๐‘™๐‘–๐‘Ž๐‘ ๐‘’๐‘‘ ๐‘Ž๐‘›๐‘‘ ๐‘“๐‘Ž๐‘™๐‘–๐‘Ž๐‘ ๐‘’๐‘‘ are outside the fundamental frequency range:

โˆ’๐น๐‘†

2 โ‰ค ๐น๐‘๐‘Ž๐‘ ๐‘’ โ‰ค

๐น๐‘†

2 and โˆ’

1

2 โ‰ค ๐‘“๐‘๐‘Ž๐‘ ๐‘’ โ‰ค

1

2

Avoiding Aliasing

In order to avoid aliasing we must restrict the analog signal xa(t) to the frequency

range, Fo less than Fs/2. Thus, every sampler must be preceded by an analog low-pass

filter, known as an anti-aliasing filter; with a cut-off frequency fc equals fs /2.

This means that the high frequency artifacts of the continuous-time signal will be lost. This

is the cost of managing aliasing. In practice, the anti-aliasing filter will have a cutoff

frequency at roughly 90% of

Figure 3.5 Avoiding aliasing in signal processing

Page 8: Objectives Introductionsite.iugaza.edu.ps/.../10/lab1_Sampling-and-Quantization.pdfCommunication II Lab (EELE 4170) Lab#3 Sampling and Quantization Objectives When you have completed

Quantization

The second stage in the A/D process is amplitude quantization, where the sampled

discrete-time signal x(n), is quantized into a finite set of output levels . The quantized signal

can take only one of L levels, which are designed to cover the dynamic range:

xmin โ‰ค x(n) โ‰ค xmax

The step size or resolution of the uniform quantizer is given as:

ฮ” = ๐‘ฅ๐‘š๐‘Ž๐‘ฅ โˆ’ ๐‘ฅ ๐‘š๐‘–๐‘›

L โˆ’ 1

The step size can be either integer or fraction and is determined by the number of levels L.

For binary coding, L is usually a power of 2, and practical values are 256 (=2 ^8) or greater.

The difference between the actual analog value and quantized digital value is

called quantization error. This error is due to rounding.

and,

A continuous time signal, such as voice, has a continuous range of amplitudes and therefore

its samples have a continuous amplitude range i.e. they are only discrete in time not in

amplitude. In other words, within the finite amplitude range of the signal, we find an

infinite number of amplitude levels. It is not necessary in fact to transmit the exact

amplitude of the samples. Any human sense (the ear or the eye), as ultimate receiver, can

detect only finite intensity differences. This means that the original continuous time signal

may be approximated by a signal constructed of discrete amplitudes selected on a minimum

error basis from an available set. Clearly, if we assign the discrete amplitude levels with

sufficiently close spacing we may take the approximated signal practically indistinguishable

from the original continuous signal.

Amplitude quantization is defined as the process of transforming the sample amplitude

m(nTs) of a message signal m(t) at time t=nTs into a discrete amplitude v(nTs) taken from a

finite set of possible amplitudes.

Quantization error : ( ) ( ) ( )q qe n x n x n

2 2error

Page 9: Objectives Introductionsite.iugaza.edu.ps/.../10/lab1_Sampling-and-Quantization.pdfCommunication II Lab (EELE 4170) Lab#3 Sampling and Quantization Objectives When you have completed

Practical Parts:

Part 1: Aliasing in Time Domain

The signal ๐‘ฅ ๐‘ก = cos 2๐œ‹๐น๐‘œ๐‘ก can be sampled at the rate ๐น๐‘† =1

๐‘‡๐‘† to yield

๐‘ฅ(๐‘›) = ๐‘๐‘œ๐‘  2๐œ‹๐น๐‘œ

๐น๐‘† ๐‘›

Aliasing will be observed for various ๐น๐‘œ

a) Let ๐‘ญ๐‘บ=10 kHz and ๐‘ญ๐’=1 kHz. Compute and plot x[n] using stem.

n=0:50;

Fs=10000;

Fo=1000;

xn=cso(2*pi*(Fo/Fs)*n)

figure(1)

stem(xn)

b) Use subplot to plot x(t) for ๐น๐‘œ=300 Hz and 700 Hz.

Fs=10000;

t=0:0.0001:50/Fs;

Fo=[300,700];

for i=1:2;

subplot(2,1,i)

xt=cos(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: .

.

Page 10: Objectives Introductionsite.iugaza.edu.ps/.../10/lab1_Sampling-and-Quantization.pdfCommunication II Lab (EELE 4170) Lab#3 Sampling and Quantization Objectives When you have completed

c) Use subplot to plot x[n] for ๐น๐‘œ=300 Hz and 700 Hz.

Fs=10000;

n=0:50;

Fo=[300,700];

for i=1:2;

subplot(2,1,i)

xn=cos(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) Repeat (b) and (c) for ๐น๐‘œ=9700 Hz and 9300 Hz.

e) Repeat (b) and (c) for ๐น๐‘œ=10300 Hz and 10700 Hz.

Page 11: Objectives Introductionsite.iugaza.edu.ps/.../10/lab1_Sampling-and-Quantization.pdfCommunication II Lab (EELE 4170) Lab#3 Sampling and Quantization Objectives When you have completed

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 3.6 Simulink model to implement aliasing in frequency domain

Al Fajer
Highlight
Al Fajer
Sticky Note
Un wanted
Page 12: Objectives Introductionsite.iugaza.edu.ps/.../10/lab1_Sampling-and-Quantization.pdfCommunication II Lab (EELE 4170) Lab#3 Sampling and Quantization Objectives When you have completed

Part 3: 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));

b) Use this function to quantize an analog sinusoidal signal with L=4 and 32 levels.

Compute the SQR for each level.

t=0:.001:1;

y=2*sin(2*pi*t)

figure(1)

subplot(311)

plot(y)

q1=uquant(y,4)

subplot(312)

plot(q1)

q2=uquant(y,32)

subplot(313)

plot(q2)

Ps=mean(y.^2);

Pq1=mean(q1.^2);

Pq2=mean(q2.^2);

SQR1=Ps/Pq1;

SQR2=Ps/Pq2;

Page 13: Objectives Introductionsite.iugaza.edu.ps/.../10/lab1_Sampling-and-Quantization.pdfCommunication II Lab (EELE 4170) Lab#3 Sampling and Quantization Objectives When you have completed

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

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

Page 14: Objectives Introductionsite.iugaza.edu.ps/.../10/lab1_Sampling-and-Quantization.pdfCommunication II Lab (EELE 4170) Lab#3 Sampling and Quantization Objectives When you have completed

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

d) Construct the simulink model shown in Figure 3.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).

Page 15: Objectives Introductionsite.iugaza.edu.ps/.../10/lab1_Sampling-and-Quantization.pdfCommunication II Lab (EELE 4170) Lab#3 Sampling and Quantization Objectives When you have completed

Figure 4.7 Simulink model for sampling and quantization

Image Quantization

Use uquant function to quantize the office_4.jpg image (you can found it in the direction c:\Program Files\matlab\toolbox\images\imdemosimage\office_4.jpg)

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.

Audio Quantization

Form results in part 3(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 1

Exercise 2

Al Fajer
Highlight
Al Fajer
Sticky Note
un wNTED
Page 16: Objectives Introductionsite.iugaza.edu.ps/.../10/lab1_Sampling-and-Quantization.pdfCommunication II Lab (EELE 4170) Lab#3 Sampling and Quantization Objectives When you have completed

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.

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.

Exercise 3

Al Fajer
Highlight
Al Fajer
Sticky Note
UN WANTED