Parks-McClellan FIR filter - MATLAB firgr - MathWorks 中国 (2024)

Parks-McClellan FIR filter

collapse all in page

Syntax

b = firgr(n,f,a,w)

b = firgr(n,f,a,ftype)

b = firgr(m,f,a,r),

b = firgr({m,ni},f,a,r)

b = firgr(n,f,a,w,e)

b = firgr(n,f,a,s)

b = firgr(n,f,a,s,w,e)

b = firgr(___,'1')

b = firgr(___,'minphase')

b = firgr(___,'check')

b = firgr(___,{lgrid}),

[b,err] = firgr(___)

[b,err,res] = firgr(___)

b = firgr(n,f,fresp,w)

b = firgr(n,f,{fresp,p1,p2,...},w)

b = firgr(n,f,a,w)

b = firgr(___,'h')

Description

example

b = firgr(n,f,a,w) uses a minimax filter design algorithm to design a real linear phase FIR filter b of length n+1. The filter has the best approximation to the desired frequency response described by f and a in the minimax sense. w is a vector of weights, one per band. When you omit w, all bands are weighted equally. For more information on the input arguments, see firpm.

b = firgr(n,f,a,ftype) design a filter of type specified by ftype

b = firgr(m,f,a,r), designs filters repeatedly until the minimum order filter as specified in m and that meets the specifications f,a is found. m can be one of 'minorder', 'mineven' or 'minodd'. r is a vector containing the peak ripple per frequency band. You must specify r. When you specify 'mineven' or 'minodd', the minimum even or odd order filter is found.

b = firgr({m,ni},f,a,r) where m is one of 'minorder', 'mineven' or 'minodd', uses ni as the initial estimate of the filter order. ni is optional for common filter designs, but it must be specified for designs in which firpmord cannot be used, such as while designing differentiators or Hilbert transformers.

b = firgr(n,f,a,w,e) specifies independent approximation errors for different bands. Use this syntax to design extra ripple or maximal ripple filters. These filters have interesting properties such as having the minimum transition width. e is a cell array of character vectors specifying the approximation errors to use. Its length must equal the number of bands.

b = firgr(n,f,a,s) is used to design filters with special properties s at certain frequency points.

b = firgr(n,f,a,s,w,e) specifies weights and independent approximation errors for filters with special properties. The weights and properties are included in vectors w and e. Sometimes, you may need to use independent approximation errors to get designs with forced values to converge. For example,

b = firgr(82,[0 0.055 0.06 0.1 0.15 1], [0 0 0 0 1 1],... {'n' 'i' 'f' 'n' 'n' 'n'}, [10 1 1] ,{'e1' 'e2' 'e3'});

b = firgr(___,'1') designs a type 1 filter (even-order symmetric). You can specify type 2 (odd-order symmetric), type 3 (even-order antisymmetric), and type 4 (odd-order antisymmetric) filters as well. Note that restrictions apply to a at f = 0 or f = 1 for FIR filter types 2, 3, and 4.

b = firgr(___,'minphase') designs a minimum-phase FIR filter. You can use the argument 'maxphase' to design a maximum phase FIR filter.

b = firgr(___,'check') returns a warning when there are potential transition-region anomalies.

b = firgr(___,{lgrid}), where {lgrid} is a scalar cell array. The value of the scalar controls the density of the frequency grid by setting the number of samples used along the frequency axis.

[b,err] = firgr(___) returns the unweighted approximation error magnitudes. err contains one element for each independent approximation error returned by the function.

[b,err,res] = firgr(___) returns the structure res comprising optional results computed by firgr.

b = firgr(n,f,fresp,w) returns a length n + 1 FIR filter which has the best approximation to the desired frequency response as returned by the user-defined function fresp.

firgr includes a predefined frequency response function named 'firpmfrf2'. You can write your own based on the simpler 'firpmfrf'. See the help for private/firpmfrf for more information.

b = firgr(n,f,{fresp,p1,p2,...},w) specifies optional arguments p1, p2,…, pn to be passed to the response function fresp.

b = firgr(n,f,a,w) isa synonym for b = firgr(n,f,{'firpmfrf2',a},w),where a is a vector containing your specified responseamplitudes at each band edge in f. By default, firgr designssymmetric (even) FIR filters. 'firpmfrf2' is thepredefined frequency response function. If you do not specify yourown frequency response function (the fresp variable), firgr uses'firpmfrf2'.

b = firgr(___,'h') and b = firgr(__,'d') design antisymmetric (odd) filters. When you omit the 'h' or 'd' arguments from the firgr command syntax, each frequency response function fresp can tell firgr to design either an even or odd filter. Use the command syntax sym = fresp('defaults',{n,f,[],w,p1,p2,...}).

firgr expects fresp to return sym = 'even' or sym = 'odd'. If fresp does not support this call, firgr assumes even symmetry.

