https://github.com/vensim/embedded_ml
Application of TinyML on an ESP32 system. To sample ECG data, feature gather and output new ML model based on sampled data to be re-compiled into ESP32.
https://github.com/vensim/embedded_ml
data-processing ecg esp32 esp32-arduino machine-learning sampling tinyml
Last synced: 8 months ago
JSON representation
Application of TinyML on an ESP32 system. To sample ECG data, feature gather and output new ML model based on sampled data to be re-compiled into ESP32.
- Host: GitHub
- URL: https://github.com/vensim/embedded_ml
- Owner: Vensim
- Created: 2021-03-31T16:30:44.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-06-21T18:26:34.000Z (over 1 year ago)
- Last Synced: 2025-04-16T01:54:31.733Z (8 months ago)
- Topics: data-processing, ecg, esp32, esp32-arduino, machine-learning, sampling, tinyml
- Language: Python
- Homepage:
- Size: 923 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Embedded ML for ECG applications
[](https://gitlab.com/Sesven/Embedded_ML/-/commits/main)
## Introduction
> Objective of this repository is to acquire experience in developing products and to get familiar with new technologies. Secondary objective is to create a framework of sensor to machine learning starting with raw electrocardiogram data with the intent of quantize how deviated the heart wave is from sample data and in addition to predict future heart states with different activities. In the future different sensors could be applied such as electromyography sensors.
Server-runner added.




## Current progress
Goal | Progress
------------ | -------------
ECG to ESP data aquisition | Y
ESP UDP control | Y
ESP UDP data transmission | Y
Feature extraction | Basic
Machine Learning model | In progress
ESP Prediction | In progress
Analog input produces 50~ Hertz noise, research into implementing Low-pass filter
Implement windowing to individual heart pulses for additional feature extraction
Find way to change Machine Learning model, the hex array, without recompiling whole program.
## Installation
Optional:
Initialise virtual python env.
```bash
conda create -n EmbeddedML_env python=3.8.5
conda activate EmbeddedML_env
pip install requirements.txt
```
Initialise system variables with bash script. This will give prompt for ESSID, Password and UDP IP configurations.
```bash
chmod +x env_init.sh
./env_init.sh
```
Or edit the script files and the ESP32.ino file manually.
Will output network interface configuration. Use the ip the python scripts will be run off.
Install the ESP32 arduino program with new initialised values.
Place ECG electrodes.
Image from ConnectMed.com

Test the output of the ECG sensor in a serial monitor.
```bash
python UDP_init_test_mode.py
```
Gather sample data. Enable sampling server then initialise sampling.
```bash
python ECG_sampling_server.py
python UDP_init_sample_mode.py
```
Example output

With sampled data, perform feature extraction
```bash
python ECG_feature_extraction.py
python Visualise_ECG_features.py # Optional, to visualise the output.
```
Feature extraction example output.

To generate model with featured data
```bash
python ECG_ML_Modelgen.py
```
This script will produce 2 files, ECG_model_quantized.tflite and ECG_ML_Model.h.
ECG_ML_Model.h to be used with Arduino IDE as header file.
Recompile the ESP32 with the new header file and activate Machine Learning mode
```bash
python UDP_init_ML_mode.py
```
Expected output

Heart sensor schematic.
