Skip to content

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.

Notifications You must be signed in to change notification settings

Vensim/Embedded_ML

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Embedded ML for ECG applications

pipeline status

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.

ECG Features

Fourier

ML Prediction

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.

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.

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.

python UDP_init_test_mode.py

Gather sample data. Enable sampling server then initialise sampling.

python ECG_sampling_server.py
python UDP_init_sample_mode.py

Example output

img

With sampled data, perform feature extraction

python ECG_feature_extraction.py
python Visualise_ECG_features.py # Optional, to visualise the output.

Feature extraction example output.

img

To generate model with featured data

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

python UDP_init_ML_mode.py

Expected output image

Heart sensor schematic.

image

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published