For more information about the input arguments to firgr, refer to firpm.

Examples

collapse all

Design a Filter Using firgr

Open Live Script

Design an FIR filter with two single-band notches at 0.25 and 0.55.

b1 = firgr(42,[0 0.2 0.25 0.3 0.5 0.55 0.6 1],[1 1 0 1 1 0 1 1],... {'n' 'n' 's' 'n' 'n' 's' 'n' 'n'});

Design a highpass filter whose gain at 0.06 is forced to be zero. The gain at 0.055 is indeterminate since it should abut the band.

b2 = firgr(82,[0 0.055 0.06 0.1 0.15 1],[0 0 0 0 1 1],...{'n' 'i' 'f' 'n' 'n' 'n'});

Design a second highpass filter with forced values and independent approximation errors.

b3 = firgr(82,[0 0.055 0.06 0.1 0.15 1], [0 0 0 0 1 1], ...{'n' 'i' 'f' 'n' 'n' 'n'}, [10 1 1] ,{'e1' 'e2' 'e3'});

View the frequency response of the filters.

filterAnalyzer(b1,1,b2,1,b3,1,FilterNames=["Filter_b1","Filter_b2","Filter_b3"]);

Parks-McClellan FIR filter - MATLAB firgr- MathWorks 中国 (1)

Input Arguments

collapse all

nFilter order
integer greater than or equal to 3

Filter order, specified as an integer greater than or equal to 3.

fNormalized frequency points
real-valued vector

Normalized frequency points, specified as a real-valued vector. The argument must be in the range [0, 1] , where 1 corresponds to the Nyquist frequency. The length of f must be even. The frequencies must be in increasing order.

aDesired amplitude
vector

Desired amplitudes at the points specified in f, specified as a vector. f and a must be of the same length. The length of a must be even.

wWeights
real-valued vector

Weights used to adjust the fit in each frequency band, specified as a real-valued vector. The length of w is half the length of f and a, so there is exactly one weight per band.

ftypeFilter type
'hilbert' | 'differentiator'

Filter type for linear-phase filters with odd symmetry (type III and type IV), specified as either 'hilbert' or 'differentiator':

  • 'hilbert' — The output coefficients in b obey the relation b(k) = –b(n + 2 – k), k = 1, ..., n + 1. This class of filters includes the Hilbert transformer, which has a desired amplitude of 1 across the entire band.

    For example,

    b = firgr(30,[0.1 0.9],[1 1],'hilbert');

    designs an approximate FIR Hilbert transformer of length 31.

  • 'differentiator' — For nonzero amplitude bands, the filter weighs the error by a factor of 1/f so that the error at low frequencies is much smaller than at high frequencies. For FIR differentiators, which have an amplitude characteristic proportional to frequency, these filters minimize the maximum relative error (the maximum of the ratio of the error to the desired amplitude).

mType of minimum order filter
'minorder' | 'mineven' | 'minodd'

Type of minimum order filter, specified as 'minorder', 'mineven', or 'minodd'. When you specify 'mineven' or 'minodd', the function designs a minimum even order or minimum odd order filter.

rPeak ripple per frequency band
real-valued vector

Peak ripple per frequency band, specified as a real-valued vector. The length of r is half the length of f and a, so there is exactly one weight per band.

niInitial estimate of filter order
integer greater than or equal to 3

Initial estimate of the filter order, specified as an integer greater than or equal to 3. The function accepts this value in the b = firgr({m,ni},f,a,r} syntax. ni is optional for common filter designs, but it must be specified for designs in which firpmord cannot be used, such as while designing differentiators or Hilbert transformers.

eApproximation errors
cell array of character vectors | array of strings

Independent approximation errors to use for different bands, specified as a cell array of character vectors or an array of strings. The length of e must equal the number of bands. Entries of e must be in the form 'e#' or "e#" where # indicates which approximation error to use for the corresponding band. For example, when e = ["e1","e2","e1"], the first and third bands use the same approximation error "e1" and the second band uses a different one "e2". When all bands use the same approximation error, such as ["e1","e1","e1",...], it is equivalent to omitting e, as in b = firgr(n,f,a,w).

Data Types: char | string

sSpecial properties at certain frequency points
cell array of character vectors | array of strings

Special properties at certain frequency points, specified as a cell array of character vectors or an array of strings. s must have the same length as f and a. Entries of s must be one of:

  • 'n' or "n" — Normal frequency point.

  • 's' or "s" — Single-point band. The frequency “band” is given by a single point. Specify the corresponding gain at this frequency point in a.

  • 'f' or "f" — Forced frequency point. Forces the gain at the specified frequency band to be the value specified.

  • 'i' or "i" — Indeterminate frequency point. Use this argument when adjacent bands abut one another (no transition region).

