Você está na página 1de 13

Department of Electrical and Computer Engineering

Faculty of Engineering and Architecture


American University of Beirut

EECE 442L – Communications Laboratory

Experiment on
Sampling and Quantization

Version: August 2009


Sampling and Quantization

OBJECTIVES

• Understand the basic concepts of sampling and quantization.

• Demonstrate and analyze the process of sampling with emphasis on the sampling
conditions that enable regeneration of an original signal.

• Demonstrate and analyze uniform and non-uniform quantization algorithms taking into
account the pros and cons of each approach.

THEORETICAL BACKGROUND

This experiment gives a theoretical overview as well as a practical insight into the various
steps that are needed to convert analog signals (e.g., voice and music), which are
predominant in nature, into digital representations.

A. INTRODUCTION

Information sources can be either analog or discrete in nature. The output of an analog
information source can take any value from a continuous range of amplitudes, whereas the
output of a discrete information source can take its values from a finite set of amplitudes.
Analog information sources can be transformed into digital signals through the processes of
sampling and quantization as shown in Figure 1 .

B. SAMPLING

The sampling process transforms a time-continuous signal into a time-discrete signal by


extracting samples of the input signal at equidistant time instants. It is important to properly
choose the sampling rate so that the obtained sequence of samples uniquely defines the
original analog signal. This condition is necessary for perfect reconstruction of the analog
signal from the generated set of samples.

Sampling and Quantization – August 2009  Page 1 
Sample Quantizer
Analog signal Sampled signal Digital signal
(Continuous in (Discrete in (Disrete in both
both time and time domain time and
amplitude and continuous amplitude
domains) in amplitude domains)
domain)

Figure 1: Analog-to-digital conversion process.

Assume the analog source signal x(t ) is sampled with a rate f s = 1 / Ts ,i.e., one sample is

obtained every Ts seconds. Assume that the signal x ( t ) is band-limited with no frequency

component higher than W. A sampling period of Ts ≤ 1 / 2W is sufficient for ideal


reconstruction of the signal from its samples. On the other hand, a sampling period
Ts > 1 / 2W results in distortion called aliasing that prohibits perfect reconstruction. It is

important to note that the case where the sampling rate f s is equal to 2W (or Ts = 1 / 2W )

is referred to as the Nyquist sampling rate.

In practice, sampling is normally done at a rate higher than the Nyquist sampling rate. This
is important to avoids aliasing due to undersampling in case the soure signal is not strictly
band-limited. This is also useful for simplifying the design of the reconstruction filter used
to recover the original signal from its sampled version at the receiver side. To reconstruct
the original signal from its sampled version, a low pass filter is used with high cut off
frequency that includes the highest frequency in the source signal.

For more background information on sampling, check Section 2.4 in [1] and/or
Sections 6.2-6.3 in [2].

C. QUANTIZATION

Quantization is the process of mapping samples of a continuous amplitude waveform into a


finite set of amplitudes. The hardware that performs this mapping is normally called the
analog-to-digital converter (ADC or A-to-D). Every quantizer is characterized by decision
thresholds xk and reconstruction values qk that lie in the center of the quantization-intervals

Sampling and Quantization – August 2009  Page 2 
[xk , xk+1]. Assuming that there are L quantizing levels and that each quantizing level is
represented by an R-bit binary word, it follows that L = 2R. The quantization process is not
reversible, and the difference between the input and output of a quantizer is called the
quantization error or the quantization noise. Quantizers that exihibit equally spaced
increments between possible quantized output levels are called uniform quantizers,
otherwise they are called nonuniform quantizers.

C.1 UNIFORM QUANTIZATION

With uniform quantization, the quantization intervals are all of the same length. The
quantization error variance σq2 of a uniform quantizer can be calculated as follows:

1 x max
2
σ q2 = 2 − 2 R x max
2
=
3 3L2

where xmax is the maximum amplitude of the signal. The signal-to-quantization-noise-ratio


of a uniform quantizer can be calculated as follows:

⎛ σ x2 ⎞
⎟ = 10 log10 ⎜ 3L σ x
⎛ 2 2 ⎞
SNR (dB ) = 10 log10 ⎜ 2
U
⎜ x2


q
⎜σ ⎟
⎝ q ⎠ ⎝ max ⎠

where σx2 is the variance of the input signal. For the special case where the modulating
signal is a sinusoid of amplitude Am, its variance is σ x2 = Am2 / 2 , and using the number of

bits per sample R = log 2 L results in:

⎛3 ⎞
SNRqU (dB) = 10 log10 ⎜ L2 ⎟ = 6.02 R + 1.76
⎝2 ⎠

It can be seen that as the number of quantization levels L increases, the value of R increases
and, thus, the SNR increases.

C.2 OPTIMAL QUANTIZATION

Uniform quantization is the most common method for transforming signals with continuous
amplitudes into signals with discrete amplitudes. In general, it is possible to quantize a
random variable X with a lower quantization-error variance. This can be achieved by using
smaller quantization-intervals where the pdf pX(x) is concentrated. Hence the uantization

