0% found this document useful (0 votes)
21 views10 pages

Sampling and Quantization Manual

Uploaded by

Monif Sharanek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views10 pages

Sampling and Quantization Manual

Uploaded by

Monif Sharanek
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

EECE442L – Communications Laboratory 1

Sampling and Quantization

Department of Electrical and Computer Engineering

Faculty of Engineering and Architecture

American University of Beirut

EECE 442L – Communications Laboratory

Experiment on Sampling and Quantization

Objectives
In this experiment, you will:

 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.

Software Requirements: LabVIEW Com 2.0

I. Sampling and Reconstruction


The sampling process is an operation that is basic to digital signal processing and digital communications. It

transforms a time-continuous signal 𝑥(𝑡) into a time discrete signal by extracting samples 𝑥[𝑛] of the input signal

at equidistant time instants as shown in figure 1.

Figure 1- Sampling of analog signal

It is important to properly choose the sampling rate so that the obtained sequence of samples uniquely defines

the original analog signal. This is the essence of the sampling theorem and is necessary for perfect reconstruction

of the analog signal from the generated set of samples.


1
𝑥[𝑛] is obtained by extracting 𝑥(𝑡) every 𝑇𝑠 (s) where 𝑇𝑠 = is known as the sampling period.
𝐹𝑠
EECE442L – Communications Laboratory 2
Sampling and Quantization

Figure 2:Sampling Period

𝑥 [𝑛] = 𝑥(𝑡)|𝑡=𝑛𝑇 = 𝑥(𝑛𝑇), n=…-1,0,1,2… [1]

Figure 3: Illustration of the Sampling Process

The mathematical description of the sampled signal is 𝑠(𝑡) = 𝑥(𝑡) ∑𝑛 𝛿(𝑡 − 𝑛𝑇) = ∑𝑛 𝑥(𝑛𝑇)𝛿(𝑡 − 𝑛𝑇). In other
words it is a multiplication of a signal with an impulse train. As a consequence its Fourier Transform is
obtained by convolving the signal’s spectrum with an impulse train. Remember that the Fourier Transform of
an impulse train is an impulse train. Thus S(f)=X(f)*∑𝑛 𝛿(𝑓 − 𝑛/𝑇) = ∑ 𝑋(𝑓 − 𝑛/𝑇). The FT of 𝛿(𝑡 − 𝑛𝑇) is given
by 𝑒 𝑗 𝑛 𝜔 𝑇 . Hence S(f) can also be expressed as ∑𝑛 𝑥(𝑛𝑇) 𝑒 𝑗 𝑛 𝜔 𝑇 . If we set 𝑒 𝑗 𝑛 𝜔 𝑇 = 𝑧 −1 we obtain the Z-
transform expression ∑𝑛 𝑥(𝑛𝑇) 𝑧 −𝑛 . This form is often used to describe time-discrete signals.

The Nyquist Sampling Theorem

The sampling rate of 2W samples per second for a signal bandwidth of W hertz is called the Nyquist rate; its
1
reciprocal (measured in seconds) is called the Nyquist interval.
2𝑊

The Nyquist sampling theorem states that: “A signal can be recovered from its samples completely only if sampling is
done on the condition that the sampling frequency 𝐹𝑠 is equal or greater than twice the maximum frequency 𝐹𝑚 of the analog
signal, which is subjected to sampling”.
So, the sampling theorem is expressed as

𝐹𝑠 ≥ 2𝐹𝑚 [2]
EECE442L – Communications Laboratory 3
Sampling and Quantization

Note: In practice we can sample at a rate somewhat greater than 2𝐹𝑚 which makes reconstruction
easier.

Q1. What sampling rate must be exceeded in order to accurately reconstruct the following signal from its
samples?
TO DO
Tip: First find the bandwidth of the signal.

sin(2𝑓 𝜋𝑡)
𝑚(𝑡) = (𝑎𝑛𝑠𝑤𝑒𝑟 𝑓𝑜𝑟 𝑡ℎ𝑒 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛 𝑦𝑜𝑢 𝑔𝑒𝑡 𝑜𝑛 𝑀𝑜𝑜𝑑𝑙𝑒)
𝜋𝑡
Q2. Match the following

TO DO

Sampling a sine at fs=2f.

Sampling at a low rate

Sampling at a high rate

Lab Procedure