For example, the following command designs a bandstop filter with zero-valued single-point stopbands (notches) at 0.25 and 0.55.

b = firgr(42,[0 0.2 0.25 0.3 0.5 0.55 0.6 1],...[1 1 0 1 1 0 1 1],["n" "n" "s" "n" "n" "s" "n" "n"])

b = firgr(82,[0 0.055 0.06 0.1 0.15 1],[0 0 0 0 1 1],["n" "i" "f" "n" "n" "n"]) designs a highpass filter with the gain at 0.06 forced to be zero. The band edge at 0.055 is indeterminate since the first two bands actually touch. The other band edges are normal.

Data Types: char | string

lgridDensity of frequency grid
16 (default) | 1-by-1 cell array with integer value

Control the density of the frequency grid, which has roughly (lgrid*n)/(2*bw) frequency points, where bw is the fraction of the total frequency band interval [0,1] covered by f. Increasing lgrid often results in filters that more exactly match an equiripple filter, but that take longer to compute. The default value of 16 is the minimum value that should be specified for lgrid.

frespFrequency response
function handle

Frequency response, specified as a function handle. The function is called from within firgr with this syntax:

[dh,dw] = fresp(n,f,gf,w)

where:

  • fresp identifies the function that you use to define your desired filter frequency response.

  • n is the filter order.

  • f is the vector of frequency band edges which must appear monotonically between 0 and 1, where 1 is one-half of the sampling frequency. The frequency bands span f(k) to f(k+1) for k odd. The intervals f(k+1) to f(k+2) for k odd are “transition bands” or “don't care” regions during optimization.

  • gf is a vector of grid points that have been chosen over each specified frequency band by firgr, and determines the frequencies at which firgr evaluates the response function.

  • w is a vector of real, positive weights, one per band, for use during optimization. w is optional in the call to firgr. If you do not specify w, it is set to unity weighting before being passed to fresp.

  • dh and dw are the desired frequency response and optimization weight vectors, evaluated at each frequency in grid gf.

Output Arguments

collapse all

b — Filter coefficients
row vector

Filter coefficients, returned as a row vector of length n + 1.

The firgr uses the minimax filter design algorithm to design the following types of real FIR filters:

  • Types 1-4 linear phase:

    • Type 1 is even order, symmetric

    • Type 2 is odd order, symmetric

    • Type 3 is even order, antisymmetric

    • Type 4 is odd order, antisymmetric

  • Minimum phase

  • Maximum phase

  • Minimum order (even or odd)

  • Extra ripple

  • Maximal ripple

  • Constrained ripple

  • Single-point band (notching and peaking)

  • Forced gain

  • Arbitrary shape frequency response curve filters

err — Unweighted approximation error magnitude
scalar | vector

Unweighted approximation error magnitudes, returned as a scalar or a vector. err contains one element for each independent approximation error returned by the function.

res — Frequency response characteristics
structure

Frequency response characteristics, returned as a structure. The structure res has the following fields:

Structure Field

Contents

res.fgrid

Vector containing the frequency grid used in the filter design optimization

res.des

Desired response on fgrid

res.wt

Weights on fgrid

res.h

Actual frequency response on the frequency grid

res.error

Error at each point (desired response - actual response) on the frequency grid

res.iextr

Vector of indices into fgrid of external frequencies

res.fextr

Vector of external frequencies

res.order

Filter order

res.edgecheck

Transition-region anomaly check. One element per band edge. Element values have the following meanings: 1 = OK, 0 = probable transition-region anomaly, -1 = edge not checked. Computed when you specify the 'check' input option in the function syntax.

res.iterations

Number of s iterations for the optimization

res.evals

Number of function evaluations for the optimization

Extended Capabilities

Version History

Introduced in R2011a

expand all

See Also

butter | cheby1 | cheby2 | ellip | freqz | filter | firls | fircls | firpm

MATLAB 命令

您点击的链接对应于以下 MATLAB 命令:

 

请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。

Parks-McClellan FIR filter - MATLAB firgr- MathWorks 中国 (2)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

Europe

Asia Pacific

Contact your local office

Parks-McClellan FIR filter - MATLAB firgr
- MathWorks 中国 (2024)

FAQs

What is the Parks-McClellan algorithm for filter design? ›

The Parks–McClellan algorithm is utilized to design and implement efficient and optimal FIR filters. It uses an indirect method for finding the optimal filter coefficients. The y-axis is the frequency response H(ω) and the x-axis are the various radian frequencies, ωi.

What is the command for FIR filter in Matlab? ›

b = fir1( n , Wn , ftype ) designs a lowpass, highpass, bandpass, bandstop, or multiband filter, depending on the value of ftype and the number of elements of Wn . b = fir1(___, window ) designs the filter using the vector specified in window and any of the arguments from previous syntaxes.

What is the firpm function in Matlab? ›

