Sei sulla pagina 1di 13

Filters are used in a wide variety of applications.

Most of the time, the final goal


of using a filter is to achieve a kind of frequency selectivity on the spectrum of
the input signal.
As an example, suppose that a 50-Hz noise falls on top of the signal produced
by a sensor. The noise component may be strong enough to limit the
measurement precision. The output of the sensor is usually converted to a
digital signal by an ADC to be processed by a DSP or a microcontroller.
Therefore, we can use a digital filter after the ADC to eliminate the noise
component. In this particular example, a notch filter centered at 50 Hz can be
utilized to suppress the noise.
At this point, it is worth reviewing the frequency response of a practical filter.
Figure (1) shows an example of a practical lowpass filter. In this example,
frequency components in the passband, from DC to ωp ωp, will pass through
the filter almost with no attenuation. The components in the stopband,
above ωs ωs, will experience significant attenuation. Note that the frequency
response of a practical filter cannot be absolutely flat in the passband or in the
stopband. As shown in Figure (1), some ripples will be unavoidable and the
transition band, ωp<ω<ωs ωp<ω<ωs, cannot be infinitely sharp in practice.
Figure (1) Frequency response of a practical lowpass filter. Image courtesy of the University of
Michigan (PDF).

General Considerations
Digital filter design involves four steps:

1) Determining specifications

First, we need to determine what specifications are required. This step


completely depends on the application. In the example of 50-Hz noise on the
output of the sensor, we need to know how strong the noise component is
relative to the desired signal and how much we need to suppress the noise. This
information is necessary to find the filter with minimum order for this
application.

2) Finding a transfer function


With design specifications known, we need to find a transfer function which will
provide the required filtering. The rational transfer function of a digital filter is
as in Equation (1).

H( z ) = ∑ M − 1k = 0bk z− k ∑ N − 1k = 0 a k z− k H(z)=∑k=0M−1b
kz−k∑k=0N−1akz−k

Equation (1)

This step calculates the coefficients, a k akand bk bk, in Equation (1).


3) Choosing a realization structure

Now that H( z ) H(z)is known, we should choose the realization structure. In


other words, there are many systems which can give the obtained transfer
function and we must choose the appropriate one. For example, any of the
direct form I, II, cascade, parallel, transposed, or lattice forms can be used to
realize a particular transfer function. The main difference between the
aforementioned realization structures is their sensitivity to using a finite length
of bits. Note that in the final digital system, we will use a finite length of bits to
represent a signal or a filter coefficient. Some realizations, such as direct forms,
are very sensitive to quantization of the coefficients. However, cascade and
parallel structures show smaller sensitivity and are preferred.
4) Implementing the filter

After deciding on what realization structure to use, we should implement the


filter. You have a couple of options for this step: a software implementation
(such as a MATLAB or C code) or a hardware implementation (such as a DSP, a
microcontroller, or an ASIC).
This article focuses on the second step in designing an FIR filter.

FIR Filters
An FIR filter is a special case of Equation (1),
where a 0 = 1 a0=1and a k = 0 ak=0for k = 1 ,..., N − 1 k=1,...,N−1, hence
we obtain:

H( z ) = M − 1 ∑ k = 0bk z− k H(z)=∑k=0M−1bkz−k

Equation (2)

The direct form realization of Equation (2) for M=3 is shown in Figure (2). As
shown in this figure, a digital filter can be implemented using only three
elements:

1. Addition
2. Multiplication by a constant (necessary for the implementation of the
coefficients)
3. Delay blocks

Figure (2) Direct form of an FIR filter of order 2

There are three coefficients and two delay cells in Figure (2). Note that this filter
is of order 2, the number of delay cells, not 3, the number of coefficients.
An FIR filter has two important advantages over an IIR design:
Firstly, as shown in Figure (2), there is no feedback loop in the structure of an
FIR filter. Due to not having a feedback loop, an FIR filter is inherently stable.
Meanwhile, for an IIR filter, we need to check the stability.
Secondly, an FIR filter can provide a linear-phase response. As a matter of fact,
a linear-phase response is the main advantage of an FIR filter over an IIR
design—otherwise, for the same filtering specifications, an IIR filter will lead to
a lower order.
In order to have a linear-phase FIR filter, we must provide symmetry in the time
domain, i.e. b[ n ] = ±b[M − 1 −n ] b[n]=±b[M−1−n]. In the example
shown in Figure (2), assume that b0 = b2 b0=b2, hence Equation (2) gives

H( z ) = b0 + b1 e− j ω+ b0 e− j2 ω = e− j ω (b1 + 2b0 cos ( ω )) H


(z)=b0+b1e−jω+b0e−j2ω=e−jω(b1+2b0cos⁡(ω))

Equation (3)

Since bk bkis real, phase of H( z ) H(z)will be

