OpenStax-CNX module: m22178 1
Acoustic Noise Cancellation∗
Jacob Fainguelernt
This work is produced by OpenStax-CNX and licensed under the
Creative Commons Attribution License 2.0†
Abstract
The Least Mean Squares (LMS) Algorithm can be used in a range of Digital Signal Processingapplications such as echo cancellation and acoustic noise reduction. This laboratory shows how to designa model of LMS Noise Cancellation using Simulink and run it on a Texas Instruments C6000 DSP.
1 Introduction
The Least Mean Squares (LMS) Algorithm can be used in a range of Digital Signal Processing applicationssuch as echo cancellation and acoustic noise reduction.
This laboratory shows how to design a model of LMS Noise Cancellation using Simulink and run it on aTexas Instruments C6000 DSP.
1.1 Objectives
• Design a model of LMS Noise Reduction for the Texas Instruments C6000 family of DSP devices usingMATLAB® and Simulink®.
• Modify an existing Simulink demonstration model for use as a template.• Run the project on the Texas Instruments DSK6713 with a microphone and computer loudspeakers /
headphones.
1.2 Level
Intermediate - Assumes prior knowledge of MATLAB and Simulink. It also requires a theoretical under-standing of matrices and the LMS algorithm.
1.3 Hardware and Software Requirements
This laboratory was originally developed using the following hardware and software:
• MATLAB R2006b with Embedded Target for TI C6000 and the Signal Processing Toolbox.• Code Composer Studio (CCS) v3.1• Texas Instruments DSK6713 hardware.• Microphone and computer loudspeakers / headphones.
∗Version 1.1: Apr 20, 2009 8:02 am -0500†http://creativecommons.org/licenses/by/2.0/
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 2
1.4 Related Files
• Powerpoint Presentation AcousticNoiseCancellation.ppt1
• Simulink Model for Simulation- AcousticNoiseCancellation.mdl2
• Simulink Model for Real-Time AcousticNoiseCancellationDSKC6713.mdl3
2 Simulation
You will now start with a simple Simulink model and run it to see how it works.
2.1 Opening the Acoustic Noise Cancellation Model
Open the AcousticNoiseCancellation.mdl4
Figure 1: Opening the AcousticNoiseCancellation Model
Run the model.
1See the �le at <http://cnx.org/content/m22178/latest/AcousticNoiseCancellation.ppt>2See the �le at <http://cnx.org/content/m22178/latest/AcousticNoiseCancellation.mdl>3See the �le at <http://cnx.org/content/m22178/latest/AcousticNoiseCancellationDSKC6713.mdl>4See the �le at <http://cnx.org/content/m22178/latest/AcousticNoiseCancellation.mdl>
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 3
2.2 Inputs and Outputs of LMS Filter
The output from the LMS Filter starts at zero and grows slowly. Initially, some of the sine wave informationis lost as LMS Error.
Figure 2: LMS Filter Inputs and Outputs
2.3 LMS Filter Weights (Coe�cients)
The LMS Filter Weights all start at zero and take several iterations to reach their �nal values.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 4
Figure 3: LMS Filter Weights (Coe�cients)
2.4 Tuning the Model
The critical variable in the LMS Filter is the �Step size (mu)�. This sets the rate of convergence of the LMS�lter.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 5
Figure 4: Changing the Step size (mu) to 0.1
Double-click on the �LMS Filter� block and change the �Step size (mu) to 0.1Run the model.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 6
2.5 Filter Outputs for Step size (mu) = 0.1
When the �Step size (mu)� is increased, LMS algorithm converges more quickly, but at the expense ofgranularity � the LMS Filter Output is not as smooth.
Figure 5: Input and LMS Filter Outputs for Step size (mu) = 0.1
2.6 Filter Weights for Step size (mu) = 0.1
Note that the �lter weights (coe�cients) do not attain smooth values, as would be the case for smaller valuesof Step size (mu).
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 7
Figure 6: LMS Filter Weights for Step size (mu) = 0.1
2.7 Changing the Delay
Part of the Acoustic Noise Algorithm is the delay. The delay should ideally be at least half a wavelength sothe two inputs to the LMS Filter have di�erent random noise.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 8
Figure 7: Changing the Delay
Experiment with di�erent values of delay to see how it e�ects the operation of the LMS Filter.
2.8 Changing the Number of Weights
Double-click on the �LMS Block� and change the Filter Size (number of Weights).If the number of Weights is large, the algorithm will be slow to run.If the number of Weights is too small, the �lter will not remove the noise properly.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 9
Figure 8: Changing the Filter Length
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 10
2.9 Summary
From practical experience, you should now know how to use LMS algorithm and how you can adjust theStep size (mu), the �lter delay and the number of weights to obtain optimum performance.
You will now apply this to building a real-time model.
3 Real-Time Model
You have now run the simulation and understand the operation of the LMS Filter.You will now implement the Real-Time Acoustic Noise Cancellation Model using the Texas Instrument
C6713.
3.1 Texas Instruments DSK6713 Setup
Figure 9: Texas Instruments DSK6713 Setup
Alternatively, you can use computer loudspeakers.
3.2 Starting up Code Composer Studio
3.2.1 Connecting the DSK6713
Start Code Composer Studio for DSK6713 and use Debug -> Connect
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 11
Figure 10: Startup Screen for Code Composer Studio (CCS)
3.2.2 Opening an Existing Model
Start MATLAB 7.3.0 R2006b:
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 12
Figure 11: Opening an Existing Demo
Click on �Demos�. The following screen will appear:
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 13
Figure 12: Selecting the Audio Demo Models
Highlight �Embedded Target for TI C6000 DSP� then �Audio�. Click on �Wavelet Denoising�. We aregoing to use this as our template.
3.2.3 Viewing the Original Model
The �Wavelet Denoising� model is now displayed.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 14
Figure 13: Wavelet Denoising Parent
3.2.4 Saving the Model
For convenience, save the model to the MATLAB �Work� directory, where most models are stored.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 15
Figure 14: Saving the Model to the MATLAB �Work� directory
3.2.5 Changing the Title
Delete the �Info� box. Change the title to �LMS Noise Reduction�. You may also wish to move the �DSK6713�icon to the left hand side.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 16
Figure 15: LMS Noise Reduction Parent
3.2.6 The Original Wavelet Noise Reduction Algorithm
Double-click on the �function()� box. The �Wavelet Noise Reduction Algorithm� model is now displayed.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 17
Figure 16: Wavelet Denoising Algorithm
3.2.7 Delete Blocks
Delete the blocks and connect the input directly to the output. Add a title.
Figure 17: LMS Denoising Algorithm Template
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 18
3.2.8 Overview of the LMS Model
We are going to implement the model shown below.We will now update the empty model by dragging-and-dropping some library components onto the model.
Figure 18: Overview of the LMS Algorithm
3.2.9 Changing the Input to Microphone
Double-click on the blue box to the left marked �DSK6713 ADC�. The following screen will appear.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 19
Figure 19: Setting up the ADC for Mono Microphone Input
Change the �ADC source� to �Mic In�.If you have a quiet microphone, select �+20dB Mic gain boost�.Set the �Sampling rate (Hz)� to �48 kHz�.Set the �Samples per frame� to 64.When done, click on �OK�.Important: Make sure the �Stereo� box is empty.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 20
3.2.10 The DAC Settings
The DAC settings need to match those of the ADC. Check that it uses the same sampling rates. Click on�OK�.
Figure 20: Setting the DAC Parameters
3.2.11 Adding an LMS Block
The Simulink block for LMS is to be found in the �Signal Processing Toolbox�.Select View -> Library Browser -> Signal Processing Blockset ->Filtering-> Adaptive Filters.Highlight �Adaptive Filters�. Drag-and-drop the �LMS Filter� block onto the model.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 21
Figure 21: Adding an LMS Filter Block
3.2.12 Setting the LMS Filter Parameters
The most critical variable in an LMS �lter is the �Step size (mu)�.If �mu� is too small, the �lter has very �ne resolution, but reacts too slowly to the audio signal.If �mu� is too great, the �lter reacts very quickly, but the error also remains large.We will start with 0.005.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 22
Figure 22: Setting the Parameter �Set size (mu)�
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 23
3.2.13 Adding a Delay
From the �Signal Processing Blockset�, highlight �Signal Operations�. Drag-and-drop the �Delay�5 block ontothe model.
Figure 23: Adding a Delay
3.2.14 Setting the Delay Parameters
Because we are working with frames of 64 samples, it is convenient con�gure the delay using frames. Double-click on the �Delay� block.
Change the �Delay units� to Frames.Set the �Delay (frames)� to 1. This makes the delay 64 samples.
5Since we are working with frames, the delay from �Discrete Components� library will not work!
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 24
Figure 24: Setting the Delay Size
3.2.15 Adding a DIP Switch and LED
So we can hear the di�erence without LMS denoising and with LMS noise reduction, we will use a DIPswitch of the DSK6713.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 25
Figure 25: Adding a Switch and LED
Select View -> Library Browser -> Embedded Target for TI C6000 DSP. Highlight �DSK6713 BoardSupport�.
Drag-and-drop the �Switch� block onto the model. Also drag-and-drop the �LED� block onto the model.
3.2.16 DIP Switch Settings
The DIP switch needs to be con�gured. Double-click on the �Switch� block.Select all the boxes and set �Data type� to Integer. The �Sample time� should also be set to ��1�.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 26
Figure 26: Setting up the DIP Switch Values
3.2.17 Adding a Constant, Switch and Relational Operator
We now need to setup a way to switch between straight through without noise reduction and with LMSnoise reduction.
Select View -> Library Browser -> Simulink. Highlight �Commonly Used Blocks�.Drag-and-drop a �Constant� onto the model.Drag-and-drop a �Switch� block onto the model.Drag-and-drop a �Relational Operator� block onto the model.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 27
Figure 27: Selecting the Commonly Used Blocks
3.2.18 Setting the Constant Value
The switch values lie between 0 and 15. We will use switch values 0 and 1. Double-click on the �Constant�block. Set the �Constant value� to 1 and the �Sample time� to �inf�.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 28
Figure 28: Setting the Echo Delay Gain
3.2.19 Setting the Constant Data Type
Click on the �Signal Data Types� tab. Set the �Output data type mode� to �int16�. This is compatible withthe DAC on the DSK6713.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 29
Figure 29: Data Type Conversion to 16-bit Integer
3.2.20 Setting the Relational Operator Type
Double click on the �Relational Operator� block. Change the �Relational operator� to �==�. Click on the�Signal Data Types� tab.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 30
Figure 30: Changing the Relational Operator
3.2.21 Setting the Relational Operator Data Type
Set the �Output data type mode� to �Boolean�. Click on �OK�.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 31
Figure 31: Changing the Output Data Type
3.2.22 Joining the Blocks
Move the blocks and join them as shown in the Figure below.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 32
Figure 32: Joining the Blocks
3.2.23 Returning to the Parent System
From the Toolbar, select the �Up Arrow� icon. This returns you to the next higher level.
Figure 33: Returning to the Parent System
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 33
3.3 Building the Model
3.3.1 Selecting Real-Time Workshop
Select Tools -> Real-Time Workshop -> Build Model.
Figure 34: Building the Model
3.3.2 Frames Displayed on Model
When built, the single lines are replaced by double lines. This shows frames.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 34
Figure 35: Frames
3.3.3 The Completed Model Running on Code Composer Studio
From the folders on the left, select the source code for the project.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 35
Figure 36: The Completed Model Running in Code Composer Studio
3.4 Di�erent Settings on the DSK6713
3.4.1 Microphone Straight Through to Loudspeakers
To check out the microphone and loudspeakers, set the DIP switches on the DSK6713 as follows:
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 36
Figure 37: Switch Position 0
The microphone is fed directly to the loudspeakers. There is no LMS noise reduction.
3.4.2 Switch Position for LMS Noise Reduction
To run the �LMS Noise Reduction� subsystem, set the DIP switch to 1.
Figure 38: Switch Position 1 for LMS Noise Reduction
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 37
4 Some Things to Try
You may wish to experiment with di�erent settings. Here are some suggestions.
4.1 Experiment with LMS Filter Settings
Change the value of �Step size (mu)� between 0.0001 and 0.5. This is the critical value.Low values of mu give good resolution, but a slow reaction time.High values of mu give less resolution, but faster reaction times.Find the best value of mu for noise reduction on the TI DSK6713.
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 38
Figure 39: Con�guring the LMS Filter Block Parameter
http://cnx.org/content/m22178/1.1/
OpenStax-CNX module: m22178 39
4.2 Experiment with LMS Filter Settings
Try di�erent value of �Filter Length�. What is the minimum value that will allow the �lter to work correctly?
4.3 Change from LMS Filter to RLS Filter
Inside the �Adaptive Filters� are di�erent LMS types. Which are suitable for LMS denoising and which arenot?
Figure 40: Available Adaptive Filter Types
Figure 40 �MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks
for a list of additional trademarks. Other product or brand names may be trademarks or registered trade-marks of their respective holders.
http://cnx.org/content/m22178/1.1/