| Filter Design Toolbox | ![]() |
adaptfilt.ss Example--Noise Cancellation
One 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 adaptfilt.sd Example--Noise Cancellation.
The sign-sign algorithm (SSLMS) replaces the mean square error calculation to 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
,
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. µ(mu) is the step size. As you specify mu smaller, the correction to the filter weights gets smaller for each sample and the SSLMS error falls more slowly. Larger mu changes the weights more for each step so the error falls more rapidly, but the resulting error does not approach the ideal solution as closely. To ensure good convergence rate and stability, select mu within the following practical bounds
where N is the number of samples in the signal. Also, define mu as a power of two for efficient computation.
In this noise cancellation example, adaptfilt.ss requires two input data sets:
For the signal, use a sine wave. Note that signal is a column vector of 1000 elements.
Now, add correlated white noise to signal. To ensure that the noise is correlated, pass the noise through a lowpass FIR filter, then add the filtered noise to the signal.
noise=randn(1,1000); nfilt=fir1(11,0.4); % Eleventh order lowpass filter fnoise=filter(nfilt,1,noise); % Correlated noise data d=signal.'+fnoise;
fnoise is the correlated noise and d is now the desired input to the sign-data algorithm.
To prepare the adaptfilt object for processing, set the input conditions coeffs and mu for the object. As noted earlier in this section, the values you set for coeffs and mu determine whether the adaptive filter can remove the noise from the signal path. In adaptfilt.lms Example--System Identification, you constructed a default filter that sets the filter coefficients to zeros. Except in rare cases, that approach does not work for the sign-sign 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, we start with the coefficients in the filter we used to filter the noise (nfilt), and modify them slightly so the algorithm has to adapt.
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 adaptfilt.ss prepared, run the adaptation and view the results.
ha = adaptfilt.ss(12,mu) set(ha,'coefficients',coeffs); set(ha,'resetbeforefiltering','off'); % Prevent filter reset. [y,e] = filter(ha,noise,d); plot(0:199,signal(1:200),0:199,e(1:200));
Notice that you have to set the property ResetBeforeFiltering to off when you manually change the settings of object ha. If ResetBeforeFiltering is left to on, the default, when you try to apply ha with the method filter, the filtering process starts by resetting the object properties to their initial conditions at construction. To preserve the customized coefficients in this example, we set ResetBeforeFiltering to off so the coefficients do not get reset automatically back to zero.
When adaptfilt.ss runs, it uses far fewer multiply operations than either of the LMS algorithms. Also, performing the sign-sign adaptation requires only bit shifting multiplys when the step size is a power of two. 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 coeffs, mu, or even the lowpass filter you used to create the correlated noise can cause noise cancellation to fail and the algorithm to become useless.
As an aside, the sign-sign LMS algorithm is part of the international CCITT standard for 32 Kb/s ADPCM telephony.
| adaptfilt.se Example--Noise Cancellation | Example of Adaptive Filter That Uses RLS Algorithm | ![]() |
Learn more about the latest releases of MathWorks products: |
| © 1994-2009 The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |