Main Content

G.729 Voice Activity Detection for STM32 Processor Based Board

This example shows how to model the ITU-T G.729 Voice Activity Detector (VAD) algorithm and run it on the ARM® Cortex®-M based STMicroelectronics® STM32 boards using Embedded Coder® Support Package for STMicroelectronics STM32 Processors.

The example is categorized into 2 workflows.

STM32CubeMX workflow

  • Available boards - STM32F4xx-based board.

Legacy workflow

  • Available boards - STM32F4-Discovery, STM32F746G-Discovery, STM32F769I-Discovery and STM32F746G-Discovery

  • Support for the legacy workflow will be removed in a future release of MATLAB®

The blocks between the 2 workflows are not compatible with each other. For example, blocks from stm32discoverylib cannot be used in a model set with hardware boards of STM32F4xx Based.

Prerequisites

We recommend completing:

STM32CubeMX Workflow

Discovery Boards (Legacy without CubeMX workflow)

Required Hardware

  • STM32F4xx-based board (CubeMX workflow) or STMicroelectronics STM32F4-Discovery board or STM32F746G-Discovery board.

  • In case A USB TTL-232 adapter for Monitor and Tuning.

Available Versions

Model

To open the model, run this command at the MATLAB® Command Window:

Voice Activity Detection (VAD) is a critical problem in many speech/audio applications including speech coding, speech recognition or speech enhancement. For instance, the ITU-T G.729 standard uses VAD modules to reduce the transmission rate during silence periods of speech.

This example is an extension of the G.729 Voice Activity Detection (DSP System Toolbox) example from the DSP System Toolbox that you can use to simulate the behavior of the audio algorithm on your host computer. Also refer to the Parametric Audio Equalizer for ARM Cortex-M Processor example that explains how to take advantage of the ARM Cortex-M Code Replacement Library (CRL) for DSP functions.

In this example, you will learn how to deploy the G.729 Voice Activity Detection (DSP System Toolbox) algorithm on the STM32 Discovery boards using Simulink®.

Set ARM Cortex-M CMSIS Code Replacement Library (CRL)

The Embedded Coder Support Package for ARM Cortex-M Processors provides an optimized Code Replacement Library for signal processing and math operations.

Set the ARM Cortex-M Code Replacement Library for the

STM32CubeMX Workflow

In the G.729 Voice Activity Detection for STM32F4xx based board example, the model uses a I2S Mic In block from the stm32blockslib to get audio data from the microphone. This block outputs a frame of 16-bit audio samples. The 'I2S Mic In' block is set with a sample frequency of 8kHz. The frame size is set to 80 audio samples to get a 10 millisecond audio frame.

The base rate trigger is automatically selected as the Audio Input in case of STM32F4xx based boards.

STM32 Discovery Boards (Legacy Workflow)

In the G.729 Voice Activity Detection for STM32F4-Discovery Board example model and G.729 Voice Activity Detection for STM32F746G-Discovery Board example model, the model uses a 'Mic In' block and 'Audio In' block from the STM32F4-Discovery library to get audio data from the microphone.

Use the STM32F4-Discovery Mic In Block and Schedule Your Algorithm Based on the Mic In DMA Interrupt

In the G.729 Voice Activity Detection for STM32F4-Discovery Board example, the voice activity detection algorithm uses audio data coming from the microphone available on the STM32F4-Discovery board. The model uses a 'Mic In' block from the STM32F4-Discovery library to get audio data from the microphone. This block outputs a frame of 16-bit audio samples. The 'Mic In' block is set with a sample frequency of 8000Hz. The frame size is set to 80 audio samples to get a 10 millisecond audio frame.

Set the 'Mic In' block to emit a 10 millisecond audio frame following step 2 of the Parametric Audio Equalizer for STM32 Discovery Boards example.

Set the "Mic In" block DMA interrupt as the Base rate trigger for the model following steps 4 and 5 of the Parametric Audio Equalizer for STM32 Discovery Boards example.

Use the STM32F746G-Discovery Audio In Block

In the G.729 Voice Activity Detection for STM32F746G-Discovery Board example model, the voice activity detection algorithm uses audio data coming from the dual microphones available on the STM32F746G-Discovery board. The model uses a 'Audio In' block from the STM32F746G-Discovery library to get audio data from the microphone. This block outputs a frame of 2 channel 16-bit audio samples. The 'Audio In' block is set with a sample frequency of 8000Hz. The frame size is set to 80 audio samples to get a 10 millisecond audio frame.

The base rate trigger is automatically selected as the Audio Input in case of STM32F746G-Discovery.

Extend the G.729 Voice Activity Detection DSP Example

The G.729 Voice Activity Detection (DSP System Toolbox) example describes how to create and simulate a voice activity detection algorithm on your host computer. The algorithm for G.729 Voice Activity Detection is implemented in the following MATLAB® function: vadG729.m. The G.729 Voice Activity Detection for STM32 Discovery Board examples uses vadG729.m inside the following MATLAB Functions (Simulink Check) block: stm32f4discovery_vadG729/VAD_G729.

Configure the Hardware and Model for Monitoring and Tuning

In this task, you will perform Monitor and Tune action for the model. When you are prototyping and developing algorithms, it is useful to monitor signals and tune parameters while the model is running in real-time on the hardware. Monitor and Tune enables this capability.

The Monitor and Tune uses a serial communication interface with the STM32 Discovery board. If you are using the STM32F4-Discovery board, you must use a serial adapter like the USB TTL-232 to exchange data between the host machine and the STM32F4-Discovery board. On the STM32F746G-Discovery board, you will use the serial over USB provided by the same USB connection needed for programming the board. So there is no need for an extra serial connection on the STM32F746G-Discovery board.

Open the VAD model appropriate to your target hardware from above. By default, the model is using serial COM port 28 on the host machine. Refer to Task 5 of the Code Verification and Validation with PIL and Monitoring and Tuning example to configure the model and set the proper connections between the STM32 Discovery board and the host machine.

To start the External mode simulation, switch the model simulation mode to External and click on the Play button as explained in Task 4 of the Code Verification and Validation with PIL and Monitoring and Tuning example.

External mode verbose mode is enabled by default in this example, which enables the display of debug messages for each Monitor and Tune operation.

When voice is detected, a blue LED glows on the STM32F4-Discovery, a green LED glows on the STM32F746G-Discovery board. While running in Monitor and Tune, the signal feeding the LED can be monitored on the Simulink scope indicating detection of voice.

Summary

This example showed how to deploy the G.729 Voice Activity Detection (VAD) algorithm on the STM32 Discovery boards. It demonstrated how to use the microphone available on the board to get a speech signal as well as an LED to display VAD results using Monitor and Tune and Code Replacement Library (CRL) for ARM Cortex-M CMSIS DSP functions.