NEW DATABASE - 350 MILLION DATASHEETS FROM 8500 MANUFACTURERS
DS70134A ISO/TS-16949 DS70046 DS70082 DS70083 DS70116 DS70117 DS70030 DS70043 - Datasheet Archive
Acoustic Echo Cancellation Library User's Guide 2004 Microchip Technology Inc. DS70134A Note the following details of the code
dsPIC30F Acoustic Echo Cancellation Library User's Guide 2004 Microchip Technology Inc. DS70134A DS70134A Note the following details of the code protection feature on Microchip devices: · Microchip products meet the specification contained in their particular Microchip Data Sheet. · Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the intended manner and under normal conditions. · There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip's Data Sheets. Most likely, the person doing so is engaged in theft of intellectual property. · Microchip is willing to work with the customer who is concerned about the integrity of their code. · Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not mean that we are guaranteeing the product as "unbreakable." Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our products. Attempts to break Microchip's code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act. Information contained in this publication regarding device applications and the like is intended through suggestion only and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. No representation or warranty is given and no liability is assumed by Microchip Technology Incorporated with respect to the accuracy or use of such information, or infringement of patents or other intellectual property rights arising from such use or otherwise. Use of Microchip's products as critical components in life support systems is not authorized except with express written approval by Microchip. No licenses are conveyed, implicitly or otherwise, under any intellectual property rights. Trademarks The Microchip name and logo, the Microchip logo, Accuron, dsPIC, KEELOQ, microID, MPLAB, PIC, PICmicro, PICSTART, PRO MATE, PowerSmart, rfPIC, and SmartShunt are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. AmpLab, FilterLab, MXDEV, MXLAB, PICMASTER, SEEVAL, SmartSensor and The Embedded Control Solutions Company are registered trademarks of Microchip Technology Incorporated in the U.S.A. Analog-for-the-Digital Age, Application Maestro, dsPICDEM, dsPICDEM.net, dsPICworks, ECAN, ECONOMONITOR, FanSense, FlexROM, fuzzyLAB, In-Circuit Serial Programming, ICSP, ICEPIC, Migratable Memory, MPASM, MPLIB, MPLINK, MPSIM, PICkit, PICDEM, PICDEM.net, PICLAB, PICtail, PowerCal, PowerInfo, PowerMate, PowerTool, rfLAB, rfPICDEM, Select Mode, Smart Serial, SmartTel and Total Endurance are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. SQTP is a service mark of Microchip Technology Incorporated in the U.S.A. All other trademarks mentioned herein are property of their respective companies. © 2004, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved. Printed on recycled paper. Microchip received ISO/TS-16949 ISO/TS-16949:2002 quality system certification for its worldwide headquarters, design and wafer fabrication facilities in Chandler and Tempe, Arizona and Mountain View, California in October 2003. The Company's quality system processes and procedures are for its PICmicro® 8-bit MCUs, KEELOQ® code hopping devices, Serial EEPROMs, microperipherals, nonvolatile memory and analog products. In addition, Microchip's quality system for the design and manufacture of development systems is ISO 9001:2000 certified. DS70134A-page ii 2004 Microchip Technology Inc. dsPIC30F ACOUSTIC ECHO CANCELLATION LIBRARY USER'S GUIDE Table of Contents Preface . 1 Chapter 1. Introduction 1.1 Introduction . 7 1.2 HIghlights . 7 1.3 Acoustic Echo Cancellation Overview . 7 1.4 Features . 8 1.5 Host System Requirements . 9 1.6 Devices Supported . 9 1.7 Accessory Kit . 9 Chapter 2. Installation 2.1 Introduction . 11 2.2 Highlights . 11 2.3 Installation Procedure . 11 2.4 Library Archive . 12 2.5 Include Files . 12 2.6 Demo Files . 13 2.7 User's Guide . 13 Chapter 3. Application Programming Interface 3.1 Introduction . 15 3.2 Highlights . 15 3.3 Acoustic Echo Cancellation Library Functions . 15 3.4 `C' Data Types Used for Function Arguments . 15 3.5 Function Prototypes and Arguments . 16 Chapter 4. Resource Requirements 4.1 Introduction . 21 4.2 Highlights . 21 4.3 Program Memory Requirements . 21 4.4 Data Memory Requirements . 22 4.5 Computational Speed Requirements . 22 Chapter 5. Acoustic Echo Cancellation Algorithm 5.1 Introduction . 23 5.2 Highlights . 23 5.3 AEC Algorithm Overview . 23 5.4 NLMS Algorithm . 25 5.5 Double Talk Detection . 28 2004 Microchip Technology Inc. DS70134A-page iii dsPIC30F Acoustic Echo Cancellation Library User's Guide 5.6 Voice Activation Detection . 28 5.7 Non-Linear Processor . 34 5.8 Howling Control (Optional) . 34 Chapter 6. AEC Demonstration 6.1 Introduction . 37 6.2 Highlights . 37 6.3 Demonstration Summary . 37 6.4 Demonstration Setup . 39 6.5 Demonstration Procedure . 41 6.6 Demo Code Description . 41 Index .43 Worldwide Sales and Service .44 DS70134A-page iv 2004 Microchip Technology Inc. dsPIC30F ACOUSTIC ECHO CANCELLATION LIBRARY USER'S GUIDE Preface INTRODUCTION This user's guide supports the dsPIC30F Acoustic Echo Cancellation Library. This manual provides information you need to incorporate acoustic echo cancellation capability into your embedded solution. HIGHLIGHTS Items discussed in this chapter are: · · · · · · About This Guide Warranty Registration Recommended Reading The Microchip Web Site Development Systems Customer Notification Service Customer Support ABOUT THIS GUIDE This User's Guide describes how to use the dsPIC30F Acoustic Echo Cancellation Library. The document is organized as follows: · Chapter 1: Introduction This chapter introduces the dsPIC30F Acoustic Echo Cancellation Library (Chapter Name) and provides a brief overview of acoustic echo cancellation. It also outlines requirements for a host PC, dsPIC30F device resource requirements and specific dsPIC30F devices that support the AEC library. Finally, it provides information on the optional AEC Accessory Kit. · Chapter 2: Installation This chapter provides instructions for installing the library files and describes the contents of the source files, include files, demo files and archive files. · Chapter 3: Application Programming Interface This chapter provides detailed information needed to interface the AEC library to a user application on a dsPIC30F device. · Chapter 4: Resource Requirements This chapter describes the resources required to support the AEC Library in a dsPIC30F embedded application. · Chapter 5: Acoustic Echo Cancellation Algorithm This chapter describes the acoustic echo cancellation algorithms contained in the AEC Library. · Chapter 6: AEC Demonstration This chapter provides a hands-on demonstration of acoustic echo cancellation in a working application. 2004 Microchip Technology Inc. DS70134A-page 1 dsPIC30F Acoustic Echo Cancellation Library User's Guide Conventions Used in This Guide This User's Guide uses the following documentation conventions: DOCUMENTATION CONVENTION Description Code (Courier font): Plain characters Angle brackets: < > Square brackets [ ] Curly brackets and pipe character: { | } Lower case characters in quotes Ellipses. 0xnnn Represents Examples Sample code Filenames and paths Variables Optional arguments Choice of mutually exclusive arguments; an OR selection Type of data #define START c: utoexec.bat , pic30-as [main.s] errorlevel {0|1} Used to imply (but not show) additional text that is not relevant to the example list ["list_option., "filename" "list_option"] A hexadecimal number where n is a 0xFFFF, 0x007A hexadecimal digit A variable argument; it can be either a char isascii (char, type of data (in lower case characters) ch); or a specific example (in upper case characters) Italic characters Interface (Arial font): Underlined, italic text with right arrow Bold characters Characters in angle brackets < > Documents (Arial font): Italic characters A menu selection from the menu bar File > Save A window or dialog button to click A key on the keyboard OK, Cancel , Referenced books MPLAB IDE User's Guide Documentation Updates All documentation becomes dated, and this user's guide is no exception. Since the dsPIC30F Acoustic Echo Cancellation Library and other Microchip tools are constantly evolving to meet customer needs, some actual dialogs and/or tool descriptions may differ from those in this document. Please refer to our web site to obtain the latest documentation available. Documentation Numbering Conventions Documents are numbered with a "DS" number. The number is located on the bottom of each page, in front of the page number. The numbering convention for the DS Number is DSXXXXXA, where: XXXXX DS70134A-page 2 = The document number. A = The revision level of the document. 2004 Microchip Technology Inc. Preface WARRANTY REGISTRATION Please complete the enclosed Warranty Registration Card and mail it promptly. Sending in your Warranty Registration Card entitles you to receive new product updates. Interim software releases are available at the Microchip web site. RECOMMENDED READING This user's guide describes how to use the dsPIC30F Acoustic Echo Cancellation Library. Other useful documents include: dsPIC30F Family Reference Manual (DS70046 DS70046) Consult this document for detailed information on dsPIC30F device operation. This reference manual explains the operation of the dsPIC30F MCU family architecture and peripheral modules but does not cover the specifics of each device. Refer to the appropriate device data sheet for device-specific information. dsPIC30F Data Sheet, Motor Control and Power Conversion Family (DS70082 DS70082) Consult this document for detailed information on the dsPIC30F Motor Control and Power Conversion devices. Reference information found in this data sheet includes: · · · · Device memory map Device pinout and packaging details Device electrical specifications List of peripherals included on the device dsPIC30F Data Sheet, General Purpose and Sensor Families (DS70083 DS70083) Consult this document for detailed information on the dsPIC30F Sensor and General Purpose devices. Reference information found in this data sheet includes: · · · · Device memory map Device pinout and packaging details Device electrical specifications List of peripherals included on the device dsPIC30F5011, dsPIC30F5013 Data Sheet, High Performance Digital Signal Controllers (DS70116 DS70116) This data sheet contains specific information for the dsPIC30F5011/5013 Digital Signal Controller (DSC) devices. dsPIC30F6011, dsPIC30F6012, dsPIC30F6013, dsPIC30F6014 Data Sheet, High Performance Digital Signal Controllers (DS70117 DS70117) This data sheet contains specific information for the dsPIC30F6011/6012/6013/6014 Digital Signal Controller (DSC) devices. dsPIC30F Programmer's Reference Manual (DS70030 DS70030) This manual is a software developer's reference for the dsPIC30F 16-bit MCU family of devices. This manual describes the instruction set in detail and also provides general information to assist you in developing software for the dsPIC30F MCU family. 2004 Microchip Technology Inc. DS70134A-page 3 dsPIC30F Acoustic Echo Cancellation Library User's Guide dsPIC® High Performance 16-bit Digital Signal Controller Family Overview (DS70043 DS70043) This document provides an overview of the functionality of the dsPIC product family. Its purpose is to help you determine how the dsPIC 16-bit Digital Signal Controller Family fits your specific product application. This document is a supplement to the dsPIC30F Family Reference Manual. MPLAB ASM30 ASM30, MPLAB LINK30 LINK30 and Utilities User's Guide (DS51317 DS51317) This document helps you use Microchip Technology's language tools for dsPIC® devices based on GNU technology. The language tools discussed are: · · · · MPLAB ASM30 ASM30 Assembler MPLAB LINK30 LINK30 Linker MPLAB LIB30 LIB30 Archiver/Librarian Other Utilities MPLAB® C30 C Compiler User's Guide (DS51284 DS51284) A guide to using the dsPIC DSC C compiler. MPLAB LINK30 LINK30 is used with this tool. dsPICTM Language Tools Libraries (DS51456 DS51456) DSP, dsPIC peripheral and standard (including math) libraries for use with dsPIC language tools. GNU HTML Documentation This documentation is provided on the language tool CD-ROM. It describes the standard GNU development tools, upon which these tools are based. MPLAB IDE Simulator, Editor User's Guide (DS51025 DS51025) Consult this document for more information pertaining to the installation and implementation of the MPLAB Integrated Development Environment (IDE) Software. Microchip Web Site Our web site (www.microchip.com) contains a wealth of documentation. Individual data sheets, application notes, tutorials and user's guides are all available for easy download. All documentation is in Adobe® Acrobat® (pdf) format. THE MICROCHIP WEB SITE Microchip provides online support on the Microchip World Wide Web (WWW) site. The website is used by Microchip as a means to make files and information easily available to customers. To view the site, you must have access to the Internet and a web browser, such as, Netscape® Navigator or Microsoft® Internet Explorer. The Microchip web site is available at:www.microchip.com. The web site provides a variety of services. Users may download files for the latest development tools, data sheets, application notes, user's guides, articles, and sample programs. A variety of information specific to the business of Microchip is also available, including listings of Microchip sales offices, distributors and factory representatives. DS70134A-page 4 2004 Microchip Technology Inc. Preface Technical Support · Frequently Asked Questions (FAQ) · Online Discussion Groups Conferences for products, Development Systems, technical information and more · Microchip Consultant Program Member Listing · Links to other useful web sites related to Microchip products Developer's Toolbox · Design Tips · Device Errata Other Available Information · Latest Microchip Press Releases · Listing of Seminars and Events · Job Postings DEVELOPMENT SYSTEMS CUSTOMER NOTIFICATION SERVICE Microchip started the customer notification service to help our customers stay current on Microchip products with the least amount of effort. Once you subscribe, you will receive E-mail notification whenever we change, update, revise or have errata related to your specified product family or development tool of interest. Go to the Microchip web site at (www.microchip.com) and click on Customer Change Notification. Follow the instructions to register. The Development Systems product group categories are: · · · · · Compilers Emulators In-Circuit Debuggers MPLAB Programmers Here is a description of these categories: Compilers The latest information on Microchip C compilers and other language tools. These include the MPLAB C17, MPLAB C18 and MPLAB C30 C compilers; MPASMTM and MPLAB ASM30 ASM30 assemblers; MPLINKTM and MPLAB LINK30 LINK30 object linkers; MPLIBTM and MPLAB LIB30 LIB30 object librarians. Emulators The latest information on Microchip in-circuit emulators. This includes the MPLAB ICE 2000 and MPLAB ICE 4000. In-Circuit Debuggers The latest information on Microchip in-circuit debuggers. These include the MPLAB ICD and MPLAB ICD 2. MPLAB The latest information on Microchip MPLAB IDE, the Windows Integrated Development Environment for development systems tools. This list is focused on the MPLAB IDE, MPLAB SIM and MPLAB SIM30 SIM30 simulators, MPLAB IDE Project Manager and general editing and debugging features. Programmers The latest information on Microchip device programmers. These include the PRO MATE® II device programmer and PICSTART® Plus development programmer. 2004 Microchip Technology Inc. DS70134A-page 5 dsPIC30F Acoustic Echo Cancellation Library User's Guide CUSTOMER SUPPORT Users of Microchip products can receive assistance through several channels: · · · · · Distributor or Representative Local Sales Office Field Application Engineer (FAE) Corporate Applications Engineer (CAE) Hotline Customers should call their distributor, representative or field application engineer (FAE) for support. Local sales offices are also available to help customers. See the sales offices and locations listed on the back of this publication. Corporate Applications Engineers (CAEs) may be contacted at (480) 792-7627. In addition, there is a Systems Information and Upgrade Line. This line provides system users a listing of the latest versions of all of Microchip's development systems software products. Plus, this line provides information on how customers can receive any currently available upgrade kits. The Hotline Numbers are: 1-800-755-2345 for U.S. and most of Canada. 1-480-792-7302 for the rest of the world. DS70134A-page 6 2004 Microchip Technology Inc. dsPIC30F ACOUSTIC ECHO CANCELLATION LIBRARY USER'S GUIDE Chapter 1. Introduction 1.1 INTRODUCTION This chapter introduces the dsPIC30F Acoustic Echo Cancellation Library. This library provides a function to eliminate echo generated in the acoustic path between a speaker and a microphone. This manual provides information needed to incorporate acoustic echo cancellation capability into an embedded solution. 1.2 HIGHLIGHTS This chapter includes information on these topics: · · · · · 1.3 Acoustic Echo Cancellation Overview Features Host System Requirements Devices Supported Accessory Kit ACOUSTIC ECHO CANCELLATION OVERVIEW Acoustic echo cancellation eliminates echoes generated in the acoustic path between a speaker and a microphone, as illustrated in Figure 1-1. Acoustic echo cancellation is useful for speech and telephony applications in which a microphone is located near a speaker and is susceptible to output from the speaker. Such acoustic echoes result in a perceptible and distracting echo effect at the far end. FIGURE 1-1: ACOUSTIC ECHO CANCELLATION Far End Speech Far End Speech Receive Path Acoustic Echo Canceller Echo Adaptive Filter Near End Speech - Near End Speech + Send Path FAR END 2004 Microchip Technology Inc. NEAR END DS70134A-page 7 dsPIC30F Acoustic Echo Cancellation Library User's Guide Acoustic echo cancellation is especially suitable for applications such as: · · · · Hands-free cell phone kits Speakerphones Intercoms Teleconferencing systems For hands-free phones intended to be used in compact environments such as a car cabin, this library is fully compliant with the G.167 Standard for Acoustic Echo Cancellation. The Acoustic Echo Cancellation (AEC) Library is written entirely in assembly language and is highly optimized to make extensive use of the dsPIC30F DSP instruction set and advanced addressing modes. The algorithm avoids data overflow. The AEC Library provides an AcousticEchoCancellerInit function for initializing the various data structures required by the algorithm and an AcousticEchoCanceller function to remove the echo component from a 10 ms block of sampled 16-bit speech data. You can easily call both functions through a well-documented Application Programmer's Interface (API). The AcousticEchoCanceller function is primarily a Time Domain algorithm. The received far-end speech samples (typically received across a communication channel such as a telephone line) are filtered using an adaptive Finite Impulse Response (FIR) filter. The coefficients of this filter are adapted using the Normalized Least Mean Square (NLMS) algorithm, such that the filter closely models the acoustic path between the near end speaker and the near end microphone (i.e., the path traversed by the echo). Voice Activity Detection (VAD) and Double Talk Detection (DTD) algorithms are used to avoid updating the filter coefficients when there is no far end speech and also when there is simultaneous speech from both ends of the communication link double talk). As a consequence, the algorithm functions correctly even in the presence of full-duplex communication. A Non-Linear Processor (NLP) algorithm is used to eliminate residual echo. 1.4 FEATURES Key feature of the dsPIC30F Acoustic Echo Cancellation Library include: · Employs only two user functions: AcousticEchoCancellerInit and AcousticEchoCanceller. Both functions can be called from a C or assembly application program · Full compliance with the Microchip dsPIC30F C30 Compiler, Assembler and Linker · Simple user interface only one library file and one header file · Highly optimized assembly code that uses DSP instructions and advanced addressing modes · Echo cancellation for 16, 32 or 64 ms echo delays or "tail lengths" (configurable) · Fully tested for compliance with G.167 specifications for in-car applications · Audio Bandwidth: 0 to 4 kHz at 8 kHz sampling rate · Convergence Rate: Up to 43 dB/sec., typically greater than 30 dB/sec. · Echo Cancellation: Up to 50 dB, typically > 40 dB · Can be used together with the Noise Suppression (NS) Library, since the same processing block size (10 ms) is used · Library User's Guide is provided to help the user understand and use the library · Demo application source code is provided with the library · Accessory Kit available for purchase (see Section 1.7 "Accessory Kit"). DS70134A-page 8 2004 Microchip Technology Inc. Introduction 1.5 HOST SYSTEM REQUIREMENTS The AEC Library requires a PC-compatible system with these attributes: · · · · 1.6 Intel Pentium class or higher processor, or equivalent 16 MB RAM (minimum) 40 MB (minimum) available hard drive space Microsoft Windows® 98, Windows 2000 or Windows XP DEVICES SUPPORTED The AEC Library is supported by these dsPIC30F devices: · · · · 1.7 dsPIC30F6014 dsPIC30F6012 dsPIC30F5013 (for a maximum of 32 ms echo delay) dsPIC30F5011 (for a maximum of 16 ms echo delay) ACCESSORY KIT An optional Acoustic Accessory Kit (Part # AC300030 AC300030) includes these items: · · · · · · · 6 ft. Audio Cable (1/8 stereo) Headset Two 14.7456 MHz oscillators Microphone Speaker 6 ft. DB9 M/F RS-232 RS-232 cable DB9M-DB9M Null Modem Adaptor 2004 Microchip Technology Inc. DS70134A-page 9 dsPIC30F Acoustic Echo Cancellation Library User's Guide NOTES: DS70134A-page 10 2004 Microchip Technology Inc. dsPIC30F ACOUSTIC ECHO CANCELLATION LIBRARY USER'S GUIDE Chapter 2. Installation 2.1 INTRODUCTION This section describes the various files in the AEC library and includes instructions for installing the library on your laptop or PC for use with dsPIC30F programming tools. 2.2 HIGHLIGHTS This chapter includes information on these topics: · · · · 2.3 Installation Procedure Library Archive Include Files User's Guide INSTALLATION PROCEDURE The dsPIC30F AEC Library is packaged on a CD. It can also be purchase and downloaded from the Microchip web site. To install the library follow these steps: 1. Insert the library CD into the appropriate drive and start the setup procedure. Run aec.exe from the download location. The installation screen displays, as shown in Figure 2-1. FIGURE 2-1: 2004 Microchip Technology Inc. INSTALLATION SCREEN DS70134A-page 11 dsPIC30F Acoustic Echo Cancellation Library User's Guide 2. Decide where to install the files (the default location is the root of your hard drive), then click OK to continue. 3. Review the License Agreement (Figure 2-2), then click OK to continue. FIGURE 2-2: PROGRAM LICENSE AGREEMENT 4. When the Installation Complete message displays (Figure 2-3), click OK. FIGURE 2-3: 2.4 INSTALLATION COMPLETE MESSAGE LIBRARY ARCHIVE The Library Archive (libaec.a) is a pre-compiled object file that contains all the Acoustic Echo Cancellation Library functions. Upon installing the library, the libaec.a file is located in the AEC v1.0\lib folder on your hard drive. 2.5 INCLUDE FILES The C header file for the AEC Library is aec.h. This file contains various constant parameters used by C application programs that use the AEC algorithm, as well as the C function prototypes of the two user-callable functions AcousticEchoCancellerInit and AcousticEchoCanceller. The maximum echo tail length to be cancelled is specified in this file. The assembly header file for the AEC Library is aec.inc. This file contains various constant parameters used by dsPIC30F assembly language application programs that incorporate the AEC algorithm. The maximum echo tail length to be cancelled is specified in this file. After installation, both the include files are located in the AEC v1.0\inc folder. DS70134A-page 12 2004 Microchip Technology Inc. Installation 2.6 DEMO FILES The source, include, MPLAB project and workspace files, as well as a ready-to-use.hex file (echodemo.hex) and.cof (echodemo.cof) file, are provided in the AEC v1.0\demo folder. This folder also contains a local copy of the libaec.a and aec.h files, which are used by the demo to avoid any project tool path dependencies. 2.7 USER'S GUIDE The AEC Library User's Guide is located in the AEC v1.0\doc folder and is called AEC Library User's Guide.pdf. This document can also be downloaded from the Acoustic Echo Cancellation Library product page on the Microchip web site (www.microchip.com). 2004 Microchip Technology Inc. DS70134A-page 13 dsPIC30F Acoustic Echo Cancellation Library User's Guide NOTES: DS70134A-page 14 2004 Microchip Technology Inc. dsPIC30F ACOUSTIC ECHO CANCELLATION LIBRARY USER'S GUIDE Chapter 3. Application Programming Interface 3.1 INTRODUCTION This section outlines how the functions provided in the AEC Library can be used by user application software, via an Application Programming Interface. 3.2 HIGHLIGHTS This chapter includes information on these topics: · Acoustic Echo Cancellation Library Functions · `C' Data Types Used for Function Arguments · Function Prototypes and Arguments 3.3 ACOUSTIC ECHO CANCELLATION LIBRARY FUNCTIONS The AEC Library consists of the two functions listed below, which can be called from a user application. The user program(s) that utilizes these functions can be written either in `C' or dsPIC30F assembly language. TABLE 3-1: AEC LIBRARY FUNCTIONS Function Name Purpose Usage AcousticEchoCancellerInit To initialize the data structures used by this function. AcousticEchoCanceller 3.4 To cancel out the acoustic echo component from a 10 ms block of signal samples. Called by the user only once, before the first usage of the function. Called by the user once for every 10 ms block of signal samples. `C' DATA TYPES USED FOR FUNCTION ARGUMENTS Two basic data types (corresponding to standard data types defined by the `C' programming language) are used for various parameters or arguments passed to the library functions. These data types, along with the alias symbols defined for them in the "aec.h" include file, are listed below: TABLE 3-2: ARGUMENT DATA TYPES Symbol Word16 Short int Word32 2004 Microchip Technology Inc. Standard Data Type Long int DS70134A-page 15 dsPIC30F Acoustic Echo Cancellation Library User's Guide 3.5 FUNCTION PROTOTYPES AND ARGUMENTS The prototypes, along with a description of the arguments used by each function, are given below. The `C' function prototypes are defined in the header file aec.h. For each function, the actual name of the library function, as would be used when it is called from a user application written in assembly language, is also listed. 3.5.1 AEC Initialization Function Function prototype, when the function is invoked from `C' void AcousticEchoCancellerInit (Word32 *echo_mem, Word16 order, Word32 *vad_mem, Word32 *scratch_ptr, Word16 howling_control ); Note: These five arguments must be successively assigned to W0, W1, W2, W3 and W4, respectively, before the function can be called. Function call, when the function is invoked from assembly language CALL _AcousticEchoCancellerInit Note: DS70134A-page 16 The RCALL instruction may be used instead of CALL, when the conditions for usage of the RCALL instruction are satisfied 2004 Microchip Technology Inc. Application Programming Interface Function Arguments Description: echo_mem Pointer to a block of static variables in RAM utilized by the AEC algorithm. This memory block needs to be allocated by the user application. Its length is defined in the aec.h header file (used if the calling application routine is written in C) and the aec.inc include file (used if the calling application routine is written in assembly). It is dependent on the maximum echo tail length for which the echo needs to be eliminated. In order to configure the appropriate echo tail length, the echo_delay constant in the aec.h or aec.inc file must be modified by the user. The echo_mem memory block must have a size equal to (8 * echo delay) + 47) long integers or (32 * echo_delay) + 188) bytes. This memory block must be allocated in X data memory. order Order of AEC adaptive filter, as given by the constant ORDER defined in aec.h and aec.inc. For a signal sampling rate of 8 kHz, ORDER = 8 * echo_delay. The user must pass the constant ORDER as the function argument. vad_mem Pointer to a 296 byte (74 long integers) block of static variables in RAM used by the Voice Activity Detection algorithm (described in the next section). This memory block must be allocated by the user application in X data memory. scratch_mem Pointer to a block of RAM utilized by the AEC algorithm. This memory block must be allocated by the user application in X data memory, and must have a size equal to: (ORDER+(3 * FRAME)/2 long integers, or 2 * (ORDER+ (3 * FRAME) bytes, where FRAME = 80 (a constant defined in aec.h and aec.inc), which represents the number of signal samples in each 10 ms processing frame. Howling_control This argument determines if the optional Howling Control feature will be enabled. If the value passed is `1', then Howling Control is enabled; if it is `0', then Howling Control is Disabled. Note: Return Value: 2004 Microchip Technology Inc. For 64 ms echo tail length, this argument must be `0', i.e., Howling Control is not supported for 64 ms echo tail length. None DS70134A-page 17 dsPIC30F Acoustic Echo Cancellation Library User's Guide 3.5.2 AEC Frame Processing Function Function prototype, when the function is invoked from `C' void AcousticEchoCanceller (Word32 *echo_mem, Word32 *vad_mem, Word16 *rin_in, Word16 *sin_in, Word16 *sout, Word16 inhibit_flag, Word16 *yscrptr); Note: These seven arguments must be successively assigned to W0, W1, W2, W3, W4, W5 and W6, respectively, before the function can be called. Function call, when the function is invoked from assembly language CALL _AcousticEchoCanceller Note: DS70134A-page 18 The RCALL instruction may be used instead of CALL, when the conditions for usage of the RCALL instruction are satisfied. 2004 Microchip Technology Inc. Application Programming Interface Function Arguments Input Arguments: echo_mem Pointer to a block of static variables in RAM utilized by the AEC algorithm. This memory block needs to be allocated by the user application. Its length is defined in the aec.h header file (used if the calling application routine is written in C) and the aec.inc include file (used if the calling application routine is written in assembly). It is dependent on the maximum echo tail length for which the echo needs to be eliminated. In order to configure the appropriate echo tail length, the echo_delay constant in the aec.h or aec.inc file must be modified by the user. The echo_mem memory block must have a size equal to: (8 * echo_delay) + 47) long integers or (32 * echo_delay) + 188) bytes. This memory block must be allocated in X data memory. vad_mem Pointer to a 296-byte (74 long integers) block of static variables in RAM used by the Voice Activity Detection algorithm (described in the next section). This memory block must be allocated by the user application in X data memory. rin_in Pointer to the RAM buffer containing the current processing frame of 80 samples of the Receive-In (RIN) signal. sin_in Pointer to the RAM buffer containing the current processing frame of 80 samples of the Send-In (SIN) signal. inhibit_flag A flag variable which determines if adaptation of filter coefficients will be performed for the current processing frame. If the argument value passed is `1', adaptation is inhibited; if the value passed is `0', filter adaptation is performed. This parameter is primarily useful for application debugging purposes; during normal operation this argument should be `1'. yscrptr Pointer to a block of RAM utilized by the AEC algorithm. This memory block must be allocated by the user application in Y data memory and must have a size equal to (ORDER + FRAME) words or (2 * (ORDER + FRAME) bytes, where FRAME = 80. Output Argument: sout Pointer to the RAM buffer containing the current processing frame of 80 samples of the Send-Out (SOUT) signal. Return Value: None 2004 Microchip Technology Inc. DS70134A-page 19 dsPIC30F Acoustic Echo Cancellation Library User's Guide NOTES: DS70134A-page 20 2004 Microchip Technology Inc. dsPIC30F ACOUSTIC ECHO CANCELLATION LIBRARY USER'S GUIDE Chapter 4. Resource Requirements 4.1 INTRODUCTION This chapter describes the resources required to support the AEC Library. 4.2 HIGHLIGHTS This chapter includes information on these topics: · Program Memory Requirements · Data Memory Requirements · Computational Speed Requirements 4.3 PROGRAM MEMORY REQUIREMENTS All lookup tables used by the library functions are located in program memory. lists the program memory requirements. TABLE 4-1: PROGRAM MEMORY REQUIREMENTS Function Memory Required Code in Program Memory 5180 bytes Tables in Program Memory 860 bytes 2004 Microchip Technology Inc. DS70134A-page 21 dsPIC30F Acoustic Echo Cancellation Library User's Guide 4.4 DATA MEMORY REQUIREMENTS The various blocks of data memory that the user application is required to allocate are described in the API description. The number of bytes of RAM used by each of these memory blocks is listed in Table 4-2 for different echo tail lengths (16, 32 and 64 ms). The memory block pointer names used in the API section have been used in this table. TABLE 4-2: DATA MEMORY REQUIREMENTS 16 ms echo tail length: ECHO_MEM 700 bytes (X data memory) VAD_MEM 296 bytes (X data memory) SCRATCH_MEM 736 bytes (X data memory) YSCRPTR 416 bytes (Y data memory) RIN_IN 160 bytes SIN_IN 160 bytes 160 bytes SOUT Total RAM Usage 2628 bytes 32 ms echo tail length: ECHO_MEM 916 bytes (X data memory) VAD_MEM 296 bytes (X data memory) SCRATCH_MEM 992 bytes (X data memory) YSCRPTR 672 bytes (Y data memory) RIN_IN 160 bytes SIN_IN 160 bytes SOUT 160 bytes Total RAM Usage 3356 bytes 64 ms echo tail length: ECHO_MEM 2236 bytes VAD_MEM 296 bytes (X data memory) SCRATCH_MEM 1504 bytes (X data memory) YSCRPTR 1184 bytes (Y data memory) RIN_IN 160 bytes SIN_IN 160 bytes SOUT 160 bytes Total RAM Usage 4.5 (X data memory) 5700 bytes COMPUTATIONAL SPEED REQUIREMENTS Million Instructions Per Second (MIPS) required on a dsPIC30F device are listed in Table 4-3 for different echo tail lengths (without Howling Control enabled). TABLE 4-3: COMPUTATIONAL SPEED REQUIREMENTS Echo Tail Length MIPS 16 ms 10.5 64 ms DS70134A-page 22 7.5 32 ms 16.5 2004 Microchip Technology Inc. dsPIC30F ACOUSTIC ECHO CANCELLATION LIBRARY USER'S GUIDE Chapter 5. Acoustic Echo Cancellation Algorithm 5.1 INTRODUCTION This chapter describes the acoustic echo cancellation algorithms contained in the AEC Library. 5.2 HIGHLIGHTS This chapter includes information on these topics: · · · · · 5.3 AEC Algorithm Overview NLMS Algorithm Double Talk Detection Non-Linear Processor Howling Control (Optional) AEC ALGORITHM OVERVIEW The Acoustic Echo Cancellation (AEC) algorithm can be divided broadly into these functions: · · · · · Normalized Least Mean Square (NLMS) Adaptation Algorithm Double Talk Detector (DTD) Voice Activity Detector (VAD) Non-Linear Processor (NLP) Howling Control A conceptual block diagram illustrating the operation of the AEC algorithm is shown in Figure 5-1. FIGURE 5-1: CONCEPTUAL BLOCK DIAGRAM OF AEC ALGORITHM SIN NLP Acoustic echo path from speaker to microphone Normalized Least Mean Square (NLMS) Adaptive Filter Howling Control (Optional) SOUT DTD VAD ROUT 2004 Microchip Technology Inc. RIN DS70134A-page 23 dsPIC30F Acoustic Echo Cancellation Library User's Guide A typical AEC system involves four signals: · · · · Far-end speech receive input (RIN), Near-end speech send output (SOUT), Far-end speech output (ROUT), usually sent to a local speaker Near-end speech input (SIN), usually received from a local microphone. In systems in which the near-end speaker and microphone do not have sufficient acoustic separation, the SIN signal not only contains the microphone input (presumably spoken by a talker at the near-end), but also an undesirable echo generated by the acoustic path from the speaker to the microphone. This signal is then transmitted to the far-end through the communication channel (wired or wireless), with the result that the listener at the other end hears a perceptible echo of his/her own speech. Traditionally, this problem had to be avoided by allowing only one person to talk at any given time (i.e., by not allowing "double talk"). An Acoustic Echo Cancellation algorithm consists of an adaptive filter and various associated control functions, which not only eliminate the acoustic echo but also enable double talk (i.e., full-duplex operation). This algorithm operates at the same communicating node at which the echo was generated. The control functions used in the AEC algorithm in conjunction with the Normalized LMS adaptive filter are Double Talk Detector, Voice Activity Detector, Non-Linear Processor and Howling Control. Normalized Least Mean Squares (NLMS) is the fundamental adaptation algorithm used for estimating and cancelling out the acoustic echo. However, the filter adaptation should only be performed when a far-end speech signal is received through the communication channel. This decision is taken by the Voice Activity Detector (VAD) block. Moreover, when the two talkers on both sides (RIN and SIN) speak at the same time, it is known as a double-talk condition. During double talk, the SIN signal acts as uncorrelated noise and may cause the adaptive filter to diverge from its desired state, thereby reducing the efficacy of the AEC algorithm. This is prevented by the Double-Talk Detection (DTD) block. A Non-Linear Processor (NLP) block is required to remove any residual echo, because the adaptive filter in itself can not model non-linearities in the echo path. DS70134A-page 24 2004 Microchip Technology Inc. Acoustic Echo Cancellation Algorithm 5.4 NLMS ALGORITHM Figure 3.2 illustrates the fundamental principle of Acoustic Echo Cancellation. The far-end signal x(n) traverses the acoustic echo path between the speaker and the microphone (with its impulse response represented here as h), thereby generating an echo. The signal y(n) is the sum of near-end speech t(n) and the echo. The signal y(n) is the near-end signal. FIGURE 5-2: GENERIC ECHO CANCELLER x(n) ^ h ^ y(n) h - y(n) e(n) t(n) The AEC algorithm filters the far-end speech x(n) using a continuously-adapting esti^ mate (with its impulse response represented as h ) of the echo path. It then subtracts the output of this estimated echo path from the `output' (the near-end speech input) of the actual echo path, thereby effectively eliminating the echo from the resultant signal which can then be transmitted over the communication channel. 5.4.1 Bandpass Filters Bandpass filters are used to remove unwanted low frequency and high frequency components of the SIN and RIN signals. The cutoff frequencies for both the bandpass filters are 100 Hz and 3.2 kHz. The bandpass filtering used for this signal pre-processing operation is performed using a cascade of a 2nd order High Pass Filter (HPF) and a 2nd order Low Pass Filter (LPF), with the resultant filter transfer function being Equation 5-1: EQUATION 5-1: S(z) = S1 S2 The transfer function for the HPF is given by Equation 5-2 EQUATION 5-2: S1 ( z ) 0.94597 ( 1.89195z 1 + 0.94597z 2 ) = -1 + 1.88903z 1 0.89487z 2 The transfer function for the LPF is given by Equation 5-3 EQUATION 5-3: S2 ( z ) 2004 Microchip Technology Inc. 0.63894 + 1.27789z 1 + 0.63894z 2 = -1 ( 1.14298z 1 0.41280z 2 ) DS70134A-page 25 dsPIC30F Acoustic Echo Cancellation Library User's Guide 5.4.2 Decorrelation Filters To avoid degradation of the performance of the NLMS algorithm due to the strong correlations of speech signals, each of the speech inputs are "pre-whitened" by applying a Decorrelation Filter, before passing it to the adaptive filter. A Decorrelation Filter is a prediction error filter with its coefficients matched to the correlation properties of the speech signal. Where speech signals are concerned, this serves to increase the convergence rate of the coefficients of the adaptive filter. A 1st order Decorrelation Filter is used to decorrelate the input signal: y(n) = x(n)- (alpha)*x(n-1) An inverse de-correlation filter of the 1st order decorrelation filter is used at the other end to recover the signal. 5.4.3 Adaptive Filter Adaptive step-size control is used to improve the filter performance for speech and to better deal with noisy environments. The step-size µ can be calculated for every 10 ms (80-sample) frame based on the residual echo energy from the previous frame. step_size = (1/(1/step_factor + prev_sout_egy) where: step_size = Variable step size used for adaptation of NLMS filter, prev_sout_energy = Energy contained in previous frame of residual echo, step_factor = Constant term corresponding to a step size of 0.732421875. The purpose of the prev_sout_energy term is to decrease the step size during double talk and noisy conditions when the energy of the frame temporarily increases. Therefore, using adaptive step-size control serves to improve the robustness of the adaptive filter. The impulse response estimate is updated as shown in Equation 5-4. EQUATION 5-4: µ e(n) ^ ^ h k ( n + 1 ) = h k ( n ) + - x ( n k ) N ( Ex ( n ) + ) where: N is the length of the NLMS adaptive filter (512, 256 or 128 taps in this case), e(n) is the difference between the near-end signal y(n) and the predicted signal ^ y ( n ) , given by Equation 5-5 and Equation 5-6, µ is referred to as the adaptive filter loop gain or step-size parameter (0 < µ < 2 for NLMS), is a regularization parameter that prevents division by zero, and eE x ( n ) is the average far-end energy, given by Equation 5-7. EQUATION 5-5: N1 ^ y(n) = ^ hk ( n )x ( n k ) k=0 EQUATION 5-6: ^ e(n) = y(n) y(n) DS70134A-page 26 2004 Microchip Technology Inc. Acoustic Echo Cancellation Algorithm EQUATION 5-7: N1 1 E x ( n ) = - N x2( n k ) k=0 µ should be any value between 0 and 2, so that stability of the NLMS algorithm is ensured. However, a suitable value should be used such that the convergence rate of the adaptation algorithm is fast, divergence rate in the case of double talk is slow and the steady state (residual) error is minimum. The effective value of µ used by the algorithm depends on the average far-end energy. ^ The predicted signal y ( n ) is obtained by filtering the signal x(n) with a filter having a transfer function. Thereafter, the error e(n) is calculated. The average far-end energy E x ( n ) is calculated as described by Equation 5-7. To optimize the calculations for NLMS filter coefficient updates, the AEC algorithm uses the previously calculated error e(n-1), and also uses the previous input signal vector x(n-1). Thus, Equation 5-4 is transformed into: EQUATION 5-8: µ e(n 1) ^ ^ h k ( n + 1 ) = h k ( n ) + - x ( n 1 k ) N Ex ( n ) where Ex(n) is defined by Ex(n) = m2-exp (m is the mantissa and exp is the exponent of the floating point value Ex(n). Therefore, Equation 5-8 can also be written as Equation 5-9. EQUATION 5-9: SF µ e(n 1) 2 2 P 2 exp ^ ^ h k ( n + 1 ) = h k ( n ) + - x ( n 1 k ) m Where: SF = log2(N) p = 1 for Ex(n) > 0x00008000 p = 2 for 0x00008000 < Ex(n) < 0x00000800 Effective Adaptation Step Size is µp = µ2-p Thus, the step size is automatically scaled to obtain a low step size when the far-end energy Ex(n) is low. In general, low far-end energy indicates the absence of far-end speech. When there is no far end speech, the step size gets reduced to prevent divergence of the filter. The constants 0x00008000 and 0x800 represent thresholds for far-end energy, based on which the adaptation step size is altered. Equation 5-9 is used for implementing the adaptation of the NLMS adaptive filter. 2004 Microchip Technology Inc. DS70134A-page 27 dsPIC30F Acoustic Echo Cancellation Library User's Guide The parameters associated with a specified maximum echo delay `td' in ms, for a sampling rate Fs, are shown in Table 5-1: TABLE 5-1: ADAPTIVE FILTER PARAMETERS Constant Parameters Description Value td*Fs N Associated with the implementation of Equation 5-9 log2(N) 5.5 Number of taps of the filter SF Associated with the implementation of Equation 5-4 N DOUBLE TALK DETECTION Double Talk is the condition that occurs as a result of two talkers on both sides (RIN and SIN) talking at the same time. During double talk, the signal SIN acts like uncorrelated noise and may cause the coefficients of the NLMS adaptive filter to diverge, thereby failing to effectively cancel the acoustic echo. To prevent such a condition, a Double Talk Detector (DTD) is used to inhibit adaptation of the filter during periods of simultaneous far-end and near-end speech. In this algorithm, an energy-based double talk detector is used, in which double talk is detected when Average Energy of SOUT > Average Energy of RIN A hang-over time of one 10 ms frame is specified so that if double talk is detected the adaptation is inhibited for one frame beyond the detected end of the double talk condition. 5.6 VOICE ACTIVATION DETECTION Voice Activity Detection (VAD) is used to detect the presence of far-end speech. VAD uses the background noise energy estimate and energy of the current RIN frame to detect speech. A block diagram of the VAD algorithm is shown in Figure 5-3. FIGURE 5-3: VOICE ACTIVITY DETECTOR Far End Speech HPF FFT Band Energy Computation Band SNR Computation VAD VAD Flag If Noise Update Noise Energy 1 Frame Delay DS70134A-page 28 2004 Microchip Technology Inc. Acoustic Echo Cancellation Algorithm 5.6.1 High Pass Filter A High Pass Filter with a cut-off frequency of 80 Hz is used to remove DC and other low frequency components of the far-end speech signal. The output of the HPF is denoted as s'(n). The transfer function of the LPF is described by Equation 5-10. EQUATION 5-10: 0.92727435 1.8544941z 1 + 0.92727435z 2 H ( z ) = 0.5 -1 1.9059465z 1 + 0.9114024z 2 5.6.2 Fast Fourier Transform The input samples are pre-emphasized using Equation 5-11. EQUATION 5-11: d ( n ) = s' ( n ) + ( s' ( n 1 ) ) Where: = -0.8. Pre-emphasized samples are buffered for 10 ms and overlapped with 3 ms of signal samples from the previous frame, thus yielding 104 samples. The resulting buffer is zero-padded with 24 zeros, thereby forming a 128-sample buffer. This buffer is windowed using a smoothed trapezoidal window, as defined in Table 5-2. TABLE 5-2: BUFFER WINDOW COEFFICIENTS Window Coefficient 2 For sin (n + 0.5)/2D) 0n