AN3998 Application note



Similar documents
AN3332 Application note

EVL185W-LEDTV. 185 W power supply with PFC and standby supply for LED TV based on the L6564, L6599A and Viper27L. Features.

AN3354 Application note

TN0023 Technical note

BD238. Low voltage PNP power transistor. Features. Applications. Description. Low saturation voltage PNP transistor

DDSL01. Secondary protection for DSL lines. Features. Description

AN4108 Application note

Single LNB supply and control IC DiSEqC 1.X compliant with EXTM based on the LNBH29 in a QFN16 (4x4) Description

SPC5-FLASHER. Flash management tool for SPC56xx family. Description. Features

AN2604 Application note

AN2389 Application note

AN3265 Application note

2STBN15D100. Low voltage NPN power Darlington transistor. Features. Application. Description

BD241A BD241C. NPN power transistors. Features. Applications. Description. NPN transistors. Audio, general purpose switching and amplifier transistors

AN3997 Application note

AN4156 Application note

ULN2801A, ULN2802A, ULN2803A, ULN2804A

AN2680 Application note

UM0985 User manual. Developing your STM32VLDISCOVERY application using the IAR Embedded Workbench software. Introduction

Description. IO and RF AGC. ASIC controller and power management. Carrier recovery loop. GPIO switch matrix. Lock indicator and monitoring DVBS2 FEC

UM1676 User manual. Getting started with.net Micro Framework on the STM32F429 Discovery kit. Introduction

How To Write To An Eeprom Memory On A Flash Memory On An Iphone Or Ipro Memory On Microsoft Flash Memory (Eeprom) On A Microsoft Microsoft Powerbook (Ai) 2.2.2

AN3252 Application note

ST High voltage fast-switching NPN power transistor. Features. Applications. Description

BD135 - BD136 BD139 - BD140

AN2824 Application note

AN3270 Application note

M24LRxx/CR95HF application software installation guide

LM337. Three-terminal adjustable negative voltage regulators. Features. Description

MC Low noise quad operational amplifier. Features. Description

L78MxxAB L78MxxAC. Precision 500 ma regulators. Features. Description

UM1727 User manual. Getting started with STM32 Nucleo board software development tools. Introduction

UM1680 User manual. Getting started with STM32F429 Discovery software development tools. Introduction

AN3353 Application note

AN3110 Application note

STEVAL-IEG001V2. Smart real-time vehicle tracking system. Features

UM1790 User manual. Getting started with STM32L053 discovery kit software development tools. Introduction

AN3990 Application note

ETP01-xx21. Protection for Ethernet lines. Features. Description. Applications. Benefits. Complies with the following standards

EN: This Datasheet is presented by the m anufacturer. Please v isit our website for pricing and availability at ore.hu.

DSL01-xxxSC5. Secondary protection for DSL lines. Features. Description. Applications. Benefits. Complies with the following standards

LM134-LM234-LM334. Three terminal adjustable current sources. Features. Description

Description. Table 1. Device summary. Order code Temperature range Package Packaging Marking

AN2557 Application note

ULN2001, ULN2002 ULN2003, ULN2004

ST19NP18-TPM-I2C. Trusted Platform Module (TPM) with I²C Interface. Features

AN2760 Application note

Table 1. Absolute maximum ratings (T amb = 25 C) Symbol Parameter Value Unit. ISO C = 330 pf, R = 330 Ω : Contact discharge Air discharge

Description. Table 1. Device summary

AN3359 Application note

TDA W CAR RADIO AUDIO AMPLIFIER

SPC5-CRYP-LIB. SPC5 Software Cryptography Library. Description. Features. SHA-512 Random engine based on DRBG-AES-128

AN2866 Application note

UA741. General-purpose single operational amplifier. Features. Applications. Description. N DIP8 (plastic package)

ESDLIN1524BJ. Transil, transient voltage surge suppressor diode for ESD protection. Features. Description SOD323

BZW50. Transil, transient voltage surge suppressor (TVS) Features. Description

TDA2004R W stereo amplifier for car radio. Features. Description

Getting started with DfuSe USB device firmware upgrade STMicroelectronics extension

