Main Content

Minimax FIR Filter Design

This example shows how to use some of the key features of the generalized Remez FIR filter design function. This function provides all the functionality included infirpmplus many additional features showcased here.

Weighted-Chebyshev Design

The following is an illustration of the weighted-Chebyshev design. This example shows the compatibility offirgrwithfirpm.

N = 22;% Filter orderF = [0 0.4 0.5 1];% Frequency vectorA = [1 1 0 0];% Magnitude vectorW = [1 5];% Weight vectorb = firgr(N,F,A,W); fvtool(b,1)

The following is a weighted-Chebyshev design where a type 4 filter (odd-order, asymmetric) has been explicitly specified.

N = 21;% Filter orderF = [0 0.4 0.5 1];% Frequency vectorA = [0 0 1 1];% Magnitude vectorW = [2 1];% Weight vectorb = firgr(N,F,A,W,'4'); fvtool(b,1)

"Least-Squares-Like" Design

The following illustrates a "least-squares-like" design. A user-supplied frequency-response function (taperedresp.m) is used to perform the error weighting.

N = 53;% Filter orderF = [0 0.3 0.33 0.77 0.8 1];% Frequency vectorfresp = {@taperedresp, [0 0 1 1 0 0]};% Frequency response functionW = [2 2 1];% Weight vectorb = firgr(N,F,fresp,W); fvtool(b,1)

Filter Designed for Specific Single-Point Bands

This is an illustration of a filter designed for specified single-point bands. The frequency points f = 0.25 and f = 0.55 are single-band points. These points have a gain that approaches zero.

The other band edges are normal.

N = 42;% Filter orderF = [0 0.2 0.25 0.3 0.5 0.55 0.6 1];% Frequency vectorA = [1 1 0 1 1 0 1 1];% Magnitude vectorS = {'n''n''s''n''n''s''n''n'}; b = firgr(N,F,A,S); fvtool(b,1)

Filter Designed for Specific In-Band Value

Here is an illustration of a filter designed for an exactly specified in-band value. The value is forced to be exactly the specified value of 0.0 at f = 0.06.

This could be used for 60 Hz rejection (with Fs = 2 kHz). The band edge at 0.055 is indeterminate since it should abut the next band.

N = 82;% Filter orderF = [0 0.055 0.06 0.1 0.15 1];% Frequency vectorA = [0 0 0 0 1 1];% Magnitude vectorS = {'n''i''f''n''n''n'}; b = firgr(N,F,A,S); zerophase(b,1)

Filter Design with Specific Multiple Independent Approximation Errors

Here is an example of designing a filter using multiple independent approximation errors. This technique is used to directly design extra-ripple and maximal ripple filters. One of the interesting properties that these filters have is a transition region width that is locally minimal. Further, these designs converge very quickly in general.

N = 12;% Filter orderF = [0 0.4 0.5 1];% Frequency vectorA = [1 1 0 0];% Magnitude vectorW = [1 1];% Weight vectorE = {'e1''e2'};% Approximation errorsb = firgr(N,F,A,W,E); fvtool(b,1)

Extra-Ripple Bandpass Filter

Here is an illustration of an extra-ripple bandpass filter having two independent approximation errors: one shared by the two passbands and the other for the stopband (in blue). For comparison, a standard weighted-Chebyshev design is also plotted (in green).

N = 28;% Filter orderF = [0 0.4 0.5 0.7 0.8 1];% Frequency vectorA = [1 1 0 0 1 1];% Magnitude vectorW = [1 1 2];% Weight vectorE = {'e1','e2','e1'};% Approximation errorsb1 = firgr(N,F,A,W,E); b2 = firgr(N,F,A,W); fvtool(b1,1,b2,1)

德signing an In-Band-Zero Filter Using Three Independent Errors

We'll now re-do our in-band-zero example using three independent errors.

Note:It is sometimes necessary to use independent approximation errors to get designs with forced in-band values to converge. This is because the approximating polynomial could otherwise be come very underdetermined. The former design is displayed in green.

