fir1

Create a digital FIR filter.

Syntax

[b] = fir1(n,w)

[b] = fir1(n,w,type)

[b] = fir1(n,w,type,window)

[b] = fir1(n,w,type,window,noscale)

Inputs

n
The filter order.
Type: integer
Dimension: scalar
w
A scalar specifying the cutoff frequency of a low or high pass filter, or a two element vector specifying the cutoff frequencies of a bandpass or band stop filter, or. For a vector containing cutoff frequencies of a multi-band filter.
Type: double
Dimension: scalar | vector
type
The band type of the filter. The valid options are:
  • 'low' for a low pass filter
  • 'high' for a high pass filter
  • 'bandpass' for a bandpass filter
  • 'stop' for a band stop filter
  • 'DC-0' for a multi-band filter with a DC value of 0
  • 'DC-1' for a multi-band filter with a DC value of 1
If type is omitted, the defaults are 'low', 'bandpass', or 'DC-0', depending on the content of w.
Type: string
window
A window vector of size n+1. If omitted or [], a Hamming window is used.
Type: double
Dimension: vector
noscale
Set to noscale if the output is not to be normalized. When omitted, the gain is set to 1 as follows:
  • at DC for 'low'
  • at the Nyquist frequency for 'high'
  • at the center of the pass band for 'bandpass'
  • at DC for 'stop'
  • at the center of the first pass band for 'DC-0'
  • at DC for 'DC-1'
Type: string

Outputs

b
The polynomial coefficients of the filter.
Type: vector

Example

Plot the magnitude response in decibels for a 50th order FIR low pass digital filter with a 250 Hz cutoff frequency and a 2000 Hz sampling frequency.

w = hamming(51, 'symmetric');
fc = 250;
fs = 2000;
num = fir1(50,fc/(fs/2),'low',w);
[h,f] = freqz(num,1,[0:5:1000],fs);
plot(f,20*log10(abs(h)));

Example



Plot the magnitude response in decibels for a 50th order FIR multiband digital filter with passbands of [300,400], [590,610], [775,825], and a 2000 Hz sampling frequency.

w = hamming(51, 'symmetric');
fc = [300,400,590,610,775,825];
fs = 2000;
num = fir1(50,fc/(fs/2),'DC-0',w);
[h,f] = freqz(num,1,[0:5:1000],fs);
plot(f,20*log10(abs(h)));


Comments

The filter order must be even for highpass or band stop filters. The function will increment an invalid odd order automatically when the default window is used.