Engee documentation

butter

The design of the Butterworth filter.

Library

EngeeDSP

Syntax

Function call

  • b,a = butter(n,Wn) — designs a digital Butterworth low-pass filter n-th order with a normalized cutoff frequency Wn. Function butter coefficients of the numerator and denominator of the filter transfer function.

  • b,a = butter(n,Wn,ftype) — designs a digital Butterworth filter: low-pass filter, high-pass filter, bandpass filter or notch filter, depending on the value of the argument ftype and the number of elements Wn. The resulting designs of the bandpass and notch filters are of the following order 2n.

    When designing IIR filters with a gear ratio up to `4`Numerical instability can be encountered. For more information about numerical problems affecting the formation of the transfer function, see Transfer functions and CTFs.
  • z,p,k = butter(___,out=3) — designs a digital Butterworth filter and returns its zeros, poles, and gain. This syntax can include any input arguments from the previous options. Argument out shows how many output arguments the function will return. If the argument is out omitted, the function will calculate only for the two output arguments.

  • A,B,C,D = butter(___,out=4) — designs a digital Butterworth filter and returns matrices that define its representation in the state space.

  • ___ = butter(___,"s") — designs an analog Butterworth filter using any of the input or output arguments in the previous syntaxes.

  • B,A = butter(n,Wn,"ctf") — designs a digital Butterworth low-pass filter using cascaded transfer functions of the second order (Cascaded Transfer Functions, CTF). The function returns matrices containing the polynomial coefficients of the denominator and numerator of the filter transfer function, represented as a cascade of filter sections. This approach makes it possible to create IIR filters with improved numerical stability compared to single-section transfer functions.

  • ___ = butter(n,Wn,ftype,"ctf") — Designs a digital Butterworth low-pass, high-pass, bandpass, or notch filter and returns a CTF representation of the filter. The resulting sections of the structure have the following order 2 (low- and high-pass filters) or 4 (bandpass and notch filters).

  • ___,gS = butter(___) — returns the total gain of the system. For a refund gS you must specify "ctf".

Arguments

Input arguments

# n — filter order

+ an integer scalar

Details

The filter order, specified as an integer scalar, is less than or equal to 500. For bandpass and notch filters, the argument n represents half of the filter order.

Data types

Float64

# Wn is the cutoff frequency

+ scalar | two-element vector

Details

The cutoff frequency, specified as a scalar or a two-element vector. The cutoff frequency is the frequency at which the amplitude-frequency response of the filter is .

  • If Wn is a scalar, then the function butter designs a low-pass or high-pass filter with a cutoff frequency Wn.

    If Wn — two-element vector [w1,w2], where w1 < w2, then the function butter designs a bandpass or notch filter with a lower cutoff frequency w1 and and the upper cutoff frequency w2.

  • For digital filters, the cutoff frequencies should be in the range of 0 before 1, where 1 corresponds to the Nyquist frequency — half of the sampling frequency or rad/countdown.

    For analog filters, the cutoff frequencies must be expressed in radians per second and can take any positive value.

Data types

Float64

# ftype — filter type

+ "low" | "bandpass" | "high" | "stop"

Details

The type of filter set using one of the following methods:

  • "low" defines a low-pass filter with a cutoff frequency Wn. Meaning "low" is the default value for a scalar Wn.

  • "high" defines a high-pass filter with a cutoff frequency Wn.

  • "bandpass" defines a bandpass filter of the order 2n if Wn — a two-element vector. Meaning "bandpass" it is the default value if Wn It consists of two elements.

  • "stop" defines the notch filter of the order 2n if Wn — a two-element vector.

Name-value input arguments

# out — number of output arguments

+ a positive integer scalar

Details

The number of output arguments specified as a positive integer. If the argument is out not specified, the function returns two output arguments by default.

Output arguments

# b,a are the coefficients of the transfer function

+ string vectors

Details

Coefficients of the filter transfer function returned as row vectors. With the specified filter order n the function returns b and a with r by counting where r = n + 1 for low and high pass filters and r = 2 * n + 1 for band-pass and notch filters.

The transfer function is expressed in terms of and as follows:

  • for digital filters;

  • for analog filters.

Data types

Float64

# z,p,k — zeros, poles, and gain

+ column vectors, scalar

Details

Zeros, poles, and filter gain, returned as two vectors-columns and a scalar. With the specified filter order n the function returns z and p with r by counting where r = n for low and high pass filters and r = 2 * n for band-pass and notch filters.

