Engee documentation

firgr

Designing a generalized FIR Remez filter.

Library

EngeeDSP

Syntax

Function call

  • b,err,res = firgr(n,f,a,w) — uses a minimax algorithm to design a real linear-phase FIR filter with a vector of coefficients b length n + 1. In the sense of the minimax criterion, the filter provides the best approximation to the desired frequency response, determined by the parameters f and a. Argument w — a vector of filter weights, one for each band. If not used w, all bands will be weighted equally. The function also returns the values of the unweighted approximation errors. err and the structure res, containing additional results calculated using firgr. For more information about the arguments, see firpm.

  • b,err,res = firgr(m,f,a,r) — re-designs filters until a filter of the minimum order specified in is found. m and corresponding to the arguments f and a. Argument m It can take one of the values: "minorder", "mineven" or "minodd". Argument r — this is a vector containing the peak ripple for each frequency band, it must be set. When specifying "mineven" or "minodd" the function finds the minimum even or odd order filter.

  • b,err,res = firgr((m,ni),f,a,r) — as an initial estimate of the filter order, the following is used ni. Argument ni It is not mandatory for standard filter designs, but it must be specified for designs in which it is impossible to use firpmord for example, when designing differentiators or Hilbert converters.

  • b,err,res = firgr(n,f,a,w,e) — sets independent approximation errors for different bands. Use this syntax to design filters with additional ripple or maximum ripple. These filters have interesting properties, such as the minimum width of the transition. Argument e — this is a string vector specifying the approximation errors that should be used. Its length should be equal to the number of stripes.

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

  • b,err,res = firgr(n,f,a,s,w,e) — sets the filter weights and independent approximation errors for filters with special properties. The weights and properties are contained in the vectors w and e. Sometimes it may be necessary to use independent approximation errors to ensure that the design converges with the specified values. For example,

    b,err,res = 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,err,res = firgr(_,type) — designs a filter, the type of which is specified in the argument type. Argument type set as "1" — symmetric even-order filter, "2" — symmetric odd-order filter, "3" — antisymmetric filter of even order or "4" — antisymmetric filter of odd order. Note that for FIR filters of the following types: "2", "3" and "4" there are limitations on the amplitude values a. For type filters "2" and "3" the amplitude should be equal to 0 on the frequencies f = 0 and f = 1, and for a filter like "4" the amplitude should be equal to 0 on the frequency f = 0.

  • b,err,res = firgr(_,mp) — designs a FIR filter with a minimum or maximum phase, depending on the value of the argument mp.

  • b,err,res = firgr(_,"check") — returns a warning when a transition zone anomaly is detected.

  • b,err,res = firgr(_,(lgrid,)) — sets the density of the frequency grid (lgrid,) in the form of the number of samples used along the frequency axis.

  • b,err,res = firgr(_,hd) — designs a filter, the parity of which is determined by the argument hd.

Arguments

Input arguments

# n — filter order

+ scalar

Details

The filter order, specified as an integer, is at least 3.

Типы данных

Int64

# f — normalized frequencies

+ vector

Details

Normalized frequency points, defined as a vector of real values. The value of the argument must be in the range [0, 1], where 1 corresponds to the Nyquist frequency. Vector length f it must be even. The frequencies should be ordered in ascending order.

Типы данных

Float64

# a — desired amplitudes at specified frequency points

+ vector

Details

The desired amplitudes at the points indicated in f, set as a vector. Vectors f and a they must have the same length. Length a it must be even.

Типы данных

Float64

# w — approximation coefficients within the frequency bands

+ vector

Details

The weighting coefficients used to adjust the approximation in each frequency band, given as a vector of real values. Length w It is half the length f and a therefore, there is exactly one weight for each strip.

Типы данных

Float64

# ftype — filter type

+ "hilbert" | "differentiator"

Details

The filter type for linear-phase filters with odd symmetry (type III and type IV), set by one of the following values:

  • "hilbert" — coefficients at the output in b they obey the ratio . This class of filters includes the Hilbert converter, which has a specified amplitude equal to 1, in the entire frequency band.

    For example,

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

    designs an approximate Hilbert FIR converter of length 31.

  • "differentiator" — for bands with non-zero amplitude, the filter weighs the error by a factor of , so the error at low frequencies is significantly less than at high frequencies. For FIR differentiators, the amplitude characteristic of which is proportional to the frequency, these filters minimize the maximum relative error (the maximum value of the ratio of the error to the desired amplitude).

Типы данных

String

# m is the type of setting the minimum filter order

+ "minorder" | "mineven" | "minodd"

Details

The type of setting the minimum filter order, set as "minorder", "mineven" or "minodd". When specifying "mineven" or "minodd" The function designs a minimum even or minimum odd order filter.

Типы данных

String

# type — the number of the filter type

+ "1" | "2" | "3" | "4"

Details

