Acoustic Noise Cancellation

21
© 2007 Texas Instruments Inc, 1 Acoustic Noise Cancellation 1 Introduction The Least Mean Squares (LMS) Algorithm can be used in a range of Digital Signal Processing applications such 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 a Texas Instruments C6000 DSP. 1.1 Objectives Design a model of LMS Noise Reduction for the Texas Instruments C6000 family of DSP devices using MATLAB ® 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 understanding 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.

description

Noise Cancellation

Transcript of Acoustic Noise Cancellation

  • 2007 Texas Instruments Inc, 1

    Acoustic Noise Cancellation

    1 Introduction The Least Mean Squares (LMS) Algorithm can be used in a range of Digital Signal

    Processing applications such 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 a Texas Instruments C6000 DSP.

    1.1 Objectives

    Design a model of LMS Noise Reduction for the Texas Instruments C6000

    family of DSP devices using MATLAB 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 understanding 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.

  • 2007 Texas Instruments Inc, 2

    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.mdl

    Figure 1 Opening the AcousticNoiseCancellation Model

    Run the model.

    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 information is lost as LMS Error.

    Figure 2 LMS Filter Inputs and Outputs

  • 2007 Texas Instruments Inc, 3

    2.3 LMS Filter Weights (Coefficients)

    The LMS Filter Weights all start at zero and take several iterations to reach their

    final values.

    Figure 3 LMS Filter Weights (Coefficients)

    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 filter.

    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.1

    Run the model.

  • 2007 Texas Instruments Inc, 4

    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 of granularity 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 filter weights (coefficients) do not attain smooth values, as would

    be the case for smaller values of Step size (mu).

    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 so the two inputs to the LMS Filter have different random

    noise.

  • 2007 Texas Instruments Inc, 5

    Figure 7 Changing the Delay

    Experiment with different values of delay to see how it effects 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 filter will not remove the noise properly.

    Figure 8 Changing the Filter Length

    2.9 Summary

    From practical experience, you should now know how to use LMS algorithm and

    how you can adjust the Step size (mu), the filter delay and the number of weights

    to obtain optimum performance.

    You will now apply this to building a real-time model.

  • 2007 Texas Instruments Inc, 6

    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

    Figure 10 Startup Screen for Code Composer Studio (CCS)

  • 2007 Texas Instruments Inc, 7

    3.2.2 Opening an Existing Model

    Start MATLAB 7.3.0 R2006b:

    Figure 11 Opening an Existing Demo

    Click on Demos. The following screen will appear:

    Figure 12 Selecting the Audio Demo Models

    Highlight Embedded Target for TI C6000 DSP then Audio. Click on Wavelet

    Denoising. We are going to use this as our template.

  • 2007 Texas Instruments Inc, 8

    3.2.3 Viewing the Original Model

    The Wavelet Denoising model is now displayed.

    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.

    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.

  • 2007 Texas Instruments Inc, 9

    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.

    Figure 16 - Wavelet Denoising Algorithm

    3.2.7 Delete Blocks

    Delete the blocks and connect the input directly to the output. Add a title.

  • 2007 Texas Instruments Inc, 10

    Figure 17 - LMS Denoising Algorithm Template

    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.

    Figure 19 Setting up the ADC for Mono Microphone Input

  • 2007 Texas Instruments Inc, 11

    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.

    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.

    Figure 21 Adding an LMS Filter Block

  • 2007 Texas Instruments Inc, 12

    3.2.12 Setting the LMS Filter Parameters

    The most critical variable in an LMS filter is the Step size (mu).

    If mu is too small, the filter has very fine resolution, but reacts too slowly to the

    audio signal.

    If mu is too great, the filter reacts very quickly, but the error also remains large.

    We will start with 0.005.

    Figure 22 Setting the Parameter Set size (mu)

    3.2.13 Adding a Delay

    From the Signal Processing Blockset, highlight Signal Operations. Drag-and-

    drop the Delay1 block onto the model.

    Figure 23 Adding a Delay

    1 Since we are working with frames, the delay from Discrete Components library

    will not work!

  • 2007 Texas Instruments Inc, 13

    3.2.14 Setting the Delay Parameters

    Because we are working with frames of 64 samples, it is convenient configure 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.

    Figure 24 Setting the Delay Size

    3.2.15 Adding a DIP Switch and LED

    So we can hear the difference without LMS denoising and with LMS noise

    reduction, we will use a DIP switch of the DSK6713.

    Figure 25 Adding a Switch and LED

    Select View -> Library Browser -> Embedded Target for TI C6000 DSP. Highlight

    DSK6713 Board Support.

    Drag-and-drop the Switch block onto the model. Also drag-and-drop the LED

    block onto the model.

  • 2007 Texas Instruments Inc, 14

    3.2.16 DIP Switch Settings

    The DIP switch needs to be configured. 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.

    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 LMS noise 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.

    Figure 27 Selecting the Commonly Used Blocks

  • 2007 Texas Instruments Inc, 15

    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.

    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 with the DAC on the DSK6713.

    Figure 29 Data Type Conversion to 16-bit Integer

  • 2007 Texas Instruments Inc, 16

    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.

    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.

    Figure 31 Changing the Output Data Type

  • 2007 Texas Instruments Inc, 17

    3.2.22 Joining the Blocks

    Move the blocks and join them as shown in the Figure below.

    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

    3.3 Building the Model

    3.3.1 Selecting Real-Time Workshop

    Select Tools -> Real-Time Workshop -> Build Model.

    Figure 34 Building the Model

  • 2007 Texas Instruments Inc, 18

    3.3.2 Frames Displayed on Model

    When built, the single lines are replaced by double lines. This shows frames.

    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.

    Figure 36 The Completed Model Running in Code Composer Studio

  • 2007 Texas Instruments Inc, 19

    3.4 Different 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:

    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

  • 2007 Texas Instruments Inc, 20

    4 Some Things to Try You may wish to experiment with different 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.

    Figure 39 - Configuring the LMS Filter Block Parameters

    4.2 Experiment with LMS Filter Settings

    Try different value of Filter Length. What is the minimum value that will allow

    the filter to work correctly?

    4.3 Change from LMS Filter to RLS Filter

    Inside the Adaptive Filters are different LMS types. Which are suitable for LMS

    denoising and which are not?

  • 2007 Texas Instruments Inc, 21

    Figure 40 Available Adaptive Filter Types

    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 trademarks of their respective holders.