You are on page 1of 9

Daltech, Dalhousie University Department of Electrical and Computer Engineering

ECED 4502 Digital Signal Processing

Lab 5 Finite Impulse Response Filtering in Labview


ERRONOUS SET-UP OF SIGNALS CAUSES DESTRUCTION OF CIRCUITRY 1) Before switching the computer on, make sure that the Screw Terminal is connected to the Labview DAQ board on PC using the ribbon cable provided; 2) Before you apply any signal to the A/D converter, using the scope ensure at all times that the output of the signal generator does n exceed 1Vpp (use 200mVpp ot for the start); monitor the signal generator output by observing it on channel 1 of the scope; and connect the signal generator output to the coax cable attached to the screw terminal using the BNC splitter. Objectives The objectives of this lab is (i) to observe the characteristics of finite impulse response (FIR) filters and to design your own FIR filters in Labview; (ii) to verify your designs in Matlab . Background The background material for this Lab is presented in Appendix A. Procedure 1. Connect the DAQ board (screw terminal) to the signal generator using the 2 -wire oscilloscope connector. Pin associations can be found in the spec sheets. To avoid unnecessary problems you should have ground of the signal generator connected to the screw labeled as 9 and the hot wire connected to the screw labeled 1. The general setup for the lab is illustrated in Fig.1. 2. Set the signal generator to produce a 100 mVp-p, 1 kHz sine wave. 3. Start up "National Instruments LabView" from the start menu. 4. When the initial splash screen appears, choose " PEN" the vi file and choose the O firspec.vi file in the c:\dsp\labview\fir subdirectory. The following screen should appear (Fig.2):

- 1ECED4502 Lab5

Fig.1. General Labview Setup for the FIR filtering experiment

Fig.2. Labview Screen with the FIR vi software running in the design mode.

- 2ECED4502 Lab5

5. By setting up Filter Input switch into the Delta position (default) you will be able to design your own FIR filter in Labview. In this case, the lower diagram shows the frequency response of your filter. The parameters of your filter are given in the FIR Filter Settings part of the screen where you can select (i) the filter type you should try first the low-pass filter; (ii) the number of coefficients (taps) in your filter (the more taps, the better approximation of the ideal filter you will get) and (iii) the cut-off frequency of your filter the cut-off frequency should be always smaller than f2s with f s selected in the part of the screen Acquire Settings. You could try to design your filter using different windows, number of taps, and by using different setting for the DISPLAY button so that you could observe better distinction between the logarithmic and linear scales along the Y axis. Please switch also from automatic to manual display so that you could measure the 3-dB bandwidth and capture more interesting parts of the frequency response graphs. The coefficients in your design are printed in the FIR Windowed Coefficients table using a sliding window approach you see actually at any given time only 8 coefficients but by adjusting the index of the first displayed coefficient you can get the whole impulse response. q Change the filter type to cover the various types but you should concentrate on the lowpass filter design; q Change the sampling rate to 10kHz and the cutoff frequency to 2 kHz; (Do not worry about the high cut off frequency as we are only dealing with a low pass filter); q Change the number of taps (length of your filer) from 33 to 7 and 5 taps. q Record your filter frequency responses as later you will be comparing them with frequency responses of filters designed in Matlab. q In your designs, you should focus on the FIR filter design with no windowing as this corresponds to the usage of the rectangular window or equivalently truncating the h[n] = Sinc(f 0 t) t = n Ts impulse response of the ideal low-pass (brickwall) filter with the cut-off frequency f 0 to cover indexes from n = N till N and shifting this impulse response to 2 2 make the filter causal. 6. Once you designed your filter, you may filter the real (sampled) signal in the same program by setting up Filter Input switch into the Sampled Data position. By varying the frequency of your sinusoidal input (keep the amplitude the same), you can observe in the lower graph the discrete Fourier transform (DFT) of your output after passing through the filter you designed earlier. The middle graph shows the DFT of the input. Both input and output DFTs are based on the number of samples specified in the Frame Size box of the ACQUIRE SETTING part of the screen. By varying the frequency of your input in the range from 0 to f2s , you should be able to measure the frequency response of your filter using the traditional approach in analog signal processing when the transfer function is measured for discrete frequency f 0 points by giving at the input the sinusoidal input with amplitude Vin ( f 0 ) and measuring the amplitude of the sinusoidal output Vout ( f 0 ) , and getting the frequency response at f 0 as - 3ECED4502 Lab5