N = 82;% Filter orderF = [0 0.055 0.06 0.1 0.15 1];% Frequency vectorA = [0 0 0 0 1 1];% Magnitude vectorS = {'n''i''f''n''n''n'}; W = [10 1 1];% Weight vectorE = {'e1''e2''e3'};% Approximation errorsb1 = firgr(N,F,A,S,W,E); b2 = firgr(N,F,A,S); fvtool(b1,1,b2,1)

Checking for Transition-Region Anomalies

With the'check'option, one is made aware of possible transition region anomalies in the filter that is being designed. Here is an example of a filter with an anomaly. The'check'option warns one of this anomaly: One also get a results vectorres.edgeCheck. Any zero-valued elements in this vector indicate the locations of probable anomalies. The "-1" entries are for edges that were not checked (there can't be an anomaly at f = 0 or f = 1).

N = 44;% Filter orderF = [0 0.3 0.4 0.6 0.8 1];% Frequency vectorA = [1 1 0 0 1 1];% Magnitude vectorb = firgr(N,F,A,'check');
Warning: Probable transition-region anomalies. Verify with freqz.
fvtool(b,1)

德termination of the Minimum Filter Order

Thefirpmalgorithm repeatedly designs filters until the first iteration wherein the specifications are met. The specifications are met when all of the required constraints are met. By specifying'minorder',firpmordis used to get an initial estimate. There is also'mineven'and'minodd'to get the minimum-order even-order or odd-order filter designs.

F = [0 0.4 0.5 1];% Frequency vectorA = [1 1 0 0];% Magnitude vectorR = [0.1 0.02];% Deviation (ripple) vectorb = firgr('minorder',F,A,R); zerophase(b,1)

Differentiators and Hilbert Transformers

While using the minimum-order feature, an initial estimate of the filter order can be made. If this is the case, thenfirpmordwill not be used. This is necessary for filters thatfirpmorddoes not support, such as differentiators and Hilbert transformers as well as user-supplied frequency-response functions.

N = {'mineven',18};% Minimum even-order, start order estimate at 18F = [0.1 0.9];% Frequency vectorA = [1 1];% Magnitude vectorR = 0.1;% Deviation (ripple)b = firgr(N,F,A,R,'hilbert'); freqz(b,1,'whole')

德sign of an Interpolation Filter

This section illustrates the use of an interpolation filter for upsampling band-limited signals by an integer factor. Typically one would useintfilt(r,l,alpha)from the Signal Processing Toolbox™ to do this. However,intfiltdoes not give one as much flexibility in the design as doesfirgr.

N = 30;% Filter orderF = [0 0.1 0.4 0.6 0.9 1];% Frequency vectorA = [4 4 0 0 0 0];% Magnitude vectorW = [1 100 100];% Weight vectorb = firgr(N,F,A,W); fvtool(b,1)

A Comparison Betweenfirpmandintfilt

Here is a comparison made between a filter designed usingfirpm(blue) and a 30-th order filter designed usingintfilt(green).

Notice that by using the weighting function infirpm, one can improve the minimum stopband attenuation by almost 20 dB.

b2 = intfilt(4, 4, 0.4); fvtool(b,1,b2,1)

Notice that the equiripple attenuation throughout the second stopband is larger than the minimum stopband attenuation of the filter designed withintfiltby about 6 dB. Notice also that the passband ripple, although larger than that of the filter designed withintfilt, is still very small.

德sign of a Minimum-Phase Lowpass Filter

Here is an illustration of a minimum-phase lowpass filter.

N = 42;% Filter orderF = [0 0.4 0.5 1];% Frequency vectorA = [1 1 0 0];% Magnitude vectorW = [1 10];% Weight-constraint vectorb = firgr(N,F,A,W, {64},'minphase');

The pole/zero plot shows that there are no roots outside of the unit circle.

zplane(b,1)