Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
112 views6 pages

Lab5 PDF

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 6

LAB 5 DIGITAL FILTERING

5.1. LAB OBJECTIVE The purpose of this lab is to design and implement digital filters. You will design and implement a first order IIR (Infinite Impulse Response) filter and a second order IIR filter. Both filters are low pass filters. You will learn how to determine the analytical frequency response of each filter. During the lab session, you will measure the frequency response of the filters and compare the results with the analytical solution. You will also learn about another type of filter called the FIR (Finite Impulse Response) filter. An important application of a digital filter is to eliminate noise from a sensor, such as a strain gauge, tachometer etc.

5.2. BACKGROUND 5.2.1. Introduction to Digital Filtering The two types of filters discussed in this lab are: Infinite Impulse Response (IIR) filter Finite Impulse Response (FIR) filter Detailed information on these filters will be given in lecture. However, a short summary of each filter is given below. 5.2.2. IIR Filters The recursive equation for a first order IIR filter is Y(n) = A*y(n-1) + B*x(n) Where, X(n) is the input sequence. Y(n) is the output sequence. A & B are constants to be determined during filter design. The frequency response of the filter depends on the values of constants A and B. In the lecture, you will learn how to select A and B to achieve the desired frequency response.

29

5.2.3. FIR Filters The recursive equation for a first order finite response filter is Y(n) = C*x(n) + D*x(n-1) Similarly, the frequency response of the FIR filter depends on C and D which you will learn how to choose in lecture. 5.2.4. Double Filtering One method for obtaining a second order filter is double filtering. Two cascaded first order filters are equivalent to a second order filter. If the two first order filters are identical, the transfer function of the second order filter is the square of the first order transfer function. The double filtering procedure can be performed in two steps: 1) The input sequence x(n) is filtered with a first order filter, and an output sequence y(n) is obtained. y(n) = A*y(n-1) + B*x(n) 2) y(n) is filtered with the same first order filter to obtain the output z(n). z(n) is the output of a second order filter. z(n) = A*z(n-1) + B*y(n) A detailed procedure for finding the filter coefficients for double filtering will be given in lecture.

5.3. PRELAB Prelabs will be checked at the beginning of class. 1. Design a first order IIR filter with a cutoff frequency of 20Hz. Determine the filter coefficients A and B for this frequency response. Assume a sampling frequency of 750 Hz. 2. Write a C program that implements this filter. The best way to write this program is to start with the sine_io.c program available on the course website. Only a few lines of code need to be altered to create the filtering program. 3. Design a second order IIR filter with a cutoff frequency of 20 Hz. Determine the filter coefficients A and B for this frequency response. Assume a sampling frequency of 750 Hz. 4. Write a C Program that implements this filter. 5. Determine the analytical frequency response of the filters by completing the following
30

table. Do not convert the magnitude to decibels. Plot the analytical frequency response using graph paper or a computer-plotting package. Analytical Frequency Response: FREQUENCY (Hz.) MAGNITUDE (first order filter) 5 10 15 20 25 30 40 50 60 70 80 90 100 125 150 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ . . . . . . . . . . . . . . . MAGNITUDE (second order filter) ______________ ______________ ______________ ______________ ______________ ______________ ______________ ______________ ______________ ______________ ______________ ______________ ______________ ______________ ______________

6. Write a C-program that reads in a 20Hz sine wave with an amplitude of 1V (rms) through ADC0 channel and writes out its derivative at DAC0 channel. Use a sampling frequency of 750 Hz. Again, start with sine_io.c for creating this program.

31

5.4. LAB PROCEDURE This laboratory assignment involves measuring the actual frequency response of a first order filter and comparing the results to the analytical frequency response that you determined in the prelab. Create your first order IIR lowpass filter program using the editor. Compile and build the program. 1. Use the function generator to output a 5 Hz sine wave with a magnitude of 1V rms (2.828 volts peak to peak). 2. Connect the function generator and channel 1 of the oscilloscope to the ADC0 channel. 3. Connect channel 2 of the oscilloscope and the multimeter to the DAC0 channel. 4. Write down the amplitude of the filtered signal by reading the multimeter. 5. Repeat the above steps for all the frequencies listed in the table in the prelab. Use the same procedure to experimentally determine the frequency response of the second order filter. For each frequency in the following table, measure the output voltage using the multimeter. Record the result in the table. Observe the input and output signals on the oscilloscope. Experimental frequency response: FREQUENCY (Hz.) MAGNITUDE (first order filter) 5 10 15 20 25 30 40 50 . . . . . . . . . . . . . . . . . . . . . . . . ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________
32

MAGNITUDE (second order filter) . . . . . . . . ______________ ______________ ______________ ______________ ______________ ______________ ______________ ______________

60 70 80 90 100 125 150

. . . . . . .

. . . . . . .

. . . . . . .

____________ ____________ ____________ ____________ ____________ ____________ ____________

. . . . . . .

______________ ______________ ______________ ______________ ______________ ______________ ______________

5.5. POSTLAB AND LAB REPORT 1. Determine the analytical frequency response of the FIR filters given below by completing the table. Do not convert the magnitude to decibels. Assume a sampling frequency of 30000 Hz. Plot the analytical frequency response for each filter using graph paper or a computer plotting package. FILTER A: FILTER B: FREQUENCY (kHz.) y(n) = 0.5*x(n) + 0.5*x(n-1) y(n) = 0.9*x(n) + 0.1*x(n-1) FILTER A. MAGNITUDE: . . . . . . . . . . . . . . ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ ____________ . . . . . . . . . . . . . . FILTER B. MAGNITUDE ______________ ______________ ______________ ______________ ______________ ______________ ______________ ______________ ______________ ______________ ______________ ______________ ______________ ______________

0.01 1 2 3 4 5 6 7 8 9 10 11 12 14

2. What are the cutoff frequencies of the FIR filters A and B in Question 1?
33

3. Is it possible to design a first order lowpass FIR filter with a cutoff frequency of 250 Hz.? Why or why not? Use a sampling frequency of 29940 Hz. 4. Compare the analytical and experimental frequency responses for the IIR filters that you designed. Explain the similarity and/or discrepancy. 5. When you calculated the derivative of a sine wave, did you get a perfect cosine wave (i.e. did you get a perfect phase shift of 90o)? Were there any problems due to noise? Explain. 6. Show that the circuit shown below acts as a high-pass filter in which low frequencies are attenuated and high frequencies are passed. Vo

Vi

(Hint: First find the transfer function Vo(s)/Vi(s) of the circuit. To find the frequency response, substitute s = j in the transfer function and find the magnitude for <<(1/RC) and for >>(1/RC)). Lab Report Requirements Solutions to questions one through six. Hardcopy of the C Programs for the first and second order filters. Analytical and experimental frequency response for the first and second order IIR filters. Plot analytical and experimental frequency response for each filter on one graph. Use whatever plotting package you want.

34

You might also like