-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: this PR adds blog for EMG Armband. (#50)
* added code walkthorugh of the blog * added git repo * added bloogh * fix typos * fixed bg * bg fix wont work * removedf the bg * Update 2024-07-26-how-does-emg-armband-work.md * added final things * fixed the .ds_store issue, fml * added updates on *weekly* basis * added lore about ml and esp_now protocall * revert changes
- Loading branch information
Showing
8 changed files
with
446 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
--- | ||
layout: post | ||
title: EMG Armband, The Conclusion | ||
tags: ML Systems IoT PCB Designing Embedded | ||
description: Developing an EMG system that can understand human hand motions. | ||
--- | ||
|
||
## Mentees: | ||
- [Shaunak Datar](https://github.com/ShaunakKDatar) | ||
- [Piyush Patle](https://github.com/PiyushPatle26) | ||
- [Atharva Kshirsagar](https://github.com/vovw) | ||
|
||
### This project is sponsored by [Upside Down Labs](https://upsidedownlabs.tech/) | ||
![up](/assets/posts/emg-armband/upside_down.svg) | ||
### GitHub Repo: [vovw/emgband](https://github.com/vovw/emgband) | ||
|
||
# What is our project? | ||
We read Electromyography (EMG) data using sensors, amplify it, filter it, perform ADC conversion, and conduct a frequency analysis (FFT) on it. Using the analyzed data, we train an ML model that can understand what hand movement was performed to get those readings. | ||
|
||
![Hardware Flow](/assets/posts/emg-armband/hardware_flow.png) | ||
|
||
# What work has been done? | ||
- Initially, we *attempted* to approach this problem from first principles. We implemented the **biopotential signal-acquisition board** from scratch but encountered some issues. | ||
- We then pivoted temporarily to using Upside Down Labs' [EXG Pill](https://github.com/upsidedownlabs/BioAmp-EXG-Pill), which works well. | ||
(Add images of the readings) | ||
|
||
## Signal Processing: | ||
- The raw signal goes through a bandpass filter to focus on frequencies between 75 and 150 Hz. | ||
- This filtering helps remove noise and focus on the most relevant part of the EMG signal. | ||
|
||
## ADC (Analog-to-Digital Converter) | ||
- Converts the continuous analog signal from the sensor into digital values the microcontroller can process. | ||
- We utilized the entire 12-bit ADC provided in the ESP32. | ||
- We later bound the values and mapped them to reduce the 0-4095 range to 0-1000 readings. | ||
|
||
## Bandpass Filter: | ||
- A filter that allows signals between two specific frequencies to pass through while blocking others. | ||
- A bandpass filter which filters the signal and returns a 72.5-725Hz signal is included in the Bio-amp EXG Pill. | ||
- Additionally, we implemented a Band-Pass Butterworth IIR digital filter generated using filter_gen.py. | ||
|
||
## Frequency Analysis: | ||
- The code uses the Fast Fourier Transform (FFT) to convert the time-domain signal into frequency components. | ||
- This helps identify which frequencies are most prominent in the EMG signal. | ||
- We used the [Cooley-Tukey Algorithm](https://en.wikipedia.org/wiki/Cooley%E2%80%93Tukey_FFT_algorithm) for the Fast Fourier Transform. | ||
|
||
![FFT](/assets/posts/emg-armband/fft.png) | ||
|
||
## ESP-now | ||
|
||
WIP code implimentation - [vovw/emgband](https://github.com/vovw/emgband/commit/8a69945c57ba3d73bbc88cc48f8bd2ccd03453a0) | ||
|
||
1. **ESP-NOW Sender Configuration**: | ||
- The sender code initializes ESP-NOW and sets up a task to periodically send sensor data (ADC readings) to a broadcast address. | ||
- The sensor data is read from a GPIO pin using the ADC module. | ||
- The sender registers a peer with a broadcast address and sends data using `esp_now_send`. | ||
|
||
2. **ESP-NOW Receiver Configuration**: | ||
- The receiver code initializes ESP-NOW and registers a callback function to handle incoming data. | ||
- The receiver adds a peer with a specific MAC address (sender's address) to receive data. | ||
- The received data is written to a file in the SPIFFS filesystem for storage and further processing. | ||
|
||
3. **File System Integration**: | ||
- The receiver uses the LittleFS file system to store the received data in a file named `output.txt`. | ||
- The file system is initialized and a file is created to store the incoming data. | ||
|
||
We have successfully implemented ESP-NOW communication between two ESP32 devices. The sender device reads ADC data from a GPIO pin and sends it to the receiver using ESP-NOW. The receiver device receives the data and stores it in a file on the LittleFS file system. | ||
|
||
#### here is the complete flow of how it works | ||
![Flow](/assets/posts/emg-armband/flow.png) | ||
|
||
## Storing the Signal | ||
To train our Machine Learning Model, we need to store the readings as data. We initially decided to label two events: Finger Moving and Palm Closing. | ||
|
||
We output the data in frequency bins generated by the FFT on the serial port and store it in a .txt file. We wrote a Python script that maps this data from .txt to a CSV format, making it easier to read using pandas in our Model script. | ||
|
||
## Machine learning | ||
[vovw/emgband/ml](https://github.com/vovw/emgband/tree/main/ml) | ||
|
||
We are currently expirementing with different architecture mainly a simple [feed forward network](https://en.wikipedia.org/wiki/Feedforward_neural_network) and [classfication](https://en.wikipedia.org/wiki/Statistical_classification). Depending on the loss curves and which architecture fits the traning data better we will decide to go with that one. | ||
|
||
#### planned ml ML for the EMG system | ||
![ml](/assets/posts/emg-armband/ml.png) | ||
|
||
|
||
# Updates on weekly basis | ||
|
||
## Week 1: Fundamentals and Electronic Components | ||
- Gained understanding of operational amplifiers | ||
- Studied bandpass filters | ||
- Explored essential electronic components for bio-amplifiers | ||
- Introduced to basic neural networks and their implementation | ||
|
||
## Week 2: Hardware Acquisition and Signal Understanding | ||
- Received components from Upside Down Labs | ||
- Focused on understanding EMG bio-amplifier output signals, specifically the EXG Pill | ||
- Studied open-source documentation and repositories | ||
- Experimented with basic machine learning papers and algorithms | ||
|
||
## Week 3: Signal Processing and Machine Learning Foundations | ||
- Implemented Fast Fourier Transform (FFT) code | ||
- Worked on Analog-to-Digital Conversion (ADC) | ||
- Adapted Arduino code for ESP32 platform | ||
- Studied optimization algorithms: | ||
- Gradient descent | ||
- Backpropagation | ||
|
||
## Week 4: Data Collection and Wireless Communication | ||
- Developed Python script for: | ||
- Data collection | ||
- Data cleaning | ||
- CSV storage | ||
- Implemented ESP-NOW protocol for communication between two ESP32 devices: | ||
- One connected to the computer | ||
- One connected to the hand band | ||
- Progress towards creating a wireless EMG band | ||
|
||
The following weeks dictate the project flow: | ||
|
||
## Week 5: Comprehensive Data Collection | ||
- Gather data for various hand movements: | ||
- Individual finger movements | ||
- Clenching and relaxing wrists | ||
- Thumbs up and thumbs down gestures | ||
- Focus on data cleaning and preparation | ||
|
||
![hand](/assets/posts/emg-armband/claw.png) | ||
|
||
## Week 6: Model Development and Embedded Implementation | ||
- Create a sequential model | ||
- Train the model on collected data | ||
- Experiment with different architectures to optimize output | ||
- Convert the trained model to TensorFlow Lite format | ||
- Run the model locally on ESP32 | ||
|
||
## Week 7: Hardware Integration and Enclosure | ||
- Design and create hardware casing to enclose: | ||
- Three Upside Down Labs Patchy devices | ||
- Amplifiers | ||
- ESP32 microcontroller | ||
- Focus on developing a clean and efficient system | ||
![emg](/assets/posts/emg-armband/emg.png) | ||
|
||
## Week 8: Web Integration and Future Applications | ||
- Develop a web server for data visualization and control | ||
- Explore potential applications of our EMG system |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.