AN3155 Application note

LM135-LM235-LM335. Precision temperature sensors. Features. Description

UM1613 User manual. 16-pin smartcard interface ST8034P demonstration board. Introduction

STDP2690. Advanced DisplayPort to DisplayPort (dual mode) converter. Features. Applications

AN4368 Application note

L6234. Three phase motor driver. Features. Description

STP60NF06. N-channel 60V Ω - 60A TO-220 STripFET II Power MOSFET. General features. Description. Internal schematic diagram.

Description. Table 1. Device summary. Order codes. TO-220 (single gauge) TO-220 (double gauge) D²PAK (tape and reel) TO-220FP

Order code Temperature range Package Packaging

STN3NF06L. N-channel 60 V, 0.07 Ω, 4 A, SOT-223 STripFET II Power MOSFET. Features. Application. Description

STTH2R06. High efficiency ultrafast diode. Features. Description

STP60NF06FP. N-channel 60V Ω - 30A TO-220FP STripFET II Power MOSFET. General features. Description. Internal schematic diagram.

Description SO-8. series. Furthermore, in the 8-pin configuration Very low-dropout voltage (0.2 V typ.)

AN4128 Application note

STTH1R04-Y. Automotive ultrafast recovery diode. Features. Description

AN2328 Application note

P6KE. Transil, transient voltage surge suppressor (TVS) Features. Description. Complies with the following standards

AN1754 APPLICATION NOTE

AN974 APPLICATION NOTE

STDP2600. Advanced HDMI to DisplayPort (dual mode) converter. Features. Applications

STP55NF06L STB55NF06L - STB55NF06L-1

AN2703 Application note

Obsolete Product(s) - Obsolete Product(s)

STDP4328. DisplayPort 1.2a concentrator. Features. Applications

STGB10NB37LZ STGP10NB37LZ

AN1819 APPLICATION NOTE Bad Block Management in Single Level Cell NAND Flash Memories

AN3211 Application note

STP10NK80ZFP STP10NK80Z - STW10NK80Z

STDP4320. DisplayPort 1.2a splitter. Features. Applications

AN820 APPLICATION NOTE INPUT/OUTPUT PROTECTION FOR AUTOMOTIVE COMPUTER

AN4646 Application note

TDA CHANNEL VOLUME CONTROLLER 1 FEATURES 2 DESCRIPTION. Figure 1. Package

STCS A max constant current LED driver. Features. Applications. Description

AN2658 Application note

UM0834 User manual. Developing and debugging your STM8S-DISCOVERY application code. Introduction. Reference documents

UM1075 User manual. ST-LINK/V2 in-circuit debugger/programmer for STM8 and STM32. Introduction

AN4427 Application note

STB4NK60Z, STB4NK60Z-1, STD4NK60Z STD4NK60Z-1, STP4NK60Z,STP4NK60ZFP

STLM20. Ultra-low current 2.4 V precision analog temperature sensor. Features. Applications

STCS1A. 1.5 A max constant current LED driver. Features. Applications. Description

AN3969 Application note

Transcription:

Application note PDM audio software decoding on STM32 microcontrollers 1 Introduction This application note presents the algorithms and architecture of an optimized software implementation for PDM signal decoding and audio signal reconstruction when connecting an ST MP45DT02 MEMS microphone with an STM32 microcontroller. It can directly take the Pulse Density Modulated (PDM) data output from the microphone and convert it to 16-bit pulse-code modulation (PCM) format. This document also provides quick start information describing how to implement the PDM Library for single microphone acquisition via I2S based on the STM32F4 microcontroller and STM32F4DISCOVERY board. For more details about this implementation, please refer to AN3997 Audio playback and recording using the STM32F4DISCOVERY. October 2011 Doc ID 022391 Rev 1 1/10 www.st.com

Contents AN3998 Contents 1 Introduction................................................ 1 2 PDM signal introduction...................................... 4 3 Hardware interface: microphone connection and acquisition....... 5 4 Software interface: digital signal processing..................... 6 4.1 PDM digital filtering and decimation.............................. 6 4.2 Digital signal conditioning...................................... 6 5 PDM audio software decoding library description................. 7 5.1 PDM_Filter_Init.............................................. 7 5.2 PDM_Filter_xx_xx........................................... 8 6 Revision history............................................ 9 2/10 Doc ID 022391 Rev 1

