# How to apply the gain factor G to SOS coefficients when designing a IIR filter on sptool (MATLAB)?

After designing an IIR filter on sptool, I export the coefficients (SOS) and gain (G) into a .mat file. When filtering, we can use sosfilt(SOS, x), which results in the correct output but with the wrong scaling. I guess this is what the gain variable G is for, but the documentation of sosfilt() never mentions this.

The impulse response of the filter has values of several powers of ten (~10^16), whereas in sptool it had very small coefficients (< 1).

How is one supposed to use the SOS and G variables when exported from sptool, to correctly scale the weights of the exported IIR filter?

• The SOS gain can be applied before the filter, after the filter, or you could multiply the numerator coefficients by the SOS gain.
– Ben
Apr 16 at 16:30
• @Ben could you provide an example of how that would look like? Apr 16 at 16:37

The easiest way would be

y = prod(G)*sosfilt(SOS,x);


An alternative would be put to the cumulative gain into the first section.

sosScaled = SOS;
sosScaled(1,1:3) = sosScaled(1,1:3)*prod(G);
y = sosfilt(sosScaled,x);

• this is great. I am not sure I understand why we do this. Could you point out to where you came up with this solution? I didn't see this on any documentation of these functions in matlab. Would really appreciate some intuition Apr 16 at 16:58
• Each section is formed by matching a complex pair of zeros with a complex pair of poles. fdatool does not apply any scaling, but puts a separate scale factor for each section. For a lowpass filter, it's chosen so that the DC gain of each section is 0 dB. That can be useful for a fixed point implementation, but it's pointless and needlessly complicated for a standard floating point implementation. The overall gain is simply the product of all section gains. The "normal procedure" would be to wrap the total gain into the numerator of the first section. Apr 16 at 18:28