Professional Documents
Culture Documents
Handout - 4 Sampling
Handout - 4 Sampling
Using Matlab
2
Introduction
• Continuous-time (analog) signals can be converted into
discrete-time (digital) signals using sampling and
quantization operations: analog-to-digital conversion
(ADC or A/D).
• Digital signals can be converted into analog signals using a
reconstruction operation: digital-to-analog conversion
(DAC or D/A).
• Using Fourier analysis, we can describe the sampling
operation from the frequency-domain view-point, analyze
its effects and then address the reconstruction operation.
• We will also assume that the number of quantization levels
is sufficiently large so that the effect of quantization on
discrete signals is negligible.
3
The Sampling Theorem
A/D Converter
4
The Sampling Theorem
Discrete-time signals are usually formed by periodically sampling a
continuous-time signal where:
𝑇𝑠 : the sampling period in seconds
𝐹𝑠 = 1/𝑇𝑠 : the sampling frequency in samples per second (or Hz)
5
The Sampling Theorem
Mathematically, the sampling process can be viewed by multiplying the
analog signal 𝑥𝑎 𝑡 by a periodic sequence of impulses 𝑠𝑎 𝑡 with
sample spacing 𝑇𝑠 to get the sampled signal 𝑥𝑠 𝑡 .
The sample locations of the resulting signal is then mapped from 𝑛𝑇𝑠
into 𝑛 to generate the discrete-time signal 𝑥[𝑛] = 𝑥𝑎 (𝑛𝑇𝑠 )
6
The Sampling Theorem
• The periodic impulse train can be represented using the continuous-
time Fourier series (CTFS) as:
∞ ∞
1 2𝜋
𝑠𝑎 𝑡 = 𝛿(𝑡 − 𝑛𝑇𝑠 ) = 𝑒 𝑗𝑘Ω𝑠 𝑡 where Ω𝑠 =
𝑇𝑠 𝑇𝑠
𝑘=−∞ 𝑘=−∞
8
The Sampling Theorem
• This means that 𝑋 𝜔 is a countable sum of amplitude-scaled,
frequency-scaled, and translated version of 𝑋𝑎 Ω .
𝑋𝑎 Ω
𝑋 𝜔
9
The Sampling Theorem
Analog and digital frequencies
analog
frequencies
digital
frequencies
11
The Sampling Theorem
𝑋𝑎 Ω
• Band-limited signal 𝑥𝑎 (𝑡) is the
signal that has a maximum analog
frequency of Ω0 . (i.e., 𝑋𝑎 Ω is zero
for Ω > Ω0 rad/sec).
• The frequency 𝐹0 = Ω0 /2𝜋 is called the signal bandwidth in Hz.
Sampling Theorem:
A band-limited signal 𝑥𝑎 (𝑡) with a bandwidth 𝐹0 can be reconstructed
from its samples 𝑥[𝑛] if the sampling frequency 𝐹𝑠 = 1/𝑇𝑠 is greater
than twice the bandwidth 𝐹0 , that is 𝐹s > 2𝐹0 . Otherwise, aliasing
would result in 𝑥[𝑛].
𝑋 𝜔
13
The Effect of Aliasing
14
The Effect of Aliasing
Example
Solution
𝑥(𝑛)
18
Quantization Error
Signal-to-Quantization Noise Ratio (SQNR)
Quantization error
∆ ∆
𝑒𝑞 𝑛 = 𝑥𝑞 𝑛 − 𝑥(𝑛) − ≤ 𝑒𝑞 𝑛 ≤
2 2
where ∆ is the quantization step size (resolution). It is defined as:
𝑅 𝑅
∆= = 𝐵
𝐿 2
where
𝑅 = quantizer range = 𝑥𝑚𝑎𝑥 − 𝑥𝑚𝑖𝑛
𝐿 = number of quantization levels = 2𝐵
𝐵 = number of bits
19
Quantization Error
Signal-to-Quantization Noise Ratio (SQNR)
SQNR is given by
𝑃𝑥
SQNR = 10 log10 dB
𝑃𝑞
where
2
𝑃𝑥 = 𝑋𝑟𝑚𝑠 = average power of the input signal 𝑥(𝑛)
∆2 𝑅/2𝐵 2
𝑃𝑞 = quantization noise power = =
12 12
Therefore,
SQNR = 10 log10 𝑃𝑥 − 20 log10 𝑅 + 10.79 + 6.02𝐵
21
Quantization Error
Example:
The continuous-time signal 𝑥𝑎 𝑡 = 4 cos(1000𝜋𝑡) is sampled and
quantized with a resolution ∆= 0.01.
a) How many bits are required? (ans. 10 bits)
b) How many quantization levels? (ans. 1024)
c) What is the SQNR? (ans. 59.82 dB)
22
Reconstruction (D/A conversion)
1. Ideal interpolation
24
Reconstruction (D/A conversion)
2. Zero-order-hold (ZOH) interpolation
0.8
0.6
0.4
0.2
-0.2
-0.4
-2 -1 0 1 2 3 4 5 6 7 8
26
Reconstruction (D/A conversion)
3. First-order-hold (FOH) interpolation
27
Reconstruction (D/A conversion)
4. Cube-order-hold (COH) interpolation
28
Matlab Implementation
MATLAB:
Ts = 0.0002;
Fs = 1/Ts;
n = -25:25;
nTs = n*Ts;
% Discrete-time signal
x = exp(-1000*abs(nTs));
% Analog signal reconstruction
dt = 0.00005;
t = -0.005:dt:0.005;
% First-Order-Hold Interpolation
xa_FOH = interp1(nTs, x, t, 'linear');
% Cube-Order-Hold Interpolation
xa_COH = interp1(nTs, x, t, 'spline'); % xa_COH = spline(nTs, x, t);
plot(t, exp(-1000*abs(t)), t, xa_FOH, 'r', t, xa_COH, 'k')
% Check
error_FOH = max(abs(xa_FOH - exp(-1000*abs(t))))
error_COH = max(abs(xa_COH - exp(-1000*abs(t))))
Legend()
29
Matlab Implementation
1
Original signal
0.9 Linear interpolation
spline interpolation
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-5 -4 -3 -2 -1 0 1 2 3 4 5
-3
x 10
30
Useful Links
Sampling Theory
https://www.youtube.com/watch?v=iQaFDpiNOlA
Aliasing
https://www.youtube.com/watch?v=v7qjeUFxVwQ
31