Professional Documents
Culture Documents
Aims
This lab session aims at the theory for the processing of digital signals. To process signals, we have to
design and implement filters. Before we discuss the design issue, we first concern ourselves with how
these filters can be implemented
Pre-Lab:
Basic Elements
Since our filters are LTI systems, we need three basic elements to describe digital filter structures.
1. Adder: This element has two inputs and one output and is shown in Figure 7.1. Note that the
addition of three or more signals is implemented by successive two-input adders.
2. Multiplier (gain): This is a single-input, single-output element and is shown in Figure 7.2. Note
that the multiplication by 1 is understood.
3. Delay element (shifter or memory): This element delays the signal passing through it by one
sample, as shown in Figure 7.3. It is implemented by using a shift register.
Using these basic elements, we can now describe various structures of all kind of filters. MATLAB is a
convenient tool in the development of these structures that require operations on polynomials.
Page 1
Laboratory 7: Discrete Filter Structure 7.2
Filter Structure
The system function of an IIR filter is given by
𝐵(𝑧) ∑𝑀
𝑛=0 𝑏𝑛 𝑧
−𝑛
𝑏0 + 𝑏1 𝑧 −1 + ⋯ + 𝑏𝑀 𝑧 −𝑀
𝐻(𝑧) = = = (7.1)
𝐴(𝑧) ∑𝑁
𝑛=0 𝑎𝑛 𝑒
−𝑛 1 + 𝑎1 𝑧 −1 + ⋯ + 𝑎𝑁 𝑧 −𝑁
where 𝑏𝑛 and 𝑎𝑛 are the coefficients of the filter. We have assumed without loss of generality that 𝑎0 =
1. The order of such an IIR filter is called N if 𝑎𝑁 ≠ 0. The difference equation representation of an IIR
filter is expressed as
𝑁 𝑁
𝑀
𝐵(𝑧)
𝐻(𝑧) = = ∑ 𝑏𝑛 𝑧 −𝑛 (7.3)
𝐴(𝑧)
𝑛=0
where 𝑏𝑛 is the coefficients of the filter. The difference equation representation of an IIR filter is
expressed as
𝑦(𝑛) = ∑ 𝑏𝑚 𝑥(𝑛 − 𝑚)
(7.4)
𝑚=0
1. Direct form: In this form the difference equations (7.2) and (7.4) are implemented directly as
given. There are two parts to this filter, namely the moving average part and the recursive part
(or equivalently, the numerator and denominator parts). Therefore this implementation leads to
two versions: direct form I and direct form II structures.
2. Cascade form: In this form the system function H(z) in equations (7.1) and (7.3) are factored into
smaller 2nd-order sections, called biquads. The system function 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.
3. Parallel form: This is similar to the cascade form, but after factorization, a partial fraction
expansion is used to represent H(z) as a sum of smaller 2nd-order sections. Each section is again
implemented in a direct form, and the entire system function is implemented as a parallel
network of sections.
Laboratory 7: Discrete Filter Structure 7.3
Direct Form
As the name suggests, the difference equation is implemented as given using delays, multipliers, and
adders. For the purpose of illustration, let M = N = 4. Then the difference equation is
The direct form I structure implements each part of the rational function H(z) separately with a cascade
connection between them. The numerator part is a tapped delay line followed by the denominator part,
which is a feedback tapped delay line. Thus there are two separate delay lines in this structure, and
hence it requires eight delay elements. We can reduce this delay element count or eliminate one delay
line by interchanging the order in which the two parts are connected in the cascade. Now the two delay
lines are close to each other, connected by a unity gain branch. Therefore one delay line can be
removed, and this reduction leads to a canonical structure called direct form II structure, shown in
Figure 7.5.
An equivalent structure to the direct form can be obtained using a procedure called transposition. In this
operation three steps are performed:
The resulting structure is called the transposed direct form structure. The transposed direct form II
structure is shown in Figure 7.6.
Cascaded Form
In this form the system function H(z) is written as a product of 2nd-order sections 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 2nd-order polynomials.
𝐾
1 + 𝐵𝑘.1 𝑧 −1 + 𝐵𝑘.2 𝑧 −2
𝐻(𝑧) = 𝑏0 ∏
1 + 𝐴𝑘.1 𝑧 −1 + 𝐴𝑘.2 𝑧 −2 (7.5)
𝑘=1
The 2nd-order section is called the kth biquad section. The input to the kth biquad section is the output
from the (k − 1)th biquad section and so on. Each biquad section Hk(z) can be implemented in direct form
II. The entire filter is then implemented as a cascade of biquads.
As an example, consider N = 4. Figure 7.7 shows a cascade form structure for this 4th-order IIR filter.
Matlab Implementation
Given the coefficients {bn} and {an} of the direct form filter, we have to obtain the coefficients b0, {Bk,i},
and {Ak,i}. This is done by the following function dir2cas.
This function converts the b and a vectors into K × 3 B and A matrices. It begins by computing b0, which
is equal to b0/a0 (assuming a0≠1). It then makes the vectors b and a of equal length by zero-padding the
shorter vector. This ensures that each biquad has a nonzero numerator and denominator. Next it
computes the roots of the B(z) and A(z) polynomials. Using the cplxpair function, these roots are
ordered in complex conjugate pairs. Now every pair is converted back into a 2nd-order numerator or
denominator polynomial using the poly function. The SP toolbox function, tf2sos (transfer function to
2nd-order section), also performs a similar operation.
The following MATLAB function, cas2dir, converts a cascade form to a direct form. This is a simple
operation that involves multiplication of several 2nd-order polynomials. For this purpose, the MATLAB
function conv is used in a loop over K factors. The SP toolbox function, sos2tf also performs a similar
operation.
Parallel Form
In this form the system function H(z) is written as a sum of 2nd-order sections using partial fraction
expansion
𝐾 𝑀−𝑁
𝐵(𝑧) 𝐵𝑘.0 + 𝐵𝑘.1 𝑧 −1
𝐻(𝑧) = =∑ −1 −2
+ ∑ 𝐶𝑘 𝑧 −𝑘 (7.6)
𝐴(𝑧) 1 + 𝐴𝑘.1 𝑧 + 𝐴𝑘.2 𝑧
𝑘=1 0
The 2nd-order section is the kth proper rational biquad section. The filter input is available to all biquad
sections as well as to the polynomial section. The output from these sections is summed to form the
filter output. Now each biquad section Hk(z) can be implemented in direct form II. Due to the summation
of subsections, a parallel structure can be built to realize H(z).
As an example, consider M = N = 4. Figure 7.8 shows a parallel-form structure for this 4th-order IIR filter.
Matlab Implementation
The following function dir2par converts the direct-form coefficients {bn} and {an} into parallel form
coefficients {Bk,i} and {Ak,i}.
We need to arrange pole-and-residue pairs into complex conjugate pole-and-residue pairs followed by
real poleand-residue pairs. To do this, the cplxpair function from MATLAB can be used; this sorts a
complex array into complex conjugate pairs. However, two consecutive calls to this function, one each
for pole and residue arrays, will not guarantee that poles and residues will correspond to each other.
Therefore a new cplxcomp function is developed, which compares two shuffled complex arrays and
returns the index of one array, which can be used to rearrange another array
function I = cplxcomp(p1,p2)
% I = cplxcomp(p1,p2)
% Compares two complex pairs which contain the same scalar elements
% but (possibly) at differrent indices. This routine should be
% used after CPLXPAIR routine for rearranging pole vector and its
% corresponding residue vector.
% p2 = cplxpair(p1)
%
I=[];
for j=1:1:length(p2)
for i=1:1:length(p1)
if (abs(p1(i)-p2(j)) < 0.0001)
I=[I,i];
end
end
end
Laboratory 7: Discrete Filter Structure 7.8
I=I';
Similarly, to obtain a direct form from a parallel form, the function par2dir can be used. It computes
poles and residues of each proper biquad and combines these into system poles and residues. Another
call of the residuez function in reverse order computes the numerator and denominator polynomials.
Main Lab
6B: Consider the block diagram shown in Figure 7.11. This structure contains a cascade of two parallel
sections.
6C: Draw the structure in MATLAB using Simulink also redraw the reduce structure in Simulink.
Providing an input to the system and by showing the response on scope verify that all structure gave
same response.