Main Content

sosfilt

Second-order (biquadratic) IIR digital filtering

Description

example

y= sosfilt(sos,x)applies the second-order section digital filtersosto the input signalx.

  • Ifxis a matrix, then the function operates along the first dimension and returns the filtered data for each column.

  • Ifxis a multidimensional array, then the function operates along the first array dimension with size greater than 1.

y= sosfilt(sos,x,dim)operates along the dimensiondim.

Examples

collapse all

Loadchirp.mat. The file contains a signal,y, that has most of its power aboveFs/4, or half the Nyquist frequency. The sample rate is 8192 Hz.

loadchirpt = (0:length(y)-1)/Fs;

Design a seventh-order Butterworth highpass filter to attenuate the components of the signal belowFs/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)

Figure contains 2 axes objects. Axes object 1 with title Phase, xlabel Normalized Frequency (\times\pi rad/sample), ylabel Phase (degrees) contains an object of type line. Axes object 2 with title Magnitude, xlabel Normalized Frequency (\times\pi rad/sample), ylabel Magnitude (dB) contains an object of type line.

Filter the signal. Display the original and highpass-filtered signals. Use the samey-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)

Figure contains 2 axes objects. Axes object 1 with title Original Signal contains an object of type line. Axes object 2 with title Highpass-Filtered Signal, xlabel Time (s) contains an object of type line.

Design a lowpass filter with the same specifications. Filter the signal and compare the result to the original. Use the samey-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)

Figure contains 2 axes objects. Axes object 1 with title Original Signal contains an object of type line. Axes object 2 with title Lowpass-Filtered Signal, xlabel Time (s) contains an object of type line.

Input Arguments

collapse all

Second-order section digital filter, specified as anL-by-6 matrix whereLis the number of second-order sections. The matrix

sos = [ b 01 b 11 b 21 1 a 11 a 21 b 02 b 12 b 22 1 a 12 a 22 b 0 L b 1 L b 2 L 1 a 1 L a 2 L ]

represents the second-order section digital filter

H ( z ) = k = 1 L H k ( z ) = k = 1 L b 0 k + b 1 k z 1 + b 2 k z 2 1 + a 1 k z 1 + a 2 k z 2 .

Example:[b,a] = butter(3,1/32); sos = tf2sos(b,a)指定了一个三阶Butterworth filter with a normalized 3 dB frequency ofπ/32 rad/sample.

Data Types:single|double

Input signal, specified as a vector, matrix, orN-D array.

Example:x = [2 1].*sin(2*pi*(0:127)'./[16 64])specifies a two-channel sinusoid.

Data Types:single|double
Complex Number Support:Yes

维to operate along, specified as a positive integer scalar. By default, the function operates along the first array dimension ofxwith size greater than 1.

Data Types:single|double

Output Arguments

collapse all

Filtered signal, returned as a vector, matrix, orN-D array.yhas the same size asx.

References

[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.

[2] Orfanidis, Sophocles J.Introduction to Signal Processing. Englewood Cliffs, NJ: Prentice-Hall, 1996.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced before R2006a