Products & Services Solutions Academia Support User Community Company

Example: The LMS Filter

Description

A least mean squares (LMS) filter is an adaptive filter that adjusts its transfer function according to an optimizing algorithm. You provide the filter with an example of the desired output together with the input signal. The filter then calculates the filter weights, or coefficients, that produce the least mean squares of the error between the output signal and the desired signal.

The example for this tutorial uses a LMS filter to remove the noise in a music recording. This example uses two inputs. The first input is the distorted signal: the music recording plus noise. The second input is the noise. The filter works to eliminate the difference between these two signals and outputs the difference, which, in this case, is the clean music recording. When you start the simulation, you hear both noise and the music. Over time, the adaptive filter filters out the noise so you hear only the music.

Algorithm

This tutorial uses the least mean squares (LMS) algorithm to remove noise from an input signal. The LMS algorithm computes the filtered output, filter error, and filter weights given the distorted and desired signals.

The LMS algorithm at the start of the tutorial uses a batch process to filter the audio input. This algorithm is suitable for MATLAB, where you are likely to load in the entire signal and process it all at once. However, a batch process is not suitable for processing a signal in real time. As you work through the tutorial, you refine the design of the filter to convert the algorithm from batch-based to stream-based processing.

The function signature for the algorithm is:

function [ signal_out, err, weights ] = lms(distorted, desired )

The filtering is performed in the following loop:

for n = 1:N
	signal_out(n) = weights' * distorted(n:n+L-1);
	err(n) = desired(n) - signal_out(n) ;
	weights = weights + mu*err(n)*distorted(n:n+L-1);
end

where N is the length of the input signal, L is the filter length, and mu is the adaptation step size.

 What is the adaptation step size?

The Filtering Process

The filtering process has three phases:

Reference

Haykin, Simon, Adaptive Filter Theory, Prentice-Hall, Inc., 1996

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS