LMS Adaptive FiltersLMS Filter Introductory ExamplesThis section provides introductory examples using some of the least mean squares (LMS) adaptive filter functionality in the toolbox. The toolbox provides
To demonstrate the differences and similarities among the various
LMS algorithms supplied in the toolbox, the LMS and NLMS adaptive
filter examples use the same filter for the unknown system. The unknown
filter is the constrained lowpass filter from [b,err,res]=fircband(12,[0 0.4 0.5 1], [1 1 0 0], [1 0.2],...
{'w' 'c'});
fvtool(b,1); From the figure you see that the filter is indeed lowpass and constrained to 0.2 ripple in the stopband. With this as the baseline, the adaptive LMS filter examples use the adaptive LMS algorithms to identify this filter in a system identification role. To review the general model for system ID mode, look at System Identification for the layout. For the sign variations of the LMS algorithm, the examples use noise cancellation as the demonstration application, as opposed to the system identification application used in the LMS examples. System Identification Using the LMS AlgorithmTo use the adaptive filter functions in the toolbox you need to provide three things:
Start by defining an input signal x = 0.1*randn(250,1); The input is broadband noise. For the unknown system filter,
use [b,err,res] = fircband(12,[0 0.4 0.5 1],[1 1 0 0],[1 0.2],{'w','c'});
Although you do not need them here, include the Now filter the signal through the unknown system to get the desired signal. d = filter(b,1,x); With the unknown filter designed and the desired signal in place you construct and apply the adaptive LMS filter object to identify the unknown. Preparing the adaptive filter object requires that you provide
starting values for estimates of the filter coefficients and the LMS
step size. You could start with estimated coefficients of some set
of nonzero values; this example uses zeros for the 12 initial filter
weights. Set the For the step size, 0.8 is a reasonable value — a good compromise between being large enough to converge well within the 250 iterations (250 input sample points) and small enough to create an accurate estimate of the unknown filter. mu = 0.8;
lms = dsp.LMSFilter(13,'StepSize',mu,'WeightsOutputPort',true);
Finally, using the [y,e,w] = lms(x,d); stem([b.' w]) title('System Identification by Adaptive LMS Algorithm') legend('Actual Filter Weights','Estimated Filter Weights',... 'Location','NorthEast') As an experiment, try changing the step size to 0.2. Repeating
the example with mu = 0.2;
lms = dsp.LMSFilter(13,'StepSize',mu,'WeightsOutputPort',true);
[y,e,w] = lms(x,d);
stem([b.' w])
title('System Identification by Adaptive LMS Algorithm')
legend('Actual Filter Weights','Estimated Filter Weights',...
'Location','NorthEast') Since this may be because you did not iterate over the LMS algorithm enough times, try using 1000 samples. With 1000 samples, the stem plot, shown in the next figure, looks much better, albeit at the expense of much more computation. Clearly you should take care to select the step size with both the computation required and the fidelity of the estimated filter in mind. for index = 1:4 x = 0.1*randn(250,1); d = filter(b,1,x); [y,e,w] = lms(x,d); end stem([b.' w]) title('System Identification by Adaptive LMS Algorithm') legend('Actual Filter Weights','Estimated Filter Weights',... 'Location','NorthEast') System Identification Using the Normalized LMS AlgorithmTo improve the convergence performance of the LMS algorithm, the normalized variant (NLMS) uses an adaptive step size based on the signal power. As the input signal power changes, the algorithm calculates the input power and adjusts the step size to maintain an appropriate value. Thus the step size changes with time. As a result, the normalized algorithm converges more quickly with fewer samples in many cases. For input signals that change slowly over time, the normalized LMS can represent a more efficient LMS approach. In the normalized LMS algorithm example, you used First, generate the input signal and the unknown filter. x = 0.1*randn(500,1);
[b,err,res] = fircband(12,[0 0.4 0.5 1], [1 1 0 0], [1 0.2],...
{'w' 'c'});
d = filter(b,1,x); Again lms = dsp.LMSFilter(13,'StepSize',mu,'Method',... 'Normalized LMS','WeightsOutputPort',true); You use the preceding code to initialize the normalized LMS
algorithm. For more information about the optional input arguments,
refer to Running the system identification process is a matter of using
the [y,e,w] = lms(x,d);
stem([b.' w])
title('System Identification by Normalized LMS Algorithm')
legend('Actual Filter Weights','Estimated Filter Weights',...
'Location','NorthEast')
As shown in the following stem plot (a convenient way to compare the estimated and actual filter coefficients), the two are nearly identical. If you compare the convergence performance of the regular LMS algorithm to the normalized LMS variant, you see the normalized version adapts in far fewer iterations to a result almost as good as the nonnormalized version. lms_normalized = dsp.LMSFilter(13,'StepSize',mu,... 'Method','Normalized LMS','WeightsOutputPort',true); lms_nonnormalized = dsp.LMSFilter(13,'StepSize',mu,... 'Method','LMS','WeightsOutputPort',true); [~,e1,~] = lms_normalized(x,d); [~,e2,~] = lms_nonnormalized(x,d); plot([e1,e2]); title('Comparing the LMS and NLMS Conversion Performance'); legend('NLMS Derived Filter Weights', ... 'LMS Derived Filter Weights','Location', 'NorthEast'); Noise Cancellation Using the Sign-Data LMS AlgorithmWhen the amount of computation required to derive an adaptive filter drives your development process, the sign-data variant of the LMS (SDLMS) algorithm may be a very good choice as demonstrated in this example. Fortunately, the current state of digital signal processor (DSP) design has relaxed the need to minimize the operations count by making DSPs whose multiply and shift operations are as fast as add operations. Thus some of the impetus for the sign-data algorithm (and the sign-error and sign-sign variations) has been lost to DSP technology improvements. In the standard and normalized variations of the LMS adaptive filter, coefficients for the adapting filter arise from the mean square error between the desired signal and the output signal from the unknown system. Using the sign-data algorithm changes the mean square error calculation by using the sign of the input data to change the filter coefficients. When the error is positive, the new coefficients are the previous coefficients plus the error multiplied by the step size µ. If the error is negative, the new coefficients are again the previous coefficients minus the error multiplied by µ — note the sign change. When the input is zero, the new coefficients are the same as the previous set. In vector form, the sign-data LMS algorithm is w(k 1)=w(k) μe(k)sgn[x(k)],sgn[x(k)]=1,x(k)>00,x(k)=0−1,x(k)<0 with vector w containing the
weights applied to the filter coefficients and vector x containing the input data. e(k) (equal
to desired signal - filtered signal) is the error at time k and
is the quantity the SDLMS algorithm seeks to minimize. µ ( As you specify 0<μ<1N{InputSignalPower} where N is the number of samples in the signal.
Also, define NoteHow you set the initial conditions of the sign-data algorithm profoundly influences the effectiveness of the adaptation. Because the algorithm essentially quantizes the input signal, the algorithm can become unstable easily. A series of large input values, coupled with the quantization process may result in the error growing beyond all bounds. You restrain the tendency of the sign-data algorithm to get out of control by choosing a small step size (µ<< 1) and setting the initial conditions for the algorithm to nonzero positive and negative values. In this noise cancellation example, set
For the signal, use a sine wave. Note that signal = sin(2*pi*0.055*[0:1000-1]'); Now, add correlated white noise to noise = randn(1000,1); nfilt = fir1(11,0.4); % Eleventh order lowpass filter fnoise = filter(nfilt,1,noise); % Correlated noise data d = signal fnoise;
To prepare the In System Identification Using the LMS Algorithm, you constructed a default filter that sets the filter coefficients to zeros. In most cases that approach does not work for the sign-data algorithm. The closer you set your initial filter coefficients to the expected values, the more likely it is that the algorithm remains well behaved and converges to a filter solution that removes the noise effectively. For this example, start with the coefficients in the filter
you used to filter the noise ( coeffs = nfilt.' -0.01; % Set the filter initial conditions.
mu = 0.05; % Set the step size for algorithm updating. With the required input arguments for lms = dsp.LMSFilter(12,'Method','Sign-Data LMS',... 'StepSize',mu,'InitialConditions',coeffs); [~,e] = lms(noise,d); L = 200; plot(0:L-1,signal(1:L),0:L-1,e(1:L)); title('Noise Cancellation by the Sign-Data Algorithm'); legend('Actual Signal','Result of Noise Cancellation',... 'Location','NorthEast'); When Although the performance of the sign-data algorithm as shown in the next figure is quite good, the sign-data algorithm is much less stable than the standard LMS variations. In this noise cancellation example, the signal after processing is a very good match to the input signal, but the algorithm could very easily grow without bound rather than achieve good performance. Changing Noise Cancellation Using Sign-Error LMS AlgorithmIn some cases, the sign-error variant of the LMS algorithm (SELMS) may be a very good choice for an adaptive filter application. In the standard and normalized variations of the LMS adaptive filter, the coefficients for the adapting filter arise from calculating the mean square error between the desired signal and the output signal from the unknown system, and applying the result to the current filter coefficients. Using the sign-error algorithm replaces the mean square error calculation by using the sign of the error to modify the filter coefficients. When the error is positive, the new coefficients are the previous coefficients plus the error multiplied by the step size µ. If the error is negative, the new coefficients are again the previous coefficients minus the error multiplied by µ — note the sign change. When the input is zero, the new coefficients are the same as the previous set. In vector form, the sign-error LMS algorithm is w(k 1)=w(k) μsgn[e(k)][x(k)],sgn[e(k)]=1,e(k)>00,e(k)=0−1,e(k)<0 with vector w containing the
weights applied to the filter coefficients and vector x containing the input data. e(k) (equal
to desired signal - filtered signal) is the error at time k and
is the quantity the SELMS algorithm seeks to minimize. µ ( Larger 0<μ<1N{InputSignalPower} where N is the number of samples in the signal.
Also, define NoteHow you set the initial conditions of the sign-data algorithm profoundly influences the effectiveness of the adaptation. Because the algorithm essentially quantizes the error signal, the algorithm can become unstable easily. A series of large error values, coupled with the quantization process may result in the error growing beyond all bounds. You restrain the tendency of the sign-error algorithm to get out of control by choosing a small step size (µ<< 1) and setting the initial conditions for the algorithm to nonzero positive and negative values. In this noise cancellation example, the
For the signal, use a sine wave. Note that signal = sin(2*pi*0.055*[0:1000-1]'); Now, add correlated white noise to noise = randn(1000,1); nfilt = fir1(11,0.4); % Eleventh order lowpass filter. fnoise = filter(nfilt,1,noise); % Correlated noise data. d = signal fnoise;
To prepare the Setting the coefficients to zero often does not work for the sign-error algorithm. The closer you set your initial filter coefficients to the expected values, the more likely it is that the algorithm remains well behaved and converges to a filter solution that removes the noise effectively. For this example, you start with the coefficients in the filter
you used to filter the noise ( coeffs = nfilt.' -0.01; % Set the filter initial conditions.
mu = 0.05; % Set step size for algorithm update. With the required input arguments for lms = dsp.LMSFilter(12,'Method','Sign-Error LMS',... 'StepSize',mu,'InitialConditions',coeffs); [~,e] = lms(noise,d); L = 200; plot(0:199,signal(1:200),0:199,e(1:200)); title('Noise Cancellation Performance by the Sign-Error LMS Algorithm'); legend('Actual Signal','Error After Noise Reduction',... 'Location','NorthEast') When the sign-error LMS algorithm runs, it uses far fewer multiply operations than either of the LMS algorithms. Also, performing the sign-error adaptation requires only bit shifting multiplies when the step size is a power of two. Although the performance of the sign-data algorithm as shown in the next figure is quite good, the sign-data algorithm is much less stable than the standard LMS variations. In this noise cancellation example, the signal after processing is a very good match to the input signal, but the algorithm could very easily become unstable rather than achieve good performance. Changing the weight initial conditions ( Noise Cancellation Using Sign-Sign LMS AlgorithmOne more example of a variation of the LMS algorithm in the toolbox is the sign-sign variant (SSLMS). The rationale for this version matches those for the sign-data and sign-error algorithms presented in preceding sections. For more details, refer to Noise Cancellation Using the Sign-Data LMS Algorithm. The sign-sign algorithm (SSLMS) replaces the mean square error calculation with using the sign of the input data to change the filter coefficients. When the error is positive, the new coefficients are the previous coefficients plus the error multiplied by the step size µ. If the error is negative, the new coefficients are again the previous coefficients minus the error multiplied by µ — note the sign change. When the input is zero, the new coefficients are the same as the previous set. In essence, the algorithm quantizes both the error and the input by applying the sign operator to them. In vector form, the sign-sign LMS algorithm is w(k 1)=w(k) μsgn[e(k)]sgn[x(k)],sgn[z(k)]=1,z(k)>00,z(k)=0−1,z(k)<0 where z(k)=[e(k)]sgn[x(k)] Vector w contains the weights
applied to the filter coefficients and vector x contains
the input data. e(k) ( = desired signal - filtered signal) is the error at time k and
is the quantity the SSLMS algorithm seeks to minimize. µ( Larger 0<μ<1N{InputSignalPower} where N is the number of samples in the
signal. Also, define NoteHow you set the initial conditions of the sign-sign algorithm profoundly influences the effectiveness of the adaptation. Because the algorithm essentially quantizes the input signal and the error signal, the algorithm can become unstable easily. A series of large error values, coupled with the quantization process may result in the error growing beyond all bounds. You restrain the tendency of the sign-sign algorithm to get out of control by choosing a small step size (µ<< 1) and setting the initial conditions for the algorithm to nonzero positive and negative values. In this noise cancellation example,
For the signal, use a sine wave. Note that signal = sin(2*pi*0.055*[0:1000-1]'); Now, add correlated white noise to noise = randn(1000,1); nfilt = fir1(11,0.4); % Eleventh order lowpass filter fnoise = filter(nfilt,1,noise); % Correlated noise data d = signal fnoise;
To prepare the The closer you set your initial filter coefficients to the expected
values, the more likely it is that the algorithm remains well behaved
and converges to a filter solution that removes the noise effectively.
For this example, you start with the coefficients in the filter you
used to filter the noise ( coeffs = nfilt.' -0.01; % Set the filter initial conditions.
mu = 0.05; % Set the step size for algorithm updating. With the required input arguments for lms = dsp.LMSFilter(12,'Method','Sign-Sign LMS',... 'StepSize',mu,'InitialConditions',coeffs); [~,e] = lms(noise,d); L = 200; plot(0:199,signal(1:200),0:199,e(1:200)); title('Noise Cancellation Performance by the Sign-Error LMS Algorithm'); legend('Actual Signal','Error After Noise Reduction',... 'Location','NorthEast') When Although the performance of the sign-sign algorithm as shown in the next figure is quite good, the sign-sign algorithm is much less stable than the standard LMS variations. In this noise cancellation example, the signal after processing is a very good match to the input signal, but the algorithm could very easily become unstable rather than achieve good performance. Changing the weight initial conditions ( As an aside, the sign-sign LMS algorithm is part of the international CCITT standard for 32 Kb/s ADPCM telephony. References[1] Hayes, Monson H., Statistical Digital Signal Processing and Modeling, John Wiley & Sons, 1996, 493–552. [2] Haykin, Simon, Adaptive Filter Theory, Prentice-Hall, Inc., 1996 |
|