# MATLAB IIRs — extracting and scaling the coefficients of second order sections

suppose I generate the following filter:

Fs = 32000;  % Sampling Frequency
N     = 4;    % Order
Fpass = 400;  % Passband Frequency
Apass = 1;    % Passband Ripple (dB)
h  = fdesign.lowpass('N,Fp,Ap', N, Fpass, Apass, Fs);
Hd = design(h, 'cheby1', 'FilterStructure', 'df2sos');


"Hd" at the interactive prompt gives me:

 sosMatrix: [1 2 1 1 -1.97232454484577 0.978340933957857;1 2 1 1 -1.94676435093801 0.948444394718458]
ScaleValues: [0.00150409727802169;0.000420010945111697;0.891250938133746]


I notice that freqz(Hd.sosMatrix) gives me a wildly off magnitude estimation (but with the correct frequency cutoff).

My question is, how do I use this Hd.ScaleValues factor? There are 3 values for two sections.

These scale values are applied before and after each section, so for $N$ sections you have $N+1$ scale values. Check the Matlab documentation, there must be some related property that you can set to 'scalar', and this will give you a single total scaling value. In any case, the total scaling is just the product of the three values in your case. So you have to multiply the b coefficients of one filter section by the product of all scale values, then the total scaling will be OK, i.e. the maximum frequency response magnitude will be 0 dB.