In parallel with following these instructions open the Moodle question blocks and record the answers to the
questions formulated.

A template for the experiment has been provided in the file Sampling_Template.gvi. To complete this template,
you will be asked to perform two tasks:

 Signal Sampling
 Signal Reconstruction

A. Signal Sampling

This part of the experiment aims to generate a sinusoidal signal and sample it.
EECE442L – Communications Laboratory 4
Sampling and Quantization

1. Open the file Sampling_Template.gvi. It contains some blocks that you will use to complete your VI.
Notice that some blocks were added to disable structure which comments some blocks out. Whenever a
VI is needed, drag it outside the structure.

2. Include, in your project, the subVI Basic Mutltitone.gvi which is provided to you. This VI is used as the
original waveform to be sampled.

Now, we need to create the impulse train that will be used to sample the signal. Our aim is to generate an impulse
train, so we need to create a single impulse, and specify the number impulses we need to generate. We need to
use the pulse train block and the impulse pattern block provided to you in the template:

3. The Impulse Pattern: generates a signal containing an impulse pattern. It is used as the prototype pulse,
which starts at zero in the time axis, for the prototype specification of the Pulse Train VI.

Figure 4: Impulse Pattern VI

Note: The Impulse Pattern VI added in the template can be found in the palette as Pattern
Generator block and choosing “Impulse” for Function Configuration.

a. Set 𝑇𝑠 (in the MathScript Node) as the inverse of the Sampling Frequency.

𝑇𝑠
b. Set the number of samples of the Impulse Pattern VI to .
𝑑𝑡

Tips: Use the Waveform Properties VI to get the dt of the signal.

c. Set the amplitude of the Impulse Pattern VI to the amplitude of the original waveform.

2. The Pulse Train: takes a specific prototype pulse, and generates N duplicates of pulses, repeated every
delay d of time, of this prototype. It constructs the pulse train using a specific interpolation method.

Figure 5: Pulse Train VI

a. In order to feed the pulse train, create the delay of the impulse train and the amplitude of the impulse
train pulses by completing the “MathScript” code:
EECE442L – Communications Laboratory 5
Sampling and Quantization

Its inputs are as follows:


 amplitude: the pulse amplitude.
 nbr_pulses: the number of pulses.
 Ts: the delay increment value.
In the mathscript’s first loop, for each element of the amplitude_array (it’s one of the outputs of the
MathScript Node), set it equal to the amplitude input provided.
Next, complete the second loop according to the tips below:

Tips:

 The delay is the spacing between the impulses. So you have to link it to the sampling frequency.
 The delay is incremental. i.e, the first impulse occurs at 0s, the second at Ts, the third at 2Ts and
so on…

b. Connect the dt input of the Pulse Train VI from the Waveform Properties VI of the original waveform in
order to get consistent time scaling among the different signals.

𝑇𝑠
c. Set the number of samples of the Pulse Train VI to 𝑛𝑏𝑟_𝑝𝑢𝑙𝑠𝑒𝑠 ∗ .
𝑑𝑡

d. Use the cluster to build the prototype specification input of the Pulse Train VI composed of the
impulse pattern and the dt of the original signal.

3. Use Build Waveform VI to build the waveform of the pulse train and take dt same as dt of the original
waveform.

4. Multiply the pulse train waveform with the original signal waveform using the multiple block already
provided in the template.

5. Plot the sampled waveform with the original one on the same graph using Build Array VI.

6. Set the following parameters in the Panel:


a. #tones= 1
b. start frequency=10Hz
c. delta frequency=10Hz
d. amplitude= 1
e. number of pulses = 100
f. pulse amplitude = 1

7. Run your VI after setting the appropriate sampling frequency to 4*fmax, because the impulse train
coincides with the zero crossings of the original signal at lower sampling frequency.

TO DO
Q3. What is the sampling frequency?
EECE442L – Communications Laboratory 6
Sampling and Quantization

Q4. What is the sampling period?


Q5. Add a screenshot of the original and sampled signal graphs.
TO DO

Up till this point, you have implemented a sampler.

B. Signal Reconstruction

Now, we need to reconstruct the signal from the discrete samples. We do this by convolving the samples with a
sinc waveform, thus implementing the following interpolation formula:

𝑡−𝑘𝑇
𝑦(𝑡) = ∑∞
𝑘=−∞ 𝑦[𝑘 ]𝑠𝑖𝑛𝑐 ( ) [3]
𝑇

1. Drag and drop all the blocks from the disable structure to the outside.

2. Include, in your project, the subVI sincWave.gvi which is provided to you. Set the delay Rs of the sincWave
VI equal to the sampling frequency.

3. Set the dt equal to the dt obtained from the original signal.

4. Apply convolution between the discrete sampled signal (the y values of the waveform ie. y values from
the Waveform Properties VI) and the sinc waveform using the 1D Convolution VI.

5. Plot the reconstructed signal using Build Waveform VI and set dt same as the dt of the discrete samples.

6. Set the following parameter in the Panel: nrPer= 10

7. Plot the power spectrum of the sampled signal using the Power Spectrum VI provided.

8. Run your VI.


Q6. Add a screenshot of the obtained reconstructed signal and compare it with the original one.
TO DO
Q7. Add screenshot of the power spectrum of the sampled sine wave. By looking at the “Original
Waveform and Sampled Signal Graphs”, explain why the spectrum turned out this way.

9. Set the sampling frequency to fmax and fmax/2 and run the VI. This is called aliasing. Aliasing refers to
the phenomenon of a high-frequency component in the spectrum of the signal seemingly taking on the
identity of a lower frequency in the spectrum of its sampled.
TO DO
Q8. Explain why it was difficult to reconstruct the signal. Add a screenshot of “original and sampled
graph” and the Reconstructed waveform graph for each of the two sampling frequencies.

10. Generate a three tone signal of frequencies 10, 20 and 30 Hz.

TO DO
EECE442L – Communications Laboratory 7
Sampling and Quantization

Q9. Calculate the sampling frequency (as we did in the first part) and run the VI again. Add a
screenshot of your obtained graphs in the panel.

As noticed, the sine wave needs to be over modulated at a sampling frequency= 4*fmax. Other
waveforms, especially finite ones would be enough to be sampled at Nyquiste. To observe this, replace
the sine wave with a sinc waveform VI provided to you (add a build waveform after it to get the
waveform and connect its dt and the dt control to the dt input of the sinc wave).
Configure the sinc block as follows: Rs=40, dtLV=0.001, and nrPer=10. Set the sampling frequency as
2*fmax to observe the mentioned difference.

Q10. Add a screenshot of the obtained reconstructed signal and compare it with the original one.
TO DO
Q11. Add screenshot of the power spectrum of the sampled sinc wave. Similarly as before, explain
why you got its frequency components as such (in terms of frequency).

Save your sampling experiment in a file whose name includes the letters “Sampling” and your initials
(e.g. Sampling_BAB.gvi).

II. 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 [xk , xk+1]. One of the basic choices in quantization is the number of discrete
quantization levels to use. The fundamental tradeoff in this choice is the resulting signal quality versus the
amount of data needed to represent each sample.

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 exhibit equally
spaced increments between possible quantized output levels are called uniform quantizers, otherwise they are
called non-uniform quantizers.

Figure 6: Analog-to-digital conversion process Figure 7: Quantized grap


EECE442L – Communications Laboratory 8
Sampling and Quantization

Lab Procedure
In parallel with following these instructions open the Moodle question blocks and record the answers to the
questions formulated.

1. Download and open Quantization.gvi and add the needed VIs provided to you in the SubVIs file.

2. Set the following values and run:


Quantity Value
Frequency 2000 Hz
Sampling frequency 44.4 kHz
Bits per sample 2
Choice of message signal Function generator
Signal type Sine Wave
Uniform? True
Fs 40000 Hz
#s 2000

Q12. What do the blue, red and green curves represent?


TO DO
Q13. Take a screenshot of the Quantization graph showing the values of x and q from their respective
indicators.

TO DO Q14. What are the four quantization levels?

TO DO Q15. What is the resulting bit rate? (you should use the values of the relevant panel controls)

3. Increase ‘Bits per sample’ to 4 and run the VI.


TO DO Q16. How many peaks are observed in the histogram and what do they represent?

Uniform vs non-uniform
With uniform quantization, the quantization intervals are all of the same length. However, the quantization
process introduces an error because the real amplitude of a sample is replaced by an approximate value. This
error is called quantization noise or quantization distortion.

The quantization error variance 𝜎𝑞2 of a uniform quantizer can be calculated as follows:

