You are on page 1of 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.

SamplingandQuantizationAugust2009

Page1

Sample
Analog signal (Continuous in both time and amplitude domains) Sampled signal (Discrete in time domain and continuous in amplitude domain)

Quantizer
Digital signal (Disrete in both time and amplitude domains)

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
SamplingandQuantizationAugust2009 Page2

[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:
2 2 q = 2 2 R x max =

1 3

2 x max 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:
2 x SNR (dB ) = 10 log10 2 q U q

2 2 = 10 log10 3L x x2 max

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

bits per sample R = log 2 L results in:

3 U SNRq (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
SamplingandQuantizationAugust2009 Page3

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:

q2 =

1 x (x q k ) k=
x k +1
k

p X ( x )dx

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:
(1) x k ,opt = q k 1 + q k , 2
x k +1 xk x k +1

k = 2 ,3,..., L

(2)

q k ,opt =

xp
xk

( x ) dx ( x ) dx

= E [X X ( x k , x k +1 )]

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 Step 2 Step 3 Step 4

Begin from an arbitrary set of decision thresholds xk (normally uniform thresholds) Use Equation (2) to get the improved quantization levels qk Use Equation (1) to get the improved decision thresholds xk 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

SamplingandQuantizationAugust2009

Page4

Flowchart 1: The Lloyd algorithm.

Initial xk

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

xk =

q2 =
k =1

x k +1

xk

(x q k )

p X ( x )dx

Small enough?

STOP

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

SamplingandQuantizationAugust2009

Page5

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 Signal Frequency Sampling Frequency Bits per Sample

Triangle wave 2000 Hz 4000 Hz 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.

SamplingandQuantizationAugust2009

Page6

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.

SamplingandQuantizationAugust2009

Page7

B. SAMPLING A SINE WAVEFORM

On the Front Panel of the SamplingExample.VI, set the following parameters: Signal Type Signal Frequency PreSampling LPF ON?
Q.4

Sine Wave 5 kHz OFF

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?

SamplingandQuantizationAugust2009

Page8

C. SAMPLING A SAW-TOOTH WAVEFORM

On the Front Panel of the SamplingExample.VI, set the following parameters: Signal Type Signal Frequency PreSampling LPF ON? Sampling Frequency Reconstruction Cut-off Frequency Run the VI.
Q.10 What do you observe on the spectrum graph of the original signal?

Sawtooth Wave 5 kHz OFF 40 kHz 5 kHz

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?

SamplingandQuantizationAugust2009

Page9

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?

SamplingandQuantizationAugust2009

Page10

On the Front Panel of UniformExample.VI, set the following parameters: Signal Frequency 5 kHz Bits per Sample 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 Signal Frequency Bits per Sample
SamplingandQuantizationAugust2009

Sine Wave 2 kHz 3


Page11

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.

SamplingandQuantizationAugust2009

Page12

You might also like