Вот сам фильтр который не желает усреднять.
Может с ним что не так?
Есть подозрение что у коэфф. точности флоата не хватает и он возбуждается.
Но не уверен.
/**************************************************************
WinFilter version 0.8
http://www.winfilter.20m.comakundert@hotmail.com
Filter type: Low Pass
Filter model: Bessel
Filter order: 4
Sampling Frequency: 8 KHz
Cut Frequency: 0.005000 KHz
Coefficents Quantization: float
Z domain Zeros
z = -1.000000 + j 0.000000
z = -1.000000 + j 0.000000
z = -1.000000 + j 0.000000
z = -1.000000 + j 0.000000
Z domain Poles
z = 0.994770 + j -0.001392
z = 0.994770 + j 0.001392
z = 0.999100 + j -0.004321
z = 0.999100 + j 0.004321
***************************************************************/
#define NCoef 4
float iir(float NewSample) {
float ACoef[NCoef+1] = {
0.00000000008095721658,
0.00000000032382886631,
0.00000000048574329947,
0.00000000032382886631,
0.00000000008095721658
};
float BCoef[NCoef+1] = {
1.00000000000000000000,
-3.98773984171834520000,
5.96328712390839670000,
-3.96335452951837610000,
0.98780724756468707000
};
static float y[NCoef+1]; //output samples
static float x[NCoef+1]; //input samples
int n;
//shift the old samples
for(n=NCoef; n>0; n--) {
x[n] = x[n-1];
y[n] = y[n-1];
}
//Calculate the new output
x[0] = NewSample;
y[0] = ACoef[0] * x[0];
for(n=1; n<=NCoef; n++)
y[0] += ACoef[n] * x[n] - BCoef[n] * y[n];
return y[0];
}