1 2
𝑥𝑚𝑎𝑥
𝜎𝑞2 = 2−2𝑅 𝑥𝑚𝑎𝑥
2
= [4]
3 3𝐿2

where 𝑥𝑚𝑎𝑥 is the maximum amplitude of the signal. The signal-to-quantization-noise-ratio of a uniform
quantizer can be calculated as follows:

𝜎2 3𝐿2 𝜎𝑥2
𝑆𝑁𝑅𝑞𝑈 (𝑑𝐵) = 10 log10 ( 𝑥2) = 10 log10 ( 2 ) [5]
𝜎 𝑞 𝑥 𝑚𝑎𝑥
EECE442L – Communications Laboratory 9
Sampling and Quantization

where 𝜎𝑥2 is the variance of the input signal. For the special case where the modulating signal is a sinusoid of
𝐴2𝑚
amplitude Am, its variance is 𝜎𝑥2 = , and using the number of bits per sample 𝑅 = log 2 𝐿 results in:
2

3
𝑆𝑁𝑅𝑞𝑈 (𝑑𝐵) = 10 log10 ( 𝐿2 ) = 6.02𝑅 + 1.76 [6]
2

TO DO Q17. Define the quantization error.

Q18. Fill the following table by running the VI with each of the following bits per sample values (for
TO DO
Calculated SNR, use equation 6).

Calculated
Bit per sample SNR(dB) error rms SNR(dB)

TO DO Q19. Complete the following statements:

 Based on equation 6 above, for every bit added the SNRq should improve by ……… dB
 As the number of quantization levels L increases, the value of R ……… and, thus, the SNR ……… and
the error ………
 ……… is the process of dividing the time domain into slots.
 ……… is the process of dividing the amplitude of the signal into slots.

Up till now we can observe from the histogram that the distribution of sample values is uniform, from the values
of x[k] and q[k] we can see that the quantization process is uniform as well. In certain applications, however, it
is preferable to use a variable separation between the representation levels. For example, the range of voltages
covered by voice signals, from the peaks of loud talk to the weak passages of weak talk, is on the order of 1000
to 1.

Q20. Assume we have a quantization error of 0.05V, and a high level signal such as 5V. Calculate the
TO DO noise ratio which is the quantization error over the high level signal.

Q21. For the same quantization error, calculate the noise ratio at a low level signal such as 0.5V.

Q22. So for uniform quantization, the signal to noise ratio is good for ……… level signals but bad for
at ……… level signals.

By using a non-uniform quantizer with the feature that the step size increases as the separation from the origin
of the input–output amplitude characteristic is increased, the large end-step of the quantizer can take care of
possible excursions of the voice signal into the large amplitude ranges that occur relatively infrequently. In other
EECE442L – Communications Laboratory 10
Sampling and Quantization

words, the weak passages that need more protection are favored at the expense of the loud passages. In this
way, a nearly uniform percentage precision is achieved throughout the greater part of the amplitude range of
the input signal, with the result that fewer steps are needed than would be the case if a uniform quantizer were
used.

In particular sound and voice sources show a strong non-uniform sample value distribution.

To show that, we will examine the sinc wave that has similar properties to sound and voice sources.

TO DO Q23. Set the Sinc wave as the choice of message signal and the number of bits per sample to 4. Run
the VI and take a screenshot of histogram of sample value distribution. What can you deduce from
the histogram about performing a uniform quantization on the sinc wave?

There are two types of non uniform quantization methods in popular use today: the A-law and the µ-law which
we will talk about during the next lab.

With the following settings we will explore a signal with a non-uniform distribution.

Turn the uniform button off on the front panel and choose the Function Generator as the message signal.

TO DO Q24. Run the VI with the following configuration and fill up the table below:

uniform Non-uniform
Bit per sample SNR(dB) error rms SNR(db) error rms

TO DO Q25. According to the observed SNR values, is the case of uniform quantization optimal?

TO DO
Q26. Complete the following statements:

 For ……… Quantization, the quantization step size remains same throughout the dynamic range
of the signal.
 For ……… Quantization, the quantization step size varies with the amplitude of the input signal.
 The higher sound quality we require, the more ……… we need and higher ……… for
transmission of the data representing the original message (in real-time) and, finally, larger
………
 Linear quantizing is not the optimum solution because at low signal levels the quantizing noise
is ………and the S/N is very ……….

TO DO Q27. Upload your VIs

You might also like