Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

Digital Signal Processing

Using Matlab

Sampling and Reconstruction


of Analog Signals
Overview
• Introduction
• The Sampling Theorem
• The Effect of Aliasing
• Reconstruction (D/A conversion)
• Quantization Error and SQNR

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

Basic parts of an analog-to-digital (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 Ω𝑠 =
𝑇𝑠 𝑇𝑠
𝑘=−∞ 𝑘=−∞

• The product of the input signal by this impulse train gives



1
𝑥𝑠 𝑡 = 𝑥𝑎 𝑡 𝑠𝑎 𝑡 = ෍ 𝑥𝑎 𝑡 𝑒 𝑗𝑘Ω𝑠 𝑡
𝑇𝑠
𝑘=−∞

• The continuous-time Fourier transform (CTFT) of the analog signal


𝑥𝑎 (𝑡) is defined as

𝑋𝑎 Ω ≝ න 𝑥𝑎 (𝑡) 𝑒 −𝑗Ω𝑡 𝑑𝑡
−∞

where Ω is an analog frequency in radians/sec


7
The Sampling Theorem
• According to the “shifting” property of the CTFT
if 𝑥(𝑡) ↔ 𝑋 Ω , then 𝑥(𝑡)𝑒 𝑗Ω𝑠𝑡 ↔ 𝑋 Ω − Ω𝑠

• Therefore, the CTFT of the sampled signal 𝑥s (𝑡) is


∞ ∞
1 −𝑗𝑘Ω 𝑡
1
𝑋𝑠 Ω = 𝐹 ෍ 𝑥𝑎 𝑡 𝑒 𝑠 = ෍ 𝑋𝑎 Ω − 𝑘Ω𝑠
𝑇𝑠 𝑇𝑠
𝑘=−∞ 𝑘=−∞

• It can be shown that the DTFT of 𝑥 𝑛 is



1 𝜔 2𝜋𝑘
𝑋 𝜔 = 𝑋𝑠 Ω ቚ 𝜔 = ෍ 𝑋𝑎 −
Ω=
𝑇𝑠
𝑇𝑠 𝑇𝑠 𝑇𝑠
𝑘=−∞

where 𝜔 = Ω𝑇𝑠 is the digital frequency in radian per sample.

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

• Ω is the analog frequency in rad/sec and 𝜔 is the digital


frequency in rad/sample. The analog and digital frequencies are
related through 𝑇𝑠 as follows:
𝜔 = Ω𝑇𝑠 rad/sample
• The sampling frequency 𝐹𝑠 is given by
1
𝐹𝑠 = sample/sec
𝑇𝑠
• The spectrum of sampled signal has:
– Amplitude scaled factor: 1/𝑇𝑠 ;
– Frequency-scaled factor: 𝜔 = Ω𝑇𝑠 (ω=0~2π);
– Frequency-translated factor: 2𝜋𝑘/𝑇𝑠 10
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 𝑥[𝑛].

• For a given signal bandwidth 𝐹0 , the minimum sampling rate 𝐹s = 2𝐹0


is known as the Nyquist Rate.
• For a given sampling rate 𝐹s , the maximum signal frequency 𝐹0 =
𝐹𝑠 /2 is called the Nyquist Frequency.
12
The Effect of Aliasing
𝑋 𝜔

𝑋 𝜔

13
The Effect of Aliasing

14
The Effect of Aliasing
Example

Determine the Nyquist Rate to sample this continuous-time signal:


𝑥 𝑡 = 3 cos 60𝜋𝑡 + 2 cos 340𝜋𝑡 .
What is the resulting discrete-time signal if we sample this signal at
(a) 𝐹𝑠 = 400 Hz (b) 𝐹𝑠 = 200 Hz?

Solution

This signal is composed of two sinusoidal signals of analog frequencies



Ω1 = 60𝜋  𝐹1 = 1 = 30 Hz
2𝜋

Ω2 = 340𝜋  𝐹2 = 2 = 170 Hz
2𝜋
So, the bandwidth of this signal is 𝐹0 = 𝐹2 = 170 Hz . The Nyquist rate
is therefor 𝐹𝑠 = 2𝐹0 = 340 samples/sec (Hz).
15
The Effect of Aliasing
(a) 𝐹𝑠 = 400 Hz (greater than the Nyquist rate) or 𝑇𝑠 = 0.0025 sec
𝑥 𝑛 = 𝑥 𝑡 |𝑡=𝑛𝑇𝑠
= 3 cos 60𝜋(0.0025𝑛) + 2 cos 340𝜋(0.0025𝑛)
= 3 cos 0.15𝜋𝑛 + 2 cos(0.85𝜋𝑛)
There is no aliasing in this case.

(b) 𝐹𝑠 = 200 Hz (less than the Nyquist rate) or 𝑇𝑠 = 0.005 sec


𝑥 𝑛 = 𝑥 𝑡 |𝑡=𝑛𝑇𝑠
= 3 cos 60𝜋(0.005𝑛) + 2 cos 340𝜋(0.005𝑛)
= 3 cos 0.3𝜋𝑛 + 2 cos 1.7𝜋𝑛
= 3 cos 0.3𝜋𝑛 + 2 cos(1.7𝜋𝑛 − 2𝜋𝑛) = 5 cos(0.3𝜋𝑛)
• There is an aliasing in this case
16
The Effect of Aliasing
Alias Frequencies

An alias frequency (𝐹0′ ) can be predicted as


𝐹0′ = 𝐹0 ± 𝑘𝐹s where 𝑘 = 1, 2, 3 ⋯
Example:
Find two different continuous time signals that will produce the
sequence 𝑥 𝑛 = cos(0.1𝜋𝑛) when sampled at 𝐹s = 10 kHz.
Solution:
𝑥 𝑡 = 𝑥 𝑛 |𝑛=𝑡𝐹𝑠 = cos 0.1𝜋 104 𝑡 = cos 1000𝜋𝑡
𝐹0 = 500 Hz
𝐹0′ = 𝐹0 ± 𝑘𝐹s = 9500 Hz, for example
𝑥 ′ 𝑡 = cos 2𝜋𝐹0′ 𝑡 = cos 19000𝜋𝑡
17
Quantization Error

𝑥(𝑛) Quantizer 𝑥𝑞 (𝑛)

𝑥(𝑛)

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𝐵

The SQNR increases approximately 6 dB for each additional bit.


20
Quantization Error
Example:
An Arduino microcontroller has a 10-bit ADC with 0-5 V input
range. If the input signal power is 2 V2 calculate the SQNR.
(ans. 60 dB)

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

Impulse train Ideal lowpass


x(n) conversion filter
xa (t )

• The ideal lowpass filter is band-limited to [−𝐹𝑠 /2, 𝐹𝑠 /2]


• The ideal interpolation is not practically feasible because the
entire system is noncausal and hence not realizable.
23
Reconstruction (D/A conversion)
1. Ideal interpolation

24
Reconstruction (D/A conversion)
2. Zero-order-hold (ZOH) interpolation

• In this method a given sample value is held for the sample


interval until the next sample is received.
• It can be obtained by filtering the impulse train through an
interpolating filter of the form

xˆa (t )  x(n), nTs  n  (n  1)Ts


1 0  t  Ts
h0 (t )  
0 otherwise

x(n) ZOH xˆa (t ) Post-Filter xa (t )


25
Reconstruction (D/A conversion)
2. Zero-order-hold (ZOH) interpolation
• The resulting signal is a piecewise-constant (staircase) waveform
which requires an appropriately designed analog post-filter for
accurate waveform reconstruction.

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

• In this case the adjacent samples are joined by


straight lines.
 t
1  T 0  t  Ts
 s
 t
h1 (t )  1  Ts  t  2Ts
 Ts
 0 otherwise


27
Reconstruction (D/A conversion)
4. Cube-order-hold (COH) interpolation

• This approach uses spline interpolation for a smoother, but not


necessarily more accurate, estimate of the analog signal
between samples.
• Hence this interpolation does not require an analog post-filter
• The smoother reconstruction is obtained by using a set of
piecewise continuous third-order polynomials called cubic
splines

xa (t )   0 (n)  1 (n)(t  nTs )   2 (n)(t  nTs ) 2   3 (n)(t  nTs )3 ,


nTs  t  (n  1)Ts

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

You might also like