home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_10_05
/
1005052b
< prev
next >
Wrap
Text File
|
1992-03-11
|
1KB
|
37 lines
Listing 4. Filter with circular buffer
/* Filters the vector, v, of input values, putting the
* results back in the same vector.
*/
void filter(Filter *f, double *v, int length)
{
/* Making a local copy saves execution time */
CircularBuffer y = *(f->y);
/* Loop through the vector values */
for(; length--; v++)
{
double
sum = *v, /* becomes filter output */
*c = f->coef;
int k = f->order, /* The number of coefficients */
i = y.index; /* Index to previous outputs */
/* Loop through filter coefficients */
for(; k--; c++)
{
i = (i - 1) & y.mask;
sum -= *c * y.buffer[i];
}
/* Save output for next data point */
y.buffer[y.index] = sum;
y.index = (y.index + 1) & y.mask;
*v = sum; /* Set output value */
}
/* Store the local copy back in the filter structure */
*(f->y) = y;
}