List of figures List of figures Figure 1. Block diagram of a microphone connection to an STM32........................... 5 Figure 2. Digital signal processing.................................................... 6 Doc ID 022391 Rev 1 3/10

PDM signal introduction AN3998 2 PDM signal introduction Pulse density modulation, or PDM, is a form of modulation used to represent an analog signal in the digital domain. In a PDM signal, specific amplitude values are not encoded into pulses as they would be in PCM. Instead it is the relative density of the pulses that corresponds to the analog signal's amplitude. To get the framed data from the PDM bit stream, decimation filters are usually used. The first stage of decimation is used to reduce the sampling frequency, followed by a high pass filter to remove the signal DC offset. 4/10 Doc ID 022391 Rev 1

Hardware interface: microphone connection and acquisition 3 Hardware interface: microphone connection and acquisition The MP45DT02 MEMS microphone outputs a PDM signal, which is a high frequency (1 to 3.25 MHz) stream of 1-bit digital samples. This output is acquired in blocks of 8 samples by using a synchronous serial port (SPI or I2S) of the STM32 microcontroller. The microphone's PDM output is synchronous with its input clock; therefore an STM32 SPI/ I2S peripheral generates a clock signal for the microphone. Figure 1. Block diagram of a microphone connection to an STM32. STM32 Internal Flash Microphone MEMS I2S clk to MIC clk USB key MIC Data to I2S SD I2S PDM Lib MS19892V1 Doc ID 022391 Rev 1 5/10

Software interface: digital signal processing AN3998 4 Software interface: digital signal processing The data coming from the microphone is sent to the decimation process, which consists of two parts: a decimation filter converting 1-bit PDM data to PCM data, followed by two individually configurable IIR filters (low pass and high pass). The reconstructed audio is in 16-bit pulse-code modulation (PCM) format. After the conversion, it produces raw data that can be handled depending on the application implementation (stored as wave/compressed data in a mass storage media, transferred to an external audio codec DAC through I2S peripheral...). Figure 2. Digital signal processing PDM in PDM digital filtering and decimation Digital signal conditioning Audio out MS19893V1 4.1 PDM digital filtering and decimation The PDM signal from the microphone is filtered and decimated in order to obtain a sound signal at the required frequency and resolution. The frequency of the PDM data output from the microphone (which is the clock input to the microphone) must be a multiple of the final audio output needed from the system. For example, to perform a decimation of 80, for the output rate of 30 khz, we need to provide a clock frequency 2.4MHz to the microphone. The output of the filter pipeline is a 16-bit value, we consider [-32768, 32767] as the output range for a unitary gain (0 db). 4.2 Digital signal conditioning The digital audio signal resulting from the previous filter pipeline is further processed for proper signal conditioning. The first stage is a high pass filter designed mainly to remove the signal DC offset. It has been implemented via an IIR filter with a cut-off frequency below the audible frequency range in order to preserve signal quality. The second stage is a low pass filter implemented using an IIR filter. Both filters can be enabled/disabled and configured (cut-off frequencies) by using the filter initialization function.gain can be controlled by an external integer variable (MicGain) as shown in the following equation: G = MicGain/64. 6/10 Doc ID 022391 Rev 1

