I've implemented a IIR filter but it outputs only noise (like FM radio out of tuning) and I can't see what's wrong.
This is the processing function:
void Filter::process(int size, double *in, double *out)
{
double xb[2] = { 0, 0 };
double yb[2] = { 0, 0 };
for (int n = 0; n < size; n++)
{
out[n] = (coeffs->a0 * in[n]) + (coeffs->a1 * xb[0])
+ (coeffs->a2 * xb[1]) - (coeffs->b1 * yb[0])
- (coeffs->b2 * yb[1]);
xb[1] = xb[0];
xb[0] = in[n];
yb[1] = yb[0];
yb[0] = out[n];
}
}
in
and out
are the buffers of sampled data at 48kHz; and size
is 1024.
The coefficients are for $ {Fc \over Fs} = {500 \over 48000 } $ and $ Q = 0.7071 $
a0: 0.00107054
a1: 0.00214108
a2: 0.00107054
b1: -1.99572
b2: 0.953753
b1
andb2
coefs don't look like they result in stable poles. |b1
| needs to be smaller than 1+b2
. |b1
+b2
| should be less than 1. $\endgroup$b
in yourxb[2]
andyb[2]
states signify? $\endgroup$b
stands forbuffer
$\endgroup$