Digital Signal Processing Reference
In-Depth Information
filled with zeros (unless we know the state of the filter), and the C array is filled
with the FIR coefficients in reverse order. The final value of the C array is the
filter's gain constant. We will use movable pointers within the M and C arrays. The
m1 and m2 pointers are initially set to the start of the array and then incremented
toward the end. By using two movable pointers, we can transfer memory states
without any need for address computation. The final step in the process (before
converting the output variable back to an integer) is to multiply the accumulated
value in o by the gain constant of the filter. Although for this code, we obtain the
value of input from an array, it could just as well be coming from an input port on
a DSP system. Likewise, the output value could be written to an output port
instead of an array.
/*====================================================
Dig_FIR_Filt_RT() - filters input array using FIR
coefs (uses real-time code)
Prototype: void Dig_FIR_Filt_RT(int *X,int *Y,
double *M,double *C,int numb_coefs,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_coefs - number of coefficients
N - number of values in array
====================================================*/
void Dig_FIR_Filt_RT(int *X,int *Y,double *M,double *C
,int numb_coefs,int N)
{ int *x,*y, /* ptrs to in/out arrays */
i,j; /* loop counters */
double *c,*m1,*m2, /* ptrs to coef/memory array */
o; /* output value */
/* Make copies of input and output pointers */
x = X;
y = Y;
/* Start loop for number of data values */
for(i = 0; i < N ;i++)
{ /* Make copy of pointers and start loop */
M[numb_coefs-1] = *x++;
c = C;
m1 = m2 = M;
o = *m1++ * *c++;
/* Use convolution method for computation */
for(j = 1; j < numb_coefs ;j++)
{ *m2++ = *m1;
o += *m1++ * *c++;
}
/* Multiply by gain, convert to int and store */
o *= *c;
*y++ = (int)ceil(o-0.5);
}
}
Listing 8.4 Dig_FIR_Filt_RT function.
Search WWH ::




Custom Search