EE 422G

Signals and Systems Laboratory
Lab 1 Sampling and Quantization
Written by
Kevin D. Donohue
Department of Electrical and Computer Engineering
University of Kentucky
Lexington, KY 40506
January 17
, 20
1
3
Objectives:
Introduction to Matlab and Simulink features for signal analysis.
Apply Matlab to examine relationship between quantization bits and signal

to

noise
ratios (SNR).
Apply
Simulink
to examine
aliasing and the impact of
non

ideal
low

pass filtering for
recons
tructing a signal from its samples.
1.
Back ground
This laboratory exercise focuses on
the relationship between
noise and interference
resulting
from
digitizing
an analog signal. Digitization results in 2 types of noise. The first
i
s from
sampling a continuous

time (CT) signal
at
discrete
points in
time
,
which
causes
aliasing
.
I
f
th
e
signal
is not
sampled
at a rate higher than twice its highest frequency, then interference
from aliasing may occur.
The second type of noise results f
rom round
ing

off the sample
amplitudes to discre
te levels.
This rounding error results in an additive noise process referred
to as
quantization noise
.
Sampling
and A
liasing
:
A
mathematical representation of the sampling
operation
is given by
a
sequence of
impulse
functions
in continuous time
:
n
nT
t
t
s
)
(
)
(
,
(1)
w
here the impulses are separated by
T
seconds (sampling interval)
corresponding
to a
sampling frequency of
T
F
s
1
Hz.
The sampling function
s
(
t
)
is shown in Fig. 1
.
Figure 1.
Impulse train to model sampling operation.
t
s
(
t
)

3
T

2
T

T
0
T
2
T
3
T
…
…
1
It can be shown that the
Fourier Transform of
s
(
t
)
is
also
an im
pulse train
in the frequency
domain with impulse
s
separated by the sampling frequency
:
k
s
kF
f
T
f
S
)
(
1
)
(
ˆ
(2)
This
impulse train
is illustrated in Fig. 2.
Figure
2
.
Fourier transform of sampling impulse train that creates aliased spectra
.
Now consider a CT signal,
x
c
(
t
), that is bandlimited to
N
F
:
N
for
0
F
f
f
X
c
(3
)
where
N
F
is referred to as the
bandlimit
.
As an example, consider t
he Fourier Transform
of
bandlimited signal
presented in Fig. 3.
Figure 3
.
Example of Fourier Transform of a bandlimited continuous

time signal.
Consider sampling
x
c
(
t
) by multiplying it with
the impulse train of Eq. (1), which
effectively
zeros out the infor
mation between sampli
ng points
:
n
c
s
nT
t
t
x
t
x
)
(
)
(
)
(
.
(4
)
Now f
or a
linear time

invariant (
LTI
) system, multiplication
in the time domain corresponds
to
convolution in the frequency domain
, given by
:
d
kF
f
X
T
kF
f
T
f
X
f
X
k
s
c
k
s
c
s
)
(
)
(
ˆ
1
)
(
1
)
(
ˆ
)
(
ˆ
.
(5
)
F
N
f

F
N
1
X
c
(
f
)
)
(
ˆ
f
S

3
F
s

2
F
s

F
s
0
F
s
2
F
s
3
F
s
…
…
f
T
1
Since the convolution of a signal with
a shifted delta Dirac function, results in a shift version
of the signal, E
quation (5
) shows
that sampling
replicates
the original
signal
spectrum along
the frequency axis separated by
integer multiples of
the sampling frequency
F
s
.
The
convolu
tion integr
al of Eq. (5) becomes
:
k
s
c
s
kF
f
X
T
f
X
)
(
ˆ
1
)
(
ˆ
(6)
The aliasing described in
Eq. (6)
is illustrated in Fig.
4
for two
case
s
. Figure 4a
shows the
case when
the sampling frequency is greater than
twice
N
F
.
Figure 4b shows
the case when
the sampling frequency is
less than
twice
N
F
.
The
Nyquist frequency
defined as half
of the sampling frequency of a digital processing
system
. This is also referred to as the folding frequency since frequencies beyond this
value
fold back onto the non

aliased spectral range.
Note that when the conditions on the sampling
theorem are met
(i.e. Nyquist frequency is greater than
F
N
)
,
the aliased spectra do not
interfere with each other and the original signal can be recovered
from its samples
with an
idea low

pass filter.
When overlap between aliased spectra occurs, the
interference
results in
an irreversible noise
/distortion
process and
the original signal cannot be recovered.
A
liasing
in this case
irreversibly
degrades the
signal.
Bandlimit
F
N
is a property of the continuous

time signal and is sometimes referred to as the Nyquist rate.
Note:
The
Nyquist frequency is
a
property of the processing system while
Nyquist rate
is
a property
of the continuous

time
signal.
(a)
(b)
Figure 4
.
Aliased spectra when sampling rate is
(a)
greater than
twice the bandlimit;
N
s
F
F
2
, (b) less than twice the
bandlimit
,
N
s
F
F
2
.
X
s
(
f
)
F
S

F
N
f
F
S

2
F
S

F
S
2
F
S
…
…
3
F
S

3
F
S
F
N
f

F
N
X
s
(
f
)
F
S

2
F
S

F
S
2
F
S
…
…
The derivation leading to Fig. 4
is the basis for the sampling theorem, which states that a
bandlimited signal can be recovered from it samples if it is sampled at a rate greater than
twice its highest frequency.
The recovery can be performed with ideal low

pass filtering or
sinc functi
on interpolation.
Note in Fig. 4a an ideal low

pass filter can be applied with a cut

off anywhere between
F
N
and
F
S

F
N
. This way the original spectrum is undistorted and the
aliased
spectra are all eliminated. For the sampled signal of
Fig. 4b
,
this is not possible
because the original spectrum overlaps with the aliased spectra. No cutoff exists to eliminate
the aliased spectra without distorting the original spectrum.
Quantization and Uniformly Distributed Additive Noise.
A discrete

time signal cannot be stored on a computer, since it
has continuous amplitudes.
Therefore, th
e amplitude
s
must also be converted to discrete levels to
be
store
d
as binary
words
in
a
computer memory.
Figure 5 illustrates the quantization proces
s.
(a)
(b)
(c)
Figure 5.
(a) CT signal, (b) corresponding discrete

time
signal, (c)
digital
signal
quantized
to 4 levels corresponding to a 2 bit word per sample.
For or real signals t
he
error from round

off to the nearest quantization level is effectively a
random
noise process. The error can be modeled by subtracting
the distance from the
discrete

time signal amplitude to the nearest quantization level
, given by
:
)
(
)
(
)
(
nT
x
nT
x
nT
n
q
c
q
,
(7
)
w
here
x
q
(n
T
) is the signal value after roundi
ng off to a quantization level.
Noise processes are
modeled as random variables (RV)
with probability distribution
s
to
describe their amplitude variations
. If noise samples are uncorrelated from sample to sample,
the
process is called
white noise
and has a flat average spectrum (equal energy is expected at
a
ll frequencies). The noise amplitude values
are
modeled with
normal distribution
s for many
natural
processes
. However
,
quantization noise
is
typically modeled with a uniform
distribution,
since the amplitude
s
of
n
q
are expected with equal probability
between
the
quantization levels
.
Let
denote the distance between quantization levels. Then the
probability density function for
RV
n
q
is give
n
as:
)
(
t
x
c
)
(
nT
x
c
)
(
nT
x
q
Elsewhere
0
2
Δ
2
Δ
for
1
)
(
q
q
n
n
p
(8
)
Noise and signal relationships are often described in terms of their power ratios. For a noise
process mode
led as a
zero

mean
RV
, its
power is the same as
its
variance
. In the case of the
uniform distribution, the variance or power is given by
12
2
2
n
(9
)
a
nd the rms
value is equivalent to
its standard deviation (
i.e.
squ
are root of
ex
pression in
Eq.
(9
)).
In a classic derivation of the SNR for qua
ntization noise,
the signal is
assumed
to be
a
sinusoid with
amplitude
A
such that it extends
from the highest to
lowest
quantization levels.
Given the signal amplitude
extends to
the f
ul
l

scale range of the quantizer (2
A
),
can be
expressed
in terms of
A
for a specified number of bits
(
R
)
of
the computer word
used for
signal amplitude representations
.
The
SNR for a quantized full

range sinusoid
in dB is given
as:
dB
)
1
2
(
log
20
7609
.
1
)
(
10
R
q
R
SNR
.
(10
)
For large
R
(i.e. greater than 4)
, the minus 1 is ignored and
Eq. (10
) is often approximated as:
dB
6
7609
.
1
)
(
R
R
SNR
q
,
(11
)
which lead
s
to an oft
en
quoted
rule

of

thumb that 6dB SNR is gained
for each
additional
bit
used to encode (qu
antize) the sampled
signal.
Note that the SNRq formula for Eq. (10) only
applies to a sinusoid that fills the full range of the quantizer. If the sinusoid does not extend
from the highest to lowest quantization level, then the SNR values will be less. T
his idea is
developed in one of the pre

lab exercises.
2.
Pre

L
ab
oratory
Assignment
1.
Consider quantizing the signal
)
2
cos(
8
)
(
t
t
x
Volts
.
a)
For one full period, sket
ch the results of quantizing
x
(
t
) uniformly with a 3 bit
word
, where the highest
quantization level
is set to
7
volts
and
the lowest level is
set to

