FIR Filter Design by Windowing: Concepts and the Rectangular Window

In this article, we'll review the basic concepts in digital filter design. We'll also briefly discuss the advantages of FIR filters over IIR designs, e.g. stability and the linear-phase response. Finally, we'll go over an introduction to designing FIR filters via the window method.

Why Do We Need Filters?                                            

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=0bkz−kN−1k=0akz−kH(z)=∑k=0M−1bkz−k∑k=0N−1akz−k

 
Equation (1)

 

This step calculates the coefficients,

akak

 and

bkbk

, 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

a0=1a0=1

 and

ak=0ak=0

 for

k=1,...,N−1k=1,...,N−1

, hence we obtain:

 

H(z)=∑k=0M−1bkz−kH(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=b2b0=b2

, hence Equation (2) gives

 

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

 

Equation (3)

 

Since

bkbk

 is real, phase of

H(z)H(z)

 will be

 

H(z)={−ωp−ωp+πb1+2b0cos(ω)>0b1+2b0cos(ω)<0H(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

MM

, 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

bkbk

 without 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)=Acos1t)x(t)=Acos(ω1t)

 to this system, the output will be

y(t)=αAcos1t−βω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)=−H(z)=−

 where

kk

 is 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:

 

Hd(ω)={10|ω|<ωcelseHd(ω)={1|ω|<ωc0else

 

Equation (6)

 

To find the equivalent time-domain representation, we calculate the inverse discrete-time Fourier transform:

 

hd[n]=12π∫+π−πHd(ω)ejωnhd[n]=12π∫−π+πHd(ω)ejωndω

 

Equation (7)

 

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

 

hd[n]=12π∫c−ωcejωndω=sin(nωc)nπhd[n]=12π∫−ωc+ωcejωndω=sin⁡(nωc)nπ

 

Equation (8)

 

Equation (8) for

ωc=π4ωc=π4

 is 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−12M−12

 samples. In other words, in response to an impulse at

n=0n=0

, the system will not react until almost

n=M−12n=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−1n=0,...,M−1

 and 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, akak and bkbk in Equation (1).

     An FIR filter is a special case of Equation (1), where a0=1a0=1and ak=0ak=0 for k=1,...,N−1k=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−1n=0,...,M−1 and 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.