Digital Signal Processing Reference
In-Depth Information
Although the algorithm in Listing 8.1 will make the correct computations, it
could be slow because of all of the index calculations that must be made.
(Actually, compilers will differ in terms of how much optimization can be made
with speed-critical code such as we are discussing.) The speed of this loop can
usually be increased by using pointers to the coefficients and memory values. In
order to take advantage of this pointer efficiency we must store the filter
coefficients in an orderly manner, which will allow them to be accessed
sequentially in the exact order that they are needed. We can define a new array C
that will store all of the needed coefficients as well as the filter gain constant. The
first element in the array will be the gain constant followed by the coefficients b 1 ,
b 2 , a 1 , and a 2 for each quadratic factor. The structure of the C array then has the
following form:
C[0] = gain
C[5] = b 1 (quad 2)
C[1] = b 1 (quad 1)
C[6] = b 2 (quad 2)
C[2] = b 2 (quad 1)
C[7] = a 1 (quad 2)
C[3] = a 1 (quad 1)
C[8] = a 2 (quad 2)
C[4] = a 2 (quad 1)
...
In addition, an M array must be created to store the memory states of the IIR
filter. The size of the array is equal to twice the number of quadratic factors with
the m 1 states stored in the first half of the array and the m 2 states in the last half.
Initially, all of the memory states are set to zero (unless we know some predefined
state exists for the filter). Thus, the M array has the following structure where N is
the number of quadratics:
M[0] = m 1 (quad 1)
M[N] = m (quad 1)
2
M[1] = m 1 (quad 2)
M[N + 1] = m 2 (quad 2)
M[2] = m (quad 3)
M[N + 2] = m (quad 3)
1
2
...
...
Listing 8.2 shows the Dig_IIR_Filter function used in the DIGITAL
program discussed later in this chapter. (All of the functions discussed in this
chapter can be found in the \DIGITAL\DIGITAL.C module on the software disc
that accompanies this text.) The function takes as arguments pointers to arrays of
input values ( X ), output values ( Y ), memory states ( M ), and coefficient values ( C ),
as well as the number of quadratic factors and number of values in the input and
output arrays. Notice that since we will be progressing through the X , Y , C , and M
arrays, we have defined indexing pointers x , y , c , and m, which can take on
changing values. ( Never use the array name itself as an index or the address of the
array will be lost.) The notation may look a little foreign so let's take a look at the
code on a line-by-line basis. (The line numbers shown are to help with this
discussion and are not part of the normal code.) The process of using pointers is
very efficient for computational purposes because it fits the nature of the
computer. However, it can be a bit confusing to follow. Therefore, in order to
provide a more descriptive analysis of the IIR filter code, the code has been
annotated with the status of primary arrays and variables. For this illustration, it is
Search WWH ::




Custom Search