tonyfu97 / TinyRhythmAnalyzer

TinyML-powered ECG arrhythmia detection on Arduino Nano 33 BLE Sense, comes with a video tutorial

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TinyRhythmAnalyzer

TinyML-powered ECG arrhythmia detection on Arduino Nano 33 BLE Sense

demo_gif


Requirements

Hardware

Software


Disclaimer

This project is a conceptual tool intended for educational and research purposes only. It is not a medical device and should not be used for diagnosing or treating health conditions. The outputs of this project should not be considered accurate or reliable for clinical or diagnostic use. The creators of this project are not liable for any misuse or for any direct or indirect damage that may result from the use of the information provided. Always seek the advice of a qualified healthcare provider with any questions you may have regarding a medical condition or health concerns.


Tutorial

I have recorded a video tutorial for this project: link

TinyRhythmAnalyzer Tutorial

And here are the rough steps:

1. Download the MIT-BIH Arrhythmia Database

Download the MIT-BIH Arrhythmia Database and extract the mit-bih-arrhythmia-database-1.0.0.zip file.

2. Train a TensorFlow Model on Colab

Start a new notebook on Google Colab and upload the MIT-BIH Arrhythmia Database to your Google Drive. Clean the dataset to retain only signals with 'N' and 'V' annotations. Address any class imbalances with SMOTE. Develop a model that processes an array of 10 R-R intervals, predicting if the signal is normal or arrhythmic. Save the trained model as a .tflite file, then hexdump it to a .cpp file.

The model can be either a fully-connected neural network or a 1D convolutional neural network. I used the former for simplicity, but the latter makes more sense for time series data like ECG signals. LSTM networks are also a good option.

3. Write the Arduino Code

Write Arduino Code to extract R-R intervals from the incoming ECG signal.

4. (Optional) Test the Code on Local Machine

Test the code for R-R interval extraction on your local machine using CppUnitLite. Testing the TensorFlow Lite model is a bit more complicated. I recommend cloning the TensorFlow Lite for Microcontrollers and overwriting the tensorflow/lite/micro/examples/hello_world example with your own test code. Then, you can run the test using make -f tensorflow/lite/micro/tools/make/Makefile test_hello_world_test.

5. Test the Code on Arduino

Put together the Arduino sketch and test it on the Arduino Nano 33 BLE Sense. I first use a potentiometer to simulate the ECG signal, just to make sure the code is working. Then, I connect the SparkFun Single Lead Heart Rate Monitor to the Arduino and test the code with real ECG signals.

About

TinyML-powered ECG arrhythmia detection on Arduino Nano 33 BLE Sense, comes with a video tutorial

License:MIT License


Languages

Language:C++ 52.4%Language:Jupyter Notebook 47.2%Language:C 0.3%Language:Makefile 0.2%