Sampling and Quantization – August 2009  Page 3 
process depends on the input signal. One approach to achieve a lower quantization noise is
to perform optimal quantization using the Lloyd-Max algorithm. The variance of the
quantization noise to be minimized can be expressed as follows:

L 2

∑ ∫x (x − q k ) p X ( x )dx
x k +1
σ q2 =
k
k =1

This is a (2L+1) variable equation (L variables for q and L+1 variables for x). Minimizing
this equation leads to the following results:

q k −1 + q k
(1) x k ,opt = , k = 2 ,3,..., L
2
x k +1

∫ xp X ( x ) dx
= E [X X ∈ ( x k , x k +1 )]
xk
(2) q k ,opt = x k +1

∫p
xk
X ( x ) dx

Equation (1) indicates that the optimal decision thresholds for the quantization intervals are
the midpoints between two adjacent quantization levels, whereas Equation (2) indicates
that the optimal quantization level for a given quantization interval is the expected value of
the pdf for that interval.

In practice, the above equations can be solved iteratively to obtain the optimal intervals and
their corresponding quantization levels. The steps of the algorithm, called Lloyd algorithm,
are summarized in Table 1 and further illustrated in Flowchart 1.

Table 1: The Lloyd algorithm.

Step 1 Begin from an arbitrary set of decision


thresholds xk (normally uniform thresholds)
Step 2 Use Equation (2) to get the improved
quantization levels qk
Step 3 Use Equation (1) to get the improved
decision thresholds xk
Step 4 Compute σq2. Restart at Step 2 as many
times as needed to get σq2 below a given
desired value or until a certain number of
iterations is executed

Sampling and Quantization – August 2009  Page 4 
Flowchart 1: The Lloyd algorithm.

Initial xk

q k = E[X X ∈ (xk , xk +1 )]

qk −1 + qk
xk =
2

L 2
σ q2 = ∑ ∫ (x − q k ) p X ( x )dx
x k +1

xk
k =1

Small enough?

STOP

For more background information on quantization, check Section 6.5 in [1] and/or
Section 6.7 in [2].

Sampling and Quantization – August 2009  Page 5 
PREPARATION EXERCISE FOR SAMPLING AND QUANTIZATION

This demo gives a primary overview of sampling and quantization for band-limited and
non band-limited signals. Open the front panel of “Demo_Sampling_Quantization.vi”,
and set the following parameters:

Quantity/Setting Value
Signal Type Triangle wave
Signal Frequency 2000 Hz
Sampling Frequency 4000 Hz
Bits per Sample 3

Observe the time domain of the original signal and its sampled version, and their
corresponding frequency domain graphs. Inspect also the time domain graphs of the
quatized signal for both the original and the sampled signals. In telecommunication
systems, quatization is applied after sampling, but for clarification purposes the original
quantized signal is included too.

Try to think of answers to the following questions: Is the used sampling frequency
sufficient to recover the original signal? Increase the number of bits per sample, and
observe the quantized graphs. What is the effect of increasing the number of bits per
sample? For each signal type in the VI, try to vary the different parameters such as
sampling frequency and bits per sample, and analyze the effect of each of these.

Sampling and Quantization – August 2009  Page 6 
EXPERIMENT DESCRIPTION

GENERAL RULES

ƒ If you open a VI and you are not asked to do any changes to it, then close it without
saving changes by clicking on “Defer decision”.

ƒ Save VIs as [GroupID]_name of VI.vi

ƒ Save plots as [GroupID]_Question number.jpg. For questions with more than one plot,
append extra info to the name to differentiate between the plots.

PART I: SAMPLING

In this part, you will investigate the sampling procedure on various simple input signals.
You will consider the effect of aliasing and attempt to correct it by two approaches:
(1) increasing the sampling frequency and (2) band-limiting the input signal.

A. THE SAMPLING VI

Open the Block Diagram of “SamplingExample.VI”.

The two block subVIs are the following:

Sampling.VI
Samples a signal according to the specified sampling frequency.
SignalReconstruction.VI
Reconstructs a sampled signal to its initial state.

Q.1 Explain how the case structure between the signal generator and the
sampler works. What is its function?

Double-click on “Sampling.VI”.

Q.2 Explain in details how sampling is implemented.

Double-click on “SignalReconstruction.VI”.

Q.3 Explain how reconstruction is performed.

Sampling and Quantization – August 2009  Page 7 
B. SAMPLING A SINE WAVEFORM

On the Front Panel of the “SamplingExample.VI”, set the following parameters:

Signal Type Sine Wave


Signal Frequency 5 kHz
PreSampling LPF ON? OFF

Q.4 For the given sine wave, what is the theoretical minimum sampling
frequency to allow perfect reconstruction? Justify your answer.

Q.5 What value would you choose for the Reconstruction LPF Cut-off
Frequency? Justify your answer.

Set the Sampling Frequency to the value in Q.4, and the Reconstruction LPF Cut-off
Frequency to the value in Q.5 and run the VI.