Vout ( f 0 ) . In order to observe roughly the attenuation of your filter in the Vin ( f 0 ) stopband, you should disable the automatic scaling along the Y -axis in the lowest graph. Please read carefully, the Appendix A of this Lab description to find out how we are getting the frequency response of digital filters. 7. Before you login to the Eng-Srv to use Matlab, it is recommended that you quit Labview as some of our systems may become unstable. 8. After designing a FIR filter with N=5 taps in Labview for f s =10kHz and cutoff frequency of your choice, you will verify your design in Matlab using the following steps: q If your coefficients were [0.15 0.19 0.20 0.19 0.15], define in Matlab the impulse response vector h as: h=[0.15 0.19 0.20 0.19 0.15]; and get the frequency response of your filter as hf=fft(h); plot(abs(hf)); q Now try to do zero padding on your impulse response as to get h1=[h zeros(1,100)]; hf1=fft(h1); plot(abs(hf1)); plot(20*log10(abs(hf1))); q Comment on your observations in these two steps and compare the last results to the frequency response of the filter displayed in Labview. q In the Matlab code provided, describe what each line does and how it affects the graphs. q You could design your own low-pass FIR filter with the impulse response myh in Matlab by using the following sample statements: myt=-4:4; myh=sinc(0.2*t); q You should also try to filter some sinusoidal signals x[n] = sin( 0 n) with different 0 using filter having the impulse response h from your design using filter command in Matlab: t=1:200; x=sin(0.25*t); y=filter(h,1,x); plot(y); plot(abs(fft(y))); H ( f0) = 9. In your lab report you should comment on the following: q How does the number of taps affect the frequency response of your FIR filters? q What is the separation between the passband and stopband in your designs? q How far does the transition zone extend? 10. Comment on your observations. - 4ECED4502 Lab5

Appendix A

FIR Digital Filters

Introduction
A digital filter is a basic building block in any Digital Signal Processing (DSP) system. The frequency response of the filter depends on the value of its coefficients, or taps. Many software programs can compute the values of the coefficients based on the desired frequency response. In our course, the students are using Labview programs to obtain the filter coefficients. These values are typically floating point numbers and they are represented with a fairly high degree of precision. However, when a digital filter is implemented in hardware, such as the TI TMS320C26 boards as it is a case in the second part of this laboratory experiment, the designer wants to represent the coefficients (and also the data) with the smallest number of bits that still gives acceptable resolution for the numbers. This is because representing a number with excess bits increases the size of the registers, buses, adders, multipliers and other hardware used to process that signal. The bigger sizes result in a chip with a larger die size, which translates into increased power consumption and a higher chip price. Thus, the bit precisions used to represent numbers are important in the performance of real-world signal processing designs.

Filtering with FIR systems


A Finite Impulse Response (FIR) digital filter is one whose impulse response is of finite duration. This can be stated mathematically as h[n ] = 0 n < 0 or n > N where h[n] denotes the impulse response of the digital filter, n is the discrete time index, and is the length of the filter. A difference equation is the discrete time equivalent of a continuous time differential equation. The general difference equation for a FIR digital filter is

y[n ] = h[ k ] x[ n k ]
k =0

where y(n) is the filter output at discrete time instance n, h[k] is the k-th feedforward tap, or filter coefficient, and x[n-k] is the filter input delayed by k samples. The

N k =0

denotes summation from k = 0

to k = N where N is the number of feedforward taps in the FIR filter. The calculations of the output sample in terms of the input samples and the h[k] coefficients are represented in the figure below with the

z 1 representing the delays (of one sampling period):

Figure 3: FIR structure


Note that the FIR filter output depends only on the previous N inputs. This feature is why the impulse response for a FIR filter is finite. When the input to a FIR filter is the unit impulse [n] , the output of the filter is the impulse response h[n].

- 5ECED4502 Lab5

Advantages of FIR filters


FIR filters are simple to design and they are guaranteed to be bounded input-bounded output (BIBO) stable. By designing the filter taps to be sym-metrical about the center tap position, a FIR filter can be guaranteed to have linear phase. This is a desirable property for many applications such as music and video processing. FIR filters also have a low sensitivity to filter coefficient unitization errors. This is an important property to have when implementing a filter on a DSP processor or on an integrated circuit.

FIR Filter Design by Windowing


The most commonly used techniques for design of infinite impulse response (IIR) filters are based on transformations of continuous-time systems into discrete-time IIR systems. This is partly because continuous-time filter design was a highly advanced art before discrete-time filters were of interest and partly because of the difficulty of implementing a noniterative direct design method for IIR filters. In contrast, FIR filters are almost entirely restricted to discrete-time implementations. Consequently the design techniques for FIR filters are based on directly approximating the desired frequency response of the discrete-time ssystem. Furthermore, most techniques for approximating the magnitude response of an FIR system assume a linear phase constraint, thereby avoiding the problem of spectrum factorization that comp licates the direct design of IIR filters. The simplest method of FIR filter design is called the window method. This method generally begins with an ideal desired frequency response that can be represented as

H d ( e j ) =
where

n =

h [n] e
d

(0)

hd [n] is the corresponding impulse response sequence, which can be expressed in terms of 1 hd [ n] = H d ( e j ) e j d 2

H d (e j ) as
(1)

Many idealized systems are defined by piecewise-constant or piecewise-functional frequency responses with discontinuities at the boundaries between bands. As a result, they have impulse responses that are noncausal and infinitely long. The most straightforward approach to obtaining a causal FIR approximation to such systems is to truncate the ideal response. Equation (1) can be thought of as a Fourier series representation of the periodic frequency response

