# OpenStax-CNX

You are here: Home » Content » Adaptive FIR Filtering

### Recently Viewed

This feature requires Javascript to be enabled.

Module by: Lee Potter. E-mail the author

Summary: In this laboratory, students implement a real-time adaptive FIR filter, investigate the convergence of the least mean squares (LMS) algorithm, and apply the adaptive filter to the problems of system identification and echo cancellation.

First, use MATLAB to simulate the system identification block diagram in Figure 1. For the simulation, let xn x n be a Gaussian random noise input, which can be generated in MATLAB using the command randn. For the "unknown" system, use a fourth-order, low-pass elliptical IIR filter. Thus, the reference signal can be generated with the following MATLAB commands:


>> x = randn(1000,1);%random input signal
>> [B,A] = ellip(4,0.25,10,0.25);%IIR filter
>> d = filter(B,A,x);%reference signal
>> figure;freqz(B,A)%view frequency response

Simulate the system with an adaptive filter of length 32 (32 taps) and a step-size of 0.02. Initialize all adaptive filter coefficients to zero. Because the adaptive filter coefficients change with time, implement the filter on a sample by sample basis (e.g., using a loop with the for or while commands). Plot the squared-error versus sample number as the filter adapts over time. Also, use freqz to plot the frequency response of the adaptive filter coefficients, W, at the end of the simulation. Finally, use figure;stem(W) and figure;stem(dimpulse(B,A,32)) to view and compare the adaptive FIR impulse response and the IIR impulse reponse.

How well does the adaptive FIR filter at convergence approximate the fourth-order IIR system? How long does the adaptive FIR filter take to converge?

Second, write pseduo code for an assembly program to implement an adaptive FIR filter. Your code can be modified from the FIR filtering laboratory exercise. The foundation for your modification is the LMS filter coefficient update equation

Wn+1=Wn+μenXn W n 1 W n μ e n X n
(1)
where Wn W n is the vector of 32 FIR filter coefficients at time nn, en=dnyn e n d n y n is the error between the reference and output, μμ is the step size, and Xn X n is the length 32 vector of current and past input samples. (Note the upper-case X is used to denote the state vector that stores the current and past 31 input samples.) Observe that the update is implemented by multiply and accumulate operations applied to the buffer of filter coefficients. Consider the following five suggestions for implementing the processing shown in Figure 1.
1. The filter coefficients should be initialized to zero at the start of program execution.
2. The left input channel is the input xn x n to the adaptive filter.
3. The right input channel is the reference input signal dn d n .
4. The left channel output is the adaptive filter output yn y n .
5. The right channel output is the error signal en e n .
The following opcodes may be useful: SUB, MPY, MAC, BCC.

## Lab Exercise: Adaptive Filtering for System Identification

One application of adaptive filters is adaptive modeling or system identification. Figure 2 depicts the system modeling problem. The output of an unknown system to a known input is used as the reference input to an adaptive filter. The known input signal is fed through the adaptive filter in an effort to duplicate the unknown system output. Upon convergence, the adaptive filter parameters represent an estimate of the unknown system.

### System ID

Test your adaptive filter program by applying it to the identification of a known system. Use a filter box as your "unknown" system. Use a random noise generator as your "known" input signal. Run your adaptive filter program using only 10 filter taps and stop the program after the filter has converged. Enter the estimated filter coefficients into MATLAB and plot the magnitude response to verify that the adaptive filter has approximated the system.

## Lab Exercise: Adaptive Interference Cancellation

Adaptive filters are used in modern telephony to perform echo suppression. A small amount of speech from talker A, transmitted to talker B, is unavoidably "echoed" back to talker A with talker B's speech.

### Echo Cancellation

With this application in mind, a stereo speech recording has been made. On one channel, talker A is speaking. On the other channel, speech from talker B is present, along with a delayed "echo" of talker A's speech. Use your adaptive filter to suppress the "echo" from the speech of talker B. Can you estimate the delay of the "echo"? Does the step size, μμ, or number of filter taps, NN, have any effect on your results?

Report the estimated filter coefficients. Describe the echo in specific terms (seconds delay, frequency response, etc.). Qualitatively report on the effects observed by changing the step size or the number of filter taps.

## Content actions

### Give feedback:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks