firpm
Designing an optimal FIR filter by the Parks-McClellan method.
| Library |
|
Syntax
Function call
-
b, err, res = firpm(n, f, a)— returns a vector stringb, containingn+1coefficients of the FIR filter of the ordern, the maximum deviation of the amplitude characteristic from the desired oneerrand the frequency response in the form of a structureres. The frequency and amplitude characteristics of the resulting filter correspond to the vectorsfanda.
Arguments
Input arguments
# n — filter order
+
positive integer
Details
The filter order is set as a positive integer.
| Типы данных |
|
# f — normalized frequency values
+
vector | the matrix
Details
Normalized frequency values specified as a vector or matrix of dimension on 1. The values must be in the range [0, 1], where 1 corresponds to the Nyquist frequency. The number of elements of a vector is always a multiple 2. The frequencies should be arranged in ascending order.
| Типы данных |
|
# a is the desired amplitude response
+
vector | the matrix
Details
The desired amplitude at the appropriate points f, defined as a vector or matrix of dimension on 1. Dimensions a and f they must match. The dimension must be an even number.
-
On segments with an odd index the interpolation is linear.
-
On segments with an even index the behavior is undefined (transition zones).
| Типы данных |
|
# w — weight coefficients
+
vector | the matrix
# ftype — filter type
+
"hilbert" | "differentiator" | "multiband" | "lowpass" | "highpass" | "bandpass" | "bandstop" | "invsinc"
Details
Filter type for calculating linear-phase filters with odd symmetry (type III or IV):
-
"hilbert"— the Hilbert filter: ;An example of calculating an approximate FIR of a Hilbert transformer.
31:h = firpm(30,[0.1; 0.9],[1; 1],"hilbert") -
"differentiator"— a derivative filter with weights inversely proportional to the frequency; -
"multiband"— multiband filter; -
"lowpass"— low-pass filter (low-pass filter); -
"highpass"— high-pass filter (high-frequency filter); -
"bandpass"— bandpass filter; -
"bandstop"— notch (blocking) filter; -
"invsinc"— inverse sinc filter.
| Типы данных |
|
# lgrid — frequency grid density
+
16 (by default) | scalar
Details
The density of the frequency grid, which contains approximately (lgrid*n)/(2*bw) points where bw — this is a fraction of the total frequency range interval [0, 1], covered by f. Increase lgrid This often results in filters that more accurately match filters with a characteristic with a uniform ripple level, but require more time to calculate. Default value 16 — this is the minimum value that should be specified for lgrid.
| Типы данных |
|
# fresp — frequency response
+
function
Details
It is used to set the desired amplitude as a function, rather than as a set of values.
Function firpm causes fresp as follows:
dh, dw = fresp(n, f, gf, w)
Input arguments
-
n— filter order; -
f— vector of band boundaries, values from0before1(where1— this is the Nyquist frequency); -
gf— the frequency grid on which it is necessary to calculate the desired characteristic; -
w— a vector of weighting coefficients, one for each lane (if not specified, thenw = ones(…)).
Output arguments
-
dh— the desired frequency response calculated on the frequency gridgf; -
dw— a vector of weighting coefficients corresponding togf, usually repeatingwat the relevant sites.
Function example fresp:
function fresp(
n::Int,
f::AbstractArray{<:Real},
gf::AbstractArray{<:Real},
w::AbstractArray{<:Real}
)
dh = Float64.((gf .>= f[1]) .& (gf .<= f[2])) # The frequency response is equal to 1 in the band [f[1], f[2]]
dw = ones(length(gf)) .* w[1] # The weight is the same across the band
return dh, dw
end
Output arguments
#
err —
maximum deviation of the amplitude characteristic from the desired
one
real scalar
Details
The maximum deviation of the amplitude characteristic from the desired one, returned as a scalar.
# res — frequency response
+
structure
Details
The frequency response returned as a structure. Structure res it has the following fields:
-
res.fgrid— the frequency grid vector used to optimize the filter design; -
res.des— the desired frequency response for each pointres.fgrid; -
res.wt— weight coefficients at each pointres.fgrid; -
res.H— the obtained frequency response for each pointres.fgrid; -
res.error— error for each pointres.fgrid(res.des-res.H); -
res.iextr— the vector of extreme frequency indices inres.fgrid; -
res.fextr— vector of extreme frequencies.
Recommendations
If the filter does not converge, it is possible that it is designed incorrectly. Verify the correctness of the calculation by checking the frequency response.
If the filter does not converge and the result is incorrect, try one or more of the following actions:
-
Increase the filter order.
-
Soften the filter calculation by reducing the attenuation in the delay bands and/or extending the transition regions.
Algorithms
Function firpm designs a FIR filter with a linear phase characteristic using the Parks-McClellan algorithm [2]. The Parks-McClellan algorithm uses the Remez substitution algorithm and Chebyshev approximation theory to design filters with optimal matching between desired and actual frequency characteristics. Filters are optimal in the sense that the maximum error between the desired and actual frequency characteristics is minimized. Filters designed in this way exhibit a frequency response with a uniform ripple level. Function firpm It exhibits discontinuities at the beginning and end of its pulse response due to a single level of pulsation.
These are filters with linear phase characteristics of type I (n odd) and type II (n even). Vectors f and a the frequency-amplitude characteristics of the filter are set:
-
fis a vector of pairs of frequency points set in the range from0before1, where1corresponds to the Nyquist frequency. The frequencies should be arranged in ascending order. -
a— a vector containing the desired amplitude at the points indicated inf.The desired amplitude function at frequencies between pairs of points for odd numbers — this is a straight line segment connecting the points and .
The desired amplitude function at frequencies between pairs of points with an even number not defined. These are transitional or irrelevant areas.
-
fandathey have the same length. This length must be an even number.
Function firpm always uses an even filter order for configurations with even symmetry and non-zero bandwidth at the Nyquist frequency. The reason for the even filter order is that for pulse characteristics with even symmetry and odd orders, the frequency response at the Nyquist frequency is necessarily equal to 0. If an odd value is specified n Then firpm increases it by 1.
Function firpm designs filters with linear phase characteristics of types I, II, III and IV. Types I and II are used by default for even and odd n accordingly, while types III (n even) and IV (n odd) are set using the argument ftype using "hilbert" or "differentiator" accordingly. Different types of filters have different symmetries and certain limitations on their frequency characteristics. (For more information, see [3]).
| Filter type with linear phase response | Filter order | Symmetry of coefficients | (Nyquist) | |
|---|---|---|---|---|
Type I |
Even-numbered |
Even numbers: |
There are no restrictions |
There are no restrictions |
Type II |
Odd |
Even numbers: |
There are no restrictions |
Function |
Type III |
Even-numbered |
Odd numbers: |
|
|
Type IV |
Odd |
Odd numbers: |
|
There are no restrictions |
Literature
-
Digital Signal Processing Committee of the IEEE Acoustics, Speech, and Signal Processing Society, eds. Selected Papers in Digital Signal Processing. Vol. II. New York: IEEE Press, 1976.
-
Digital Signal Processing Committee of the IEEE Acoustics, Speech, and Signal Processing Society, eds. Programs for Digital Signal Processing. New York: IEEE Press, 1979, algorithm 5.1.
-
Oppenheim, Alan V., Ronald W. Schafer, and John R. Buck. Discrete-Time Signal Processing. Upper Saddle River, NJ: Prentice Hall, 1999, p. 486.
-
Parks, Thomas W., and C. Sidney Burrus. Digital Filter Design. New York: John Wiley & Sons, 1987, p. 83.
-
Rabiner, Lawrence R., James H. McClellan, and Thomas W. Parks. «FIR Digital Filter Design Techniques Using Weighted Chebyshev Approximation.» Proceedings of the IEEE®. Vol. 63, Number 4, 1975, pp. 595–610.