S522, Kewley-Port
Spring, 2008

Understanding Filtering (Assignment #9)
(15 points)

Assignment from Chap 7 and 8, Week 9, due 3/19/06

Write a computer program (in your language of choice), or a MatLab function, to implement a filter from the general linear difference equation. The program, myfilter, should consist of two parts, one for the FIR, non-recursive (b coefficients) terms, and the other for the recursive section (a coefficients).

You may program in any language. If you choose Matlab (most of you will), I recommend that you try to do the program not to use functions filter or conv, so that you actually calculate the filtering equations with for loops and indexed values of the arrays. For example, here's a simple calculation:

FOR I = 1:N,
FOR J = 1:N,
A(I,J) = 1/(I+J-1);
END
END

However, for students with poorer programming background, you may use conv or filter and write the program as a Matlab function as described below. Start with the FIR part, and them add the IIR part.

In Matlab, the myfilter.m should have the following format:

function yout = myfilter (bb, aa, xx)
%Function to implement a general difference function of the form
% y[n] = aa(1)*y[n-1] + ....... + bb(M)*x[n-M]
%where yout is the filtered output sequence, y[n]
%bb are the FIR, non-recursive coefficients
%aa are the recursive coefficients
%xx is the input sequence, x[n]

To verify that the program works, calculate, print and plot the output sequence y[n] for each of the two filters below.

Use the following input sequence for both filters for n = 1,...,40 :

x[n] = 1 for n = 5
x[n]= 0 otherwise (n in {1,4} and n in{6,40})

1) FIR filter: y[n] = x[n] + 2x[n-1] + 3x[n-2]

2) IIR, recursive filter: y[n] = -0.95y[n-1] +x [n]

Turn in your program code and the following plots separately for each of the two filters (you may use Matlab or hand plots):

1. the filter structure using block diagrams
2. the unit sample response
3. the pole-zero plots
4. the magnitude spectrum of the transfer function
5. stem plots of the output

{Updated on 3/2/08}