Sampling and Quantization Manual
Sampling and Quantization Manual
Objectives
In this experiment, you will:
transforms a time-continuous signal 𝑥(𝑡) into a time discrete signal by extracting samples 𝑥[𝑛] of the input 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
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 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
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.
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 .
𝑑𝑡
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.
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
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.
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
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.
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.
7. Plot the power spectrum of the sampled signal using the Power Spectrum VI provided.
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.
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.
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.
TO DO Q15. What is the resulting bit rate? (you should use the values of the relevant panel controls)
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
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)
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 ……….