Digital Signal Processing Reference
In-Depth Information
assumed that there are two quadratic factors and sample values have been entered
for the C and M arrays. At each step of the process, the particular values to which
c, m1 , or m2 are pointing within the arrays are shown in bold. Only the first time
through the inner loop is illustrated, but we can see from this how the pointers
progress through the arrays, and how the memory state array is changed.
In lines 1 and 2 of Listing 8.2, the addresses of the input and output arrays are
transferred to temporary variables x and y that can change without affecting the
addresses stored in X and Y . Then, line 4 begins a for loop to process every value
in the input array. Lines 6 to 8 set up pointers to the memory states and coefficient
arrays. The m1 pointer is set to start at the beginning of the M array where the m 1
states are stored, while the m2 pointer is set midway through the M array since the
m 2 states are stored in the second half of the array. The initial value of the output,
indicated by o , is calculated by multiplying the input value by the first value in the
coefficient array, which is the gain constant.
/*====================================================
Dig_IIR_Filter() - filters input array using IIR
coefs and mem values to generate output
Prototype: void Dig_IIR_Filter(int *X,int *Y,
double *M,double *C,int numb_quads,int N);
Return: error value.
Arguments: X - ptr to input array
Y - ptr to output array
M - ptr to memory array
C - ptr to coefs array
numb_quads - number of quadratics
N - number of values in array
====================================================*/
void Dig_IIR_Filter(int *X,int *Y,double *M,double *C,
int numb_quads,int N)
{ int *x,*y, /* ptrs to in/out arrays */
i,j; /* loop counters */
double *c,*m1,*m2, /* ptrs to coef/memory arrays*/
w,o; /* intermed & output values */
/* Make copies of input and output pointers */
01 x = X;
02 y = Y;
x: 3 ,4,5,6,7,...
y: 0 ,0,0,0,0,...
03 /* Start loop for number of data values */
04 for(i = 0; i < N ;i++)
05 { /* Make copies of pointers and start calcs */
06 m1 = M;
07 m2 = M + numb_quads;
08 c = C;
C: 0.20 ,1.0,-0.80,-2.0,-1.0,0.05,-0.20,-2.0,-1.0
M : 1.0 ,3.0, 2.0 ,4.0
09 o = *x++ * *c++;
C: 0.20, 1.0 ,-0.80,-2.0,-1.0,0.05,-0.20,-2.0,-1.0
x: 3, 4 ,5,6,7,...
o: 0.60
Listing 8.2 Dig_IIR_Filter function.
Search WWH ::




Custom Search