Signal Processing Toolbox | ![]() ![]() |
Compute the Parks-McClellan optimal FIR filter design
Syntax
b=
remez(n,f,a) b=
remez(n,f,a,w) b=
remez(n,f,a,'ftype
') b=
remez(n,f,a,w,'ftype
') b=
remez(...,{lgrid}) b=
remez(n,f,'fresp
',w) b=
remez(n,f,'fresp
',w,'ftype
') b=
remez(n,f,{'fresp
',p1,p2,...},w) b=
remez(n,f,{'fresp
',p1,p2,...},w,'ftype
') [b,delta]=
remez(...) [b,delta,opt]=
remez(...)
Description
remez
designs a linear-phase FIR filter using the Parks-McClellan algorithm [1]. The Parks-McClellan algorithm uses the Remez 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. remez
exhibits discontinuities at the head and tail of its impulse response due to this equiripple nature.
b
returns row vector =
remez(n,f,a)
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:
f
is a vector of pairs of normalized frequency points, specified in the range between 0 and 1, where 1 corresponds to the Nyquist frequency. The frequencies must be in increasing order.
a
is a vector containing the desired amplitudes at the points specified in f
.
The desired amplitude at frequencies between pairs of points (f(k), f(k+1)) for k even is unspecified. The areas between such points are transition or "don't care" regions.
The relationship between the f
and a
vectors in defining a desired frequency response is shown in the example below.
remez
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
, remez
increments it by 1.
remez(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
specify a filter type, where =
remez(n,f,a,w,'ftype
')
'
ftype
'
is
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.
designs an approximate FIR Hilbert transformer of length 31.
uses the integer b = remez(...,{
lgrid})
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
returns row vector =
remez(n,f,'fresp
',w)
b
containing the n+1
coefficients of the order n
FIR filter whose frequency-amplitude characteristics best approximate the response specified by function fresp
. The function is called from within remez
with the following syntax.
The arguments are similar to those for remez
:
n
is the filter order.
f
is the vector of normalized frequency band edges that appear monotonically between 0 and 1, where 1 is the Nyquist frequency.
gf
is a vector of grid points that have been linearly interpolated over each specified frequency band by remez
. gf
determines the frequency grid at which the response function must be evaluated, and contains the same data returned by cremez
in the fgrid
field of the opt
structure.
w
is a vector of real, positive weights, one per band, used during optimization. w
is optional in the call to remez
; if not specified, it is set to unity weighting before being passed to fresp
.
dh
and dw
are the desired complex frequency response and band weight vectors, respectively, evaluated at each frequency in grid gf
.
The predefined frequency response function fresp
that remez
calls is remezfrf
in the signal/private
directory.
b
allows you to specify additional parameters ( =
remez(n,f,{'fresp
',p1,p2,...},w)
p1
, p2
, etc.) to pass to fresp
. Note that b =
remez(n,f,a,w) is a synonym for b =
remez(n,f,{'remezfrf
',a},w), where a
is a vector containing the desired amplitudes at the points specified in f
.
b
and =
remez(n,f,'fresp
',w,'ftype
')
b
design antisymmetric (odd) rather than symmetric (even) filters, where =
remez(n,f,{'fresp
',p1,p2,...},w,'ftype
')
'
ftype
'
is either 'd'
for a differentiator or 'h'
for a Hilbert transformer.
In the absence of a specification for ftype
, a preliminary 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 remez
expects to be either 'even'
or 'odd'
. If the fresp
function does not support this calling syntax, remez
defaults to even symmetry.
[b,delta]
returns the maximum ripple height in delta. =
remez(...)
returns a structure with the following fields. [b,delta,opt] = remez(...)
Examples
Graph the desired and actual frequency responses of a 17th-order Parks-McClellan bandpass filter:
f=
[0 0.3 0.4 0.6 0.7 1]; a=
[0 0 1 1 0 0]; b=
remez(17,f,a); [h,w]=
freqz(b,1,512); plot(f,a,w/pi,abs(h)) legend('Ideal','remez Design')
Algorithm
remez
is a MEX-file version of the original Fortran code from [1], altered to design arbitrarily long filters with arbitrarily many linear bands.
remez
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).
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
, cremez
, ellip
, fir1
, fir2
, fircls
, fircls1
, firls
, firrcos
, gremez
, remezord
, 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.
![]() | rectwin | remezord | ![]() |