In signal processing, a finite impulse response (FIR) filter is a filter whose impulse response (or response to any finite length input) is of finite duration, because it settles to zero in finite time. This is in contrast to infinite impulse response (IIR) filters, which may have internal feedback and may continue to respond indefinitely (usually decaying).
The impulse response (that is, the output in response to a Kronecker delta input) of an Nth-order discrete-time FIR filter lasts exactly
N+1
FIR filters can be discrete-time or continuous-time, and digital or analog.
For a causal discrete-time FIR filter of order N, each value of the output sequence is a weighted sum of the most recent input values:
\begin{align} y[n]&=b0x[n]+b1x[n-1]+ … +bNx[n-N]\\ &=
N | |
\sum | |
i=0 |
bi ⋅ x[n-i], \end{align}
where:
This computation is also known as discrete convolution.
The in these terms are commonly referred to as s, based on the structure of a tapped delay line that in many implementations or block diagrams provides the delayed inputs to the multiplication operations. One may speak of a 5th order/6-tap filter, for instance.
The impulse response of the filter as defined is nonzero over a finite duration. Including zeros, the impulse response is the infinite sequence:
h[n]=
N | |
\sum | |
i=0 |
bi ⋅ \delta[n-i]=\begin{cases} bn&0\len\leN\\ 0&otherwise.\end{cases}
If an FIR filter is non-causal, the range of nonzero values in its impulse response can start before
n=0
An FIR filter has a number of useful properties which sometimes make it preferable to an infinite impulse response (IIR) filter. FIR filters:
The main disadvantage of FIR filters is that considerably more computation power in a general purpose processor is required compared to an IIR filter with similar sharpness or selectivity, especially when low frequency (relative to the sample rate) cutoffs are needed. However, many digital signal processors provide specialized hardware features to make FIR filters approximately as efficient as IIR for many applications.
The filter's effect on the sequence
x[n]
\underbrace{l{F}\{x*h\}}Y(\omega)=\underbrace{l{F}\{x\}}X(\omega) ⋅ \underbrace{l{F}\{h\}}H(\omega)
y[n]=x[n]*h[n]=l{F}-1\{X(\omega) ⋅ H(\omega)\},
where operators
l{F}
l{F}-1
H(\omega)
H2\pi(\omega) \triangleq
infty | |
\sum | |
n=-infty |
h[n] ⋅ \left({ei
where the added subscript denotes
2\pi
\omega
H2\pi(2\pif')
1
f'
\omega=\pi
f'=\tfrac{1}{2}.
x[n]
fs
f=f' ⋅ fs=\tfrac{\omega}{2\pi} ⋅ fs
f1,
f2,
f1/fs,
f2/fs,
H2\pi(\omega)
\widehatH(z) \triangleq
infty | |
\sum | |
n=-infty |
h[n] ⋅ z-n.
H2\pi(\omega)=\left.\widehatH(z)
\right| | |
z=ej |
=\widehatH(ej).
FIR filters are designed by finding the coefficients and filter order that meet certain specifications, which can be in the time domain (e.g. a matched filter) or the frequency domain (most common). Matched filters perform a cross-correlation between the input signal and a known pulse shape. The FIR convolution is a cross-correlation between the input signal and a time-reversed copy of the impulse response. Therefore, the matched filter's impulse response is "designed" by sampling the known pulse-shape and using those samples in reverse order as the coefficients of the filter.[1]
When a particular frequency response is desired, several different design methods are common:
Software packages such as MATLAB, GNU Octave, Scilab, and SciPy provide convenient ways to apply these different methods.
In the window design method, one first designs an ideal IIR filter and then truncates the infinite impulse response by multiplying it with a finite length window function. The result is a finite impulse response filter whose frequency response is modified from that of the IIR filter. Multiplying the infinite impulse by the window function in the time domain results in the frequency response of the IIR being convolved with the Fourier transform (or DTFT) of the window function. If the window's main lobe is narrow, the composite frequency response remains close to that of the ideal IIR filter.
The ideal response is often rectangular, and the corresponding IIR is a sinc function. The result of the frequency domain convolution is that the edges of the rectangle are tapered, and ripples appear in the passband and stopband. Working backward, one can specify the slope (or width) of the tapered region (transition band) and the height of the ripples, and thereby derive the frequency-domain parameters of an appropriate window function. Continuing backward to an impulse response can be done by iterating a filter design program to find the minimum filter order. Another method is to restrict the solution set to the parametric family of Kaiser windows, which provides closed form relationships between the time-domain and frequency domain parameters. In general, that method will not achieve the minimum possible filter order, but it is particularly convenient for automated applications that require dynamic, on-the-fly, filter design.
The window design method is also advantageous for creating efficient half-band filters, because the corresponding sinc function is zero at every other sample point (except the center one). The product with the window function does not alter the zeros, so almost half of the coefficients of the final impulse response are zero. An appropriate implementation of the FIR calculations can exploit that property to double the filter's efficiency.
Goal:
To design FIR filter in the MSE sense, we minimize the mean square error between the filter we obtained and the desired filter.
-1 | |
MSE=f | |
s |
fs/2 | |
\int | |
-fs/2 |
2df | |
|H(f)-H | |
d(f)| |
fs
H(f)
Hd(f)
Method:
Given an N-point FIR filter
h[n]
r[n]=h[n+k],k=
(N-1) | |
2 |
Step 1: Suppose
h[n]
r[n]
R(F)=ej2H(F)=
k | |
\sum | |
n=0 |
s[n]\cos(2\pinF)
Step 2: Calculate mean square error.
1/2 | |
MSE=\int | |
-1/2 |
2dF | |
|R(F)-H | |
d(F)| |
Therefore,
MSE=
1/2 | |
\int | |
-1/2 |
k | |
\sum | |
n=0 |
s[n]\cos(2\pinF)
k | |
\sum | |
\tau=0 |
s[\tau]\cos(2\pi\tauF)dF
1/2 | |
-2\int | |
-1/2 |
k | |
\sum | |
n=0 |
s[n]\cos(2\pinF)HddF+
1/2 | |
\int | |
-1/2 |
2dF | |
H | |
d(F) |
Step 3: Minimize the mean square error by doing partial derivative of MSE with respect to
s[n]
\partialMSE | |
\partials[n] |
=
k | |
2\sum | |
\tau=0 |
s[\tau]
1/2 | |
\int | |
-1/2 |
\cos(2\pinF)\cos(2\pi\tauF)dF-
1/2 | |
2\int | |
-1/2 |
2 | |
H | |
d(F) |
\cos(2\pinF)dF=0
After organization, we have
s[0]=
1/2 | |
\int | |
-1/2 |
Hd(F)dF
s[n]=
1/2 | |
\int | |
-1/2 |
\cos(2\pinF)Hd(F)dF, forn\ne0
Step 4: Change
s[n]
h[n]
h[k]=s[0],h[k+n]=s[n]/2,h[k-n]=s[n]/2, for n=1,2,3,\ldots,k,wherek=(N-1)/2
h[n]=0forn<0andn\geN
In addition, we can treat the importance of passband and stopband differently according to our needs by adding a weighted function,
W(f)
MSE
1/2 | |
=\int | |
-1/2 |
2dF | |
W(F)|R(F)-H | |
d(F)| |
A moving average filter is a very simple FIR filter. It is sometimes called a boxcar filter, especially when followed by decimation, or a sinc-in-frequency. The filter coefficients, , are found via the following equation:
b | ||||
|
To provide a more specific example, we select the filter order:
N=2
The impulse response of the resulting filter is:
h[n]=
1 | |
3 |
\delta[n]+
1 | |
3 |
\delta[n-1]+
1 | |
3 |
\delta[n-2]
The block diagram on the right shows the second-order moving-average filter discussed below. The transfer function is:
H(z)=
1 | |
3 |
+
1 | |
3 |
z-1+
1 | |
3 |
z-2=
1 | |
3 |
z2+z+1 | |
z2 |
.
The next figure shows the corresponding pole–zero diagram. Zero frequency (DC) corresponds to (1, 0), positive frequencies advancing counterclockwise around the circle to the Nyquist frequency at (−1, 0). Two poles are located at the origin, and two zeros are located at , .
The frequency response, in terms of normalized frequency ω, is:
\begin{align} H\left(ej\omega\right)&=
1 | |
3 |
+
1 | |
3 |
e-j\omega+
1 | |
3 |
e-j2\omega\\ &=
1 | |
3 |
e-j\omega\left(1+2\cos(\omega)\right). \end{align}
The magnitude and phase components of are plotted in the figure. But plots like these can also be generated by doing a discrete Fourier transform (DFT) of the impulse response. And because of symmetry, filter design or viewing software often displays only the [0, π] region. The magnitude plot indicates that the moving-average filter passes low frequencies with a gain near 1 and attenuates high frequencies, and is thus a crude low-pass filter. The phase plot is linear except for discontinuities at the two frequencies where the magnitude goes to zero. The size of the discontinuities is π, representing a sign reversal. They do not affect the property of linear phase, as illustrated in the final figure.