firpm and firls use this scheme to represent any piecewise linear frequency-response function with any transition bands. firls and firpm design lowpass, highpass, bandpass, and bandstop filters; a bandpass example is. f = [0 0.3 0.4 0.7 0.8 1]; % Band edges in pairs a = [0 0 1 1 0 0]; % Bandpass filter amplitude.

How to calculate FIR filter coefficients? ›

The key theorem of FIR filter design is that the coefficients h(n) of the FIR filter are simply the quantized values of the impulse response of the frequency transfer function H(f). Conversely, the impulse response is the Fourier Transform of H(f).

What is the use of a FIR filter? ›

A common form of a FIR filter is called an adaptive filter. Adaptive filtering is used in cases where a speech signal must be extracted from a noisy environment. Assume a speech signal is buried in a very noisy environment with many periodic frequency components lying in the same bandwidth as the speech signal.

What is the Parks-McClellan algorithm in Python? ›

The Parks-McClellan algorithm generates filter coefficients by solving the optimum equiripple Chebyshev approximation to the ideal filter provided in the specification. The Parks-McClellan algorithm internally uses the Remez exchange technique so the corresponding function in the signal module is called signal.

What is the formula for filter in MATLAB? ›

y = filter( b , a , x , zi , dim ) acts along dimension dim . For example, if x is a matrix, then filter(b,a,x,zi,2) returns the filtered data for each row. [ y , zf ] = filter(___) also returns the final conditions zf of the filter delays, using any of the previous syntaxes.

How do you generate filter code in MATLAB? ›

Generating MATLAB Code

Select File > Generate MATLAB Code > Filter Design Function and specify the file name in the Generate MATLAB code dialog box. You cannot generate MATLAB code (File > Generate MATLAB Code > Filter Design Function) if your filter was designed or edited with the Pole-Zero Editor.

What is the Firls function in MATLAB? ›

The firls function designs type I, II, III, and IV linear-phase filters. Type I and II are the default filters when n is even and odd, respectively, while the 'hilbert' and 'differentiator' flags produce type III (n is even) and IV (n is odd) filters.

What are the disadvantages of FIR filter? ›

Some of the advantages of FIR filter are linear phase, both recursive and non recursive, stable and round off noise can be made smaller. Some of the disadvantages of FIR filters are large amount of processing is required and non integral delay may lead to problems.

What are the design techniques of a FIR filter? ›

The simplest design method for FIR filters is impulse response truncation (IRT), but unfortunately it has undesirable frequency-domain characteristics, owing to the Gibb's phenomenon. The second design method for a FIR filter that we shall cover in this Chapter is the windowing technique.

What is convolution of FIR filter in MATLAB? ›

Convolution and Filtering

For a finite impulse response (FIR) filter, the output y(k) of a filtering operation is the convolution of the input signal x(k) with the impulse response h(k): y ( k ) = ∑ l = − ∞ ∞ h ( l ) x ( k − l ) .

How do you test a FIR filter? ›

The go-to method of testing FIR filters is to apply a unit impulse response – a unity value followed by zeros, also known as the Dirac delta function (see Figure 1). As the unity value makes its way through the FIR delay line, it passes through every tap, leading to an output that equals the respective coefficient.

What is the Parks McClellan Remez exchange algorithm? ›

The Parks-McClellan algorithm, or Remez Exchange, uses an iterative technique based on an error criterion to design FIR filter coefficients. You can use the Parks-McClellan algorithm to design optimum, linear-phase, FIR filter coefficients.

What algorithm does filter use? ›

Filter algorithms are classified into univariate and multivariate algorithms.

What is the PT1 filter algorithm? ›

A PT1 filter is a transfer function that performs convex interpolation between a new value x_n and an old value (from one cycle before) x_a . The filter time parameter, a nonnegative value in the unit of seconds, has to be entered into the calculation.

What is the algorithm for adaptive median filter? ›

The adaptive median filter works in two levels denoted Level A and Level B as follows: Level A: A1= Zmed - Zmin A2= Zmed - Zmax If A1 > 0 AND A2 < 0, Go to level B Else increase the window size If window size <=Smax repeat level A Else output Zxy.

References

Top Articles
Latest Posts
Article information

Author: Amb. Frankie Simonis

Last Updated:

Views: 6177

Rating: 4.6 / 5 (76 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Amb. Frankie Simonis

Birthday: 1998-02-19

Address: 64841 Delmar Isle, North Wiley, OR 74073

Phone: +17844167847676

Job: Forward IT Agent

Hobby: LARPing, Kitesurfing, Sewing, Digital arts, Sand art, Gardening, Dance

Introduction: My name is Amb. Frankie Simonis, I am a hilarious, enchanting, energetic, cooperative, innocent, cute, joyous person who loves writing and wants to share my knowledge and understanding with you.