6.6.3 Software Implementations
As discussed in Chapter 1, the implementation of a digital filtering algorithm is often
carried out on a general-purpose computer to verify that the designed filter indeed meets
the goals of the application. In addition, such a software implementation may be
adequate if the application does not require real-time processing.
For computer software implementation, we describe the filter in the form of a set of I/O
difference equations. For example, a direct-form II realization of IIR filter is defined by
(6.3.2). The MATLAB function filter in the Signal Processing Toolbox implements
the IIR filter. The basic forms of this function are
y filter(b, a, x);
y filter(b, a, x, zi);
The numerator and denominator coefficients are contained in the vectors b and a
respectively. The first element of vector a, a(1), has been assumed to be equal to 1.
The input vector is x and the output vector generated by the filter is y. At the beginning,
the initial conditions (data in the signal buffer) are set to zero. However, they can be
specified in the vector zi to reduce transients.
The direct-form realization of IIR filters can be implemented using following C
function (iir.c in the software package):
/****************************************************************
*IIR.C ± This function performs IIR filtering
*
*
*
*naÀ1
nbÀ1
*
*yn sum ai *x(nÀi) À sum bj *y(nÀj)
*
*
i0
j1
*
*
*
****************************************************************/
float iir(float *x, int na, float *a, float *y, int nb, float *b,
int maxa, int maxb)
{
float yn;
/*Output of IIR filter */
float yn1, yn2;
/*Temporary storage
*/
int i, j;
/*Indexes
*/
yn1 (float) 0.0;
/*y1(n) 0. */
yn2 (float) 0.0;
/*y2(n) 0. */
for(i 0; i < naÀ1; ++i)
{
yn1 yn1 x[maxaÀ1Ài]*a[i];
/*FIR filtering of x(n)to get y1(n) */
}
IMPLEMENTATION CONSIDERATIONS
279