Q.6 Do you observe a perfect reconstructed signal? Comment.

Run the VI for Sampling Frequencies of 20 kHz, 30 kHz, and 40 kHz.

Q.7 Explain the effect of increasing the sampling frequency, and indicate
which value would you choose for perfect reconstruction?

Q.8 What are the periodic pulses that appear in the spectrum of the
sampled signal?
Hint: Look at the distance between two consecutive pairs.

Set the Sampling Frequency to 7.5 kHz and run the VI.

Q.9 What are the extra frequency components that appear in the spectrum
of the reconstructed signal? What is this effect called?

Sampling and Quantization – August 2009  Page 8 
C. SAMPLING A SAW-TOOTH WAVEFORM

On the Front Panel of the “SamplingExample.VI”, set the following parameters:

Signal Type Sawtooth Wave


Signal Frequency 5 kHz
PreSampling LPF ON? OFF
Sampling Frequency 40 kHz
Reconstruction Cut-off Frequency 5 kHz

Run the VI.

Q.10 What do you observe on the spectrum graph of the original signal?

Inspect the graph of the filtered signal.

Q.11 Why is the filtered signal different from the original signal?
Hint: Try to vary the value of the Reconstruction Cut-off Frequency.

Q.12 How can a pre-sampling filter be used to remove aliasing?

Q.13 What is the best value of the Cut-off frequency of the PreSampling LPF
when the sampling frequency is 40 kHz? Explain.

Set the PreSampling LPF ON and set its Cut-off Frequency to 20 kHz, similarly set the
Reconstruction Cut-off Frequency to 20 KHz and run the VI.

Q.14 Inspecting the original signal, what is the disadvantage of using a LPF
before sampling?

Sampling and Quantization – August 2009  Page 9 
PART II: QUANTIZATION
In this part, you will investigate the quantization process including the introduced
quantization noise. You will consider two quantization algorithms: (1) uniform
quantization and (2) optimal quantization. You will also compare them to each other with
regard to quantization SNR.

A. THE QUANTIZATION VI

Open the Block Diagram of “QuantizeGeneric.VI”. This VI quantizes input signal


samples based on any given set of ordered quantization levels.

Q.15 Explain how the quantizer is implemented.


Hint: Look in the help at how the “Threshold 1D array” computes the
“fractional index”.

B. UNIFORM QUANTIZATION

Open the Block Diagram of “UniformExample.VI”.


The four block subVIs are the following:

GetUniformParameters.VI
Gets the quantization values qk for a uniform quantizer.
QuantizeGeneric.VI
Already seen in part I, it quantizes a signal based on the qk passed
from the previous GetUniformParameters function.

SNRq.VI
Computes the quantization SNR in dB.
PlotQFunction.VI
Creates a plot of the quantization staircase function.

Q.16 What is the relation between the number of bits per sample and the
number of quantization levels?

Sampling and Quantization – August 2009  Page 10 
On the Front Panel of “UniformExample.VI”, set the following parameters:

Signal Frequency 5 kHz


Bits per Sample 3

Run the VI.

Q.17 What is the resulting value of the SNR in dB? Compare with the
theoretical value.

Increase the Bits per Sample to 4 and run the VI.

Q.18 Calculate the difference between the resulting value of the SNR with
the value obtained in Q.17. Comment.

C. Optimal Quantization

In this part, you will compare optimal quantization to uniform quantization. The difference
is in specifying the quantization steps and their thresholds which are referred to as
Parameters in the experiment.

Open the “GetCentroid.VI”. This VI computes the optimal quantization levels over a set
of quantization intervals.

Q.19 Explain how the VI computes the quantization levels.

Open the Block Diagram “UniformVSOptimal.VI”.

The new subVI is:

GetOptimalParameters.VI
Gets the quantization values qk for an optimal quantizer.

On the Front Panel of “UniformVSOptimal.VI”, set the following parameters:

Signal Type Sine Wave


Signal Frequency 2 kHz
Bits per Sample 3

Sampling and Quantization – August 2009  Page 11 
Examine the waveforms graph to see the difference between the quantized waveforms.

Q.20 Why are the first and last quantization intervals smaller for the optimal
quantizer compared to the uniform quantizer?

Q.21 Note the difference between the two SNR values. Comment.

Change the Signal Type to Sinc Function and the Frequency to 5 kHz. Run the VI and note
the difference.

Q.22 Compare the SNRs of both quantizers. Comment.

Q.23 Why is the gap between the optimal and uniform quantizers bigger
with Sinc Function compared to Sine Wave?

Change the Signal Type to Linear and examine the waveforms and the steps graphs.

Q.24 Compare the SNRs of both quantizers. Comment.

REFERENCES

[1] J. Proakis and M. Salehi, Communication Systems Engineering. Prentice-Hall, 2nd


edition, 2002.

[2] S. Haykin, Communication Systems. John Wiley & Sons, 3rd edition, 1994.

Sampling and Quantization – August 2009  Page 12 

Você também pode gostar