Introduction To Digital Signal Processing
Introduction To Digital Signal Processing
Aalborg
Published, sold and distributed by:
River Publishers ApS
PO box 1657
Algade 42
9000 Aalborg
Denmark
Tel.: +4536953197
EISBN: 978-87-92982-03-2
ISBN: 978-87-92329-12-7
c 2008 River Publishers
v
This page intentionally left blank
Acknowledgments
Stanley H Mneney
University of KwaZulu-Natal
vii
About the Author
Prof S. H. Mneney
Pr. Eng., B.Sc.(Hons)Eng., M.A.Sc., Ph.D., SMSAIEE, MIET
Stanley Henry Mneney was born in Arusha in Tanzania and attended
primary and secondary school in the same town. He completed the
Cambridge O-level and the Tanzania National form 6 examinations
with the maximum passes possible. He was admitted to the University
of Science and Technology in Kumasi, Ghana, in 1972 to study Electri-
cal Engineering and graduated in 1976, winning the Charles Deakens
award for being the best engineering student in that year.
While under the employment of the University of Dar es Salaam, in
Tanzania, he pursued a Master of Applied Science Degree at the Uni-
versity of Toronto in Canada and later did a sandwich PhD program
between the University of Dar es Salaam and the Eindhoven University
of Technology, in the Netherlands. In the early stages of his PhD work,
he was awarded the 1984 Pierro Fanti International prize by INTEL-
SAT and TELESPAZIO based on one of his publications.
Prof. S. H. Mneney has worked at the University of Dar es Salaam, the
Universty of Nairobi, the University of Durban Westville, the Univer-
sity of Natal and is currently employed by the University of KwaZulu-
Natal as Professor of Telecommunications and Signal Processing and
is the current Head of School of Electrical, Electronic, and Computer
Engineering. He is married with two children, now young adults.
ix
x
xi
xii
xv
xvi Contents
References 241
Appendix 243
Index 261
This page intentionally left blank
1
Introduction to Digital Signal Processing
1
2 Introduction to Digital Signal Processing
Fig. 1.4 The sampling process in the frequency domain for a large sampling rate fs .
Fig. 1.5 The sampling process in the frequency domain for fs < 2fm .
use a low resolution ADC (one bit quantizer) with a sampling rate many
times higher than the Nyquist rate.
The output of the processor is binary and may be required to be
converted to an analog signal. This is achieved using a DAC device.
The DAC devices are simpler and lower in cost compared to the ADC
devices. The most common form of the DAC devices are the multiplying
devices; both the current source multiplying DAC and voltage source
multiplying DAC. The multiplying DAC devices are fast with settling
times of about 100 ns or less. Most of the commercially available DAC
are “Zero-Order-Hold”; they convert the binary input to an analog
level and hold until the next sample arrives. This results “staircase”
waveform and requires the use of a reconstruction filter to smoothen
the waveform, Figure 1.7.
We have looked at the peripheral input and output circuits required
in the implementation of a DSP system. These two circuits feed into and
out of the DSP processor. The processor itself may contain several units
such as the arithmetic logic unit (ALU), volatile memory unit for data
and program (RAM), non-volatile memory units (ROM), and buses
2.5
d(n)
2 s(n)
x(n)=d(n)+s(n)
1.5
0.5
Amplitude
-0.5
-1
-1.5
-2
-2.5
0 5 10 15 20 25 30 35 40 45 50
Time Index n
2
s(n)
1.5 y(n)
0.5
Amplitude
-0.5
-1
-1.5
-2
0 5 10 15 20 25 30 35 40 45 50
Time Index n
Fig. 1.21 The impact of the moving average filter on the noisy signal.
0
2 3 4 5 6 7 8 9 10 11
0. 5
0
2 3 4 5 6 7 8 9 10 11
0.5
0
2 3 4 5 6 7 8 9 10 11
0
2 3 4 5 6 7 8 9 10 11
0.5
-0.5
-1
0 2 4 6 8 10 12 14 16 18 20
0.5
-0.5
-1
0 10 20 30 40 50 60 70 80
0.5
-0.5
-1
0 5 10 15 20 25 30 35 40
0.5
-0.5
-1
0 2 4 6 8 10 12 14
-1
1 2 3 4 5 6 7 8 9 10
(b) Up-sampled sequence
1
-1
0 2 4 6 8 10 12 14 16 18 20
(c) Interpolation by a factor of 2
1
-1
2 4 6 8 10 12 14 16 18 20
The key reasons for still using analog signal processors are
1.8 Problems
1.7.1 An analog signal made from three sinusoidal components is
given by x(t) = 3 sin(7Ω0 t) + 5 sin(5Ω0 t) + 7 sin(11Ω0 t). The
signal is sampled to form a discrete-time signal.
(i)
1.8 Problems 27
(ii)
(iii)
29
30 The Transform Domain Analysis: The Discrete-Time Fourier Transform
If we expand Equation (2.3) we obtain the real part and the imaginary
part of the DTFT
∞
∞
jω
X(e ) = x(n) cos(ωn) + j x(n) sin(ωn)
n=−∞ n=−∞
Solution
∞
∞
X(ejω ) = x(n)e−jωn = δ(n)e−jωn = 1.
n=−∞ n=−∞
Here the DTFT or the frequency spectrum of the unit sample sequence
is real and constant and with zero phase in the interval −π ≤ ϕ < π.
Solution
∞
∞
jω −jωn
X(e ) = x(n)e = αn µ(n)e−jωn
n=−∞ n=−∞
∞
∞
= αn e−jωn = (αe−jω )n
n=0 n=0
1
= since |αe−jω | < 1.
1 − αe−jω
32 The Transform Domain Analysis: The Discrete-Time Fourier Transform
1.5
0.5
-4 -3 -2 -1 0 1 2 3 4
ω /π
Phase spectrum alpha = 0.5
1
Phase, Radians
0.5
-0.5
-1
-4 -3 -2 -1 0 1 2 3 4
ω /π
Fig. 2.1 Plot for the magnitude and phase response for x(n) = αn µ(n) for α < 1.
2.1 The Discrete-Time Fourier Transform 33
Solution
∞
∞
X(ejω ) = x(n)e−jωn = − αn µ(−n − 1)e−jωn
n=−∞ n=−∞
−1
=− αn e−jωn .
n=−∞
Solution
∞
∞
∞
X(ejω ) = x(n)e−jωn = αn µ(n)e−jωn = αn e−jωn
n=−∞ n=−∞ n=0
∞
1
= (αe−jω )n = since |αe−jω | < 1.
1 − αe−jω
n=0
34 The Transform Domain Analysis: The Discrete-Time Fourier Transform
0.8
Magnitude
0.6
0.4
0.2
-4 -3 -2 -1 0 1 2 3 4
ω /π
Phase spectrum alpha = 2
4
Phase, Radians
-2
-4
-4 -3 -2 -1 0 1 2 3 4
ω /π
Fig. 2.2 Plot for the magnitude and phase response for x(n) = αn µ(n) for α > 1.
x 10
15 Magnitude Spectrum alpha = 1
6
Magnitude
0
-4 -3 -2 -1 0 1 2 3 4
ω /π
Phase spectrum alpha = 1
2
Phase, Radians
-1
-2
-4 -3 -2 -1 0 1 2 3 4
ω /π
Fig. 2.3 Plot for the magnitude and phase response for x(n) = αn µ(n) for α = 1.
36 The Transform Domain Analysis: The Discrete-Time Fourier Transform
Solution
π π ∞
1 1
x(n) = X(ejω )ejωn dω = 2πδ(ω − ω0 + 2πk)ejωn dω.
2π −π 2π −π k=−∞
Solution
N
1 − e−jω(N +1) −n −jωn
= 1 e .
1 − e−jω
n=0
Proof. Let the sequences x1 (n) and x2 (n) have the DTFTs
X1 (ejω ) and X2 (ejω ), respectively. Then
∞
jω
X1 (e ) = x1 (n)e−jωn and
n=−∞
∞
X2 (ejω ) = x2 (n)e−jωn .
n=−∞
also
∞
∞
X1 (ejω ) = x1 (n)e−jωn = x(n − n0 )e−jωn .
n=−∞ n=−∞
Let m = n − n0 . Then
∞
jω
X1 (e ) = x(m)e−jω(m+n0 )
n=−∞
∞
−jωn0
=e x(m)e−jωm = e−jωn0 X(ejω ).
n=−∞
(iii) The Differentiation Property: If a sequence x(n) has a DTFT
given by X(ejω ) then the sequence nx(n) has a DTFT given
jω )
by j dX(e
dω .
∞
Proof. By definition X(ejω ) = n=−∞ x(n)e
−jωn . Differ-
jω
entiating with respect to ω gives dX(e dω
)
= ∞ n=−∞ −
−jωn dX(ejω )
jnx(n)e , which can be written as j dω =
∞ jω
−jωn . This shows that j dX(e ) is DTFT of
n=−∞ nx(n)e dω
the sequence nx(n).
Proof. Let
∞
jω
X1 (e ) = x1 (n)e−jωn and
n=−∞
∞
X2 (ejω ) = x2 (n)e−jωn
n=−∞
∞
X3 (ejω ) = x1 (n) ⊗ x2 (n)e−jωn
n=−∞
2.3 Properties of the Discrete-Time Fourier Transform 39
∞
∞
= x1 (n − k)x2 (k)e−jωn .
n=−∞ k=−∞
Substituting m = n − k we get
∞
∞
jω
X3 (e ) = x2 (k) x1 (m)e−jω(m+k)
k=−∞ n=−∞
∞
∞
−jωk
= x2 (k)e x1 (m)e−jωm
k=−∞ n=−∞
Proof. Let
π
1
Y (ejω ) = X1 (ejϕ )X2∗ (ej(ω−ϕ) )dϕ.
2π −π
Then
π
1
y(n) = Y (ejω )ejωn dω
2π ω=−π
π π
1 1
= X1 (ejϕ )X2∗ (ej(ω−ϕ) )dϕejωn dω.
2π ω=−π 2π ϕ=−π
where x(k) is the weight and δ(n − k) gives location of the sample in
terms of the time instance the sample appears. Due to the linearity
property of the LTI system we can compute the response due to each
sample and add them up to obtain the output of the system as shown
in Equation (2.15).
∞
y(n) = x(k)h(n − k). (2.15)
k=−∞
Solution
The output sequence is given by the convolution sum as
∞
y(n) = x(k)h(n − k).
k=−∞
where b and a are row matrices representing the numerator and denom-
inator coefficients, respectively.
A program is developed below to show how the MATLAB functions
are applied to plot the frequency spectrum of a rational function given
0.5 0.5
Amplitude
Amplitude
0 0
-0.5 -0.5
-1 -1
-1 0 1 -1 0 1
ω /π ω /π
Magnitude Spectrum Phase spectrum
0.8 4
Phase, Radians
0.6 2
Magnitude
0.4 0
0.2 -2
0 -4
-1 0 1 -1 0 1
ω /π ω /π
in Equation (2.18)
0.0098 + 0.0393e−jω + 0.0590e−j2ω + 0.0098e−j3ω
H(ejω ) = .
1 − 1.9908e−jω + 1.7650e−j2ω − 0.7403e−j3ω + 0.1235e−j4ω
(2.18)
Program 2.1
% Plotting of the Frequency response of a rational function
% Enter the desired length of the DFT
k = input(‘Enter the number of frequency points = ’);
% Enter the numerator and denominator coefficients
num = input(‘Enter the numerator coefficients = ’);
den = input(‘Enter the denominator coefficients = ’);
% Compute the frequency response
w = -pi:pi/k:pi;
h = freqz(num, den, w);
46 The Transform Domain Analysis: The Discrete-Time Fourier Transform
subplot(2,2,1);
plot(w/pi, real(h)); grid
title(‘Real Part’);
xlabel(‘\omega/\pi’); ylabel(‘Amplitude’);
subplot(2,2,2);
plot(w/pi, imag(h)); grid
title(‘Imaginary Part’);
xlabel(‘\omega/\pi’); ylabel(‘Amplitude’);
subplot(2,2,3);
plot(w/pi, abs(h)); grid
title(‘Magnitude Spectrum’);
xlabel(‘\omega/\pi’); ylabel(‘Magnitude’);
subplot(2,2,4);
plot(w/pi, angle(h)); grid
title(‘Phase spectrum’);
xlabel(‘\omega/\pi’); ylabel(‘Phase, Radians’);
2.6 Problems
2.6.1 Determine the DTFTs of the following sequences:
(i) w(n) = β n µ(n − 2) for β < 1,
|
β n| |n| ≤ L
(ii) x(n) = , and
0 otherwise
(iii) y(n) = β n µ(−n − 4) for β > 1.
2.6.2 If x(n) is a real sequence with a DTFT X(ejω ) determine the
DTFT of x(−n) in terms of X(ejω ).
2.6.3 If X(ejω ) is the DFFT of a real sequence x(n), determine the
inverse DFTS of
(i) Xre (ejω ) (ii) Xim (ejω ) in terms of x(n).
2.6.4 For a sequence x(n) = [121013] for −1 ≤ n ≤ 4, without com-
puting the DTFT evaluate
(i) the DC component of the frequency,
2.6 Problems 47
π
(ii) the integral X(ejω )dω, and
−π
π jω 2
(iii) the integral −π |X(e )| dω.
2.6.5 A finite length sequence is given by x(n) = [1 2 3 2 1] for
0 ≤ n ≤ 4 has DTFT X(ejω ). Show that this sequence has a
linear phase.
2.6.6 The output of an FIR filter is given by the following equation:
y(n) = x(n) − 2x(n − 1) + 3x(n − 2) + 2x(n − 3) − x(n −
4). Show that the filter has linear phase.
2.6.7 If the complex sequence x(n) has a DTFT X(ejω ) prove the
following symmetry properties
(i) the DTFT of x(−n) is X(e−jω ),
(ii) the DTFT of x∗ (−n) is X(ejω ),
(iii) the DTFT of Re{x(n)} is 12 {X(ejω ) + X ∗ (e−jω )},
(iv) the DTFT of jIm{x(n)} is 12 {X(ejω ) − X ∗ (e−jω )}.
2.6.8 If the real sequence x(n) has a DTFT X(ejω ) prove the
following symmetry properties
(i) X(ejω ) = X ∗ (e−jω ) (ii) Xre (ejω ) = Xre (e−jω ) (iii)
Xim (ejω ) = −Xim (e−jω ).
2.6.9 An IIR filter frequency response is given by
jω 1 + e−jω
H(e ) = 0.0124
1 − 0.6386e−jω
1 + 1.5975e−jω + e−j2ω
×
1 − 0.9621e−jω + 0.5708e−j2ω
1 + 1.12724e−jω + e−j2ω
× .
1 − 0.5811e−jω + 0.8547e−j2ω
Using MATLAB to plot the following frequency responses
(i) magnitude response,
(ii) phase response,
(iii) of the real part of H(ejω ), and
(iv) the imaginary part of H(ejω ).
This page intentionally left blank
3
The Transform Domain Analysis: The Discrete
Fourier Transform
49
50 The Transform Domain Analysis: The Discrete Fourier Transform
Solution
N
−1
X(k) = x(n)WNkn for 0 ≤ k ≤ N − 1
n=0
X(k) = 0W40 + W4k + 0W42k + 0W43k = W4k for k = 0, 1, 2, 3
X(0) = 1, X(1) = −j, X(2) = −1, X(3) = j or as a row matrix X(k) =
[1, −j, −1, j].
Solution
N
−1
X(k) = x(n)WNkn for 0 ≤ k ≤ N − 1
n=0
X(k) = for k = 0, 1, 2, 3
X(0) = 1 + 1 + 1 + 1 = 4
3.1 The Discrete Fourier Transform 51
Solution
0
X(0) WN WN0 WN0 WN0 x(0)
X(1) W 0 WN1 WN2 WN3
N x(1)
= .
X(2) WN0 WN2 WN4 WN6 x(2)
X(3) WN0 WN3 WN6 WN9 x(3)
To simplify we must use the property of the twiddle factor that
for n > N, WNn = WNn N , where the operator N implies modulo N
operation.
Therefore substituting W44 = W40 , W46 = W42 , W49 = W41 in the
matrix equation we obtain
0
X(0) W4 W40 W40 W40 1
X(1) W 0 W 1 W 2 W 3 1
4 4 4 4
= .
X(2) W40 W42 W40 W42 1
X(3) W40 W43 W42 W41 1
Evaluating W40 = 1, W41 = e−i2π/4 = −j, W42 = (−j)2 = −1, W43 = (−j)
(−1) = j.
X(0) 1 1 1 1 1 4
X(1) 1 −j −1 j 1 0
= = ,
X(2) 1 −1 1 −1 1 0
X(3) 1 j −1 −j 1 0
Therefore X(k) = [4, 0, 0, 0], which is the same answer as we got in
Example 3.2.
3.2 MATLAB Plots of DFTs 53
−1 ∗
In order to find the IDFT we need to find WN = (WN ) . This is
obtained by conjugating each element of WN as follows:
x(0) 1 1 1 1 4 4 1
x(1) 1 1 +j −1 −j 0 1
4 1
= = = = .
x(2) 4 1 −1 1 −1 0 4 4 1
x(3) 1 −j −1 +j 0 4 1
0.5
0
0 5 10 15 20 25 30
Time Index n
Magnitude of the DFT samples
20
Magnitude
10
0
0 5 10 15 20 25 30
Frequency Index k
-2
0 5 10 15 20 25 30
Frequency Index k
Amplitude
1
0
0 5 10 15 20 25 30
Frequency Index k
Real part of x(n), the IDFT samples
1
Amplitude
-1
0 5 10 15 20 25 30
Time Index n
Imaginary part of x(n), the IDFT samples
0.5
Amplitude
-0.5
0 5 10 15 20 25 30
Time Index n
t = 0:2/(50*1000):1/50;
subplot(5,1,1)
y = square(2*pi*50*t); plot(t,y);
% The analog signal\index{analog signal} is sampled
to obtain a
digital signal\index{digital signal}
n = 0:N;
x = square(2*pi*n*1/50);
% Plot the time domain sequence
subplot(5,1,2)
stem(n,x);
title(‘Sequence in the Time Domain’);
xlabel(‘Time Index n’); ylabel(‘Amplitude’);
% Obtain and plot the magnitude and phase of the DFT
X = fft(x ,M);
% Plot the Magnitude of the DFT samples
subplot(5,1,3)
k = 0:1:M-1;
stem(k, abs(X))
title(‘Magnitude of the DFT samples’);
xlabel(‘Frequency Index k’); ylabel(‘Magnitude’);
subplot(5,1,4)
stem(k, angle(X))
title(‘Phase of the DFT samples’);
xlabel(‘Frequency Index k’); ylabel(‘Phase’);
{\%} Compute 512-point DFT x
XE = fft(x,512);
% Plot the frequency response
L = 0:511;
subplot(5,1,5)
plot(L/512,abs(XE));
hold
plot(k/M,abs(X),‘o’)
title(‘Estimation Spectrum of a Square Wave’)
xlabel(‘Normalised Angular Frequency’)
ylabel(‘magnitude’)
58 The Transform Domain Analysis: The Discrete Fourier Transform
Amplitude
1
0
-1
0 10 20 30 40 50
Time Index n
Magnitude of the DFT samples
Magnitude
40
20
0
0 10 20 30 40 50
Frequency Index k
Phase of the DFT samples
2
Phase
0
-2
0 10 20 30 40 50
Frequency Index k
Estimation Spectrum of a Square Wave
magnitude
40
20
0
0 0.2 0.4 0.6 0.8 1
Normalised Angular Frequency
Proof. Let the sequences x1 (n) and x2 (n) have the DFTs
X1 (k) and X2 (k), respectively. Then
N
−1
X1 (k) = x1 (n)WNkn for 0 ≤ k ≤ N − 1, and
n=0
N
−1
X2 (k) = x2 (n)WNkn for 0 ≤ k ≤ N − 1.
n=0
(ii) Circular Shift Property: If x(n) has DFT X(k) then the
DFT of the circular shift of x1 (n) = x(n − n0 N ) is given
by X1 (k) = W kn0 X(k).
Proof.
N
−1
X1 (k) = x1 (n)WNkn
n=0
N
−1
= x(n − n0 N )Wnkn for 0 ≤ k ≤ N − 1
n=0
Let m = n − n0 , then
N
−1
X1 (k) = x(mN )Wnk(m+n0 )
m=0
N
−1
= WNkn0 x(mN )WNkm for 0 ≤ k ≤ N − 1
m=0
(iii) Frequency Shift: If x(n) has DFT X(k) then the DFT of
x2 (n) = WN−k0 n x(n) is given by X2 (k) = X(k − k0 N ).
Proof.
N
−1
X2 (k) = x2 (n)WNkn
n=0
N
−1
= x(n)WN−k0 n Wnkn for 0 ≤ k ≤ N − 1
n=0
N
−1
(k−k0 )
= x(n)WN = X(k − k0 N ).
n=0
(iv) Circular Convolution: If y(n) is a circular convolu-
tion of two sequences x(n) and h(n), i.e., y(n) =
N −1
m=0 x(m)h(n − mN ) then the DFT of y(n) is given by
Y (k) = X(k)H(k).
62 The Transform Domain Analysis: The Discrete Fourier Transform
Proof.
N
−1
Y (k) = y(n)WNkn
n=0
N
−1 N
−1
= x(m)h(n − mN )WNkn for 0 ≤ k ≤ N − 1.
n=0 m=0
Proof.
N
−1
Y (k) = y(n)WNkn
n=0
N
−1
= x1 (n)x2 (n)WNkn for 0 ≤ k ≤ N − 1.
n=0
But
N −1
1
x1 (n) = X1 (l)WN−nl for 0 ≤ n ≤ N − 1.
N
l=0
Substituting we get
N −1
N −1
1
Y (k) = X1 (l)WN−nl x2 (n)WNkn .
N
n=0 l=0
3.4 Circular Convolution 63
Proof.
N
−1 N
−1 N
−1 N −1
1
2
|x(n)| = ∗
x(n)x (n) = X(k)WN−kn x∗ (n)
N
n=0 n=0 n=0 k=0
N −1 N −1
1
= X(k) x∗ (n)WN−kn
N
k=0 n=0
N −1
N −1
∗
1
= X(k) x(n)WNkn
N
k=0 n=0
N −1 N −1
1 1
= X(k)X ∗ (k) = |X(k)|2 .
N N
k=0 k=0
(a)
(b)
Fig. 3.5 (a) Sequences for circular convolution. (b) Graphical circular convolution.
66 The Transform Domain Analysis: The Discrete Fourier Transform
Solution
y(n) = 3m=0 x(m)h(n − m4 ) can be written in matrix form using
the concept of a circulant matrix as
y(0) 1 0 1 0 2 3
y(1) 0 1 0 1 1.5 2
= = .
y(2) 1 0 1 0 1 3
y(3) 0 1 0 1 0.5 2
3.4 Circular Convolution 67
Program 3.4
% Program to compute circular convolution
x = input(‘Input first sequence as a row matrix x = ’);
h = input(‘Input second sequence as a row matrix h = ’);
N = input(‘Desired length of output sequence N = ’);
k = 0:1:N-1;
% Plot the first Sequence
subplot(3,1,1)
stem(k,x,‘o’);
title(‘First sequence’);
xlabel(‘Time index n’); ylabel(‘Amplitude’);
% Plot the second Sequence
subplot(3,1,2)
stem(k,h,’o’);
title(‘First sequence’);
xlabel(‘Time index n’); ylabel(‘Amplitude’);
c = cconv(x,h,N);
subplot(3,1,3)
stem(k,c,‘o’);
title(‘First sequence’);
xlabel(‘Time index n’); ylabel(‘Amplitude’);
Solution
Use Program 3.4 above to obtain the following results (see Figure 3.6).
68 The Transform Domain Analysis: The Discrete Fourier Transform
First sequence
2
1.5
Amplitude
0.5
0
0 0.5 1 1.5 2 2.5 3
Time index n
Second Sequence
1
Amplitude
0.5
0
0 0.5 1 1.5 2 2.5 3
Time index n
0
0 0.5 1 1.5 2 2.5 3
Time index n
where WN = e−j2π/N .
The computation of X(k) requires N 2 complex multiplications and
N (N − 1) complex additions.
The process of decimation-in-time
where X00 (k) and X01 (k) are N/4-point DFTs and x00 (n) =
x0 (2r) = x(4m) and x01 (n) = x0 (2r) = x(4m + 2). For N =
8 eight four equations can be written relating N/2-point DFT
X0 (k) to two N/4-point DFTs X00 (k) and X01 (k).
0 X (0)
X0 (0) = X00 (0) + WN/2 01
X0 (1) = X00 (1) + WN/2 X01 (1)
1
2 X (0)
(3.23)
X0 (2) = X00 (0) + WN/2 01
4 X (1)
X0 (3) = X00 (1) + WN/2 01
Fig. 3.9 Flow graph N/2-point decimation-in-time FFT algorithm to produce X0 (k).
2 X (0)
(3.25)
X1 (2) = X10 (0) + WN/2 11
4 X (1)
X1 (3) = X10 (1) + WN/2
11
Fig. 3.10 Flow graph N/2-point decimation-in-time FFT algorithm to produce X1 (k).
Fig. 3.11 Combined flow graph for the decimation-in-time FFT algorithm.
Fig. 3.13 The complete flow graph for the decimation-in-time FFT.
3.6 Problems
3.6.1 Suppose x(n) is a complex sequence of length N with
an N -point DFT X(k). Find the DFTs of the following
sequences in terms of X(k).
(i) x∗ (n) (ii) Re {x(n)} (iii) jIm x(n).
3.6.2 Given a real x(n) sequence of length N with an N -point DFT
X(k) prove the following symmetry relations
(i) X(k) = X ∗ (−kN ).
(ii) Re X(k) = Re X(−kN ).
(iii) Im X(k) = −Im X(−kN ).
80 The Transform Domain Analysis: The Discrete Fourier Transform
where s = σ + jΩ.
If the analog signal is sampled at a rate 1/T , where T is the sampling
interval, to obtain a discrete-time signal then Equation (4.1) becomes
∞
∞
−(σ+jΩ)nT
X (s) = x (nT )e = x (nT )(eσT ejΩT )−n . (4.2)
n=−∞ n=−∞
81
82 The Transform Domain Analysis: The z-Transform
ROC is the region for which z > 1. X2 (z) has a zero at z = 0 and
a pole at z = 1, Figure 4.1. ROC is bounded by the circle through the
pole on the inside.
The unit step sequence is a causal sequence which means that unit
step sequence has no nonzero valued samples for negative values on n.
Notice that the ROC is exterior to a circle of unit radius.
∞
∞
∞
−n n −n
X3 (z) = x3 (n)z = α µ(n)z = αn z −n
n=−∞ n=−∞ n=0
∞
1
= (αz −1 )n = for |αz −1 | < 1. (4.9)
1 − αz −1
n=0
1
Hence X3 (z) = 1−αz −1
and ROC is |z| > α.
X3 (z) has a pole at z = α and a zero at z = 0. The ROC is similar
to that of Figure 4.1 except that the pole position is at z = α instead
of z = 1.
The causal exponential sequence has a region of convergence that
is also exterior to a circle of radius α. In general, whenever a sequence
is causal or right-sided, the region of convergence of its z-transform is
always exterior to a circle of some specified radius.
A right-sided sequence is that sequence that has no nonzero val-
ued samples to the left of a reference sample m. The reference sample
m may be negative or positive. If it is positive then the sequence is
causal.
where µ(n) is a unit step sequence. Notice that µ(−n − 1) has unit
values to the left of n=0 and has zero values elsewhere. The neg-
ative sign on the sequence has been intentionally placed there for
the sake of comparison which will become clear after finding the
z-transform.
∞
∞
X4 (z) = x3 (n)z −n = −αn µ(−n − 1)z −n
n=−∞ n=−∞
−1
= −αn z −n .
n=−∞
4.1 Introduction to the z-Transform 85
Let m = −n
∞
∞
−m m −1 1
X4 (z) = −α z =α z −α−m z m
m=1 m=0
1
= −α−1 z 1 × for |α−1 z 1 | < 1,
1 − α−1 z 1
which can be written as
1
X4 (z) = for |Z| < α. (4.11)
1 − αz −1
X4 (z) has a zero at the origin and a pole at the z = α. The ROC is
bounded by the circle through the pole on the outside (see Figure 4.2).
Notice that the anti-causal sequence has a region of convergence that
is interior to a circle of radius α. Whenever a sequence is anti-causal or
left-sided the region of convergence of its z-transform is always interior
to a circle of some specified radius.
A left-sided sequence is that sequence that has no nonzero valued
samples to the right of a reference sample m. The reference sample
m may be negative or positive. If it is negative then the sequence is
anti-causal.
It should also be noted that the z-transforms of X3 (z) and X4 (z)
are the same except for their regions of convergence. In order to specify
the z-transform of a unique sequence the ROC must be given.
86 The Transform Domain Analysis: The z-Transform
Solution
z n−1
X(z)z n−1 = .
(z − 2)(z − 4)
The function has a simple pole at z = 0 when n = 0 and no poles at
z = 0 for n > 0. There are also simple poles at z = 2, and at z = 4 for
all values of n. The residue at z = 0 is given by
z z n−1 1
Resz=0 = = for n = 0,
1! (z − 2)(z − 4) 8
z−2 z n−1 1
Resz=2 = =− for n = 0
1! (z − 2)(z − 4) 4
and
z−4 z n−1 1
Resz=4 = = for n = 0
1! (z − 2)(z − 4) 8
1 1 1
x(0) = − + =0
8 4 8
88 The Transform Domain Analysis: The z-Transform
For n > 0
z−2 z n−1 1
Resz=2 = = − 2n−1 ,
1! (z − 2)(z − 4) 2
z−4 z n−1 1
Resz=4 = = 4n−1 .
1! (z − 2)(z − 4) 2
1 n−1
x(n) = Resz=2 + Resz=4 = (4 − 2n−1 ) for n ≥ 0 or
2
1
= (4n−1 − 2n−1 )µ(n).
2
λl = (1 − ξl )H(z)|Z=ξl . (4.20)
It may be possible that ROC is bounded by two poles (i.e., ξk < |z| < ξj ,
then the inverse z-transform will have a combination of causal and anti-
causal sequences depending on whether ROC is exterior or interior to
a circle through the specific pole (see Figure 4.3).
1
Example 4.7. Determine the inverse z-transform of X(z) = (z−2)(z−4)
for |z| > 2 using the method of partial fraction expansion.
90 The Transform Domain Analysis: The z-Transform
Solution
Expressing X(z) as a function of z −1 we get
z −2
X(z) = for |z| > 2.
(1 − 2z −1 )(1 − 4z −1 )
Both the numerator and the denominator are second-order polyno-
mials of z −1 and X(z) must be converted to a proper fraction by long
division giving
1 6z −1 − 1
X(z) = 1+ .
8 (1 − 2z −1 )(1 − 4z −1 )
The second term can be expanded using partial fraction expansion as
6z −1 − 1 λ1 λ2
= + .
(1 − 2z −1 )(1 − 4z −1 ) 1 − 2z −1 1 − 4z −1
−1 6z −1 − 1 1
λ1 = (1 − 2z ) −1 −1
|z −1 = = −2.
(1 − 2z )(1 − 4z ) 2
6z −1 − 1 1
λ2 = (1 − 4z −1 ) | −1 = = 1.
(1 − 2z −1 )(1 − 4z −1 ) z 4
1 −2 1
X(z) = 1+ + .
8 (1 − 2z −1 ) (1 − 4z −1 )
1 1 1
x(n) = δ(n) − (2)n µ(n) + (4)n µ(n).
8 4 8
4.2 The Inverse z-Transform 91
This result can be shown to be equal to the result of Example 4.6. Notice
that x(0) = 0 giving the same answer as with the residual method. For
n > 0, δ(n) = 0 and the two expressions for x(n) obtained by the two
methods are identical.
where the constants λi are the residues and are computed in the same
manner as for simple poles, the constants χI are computed using the
formula
1 dL−1
χi = L−1
(L − i)!(−ξυ ) d(z −1 )L−1
× (1 − ξυ z −1 )L H(z) |z=ξυ for 1 ≤ i ≤ L. (4.24)
1
Example 4.8. Determine the inverse z-transform of X(z) = (z−2)(z−4)
for |Z| > 2 using the method of long division.
Solution
We can write
1 z −2
X(z) = =
(z − 2)(z − 4) 1 − 6z −1 + 8z −2
z −2 − 6z −3 + 28z −4 + 120z −5 +
1 − 6z −1 + 8z −2 z −2
z −2 − 6z −3 + 8z −4
+ 6z −3 − 8z −4
6z −3 − 36z −4 + 48z −5
+ 28z −4 − 48z −5
+ 28z −4 − 168z −5 + 224z −6
+ 120z −5 − 224z −6
+ 120z −5 − 720z −6 + 960z −7
496z −6 − 960z −7
...........................
The inverse z-transform of X(z) is then given by
x(n) = δ(n − 2) + 6δ(n − 3) + 28δ(n − 4) + 120δ(n − 5) + · · · .
The long division method does not give a closed form expression
while the methods of residue and partial fraction expansion give a
closed form expression.
Let X(z) = Z{x(n)} with ROC Rx , and Y (z) = Z{y(n)} with ROC Ry .
Proof. By definition
∞
X(z) = x(n)z −n
n=−∞
94 The Transform Domain Analysis: The z-Transform
and also
∞
∞
−n
X1 (z) = x1 (n)z = x(n − n0 )z −n .
n=−∞ n=−∞
Let m = n − n0 . Then
∞
X1 (z) = x(m)z −(m+n0 )
n=−∞
∞
= z −n0 x(m)z −m = z −n0 X(z).
n=−∞
(iii) Differentiation Property: If a sequence x(n) has a z-transform
given by X(z) then the sequence nx(n) has a z-transform
given by −z dX(z)
dz .
Proof. By definition X(z) = ∞ n=−∞ x(n)z
−n . Differentiat-
ing with respect to z gives dX(z)
dz =
∞
n=−∞ −nx(n)z
−n−1 ,
which can be written as −z dX(z)
dz =
∞
n=−∞ nx(n)z
−n . This
Proof. Let
∞
X1 (z) = x1 (n)z −n
n=−∞
and
∞
X2 (z) = x2 (n)z −n
n=−∞
∞
X3 (z) = x1 (n) ⊗ x2 (n)z −n
n=−∞
∞
∞
= x1 (n − k)x2 (k)z −n .
n=−∞ k=−∞
4.3 Properties of z-transforms 95
Substituting m = n − k we get
∞
∞
X3 (z) = x2 (k) x1 (m)z −(m+k)
k=−∞ n=−∞
∞
∞
= x2 (k)z −k x1 (m)z −m = X2 (z)X1 (z)
k=−∞ n=−∞
(v) Multiplication by an Exponential Sequence: If a sequence
x(n) has a z-transform X(z), then a sequence αn x(n) has a
z-transform X(z/α).
Proof. Let
∞
X( z) = x(n)z −n
n=−∞
and
∞
X1 (z) = αn x(n)z −n
n=−∞
∞
z −n
z
= x(n) =X
n=−∞
α α
(vi) Time Reversal Property: If a sequence x(n) has a z-transform
X(z), then a sequence x(−n) has a z-transform X(1/z)
where x(n) is the input and y(n) is the output of the system, ak and
bk are constant coefficients. The order of the system is the max(N, M ).
You can solve for the current output by making y(n) the subject of the
formula.
M
N
y(n) = bk x(n − k) − ak y(n − k). (4.27)
k=0 k=1
We can obtain the z-transform of the system by using the linearity and
the time-shifting properties as follows:
N
M
Y (z) ak z −k = X(z) bk z −k . (4.28)
k=0 k=0
b0 + b1 z −1 + b2 z −2 + · · · + bM z −M
= . (4.29)
a0 + a1 z −1 + a2 z −2 + · · · + aN z −N
If all the denominator coefficients were zero except a0 = 1, H(z) will
have a transfer function given by H(z) = b0 + b1 z −1 + b2 z −2 + · · · +
bM z −M . This represents the transfer function of a Finite Impulse
Response (FIR) filter. In this case the impulse response will be of
finite length and the coefficients of z −1 represent the impulse response
samples. Instead of using the numerator coefficient of H(z) we will use
the values of the impulse response to write the z-transform of the FIR
system.
Solution
Find the poles with respect to the unit circle. Factorize the denomina-
tor. Denominator polynomial = (0.5z + 1)(z + 0.5 + j0.59)(z + 0.5 −
j0.59). Pole positions at z = −2, z = −0.5 − j0.59 and −0.5 + j0.59
Pole–zero plot showing only poles.
4.6 Realization Structures 99
There is a pole outside the unit circle and therefore the system is
unstable.
(i) Replace all pickoff points with summers and vice versa.
(ii) Change the directions of all arrows.
Let
W (z)
H1 (z) = = b0 + b1 z −1 + b2 z −2
X(z)
and
Y (z) 1
H2 (z) = = .
−1
W (z) 1 + a1 z + a2 z −2
102 The Transform Domain Analysis: The z-Transform
ers it will not change the transfer function. It follows that the delays on
the parallel arms have the same inputs and will have the same outputs.
These delays can be merged to form the structure which is canonic
and is shown in Figure 4.9. This structure is referred to as Direct
form II structure. The transpose of Figure 4.9 gives the Direct form IIt
structure.
4.7 Problems
4.8.1 Find the z-transforms and the regions of convergence of the
following sequences
(i) x(n) = (0.5)n µ(n − 2),
(ii) x(n) = −(0.4)n µ(−n − 3),
(iii) x(n) = (−0.4)n µ(−n − 3).
4.8.2 Derive the z-transform and the region of convergence of
the sequence y(n) = (rn cos(ω0 n))µ(n). Hence obtain the
z-transform of the sequence w(n) = 2n cos π2 n µ(n).
4.8.3 Does the following sequence have a z-transform? w(n) =
2n µ(−n − 1) + 3n µ(+n + 1). Explain your answer.
4.8.4 Using the method of residues obtain the inverse z-transform
z(z−1)
of H(z) = (z−2)(z−3) for the following regions of convergence:
(i) |z| > 3, (ii) 2 < |z| < 3, and (iii) |z| < 2.
4.8.5 Using the method of partial fraction expansion to find the
z(z−1)
inverse z-transform of H(z) = (z−2)(z−3) for the following
regions of convergence
(i) |z| > 3, (ii) 2 < |z| < 3, and (iii) |z| < 2.
4.8.6 Using the method of partial fraction expansion obtain
(1−1/2z −1 )
the inverse z-transform of H(z) = for
(1−1/3z −1 )(1−2z −1 )2
|z| > 1/3.
4.8.7 The transfer function of a causal discrete-time system is given
z
by H(z) = 3z 2 −4z+1 . Using long division find the first five
samples of the impulse response.
4.8.8 The impulse response of an LTI system is given
by h(n) = α0 δ(n) + α1 δ(n − 1) + α2 δ(n − 2) + α3 δ(n − 3).
Obtain the transfer function H(z) of the system.
4.8.9 A moving average filter is a linear time-invariant sys-
tem whose input/output relationship is given by y(n) =
1 M −1
M k=0 x(n − k). Obtain its impulse response and hence
its transfer function H(z).
4.8.10 A sequence is given by y(n) = ce−αn µ(n), where µ(n) is a
unit step sequence. Making use of table for z-transforms of
4.7 Problems 107
5.1 Introduction
The reason for the review of analog filter design before pursuing with
digital filter design is twofold. Analog filters are used as anti-aliasing
filters and reconstruction filters in digital signal processing. Secondly, a
popular design method of IIR filters is through special transformation
of analog prototype filters to digital filters. Therefore, it is necessary
to be able to specify, design, and implement analog filters.
109
110 Review of Analog Filter Design
-40
Magnitude in dBs
-60
-80
-100
-120
-140
-160
0 2 4 6 8 10
Normalized Frequency rad/s
The two equations can be used to solve for the order of the filter giving
(A2 −1)
1 log10 ε2 log10 k11
N= = . (5.7)
2 log10 ΩΩs log10 k1
P
5.3 The Analog Lowpass Filters 113
Despite the fact that the order of a filter must be an integer the
value of N computed from Equation (5.7) is rarely an integer. For this
reason the value of N computed from Equation (5.7) must be rounded
up to the next higher integer. The integer value of N can then be
used in either Equation (5.5) or (5.6) to solve for the cut-off frequency
ΩC . If Equation (5.5) is used then the passband specifications will be
met exactly and stopband specifications will be exceeded. On the other
hand, if Equation (5.6) is used the stopband specifications will be met
exactly and the passband specifications will be exceeded. The decision
on which equation to use is left to the designer who may base the
decision on the sensitivity of each band to the specific application.
The MATLAB function that uses the above equations to compute
the order and the cut-off frequency is buttord and the syntax is given as
given as
-20
-40
Magnitude dB
-60
-80
-100
-120
-140
0 500 1000 1500 2000 2500 3000
Frequency in Hz
Solution
MATLAB Program
0.7
0.6
Magnitude
0.5
0.4
0.3
0.2
0.1
0
0 0.5 1 1.5 2 2.5 3
Normalized Frequency
1 1
|Ha (jΩ)|2 =
Ωs
= ,
1+ ε2 TN2 Ω A2
p
The transfer function of the Chebyshev type I filter is of the same form
as that of the Butterworth filter given by Equation (5.9) and can be
expressed as a ratio of two polynomials. The coefficients of the rational
transfer function can be obtained by the MATLAB function cheby1
and the syntax is given by
Solution
MATLAB Program
0.9
0.8
0.7
0.6
Magnitude
0.5
0.4
0.3
0.2
0.1
0
0 500 1000 1500
Frequency in Hz
Fig. 5.5 Magnitude response of the Chebyshev type I filter of Example 5.2.
Rs = 50;
[N, Wc] = cheb1ord(Wp, Ws, Rp, Rs, ‘s’);
[B, A] = cheby1(N, Rp, Wc, ‘s’);
omega = [0:1:3*Wc];
h = freqs(B,A,omega);
plot(omega./(2*pi),(abs(h)),‘m’);
title(‘Chebyshev LPF Example 5.2’);
xlabel(‘Frequency in Hz’); ylabel(‘Magnitude’);
Solution
MATLAB Program
-20
-40
Magnitude
-60
-80
-100
-120
-140
0 500 1000 1500 2000 2500 3000
Frequency in Hz
Fig. 5.6 Magnitude response of the Chebyshev type II filter of Example 5.3.
1
Ha (jΩ) = , (5.19)
2 ξ, Ω
1 + ε 2 RN Ω0
√
Ωp 1 − k’
k= , k‘ = 1 − k 2 , and ρ0 = √ .
Ωs 2(1 + k’)
The MATLAB m-file function used to compute the order of the
lowpass filter is
In order to obtain the coefficients of the transfer function for the low-
pass filter we use
MATLAB Program
-20
-40
Magnitude dB
-60
-80
-100
-120
0 500 1000 1500
Frequency in Hz
Fig. 5.8 Magnitude response for the Elliptic filter of Example 5.4.
-10
-15
0 0.2 0.4 0.6 0.8 1 1.2 1.4
Normalized Frequency in rad/s
(N + k)! x k
N
θN (0)
H(s) = where θN (x) = . (5.23)
θN (s/Ω0 ) (N − k)!k! 2
k=0
1
For N = 3H(s) = 1+6x+15x 2 +15x3 where x = s/Ω0 .
Notice that H(s) has only poles and no zeros. In order to deter-
mine the numerator and denominator of the transfer function we use
MATLAB function
[B, A] = besself(N, Wc ).
The black line in Figure 5.9 is in fact the plot for phase-frequency
characteristics of the Bessel filter and is perfectly linear.
The penalty for perfect linearity in the phase-frequency character-
istic is in the magnitude response. This can be seen in the plots of
5.4 The Analog Highpass, Bandpass,and Bandstop Filters 125
-10
-20
Magnitude
-30
Butterworth
Chebyshev I
-40 Chebyshev II
Elliptic
-50 Bessel
-60
-70
-80
0 0.5 1 1.5
Frequency in rad/s
Figure 5.10. The Bessel filter has the slowest transition from the pass-
band to the stopband, followed by the Butterworth filter. The elliptic
filter has the sharpest roll-off in the transition region compared to the
rest of the filter.
Chart 5.1 Flow Chart for the design procedure for analog highpass filters.
128 Review of Analog Filter Design
Chart 5.2 Flow chart for the design procedure for analog bandpass filters.
5.4 The Analog Highpass, Bandpass,and Bandstop Filters 129
Solution
MATLAB Program
Results
Order of the lowpass filter 4
Order of the bandstop filter 8
0.5
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8
Frequency, Hz
Magnitude Response of the Bandstop Filter
1
Magnitude
0.5
0
0 1 2 3 4 5 6 7 8 9
Frequency, Hz x 10
8
132 Review of Analog Filter Design
5.5 Problems
5.5.1 An analog Butterworth lowpass filter is to be designed to
meet the following specifications:
Passband-edge frequency ΩP = 2π 500 rad/s
Stopband-edge frequency ΩP = 2π 1250 rad/s
Maximum passband attenuation = 1 dB
Minimum stopband attenuation = 30 dB
Determine the following
(i) the transition parameter,
(ii) the discrimination parameter, and
(iii) the order of the filter.
5.5.2 A second-order Butterworth lowpass filter with a cut-off fre-
quency of 1 kHz is to be designed. Obtain the transfer func-
tion of the filter and the pole positions on the s-plane.
5.5.3 An analog Chebyshev I lowpass filter is to be designed to
meet the following specifications:
Passband-edge frequency ΩP = 2π 500 rad/s
Stopband-edge frequency ΩP = 2π 750 rad/s
Maximum passband attenuation = 1 dB
Minimum stopband attenuation = 40 dB
Determine the following
(iv) the transition parameter,
(v) the discrimination parameter, and
(vi) the order of the filter.
Use MATLAB functions to verify the order of the filter.
Obtain the transfer function and plot the magnitude and
phase response of the filter.
5.5.4 Repeat Problem 5.5.3 if the desired filter is an elliptic filter.
5.5.5 A stage in a student project requires a highpass analog filter
that will remove the bass component of music from a CD.
Any music component below 500 kHz is to be attenuated by
at least 50 dBs and any music component above 550 kHz is
5.5 Problems 133
by more than 0.5 dB. The width between the passband edge
should be about 10 Hz. Design the appropriate filter giving
the filter order, the transfer function and plot of the magni-
tude response of the final filter. Choose a filter-type that will
give you the lowest order and steepest roll-off.
6
Digital Filter Design
6.1 Introduction
The objective of filter design is to find a stable function that is realiz-
able using a suitable filter structure to estimate a specified frequency
response or impulse response. There are two classes of filters based on
the length of their impulse response. The first class includes any filter
whose impulse response is of finite length. Such filters are referred to as
Finite Impulse Response (FIR) digital filters. These filters are always
stable and can be designed to have exactly linear phase. The second
class of filters includes any filter whose impulse response is of infinite
length. Such filters are referred to as Infinite Impulse Response (IIR)
digital filters. These filters are not always stable and cannot be designed
to have exactly linear phase. However, IIR filters have one significant
advantage over FIR filters. It is possible to approximate a specified
magnitude response using an IIR filter of a much lower order than that
of an FIR filter. This means that the computational complexity in the
implementation of an IIR filter is much less than that of an FIR filter
in order to achieve the same objectives.
The design procedure requires that the specifications of the filter
are developed from the intended application. The specifications must
be given such that the filter will introduce minimum distortion in the
desired bands of the signal. The ideal filter will have a gain of unity in
the passband and zero in the stopband with the transition bandwidth
that is zero. Such a filter is not realizable in practice as it is unsta-
ble and noncausal. In order to get a stable and realizable filter the
specifications are relaxed to allow some tolerance in the passband and
stopband and a gradual transition from the passband to the stopband.
The resulting specifications are very similar to those for the analog
135
136 Digital Filter Design
filters except it must be taken into account that the magnitude response
of a discrete-time system is periodic. The normalized specifications
are shown in Figure 6.1. The specification parameters are defined as
follows:
1
The maximum passband deviation = √1+ε2
√
The maximum passband attenuation = αmax = 20 log( 1 + ε2 )
The maximum stopband magnitude =1/A
The passband-edge frequency in radians/sample = ωp
The stopband-edge frequency in radians/sample = ωs .
Ω
Ω = tan or
2
ω = 2 tan−1 Ω. (6.5)
2
Angular digital frequencies
-1
-2
-3
-4
-20 -15 -10 -5 0 5 10 15 20
Angular analogue frequencies
Fig. 6.2 Mapping of angular analog frequencies to analog digital frequencies ω = 2 tan−1 Ω.
magnitude response is transformed into the digital filter using the bilin-
ear transformation.
It should be noted that the bilinear transformation preserves mag-
nitude responses that are piecewise linear and does not preserve the
phase response.
(iv) The transfer functions read from [1] given the filter order have
been normalized with respect the cut-off frequency. They
must be scaled up in frequency such that Ĥ(s) = H(s/Ωc ).
(v) Apply the bilinear transformation to obtain the digital filter
transfer function H(z) = Ĥ(s)|s= 1−z−1 .
1+z −1
Solution
(i) Compute the normalized digital frequencies
10
ωP = 2π = 0.314 rad/s and
200
60
ωs = 2π = 1.8850 rad/s
200
Pre-warp the digital frequencies to obtain the frequencies of
the analog LPF
ΩP = tan(0.314/2) = 0.1583 rad/s and
Ωs = tan(1.8850/2) = 1.3764 rad/s
Ω2c 0.1904
Ĥ(s) = √ = 2 .
2 2
s + Ωc 2s + Ωc s + 0.6172s + 0.1904
The problem can also be solved using MATLAB. The functions used
are shown in Program 6.1 in the appendix. In the bilinear transforma-
tion one can cancel out the impact of T by using T = 2. The program
does the pre-warping outside the bilinear function and therefore the
pre-warping option is not used.
144 Digital Filter Design
ˆ = tan ω
Prewarp Ω ( 2)
Equivalent Analogue Filter Specifications
Obtain: Ω
ˆ P, Ω
ˆ S,RP ,RS
Bilinear Transformation
Solution
Stopband edge frequency Ωs = 500 Hz
Passband edge frequency Ωp = 550 Hz
The minimum stopband attenuation Rs = 30 dB
The maximum passband attenuation RP = 1 dB
Select sampling frequency F s = 1200 Hz.
Using MATLAB the following results are obtained using Pro-
gram 6.2 in the Appendix.
Results
Prototype LPF
Cut-off frequency W c = 1.8190, Order N = 4
Transfer function:
0.03162s∧ 4 − 8.397e − 017s∧ 3
+0.8371s∧ 2 − 9.183e − 016s + 2.77
H(s)LP = ∧ .
s 4 + 3.21s∧ 3 + 5.179s∧ 2 + 4.904s + 2.77
Analog Highpass filter
Transfer function:
s∧ 4 − 2.528e − 015s∧ 3 + 39.48s∧ 2
−1.118e − 012s + 194.8
H(s)HP = ∧ .
s 4 + 20.24s∧ 3 + 244.3s∧ 2 + 1730s + 6161
6.2 IIR Filter Design 147
ˆ = tan ω
Prewarp Ω ( 2)
Equivalent Analogue Filter Specifications
(i) Obtain: Ω
ˆ P1 , Ω
ˆ P2 , Ω
ˆ S1 , Ω
ˆ S 2 , R P , R S (ii) If Ωˆ P1Ωˆ P 2 > Ωˆ S1Ωˆ S 2 then decrease
Ωˆ P1 = Ω
ˆ S1Ω
ˆ S2 Ωˆ P 2 or increase Ω ˆ S1 = Ω
ˆ P1 Ω
ˆ P2 Ωˆ S 2 . If Ωˆ P1Ωˆ P 2 < Ωˆ S1Ωˆ S 2 then
increase Ωˆ P2 = Ω
ˆ S1Ω ˆ S2 Ωˆ P1 or decrease Ωˆ S2 = Ωˆ P1 Ωˆ P2 Ωˆ S1
Bilinear Transformation
-20
0
Magnitude
Magnitude
-40
-20
-60
-40
-80
-60 -100
0 2 4 0 5 10 15
Frequency in rad/s Frequency in rad/s
Chebyshev II Example 8.2 Pole-Zero Plot
1
1
0.8
Imaginary Part
0.5
Magnitude
0.6
0
0.4
-0.5
0.2
-1
0
0 200 400 600 -1 0 1
Frequency in Hz Real Part
Fig. 6.5 Magnitude response for the digital filter and the intermediate analog filters and
the pole–zero plot for the digital filter.
0
-20
-20
Magnitude
Magnitude
-40 -40
-60
-60
-80
-100 -80
0 2 4 6 8 10 0 1 2 3 4 5
Frequency in rad/s Frequency in rad/s
0.5
1 Imaginary Part
Magnitude
0.5
-0.5
-1
0
0 1 2 3 4 -1 -0.5 0 0.5 1
Frequency in rad/s Real Part
Solution
A bandpass filter is required.
The lower passband edge frequency fP 1 = 35 KHz
The upper passband edge frequency fP 2 = 45 KHz
The lower stopband edge frequency fs1 = 20 KHz
The upper stopband edge frequency fs2 = 60 KHz
The maximum passband attenuation Rp = 0.5 dB
The minimum stopband attenuation Rs = 40 dB
Let the sampling frequency is 120 KHz
Using MATLAB program the following results are obtained using
Program 6.3 in the appendix.
Results
Prototype LPF
Cut-off frequency W c = 1; Order N = 3
150 Digital Filter Design
Transfer function:
0.07845s∧ 2 − 2.954e − 017s + 0.7555
HLP (s) =
s∧ 3 + 1.24s∧ 2 + 1.529s + 0.7555
Analog Bandpass filter
Transfer function:
BSF BSF
+
BPF BPF
Fig. 6.7 Inband data and voice transmission system over a telephone line.
0 -20
Magnitude
Magnitude
-20 -40
-40 -60
-60 -80
0 1 2 0 1 2 3
Frequency in rad/s Frequency in rad/s
Chebyshev II Bandstop Filter Example 8.3
1 Pole-Zero Plot
1
Imaginary Part
Magnitude
0.5 0
-1
-1 0 1
0
0 500 1000 1500 Real Part
Frequency in Hz
Solution
Using MATLAB Program 6.4 in the appendix.
Results
Prototype LPF
Cut-off frequency Wc = 0.9149, Order N = 3
Transfer function:
0.02745s∧ 2 + 0.03063
HLP (s) = .
s∧ 3 + 0.6172s∧ 2 + 0.1901s + 0.03063
Analog Bandstop filter
Transfer function:
sos =
1.0000 −0.1775 1.0000 1.0000 −0.0743 −0.1629
1.0000 0.6275 1.0000 1.0000 1.2478 0.5965
1.0000 −0.9283 1.0000 1.0000 −1.3815 0.6411
g = 0.1097.
which shows that the integral squared error is minimized when ht (n) =
h(n) in the range − N ≤ n ≤ N . This implies that the process of trun-
cation results in a minimum integral squared error. In order to make
the filter causal we can delay the impulse response by N such that the
delayed samples are given by h1 (n) = ht (n − N ). Delaying the sam-
ples does not change the magnitude response but change the phase
response. The design procedure for FIR filters then involves truncating
the infinite-length impulse response h(n) of ideal filters and shifting
such impulse responses to make the filter causal. The expressions for
the impulse responses of ideal filters is summarized in Table 6.2.
H LP (e jω )
1 sin(ωn)
hLP [n] = , −∞ ≤ n ≤ ∞
πn
ω
−π –ω c 0 ωc π
HHP (e jω )
ωc
1 − π ,
n=0
1 [hHP [n] =
sin(ωc n
− , n = 0
πn
ω
−π –ω c 0 ωc π
HBP (e jω )
sin(ωc1 n) sin(ωc2 n)
–1 hBP (n) = −
πn πn
for |n| ≥ 0|
ω
−π –ω c2 – c1 ω c1 ω c2 π
HBS (e jω )
ωc2 − ωc1
1 − , n=0
1 π
hBS [n] =
sin(ωc1 n)
sin(ωc2 n)
− , n = 0
πn πn
ω
−π –ω c2 –ω c1 ω c1 ω c2 π
1 −M ≤ n ≤ M
w(n) = , (6.10)
0 otherwise
156 Digital Filter Design
(i) There are ripples in both the passband and the stopband.
(ii) If the filter length is increased the number of ripples in both
the passband and the stopband increase with a corresponding
decrease in the ripple width.
(iii) If a sharp transition is required the main lobe width has to be
as small as possible. The main lobe width obtained from the
first zero crossings in Equation (6.11) is 4π/(2M + 1). Thus
6.3 FIR Filter Design 157
Fig. 6.10 The windowing process shown graphically in the time and frequency domains.
Such windows reduce the height of the sidelobes and increase the main
lobe width. When the window DTFT is convolved with the magni-
tude response of the ideal filter the result is a more gradual magnitude
response of the truncated filter.
Frequency domain
40 Normalized Frequency: 0
Magnitude (dB): 30.103
30
Normalized Frequency: 0.08984375
20 Magnitude (dB): 16.86818
Magnitude (dB)
10
-10
-20
-30
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency (×π rad/sample)
Frequency domain
40 Normalized Frequency: 0.0078125
Magnitude (dB): 23.72441
20
Normalized Frequency: 0.15625
0 Magnitude (dB): -7.827975
Magnitude (dB)
-20
-40
-60
-80
-100
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency (×π rad/sample)
Frequency domain
40 Normalized Frequency: 0
Magnitude (dB): 24.51652
20
0
Magnitude (dB)
-40
-60
-80
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency (×π rad/sample)
Frequency domain
40 Normalized Frequency: 0
Magnitude (dB): 22.29222
20
-20
Magnitude (dB): -35.87919
-40
-60
-80
-100
-120
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency (×π rad/sample)
Normalized
NormalizedFrequency:
Frequency:0.1503906
0.1523438
0 Magnitude
Magnitude(dB):
(dB):-2.699513
-3.467335
-20
M agni tu de (d B)
-40
Normalized Frequency: 0.2265625
Magnitude (dB): -52.68411
-60
-80
-100
-120
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
Normalized Frequency (×π rad/sample)
Example 6.5 Design a lowpass FIR digital filter with the following
specifications:
The passband edge frequency fp = 2 KHz
The stopband edge frequency fp = 2.5 KHz
Maximum passband attenuation = 0.1 dB
Minimum stopband attenuation = 50 dB
The sampling frequency Fs = 10 KHz.
6.3 FIR Filter Design 163
0.7
0.6
Magnitude
0.5
0.4
0.3
0.2
0.1
0
0 5 10 15 20 25 30 35
Time Index n
Solution
ωp = 2πfp /Fs = 0.5π, ωs = 2πfs /Fs = 0.4π
ωp +ωs
ωc = 2 = 0.45π, ∆ω = ωp − ωs = 0.1π.
Select Hamming window since it has 54.5 dB of stopband atten-
uation and thus just exceeds the required stopband attenuation. For
the Hamming window ∆ω = 3.32π/M. Hence M = 3.32π 0.1π = 33.2. Choose
M = 34 and therefore N = 2M + 1 = 69.
The impulse response of the filter is given by
sin(ωn)
ht (n) = hLP (n) × w(n)|Hamming =
πn
2πn
× 0.54 + 0.46 cos for − M ≤ n ≤ M
2M + 1
164 Digital Filter Design
-20
Magnitude
-40
-60
-80
-100
0 0.2 0.4 0.6 0.8 1
Omga/pi
Fig. 6.17 Magnitude response of an FIR filter designed using the Hamming window.
6.4 Problems
1
6.5.1 Given the transfer function H(s) = (1+3s+s 2 ) , find H(z) using
7.1 Introduction
Numbers in digital signal processors, and in general, in computers are
represented in binary form using a string of symbols 1s and 0s which
are referred to as binary digits or in short bits A part of the string on
the right representing the integer portion is separated from the part
on the left that represents the fractional part by binary point. In gen-
eral the format takes the form:
aM −1 aM −2 aM −3 · · · a1 a0∆ a−1 a−2 · · · a−N where,
ai = 0 or 1 and ∆ is the binary point.
The bit aM −1 is referred to as the Most Significant Bit (MSB) and the
bit a−N is the least significant bit (LSB). The bit string that represents
a specific value is referred to as the word and the number of bits in the
word forms the wordlength. The wordlength is normally selected as a
power of two; 4, 8, 16, 32, etc.
The decimal value represented by the word is given by
M
−1
Valuedec = ai . (7.1)
i=−N
In digital signal processors numbers are represented in either of two
forms; using fixed point numbers or using floating point numbers. In
the next two sections, we will discuss these two forms and show how
arithmetic operations are achieved.
for s = 1.
(ii) One’s complement representation: The binary number
b = s∆ a−1 a−2 a−3 · · · a−N has a positive value given by
N −i for s = 0 (as in sign and magnitude repre-
i=1 a−i 2
sentation) and the negative number is obtained by com-
plementing each bit of the positive fraction. The decimal
equivalent of the negative number is obtained from −(1 −
2−N ) + N −i
i=1 a−i 2 , where ai are the complemented values.
(iii) Two’s complement representation: The binary number
b = s a a a · · · a−N has a positive value given by
N ∆ −1−i−2 −3
i=1 a−i 2 for s = 0 (as in sign and magnitude represen-
tation) and the negative number is obtained by comple-
menting each bit of the positive fraction, and adding a 1
to the LSB. The decimal equivalent of the negative number
is obtained from −1 + N −i
i=1 a−i 2 , where ai are the com-
plemented values.
Example 7.1.
Example 7.2.
Example 7.3.
Example 7.4.
172 Digital Signal Processing Implementation Issues
Example 7.5.
Example 7.6.
7.2 Fixed Point Number Representation and Arithmetic 173
Example 7.7.
174 Digital Signal Processing Implementation Issues
Example 7.8.
Example 7.9.
α1 = (0∆ 10101100)2101 , α2 = (0∆ 01010001)2110
α1 has the smaller exponent, shift mantissa to the
right one step (equivalent to dividing by 2) and
add 1 to the exponent (equivalent to multiplying
same number by 2).
α1 = (0∆ 01010110)2110
sum = α1 + α2 = (0∆ 01010110 + 0∆ 01010001)2110
= (0∆ 10100111)2101
Shift the mantissa to the left and subtract 1 from the exponent. This
gives the product as
16, 24, or 32. In the C64x one can select any of the three.
The mantissa of the floating point DSPs, on the hand, can
have 24 for the 32-bit format or 53 for the 64-bit format.
(ii) Coefficients word-length: The word-length is identical to the
I/O signal word-length except for the C64x DSP where only
the 16-bit option is available.
(iii) Intermediate products word-length: For a single 16-bit (from
signal) by 16-bit (from coefficient) multiplication a 32-bit
product is normally required. Also for a single 24-bit by
24-bit multiplication a 48-bit product is required. However,
the iterated MAC (multiply and accumulate) require addi-
tional bits for overflow headroom. The C62x fixed point
DSP the headroom is 8 bits. The intermediate product word-
length is therefore 40 bits (16 bits signal + 16 bits coefficients
+ 8 bits overflow). For the C67x floating point DSP only
the mantissa data path is considered. In theory the word-
length required is 64-bits (24 bits signal + 24 bits for the
coefficient +16 bits overflow). However, this is beyond the
accuracy required in most applications. Only 48 bits are kept
and due to exponentiation the accuracy achieved is much
more than for fixed-point DSPs.
Fig. 7.2 Graphs showing overflow control: (a) saturation overflow; (b) two’s complement
overflow.
εt = Q(x) − x. (7.4)
In the section below we show the range of the truncation errors for the
different type of arithmetic representation.
180 Digital Signal Processing Implementation Issues
εt = 2E (2−b − 2−ρ ).
-10
-20
-30
Gain, dB
-40
-50
-60
Fig. 7.5 Impact of coefficient quantization (Blue: infinite precision, red: 6 bits).
186 Digital Signal Processing Implementation Issues
or
∞
wi (n) = gi (k)x(n − k). (7.16)
k=−∞
We present here three methods and their merits and demerits which
can be used to prevent overflows.
that
∞
∞
|wi (n)| ≤ gi (k)x(n − k) ≤ |gi (k)| for all i.
k=−∞ k=−∞
(7.18)
If the L1 -norm = g1 = ∞ |g
k=−∞ i (k)| ≤ 1 then Equa-
tion (7.17) is satisfied. A sufficient and necessary condition
to guarantee no overflow is that the sum of the absolute val-
ues of the impulse response is less than or equal to one. If
this condition is not satisfied then the input signal is scaled
by multiplying it by a factor K given by
1
K= ∞ . (7.19)
maxi k=−∞ |gi (k)|
This is a worst case condition and does not utilize fully the
dynamic range of the registers at the adder output. It reduces
the signal to noise ratio significantly.
(b) Method 2 using the L∞ -norm: In the frequency domain
Equation (7.16) can be written as
π
1
|wi (n)| ≤ |Gi (ejω )X(ejω )|dω
2π
−π
π
max 1
|wi (n)| ≤ |Gi (ejω )| |X(ejω )|dω
−π ≤ ω ≤ π 2π
−π
π
1
|wi (n)| ≤ Gi (ejω )∞ |X(ejω )|dω
2π
−π
jω
|wi (n)| ≤ Gi (e )∞ × X1 . (7.22)
188 Digital Signal Processing Implementation Issues
2 1 jω 2 1 jω 2
|wi (n)| ≤ |Gi (e )| dω × |X(e )| dω
2π −π 2π −π
|wi (n)| ≤ Gi 2 X2 (7.25)
1
L2 -norm g2 K= ∞ 1 From input to k node
( m=0 |gk (m)|)
2 2
1
L∞ -norm G∞ K= max |Gi (ejω )|
−π ≤ ω ≤ π
Fig. 7.8 The digital filter structure for the scaling example.
The input coefficients to the program 7.2 in the appendix are shown
in Table 7.3. The program computes the scaling factors using the L2
norm. The scaling factors obtained and the filter structure, with the
new coefficients, is shown in Figure 7.9.
7.8 Problems
7.7.1 Represent the following decimal fraction in binary form using
sign and magnitude representation, one’s complement repre-
sentation, and two’s complement representation
(i) 0.65625, (ii) −0.65625, and (iii) −0.0500.
7.7.2 Perform the following operation represented by fractions
using binary numbers. Subtraction should be performed as
an addition of a negative number. Verify the result by com-
paring to a normal fraction operation.
7
(i) 8 − 14 , (ii) 1
5 − 35 , and (iii) 3
5 − 1
10 − 18 .
7.7.3 Using the multiplication algorithm for fixed-point binary
numbers perform the following multiplication showing all the
intermediate stages
5 2 5 2
(i) − 38 × 58 , (ii) − 16 × − 3 , and (iii) 16 × 3 .
7.7.4 Determine the maximum possible dynamic range for a sig-
nal variable when a microprocessor uses floating-point binary
numbers with the IEEE format.
7.7.5 Add the following floating-point numbers:
(i) (0∆ 11010101)2001 and (0∆ 01101010)2001 .
(ii) (0∆ 11010101)2011 and (0∆ 11010101)2001 .
192 Digital Signal Processing Implementation Issues
8.1 Introduction
In this chapter, the DSP hardware and software are introduced. DSP
technology is developed by many different groups from academic insti-
tutions and industries. There are many common features in DSP
hardware and software developed by different vendors. Unfortunately
there are also significant differences. The objective of this chapter is
to highlight on some common features that can be found in any DSP
processor. Since we cannot cover the different features of all the DSP
hardware and software from all vendors, we have focussed on hardware
and software of a single vendor that we have found in many academic
institutions and industry. With a thorough knowledge of the processor
from one vendor we believe it will not be so difficult to convert to that
of another vendor.
193
194 Digital Signal Processing Hardware and Software
from the program memory, one to read the coefficients and one to read
the signal value. The final write instructions can be eliminated by using
a different technique referred as modulo addressing. An example of a
processor that uses this architecture is Motorola DSP5600x [18].
Yet another alternative to the one proposed above is to use fast
memories that support multiple, sequential accesses per instruction
cycle over a single set of buses. There are processors with on-chip mem-
ories that can complete an access in one half of an instruction cycle.
Such processors when combined with the Harvard architecture will be
able to make four accesses in one instruction cycle [18].
this there are certain features that are unique to DSP processors only.
For instance DSP processors have the ability to multiply and accumu-
late (MAC) in one instruction cycle. This is achieved by embedding the
MAC instruction in hardware in the main data path. Other processors
take several instruction cycles to achieve the same operation.
Another feature is that DSP processors have the ability to complete
several accesses to memory in a single instruction cycle. For instance, a
processor can fetch an instruction while simultaneously storing results
of the previous instruction.
Some DSP processors provide special support for repetitive com-
putations, which are typical in DSP computations. A special loop or
repeat instruction is provided. Such features make DSP processors more
suitable for real-time digital signal processing even when faster proces-
sors are available in the market.
Some DSP processors have dedicated address generation units which
work in the background and allow the arithmetic processing to proceed
with maximum speed. Once the address register is configured it will
generate the address required for accessing the operand in parallel with
the execution of the arithmetic instruction.
Most DSP processors have one or more serial or parallel input and
output (I/O) interface and specialized I/O handling mechanisms such
as the direct memory access (DMA). The purpose of these peripherals
and interface is to allow a cost effective high performance input and
output [7].
(i) Arithmetic Logic Unit (ALU): ALU has a high degree of par-
allelism. It has a 40-Bit ALU including a 40-bit barrel shifter
and two independent 40-bit accumulators (ALU is not shown
in the diagram).
Fig. 8.3 The functional Block diagram of the TMS320CV5416 processor [21]. (with
permission from TI)
202 Digital Signal Processing Hardware and Software
Fig. 8.4 Program and data space memory map (Microprocessor mode).
The three bits of the PMST register MP/MC, OVLY, and DROM
determine the basic memory configuration as shown in the Table 8.2.
Figure 8.4 indicates the memory map for the program and for
the data.
Figure 8.5 indicates the input and output (I/O) space memory map.
There are eight Complex Programmable Logic Device (CPLD) regis-
ters that are used for software control of various board features. These
registers are mapped into the DSP’s lower I/O address space starting
at address 0x0000. The upper 32 K of the I/O address space is available
for daughter-cards.
8.8 The TMS 320CV5416 Development Kit 205
The extended memory mapping has been left out. It can be found
in [22]. An understanding of the memory mapping is important as it is
required during program development in code composer studio.
(i) Source files (*.c, c++): Normally in c or c++ code and they
consist of the new project.
(ii) Configuration files (*.cdb): these are created as New Config-
uration files from the ‘‘File’’ menu and selecting DSP/BIOS
configuration. Here a default simulator, or a standard simu-
lator or even a customized simulator is selected or created.
When this source file is added to the project two new files
are generated and displayed in the Project View window.
(iii) Linker command files (*.cmd): They consist of
• input files which specify object files, library, or other
command files,
• files that specify linker options,
• files that have memory directives that define the tar-
get memory configuration and section directives that
define how sections are built and allocated.
8.9 Code Composer Studio 209
When all the files have been added then one has to check on the build
options before ‘‘Building All.’’ The command ‘‘Building All’’ compiles,
assembles, and links all the necessary files in the project. A *.out (in our
example a newproject.out) executable file will be created. This file is
loaded into the target memory using the command ‘‘Load Program.’’ In
order to execute the program the command ‘‘RUN’’ from the DEBUG
menu is invoked.
and its components such as all the source files, all functions,
all global variables, user defined data-types, and assembler
labels and directives.
(iv) Watch Window: The watch window is a debugging tool where
one can define and observe a group of variables. It is selected
from the VIEW menu and choosing WATCH WINDOW. It
is possible to drag and drop variables from a program into
the watch window. In the watch window the values of the
variable is displayed.
dialogue box. From the menu DEBUG select RUN. After a while select
HALT. The dialogue box will show the profile of the functions selected.
It is also possible to profile all function and a range containing certain
commands in the program.
8.9.5 DSP/BIOS
DSP--BIOS is an important tool that simplifies the design of DSP
applications. It consists of three components; real-time kernel, real-
time analysis tool and peripheral configuration and management tool.
DSP/BIOS has configuration tool that enables the graphical selection
of either the kernel or the analysis services and to configure the periph-
eral devices. The configuration allows efficient utilization of the kernel
memory. More information on the tools and how to access them is given
below.
Fig. 8.7 Data exchange between the host and the target.
8.10 Problems
8.9.1 The first step to follow to be able to use CCS is to go
through the CCS tutorial in the Help files reached from
the CCS window. It will teach you how to load and run
a program, how to make simple changes and the use of
DSP/BIOS as a configuration tool [12].
8.9.4 Visual Linker will introduce you to its use and how to create
and open a recipe and how to manage the memory space.
Take your time to understand and do the experiment [12].
9.1 Introduction
DSK stands for Digital Signal Processing kit and represents the DSP
development kit. The TMS 320CV5416 development kit has been dis-
cussed in Section 2.7 and the Code composer studio used to develop
applications has been discussed in Section 2.8. The purpose of this
chapter is to develop the application file that is linked to library files
and the include file that define the board and some other useful func-
tions that make the application work in TMS320V5416. We will focus
on the development of the program in C and show how the various
processing algorithms are written. The key processes involve FIR filter
and the IIR filter and these will be developed in full. Other appli-
cations that we have developed and tested in our laboratory will be
included.
215
216 Examples of DSK Implementations
{
int i /∗ Loop Index ∗ /
for (i = L-1; i>0; i - -) /∗ Start with last sample and advance
back to first sample ∗ /
9.2 FIR Filter Implementation 217
Input buffer
Coefficients Buffer
New
Time t sample Time t + T
x(n) x(n)
h(0)
x(n-1) x(n-1)
h(1)
x(n-2) x(n-2)
h(2)
x(n-L+3) x(n-L+3)
h(L-3)
x(n-L+2) x(n-L+2)
h(L-2)
x(n-L+1) x(n-L+1)
h(L-1)
Discard
sample
Fig. 9.1 Input and coefficients buffer organization for FIR filtering.
{
xn(i) = xn(i−1) /∗ Shift data to delay it by 1 sample time∗ /
}
xn (0) = input; /∗ input new data to obtain the zeroth
sample ∗ /
return;
}
The process of refreshing the input buffer may be computationally
intensive particularly when the number of coefficients is large and the
process is not embedded in the hardware. A more efficient method is to
218 Examples of DSK Implementations
load the input signals into a circular buffer. Instead of shifting the input
data and holding the addresses constant the opposite is done. The data
is kept fixed and the addresses are shifted in the counter-clockwise
direction. In fact a pointer used to point to the address of the current
input is used. In the next sample only the pointer is shifted to point
to the address of the last data which in the current sample time would
be discarded. This is the new address of the current input sample. The
remaining addresses point to the delayed inputs in the clockwise direc-
tion. The positions of the coefficients remain fixed. This is shown in the
diagram of Figure 9.2. The advantage of using a circular buffer for the
coefficients is the wrap round once all the coefficients have been used.
The refreshing process is therefore implemented as follows:
(i) Initially x(n) is the current input from the ADC and all the
previous inputs are zero in line with the initial condition.
(ii) The signal buffer pointer points to address x(n), previous
data samples x(n − i) for 1 ≤ i ≤ L − 1 are loaded in a
clockwise direction.
(iii) The output y(n) is computed using Equation (9.1).
(iv) In the next sample interval at time t + T the pointer is
shifted in a counter-clockwise direction. The new sample
x(n) is loaded into position of x(n − L + 1). The value
of x(n − L + 1) at time t is discarded. The rest of the
The c-code functions that can implement the convolution process and
refresh the buffer are given below:
{
float yn = 0.0 /∗ Initialise output yn ∗ /
int i
for (i = 0; i > N; i ++) /∗ Start from 0 to N-1 ∗ /
{
N−1
yn = yn + h(i)∗ x(i) /∗ y(n) = h(l)x(n − l) ∗ /
l=0
}
return yn
{
for yn = 0.0, (i=0; i < N; i ++)
{
yn + = h[i]∗ x[i] /∗ Convolve x(n) with
h(n) ∗ /
}
output[j] = yn ;
/∗ This function refreshes the samples x(n), x(n-1), x(n-2),. . . ,
x(n-N +1) ∗ /
void shift(float ∗ x, int N, float input)
{
for( i = N - 1; i > 0; i-- )
{
x[i] = x[i – 1]; /∗ Delay each array data
sample by one unit∗ /
}
}
return;
}
Fig. 9.3 Input, output, and coefficients buffer organization for IIR filtering.
FIR filter. Despite this big advantage of IIR filters circular buffers are
still deployed with the intention of making the filtering process faster
and more efficient.
The c code below shows how the filtering and the shifting of the
signal samples can be achieved. It makes reference to Equation (9.2).
9.3 IIR Filtering Implementation 223
float yn
float yn1 , yn2
int i,j
{
for( i = L - 1; i > 0; i-- ).
{
y[i] = y[i – 1]; /∗ Delay each array data sample
by one unit∗ /
}
y(0) = yn /∗ Insert current output into
register∗ /
}
}
The Program 9.1 for the implementation of the FIR filter in the
appendix can easily be adapted to implement an IIR filter and will not
be reproduced.
/∗ Function: tone.c ∗ /
#define N 50 ∗ / N is the Buffer size∗ /
wish∗ /
}
}
}
226 Examples of DSK Implementations
#include “lpfcoeff.h”
const int BL = 8;
const real64 T B[8] = {
#include “hpfcoeff.h”
const int BL = 9;
const real64 T B[9] = {
-0.01127922557944, 0.00850167320085, 0.08571311020913,
-0.2585099772295, 0.3511156226834, -0.2585099772295,
0.08571311020913, 0.00850167320085, -0.01127922557944
}
-10
-20
Magnitude (dB)
-30
-40
-50
-60
Lowpass FIR Window
Highpass FIR Window
-70
0 0.5 1 1.5 2 2.5 3
Frequency (kHz)
The template for the program harmonics.c that will separate the
fundamental at 1 kHz from the 3rd harmonic component is given as
#include “harmonicscfg.h”
#include “dsk5416.h”
#include “dsk5416 pcm3002.h”
228 Examples of DSK Implementations
void UserTask()
{
DSK5416 PCM3002 CodecHandle hCodec;
unsigned long i;
{
/∗ Read left input channel∗ /
while (!DSK5416 PCM3002 read16(hCodec, &left input));
}
230 Examples of DSK Implementations
/∗ main() ∗/
void main()
{
/∗ Initialize the board support library ∗/
DSK5416 init();
}
When x(n) is a stationary random process and for large value of N the
periodogram oscillates and is not a good estimate of the power spectral
density. It can be shown that the mean of the periodogram converges
to the power spectral density. For this reason in order to estimate the
power spectral density L periodograms of L segments of the sequence
x(n) each of length N are obtained and averaged. The estimate of the
power spectral density is thus given by
L−1
1
Sx (ω) = PN,i (ω).
L
i=0
One can use the FFT algorithm to compute the periodogram, and hence
the power spectral densities, at uniformly spaced frequency points
Sx (ωs k/N ) for k = 0 to N − 1.
/∗ ————————————————————————————–∗ /
/∗ For compatibility with pcm3002 read / write, the following
variables must be declared as Int16 or short int, rather than int. ∗ /
/∗ ————————————————————————————–∗ /
Int16 left input;
Int16 left output;
Int16 right input;
Int16 right output;
Int16 mono input;
/∗ ————————————————————————————–∗ /
/∗ UserTask() ∗/
∗
/ ————————————————————————————–∗ /
/∗ The main user task. ∗/
/ ————————————————————————————–∗ /
∗
void UserTask()
{
DSK5416 PCM3002 CodecHandle hCodec;
long i;
unsigned int j;
unsigned int temp;
9.6 The Spectrum Analyzer 233
buffers initialize();
{
/∗ Read left input channel ∗ /
while (!DSK5416 PCM3002 read16(hCodec, &left input));
}
/∗ ————————————————————————————–∗ /
/∗ main() ∗/
/ ————————————————————————————–∗ /
∗
void main()
{
/∗ Initialize the board support library ∗/
DSK5416 init();
/∗ All other functions are scheduled by DSP/BIOS ∗ /
}
1 for i = 1, 5, 18
For the ITU-T standard h(i) = and N = 23.
0 otherwise.
{
int (i,j)
for i = 0; >50, i++
{
y(i) = 0 /∗ clear output buffer ∗ /
x(i) = 0 /∗ clear input buffer ∗ /
}
{
for j = 50-1; >0; j - -
{
x(j) = x(j-1) /∗ Shift sample ∗ /
}
x(0) = input /∗ Input new sample ∗ /
y(i) = x(i-N) + gain∗ y(i - N); /Add echo to input, gain must be
less than 1 ∗ /
output = y(i)
}
}
9.9 Reverberator
The multiple echo generator does not provide natural reverberations as
its magnitude response (which forms a comb filter magnitude response)
is not constant at all frequencies. This results in distortion of certain
frequency components and make music unpleasant to listen to. To over-
come this Schroeder [26, 27] introduced the use of an all-pass structure
as shown in Figure 9.7.
z −N −α
The transfer function is given by H(z) = 1−αz −N , and the difference
than 1 ∗ /
output = y(i)
}
}
To improve on the timber of the output sound one can have a cas-
cade implementation of Figure 9.7.
References
241
242 References
Program 2.2
% Plotting of the Frequency response of Example 2.2
% Enter the desired length of the DFT
k = input(‘Enter the number of frequency points = ’);
alpha = input(‘Enter the value of alpha, alpha = ’);
% Compute the frequency response
w = -4*pi:pi/k:4*pi;
h = 1./(1 - alpha.*cos(w)+ i*alpha.*sin(w));
subplot(2,1,1);
plot(w/pi, abs(h)); grid
title(‘Magnitude Spectrum alpha = 0.5’);
xlabel(‘\omega/\pi’); ylabel(‘Magnitude’);
subplot(2,1,2);
plot(w/pi, angle(h)); grid
title(‘Phase spectrum alpha = 0.5’);
xlabel(‘\omega/\pi’); ylabel(‘Phase, Radians’);
Program 2.3
% Plotting of the Frequency response of Example 2.3
% Enter the desired length of the DFT
k = input(‘Enter the number of frequency points = ’);
alpha = input(‘Enter the value of alpha less than 1,
alpha = ’);
% Compute the frequency response
w = -4*pi:pi/k:4*pi;
h = 1./(1 - alpha.*cos(w)+ i*alpha.*sin(w));
243
244 Appendix
subplot(2,1,1);
plot(w/pi, abs(h)); grid
title(‘Magnitude Spectrum alpha = 2’);
xlabel(‘\omega/\pi’); ylabel(‘Magnitude’);
subplot(2,1,2);
plot(w/pi, angle(h)); grid
title(‘Phase spectrum alpha = 2’);
xlabel(‘\omega/\pi’); ylabel(‘Phase, Radians’);
Program 2.4
% Plotting of the Frequency response of Example 2.4
% Enter the desired length of the DFT
k = input(‘Enter the number of frequency points = ’);
alpha = input(‘Enter the value of alpha greater than1,
alpha = ’);
% Compute the frequency response
w = -4*pi:pi/k:4*pi;
h = 1./(1 - alpha.*cos(w)+ i*alpha.*sin(w));
subplot(2,1,1);
plot(w/pi, abs(h)); grid
title(‘Magnitude Spectrum alpha = 1’);
xlabel(‘\omega/\pi’); ylabel(‘Magnitude’);
subplot(2,1,2);
plot(w/pi, angle(h)); grid
title(‘Phase spectrum alpha = 1’);
xlabel(‘\omega/\pi’); ylabel(‘Phase, Radians’);
Program 6.1
% Design a Digital Filter using the Bilinear
Transformation method
% Example 6.1
fp = 10;
% sampling frequency Fs = 200
Fs = 200;
Wp = fp*2*pi/Fs;
Appendix 245
fs = 60;
Ws = fs*2*pi/Fs;
Rp = 0.5;
Rs = 20;
% Pre-warp the normalised digital frequencies to abtain
the analogue
% filter frequencies
Omegap = tan(Wp/2)
Omegas = tan(Ws/2)
[N, Wc] = buttord(Omegap, Omegas, Rp, Rs, ‘s’);
disp(‘Cut-off frequency of the analogue filter’); disp(Wc);
disp(‘Order of the analogue filter’); disp(N);
[B, A] = butter(N, Wc,‘s’);
tf(B,A)
% Apply a bilinear transformation
[Num,Den] = bilinear(B, A, 0.5);
% Display transfer function of digital filter (must enter
sampling time)
tf(Num, Den, 0.005)
omega= [0:0.1:2*Omegas];
Hanalog = freqs(B,A,omega);
subplot(2,1,1)
plot(omega,20*log10(abs(Hanalog)),‘m’);
title(‘Butterworth LPF Example 8.1’);
xlabel(‘Frequency in rad/s’); ylabel(‘Magnitude’);
omegad= [0:pi/100:pi];
Hdigital = freqz(Num,Den,omegad);
subplot(2,1,2)
plot(omegad*Fs/(2*pi),abs(Hdigital),‘r’);
title(‘Butterworth LPF Example 8.1’);
xlabel(‘Frequency in Hz’); ylabel(‘Magnitude’);
Program 6.2
% Design a Highpass Chebyshev II Digital Filter using the
Bilinear
246 Appendix
Program 6.3
% Design a Bandpass Elliptic Digital Filter using the
Bilinear
% Transformation method Example 8.3.
% sampling frequency Fs = 120 KHz
Fs = 120000;
fp1 = 35000; fp2 = 45000;
fs1 = 20000; fs2 = 60000;
Wp1 = fp1*2*pi/Fs; Wp2 = fp2*2*pi/Fs;
Ws1 = fs1*2*pi/Fs; Ws2 = fs2*2*pi/Fs;
Rp = 0.5;
Rs = 40;
% Pre-warp the normalised digital frequencies to obtain
the analogue
248 Appendix
% filter frequencies
Omegap1 = tan(Wp1/2); Omegap2 = tan(Wp2/2);
Omegas1 = tan(Ws1/2); Omegas2 = tan(Ws2/2);
% Check for geometric sysmmetry
if Omegap1*Omegap2>Omegas1*Omegas2
Omegap1=Omegas1*Omegas2/Omegap2;
WoSquared =Omegas1*Omegas2;
else Omegas2 = Omegap1*Omegap2/Omegas1;
WoSquared = Omegap1*Omegap2;
end
Bw = Omegap2 - Omegap1;
% Obtain the specifications of the LPF
Omegap = 1;
Omegas = Omegap*(WoSquared - Omegas1ˆ2)/(Omegas1*Bw);
[N, Wc] = ellipord(Omegap,Omegas,Rp,Rs,‘s’);
disp(‘Prototype LPF’)
disp(‘Cut-off frequency Wc = ’); disp(Wc);
disp(‘Order N = ’); disp(N);
[B, A] = ellip(N,Rp,Rs,Wc,‘s’);
tf(B,A)
% Plot magnitude response of the prototype LPF
omega = [0:0.1:2*Omegas];
Hanalog = freqs(B,A,omega);
subplot(2,2,1)
plot(omega,20*log10(abs(Hanalog)),‘g’);
title(‘Prototype LPF Example 8.2’);
xlabel(‘Frequency in rad/s’); ylabel(‘Magnitude’);
% Transform the transfer function to an analogue bandpass
filter
[BD, AD] = lp2bp(B, A, Wc, Bw);
disp(‘Analogue Bandpass filter’)
tf(BD,AD)
% Plot magnitude response of the equivalent analogue BPF
omegaa = [0.1:0.1:5];
Hanalogpb = freqs(BD, AD, omegaa);
subplot(2,2,2)
Appendix 249
plot(omegaa,20*log10(abs(Hanalogpb)),‘m’);
title(‘Analogue BPF Example 8.3’);
xlabel(‘Frequency in rad/s’); ylabel(‘Magnitude’);
% Apply a bilinear transformation
[Num,Den] = bilinear(BD, AD, 0.5);
% Display transfer function of digital filter (must enter
sampling time)
disp(‘Digital Bandpass filter’)
tf(Num, Den, 0.005)
omegad= [0:pi/100:pi];
Hdigital = freqz(Num,Den,omegad);
subplot(2,2,3)
plot(omegad, abs(Hdigital),‘r’);
title(‘Elliptic Bandpass Filter Example 8.3’);
xlabel(‘Frequency in Hz’); ylabel(‘Magnitude’);
subplot(2,2,4)
zplane(Num, Den);
title(‘Pole-Zero Plot’);
Program 6.4
% Design a Bandstop chebyshev II Digital Filter using the
Bilinear
% Transformation method Example 8.4.
% sampling frequency Fs = 2.8 KHz
Fs = 2800;
fp1 = 700; fp2 = 1200;
fs1 = 800; fs2 = 1000;
Wp1 = fp1*2*pi/Fs; Wp2 = fp2*2*pi/Fs;
Ws1 = fs1*2*pi/Fs; Ws2 = fs2*2*pi/Fs;
Rp = 0.5;
Rs = 40;
% Pre-warp the normalised digital frequencies to obtain
the analogue
% filter frequencies
Omegap1 = tan(Wp1/2); Omegap2 = tan(Wp2/2);
250 Appendix
Program 7.1
% coefficient Quantisation Effects on the Frequency
response of a
% Direct Form IIR filter
clf;
[N,Wn] = ellipord(1, 2.8618058, 1, 40,‘s’);
[B,A] = ellip(N,1,40, Wn,‘s’);
[BT,AT] = lp2bp(B,A, 1.1805647, 0.777771);
[num,den] = bilinear(BT,AT,0.5);
[h,w] = freqz(num,den,512); g = 20*log10(abs(h));
bq = a2dT(num,6); aq = a2dT(den,6);
[hq,w] = freqz(bq,aq,512); gg = 20*log10(abs(hq));
plot(w/pi, g, ‘b’, w/pi, gg, ‘r:’); grid
title(‘Impact of Coefficient Quantisation’);
axis([0 1 -80 5]);
xlabel(‘\omega/\pi’); ylabel (‘Gain, dB’);
252 Appendix
pause
zplane(num,den);
title(‘Case with Unquantised Coefficients’);
pause
zplane(bq,aq);
Title(‘Case with Quantised Coefficients’);
function beq = a2dT(d,n)
% BEQ = A2DT(D,N) generates the decimal equivalent beq of
the binary
% representation of the decimal number D with N bits for
the magnitude part
% obtained by truncation.
%
m = 1; d1 = abs(d);
while fix(d1)>0
d1 = abs(d)/2ˆm;
m = m + 1;
end
beq = fix(d1*2ˆn);
beq = sign(d).*beq.*2ˆ(m-n-1);
Program 7.2
% program for scaling a discrete-time system
% Input filter coefficients.
disp(‘Coefficients of first cascade section’);
disp(‘aii are numerator and bii are denominator
coefficients’);
b00 = input(‘b00 = ’); b01 = input(‘b01 = ’);
b02 = input(‘b02 = ’); a00 = input(‘a00 = ’);
a01 = input(‘a01 = ’); a01 = -a01;
a02 = input(‘a02 = ’); a02 = -a02;
disp(‘Coefficients of second cascade section’);
b10 = input(‘b10 = ’); b11 = input(‘b11 = ’);
b12 = input(‘b10 = ’); a10 = input(‘a10 = ’);
a11 = input(‘a11 = ’); a11 = -a11;
a12 = input(‘a12 = ’); a12 = -a12;
format long
% Computing Scaling factor for signal to first adder of
first cascade
% section
k1 = 1; k2 = 1; k3 = 1;
x1 = 1/k1;
si1 = [0,0]; si2 = [0,0];
varnew = 0; k=1;
while k > 0.000001
y1 = a01.*si1(1) + a02.*si1(2) + x1;
x2 = (b00.*y1 + b01.*si1(1) + b02.*si1(2))./k2;
si1(2) = si1(1);
si1(1) = y1;
y2 = x2 + a11.*si2(1) + a12.*si2(2);
y3 = (y2.*b10 + si2(1).*b11 + si2(2).*b12)./k3;
si2(2) = si2(1);
si2(1) = y2;
varold = varnew;
varnew = varnew + abs(y1).*abs(y1);
% Compute approximate L2 norm square
254 Appendix
k = varnew - varold;
x1 = 0;
end
k1 = sqrt(varnew);
% Computing Scaling factor for signal to second adder of
first
% cascade section
x1 = 1/k1;
si1 = [0,0]; si2 = [0,0];
varnew = 0; k=1;
while k > 0.000001
y1 = a01.*si1(1)+ a02.*si1(2)+ x1;
x2 = (b00.*y1 + b01.*si1(1) + b02.*si1(2))./k2;
si1(2) = si1(1);
si1(1) = y1;
y2 = x2 + a11.*si2(1) + a12.*si2(2);
y3 = (y2.*b10 + si2(1).*b11 + si2(2).*b12)./k3;
si2(2) = si2(1);
si2(1) = y2;
varold = varnew;
varnew = varnew + abs(y2).*abs(y2);
% Compute approximate L2 norm square
k = varnew - varold;
x1 = 0;
end
k2 = sqrt(varnew);
% Computing Scaling factor for signal to second adder of
second cascade
section
x1 = 1/k1;
si1 = [0,0]; si2 = [0,0];
varnew = 0; k=1;
while k > 0.000001
y1 = a01.*si1(1) + a02.*si1(2) + x1;
x2 = (b00.*y1 + b01.*si1(1) + b02.*si1(2))./k2;
si1(2) = si1(1);
Appendix 255
si1(1) = y1;
y2 = x2 + a11.*si2(1) + a12.*si2(2);
y3 = (y2.*b10 + si2(1).*b11 + si2(2).*b12)./k3;
si2(2) = si2(1);
si2(1) = y2;
varold = varnew;
varnew = varnew + abs(y3).*abs(y3);
% Compute approximate L2 norm square
k = varnew - varold;
x1 = 0;
end
k3 = sqrt(varnew);
disp(‘Scaling factor k1 = ’); disp(k1);
disp(‘Scaling factor k2 = ’); disp(k2);
disp(‘Scaling factor k3 = ’); disp(k3);
Program 9.1
C Program to Implement FIR filtering.
/********************************************************/
#include <stdio.h> /* Required for functions printf() and
puts() */
/********************************************************/
/*
/* The next line takes the name of the module, here FIR.c
and creates FIRcfg.h */
/********************************************************/
#include ‘‘FIRcfg.h’’
#include ‘‘dsk5416.h’’
#include ‘‘dsk5416_pcm3002.h’’
#include ‘‘stereo.h’’
#include ‘‘FIR_low_pass_filter.h’’
/********************************************************/
/* Configuration setup of registers of PCM3002 Codec */
/********************************************************/
256 Appendix
DSK5416_PCM3002_Config setup = {
/********************************************************/
/* For compatibility with pcm3002 read/write, these
variables must */
/* be declared as Int16 or short int, rather than int. */
/********************************************************/
Int16 left_input;
Int16 left_output;
Int16 right_input;
Int16 right_output;
/********************************************************/
/* UserTask() */
/********************************************************/
/* The main user task. */
/* Note that this task is not called by main(). It is
scheduled by DSP/BIOS */
/* the purpose of this section is to read input from the
two input channels */
/* and to mix them to obtain a mono input */
/********************************************************/
void UserTask()
{
DSK5416_PCM3002_CodecHandle hCodec;
long l;
unsigned int switch_value;
signed int mono_input;
Appendix 257
left_output = yn;
right_output = yn;
while (!DSK5416_PCM3002_write16(hCodec,
left_output));
while (!DSK5416_PCM3002_write16(hCodec,
right_output));
DSK5416_init();
#ifndef FIR_low_pass_filter_H
#define FIR_low_pass_pass_H
0x0622, /* H23 */
0x0655, /* H24 */
0x0666, /* H25 */
0x0655, /* H26 */
0x0622, /* H27 */
0x05D1, /* H28 */
0x0565, /* H29 */
0x04E5, /* H30 */
0x0456, /* H31 */
0x03C1, /* H32 */
0x032B, /* H33 */
0x029A, /* H34 */
0x0214, /* H35 */
0x019B, /* H36 */
0x0134, /* H37 */
0x00DD, /* H38 */
0x0098, /* H39 */
0x0063, /* H40 */
0x003C, /* H41 */
0x0021, /* H42 */
0x000F, /* H43 */
0x0005, /* H44 */
0x0000, /* H45 */
0xFFFE, /* H46 */
0xFFFE, /* H47 */
0xFFFF, /* H48 */
0x0000, /* H49 */
0x0000, /* H50 */
};
#endif
/********************************************************/
/* End of FIR_low_pass_filter.h */
/********************************************************/
Index
261
262 Index
volatile memory, 10