Main Content

Noise Cancellation in金宝appUsing Normalized LMS Adaptive Filter

Create an Acoustic Environment in金宝app

Adaptive filters are filters whose coefficients or weights change over time to adapt to the statistics of a signal. They are used in a variety of fields including communications, controls, radar, sonar, seismology, and biomedical engineering.

In this topic, you learn how to create an acoustic environment that simulates both white noise and colored noise added to an input signal. You later use this environment to build a model capable of adaptive noise cancellation using adaptive filtering:

  1. At the MATLAB®command line, typedspanc.

    The DSP System Toolbox™ Acoustic Noise Cancellation example opens.

    归一化LMS块有5个输入,输入想要的, step size, adapt, and reset signal inputs. Acoustic environment subsystem block feeds the input and the desired signal. The LMS block generates output, error signal, and the weights. Output signal is connected to a terminator, Error signal to an Audio Device Writer, and the weights are downsampled by 32 and fed into a Waterfall Scope block.

  2. Copy and paste the subsystem called Acoustic Environment into a new model.

  3. Double-click the Acoustic Environment subsystem.

    Gaussian noise is used to create the signal sent to the Exterior Mic output port. If the input to the Filter port changes from 0 to 1, the Digital Filter block changes from a lowpass filter to a bandpass filter. The filtered noise output from the Digital Filter block is added to signal coming from a.wavfile to produce the signal sent to the Pilot's Mic output port.

You have now created an acoustic environment. In the following topics, you use this acoustic environment to produce a model capable of adaptive noise cancellation.

LMS Filter Configuration for Adaptive Noise Cancellation

In the previous topic,Create an Acoustic Environment in Simulink, you created a system that produced two output signals. The signal output at the Exterior Mic port is composed of white noise. The signal output at the Pilot's Mic port is composed of colored noise added to a signal from a.wavfile. In this topic, you create an adaptive filter to remove the noise from the Pilot's Mic signal. This topic assumes that you are working on a Windows®operating system:

  1. If the model you created inCreate an Acoustic Environment in Simulinkis not open on your desktop, you can open an equivalent model by typing

    ex_adapt1_audio

    at the MATLAB command prompt.

  2. From the DSP System Toolbox Filtering library, and then from the Adaptive Filters library, click-and-drag an LMS Filter block into the model that contains the Acoustic Environment subsystem.

  3. Double-click the LMS Filter block. Set the block parameters as follows, and then clickOK:

    • Algorithm=Normalized LMS

    • Filter length=40

    • Step size (mu)=0.002

    • Leakage factor (0 to 1)=1

    The block uses the normalized LMS algorithm to calculate the forty filter coefficients. Setting theLeakage factor (0 to 1)parameter to1means that the current filter coefficient values depend on the filter's initial conditions and all of the previous input values.

  4. Click-and-drag the following blocks into your model.

    Block Library Quantity

    Constant

    金宝app®/Sources

    2

    Manual Switch

    Simulink/Signal Routing

    1

    Terminator

    Simulink/Sinks

    1

    Downsample

    Signal Operations

    1

    Audio Device Writer

    Sinks

    1

    Waterfall Scope

    Sinks

    1

  5. Connect the blocks so that your model resembles the following figure.

    Two constant blocks with a value of 0 and 1, respectively control the manual switch, which controls the Filter input of the Acoustic Environment. The acoustic environment block generates the input and the desired signal which are fed as inputs to the LMS Filter block. The LMS Filter block generates the output signal, error signal, and the weights. Output signal is connected to a terminator, Error signal to an Audio Device Writer, and the weights are downsampled by 32 and fed into a Waterfall Scope block.

  6. Double-click the Constant block. Set theConstant valueparameter to0and then clickOK.

  7. Double-click the Downsample block. Set theDownsample factor, Kparameter to32. ClickOK.

    The filter weights are being updated so often that there is very little change from one update to the next. To see a more noticeable change, you need to downsample the output from the Wts port.

  8. Double-click the Waterfall Scope block. TheWaterfallscope window opens.

  9. Click theScopeparameters button.

    Waterfall scope. The three axes in the waterfall plot are Time (ranging from -5 to 0), Samples (ranging from -1 to 1), and Amplitude (ranging from 0 to 30).

    TheParameterswindow opens.

    In the Display tab of the Waterfall plot, the following Display properties are set: Display traces set to 6, Update interval set to 1, Colormap set to autumn. There are two additional Transparency related properties: Newest, Oldest.

  10. Click theAxestab. Set the parameters as follows:

    • Y Min=-0.188

    • Y Max=0.179

  11. Click theData historytab. Set the parameters as follows:

    • History traces=50

    • Data logging=All visible

  12. Close theParameterswindow leaving all other parameters at their default values.

    You might need to adjust the axes in theWaterfallscope window in order to view the plots.

  13. Click theFit to viewbutton in theWaterfallscope window. Then, click-and-drag the axes until they resemble the following figure.

    Waterfall scope. The three axes in the waterfall plot are Time (ranging from -5 to 0), Samples (ranging from -0.2 to 0.2), and Amplitude (ranging from 0 to 30).

  14. In theModelingtab, clickModel Settings. In theSolverpane, set the parameters as follows, and then clickOK:

    • Stop time=inf

    • Type=Fixed-step

    • Solver=Discrete (no continuous states)

  15. Run the simulation and view the results in theWaterfallscope window. You can also listen to the simulation using the speakers attached to your computer.

  16. Experiment with changing the Manual Switch so that the input to the Acoustic Environment subsystem is either 0 or 1.

    When the value is 0, the Gaussian noise in the signal is being filtered by a lowpass filter. When the value is 1, the noise is being filtered by a bandpass filter. The adaptive filter can remove the noise in both cases.