The transfer function is expressed in terms of , and as follows:

  • for digital filters;

  • for analog filters.

Data types

Float64

# A,B,C,D — representation in the state space

+ matrices

Details

The representation of the filter in the state space, returned as matrices. If r = n for low and high pass filters and r = 2n for band-pass and notch filters, then A equally , B equally , C equally , and D equally .

Matrices in the state space relate the state vector , the input signal and the output signal by using one of the following systems of equations.

  • For digital filters:

  • For analog filters:

Data types

Float64

# B,A are the coefficients of the cascade transfer function

+ vector string | the matrix

Details

Coefficients of the Cascaded transfer Function (CTF), returned as a row vector or matrix. B and A — the coefficients of the numerator and denominator of the cascade transfer function, respectively.

Sizes B and A: on and on accordingly. The function returns the first column of the matrix A how 1, thus, A(1)=1 when A — vector is a string.

  • L — the number of filter sections.

  • m — the order of the numerators of the filter.

  • n — the order of the denominators of the filter.

Function butter returns the coefficients of the cascade transfer function with the following order parameters:

  • for low- and high-pass filters;

  • for band-pass and notch filters.

To set up the calculation of the cascade transfer function coefficient, for example, to set a different order in the coefficients of the cascade transfer function or to adjust the gain scaling, specify the return z,p,k and then use the function zp2ctf to get B,A.

For more information about the cascade transfer function format and coefficient matrices, see Return of digital filters in CTF format.

# gS is the total gain of the system

+ the real scalar

Details

The total gain of the system, returned as a real scalar.

  • If specified, you need to return gS, function butter normalizes the coefficients of the numerator so that the first column B was equal to 1, and returns the total gain of the system in gS.

  • If not specified, what needs to be returned gS, function butter distributes the system gain evenly across all sections of the system using the function scaleFilterSections.

Additional Info

Cascading transfer functions

Details

Splitting a digital IIR filter into cascaded sections increases its numerical stability and reduces its susceptibility to coefficient quantization errors. Cascade form of the transfer function in terms of transfer functions it has the form

butter en

Return of digital filters in CTF format

Details

Specify the arguments B and A to return the filter coefficients. You can also specify gS to return the overall gain of the system. By specifying these output arguments, you can design digital filters in CTF format for signal analysis, visualization, and filtering.

coeffects of the filter

If you specify the return of the numerator and denominator coefficients in CTF format, -lowercase matrices and they are returned as

thus, the total transfer function of the filter is



where — the order of the filter numerator, and — the order of the denominator.

The following functions can be used to visualize and analyze filters in CTF format. Characteristics in the time domain — impzlength and impz. Characteristics in the frequency domain — freqz, grpdelay, phasedelay and phasez. Filter Research — islinphase, ismaxphase and isstable.

coeffects and amplification

You can specify that you want to return the coefficients and the total gain of the system using a triplet of output arguments. B,A,gS. In this case, the coefficients of the numerator are normalized, returning the matrices of the filter coefficients and the gain factor in the form

so the transfer function has the form



This transfer function is equivalent to the function defined in section Filter coefficients, where and by and .

Transfer functions and CTFs

Details

The numerical instability of the syntax of transfer functions

In general, cascading transfer functions (syntaxes) should be used to design digital IIR filters. "ctf"). When designing a filter using transfer functions (any of the syntaxes b,a), numerical instabilities may occur. These instabilities are caused by rounding errors and can even occur in orders of magnitude n up to 4.

Algorithms

Butterworth filters have the most flat amplitude-frequency response (frequency response) in the passband and are monotonic in general. This smoothness is achieved by reducing the steepness of the drop. Elliptical filters and Chebyshev filters usually provide a steeper drop for a given filter order.

Function butter uses a five-step algorithm:

  1. It finds the poles, zeros, and gain of a prototype analog low-pass filter.

  2. It converts poles, zeros, and gain into a state space form.

  3. If necessary, it uses a state space transformation to convert a low-pass filter into a band-pass, high-pass, or notch filter with the required frequency limits.

  4. A bilinear function is used to design digital filters. to convert an analog filter to a digital one by means of a bilinear conversion with a preliminary frequency distortion. Fine frequency tuning allows analog and digital filters to have the same frequency response amplitude Wn or w1 and w2.

  5. If necessary, it transforms the state space filter back into its transfer function or gain zero pole form.

Literature

  1. Lyons, Richard G. Understanding Digital Signal Processing. Upper Saddle River, NJ: Prentice Hall, 2004.