## Documentation Center |

Parks-McClellan FIR filter

`b = firgr(n,f,a,w)b = firgr(n,f,a,'hilbert')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)`

`firgr` is a minimax filter design algorithm
you use 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

`b = firgr(n,f,a,w)` returns
a length

`b = firgr(n,f,a,'hilbert')` and

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

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

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

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

`'n'`— normal frequency point.`'s'`— single-point band. The frequency "band" is given by a single point. The corresponding gain at this frequency point must be specified in`a`.`'f'`— forced frequency point. Forces the gain at the specified frequency band to be the value specified.`'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 stop bands (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.

`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

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

`b = firgr(...,'minphase')` designs
a minimum-phase FIR filter. You can use the argument

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

`[b,err,res] = firgr(...)` returns
the structure

`firgr` is also a "function function,"
allowing you to write a function that defines the desired frequency
response.

`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

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

where:

`fresp`is the string variable that 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`.

`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

`b = firgr(n,f,a,w)` is
a synonym for

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

These examples demonstrate some filters you might design using `firgr`.

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'});

Use the filter visualization tool to view the results of the filters created in these examples.

fvtool(b1,1,b2,1,b3,1)

Here is the figure from FVTool.

Shpak, D.J. and A. Antoniou, "A generalized Remez method
for the design of FIR digital filters," *IEEE ^{®} Trans.
Circuits and Systems*, pp. 161-174, Feb. 1990.

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

Was this topic helpful?