Engee documentation

fir1

Page in progress.

Calculation of FIR filter coefficients using different windows.

Library

EngeeDSP

Syntax

Function call

  • b = fir1(n, Wn) — uses a Hamming window to design a low-pass, bandpass, or multiband FIR filter n-th order with linear phase. The filter type depends on the number of Wn elements.

  • b = fir1(n, Wn, ftype) — designs a low-pass, high-pass, bandpass, notch, or multiband filter depending on the value of ftype and the number of elements Wn.

  • b = fir1(_, window) — designs a filter using the vector specified in window and any arguments from the previous syntaxes.

  • b = fir1(_, scaleopt) — additionally indicates whether the amplitude-frequency response of the filter is normalized.

Use the function fir2 for window filters with an arbitrary frequency response.

Arguments

Input arguments

# n — filter order

+ scalar

Details

The filter order is set as a positive integer.

For high-pass filters and notch filters, the function fir1 always uses an even filter order. The order must be even, since symmetric FIR filters of odd order must have zero gain at the Nyquist frequency. If an odd value is specified for the high-pass filter or the blocking filter n, then the function fir1 increases n on 1.

Data types

Int64

# Wn is the cutoff frequency

+ scalar | two-element vector | multi-element vector

Details

The cutoff frequency, specified as a scalar, two-element vector, or multi-element vector.

All the elements Wn must be in the range of 0 before 1, where 1 corresponds to the Nyquist frequency. The Nyquist frequency is equal to half the sampling frequency, or rad/countdown.

  • If Wn is a scalar, then the function fir1 designs a low-pass or high-pass filter with a cutoff frequency Wn. The cutoff frequency is the frequency at which the gear ratio is -6 dB.

  • If Wn — two-element vector [W1 W2], where W1 < W2 Then fir1 designs a bandpass or notch filter with a lower cutoff frequency W1 and the upper cutoff frequency W2.

  • If Wn — multi-element vector [W1 W2 …​ Wn], where W1 < W2 < …​ < Wn Then fir1 designs a multiband filter n-th order with stripes 0 < < W1, W1 < < W2,…​, Wn < < 1.

Data types

Float64

# window — window

+ vector

Details

A vector for windowing the impulse response. The window vector must contain n + 1 element. The default function is fir1 uses the Hamming window. List of available windows:

  • "bartlett" — Bartlett’s window;

  • "blackman" — Blackman’s window;

  • "chebyshev" — Chebyshev’s window;

  • "hamming" — Hamming window;

  • "hann" — Hannah’s window;

  • "kaiser" — Kaiser’s window;

  • "triangular" — triangular window;

Optional parameters can be specified for Kaiser and Chebyshev windows. Examples:

Using the Kaiser window with the parameter beta = 4.0:

b = fir1(N, Wn, window("kaiser", N+1, 4.0))

Using the Chebyshev window with 65.0 dB relative attenuation of the side lobes:

b = fir1(N, Wn, window("chebyshev", N+1, 65.0), "high")
Data types

Float64

# ftype — filter type

+ "low" | "high" | "bandpass" | "stop" | "DC-0" | "DC-1"

Details

Filter Type:

  • "low" defines a low-pass filter with a cutoff frequency Wn, "low" — the default value for a scalar function Wn.

  • "high" defines a high-pass filter with a cutoff frequency Wn.

  • "bandpass" defines a bandpass filter if Wn — two-element vector, "bandpass" — default value if Wn It consists of two elements.

  • "stop" detects the notch filter if Wn — a two-element vector.

  • "DC-0" determines that the first band of the multiband filter is a delay band, "DC-0" — default value if Wn It consists of more than two elements.

  • "DC-1" determines that the first band of the multiband filter is the bandwidth.

# scaleopt — scaling the filter

+ "scale" (by default) | "noscale"

Details

Scaling the filter:

  • "scale" scales the coefficients so that the amplitude-frequency response of the filter in the center of the bandwidth is equal to 1 (0 dB).

  • "noscale" does not scale coefficients.

Output arguments

# b — filter coefficients

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 fir1 uses the least squares approximation to calculate the filter coefficients, and then smooths the impulse response using window.

Literature

  1. 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.2.