% Filter design
%
[N,Wn] buttord(Wp,Ws,Rp,Rs); % Filter order selection
[b,a] butter(N,Wn);
% Butterworth filter design
[Z,P,K] tf2zp(b,a);
% Transfer function to zero-pole
[sos,G] zp2sos(Z,P,K);
% Zero-pole to second-order section
This program generates a fourth-order IIR filter with the following coefficient vectors:
b [0.0098,0.0393,0.0590,0.0393,0.0098]
a [1.0000,À1.9908,1.7650,À0.7403,0.1235].
The fourth-order IIR filter is then converted into two second-order sections repre-
sented by the coefficients matrix sos and the overall system gain G. By decomposing the
coefficient matrix sos defined in (6.4.19), we obtain two matrices
b 0:0992 0:1984 0:0992
0:0992 0:1984 0:0992
!
and a 1:0 À0:8659 0:2139
1:0 À1:1249 0:5770
!
,
6:7:1
where we equally distribute the overall gain factor into each second-order cascade
configuration for simplicity. In the subsequent sections, we will use this Butterworth
filter for the TMS320C55x experiments.
6.7.2 Experiment 6A ± Floating-Point C Implementation
For an IIR filter consists of K second-order sections, the I/O equation of the cascade
direct-form II realization is given by Equation (6.4.14). The C implementation of
general cascade second-order sections can be written as follows:
temp input[n];
for(k 0; k < IIR_SECTION; k)
{
w[k][0] temp À a[k][1]*w[k][1]À a[k][2]*w[k][2];
temp b[k][0]*w[k][0]+ b[k][1]*w[k][1]+ b[k][2]*w[k][2];
w[k][2] w[k][1];
/*w(nÀ2) <- w(nÀ1) */
w[k][1] w[k][0];
/*w(nÀ1) <- w(n)
*/
}
output[n] temp;
where a [][]and b [][]are filter coefficient matrices defined in (6.7.1), and w [][]is the
signal buffer for w
k
n À m, m 0, 1, 2. The row index k represents the kth second-
order IIR filter section, and the column index points at the filter coefficient or signal
sample in the buffer.
As mentioned in Chapter 5, the zero-overhead repeat loop, multiply±accumulate
instructions, and circular buffer addressing modes are three important features of
DSP processors. To better understand these features, we write the IIR filter function
in C using data pointers to simulate the circular buffers instead of two-dimensional
arrays. We also arrange the C statements to mimic the DSP multiply/accumulate
operations. The following C program is an IIR filter that consists of Ns second-order
286
DESIGN AND IMPLEMENTATION OF IIR FILTERS