# filtord

## Syntax

• n = filtord(b,a)
example
• n = filtord(sos)
example
• n = filtord(d)
example

## Description

example

n = filtord(b,a) returns the filter order, n, for the causal rational system function specified by the numerator coefficients, b, and denominator coefficients, a.

example

n = filtord(sos) returns the filter order for the filter specified by the second-order sections matrix, sos. sos is a K-by-6 matrix. The number of sections, K, must be greater than or equal to 2. Each row of sos corresponds to the coefficients of a second-order filter. The ith row of the second-order section matrix corresponds to [bi(1) bi(2) bi(3) ai(1) ai(2) ai(3)].

example

n = filtord(d) returns the filter order, n, for the digital filter, d. Use the function designfilt to generate d.

## Examples

collapse all

### Verify Order of FIR Filter

Design a 20th-order FIR filter with normalized cutoff frequency rad/sample using the window method. Verify the filter order.

b = fir1(20,0.5); n = filtord(b) 
n = 20 

Design the same filter using designfilt and verify its order.

di = designfilt('lowpassfir','FilterOrder',20,'CutoffFrequency',0.5); ni = filtord(di) 
ni = 20 

### Determine the Order Difference Between FIR and IIR Designs

Design FIR equiripple and IIR Butterworth filters from the same set of specifications. Determine the difference in filter order between the two designs.

fir = designfilt('lowpassfir','DesignMethod','equiripple','SampleRate',1e3, ... 'PassbandFrequency',100,'StopbandFrequency',120, ... 'PassbandRipple',0.5,'StopbandAttenuation',60); iir = designfilt('lowpassiir','DesignMethod','butter','SampleRate',1e3, ... 'PassbandFrequency',100,'StopbandFrequency',120, ... 'PassbandRipple',0.5,'StopbandAttenuation',60); FIR = filtord(fir) IIR = filtord(iir) 
FIR = 114 IIR = 41 

## Input Arguments

collapse all

### b — Numerator coefficientsvector | scalar

Numerator coefficients, specified as a scalar or a vector. If the filter is an allpole filter, b is a scalar. Otherwise, b is a row or column vector.

Example: b = fir1(20,0.25)

Data Types: single | double
Complex Number Support: Yes

### a — Denominator coefficientsvector | scalar

Denominator coefficients, specified as a scalar or a vector. If the filter is an FIR filter, a is a scalar. Otherwise, a is a row or column vector.

Example: [b,a] = butter(20,0.25)

Data Types: single | double
Complex Number Support: Yes

### sos — Matrix of second-order sectionsmatrix

Matrix of second order-sections, specified as a K-by-6 matrix. The system function of the Kth biquad filter has the rational Z-transform

${H}_{k}\left(z\right)=\frac{{B}_{k}\left(1\right)+{B}_{k}\left(2\right){z}^{-1}+{B}_{k}\left(3\right){z}^{-2}}{{A}_{k}\left(1\right)+{A}_{k}\left(2\right){z}^{-1}+{A}_{k}\left(3\right){z}^{-2}}.$

The coefficients in the Kth row of the matrix, sos, are ordered as follows.

$\left[\begin{array}{cccccc}{B}_{k}\left(1\right)& {B}_{k}\left(2\right)& {B}_{k}\left(3\right)\text{ }& {A}_{k}\left(1\right)& {A}_{k}\left(2\right)& {A}_{k}\left(3\right)\end{array}\right].$

The frequency response of the filter is the system function evaluated on the unit circle with

$z={e}^{j2\pi f}.$

Data Types: single | double
Complex Number Support: Yes

### d — Digital filterdigitalFilter object

Digital filter, specified as a digitalFilter object. Use designfilt to generate a digital filter based on frequency-response specifications.

Example: d = designfilt('lowpassiir','FilterOrder',3,'HalfPowerFrequency',0.5) specifies a third-order Butterworth filter with normalized 3-dB frequency 0.5π rad/sample.

## Output Arguments

collapse all

### n — Filter orderinteger

Filter order, specified as an integer.