∡H( z ) = { −ωp b1 + 2b0 cos ( ω ) > 0 −ωp+π b1 + 2b0 cos (

ω ) < 0 ∡H(z)={−ωpb1+2b0cos(ω)>0−ωp+πb1+2b0cos(ω)<0

Equation (4)

Therefore, the phase response will be linear. Although this example shows
a linear-phase response in the case of a three-tap filter, it can be shown that for
an arbitrary value of M M, time-domain symmetry leads to a linear-phase
response. This is an important property which helps us to examine the linear-
phase response of an FIR filter just by considering the values of bk bkwithout
any calculation.
The reader may wonder why a linear-phase frequency response is important. To
gain insight, consider the continuous-time case. Assume that the frequency
response of a system is

H( s ) = αe− j β ω H(s)=αe−jβω

Equation (5)

where α αand β βare real constants. The phase response of this system is linear,

i.e. ∡H( s ) = − β ω ∡H(s)=−βω.

If we apply x (t) = A cos ( ω 1t) x(t)=Acos(ω1t)to this system, the output


will
be y (t) = α A cos ( ω 1t − β ω 1) = αx (t − β ) y(t)=αAcos(ω1t−β
ω1)=αx(t−β). Therefore, the linear-phase response corresponds to a constant
delay. A system with a nonlinear-phase response will distort the input, even
if |H( s )| |H(s)|is constant. In such a system, different frequency components
of the input will experience different time delays as they pass through the
system. For a digital system with a phase response
of ∡H( z ) = − k ω ∡H(z)=−kωwhere k kis an integer, we can also prove
that the linear phase is equal to a constant delay.
Introduction to FIR Filter Design by
Windowing
We will explain the window method by using an example. Suppose that we want
to design a lowpass filter with a cutoff frequency of ωc ωc, i.e. the desired
frequency response will be:
H d( ω ) = { 1| ω | <ωc 0 e l se Hd(ω)={1|ω|<ωc0else

Equation (6)

To find the equivalent time-domain representation, we calculate the inverse


discrete-time Fourier transform:

hd[ n ] = 12 π ∫ +π−π H d( ω ) e j ωn d ω hd[n]=12π∫−π+πHd(ω)ej

ωndω

Equation (7)

Substituting Equation (6) into Equation (7), we obtain:

hd[ n ] = 12 π ∫ +ωc−ωce j ωn d ω = s i n ( nωc ) nπ hd[n]=12π∫−

ωc+ωcejωndω=sin⁡(nωc)nπ

Equation (8)

Equation (8) for ωc = π 4 ωc=π4is shown in Figure (3):


Figure (3) Impulse response of an ideal lowpass filter with ωc = π 4 ωc=π4
Figure (3) shows that hd[ n ] hd[n] needs an infinite number of input samples
to perform filtering and that the system is not a causal system.
The obvious solution will be to truncate the impulse response and use, for
example, only 21 samples of the input and assume other coefficients to be zero.
Intuition suggests that, as the number of samples increases, the truncated
impulse response will be closer to the ideal impulse response in Figure (3) and
therefore the frequency response of the achieved filter will be closer to Equation
(6).
On the other hand, as we increase the number of samples, more hardware will
be required. If we choose to use only 21 taps of the ideal response, there will
be three options which are shown in Figures (4) to (6).
The first option is shown in Figure (4). This impulse response corresponds to a
non-causal system and cannot be used.
Figure (4) Truncated impulse response: linear-phase, but non-causal

The next option is shown in Figure (5) which, despite being causal, does not
have a linear-phase response (the most important property of an FIR system).
Figure (5) Truncated impulse response: causal, but nonlinear-phase

The last option is shown in Figure (6). This system is both causal and linear
phase. The only drawback to this system is its delay which
is M − 12 M−12samples. In other words, in response to an impulse
at n = 0 n=0, the system will not react until almost n = M − 12 n=M−12. This
delay may cause problems in some applications.
Figure (6) Truncated impulse response: causal and linear phase

Truncation of the impulse response is equivalent to


multiplying hd[ n ] hd[n](or its shifted version) by a rectangular
window, w [ n ] w[n]which is equal to one
for n = 0 ,..., M − 1 n=0,...,M−1and zero otherwise. Therefore, considering the
applied shift, we obtain the impulse response of the designed filter:

h[ n ] = hd[ n− M − 12] w [ n ] h[n]=hd[n−M−12]w[n]

Equation (9)
Clearly the spectrum of the rectangular window will cause the filter response to
deviate from the ideal response in Equation (6). Figure (7) compares the
response of the designed filter with that of the ideal one.
This figure shows that, unlike the ideal filter, the designed filter has a smoother
transition from the passband to the stopband. Moreover, there are some ripples
in both the passband and stopband of H( ω ) H(ω). How can we make the
transition band sharper? How can we make the ripples smaller? What other
options are there to be used instead of a rectangular window?

Figure (7) Frequency response of the filter designed by a rectangular window

Summary
 To design a digital filter, we need to find the coefficients, a k akand bk bk,
in Equation (1).
 An FIR filter is a special case of Equation (1),
where a 0 = 1 a0=1and a k = 0 ak=0for k = 1 ,..., N − 1 k=1,...,N−1.
 Stability and linear-phase response are the two most important advantages
of an FIR filter over an IIR filter.
 A linear-phase frequency response corresponds to a constant delay.
 Truncation of the impulse response is equivalent to
multiplying hd[ n ] hd[n]by a rectangular window, w [ n ] w[n], which is
equal to one for n = 0 ,..., M − 1 n=0,...,M−1and zero otherwise.
 A wider transition band and ripples in the passband and stopband are the
most important differences between the ideal filters and those designed by
window method.

Potrebbero piacerti anche