Sei sulla pagina 1di 3

Adaptive Filters Laboratory

Introduction
This lab covers adaptive filters for system identification. In this case the FIR filter coefficients are modified to learn the output of an IIR bandpass filter. The system will be designed in Matlab and implemented on the C3x board.

Equipment Needed:
PC with Matlab and Signal Processing Toolbox Microphone and speakers Portable CD player Texas Instruments C30 EVM boards Signal Generator Oscilloscope

Theory
The basic theory for adaptive filters is described in the lab theory handout. In system identification, the behavior of an unknown system is modeled by accessing its input and output. An adaptive FIR filter can be used to adapt to the output of the system based on the same input. The difference in the output of the system d(n) and the output of the adaptive filter, y(n), is the error term e(n). The error term is used to update the coefficients of the FIR filter using the LMS algorithm described in the filter theory handout.

x(n)

Adaptive Filter
N 1 i =0

y(n)

hi x(n i 1)

Unknown System (in this case IIR filter) d(n)

e(n)

The equation for updating the filter parameters in the LMS algorithm is: hk (n) = hk (n 1) + * e(n) x(n k ) The basic algorithm takes the form:

1. Read in the next sample, x(n), and perform the filtering operation with the previous version of the N 1 coefficients. y (n ) = hn (k )x(n k ) k =0 2. Take the computed output and compare it with the expected output. e(n ) = d (n ) y (n ) 3. Update the coefficients using the following computation.

hk (n) = hk (n 1) + * e(n) x(n k )

The output y(n) approaches d(n) if the learning coefficient is small. The learning coefficient indicates the step size for the gradient descent method. A small step size will ensure convergence, but it means that the filter coefficients change very slowly (a slow adaptation rate). A large step size, may lead to skipping over the solution. In this case we will use = 1 x 10-3.

Part 1: Unknown System Implementation


1. Design the IIR filter: A seventh order bandpass IIR filter will act as the unknown system. Using a sampling frequency of 4 kHz, the specifications of the bandpass filter are that the filter has a passband from /3 to 2/3 (radians), with a stopband attenuation of 20 dB. Use the yulewalk.m function in Matlab to design this filter. Plot the spectrum of this filter. >order = 7; >f = [0 0.32, 1/3, 2/3, 0.67, 1]; >m = [0 0 1 1 0 0]; >[num,den]=yulewalk(order,f,m); The vector, f, defines the edges of the stopbands and passbands in frequency. It is normalized so that 1 is equal to fs/2 (= ). The vector, m, defines the desired level of the output in each band. 0 means stopband, 1 means a passband. 2. Implement this IIR filter on the C30 board using the IIR code from the last lab. Verify the functioning of this filter by inputting three sinusoidal signals at 300, 1000, and 1500 Hertz using the signal generator. Write down the attenuation for each signal using the oscilloscope. Does the filter meet the specifications?

Part 2: Adaptive Filter Implementation in Matlab


1. We will use a 32-coefficient FIR filter to adapt to the output of the IIR filter. We will first implement the filter in Matlab, then, time permitting, on the DSP board. The first step is to build a short subroutine that updates the coefficients using the LMS algorithm. Design a subroutine that implements the three steps of the LMS algorithm given above. The calling parameters should have this form:
function [h,e,err_sq] = lms(input, desired, N, beta, h) % LMS adaptive filter % input : input signal vector (Nx1 column vector) % desired : desired output signal (single element)

% % % % % %

N : no. of taps h : filter coefficients vector (Nx1 column vector) beta : learning constant e: error of adaptive filter err_sq : squared estimation error

The error terms will help us evaluate the filter performance later. 2. Check your code. Insert your filter design code and your LMS code into the lmsfilter.m file at the marked spots. Note that this filter begins estimating at the Nth input. This is because the FIR filter must have full inputs. Otherwise, it will try to learn the transient response of a filter. Compare the spectrum of your learned filter with the original filter (figures 1 and 3). Comment on any differences and similarities. 3. Adaptive filters can only learn what they are taught. What this means, if you only give them input at certain frequencies, then they will only learn the filter response at those frequencies. We will test this phenomenon by deleting the noise term in the line:
x = sin(2*pi*f1*t)+sin(2*pi*f2*t)+sin(2*pi*f3*t);%+ 0.5*randn(size(t));

Now the filter will only learn the response of the filter at f1,f2 and f3. Run this program and look at the results. Try changing the frequencies and look at your results, describe what you see.

Part 3: Adaptive Filter Implementation on C30 board


Note: This section will use code from both the IIR and FIR filter labs. We will adapt the convol.asm code to perform the adaptive filtering operation. The filtering rate will be 2KHz. Be sure that you set the constants in EVMinit properly. 1. We will use the routine convol.asm to compute the output of the adaptive filter. Look at the filtering routines for the FIR filtering lab, insert the external calls to call an assembly language subroutine. Initialize the filter tap weights to zero. 2. Calculate the error between d(t), the output of the IIR filter, and y(t), the output of the FIR filter. 3. Write a C code loop to update hr, the filter coefficients, using the LMS algorithm. 4. Using a signal that covers a wide frequency band see if you can train the filter to learn the unknown channel. Output your coefficients using the printf command. (Be sure to include the stdio.h command in your code to enable the standard I/O functions.) Use matlab to plot the frequency response of the filter.

Potrebbero piacerti anche