You are on page 1of 3

# EE 341

Lab 5

## Lab 5: The FFT and Digital Filtering

Students are divided into group of two persons to do this lab assignment. You will be using Signal Processing Tool (sptool) for this assignment so there are no Matlab files to turn in for this lab. The lab report is still required. Please esubmit the lab report file via TA email address by the due day. Thank you.

1. Goals
The goal of this lab is to help students become familiar with using the FFT to study the frequency content of a discrete-time signal. This lab is also to play with Signal Processing Tool to create some digital filters, then evaluate their behavior.

2. Lab resource
- PC with Matlab - Matlab file: frevalz.m

3. Assignments
3.1. Matlab function fft (25%) In this problem you will learn how to use the MATLAB command fft which computes the Discrete Fourier Transform (DFT) of a sequence. First, use the help feature in MATLAB to learn the syntax of the fft command. In general the FFT of a sequence will be a complex function, so you will need to look at the magnitude and phase separately. The MATLAB commands abs and angle are useful for obtaining the magnitude and phase of a complex valued sequence. Also, since the FFT only has values at discrete frequencies, it may be useful to do the plots with stem to reinforce that idea, but continuous frequency plots (i.e. using plot) are often used since they are closer to the DTFT that you are ultimately interested in. The FFT outputs a sequence that corresponds to the range 0 2 . You are probably more familiar with seeing the spectrum plotted over the range < . The fftshift function can be used for this purpose.
Plot the magnitude of the FFT of the following signal before and after the fftshift

x[n ] = 1 + cos(2 fn ); 0 n 127 for the cases where f = 0.25 and f = 0.5 . Use your understanding of the relation between discrete and continuous time to plot the magnitude of the Fourier Transform of the continuous time signal that these correspond to, assuming that the sampling period is T = 104 . Be sure to label the frequency axis correctly and indicate whether you are plotting in radians or Hertz or normalized frequency. Turn in a 3-part plot for each signal: unshifted DFT, shifted DFT, and the shifted DFT with a Hz frequency scale. Discuss why the frequency peak locations make sense.

## 3.2. Frequency Shifting (25%)

For each of the following sequences, let f1 = 0.15 and 0 n 255 . Use the built-in sinc function in MATLAB.

EE 341

Lab 5

Plot the magnitude and phase plots (using plot), where the magnitude and phase plots are over the range 0.5 < 0.5 (normalized frequency, i.e. use fftshift). a) x1[n ] = sinc( f1 ( n 32)) . b) x2 [n ] = sinc( f1 ( n 32))( 1) n .
c) x3[n ] = sinc( f1 ( n 32)) cos(2 f 2 n ) where f 2 = 0.2 . d) x4 [n ] = sinc( f 3 ( n 32)) cos(2 f 3n ) where f 3 = 0.4 . What type of signals are these (low pass, high pass, etc.)? Turn in the plots only for (d). Explain why (d) does not have a flat frequency response in the passband.

## 3.3. FIR (Finite Impulse Response) Digital Filters (25%)

In this problem, you will use frevalz.m to look at the behavior of system functions in the z-plane. The system functions you will examine will be various digital filters that you use MATLAB to design. MATLAB has numerous built-in functions for generating discrete time filters. We are going to use a few to look at how higher order systems behave in the z-plane. This will give you some insight into how digital filters are designed and into the properties of different digital filter design algorithms. You will not be expected to understand the details of how these algorithms work; you only need to evaluate their behavior. Both the filter design programs in the problems below ask you to specify cut-offs W in terms of a normalized frequency 0 < W < 1 , where W = 1 corresponds to half the sampling frequency. That is, 0 < W < 1 corresponds to 0 < < in radians for the DTFT, and 0 < f < 0.5 in normalized frequency as plotted by frevalz. Thus, a cut-off frequency of W = 0.5 corresponds to c = / 2 in radians and f c = 0.25 in normalized frequency on the frevalz frequency response. Use the MATLAB function sptool to create a low pass FIR filter of order 10 (by playing around the passband and stopband ripples specifications) with passband cutoff frequency of 0.3 and stopband cutoff frequency of 0.4. Use frevalz to study the system. Turn in the frevalz plot of the system responses. Use the MATLAB function filter to implement the FIR low pass filter youve just produced. Let the input to the filters be a pulse of length twenty: x[n] = u[n] u[n-20] but let x[n] be of total length 60 (so append 40 zeros on the end).

## 3.4. IIR (Infinite Impulse Response) Digital Filters (25%)

Use the MATLAB function butter to create a digital IIR low pass Butterworth filter with the same passband and stopband cut-off frequency specifications as the FIR design in Question 3 and filter order of 10. How does the performance of this filter compare to that of the FIR filter? In this context, performance refers to how close a filter matches an ideal low pass filter. Comment on any differences in the phase of the two filters. Turn in the frevalz plot of the system responses.

EE 341

Lab 5

Use the MATLAB function filter to implement the IIR low pass filter youve just produced with the same input in problem 3. Comment on the differences in the output of the two filters. Hand in a plot of the time signal input together with the outputs of both filters.

GOOD LUCK!!!