Skip to content

Commit ca22e95

Browse files
authored
Merge pull request #76 from zhodj/master
HLJU_Pathological_Voice_Diagnosis
2 parents 2fc8cab + 0cd4be6 commit ca22e95

File tree

219 files changed

+59141
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

219 files changed

+59141
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Pathological Voice Diagnosis
2+
3+
* [Introduction](#introduction)
4+
5+
* [Actual Picture](#actual-picture)
6+
* [Function](#function)
7+
* [System Architecture](#system-architecture)
8+
* [Hardware and Software Setup](#hardware-and-software-setup)
9+
* [Required Hardware](#required-hardware)
10+
* [Required Software](#required-software)
11+
* [Hardware Connection](#hardware-connection)
12+
* [User Manual](#user-manual)
13+
* [Before Running This Application](#before-running-this-application)
14+
* [Run This Application](#run-this-application)
15+
16+
## Introduction
17+
This application is based on the ARC IoT Development Kit which work for Pathological speech diagnosis at the edge.Firstly, the diagnostic model of pathological speech classification was trained based on lightweight RBK-NET network, and then the model was deployed using TensorFlow Lite for Microcontrollers (TFLM). Finally, the model was imported into ARC IoTDK development board through OSP.To achieve the Pathological speech diagnosis detection at the edge.
18+
19+
DEMO VIDEO:[Video presentation](https://v.youku.com/v_show/id_XNTE5MjY4NTIzNg==.html)
20+
21+
### Actual Picture
22+
23+
![actual_picture](https://github.com/zhodj/embarc_applications/blob/master/arc_design_contest/2021/HLJU_Pathological_Voice_Diagnosis/images/actual_picture.jpeg)
24+
25+
### Function
26+
27+
- Pathological Voice Diagnosis。At present, healthy and pathological speech can be recognized
28+
29+
- Display the current voice status
30+
31+
### System Architecture
32+
33+
![system_architecture](https://github.com/zhodj/embarc_applications/blob/master/arc_design_contest/2021/HLJU_Pathological_Voice_Diagnosis/images/system_architecture.png)
34+
35+
## Hardware and Software Setup
36+
### Required Hardware
37+
- ARC IoT Development Kit
38+
39+
![ARC IoT Development Kit](https://github.com/zhodj/embarc_applications/blob/master/arc_design_contest/2021/HLJU_Pathological_Voice_Diagnosis/images/arc_iot_development_kit.jpg)
40+
41+
- WM8978 CODEC module
42+
43+
![WM8978 CODEC module](https://github.com/zhodj/embarc_applications/blob/master/arc_design_contest/2021/HLJU_Pathological_Voice_Diagnosis/images/WM8978.png)
44+
45+
- OLED MC096GX (0.96inch )
46+
47+
![OLED MC096GX](https://github.com/zhodj/embarc_applications/blob/master/arc_design_contest/2021/HLJU_Pathological_Voice_Diagnosis/images/oled.png)
48+
49+
### Required Software
50+
- DesignWare ARC MetaWare Development Toolkit
51+
- TensorFlow Lite for Microcontrollers 
52+
- emcARC OSP (github master branch)
53+
- Serial port terminal, such as putty, minicom or cutecom
54+
55+
### Hardware Connection
56+
57+
58+
1.Connect I2C pins of WM8978 to I2C0 of IoT DK.
59+
60+
2.Connect I2S pins of WM8978 to I2S_RX of IoT DK.**The REF_CLK should not be connected untile the initialization of WM8978 is finished**.
61+
62+
3.OLED MC096GX pins.
63+
64+
|OLED MC096GX pins|IoT DK pins |
65+
|-----------------|-------------|
66+
|GND |GND |
67+
|VCC |3.3V |
68+
|SCL |I2C0_SCL |
69+
|SDA |I2C0_SDA |
70+
71+
4.I2C series connection.
72+
73+
![I2C Series Connection](https://github.com/zhodj/embarc_applications/blob/master/arc_design_contest/2021/HLJU_Pathological_Voice_Diagnosis/images/i2c_series_connection.png)
74+
75+
76+
## User Manual
77+
78+
### Before Running This Application
79+
- Download source code of Pathological Voice Diagnosis from github.
80+
- Make sure all the connections are correct.
81+
- The link script file has been modified to ensure the heap and stack are large enough and the addresses of program sections have also been redirected.Make sure the link script is correct.
82+
- Use MWDT compiler tool to compile the source code, which includes Tensorflow Lite and the RBK-NET binary model.
83+
84+
### Run This Application
85+
86+
- Open serial terminal and configure it to right COM port and 115200bps.
87+
- Download with USB-JTAG or use bootloader to boot the program.
88+
- Connect the MCLK(REF_CLK) wire when seeing "Please connet the mclk !"at serial terminal.
89+
- Speak to the Mic. After some seconds, you'll see pathological or healthy result shows on the OLED screen.
90+
91+
#### Makefile
92+
93+
- Selected MLI Lib here, then you can use MLI Lib API in your application:
94+
95+
LIB_SEL = embarc_mli
96+
97+
- Target options about IoT DK and toolchain:
98+
99+
BOARD = iotdk
100+
BD_VER = 10
101+
TOOLCHAIN = mw
102+
103+
- The middleware used in your application:
104+
105+
MID_SEL = common u8glib
106+
107+
See [ embARC Example User Guide][40], **"Options to Hard-Code in the Application Makefile"** for more detailed information about **Makefile Options**.
108+
109+
#### Flie structure
110+
111+
| file | Function |
112+
| ------------------- | -----------------------------------------|
113+
| tensorflow | Tensorflow Lite Micro |
114+
| third_party | Tensorflow Lite Micro third party |
115+
| main.cc | Initialization and main loop |
116+
| Makefile | Makefile |
117+
| mfcc.cc/mfcc.h | Algorithm of extracting mfcc features |
118+
| codec.cc/codec.h | Recive and store audio frames(interrupt)|
119+
| FFT.cc/FFT.h | Fast Fourier transform |
120+
| wm8978.c/wm8978.h | Config wm8978 through I2C |
121+
| wm8978i2s.c/.h | I2S driver |
122+
123+
[0]: ./images/System_Architecture.PNG "system_architecture"
124+
[1]: ./images/ARC_IoT_Development_Kit.jpg "ARC IoT Development Kit"
125+
[2]: ./images/WM8978_CODEC_module.jpg "WM8978 CODEC module"
126+
[3]: ./images/OLED(MC096GX).jpg "OLED MC096GX"
127+
128+
[40]: http://embarc.org/embarc_osp/doc/embARC_Document/html/page_example.html " embARC Example User Guide"
1.21 MB
Loading
5.8 MB
Loading
61.9 KB
Loading
64.5 KB
Loading
139 KB
Loading
319 KB
Loading
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
#include "stdlib.h"
2+
#include "math.h"
3+
4+
//#define __EXTERN_W__
5+
6+
typedef struct
7+
{
8+
float real;
9+
float imag;
10+
} Complex;
11+
12+
#ifdef __EXTERN_W__
13+
//========Paste the definitions for W here========
14+
const Complex FFT_W[15] =
15+
{
16+
{0.98078528040323,-0.195090322016128},
17+
{0.923879532511287,-0.38268343236509},
18+
{0.831469612302545,-0.555570233019602},
19+
{0.707106781186547,-0.707106781186547},
20+
{0.555570233019602,-0.831469612302545},
21+
{0.38268343236509,-0.923879532511287},
22+
{0.195090322016128,-0.98078528040323},
23+
{5.55111512312578E-17,-1},
24+
{-0.195090322016128,-0.98078528040323},
25+
{-0.38268343236509,-0.923879532511287},
26+
{-0.555570233019602,-0.831469612302545},
27+
{-0.707106781186547,-0.707106781186547},
28+
{-0.831469612302545,-0.555570233019602},
29+
{-0.923879532511286,-0.38268343236509},
30+
{-0.98078528040323,-0.195090322016128}
31+
};
32+
const Complex *w = FFT_W;
33+
//================================================
34+
#endif
35+
36+
unsigned char fftx(Complex *d,int m)
37+
{
38+
#ifndef __EXTERN_W__
39+
static Complex *w;
40+
static int mw = 0;
41+
float arg, w_real, w_imag, wr_real, wr_imag, wtemp;
42+
#endif
43+
static int n = 1;
44+
Complex temp, tmp1, tmp2;
45+
Complex *di, *dip, *dj, *wp;
46+
int i, j, k, l, le, wi;
47+
#ifndef __EXTERN_W__
48+
if(m != mw)
49+
{
50+
if(mw != 0)
51+
free(w);
52+
mw = m;
53+
if(m == 0)
54+
return 0;
55+
n = 1 << m;
56+
le = n >> 1;
57+
w = (Complex*)calloc(le - 1,sizeof(Complex));
58+
if(!w)
59+
return 0;
60+
arg = 4.0 * atan(1.0) / le;
61+
wr_real = w_real = cos(arg);
62+
wr_imag = w_imag = -sin(arg);
63+
dj = w;
64+
for(j = 1; j < le; j++)
65+
{
66+
dj->real = (float)wr_real;
67+
dj->imag = (float)wr_imag;
68+
dj++;
69+
wtemp = wr_real * w_real - wr_imag * w_imag;
70+
wr_imag = wr_real * w_imag + wr_imag * w_real;
71+
wr_real = wtemp;
72+
}
73+
}
74+
#else
75+
n = 1 << m;
76+
#endif
77+
le = n;
78+
wi = 1;
79+
for(l = 0; l < m; l++)
80+
{
81+
le >>= 1;
82+
for(i = 0; i < n; i += (le << 1))
83+
{
84+
di = d + i;
85+
dip = di + le;
86+
temp.real = (di->real + dip->real);
87+
temp.imag = (di->imag + dip->imag);
88+
dip->real = (di->real - dip->real);
89+
dip->imag = (di->imag - dip->imag);
90+
*di = temp;
91+
}
92+
wp = (Complex*)w + wi - 1;
93+
for(j = 1; j < le; j++)
94+
{
95+
tmp1 = *wp;
96+
for(i = j; i < n; i += (le << 1))
97+
{
98+
di = d + i;
99+
dip = di + le;
100+
temp.real = (di->real + dip->real);
101+
temp.imag = (di->imag + dip->imag);
102+
tmp2.real = (di->real - dip->real);
103+
tmp2.imag = (di->imag - dip->imag);
104+
dip->real = (tmp2.real * tmp1.real - tmp2.imag * tmp1.imag);
105+
dip->imag = (tmp2.real * tmp1.imag + tmp2.imag * tmp1.real);
106+
*di = temp;
107+
}
108+
wp += wi;
109+
}
110+
wi <<= 1;
111+
}
112+
113+
for(i = 0; i < n; i++)
114+
{
115+
j = 0;
116+
for(k = 0; k < m; k++)
117+
j = (j << 1) | ((i >> k) & 1);
118+
if(i < j)
119+
{
120+
di = d + i;
121+
dj = d + j;
122+
temp = *dj;
123+
*dj = *di;
124+
*di = temp;
125+
}
126+
}
127+
128+
return 1;
129+
}
130+
131+
void AmpSpectrum(Complex *pData,int m,float* pDCAmp,float* pDistortion)
132+
{
133+
// Amp = Abs / (1.414213562 * N)
134+
int i;
135+
int N = 1 << (m - 1);
136+
int N2 = 1 << m;
137+
float BasePower; //exactly BasePower*2*N*N;
138+
float SyntPower = 0; //exactly SyntPower*2*N*N;
139+
float ModelSquare;
140+
*pDCAmp = sqrt(pData[0].real * pData[0].real + pData[0].imag * pData[0].imag) / (N << 1);
141+
BasePower = pData[1].real * pData[1].real + pData[1].imag * pData[1].imag;
142+
pData[N2 - 1].real = sqrt(BasePower);
143+
pData[N2 - 1].imag = asin(pData[N2 - 1].imag / pData[N2 - 1].real);
144+
pData[N2 - 1].real /= N;
145+
for(i = 2; i < N; i++)
146+
{
147+
ModelSquare = pData[i].real * pData[i].real + pData[i].imag * pData[i].imag;
148+
pData[N2 - i].real = sqrt(ModelSquare);
149+
pData[N2 - i].imag = asin(pData[N2-i].imag/pData[N2-i].real);
150+
pData[N2 - i].real /= N;
151+
SyntPower += ModelSquare;
152+
}
153+
*pDistortion = sqrt(SyntPower / BasePower);
154+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "stdlib.h"
2+
#include "math.h"
3+
4+
typedef struct
5+
{
6+
float real;
7+
float imag;
8+
} Complex;
9+
10+
unsigned char fftx(Complex *x,int m);

0 commit comments

Comments
 (0)