Signal Processing Toolbox Previous page   Next Page
firpm

Parks-McClellan optimal FIR filter design

Syntax

Description

firpm designs a linear-phase FIR filter using the Parks-McClellan algorithm [1]. The Parks-McClellan algorithm uses the firpm exchange algorithm and Chebyshev approximation theory to design filters with an optimal fit between the desired and actual frequency responses. The filters are optimal in the sense that the maximum error between the desired frequency response and the actual frequency response is minimized. Filters designed this way exhibit an equiripple behavior in their frequency responses and are sometimes called equiripple filters. firpm exhibits discontinuities at the head and tail of its impulse response due to this equiripple nature.

b = firpm(n,f,a) returns row vector b containing the n+1 coefficients of the order n FIR filter whose frequency-amplitude characteristics match those given by vectors f and a.

The output filter coefficients (taps) in b obey the symmetry relation:

Vectors f and a specify the frequency-magnitude characteristics of the filter:

The relationship between the f and a vectors in defining a desired frequency response is shown in the illustration below.



firpm always uses an even filter order for configurations with a passband at the Nyquist frequency. This is because for odd orders, the frequency response at the Nyquist frequency is necessarily 0. If you specify an odd-valued n, firpm increments it by 1.

b = firpm(n,f,a,w) uses the weights in vector w to weight the fit in each frequency band. The length of w is half the length of f and a, so there is exactly one weight per band.

b = firpm(n,f,a,'ftype') and

b = firpm(n,f,a,w,'ftype') specify a filter type, where 'ftype' is

b = firpm(...,{lgrid}) uses the integer lgrid to 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. Note that the {lgrid} argument must be a 1-by-1 cell array.

[b,err] = firpm(...) returns the maximum ripple height in err.

[b,err,res] = firpm(...) returns a structure res with the following fields.

res.fgrid
Frequency grid vector used for the filter design optimization
res.des
Desired frequency response for each point in res.fgrid
res.wt
Weighting for each point in opt.fgrid
res.H
Actual frequency response for each point in res.fgrid
res.error
Error at each point in res.fgrid (res.des-res.H)
res.iextr
Vector of indices into res.fgrid for extremal frequencies
res.fextr
Vector of extremal frequencies

You can also use firpm to write a function that defines the desired frequency response. The predefined frequency response function handle for firpm is @firpmfrf, which designs a linear-phase FIR filter.

b = firpm(n,f,@fresp,w) returns row vector b containing the n+1 coefficients of the order n FIR filter whose frequency-amplitude characteristics best approximate the response returned by function handle @fresp. The function is called from within firpm with the following syntax.

The arguments are similar to those for firpm:

b = firpm(n,f,@fresp,w,'ftype') designs antisymmetric (odd) filters, where 'ftype' is either 'd' for a differentiator or 'h' for a Hilbert transformer. If you do not specify an ftype, a call is made to fresp to determine the default symmetry property sym. This call is made using the syntax.

The arguments n, f, w, etc., may be used as necessary in determining an appropriate value for sym, which firpm expects to be either 'even' or 'odd'. If fresp does not support this calling syntax, firpm defaults to even symmetry.

Examples

Graph the desired and actual frequency responses of a 17th-order Parks-McClellan bandpass filter:

Algorithm

firpm is a MEX-file version of the original Fortran code from [1], altered to design arbitrarily long filters with arbitrarily many linear bands.

firpm designs type I, II, III, and IV linear-phase filters. Type I and type II are the defaults for n even and n odd, respectively, while type III (n even) and type IV (n odd) are obtained with the 'hilbert' and 'differentiator' flags. The different types of filters have different symmetries and certain constraints on their frequency responses (see [5] for more details).

Linear Phase Filter Type
Filter Order
Symmetry of Coefficients
Response H(f), f = 0
Response H(f), f = 1 (Nyquist)
Type I
Even
even:


No restriction
No restriction
Type II
Odd
No restriction
H(1) = 0
Type III
Even
odd:


H(0) = 0
H(1) = 0
Type IV
Odd
H(0) = 0
No restriction

Diagnostics

If you get the following warning message,

it is possible that the filter design may still be correct. Verify the design by checking its frequency response.

See Also

butter, cheby1, cheby2, cfirpm, ellip, fir1, fir2, fircls, fircls1, firls, firrcos, firgr, firpmord, function_handle, yulewalk

References

[1] Programs for Digital Signal Processing, IEEE Press, New York, 1979, Algorithm 5.1.

[2] Selected Papers in Digital Signal Processing, II, IEEE Press, New York, 1979.

[3] Parks, T.W., and C.S. Burrus, Digital Filter Design, John Wiley & Sons, New York:, 1987, p. 83.

[4] Rabiner, L.R., J.H. McClellan, and T.W. Parks, "FIR Digital Filter Design Techniques Using Weighted Chebyshev Approximations," Proc. IEEE 63 (1975).

[5] Oppenheim, A.V., and R.W. Schafer, Discrete-Time Signal Processing, Prentice-Hall, Englewood Cliffs, NJ, 1989, pp. 256-266.


Previous page  firls firpmord Next page

© 1994-2005 The MathWorks, Inc.