Second-order (biquadratic) IIR digital filtering
Second-Order Section Filtering
chirp.mat. The file contains a signal,
y, that has most of its power above
Fs/4, or half the Nyquist frequency. The sample rate is 8192 Hz.
load chirp t = (0:length(y)-1)/Fs;
Design a seventh-order Butterworth highpass filter to attenuate the components of the signal below
Fs/4. Use a normalized cutoff frequency of 0.48π rad/sample. Express the filter coefficients in terms of second-order sections.
[zhi,phi,khi] = butter(7,0.48,'high'); soshi = zp2sos(zhi,phi,khi); freqz(soshi)
Filter the signal. Display the original and highpass-filtered signals. Use the same y-axis scale for both plots.
outhi = sosfilt(soshi,y); figure subplot(2,1,1) plot(t,y) title('Original Signal') ys = ylim; subplot(2,1,2) plot(t,outhi) title('Highpass-Filtered Signal') xlabel('Time (s)') ylim(ys)
Design a lowpass filter with the same specifications. Filter the signal and compare the result to the original. Use the same y-axis scale for both plots. The result is mostly noise.
[zlo,plo,klo] = butter(7,0.48); soslo = zp2sos(zlo,plo,klo); outlo = sosfilt(soslo,y); subplot(2,1,1) plot(t,y) title('Original Signal') ys = ylim; subplot(2,1,2) plot(t,outlo) title('Lowpass-Filtered Signal') xlabel('Time (s)') ylim(ys)
sos — Second-order section digital filter
Second-order section digital filter, specified as an L-by-6 matrix, where L is the number of second-order sections. The matrix
represents the second-order section digital filter
[b,a] = butter(3,1/32); sos = tf2sos(b,a) specifies a
third-order Butterworth filter with a normalized 3 dB frequency of
x — Input signal
vector | matrix | N-D array
Input signal, specified as a vector, matrix, or N-D array.
x = [2 1].*sin(2*pi*(0:127)'./[16 64]) specifies a
Complex Number Support: Yes
dim — Dimension to operate along
positive integer scalar
Dimension to operate along, specified as a positive integer scalar. By default,
sosfilt operates along the first array dimension of
x with size greater than 1.
 Bank, Balázs. "Converting Infinite Impulse Response Filters to Parallel Form". IEEE Signal Processing Magazine. Vol. 35, Number 3, May 2018, pp. 124-130.
 Orfanidis, Sophocles J. Introduction to Signal Processing. Englewood Cliffs, NJ: Prentice-Hall, 1996.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
Usage notes and limitations:
sosmust be stable. Use
isstableto check for filter stability.
All second-order subsections of the input filter must be IIR.
gpuArrayversion of sosfilt uses a parallel algorithm  which is different from the MATLAB® version. The algorithms give different results for complex-valued input with
In the MATLAB version, the
Infs propagate only in the real part.
Infs propagate in both the real part and the imaginary part.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).