Engee documentation

fir2

Page in progress.

Calculation of FIR filter coefficients based on frequency sampling.

Library

EngeeDSP

Syntax

Function call

  • b = fir2(n,f,m) — returns the FIR filter n-th order with frequency-amplitude characteristics given by vectors f and m. The function linearly interpolates the desired frequency response onto a dense grid, and then uses the inverse Fourier transform and the Hamming window to obtain the filter coefficients.

  • b = fir2(n,f,m,npt,lap) — defines npt — the number of points in the interpolation grid, and lap — the length of the area that the function fir2 inserts around repeating frequency points that specify steps in the frequency response.

  • b = fir2(___,window) — specifies the window vector to be used in the design in addition to any input arguments from the previous syntaxes.

Use the function fir1 for standard window low-pass filter, bandpass filter, high-pass filter, notch filter and multiband filter.

Arguments

Input arguments

# n — filter order

+ integer scalar

Details

The filter order is set as a positive integer.

For configurations with Nyquist frequency bandwidth, the function fir2 always uses an even order. If an odd value is specified for one of these configurations n, function fir2 increases n on 1.

Data types

Float64

# f — frequency-amplitude response

+ vector

Details

The frequency-amplitude characteristic, defined as a vector of the same length as m.

Argument f — a vector of frequency points in the range from 0 before 1, where 1 corresponds to the Nyquist frequency. The first point of the vector f must be equal to 0, and the last one — 1. Vector elements f they must be sorted in ascending order. Repeated frequency points are allowed and are considered as steps in the frequency response.

Data types

Float64

# m — frequency-amplitude response

+ vector

Details

The frequency-amplitude characteristic, defined as a vector of the same length as f.

Argument m — a vector containing the desired amplitude-frequency response at each of the points specified in the argument m.

Data types

Float64

# npt — number of grid points

+ 512 (by default) | a positive integer scalar

Details

The number of grid points specified as a positive integer. Meaning npt there must be more than half of the filter order.: npt > n/2.

Data types

Float64

# lap is the length of the area around the duplicate frequency points

+ 25 (by default) | a positive integer scalar

Details

The length of the area around the duplicate frequency points, set as a positive integer.

Data types

Float64

# window — window

+ column vector

Details

A window defined as a column vector. The window vector must contain n + 1 element. If the argument is window if not specified, then the function fir2 uses the Hamming window.

Function fir2 does not automatically increase the length of the argument window when trying to design an odd-order filter with a Nyquist frequency bandwidth.

Data types

Float64

Output arguments

# b — filter coefficients

+ vector string

Details

The filter coefficients are returned as a vector string of length n + 1. The coefficients are sorted by descending degrees of the Z-transformation variable. :

Algorithms

Function fir2 uses frequency sampling to calculate the filter coefficients. The function linearly interpolates the desired frequency response into a dense, evenly distributed length grid npt. Function fir2 it also creates point areas lap around duplicate values f to ensure steep but smooth transitions. To obtain the filter coefficients, the function applies the inverse fast Fourier transform to the grid and multiplies by the argument window.

List of literature

  1. Jackson, L. B. Digital Filters and Signal Processing. 3rd Ed. Boston: Kluwer Academic Publishers, 1996.

  2. Mitra, Sanjit K. Digital Signal Processing: A Computer Based Approach. New York: McGraw-Hill, 1998.