7
volts
.
What
is
(from Eq. (8)) in this case
?
Assume a sampling rate of
10 where the first sample occurs at t=0, compute the mean and variance of the
quantization noise. Is this clos
e to what you would expect (see Eq. (9))? Why are
there differences?
b)
For one full period, sketch the results of quantizing
x
(
t
) with 1 bit, where one
quantization level is set to

4 volts and the other to 4 volts.
Would you expect to
hear/see quantization
noise
or distortion
if a signal was quantized in this way?
c)
Create a table where first column is the
number of quantization
bits and the
second column is
the expe
cted SNR
q
as computed from Eq. (10
)
for
R
from
1
to
16.
2.
Consider a
n 8

bit
quantizer
with a Full

Scale range from

8 to +8
volts.
a) Compute the SNRq for a non

aliased sinusoid with amplitude 1 volt. Describe
how and why this differs from the SNR
q
computed in the 8 bit table entry of Problem
1.
b) De
scribe what occur
s when a sinusoid with a10
volt
amplitude is presented to this
quantizer. Can
the overload error (clipping) best described as
noise
or distortion
?
Provide a reason for your answer.
3.
Consider a sy
stem with a sampling rate of
f
s
=
100
0
Hz
.
For the frequency range of 0
to
f
s
, sketch the DTFT magnitudes for each of the CT signals after sampling. Be sure
to explicitly label the frequency axis to denote the sinusoids position on the axis.
(a)
)
200
2
sin(
5
)
(
t
t
s
(b)
)
450
2
sin(
5
)
(
t
t
s
(c)
)
600
2
sin(
5
)
(
t
t
s
(d)
)
1250
2
sin(
5
)
(
t
t
s
(e)
)
2520
2
sin(
5
)
(
t
t
s
4.
Lab
oratory A
ssignment
This assignment
requires the
use
and modification of a Matlab
script
called
quant
_lab1.m
downloadable from the course materials
web
site
:
http://www.engr.uky.edu/~donohue/courses.html
Go to the EE422
mfile
link and
save the
quant_lab1.m
mfile
file to your computer. Open this
file in Matlab’
s editor to study the comments and
modify
the code to do the exercises. This
also requires additional data files to be downloaded from the course materials website under
the
EE422
data
link.
Quantization
1.
Use the Matlab script
quant_lab1
to create a
2

second
sinusoid with uni
t amplitude,
frequen
cy
261.626
Hz, sampled at
16kHz
,
and quantize the signal
using
values of
“R” bits ranging from 2 to 16.
(a)
Design an experiment to determine the maximum SNR level required for noise to
be heard by humans.
Create a table with each entry
(row)
containing
the
number
of quantization bits
,
the theoretical SNR from Eq. (10), the experimental SNR
computed in the
quant_lab1
script, and
an indication of
whether
quantization
noise/distort
ion was heard
(use
the
soundsc
function in Matlab to play the
sounds)
.
Decide on
a consistent way to determine when the quantization noise is
heard, i.e. keep the volume constant for all trials, stay approximately the same
distance from the speakers, decide the
noise was heard if a majority (or all
or …
)
group members heard it.
Don’t
vary procedures between experiments
or
quantization bit values
or else you
will add unnecessary variability into the
comparisons and skew results.
(b)
Copy a
figure
of the average power spectra
for a case when the quantization
noise was clearly heard and past
e to a file so it can be put in the results section of
your lab report.
(c)
Describe the sound of the
quantization noise and indicate
if
the nature
/timbre
of
the noise
changes for decreasing number of quantization bits.
In the discussion
section address the q
uestion,
“Is there a point at which you would no longer
considered quantization a noise process?”
(d)
Listen directly to the noise sequence produced by the 12 bit and 4 bit
quantization produced in part a. Describe the difference.
In the discussion
section
explain the reason for the difference in the nature of the sound.
Also
i
n the discussion section
,
compare the computed SNR
q
values to those
computed in the pre

laboratory exercises. Provide reasons for possible
discrepa
ncies. D
escribe how
quantization no
ise
appears in
the spectrum
(what does quantization noise look like in the frequency domain)
. Use the
figure of
part (
b
)
to help in your discussion
and make your point
.
2.
Repeat
Exercise 1 using a sine wave with frequency 200 Hz.
In the discussion
section
, d
escribe and explain
observed
differences with part 1.
3.
Repeat Exercise 1 using wave file
mozart

1.wav
.
In the discussion
section,
d
escribe and explain
observed
differences with part 1.
In the discussion section for
preceding
Exercises 1,
2, and 3,
compare the 3 plots for
the average spectra and comment on differences
/similarities
observed for the
quantization noise and signals. Also comment on any difference
s
when the
qu
antization
noise became audible or changed
in nature
/timbre
(i.e. not just loud
er
noise, but a change in the way the original signal sounds).
Aliasing
From Matlab start the Simulink
prog
ram
by
either typing
simulink
at the
Matlab prompt, or
launching the Simulink
Library Browser
from the Matlab start menu button.
From the
L
ibrary
Browser
file menu, open a window for a new model.
From
the sub

libraries under
Simulink (sources) and
the Sig
nal Processing Blockset (Signal Operations, Signal Processing
Sinks, and Filtering)
populate the model space with the blocks as shown in Fig. 6.
Figure 6.
Simulink model of a sampling operation on a continuous

time signal using a
sample and hold
The sample

and

hold operation samples the signal
(from the signal generator
) on the rising
edge of the pulse generator and holds that value
constant
until the next sampling point
(
next
rising edge)
. So th
e pulse generator period is the
sampling interval for the analog

to

digital
conversion (ADC). The
sampled signal is plotted in
Time S
cope
, and the signal before
sampling is plotted in
Time S
cope1
for comparison. The FFT of the sampled signal is also
plotted
with (
Spectrum Scope
) to help identify
the signal frequency after sampling.
In order for the simulation to run properly,
parameters
need to be set
for each block and the
ove
r
all simulati
on. By double
clicking
each block element
,
a window
(dialog box)
appears
so that parameters can be set
. For the signal generator block
,
the frequency
and amplitude
must be set so
the proper sinusoid can be used to drive the system (Fig. 7a), the pulse
ge
nerator period must be set to achieve the desired
ADC
sampling rate (Fig. 7c), the FFT
(Spectrum Scope) parameters must be
configured
to define a window length over which the
FFTs are to be computed (Fig. 7b), and finally th
e simulation parameters
should
s
et
for
a
fixed step size (Fig. 7d). Typically
simulation
engine of Simulink
determines the time step
automatically based on the block settings
so the simulation is effectively continuous relative
to the timing
of the events generated by the blocks.
It must be set
for
fixed
time
so
the FFT
in
Spectrum Scope
can
sample data properly for its plots.
4.
Set the pulse generator to correspond to a sampling rate of
f
s
= 10
00
Hz. Set the
simulation time
(in
configuration parameters
)
to run from 0 to .1
seco
nds. This
window
is big enough to fit a single 10
Hz waveform. If a lower frequency is
generated, then a bigger simulation time must be set.
If there are too many periods
over
the simulation time
,
then it is hard to observe signal properties in the time
scope
windows.
So higher frequency waveforms
are
better observed in a smaller window.
There is a zoom on the graph window so the plots can be zoom in
on
if necessary.
Now set the signal generator
to
the frequenc
ies and amplitudes of those in pre

l
aborat
ory problem 3
(a) through (e). Copy the figures for the before and after time
waveforms as well as the Spectrum Scope for each case. Present these in your
results section
. In the discussion section describe key difference
s
between the
time signals before
and after sampling
,
and comment on diffe
rences between the
DTFT sketches in the pre

l
aboratory
a
ssignment
and
Spectrum Scope
output
.
5.
Now add an analog filter to the simulation to low

pass filter the output o
f the sample

and

hold operation as shown in
Fig. 8a.
Note the signal is analog after
it is low

pass
filtered,
so it must be resampled for the Spectrum Scope to process samples
and
display the FFT magnitudes
. Set the low

pass filter cut

off
(
or
edge

frequency) to a
value just less t
han half the samp
ling frequency
(i.e. 440
Hz) so the filter can roll

off
close to zero before crossing
beyond
the
half

sampling frequen
cy point. Now repeat
Exercise 4 with the low

pass filter processing the output.
In the dis
c
u
ss
ion
section
expla
in
differences observed
b
etween the filtered and non

filtered output
,
and
comment on the impact of the
(non

ideal)
low

pass filter in reconstructing a
sampled waveform.
(a)
(b)
(c)
(d)
Figure 7.
Dialog boxes for setting Simulink block and simulation parameters
(a) signal
generator (b) Spectrum Scope (FTT display) (c) Pulse Generator (d) overall simulation
configuration (from pull down menu
simulation
)
(a)
(b)
Figure 8.
(a) Simulink model for low

pass filtering sampled output. (b) Dialog box for
setting low

pass filter parameters (example shows cut

off at 225 Hz).
Enter the password to open this PDF file:
File name:

File size:

Title:

Author:

Subject:

Keywords:

Creation Date:

Modification Date:

Creator:

PDF Producer:

PDF Version:

Page Count:

Preparing document for printing…
0%
Σχόλια 0
Συνδεθείτε για να κοινοποιήσετε σχόλιο