You are on page 1of 40

EC 2314 Digital Signal

Processing
-Filter Realization
By
Dr. K. Udhayakumar
Introduction
 In earlier chapters we studied the theory of discrete
systems in both the time and frequency domains.
 We will now use this theory for the processing of
digital signals.
 To process signals, we have to design and implement
systems called filters.
 The filter design issue is influenced by such factors as
 The type of the filter: IIR or FIR
 The form of its implementation: structures
 Different filter structures dictate different design strategies.
Introduction
 IIR filters are characterized by infinite-duration
impulse response. Some of these impulse
responses can be modeled by
 Rational system functions
 Difference equations
 ARMA or recursive filters
 We will treat FIR filter separately from IIR
filters for both design and implementation
purposes.
Introduction
 Since our filters are LTI systems, we need the
following three elements to describe digital filter
structures.
 Adder
 Multiplier (Gain)
 Delay element (shift or memory)
x1(n)
x2(n)
x1(n)+x2(n)
x(n) ax(n)
a
x(n) x(n-1)
1/z
IIR Filter Structures
 The system function of an IIR filter is given by
1 ;
1 ) (
) (
) (
0
1
1
1
1 0
0
0
=
+ + +
+ + +
= = =
÷ ÷
÷ ÷
=
÷
=
÷
¿
¿
a
z a z a
z b z b b
z a
z b
z A
z B
z H
N
N
M
M
N
n
n
n
M
n
n
n


The order of such an IIR filter is called N if a
N
~=0.
The difference equation representation of an IIR filter is expressed
as
¿ ¿
= =
÷ ÷ ÷ =
M
m
N
m
m m
m n y a m n x b n y
0 1
) ( ) ( ) (
Three different structures can be used to
implement an IIR filter:
 Direct form
 In this form, there are two parts to this filter, the moving average part and the
recursive part (or the numerator and denominator parts)
 Two version: direct form I and direct form II
 Cascade form
 The system function H(z) is factored into smaller second-order sections, called
biquads. H(z) is then represented as a product of these biquads.
 Each biquad is implemented in a direct form, and the entire system function is
implemented as a cascade of biquad sections.
 Parallel form
 H(z) is represented as a sum of smaller second-order sections.
 Each section is again implemented in a direct form.
 The entire system function is implemented as a parallel network of sections.
Direct Form I Structure
 As the name suggests, the difference equation is implemented
as given using delays, multipliers, and adders.
 For the purpose of illustration, Let M=N=2,
) 2 ( ) 1 ( ) 2 ( ) 1 ( ) ( ) (
2 1 2 1 0
÷ ÷ ÷ ÷ ÷ + ÷ + = n y a n y a n x b n x b n x b n y
x(n) y(n) b0
b1
b2
-a1
-a2
1/z
1/z
1/z
1/z
H1(z) H2(z)
Direct Form II Structure
x(n) y(n)
H1(z)
-a1
-a2
1/z
1/z
H2(z)
b0
b1
b2
1/z
1/z
x(n) y(n)
H(z)
-a1
-a2
1/z
1/z
b0
b1
b2
Direct Form II structure
The
commutative
law of the
convolution
Matlab Implementation
 In Matlab the direct from structure is described
by two row vectors:
 b containing the {bn} coefficients and a
containing the {an} coefficients.
 The structure is implemented by the filter
function, which is discussed in Chapter 2.
Cascade Form
 In this form the system function H(z) is written
as a product of second-order section with real
coefficients.
 This is done by factoring the numerator and
denominator polynomials into their respective
roots and then combining either a complex
conjugate root pair or any two real roots into
second-order polynomials.
Cascade Form
 We assume that N is an even integer. Then
2
2 ,
1
1 ,
2
2 ,
1
1 ,
1
0
1
1
1
0
1
1
1
1 0
1
1
1
1
1
) (
0 0
1
÷ ÷
÷ ÷
=
÷ ÷
÷ ÷
÷ ÷
÷ ÷
+ +
+ +
H =
+ + +
+ + +
=
+ + +
+ + +
=
z A z A
z B z B
b
z a z a
z z
b
z a z a
z b z b b
z H
k k
k k
K
k
N
N
N
b
b
b
b
N
N
N
N
N




Where, K is equal to N/2, and B
k,1,
B
k,2,
A
k,1,
A
k,2
are real numbers
representing the coefficients of second-order section.

Biquad Section
) ( ) ( ); ( ) (
, , 2 , 1 ,
1
1
) (
) (
) (
1 0 1
2
2 ,
1
1 ,
2
2 ,
1
1 ,
1
z Y z Y z X b z Y with
K k
z A z A
z B z B
z Y
z Y
z H
K
k k
k k
k
k
k
= =
=
+ +
+ +
= =
+
÷ ÷
÷ ÷
+

Is called the k-th biquad section. The input to the k-th biquad section is the
output from the (k-1)-th section, while the output from the k-th biquad is the
input to the (k+1)-th biquad. Each biquad section can be implemented in direct
form II.
Yk(n)=XK+1(n)
Yk+1(n)
-Ak,1
-Ak,2
1/z
1/z
Bk,1
Bk,2
The entire filter is then implemented
as a cascade of biquads
x(n)
y(n)
-A1,1
-A1,2
1/z
1/z
B1,1
B1,2
-A2,1
-A2,2
1/z
1/z
B2,1
B2,2
b0
Cascade form structure for N=4
Matlab Implementation
 Given the coefficients {b
n
} and {a
n
} of the direct form filter
 The function [b0,B,A] = dir2cas(b,a)
 can be used to obtain the coefficients b
0
, {B
k,i}
, and {A
k,i
}.
 The cascade form is implemented using a casfiltr function
 Function y = casfiltr(b0,B,A,x)
 Function cas2dir converts a cascade form to a direct form.
 Function [b,a] = cas2dir(b0,B,A)

 Examples: 6.1
Parallel Form
 In this form the system function H(z) is written as a sum
of second-order section using partial fraction expansion.

  
  




N M if only
N M
k
k
k
K
k
k k
k k
N M if only
N M
k
k
k
N
N
N
M
N
N
M
M
z C
z A z A
z B B
z C
z a z a
z b z b b
z a z a
z b z b b
z A
z B
z H
>
÷
=
÷
=
÷ ÷
÷
>
÷
=
÷
÷ ÷
÷ ÷
÷ ÷
÷ ÷
¿ ¿
¿
+
+ +
+
=
+
+ + +
+ + +
=
+ + +
+ + +
= =
0 1
2
2 ,
1
1 ,
1
1 , 0 ,
0
1
1
1
1 0
1
1
1
1 0
1
1
ˆ ˆ ˆ
1 ) (
) (
) (
K=N/2, and
B,A are real
numbers
The second-order section
¿
< = =
=
+ +
+
= =
÷ ÷
÷
+
N M z Y z Y z X z H z Y with
K k
z A z A
z B B
z Y
z Y
z H
k k k
k k
k k
k
k
k
), ( ) ( ), ( ) ( ) (
, , 2 , 1 ,
1 ) (
) (
) (
2
2 ,
1
1 ,
1
1 , 0 ,
1

Is the k-th proper rational biquad section.
The filter input is available to all biquad section as well as
to the polynomial section if M>=N (which is an FIR part)
The output from these sections is summed to form the
filter output.
Each biquad section can be implemented in direct form II.
Parallel form structure
C0
B1,0
-A1,1
-A1,2
B1,1
B2,0
-A2,1
-A2,2
B2,1
x(n) y(n)
1/z
1/z
1/z
1/z
Parallel form structure for N=4 (M=N=4)
Matlab Implementation
 The function dir2par converts the direct form coefficients {b
n
}
and {a
n
} into parallel form coefficients {B
k,i
} and {A
k,i
}
 Functions:
 [C,B,A] = dir2par(b,a)
 I = cplxcomp(p1,p2)
 y = parfiltr(C,B,A,x)
 [b,a] = par2dir(C,B,A)

 Examples
FIR Filter Structure
A finite-duration impulse response filter has a system function of
the form:
¿
÷
=
÷ ÷
÷
÷
= + + + =
1
0
1
1
1
1 0
) (
M
n
n
n
M
M
z b z b z b b z H 
Hence the impulse response h(n) is
¹
´
¦
÷ s s
=
else
M n bn
n h
0
1 0
) (
And the difference equation representation is
) 1 ( ) 1 ( ) ( ) (
1 1 0
+ ÷ + + ÷ + =
÷
M n x b n x b n x b n y
M

Which is a linear convolution of finite support.
The order of the filter is M-1, while the length of the filter is M.
FIR Filter Structure
 Direct form:
 The difference equation is implemented as a
tapped delay line since there are no feedback paths.
 Figure 6.10
 Note that since the denominator is equal to unity,
there is only one direct form structure.
 Matlab implementation
 Function: y = filter(b,1,x)
FIR Filter Structure
 Cascade form:




 Figure 6.11
 Matlab Implementation
 Function: dir2cas, cas2dir
¸ ¸
2 / ); 1 (
1
) (
2
2 ,
1
1 ,
1
0
1
0
1
1
0
1
0
1
1
1
1 0
M K z B z B b
z
b
b
z
b
b
b
z b z b b z H
k k
K
k
M
M
M
M
= + + H =
|
|
.
|

\
|
+ + + =
+ + + =
÷ ÷
=
÷
÷
÷
÷
÷
÷


FIR Filter Structure
 Linear-phase form
 For frequency-selective filters (e.g., lowpass filters) it is
generally desirable to have a phase response that is a linear
function of frequency. That is

 For a causal FIR filter with impulse over [0,M-1] interval,
the linear-phase conditions
2
0 , , ) (
t
| t t o | ± = s < ÷ ÷ = Z or w w e H
jw
1 0 , 2 / ); 1 ( ) (
1 0 , 0 ); 1 ( ) (
÷ s s ± = ÷ ÷ ÷ =
÷ s s = ÷ ÷ =
M n n M h n h
M n n M h n h
t |
|
Symmetric impulse response vs. antisymmetric impulse response
Linear-phase form
 Consider the difference equation with a symmetric
impulse response.


 Figure 6.12: M=7(odd) and M=6(even)
 Matlab implementation
 The linear-phase structure is essentially a direct form draw differently
to save on multiplications. Hence in a Matlab implementation the
linear-phase structure is equivalent to the direct form.


+ + ÷ + ÷ + + ÷ + =
+ ÷ + + ÷ + + ÷ + =
)] 2 ( ) 1 ( [ )] 1 ( ) ( [
) 1 ( ) 2 ( ) 1 ( ) ( ) (
1 0
0 1 1 0
M n x n x b M n x n x b
M n x b M n x b n x b n x b n y
Frequency Sampling Form
 In this form we use the fact that the system function H(z) of an
FIR filter can be reconstructed from it samples on the unit
circle
) 1 , , 0 ( ) (
) 1 , , 0 (
1
) ( 1
) (
1
0
1
÷ =
÷ =
÷
|
|
.
|

\
|
÷
=
÷
÷
=
÷ ÷
÷
¿
M k residues the are k H
M k roots the are W
z W
k H
M
z
z H
k
M
M
k
k
M
M


It is also interesting to note that the FIR filter described by the
above equation has a recursive form similar to an IIR filter
because it contains both poles and zeros.
Frequency Sampling Form
 The system function leads to a parallel structure as
shown in Figure 6.15 for M=4.
 One problem with the structure in Fig.6.15 is that it
requires a complex arithmetic implementation.
 Using the symmetry properties of the DFT and the
(W
M
–k
) factor.
even M f or L odd M f or L
z
M H
z
H
z H k H
M
z
z H
M M
L
k
k
M
1 ;
1
) 2 / (
1
) 0 (
) ( | ) ( | 2
1
) (
2 2
1
1
1 1
÷ = =
)
`
¹
¹
´
¦
÷
+
÷
+
÷
=
÷
=
÷ ÷
÷
¿
 let p1=W
M
-k
=exp(-j*2*pi*k/M)
=cos(2*pi*k/M)+jsin(2*pi*k/M)
H
k
=magH
k
*exp(j*phaH
k
)
=magH
k
*(cos(phaH
k
)+jsin(phaH
k
))
Then:

2 1
1
1
*
1
*
1
1
) / 2 cos( 2 1
) / 2 cos( ) cos(
* | | 2
1
1
) (
÷ ÷
÷
÷
÷
+ ÷
÷ Z ÷ Z
=
÷
+
÷
=
z M k z
M k H z H
H
z p
H
z p
H
z H
k k
k
k k
k
t
t
Figure 6.16
MATLAB functions and Examples
 Notify the structure type
 [C,B,A]=dir2fs(h) of textbook
 A practical problem: unstable, avoid this
problem by sampling H(z) on a circle |z|=r.
 Ex6.6 find frequency sample form
 Ex6.7 In this example the frequency sample
form has less computational complexity than
direct form.
Lattice Filter Structure
 The lattice filter is extensively used in digital speech
processing and in implementation of adaptive filter.
 It is a preferred form of realization over other FIR or
IIR filter structures because in speech analysis and in
speech synthesis the small number of coefficients
allows a large number of formants to be modeled in
real-time.
 All-zeros lattice is the FIR filter representation of the lattice
filter.
 The lattice ladder is the IIR filter representation.
All-zero Lattice Filters
 An FIR filter of length M (or order M-1) has a lattice
structure with M-1 stages.
x(n)
f0(n)
g0(n)
K0
1/z 1/z 1/z
g1(n)
gM-1(n)
g2(n) gM(n)
f1(n) f2(n) fM-1(n) fM(n)
y(n)
K1
K1
K2
K2
KM
KM
1 , , 2 , 1 ), ( ) ( ) (
1 , , 2 , 1 ), ( ) ( ) (
1 1
1 1
÷ = + =
÷ = + =
÷ ÷
÷ ÷
M m n g n f K n g
M m n g K n f n f
m m m m
m m m m


Km: reflection coefficients
All-zero lattice filters
¿ ¿
÷
=
÷
=
÷ ÷
|
|
.
|

\
|
+ = =
1
0
1
1
0
0
1 ) (
M
m
M
m
m
m
m
m
z
b
b
b z b z H
If the FIR filter is given by the direct form
And if we denote the polynomial
1 , , 1 , ) ( ; ) ( 1 ) (
0
1
1
1
1 1
÷ = =
|
.
|

\
|
+ =
÷
÷
=
÷
÷ ÷
¿
M m
b
b
m z m z A
m
M
M
m
m
M M
 o o
Then the lattice filter coefficients {Km} can be obtained by
the following recursive algorithm
1 , , 2 ); (
1 , , 1 ;
1
) ( ) (
) (
1 , , 1 ); 1 ( ) (
) 1 (
2
1
1 1
0 0



÷ = =
÷ =
÷
÷
=
÷ = ÷ =
÷ =
=
÷
÷
÷ ÷
M m m K
M m
K
z J K z A
z A
M m z A z z J
M K
b K
m m
m
m m m
m
m
m
m
M M
o
o
Note that the above algorithm will fail if |Km|=1 for any m. Clearly, this
condition is satisfied by the linear-phase FIR filter.
Therefore, linear-phase FIR filter cannot be implemented using lattice
structure.
Matlab Implementation
 Functions:
 [K] = dir2latc(b)
 [y] = latcfilt(K,x)
 [b] = latc2dir(K)

 Example 6.8
All-pole Lattice Filter
 A lattice structure for an IIR filter is restricted to an all-pole
system unction.
 It can be developed from an FIR lattice structure.



 This IIR filter of order N has a lattice structure with N stages as
shown in Fig.6.20.
 Each stage of the filter has an input and output that are related
by the order-recursive equations.
) (
1
) ( 1
1
) (
1
z A
z m a
z H
N
N
m
m
N
=
+
=
¿
=
÷
All-pole Lattice Filter
x(n)=fN(n)
gN(n)
1/z 1/z
g1(n) g2(n)
g0(n)
fN-1(n) f2(n) f0(n)
y(n)
KN
-KN
K2
-K2 -K1
K1
gN-1(n)
f1(n)
1/z
) ( ) ( ) (
1 , , 1 , ), 1 ( ) ( ) (
, 1 , ), 1 ( ) ( ) (
) ( ) (
0 0
1 1
1 1
n g n f n y
N N m n g n f K n g
N N m n g K n f n f
n x n f
m m m m
m m m m
N
= =
÷ = ÷ + =
÷ = ÷ ÷ =
=
÷ ÷
÷ ÷


Matlab Implementation
 Function [K] = dir2latc(a)
 Care must be taken to ignore the K0 coefficient
in the K array.
 Function [a] = latc2dir(K)
 K0=1
Lattice ladder Filters
 A general IIR filter containing both poles and zeros can be
realized as a lattice-type structure by using an all-pole lattice as
the basic building block.
 Consider an IIR filter with system function




 Where, without loss of generality, we assume that N>=M
) (
) (
) ( 1
) (
) (
0
0
z A
z B
z k a
z k b
z H
N
M
N
k
k
N
M
k
k
M
=
+
=
¿
¿
=
÷
=
÷
Lattice ladder Filters
 A lattice type structure can be constructed by first realizing an
all-poles lattice with coefficient {Km} for the denominator and
then adding a ladder part by taking the output as a weighted
linear combination of {gm(n)} as shown in Fig.6.22 for M=N.
Lattice ladder Filters
The output of the lattice-ladder structure is given by
¿
=
=
M
m
m m
n g C n y
0
) ( ) (
{Cm} are called the ladder coefficients that determine the
zeros of the system function H(z).
0 , , 1 , ); (
, , 2 , 0 ); ( ) ( ) (
) ( ) (
1
1
0


÷ = ÷ + =
= + =
=
¿
¿
+ =
÷
=
M M m m i C b C
M m z J C z B z B
z J C n B
i
M
m i
i m m
m m m m
M
m
m m M
o
Matlab Implementation
 Function [K,C] = dir2ladr(b,a)
 To use this function, N>=M. If M>N, then the numerator
AN(z) should be divided into the denominator BM(z) using
the deconv function to obtain a proper rational part and a
polynomial part. The proper rational part can be
implemented using the lattice-ladder structure, while the
polynomial part is implemented using the direct structure.
 Function [b,a] ladr2dir(K,C)
 Function [y] = ladrfilt(K,C,x)
Readings and exercises
 Textbook : pp182~217
 Chinese ref. Book: pp.128~137, 231~234

 Exercises :
 1. 6.2, 6.3 both except (e)
 2. 6.2e, 6.3e, 6.8, 选6.10