# How to optimally normalize filter coefficients?

I have designed an IIR filter in Matlab that comprises the following biquads

0.244   0.002   0.244   1   -1.432  0.543
0.244   -0.345  0.244   1   -1.555  0.777
0.244   -0.388  0.244   1   -1.652  0.943


I want to implement this filter in a 16-bit DSP. Before converting the coefficients to short int, I therefore normalize them by dividing all coefficients by the largest magnitude present in the matrix (in this case 1.652). This results in

b0      b1      b2      a0       a1     a2
0.147   0.001   0.147   0.605   -0.866  0.328
0.147   -0.208  0.147   0.605   -0.941  0.470
0.147   -0.235  0.147   0.605   -1      0.570


I then convert these coefficients to 16-bit values ranging from +32767 to -32768. I implemented the filter using the Transposed Direct Form II. The I realized that the gain is very low although the filter shows 0 dB in the passband when testing it in Matlab. The algorithm is as follows. It iterates through all biquads and reintroduces their ouputs to the next one as necessary.

for (k = 0; k < N_sos; k++) {

y_n = (short) ((s1[k] + b[k] * x_n) >> 15);

s1[k] = s2[k] + b[k] * x_n - a[k] * y_n;

s2[k] = b[k] * x_n - a[k] * y_n;

s1[k] = s1[k];

s2[k] = s2[k];

x_n = y_n;
}

IIR_out = y_n;



Notice that I have not taken the a0 coefficient into account. Since it usually is 1, it does not matter. But I wonder if the missing gain is caused by this missing coefficient. I tried multiplying y_n with it by exchanging

y_n = (short) ((s1[k] + b[k] * x_n) >> 15);


with

y_n = (short) a[k] * ((s1[k] + b[k] * x_n) >> 15);


but this heavily distorts the signal.

• you should divide ((s1[k] + b[k] * x_n) >> 15) by a[k]
– Ben
Feb 23, 2021 at 16:04
• That doesn't make sense. It reduces the gain even more. Feb 23, 2021 at 16:12
• a is less than 1, so it will increase the gain!
– Ben
Feb 23, 2021 at 16:13
• I know and I just tried it. Now I have no output anymore, when I do that Feb 23, 2021 at 16:22
• Well simply adapt your fixed-point arithmetic to that reality... Mulitply the coefficients by 16384, not 32768. No one said that fixed-point coefficients must be smaller than 1.
– Ben
Feb 23, 2021 at 16:40