I am trying to implement an IIR filter.
I tried to implement the following filter but
FIR : y(n) = b0(x[n]) + ... +bM-1(x[n-M+1])
IIR : y(n) = {b0(x[n]) + ... +bM-1(x[n-M+1])} - {a1(y[n-1]) + ... +aN(y[n-N}
I am confused on how to implement y[n-1].....
.
Here is my code.
void IIRFloat(double *coeffs_B, double *coeffs_A, double *input, double *output, int length, int filterLength)
{
double bcc, acc;
double *coeffa, *coeffb;
double *inputp;
double *outputp;
int n,k;
//filter length =7
for (n = 0; n < length; n++) {
coeffa = coeffs_A;
coeffb = coeffs_B;
inputp = &insamp[filterLength - 1 + n]; //insamp[6]~insamp[85]
acc = 0;
bcc = 0;
for (k = 0; k < filterLength; k++) {
bcc += (*coeffb++) * (*inputp--); //b[0] * x[6] + b[1] * x[5]...+b[6] * x[0]
}
for (k = 1; k < filterLength; k++) {
acc += (*coeffa++) * (*output--); //a[1] * y[5] + a[2] * y[4]...+a[6] * y[0]
}
output[n] = bcc-acc;
}
}
I will not copy here the code for memove
function for seek of brevity.