0
$\begingroup$

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?

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

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);
$\endgroup$
2
  • $\begingroup$ 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 $\endgroup$ – hirschme Apr 16 at 16:58
  • 1
    $\begingroup$ 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. $\endgroup$ – Hilmar Apr 16 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.