Convert digital filter state-space parameters to second-order sections form
[sos,g] = ss2sos(A,B,C,D)
[sos,g] = ss2sos(A,B,C,D,iu)
[sos,g] = ss2sos(A,B,C,D,
[sos,g] = ss2sos(A,B,C,D,iu,
[sos,g] = ss2sos(A,B,C,D,iu,
sos = ss2sos(...)
ss2sos converts a state-space representation
of a given digital filter to an equivalent second-order section representation.
[sos,g] = ss2sos(A,B,C,D) finds a matrix
sos in second-order section form with gain
that is equivalent to the state-space system represented by input arguments
The input state-space system must be single-output and real.
sos is an L-by-6 matrix
whose rows contain the numerator and denominator coefficients bik and aik of the second-order sections of H(z).
[sos,g] = ss2sos(A,B,C,D,iu) specifies
iu that determines which input of the
used in the conversion. The default for
iu is 1.
[sos,g] = ss2sos(A,B,C,D, and
[sos,g] = ss2sos(A,B,C,D,iu, specify
the order of the rows in
'down', to order the sections so
the first row of
sos contains the poles closest
to the unit circle
'up', to order the sections so
the first row of
sos contains the poles farthest
from the unit circle (default)
The zeros are always paired with the poles closest to them.
[sos,g] = ss2sos(A,B,C,D,iu, specifies
the desired scaling of the gain and the numerator coefficients of
all second-order sections, where
'none', to apply no scaling (default)
'inf', to apply infinity-norm scaling
'two', to apply 2-norm scaling
Using infinity-norm scaling in conjunction with
minimizes the probability of overflow in the realization. Using 2-norm
scaling in conjunction with
the peak round-off noise.
Infinity-norm and 2-norm scaling are appropriate only for direct-form II implementations.
sos = ss2sos(...) embeds
the overall system gain,
g, in the first section, H1(z),
Embedding the gain in the first section when scaling a direct-form II structure is
not recommended and may result in erratic scaling. To avoid embedding the gain, use
ss2sos with two outputs.
Design a 5th-order Butterworth lowpass filter using the
butter function. Specify a cutoff frequency of rad/sample. Express the output in state-space form. Convert the state-space result to second-order sections. Visualize the frequency response of the filter.
[A,B,C,D] = butter(5,0.2); sos = ss2sos(A,B,C,D)
sos = 3×6 0.0013 0.0013 0 1.0000 -0.5095 0 1.0000 2.0010 1.0010 1.0000 -1.0966 0.3554 1.0000 1.9973 0.9973 1.0000 -1.3693 0.6926
A one-dimensional discrete-time oscillating system consists of a unit mass, , attached to a wall by a spring of unit elastic constant. A sensor measures the acceleration, , of the mass.
The system is sampled at Hz. Generate 50 time samples. Define the sampling interval .
Fs = 5; dt = 1/Fs; N = 50; t = dt*(0:N-1);
The oscillator can be described by the state-space equations
where is the state vector, and are respectively the position and velocity of the mass, and the matrices
A = [cos(dt) sin(dt);-sin(dt) cos(dt)]; B = [1-cos(dt);sin(dt)]; C = [-1 0]; D = 1;
The system is excited with a unit impulse in the positive direction. Use the state-space model to compute the time evolution of the system starting from an all-zero initial state.
u = [1 zeros(1,N-1)]; x = [0;0]; for k = 1:N y(k) = C*x + D*u(k); x = A*x + B*u(k); end
Plot the acceleration of the mass as a function of time.
Compute the time-dependent acceleration using the transfer function to filter the input. Express the transfer function as second-order sections. Plot the result.
sos = ss2sos(A,B,C,D); yt = sosfilt(sos,u); stem(t,yt,'filled')
The result is the same in both cases.
ss2sos uses a four-step algorithm to determine
the second-order section representation for an input state-space system:
It finds the poles and zeros of the system
It uses the function
zp2sos, which first groups the zeros
and poles into complex conjugate pairs using the
zp2sos then forms the second-order sections
by matching the pole and zero pairs according to the following rules:
Match the poles closest to the unit circle with the zeros closest to those poles.
Match the poles next closest to the unit circle with the zeros closest to those poles.
Continue until all of the poles and zeros are matched.
ss2sos groups real poles into sections with
the real poles closest to them in absolute value. The same rule holds
for real zeros.
It orders the sections according to the
proximity of the pole pairs to the unit circle.
orders the sections with poles closest to the unit circle last in
the cascade. You can tell
ss2sos to order the sections
in the reverse order by specifying the
ss2sos scales the
sections by the norm specified in the
For arbitrary H(ω), the scaling is defined
where p can be either ∞ or 2. See the references for details. This scaling is an attempt to minimize overflow or peak round-off noise in fixed point filter implementations.
 Jackson, L. B. Digital Filters and Signal Processing. 3rd Ed. Boston: Kluwer Academic Publishers, 1996, chap. 11.
 Mitra, S. K. Digital Signal Processing: A Computer-Based Approach. New York: McGraw-Hill, 1998, chap. 9.
 Vaidyanathan, P. P. “Robust Digital Filter Structures.” Handbook for Digital Signal Processing (S. K. Mitra and J. F. Kaiser, eds.). New York: John Wiley & Sons, 1993, chap. 7.