> Markdown version of https://www.imranjan.cn/projects/p-msb for AI agents and other programs. It carries the same public information as the web page. Built 2026-11-30.

September 2024 - November 2024

# "Mengsheng Cup" Electronic Design Competition

## Intelligent Sound Source Identification and Localization System

Tags: Hardware System Development, STM32 Programming, Voice Control

![Mengsheng Cup electronic design contest, project cover](https://www.imranjan.cn/images/projects/mengsheng-2024/cover.jpg)

Click to view larger image

#### Complete Source Code

Due to the large number and complex structure of the code files, the complete software source code has been uploaded to a GitHub repository, including Keil code, design reports, MATLAB simulation code, Python analysis code, etc.

[ View on GitHub](https://github.com/narmi924/mengsheng-cup-2024)

### Team Information

#### Guidance

Science and Technology Association, School of Electronic Science and Engineering

Experts from Mengsheng Electronics Company

#### Team Members

- Me Team Leader
- Dilyar Asimjan (School of Computer Science and Engineering) - Algorithm Optimization
- Rifat Memetrexat (School of Electronic Science and Engineering) - Circuit Soldering and Debugging

### Project Background & Requirements

This project originated from Topic D of the 2024 Mengsheng Cup Electronic Design Competition for senior students: "Intelligent Sound Source Identification and Localization System". The competition required designing and building an intelligent system capable of identifying and locating sound sources, achieving precise localization and voice recognition within a predefined measurement area.

#### Specific Task Requirements

- **Hardware Constraints:** The microphone array form can be self-designed, but the number of microphones cannot exceed 5\. The overall size of the system must not exceed the measurement area.
- **Localization Function:** The system must accurately identify the sound source position within 5 preset areas (A, B, C, D, E) with a localization error not exceeding ±5cm.
- **Voice Recognition:** When set to "Recognition Mode", the system must be able to distinguish between 4 commands: "turn on the light", "turn off the light", "turn on the air conditioner", "turn off the air conditioner".
- **Signal Input:** Commands are input via a mobile phone, Bluetooth speaker, or a self-made playback device.
- **Result Display:** Recognition results are displayed in real-time on an LCD screen at the system end.

#### Competition Documents

[ 📄 View Full Project Requirements](https://www.imranjan.cn/files/mengsheng-2024/project-requirements.pdf)

![Top view of the measurement area](https://www.imranjan.cn/images/projects/mengsheng-2024/measurement-area.png)Top view of the system measurement area - 5 preset areas (A, B, C, D, E)

### Solution

In response to the competition requirements, we designed an intelligent sound source identification and localization system based on the STM32H750 microcontroller. The system uses the TDOA (Time Difference of Arrival) algorithm as its core localization technology, achieving high-precision sound source localization with a four-microphone rectangular array, and integrates an ASR-PRO voice recognition module for intelligent voice control.

After rigorous theoretical simulation, hardware debugging, and system testing, we achieved a localization accuracy of ±2cm, surpassing the competition's ±5cm standard, and won the Third Prize in the 2024 Mengsheng Cup Electronic Design Competition.

#### Core Technical Solutions

![](https://www.imranjan.cn/images/projects/mengsheng-2024/icons/highlight-1.svg)

##### TDOA Localization Algorithm

Achieved ±2cm high-precision localization based on time difference principles, exceeding the ±5cm competition requirement.

![](https://www.imranjan.cn/images/projects/mengsheng-2024/icons/highlight-2.svg)

##### Four-Microphone Array

40cm×20cm rectangular layout with an optimized geometric structure to enhance localization accuracy.

![](https://www.imranjan.cn/images/projects/mengsheng-2024/icons/highlight-3.svg)

##### Voice Recognition Integration

Offline recognition of 4 smart home control commands with a response time of <100ms.

![](https://www.imranjan.cn/images/projects/mengsheng-2024/icons/highlight-4.svg)

##### Real-time Signal Processing

STM32H750 400MHz processor ensures the system's real-time performance.

### System Architecture Design

The system adopts a modular design, divided into three main layers: hardware acquisition, algorithm processing, and application control. The hardware layer is responsible for sound signal acquisition and preprocessing, the algorithm layer implements TDOA localization calculations, and the application layer provides user interaction and device control functions.

##### Signal Acquisition Module

A rectangular array of four MAX9814 microphones, combined with a high-precision AD7606 ADC for multi-channel synchronous acquisition.

##### Data Processing Module

The STM32H750 is responsible for real-time signal processing, running the TDOA algorithm to calculate the sound source coordinates.

##### Voice Recognition Module

The ASR-PRO module handles voice command recognition, supporting voice control for devices like lights and air conditioners.

![Overall System Architecture Diagram](https://www.imranjan.cn/images/projects/mengsheng-2024/architecture.png)Overall System Architecture Diagram

### Algorithm Design & Simulation

Before hardware implementation, we first analyzed the signal characteristics of different voice commands using Python. Then, we verified the feasibility of the TDOA (Time Difference of Arrival) algorithm through MATLAB simulation. Finally, we designed the control logic for the ASR-PRO voice recognition module. This complete set of algorithm design and simulation laid a solid theoretical foundation for the hardware implementation.

#### Python Sound Signal Analysis

Using the librosa library to perform frequency-domain analysis and feature extraction on the four voice commands, providing data support for subsequent algorithm design.

pythonSupports multiple audio formats

signal\_analysis.py

```python
import librosa
import numpy as np
import matplotlib.pyplot as plt

# 加载 mp3文件
audio_file = '4.mp3'  #1, 2, 3, 4分别为打开/关闭灯光，打开/关闭空调
y, sr = librosa.load(audio_file, sr=None)

# 绘制波形
plt.figure(figsize=(10, 6))
plt.plot(np.linspace(0, len(y) / sr, len(y)), y)
plt.title("guan bi kong tiao 2m ")
plt.xlabel("Time (s)")
plt.ylabel("Amplitude")
plt.show()

# 计算信号的 RMS（Root Mean Square）值作为信号强度
rms = librosa.feature.rms(y=y)
print(f"RMS value: {np.mean(rms)}")
```

#### Python Sound Signal Analysis Results

A complete signal feature analysis of the four commands—"turn on light," "turn off light," "turn on AC," and "turn off AC"—was conducted using Python's librosa library. The results revealed characteristic differences in the frequency domain, providing a crucial basis for tuning voice recognition algorithm parameters and designing the TDOA localization algorithm.

![Python Sound Signal Analysis Results - Frequency domain feature comparison of the four commands](https://www.imranjan.cn/images/projects/mengsheng-2024/python-analysis-result.png)Python Sound Signal Analysis Results - Frequency domain feature comparison of the four commands

#### TDOA Sound Source Localization Algorithm Simulation

Core algorithm implementation based on the Time Difference of Arrival principle, using an error minimization optimization method to estimate the sound source position.

matlab

tdoa\_localization.m

[ GitHub](https://github.com/narmi924/mengsheng-cup-2024/blob/main/TDOA%E7%AE%97%E6%B3%95%E4%BB%BF%E7%9C%9F.m)

```matlab
close all

% 参数设置
a = 40; % 麦克风阵列的长度（厘米）
b = 20; % 麦克风阵列的宽度（厘米）
fs = 20000; % 采样率
c = 343; % 声速（米/秒）
t = 0:1/fs:1; % 时间轴，信号时长1秒

% 麦克风阵列位置(原代位置取麦克风阵列的中心点）
mic_positions = [-a/2, -b/2;      % 麦克风1
                 a/2, -b/2;       % 麦克风2
                 -a/2, b/2;       % 麦克风3
                 a/2, b/2];       % 麦克风4

% 五个已知区域中心的声源坐标
source_positions = [0, 240;  % A区域
                    -50, 240; % B区域
                    -100, 240; % C区域
                    50, 240; % D区域
                    100, 240]; % E区域

% 从每个麦克风到声源的距离
distances = sqrt(sum((mic_positions - source_position).^2, 2));

% 模拟信号传播延时
delays = distances / c; % 根据距离计算传播延迟
signals = zeros(length(t), 4);
source_signal = sin(2 * pi * 1000 * t); % 生成一个1kHz的测试信号

% 计算TDOA
tdoa = zeros(1, 3); % TDOA between microphone pairs
tdoa(1) = delays(2) - delays(1); % Mic2-Mic1
tdoa(2) = delays(3) - delays(1); % Mic3-Mic1
tdoa(3) = delays(4) - delays(1); % Mic4-Mic1

% 使用最小化误差的优化方法估计声源位置
objective_func = @(pos) sum((sqrt(sum((mic_positions(2:end, :) - pos).^2, 2)) - sqrt(sum((mic_positions(1, :) - pos).^2)) - tdoa' * c).^2);

% 使用fminsearch进行优化，初始位置opoint为(0, 0)
opoint = [0, 0];
estimated_position = fminsearch(objective_func, opoint);
```

#### MATLAB Simulation Verification Results

Extensive simulations were conducted in MATLAB to test localization accuracy at various sound source positions. The results showed that the TDOA algorithm could achieve a localization accuracy of ±2cm under ideal conditions, fully meeting the competition's ±5cm requirement.

![Simulation Result 1 - Area A Sound Source Localization Verification](https://www.imranjan.cn/images/projects/mengsheng-2024/simulation-1.png)Simulation Result 1 - Area A Sound Source Localization Verification

![Simulation Result 2 - Area E Sound Source Localization Verification](https://www.imranjan.cn/images/projects/mengsheng-2024/simulation-2.png)Simulation Result 2 - Area E Sound Source Localization Verification

##### Simulation Analysis Summary

- Conducted 100 random sound source localization tests in the 5 preset areas.
- Average localization error: 1.8cm, Maximum error: 3.2cm.
- Algorithm convergence time: average 15ms, meeting real-time requirements.
- Maintained high accuracy in noisy environments (SNR > 20dB).

#### ASR-PRO Voice Recognition Control

The core control code for the voice recognition module, converting voice commands into device control actions.

cppReal-time response < 100ms

asr\_control.cpp

```cpp
#include "asr.h"

extern "C"{ void * __dso_handle = 0 ;}

#include "setup.h"
#include "myLib/asr_event.h"
#include "HardwareSerial.h"

uint32_t snid;

void ASR_CODE();

/*描述该功能...*/
void ASR_CODE(){
  switch (snid) {
    case 1:
     digitalWrite(4,0);
     Serial.print("11");
     break;
    case 2:
     digitalWrite(4,1);
     Serial.print("22");
     break;
    case 3:
     digitalWrite(2,0);
     Serial.print("33");
     break;
    case 4:
     digitalWrite(2,1);
     Serial.print("44");
     break;
  }
}

void hardware_init(){
  setPinFun(13,SECOND_FUNCTION);
  setPinFun(14,SECOND_FUNCTION);
  Serial.begin(9600);
  vTaskDelete(NULL);
}

void setup()
{
  set_wakeup_forever();

  //{ID:1,keyword:"命令词",ASR:"打开灯光",ASRTO:""}
  //{ID:2,keyword:"命令词",ASR:"关闭灯光",ASRTO:""}
  //{ID:3,keyword:"命令词",ASR:"打开空调",ASRTO:""}
  //{ID:4,keyword:"命令词",ASR:"关闭空调",ASRTO:""}

  setPinFun(4,FIRST_FUNCTION);
  pinMode(4,output);
  setPinFun(4,FIRST_FUNCTION);
}
```

#### ASR-PRO Code Architecture Diagram

The ASR-PRO voice recognition module uses a state machine design pattern. It processes voice recognition results through hardware interrupts, achieving efficient voice command parsing and device control logic.

![ASR-PRO Voice Recognition Control Flowchart](https://www.imranjan.cn/images/projects/mengsheng-2024/asr-code-diagram.png)ASR-PRO Voice Recognition Control Flowchart

### Hardware Design & Implementation

The hardware system is centered around the STM32H750, integrating key components such as a high-precision ADC, microphone array, and voice recognition module. The circuit design fully considered signal integrity and noise suppression to ensure high-quality sound signal acquisition.

The system utilizes a four-microphone rectangular array layout. Through precise time synchronization and signal processing, it achieves high-precision localization of the sound source. All hardware modules have undergone rigorous electromagnetic compatibility design to ensure stable operation in complex electromagnetic environments.

#### Core Processor Module

![STM32H750 Core Board - 400MHz Cortex-M7](https://www.imranjan.cn/images/projects/mengsheng-2024/stm32-board.png)STM32H750 Core Board - 400MHz Cortex-M7

- STM32H750VBT6 microcontroller with a 400MHz clock speed.
- Cortex-M7 core with floating-point unit support.
- 128KB Flash + 1MB RAM.
- Rich peripheral interfaces: SPI, I2C, UART, ADC, etc.

#### Sound Acquisition and Processing Module

- Supports offline voice recognition with a response time of <100ms.
- Built-in noise reduction algorithm adapts to complex acoustic environments.
- Customizable command words with support for Chinese recognition.
- Integrated microphone array interface.

![ASR-PRO Voice Recognition Module](https://www.imranjan.cn/images/projects/mengsheng-2024/asr-pro-module.png)ASR-PRO Voice Recognition Module

#### Analog-to-Digital Converter Module

![AD7606 High-Precision ADC Module](https://www.imranjan.cn/images/projects/mengsheng-2024/ad7606-hardware.png)AD7606 High-Precision ADC Module

- 16-bit resolution, 8-channel simultaneous sampling ADC.
- Maximum sampling rate of 200kSPS, meeting sound signal processing needs.
- Built-in programmable gain amplifier with a gain range of 1-10x.
- Differential input design to effectively suppress common-mode noise.
- SPI/Parallel interface for easy connection with STM32.

#### Microphone Array System

![Four-microphone rectangular array wiring diagram](https://www.imranjan.cn/images/projects/mengsheng-2024/mic-array-wiring.png)Four-microphone rectangular array wiring diagram

A four-microphone rectangular array layout with dimensions of 40cm×20cm is used. High-precision TDOA calculation is achieved through precise geometric layout and time synchronization. Each microphone is precisely phase-calibrated to ensure signal acquisition consistency.

**Array Dimensions:** 40cm × 20cm

**Number of Microphones:** 4 (Rectangular layout)

**Sampling Rate:** 20kHz

**Localization Accuracy:** ±2cm

#### Enclosure 3D Modeling and Printing

To protect the circuit boards and provide an aesthetic appearance, we designed a 3D model of the enclosure using SOLIDWORKS. The design considered the layout of the microphone array, circuit board mounting, heat dissipation, ventilation, and user convenience. After modeling, we used the free 3D printing service on campus to produce the enclosure.

Enclosure 3D Modeling Showcase - SOLIDWORKS

#### Completed System

![Photo of the complete system - Front view](https://www.imranjan.cn/images/projects/mengsheng-2024/system-photo.jpg)Photo of the complete system - Front view

![Photo of the complete system - Top-down view](https://www.imranjan.cn/images/projects/mengsheng-2024/system-photo-2.jpg)Photo of the complete system - Top-down view

The system is highly integrated and compact. Components such as the core processing board, voice recognition module, and microphone array are optimally connected through a well-designed PCB layout for signal transmission and electromagnetic compatibility. The entire machine has undergone rigorous environmental testing to ensure stable operation under various temperature and humidity conditions.

### System Testing & Results

The system underwent rigorous functional testing and performance verification, and finally passed the official test and acceptance at Mengsheng Electronics Company. Key metrics such as localization accuracy, response time, and voice recognition accuracy all met the competition standards. As photography and video recording were prohibited on-site, no official demonstration video is available, but test recordings from the debugging process were kept.

#### System Debugging Demonstration Videos

The following are demonstration videos recorded during the system development and debugging process, showcasing the actual performance of the sound source localization and voice recognition functions.

Debug Video 1 - AD7606 ADC Debugging (13.3MB)

Debug Video 2 - Voice Recognition Functionality Demo (25.9MB)

#### Competition Result

Third Prize (2,000 RMB Prize Money)

![Competition Result](https://www.imranjan.cn/images/projects/mengsheng-2024/盟升杯三等奖证书.png)

### Project Summary

This was our team's first foray into an embedded project of considerable engineering scale. Starting from scratch, we invested a great deal of time in learning and practice. The biggest challenge was on the software side, specifically how to seamlessly feed the multi-channel real-time data collected by the AD7606 into the TDOA localization algorithm for processing. Although we successfully drove all hardware modules and achieved stable voice recognition, we ultimately failed to complete the joint debugging of the localization function due to inexperience with ADC, DMA interrupt handling, and integrating different code libraries. Over a month of full dedication, filled with countless late nights of debugging and exploration, was a journey full of challenges and rewards. We did not give up in the face of difficulties but poured all our energy into it, learning and doing simultaneously within the limited time, experiencing the complete process from theory to practice. Although the final system did not achieve all its intended functions, we built a complete hardware system, overcame most of the software challenges, and more importantly, gained valuable teamwork experience and the ability to solve complex engineering problems. We are proud of what we accomplished and inspired by the regrets that remain.

![Award ceremony](https://www.imranjan.cn/images/projects/mengsheng-2024/颁奖典礼.png)Award ceremony

![Teammate soldering the AD7606](https://www.imranjan.cn/images/projects/mengsheng-2024/队友在焊接.png)Teammate soldering the AD7606

## Other pages

- [Home](https://www.imranjan.cn/index.md)
- [About me](https://www.imranjan.cn/about.md)
- [Projects](https://www.imranjan.cn/projects.md)
- [Photography](https://www.imranjan.cn/gallery.md)
- [LCIMS Cloud](https://www.imranjan.cn/projects/p-lcims.md)
- [imranjan.cn](https://www.imranjan.cn/projects/p-portfolio.md)
- [Open-source tools](https://www.imranjan.cn/projects/p-open-source.md)
- [Gatehouse](https://www.imranjan.cn/projects/p-gatehouse.md)
- [PlusOne](https://www.imranjan.cn/projects/p-plusone.md)
- [Gantry](https://www.imranjan.cn/projects/p-gantry.md)
- [BYOF Agent](https://www.imranjan.cn/projects/p-byof-agent.md)
- [Shopping Copilot by KI](https://www.imranjan.cn/projects/p-shopping-copilot.md)
- [Look2Act](https://www.imranjan.cn/projects/p-look2act.md)
- [AccessAudit - On-Chain Access Approval & Audit System](https://www.imranjan.cn/projects/p-accessaudit.md)
- [Eye Touch - Real-time Eye Tracking and Gaze Control System](https://www.imranjan.cn/projects/p-eyetouch.md)
- [China Collegiate Computer Competition—Mobile Application Innovation Contest](https://www.imranjan.cn/projects/p-yigui.md)
- [Nilufar Restaurant Expense Management System](https://www.imranjan.cn/projects/p-nilufar.md)
- [Voice-Interactive LED Light Panel](https://www.imranjan.cn/projects/p-led.md)
- [NUS SOC SWS 2024](https://www.imranjan.cn/projects/p-nus.md)

中文版本：https://www.imranjan.cn/zh/projects/p-msb.md
