Skip to content

Latest commit

Β 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Project Banner

Stress-Level Management via Smartwatch Monitoring

A complete end-to-end IoT solution for real-time stress detection. This system utilizes a hybrid Deep Learning model (CNN+GRU) deployed on a Wear OS smartwatch to analyze sensor data, syncs results via Firebase, and visualizes live stress events on a React web dashboard.

Academic Project β€’ Machine Learning: Supervised Tehniques β€’ Faculty of Electrical Engineering (ETF) Sarajevo

Python PyTorch Android Kotlin React Firebase License


πŸ“‹ Table of Contents

🎯 Overview

Stress is a prevalent health issue affecting productivity and well-being. While many wearables track heart rate, few offer real-time, medical-grade stress classification.

This project implements a Multimodal Stress Monitoring System that:

  1. Analyzes physiological data (HRV, EDA, BVP, Temp) using Deep Learning.
  2. Performs Inference directly on the wearable device (Edge AI).
  3. Streams data to the cloud for remote monitoring.

The system was developed through rigorous phases: from EDA and baseline LSTM models to a refined Hybrid CNN + GRU architecture optimized for mobile deployment.

πŸŽ₯ Demos & Live Dashboards

πŸ”΄ Live Prototypes

The wearable dashboard is currently deployed and listening for live events from wearable devices. View Live Dashboard

The survey-based webapp is currently deployed and ready for use. Visit Web App

πŸ“Ή Prototypes Video Showcase

Wearable Prototype Survey-Based Prototype

1st: A showcase of the Wearable app performing inference and the React Dashboard updating in real-time.

2st: A showcase of the Survey-based webapp performing inference in real-time.

βš™οΈ System Architecture

The solution consists of three main components connected via the cloud:

  1. Wearable Device (Android): Simulates sensor data collection and runs the .pt (PyTorch Lite) model for on-device inference.
  2. Backend (Firebase): Acts as the real-time bridge, storing sensor readings and stress labels with timestamp validation.
  3. Frontend (React Dashboard): A live interface for visualizing stress trends, heart rate variability, and historical logs.

Architecture Diagram

🧠 Machine Learning Pipeline

We experimented with 9 different architectures before finalizing the edge model.

ML Pipeline Diagram

1. Data Processing

  • Input: 30-second windows of physiological signals (BVP, EDA, Temp).
  • Preprocessing: Normalization, Sliding Window Segmentation.
  • Feature Selection: Reduced input size to 5 critical features (MEAN_RR, SDRR, RMSSD, HR, pNN50) to ensure high performance on limited smartwatch hardware.

2. Model Evolution

  • Baseline: LSTM (Long Short-Term Memory).
  • Intermediate: Bi-LSTM (inspired by xLSTM) and ResNet.
  • Top Performers: CNN (Convolutional Neural Networks) and GRU (Gated Recurrent Units).

3. Final Architecture: Hybrid CNN + GRU

For the wearable application, we combined the strengths of both top models:

  • CNN Layers: Extract spatial features (patterns in physiological spikes) from sensor signals.
  • GRU Layers: Capture temporal dependencies over the 30-step window. It is faster and more "mobile-friendly" than a standard LSTM.
  • Performance: The hybrid model showed realistic generalization (avoiding pure CNN overfitting) and was exported as stress_model.pt for Android.

Final Model Diagram

πŸ“± Prototypes

⌚ Wearable App (Kotlin)

Built in Android Studio. It reads sensor data (simulated for testing stability), processes it through the PyTorch model, and displays:

  • Real-time BPM.
  • Stress Label (Relaxed, Stressed, Interrupted).
  • Uploads data to Firebase (optimized with debounce to prevent API spam).

πŸ’» Web Dashboard (React.js)

A Dark-mode UI hosted on Firebase.

  • Live Connection: Listens to Firebase Realtime Database.
  • Visuals: Dynamic cards with Sparkline charts for heart rate.
  • Alerts: Visual feedback for "Stressed" (Red) or "Interrupted" (Yellow) states.

πŸ“‚ Repository Structure

β”œβ”€β”€ Code
β”‚   β”œβ”€β”€ Comparison              # Jupyter notebooks comparing model performance
β”‚   β”œβ”€β”€ EDA                     # Exploratory Data Analysis notebooks
β”‚   β”œβ”€β”€ SurveyAPI               # Server starter for survey-based webapp
β”‚   β”œβ”€β”€ Traning                 # Training scripts for baseline and improved models
β”‚   └── Traning-waearable       # Final Hybrid model training & .pt android export
β”œβ”€β”€ Dataset
β”‚   β”œβ”€β”€ full.csv                # Complete processed dataset
β”‚   β”œβ”€β”€ train.csv               # Splited training dataset
β”‚   β”œβ”€β”€ test.csv                # Splited testing dataset
β”‚   β”œβ”€β”€ train-wearable.csv      # Optimized 5-feature train dataset
β”‚   └── test-wearable.csv       # Optimized 5-feature test dataset
β”œβ”€β”€ Documentation               # PDF Reports and Demo Video
β”œβ”€β”€ Models
β”‚   β”œβ”€β”€ base                    # 9 trained models
β”‚   └── wearable                # stress_model.pt for Android
β”œβ”€β”€ Presentations               # Midterm and Final slides
β”œβ”€β”€ Prototypes
β”‚   β”œβ”€β”€ StressMonitorDashbord   # Web Dashbord (React.js) Source
β”‚   └── StressMonitorWearable   # Wearable App (Kotlin) Source
└── README.md

πŸš€ Installation & Usage

Python Analysis (ML Models)

cd Code
# Make sure to have a virtual environment with required packages
jupyter notebook

Android Wear App

  1. Open Android Studio.
  2. Select Open and navigate to Prototypes/StressMonitorWearable.
  3. Read the README inside for additional setup.
  4. Sync Gradle files.
  5. Start an Emulator (Wear OS Square/Round) or connect a physical Galaxy Watch.
  6. Run the app (Green Play Button).

Web Dashboard

cd Prototypes/StressMonitorDashbord
npm install
npm start

πŸ“Š Results

  • Comparison: The CNN model initially showed the highest accuracy on the static dataset.
  • Generalization: The Hybrid CNN+GRU proved most robust for stream data, balancing precision with computational efficiency.
  • Latency: The full pipeline (Watch -> Cloud -> Web) achieves sub-second latency for live updates.

Final Model Performance

The Hybrid CNN+GRU model achieved a 97% accuracy on the final test set, demonstrating robust classification across all stress categories without significant overfitting.

Final Performance Metrics

Final Test Report

Class Precision Recall F1-Score Support
no stress 0.99 0.96 0.98 22142
interruption 0.96 0.98 0.97 11772
time pressure 0.95 0.99 0.97 7089
accuracy 0.97 41003
macro avg 0.97 0.98 0.97 41003
weighted avg 0.97 0.97 0.97 41003

πŸ‘₯ Contributors

  • Emin HadΕΎiabdiΔ‡ [@ehadziabdic]
  • Armin MemiΕ‘eviΔ‡ [@arminn2206]
  • Muhammed PaΕ‘iΔ‡ [@MuhaxD]

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Wearable stress monitoring system: hybrid CNN+GRU in PyTorch, real-time inference on Wear OS, Firebase streaming, and a React dashboard.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages