Function File: b = fir1 (n, w)
Function File: b = fir1 (n, w, type)
Function File: b = fir1 (n, w, type, window)
Function File: b = fir1 (n, w, type, window, noscale)

Produce an order n FIR filter with the given frequency cutoff w, returning the n+1 filter coefficients in b. If w is a scalar, it specifies the frequency cutoff for a lowpass or highpass filter. If w is a two-element vector, the two values specify the edges of a bandpass or bandstop filter. If w is an N-element vector, each value specifies a band edge of a multiband pass/stop filter.

The filter type can be specified with one of the following strings: "low", "high", "stop", "pass", "bandpass", "DC-0", or "DC-1". The default is "low" is w is a scalar, "pass" if w is a pair, or "DC-0" if w is a vector with more than 2 elements.

An optional shaping window can be given as a vector with length n+1. If not specified, a Hamming window of length n+1 is used.

With the option "noscale", the filter coefficients are not normalized. The default is to normalize the filter such that the magnitude response of the center of the first passband is 1.

To apply the filter, use the return vector b with the filter function, for example y = filter (b, 1, x).

Examples:

freqz (fir1 (40, 0.3));
freqz (fir1 (15, [0.2, 0.5], "stop"));  # note the zero-crossing at 0.1
freqz (fir1 (15, [0.2, 0.5], "stop", "noscale"));

See also: filter, fir2.

Demonstration 1

The following code

 freqz(fir1(40,0.3));

Produces the following figure

Figure 1

Demonstration 2

The following code

 freqz(fir1(15,[0.2, 0.5], 'stop'));  # note the zero-crossing at 0.1

Produces the following output

warning: n must be even for highpass and bandstop filters. Incrementing.
warning: called from
    fir1 at line 102 column 5
    get_output at line 50 column 5
    __html_help_text__ at line 67 column 28
    generate_package_html>wrote_html at line 869 column 5
    generate_package_html at line 211 column 13

and the following figure

Figure 1

Demonstration 3

The following code

 freqz(fir1(15,[0.2, 0.5], 'stop', 'noscale'));

Produces the following output

warning: n must be even for highpass and bandstop filters. Incrementing.
warning: called from
    fir1 at line 102 column 5
    get_output at line 50 column 5
    __html_help_text__ at line 67 column 28
    generate_package_html>wrote_html at line 869 column 5
    generate_package_html at line 211 column 13

and the following figure

Figure 1

Package: signal