Adaptive Lab Matlab Part3
Adaptive Lab Matlab Part3
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)
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.
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.
% % % % % %
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.