You have now created a model capable of adaptive noise cancellation. The adaptive filter in your model is able to filter out both low frequency noise and noise within a frequency range. In the next topic,Modify Adaptive Filter Parameters During Model Simulation, you modify the LMS Filter block and change its parameters during simulation.

Modify Adaptive Filter Parameters During Model Simulation

In the previous topic,LMS Filter Configuration for Adaptive Noise Cancellation, you created an adaptive filter and used it to remove the noise generated by the Acoustic Environment subsystem. In this topic, you modify the adaptive filter and adjust its parameters during simulation. This topic assumes that you are working on a Windows operating system:

  1. If the model you created inCreate an Acoustic Environment in Simulinkis not open on your desktop, you can open an equivalent model by typing

    ex_adapt2_audio

    at the MATLAB command prompt.

  2. Double-click the LMS filter block. Set the block parameters as follows, and then clickOK:

    • Specify step size via=Input port

    • Initial value of filter weights=0

    • Select theAdapt portcheck box.

    • Reset port=Non-zero sample

    TheBlock Parameters: LMS Filterdialog box should now look similar to the following figure.

    LMS Filter block dialog parameters. In the Main tab, Algorithm is set to Normalized LMS, Filter length is set to 40, Specify step size via parameter is set to Input port, Leakage factor is set to 1.0, Initial values of filter weights is set to 0, Adapt port parameter is selected, Reset port is set to Non-zero sample, and Output filter weights parameter is selected.

    Step-size, Adapt, and Reset ports appear on the LMS Filter block.

  3. Click-and-drag the following blocks into your model.

    Block Library Quantity

    Constant

    Simulink/Sources

    6

    Manual Switch

    Simulink/Signal Routing

    3

  4. Connect the blocks as shown in the following figure.

    修改自适应滤波器的参数在模型模拟ulation. Two constants 0 and 1 connect to the Filter input of the Acoustic Environment block through a manual switch. The two outputs of the Acoustic environment block, Exterior Mic and Pilot's mic feed in the Input and Desired signals in the Normalized LMS block. Two constant blocks feed the step size input of the LMS Filter block through a manual switch. Two constant blocks feed the adapt input of the LMS block through a manual switch. Two constant blocks feed the reset input of the LMS block through a manual switch. The three output signals of the LMS Filter block, Output signal, Error signal, and Weights connect to a terminator, Audio Device Writer, and a Waterfall scope block, respectively. There is a Downsample block (factor of 32) in between the Weights port and the Waterfall scope.

  5. Double-click the Constant2 block. Set the block parameters as follows, and then clickOK:

    • Constant value=0.002

    • Select theInterpret vector parameters as 1-Dcheck box.

    • Sample time (-1 for inherited)=inf

    • Output data type mode=Inherit via back propagation

  6. Double-click the Constant3 block. Set the block parameters as follows, and then clickOK:

    • Constant value=0.04

    • Select theInterpret vector parameters as 1-Dcheck box.

    • Sample time (-1 for inherited)=inf

    • Output data type mode=Inherit via back propagation

  7. Double-click the Constant4 block. Set theConstant valueparameter to0and then clickOK.

  8. Double-click the Constant6 block. Set theConstant valueparameter to0and then clickOK.

  9. In theDebugtab, selectInformation Overlays>Nonscalar SignalsandSignal Dimensions.

  10. Double-click Manual Switch2 so that the input to the Adapt port is 1.

  11. Run the simulation and view the results in theWaterfallscope window. You can also listen to the simulation using the speakers attached to your computer.

  12. Double-click the Manual Switch block so that the input to the Acoustic Environment subsystem is 1. Then, double-click Manual Switch2 so that the input to the Adapt port to 0.

    The filter weights displayed in theWaterfallscope window remain constant. When the input to the Adapt port is 0, the filter weights are not updated.

  13. Double-click Manual Switch2 so that the input to the Adapt port is 1.

    The LMS Filter block updates the coefficients.

  14. Connect the Manual Switch1 block to the Constant block that represents 0.002. Then, change the input to the Acoustic Environment subsystem. Repeat this procedure with the Constant block that represents 0.04.

    You can see that the system reaches steady state faster when the step size is larger.

  15. Double-click the Manual Switch3 block so that the input to the Reset port is 1.

    The block resets the filter weights to their initial values. In theBlock Parameters: LMS Filterdialog box, from theReset portlist, you choseNon-zero sample. This means that any nonzero input to the Reset port triggers a reset operation.

现在,您已经尝试了自适应噪声cancellation using the LMS Filter block. You adjusted the parameters of your adaptive filter and viewed the effects of your changes while the model was running.

For more information about adaptive filters, see the following block reference pages:

References

[1] Hayes, Monson H.,Statistical Digital Signal Processing and Modeling. Hoboken, NJ: John Wiley & Sons, 1996, pp.493–552.

[2] Haykin, Simon,Adaptive Filter Theory. Upper Saddle River, NJ: Prentice-Hall, Inc., 1996.

Related Topics