H d (e j ) , with the sequence hd [n] playing the role of

the Fourier coefficients. Thus, the approximation of an ideal filter by truncation of the ideal impulse response is identical to the issue of the convergence of Fourier series, a subject that has received a great deal of study. A particularly important concept from this theory is the Gibbs phenomenon, which will be covered in the example with this Appendix. The simplest way to obtain a causal FIR filter from hd [n] is to define a new system with impulse response h[n] given by

h[n ] = {

hd [ n], L0 n M 0,Kotherwise

(2)

More generally, we can represent h[n] as the product of the desired impulse response and a finite-duration "window" w[n]; i.e., h[n ] = hd [ n] w[ n] (3) where for simple truncation as in Eq. (2), the window is the rectangular window

- 6ECED4502 Lab5

w[ n] = {
It follows from the windowing theorem that

1,L 0 n M 0,Kotherwise

(4)

H (e j ) =
That is,

1 H d (e j ) W ( e j ( ) )d 2

(5)

H (e j ) is the periodic convolution of the desired ideal frequency response with the Fourier j transform of the window. Thus, the frequency response H (e ) will be a "smeared" version of the desired j j j response H d (e ) . Figure 2(a) depicts typical functions H d (e ) and W (e ) as required in Eq.(5).
If w[n] = 1 for all n (i.e., we do not truncate at all), period

W (e j ) is a periodic impulse train with

2 , and therefore H d ( e j ) = H ( e j ) .

W (e j ) is concentrated in a narrow band of j j j frequencies around = 0 , then H (e ) will "look like H d (e ) except where H d (e ) changes
This interpretation suggests that if w[n] is chosen so that very abruptly. Thus, the choice of window is governed by the desire to have w[n] as short as possible in duration so as to minimize computation in the implementation of the filter while having
j

W (e j )

approximate an impulse; that is, we want W (e ) to be highly concentrated in frequency so that the convolution of Eq. (5) faithfully reproduces the desired frequency response. These are conflicting requirements, as can be seen in the case of the rectangular window of Eq. (4), where

W (e j ) = hd e j n =
n =0

1 e j ( M +1) sin( ( M + 1) / 2) = e j M / 2 j 1 e sin( / 2)


j

(6)

The magnitude of W (e ) is plotted in Fig. 8 for the case M = 7. Note that W (e ) for the rectangular window has generalized linear phase. As M increases, the width of the "main lobe" decreases. The main lobe is usually defined as the region between the first zero crossings on either side of the origin. For the rectangular window, the mainlobe width is

m =

4 . However, for the rectangular M +1

window, the sidelobes are significantly large andin fact, as M increases, the peak amplitudes of the mainlobe and the sidelobes grow in a manner such that the area under each lobe is a constant while the width of each lobe decreases with M. Consequently, as

W (e j ( ) ) "slides by" a discontinuity of H d (e j ) with increasing , the integral of W (e j ( ) ) Hd (e j ) will oscillate as each sidelobe of

W (e j ( ) ) moves past the discontinuity. This result is depicted in Fig.7(b). Since the area under each
lobe remains constant with increasing M, the oscillations occur more rapidly but do not decrease in amplitude as M increases. In the theory of Fourier series, it is well known that this nonuniform convergence, the Gibbs phenomenon, can be moderated through the use of a less abrupt truncation of the Fourier series by tapering the window smoothly to zero.

Figure 7 (a) Convolution process implied by truncation of the ideal impulse response. (b) Typical approximation resulting from windowing the ideal impulse response. - 7ECED4502 Lab5

Figure 8 Magnitude of the Fourier transform of a rectangular window (M = 7).

Design Example
The desired frequency response is defined as

Hlp (e ) = {
j

e j M / 2 ,L | || c | 0,K | c |<| || |

(86)

where the generalized linear phase factor has been incorporated into the definition of the ideal lowpass filter. The corresponding ideal impulse response is

1 sin( c ( n M / 2)) hlp [n ] = e j M / 2 e j n d = 2 (n M / 2)

(87)

- 8ECED4502 Lab5

for

< n < + . It is easily shown that hlp [ M n] = hlp [ n] , so sin( c ( n M / 2)) w[ n] ( n M / 2)

if we use a symmetric window in the equation

h[n ] =

(88)

then a linear phase system will result. The upper part of Fig. 31 depicts the character of the amplitude response that would result for the typical windows used in your design. Figure 31 displays the important properties of window method approximations to desired frequency responses that have step discontinuities. It applies accurately when c is not close to zero or to and when the width of the mainlobe is smaller than 2 c . At the bottom of the figure is a typical Fourier transform for a symmetric window. This function should be visualized in different positions as an aid in understanding the shape of the approximation

H (e j ) in the vicinity of

c .

Figure 31 Illustration of type of approximation obtained at a discontinuity of the ideal frequency response.

- 9ECED4502 Lab5

You might also like