PDM audio software decoding library description 5 PDM audio software decoding library description The PDM library is composed of a structure and the implementation of four PDM filter functions. The library uses two buffers, the PDM Input buffer and the PCM Output buffer; the application must define these buffers in the main program. Input buffer (data) is a uint8 variable with a length equal to (Output frequency / 1000 * decimation factor * Input Microphone Channels / 8) at least. Output buffer (dataout) is a uint16 variable with a length equal to (Output frequency / 1000 * Output Microphone Channels) at least. The structure is defined in the pdm_filter.h file and is used to configure the filter; it is composed as follows: typedef struct { uint16_t Fs; float LP_HZ; float HP_HZ; uint16_t Out_MicChannels; char InternalFilter[34]; } PDMFilter_InitStruct; Fs: Defines the frequency output of the filter in Hz. LP_HZ: Defines the low pass filter cut-off frequency. If 0, the low pass filter is disabled. HP_HZ: Defines the high pass filter cut frequency. If 0, the high pass filter is disabled. In_MicChannels: Define the number of microphones in the input stream. This parameter is used to specify the interlacing of microphones in the input buffer. The PDM samples are grouped eight by eight in u8 format (8-bit). Out_MicChannels: Defines the number of microphones in the output stream; this parameter is used to interlace different microphones in the output buffer. Each sample is a 16-bit value. InternalFilter: Defines a 34 Byte memory used internally by the library during the PDM decimation step. The PDM audio software decoding library includes one header file pdm_filter.h and binary/object codes for the following platforms: libpdmfilter_iar.a : for IAR compiler libpdmfilter_keil.lib : for ARM compiler libpdmfilter_gcc.a : for GNU compiler This Library is provided in the "STM32F4-DISCOVERY board firmware package" (V1.10 and later) under the following path 'Utilities\STM32F4-Discovery' 5.1 PDM_Filter_Init This function is used to initialize the filter of a single output channel. It is defined as follows: Void PDM_Filter_Init (PDMFilter_InitStruct * Filter) Doc ID 022391 Rev 1 7/10

PDM audio software decoding library description AN3998 It initializes the PDM Filter, according to the parameters specified in the PDMFilter_InitStruct. The following is an example of filter initialization for a single microphone with a PDM at 16 khz: PDMFilter_InitStruct Filter; Filter.LP_HZ = 8000; Filter.HP_HZ = 10; Filter.Fs = 16000; Filter.Out_MicChannels = 1; Filter.In_MicChannels = 1; PDM_Filter_Init ((PDMFilter_InitStruct *) Filter); Before calling the PDM_Filter_Init() function, the application code must enable the clock of the STM32 microcontroller CRC peripheral (configuration done in RCC register). Otherwise, the PDM_Filter_Init() function will fail and go into an infinite loop. 5.2 PDM_Filter_xx_xx These functions are used to process a millisecond of PDM data from a single microphone. They return a number of PCM samples equal to the frequency defined in the filter initialization, divided by 1000. In case of frequencies that are not multiple of 1000 (like 44100 Hz or 22050 Hz), the samples returned by the function are equal to the floor division of the frequencies (44 and 22). The functions are defined as follows: PDM_Filter_XX_XX(uint8_t* data, uint16_t* dataout, uint16_t MicGain, PDMFilter_InitStruct * Filter) data: is the input buffer containing the PDM; the application must pass to the function the pointer to the first input sample of the microphone that must be processed. dataout: is the output buffer processed by the PDM_Filter function. The application must pass to the function the pointer to the first sample of the channel to be obtained. Volume: is a value between 0 and 64 used to specify the microphone gain. Filter: is the structure containing all the filter parameters specified by the user using the PDM_Filter_Init function. There are four different implementations of this function depending on the decimation factor (64 or 80) and on the LSB or MSB representation of the input buffer. 8/10 Doc ID 022391 Rev 1

Revision history 6 Revision history Table 1. Document revision history Date Revision Changes 27-Oct-2011 1 Initial release. Doc ID 022391 Rev 1 9/10

Please Read Carefully: Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries ( ST ) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any time, without notice. All ST products are sold pursuant to ST s terms and conditions of sale. Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no liability whatsoever relating to the choice, selection or use of the ST products and services described herein. No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein. UNLESS OTHERWISE SET FORTH IN ST S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT. UNLESS EXPRESSLY APPROVED IN WRITING BY TWO AUTHORIZED ST REPRESENTATIVES, ST PRODUCTS ARE NOT RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY, DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER S OWN RISK. Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any liability of ST. ST and the ST logo are trademarks or registered trademarks of ST in various countries. Information in this document supersedes and replaces all information previously supplied. The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners. 2011 STMicroelectronics - All rights reserved STMicroelectronics group of companies Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan - Malaysia - Malta - Morocco - Philippines - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America www.st.com 10/10 Doc ID 022391 Rev 1