| Signal Processing Toolbox | Search  Help Desk |
| fir1 | Examples See Also |
Window-based finite impulse response filter design - standard response.
Syntax
b = fir1(n,Wn) b = fir1(n,Wn,'ftype') b = fir1(n,Wn,window) b = fir1(n,Wn,'ftype',window) b = fir1(...,'noscale')
Description
fir1 implements the classical method of windowed linear-phase FIR digital filter design [1]. It designs filters in standard lowpass, bandpass, highpass, and bandpass configurations. (For windowed filters with arbitrary frequency response, use fir2.)
b = fir1(n,Wn)
returns row vector b containing the n+1 coefficients of an order n lowpass FIR filter. This is a Hamming-windowed, linear-phase filter with cutoff frequency Wn. The output filter coefficients, b, are ordered in descending powers of z:
Wn, the cutoff frequency, is a number between 0 and 1, where 1 corresponds to half the sampling frequency (the Nyquist frequency).
If Wn is a two-element vector, Wn = [w1 w2], fir1 returns a bandpass filter with passband w1 <
< w2.
If Wn is a multi-element vector, Wn = [w1 w2 w3 w4 w5 ... wn], fir1 returns an order n multiband filter with bands 0 <
< w1, w1 <
< w2, ..., wn <
< 1.
By default, the filter is scaled so that the center of the first passband has magnitude exactly 1 after windowing.
b = fir1(n,Wn,'ftype')
specifies a filter type, where ftype is
high for a highpass filter with cutoff frequency Wn
stop for a bandstop filter, if Wn = [w1 w2]
The stopband is w1 <
< w2.
'DC-1' to make the first band of a multiband filter a passband
'DC-0' to make the first band of a multiband filter a stopband
fir1 always uses an even filter order for the highpass and bandstop configurations. This is because for odd orders, the frequency response at the Nyquist frequency is 0, which is inappropriate for highpass and bandstop filters. If you specify an odd-valued n, fir1 increments it by 1.
b = fir1(n,Wn,window)
uses the window specified in column vector window for the design. The vector window must be n+1 elements long. If no window is specified, fir1 employs a Hamming window.
b = fir1(n,Wn,'ftype',window)
accepts both ftype and window parameters.
b = fir1(...,'noscale')
turns off the default scaling.
The group delay of the FIR filter designed by fir1 is n/2.
Algorithm
fir1 uses the window method of FIR filter design [1]. If w(n) denotes a window, where 1
n
N, and the impulse response of the ideal filter is h(n), where h(n) is the inverse Fourier transform of the ideal frequency response, then the windowed digital filter coefficients are given by
Examples
Example 1
Design a 48th-order FIR bandpass filter with passband 0.35
w
0.65:
b = fir1(48,[0.35 0.65]);freqz(b,1,512)
Example 2
Thechirp.mat file contains a signal, y, that has most of its power above Fs/4, or half the Nyquist frequency. Design a 34th-order FIR highpass filter to attenuate the components of the signal below Fs/4. Use a cutoff frequency of 0.48 and a Chebyshev window with 30 dB of ripple:
load chirp % loads y and Fs b = fir1(34,0.48,'high',chebwin(35,30)); yfilt = filter(b,1,y);Check the spectra of the original and filtered signals.
[Py,fy] = pburg(y,10,512,Fs);
[Pyfilt,fyfilt] = pburg(yfilt,10,512,Fs);
plot(fy,10*log10(Py),':',fyfilt,10*log10(Pyfilt)); grid
ylabel('Magnitude (dB)'); xlabel('Frequency (Hz)');
legend('Chirp','Filtered Chirp')
Play the two signals using sound.
sound(y,Fs); sound(yfilt,Fs);
Diagnostics
Ifn is odd and you specify a bandstop or highpass filter, fir1 gives the following warning message:
For highpass and bandstop filters, N must be even. Order is being increased by 1.
See Also
filter |
Filter data with a recursive (IIR) or nonrecursive (FIR) filter. |
fir2 |
Window-based finite impulse response filter design--arbitrary response. |
fircls |
Constrained least square FIR filter design for multiband filters. |
fircls1 |
Constrained least square filter design for lowpass and highpass linear phase FIR filters. |
firls |
Least square linear-phase FIR filter design. |
freqz |
Frequency response of digital filters. |
kaiserord |
Estimate parameters for fir1 with Kaiser window. |
remez |
Parks-McClellan optimal FIR filter design. |
References
[1] IEEE. Programs for Digital Signal Processing. IEEE Press. New York: John Wiley & Sons, 1979. Algorithm 5.2.