Escolar Documentos
Profissional Documentos
Cultura Documentos
Experiment on
Sampling and Quantization
OBJECTIVES
• 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
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)
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
important to note that the case where the sampling rate f s is equal to 2W (or Ts = 1 / 2W )
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
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.
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
⎛ σ 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
⎛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.
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.
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 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
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”.
Double-click on “SignalReconstruction.VI”.
Sampling and Quantization – August 2009 Page 7
B. SAMPLING A SINE WAVEFORM
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.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
Q.10 What do you observe on the spectrum graph of the original 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.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
B. UNIFORM QUANTIZATION
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:
Q.17 What is the resulting value of the SNR in dB? Compare with the
theoretical value.
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.
GetOptimalParameters.VI
Gets the quantization values qk for an optimal quantizer.
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.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.
REFERENCES
[2] S. Haykin, Communication Systems. John Wiley & Sons, 3rd edition, 1994.
Sampling and Quantization – August 2009 Page 12