The filter type specified by one of the following values:

  • "1" — symmetric even-order filter;

  • "2" — symmetric odd-order filter;

  • "3" — antisymmetric filter of even order;

  • "4" — antisymmetric filter of odd order.

Типы данных

String, Char

# mp — choose between minimum or maximum phase filter

+ "minphase" | "maxphase"

Details

Choosing between a filter with a minimum "minphase" or the maximum "maxphase" the phase.

Типы данных

String

# r — peak ripples within the frequency bands

+ vector

Details

Peak ripples within the frequency bands, defined as a vector of real values. Length r It is half the length f and a Therefore, there is one peak ripple value per band.

Типы данных

Float64

# ni is the initial estimate of the filter order

+ scalar

Details

The initial estimate of the filter order, set as an integer greater than or equal to 3. The function takes this value in the syntax b = firgr((m,ni),f,a,r). Argument ni It is not mandatory for typical filter designs, but it must be specified for designs in which it is impossible to use firpmord for example, when designing differentiators or Hilbert converters.

Типы данных

Int64

# e — independent approximation errors for frequency bands

+ vector | the tuple

Details

Independent approximation errors used for different bands, specified as a string vector or tuple. Length e it must be equal to the number of lanes. Elements e must have the form "e#", where # specifies which approximation error should be used 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 lane is the other one "e2". When all bands use the same approximation error, for example ["e1","e1","e1",…​], this is equivalent to skipping e as in the syntax b,err,res = firgr(n,f,a,w).

Типы данных

String

# s — specification of frequency points

+ vector | the tuple

Details

Special properties at certain points of the frequency, specified as a vector or tuple of symbols. Argument s must have the same length as f and a. Elements s must have one of the following values:

  • 'n' — the usual frequency point.

  • 's' — single-point strip. Frequency «stripe» It is defined by a single point. Specify the appropriate gain at this frequency point in a.

  • 'f' — forced frequency point. Forcibly sets the gain in the specified frequency band to the set value.

  • 'i' — an undefined frequency point. Use this value when adjacent frequency bands are adjacent to each other (without a transition zone).

For example, the following team designs a barrier filter with single-point delay bands (recesses) with a zero value at frequencies 0.25 and 0.55.

b,err,res = 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'])

And this team is designing a high-pass filter with a gain factor that is forcibly set to zero at the point 0.06. The edge of the strip at the point 0.055 it is indeterminate because the first two lanes actually touch. The remaining edges of the stripes are normal.

b,err,res = firgr(82,[0 0.055 0.06 0.1 0.15 1],[0 0 0 0 1 1],['n' 'i' 'f' 'n' 'n' 'n'])
Типы данных

String, Char

# lgrid — frequency grid density

+ the tuple

Details

Controls the density of the frequency grid, which has approximately (lgrid*n)/(2*bw) frequency points where bw — the share of the total frequency band interval [0, 1], covered by f. The higher the value is lgrid the more precisely the filter approaches the reference filter with uniform pulsations, but such calculations take longer. Default value 16 — this is the minimum value that should be set for lgrid.

Типы данных

Int64

# hd — filter parity

+ "h" | "d" | 'h' | 'd'

Details

The parity of the filter, set as "h", "d", 'h' or 'd'.

Типы данных

String, Char

Output arguments

# b — filter coefficients

+ vector

Details

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

Function firgr uses a minimax design algorithm for the following types of real FIR filters:

  • Types 1-4 with linear phase:

    • Type 1 — even order, symmetric;

    • Type 2 — odd order, symmetrical;

    • Type 3 — even order, antisymmetric;

    • Type 4 is of odd order, antisymmetric.

  • The minimum phase.

  • The maximum phase.

  • Minimum order (even or odd).

  • Additional ripple.

  • Maximum ripple.

  • Ripple with limitations.

  • Single-point strip (with notch and peak).

  • Forced reinforcement.

# err is the value of the unweighted approximation error

+ scalar | vector

Details

The values of the unweighted approximation errors returned as a scalar or vector. Array err contains one element for each independent approximation error returned by the function.

# res — frequency response

+ structure

Details

The frequency response returned as a structure. Structure res contains the following fields:

Structure Field Content

res.fgrid

A vector containing the frequency grid used to optimize the filter design.

res.des

The desired response to fgrid.

res.wt

Weight factors fgrid.

res.H

The actual frequency characteristics on the frequency grid.

res.error

Error at each point (desired characteristic — actual characteristic) on the frequency grid.

res.iextr

The index vector in fgrid external frequencies.

res.fextr

The vector of external frequencies.

res.order

The filter order.

res.edge_check

Checking for anomalies in the transition zone. One element for each edge of the strip. The elements have the following values: 1 — no anomalies, 0 — probable anomaly in the transition zone, −1 — the edge is not checked. Calculated for syntax b,err,res=firgr(_,"check").

res.iterations

Number of iterations s for optimization purposes.

res.evals

The number of calculations of the function for optimization.