You are on page 1of 1

21 #define NCoef 2

22 #define DCgain 1024


23
24 __int16 iir(__int16 NewSample) {
25 __int16 ACoef[NCoef+1] = {
26 15862,
27 31724,
28 15862
29 };
30
31 __int16 BCoef[NCoef+1] = {
32 16384,
33 -31313,
34 14990
35 };
36
37 static __int32 y[NCoef+1]; //output samples
38 //Warning!!!!!! This variable should be signed (input sample width + Coefs width
+ 2 )-bit width to avoid saturation.
39
40 static __int16 x[NCoef+1]; //input samples
41 int n;
42
43 //shift the old samples
44 for(n=NCoef; n>0; n--) {
45 x[n] = x[n-1];
46 y[n] = y[n-1];
47 }
48
49 //Calculate the new output
50 x[0] = NewSample;
51 y[0] = ACoef[0] * x[0];
52 for(n=1; n<=NCoef; n++)
53 y[0] += ACoef[n] * x[n] - BCoef[n] * y[n];
54
55 y[0] /= BCoef[0];
56
57 return y[0] / DCgain;
58 }
59

You might also like