# sushantaman108durgadas/weartwin architecture

> Architecture diagram of the GitHub repository sushantaman108durgadas/weartwin, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sushantaman108durgadas/weartwin
- Repository: https://github.com/sushantaman108durgadas/weartwin

## Overview

WearTwin is a simulation-led wearable physiology prototype, not yet a complete digital-twin application. Its demonstrated path is simulated ECG and embedded ECG sampling/analysis, alongside an MPU6050 orientation path using a Kalman filter. The README also describes planned multimodal feature extraction, state estimation, gateway, and operational decision uses; these are shown as documented future branches, not implemented services. The tree contains two firmware variants and separate ECG-processing experiments. Several links rely on README architecture statements because the sketch and many processing files were not excerpted.

Main entry points: [`src/src.ino`](https://github.com/sushantaman108durgadas/weartwin/blob/main/src/src.ino) (Firmware Sketch), [`src/InertialState.cpp`](https://github.com/sushantaman108durgadas/weartwin/blob/main/src/InertialState.cpp) (Inertial Processing), [`WearTwin_FreeRTOS/WearTwin_FreeRTOS.ino`](https://github.com/sushantaman108durgadas/weartwin/blob/main/WearTwin_FreeRTOS/WearTwin_FreeRTOS.ino) (RTOS Firmware Sketch), [`src/CardialState.cpp`](https://github.com/sushantaman108durgadas/weartwin/blob/main/src/CardialState.cpp) (ECG Analysis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_sim["Signal Simulation"]
  node_simulator["ECG Simulator<br/>[ecgsim.chip.c]"]
  node_wokwi_api["Wokwi API<br/>[wokwi-api.h]"]
  node_free_simulator["ECG Simulator<br/>[ecgsim.chip.c]"]
  node_free_wokwi_api["Wokwi API<br/>[wokwi-api.h]"]
end

subgraph group_firmware["Embedded Firmware"]
  node_sketch["Firmware Sketch<br/>[src.ino]"]
  node_ecg["ECG Analysis<br/>[CardialState.cpp]"]
  node_inertial["Inertial Processing<br/>[InertialState.cpp]"]
  node_kalman["Kalman Filter<br/>[KalmanFilter.cpp]"]
  node_freertos_sketch["RTOS Firmware Sketch"]
  node_freertos_ecg["RTOS ECG Analysis<br/>[CardialState.cpp]"]
  node_freertos_inertial["RTOS Inertial Processing<br/>[InertialState.cpp]"]
  node_freertos_kalman["RTOS Kalman Filter<br/>[KalmanFilter.cpp]"]
end

subgraph group_analysis["ECG Processing"]
  node_peak["Peak Detection"]
  node_bpm_pipeline["BPM Pipeline"]
  node_queue_tool["ECG Queue Tool<br/>[dequeue.c]"]
  node_filter_pipeline["Filter Experiments<br/>[FIR_pipeline.m]"]
end

subgraph group_twin["Twin Architecture"]
  node_feature_stage["Feature Extraction"]
  node_state_stage["State Estimation"]
  node_digital_twin[("Digital Twin State")]
  node_decision["Decision Layer"]
end

node_wearer(("Wearable Sensors"))
node_operator(("Medic / Commander"))

node_simulator -->|"writes simulated signal"| node_wokwi_api
node_free_simulator -->|"writes simulated signal"| node_free_wokwi_api
node_wearer -.->|"provides sensor data"| node_sketch
node_sketch -.->|"routes ECG samples"| node_ecg
node_sketch -.->|"routes IMU readings"| node_inertial
node_inertial -->|"uses filter"| node_kalman
node_wearer -.->|"provides sensor data"| node_freertos_sketch
node_freertos_sketch -.->|"routes ECG samples"| node_freertos_ecg
node_freertos_sketch -.->|"routes IMU readings"| node_freertos_inertial
node_freertos_inertial -->|"uses filter"| node_freertos_kalman
node_ecg -.->|"yields ECG metrics"| node_feature_stage
node_inertial -.->|"yields orientation"| node_feature_stage
node_feature_stage -.->|"feeds features"| node_state_stage
node_state_stage -.->|"updates state"| node_digital_twin
node_digital_twin -.->|"informs decisions"| node_decision
node_decision -.->|"presents triage"| node_operator
node_peak -.->|"supports BPM analysis"| node_bpm_pipeline

click node_simulator "https://github.com/sushantaman108durgadas/weartwin/blob/main/src/ecgsim.chip.c"
click node_wokwi_api "https://github.com/sushantaman108durgadas/weartwin/blob/main/src/wokwi-api.h"
click node_free_simulator "https://github.com/sushantaman108durgadas/weartwin/blob/main/WearTwin_FreeRTOS/ecgsim.chip.c"
click node_free_wokwi_api "https://github.com/sushantaman108durgadas/weartwin/blob/main/WearTwin_FreeRTOS/wokwi-api.h"
click node_sketch "https://github.com/sushantaman108durgadas/weartwin/blob/main/src/src.ino"
click node_ecg "https://github.com/sushantaman108durgadas/weartwin/blob/main/src/CardialState.cpp"
click node_inertial "https://github.com/sushantaman108durgadas/weartwin/blob/main/src/InertialState.cpp"
click node_kalman "https://github.com/sushantaman108durgadas/weartwin/blob/main/src/KalmanFilter.cpp"
click node_freertos_sketch "https://github.com/sushantaman108durgadas/weartwin/blob/main/WearTwin_FreeRTOS/WearTwin_FreeRTOS.ino"
click node_freertos_ecg "https://github.com/sushantaman108durgadas/weartwin/blob/main/WearTwin_FreeRTOS/CardialState.cpp"
click node_freertos_inertial "https://github.com/sushantaman108durgadas/weartwin/blob/main/WearTwin_FreeRTOS/InertialState.cpp"
click node_freertos_kalman "https://github.com/sushantaman108durgadas/weartwin/blob/main/WearTwin_FreeRTOS/KalmanFilter.cpp"
click node_peak "https://github.com/sushantaman108durgadas/weartwin/blob/main/ECG_processing/cscripts/derivative_peak_detection.c"
click node_bpm_pipeline "https://github.com/sushantaman108durgadas/weartwin/blob/main/ECG_processing/cscripts/peak_detection_bpm_pipeline.c"
click node_queue_tool "https://github.com/sushantaman108durgadas/weartwin/blob/main/ECG_processing/cscripts/dequeue.c"
click node_filter_pipeline "https://github.com/sushantaman108durgadas/weartwin/blob/main/ECG_processing/octavescripts/FIR_pipeline.m"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_simulator,node_wokwi_api,node_free_simulator,node_free_wokwi_api toneBlue
class node_sketch,node_ecg,node_inertial,node_kalman,node_freertos_sketch,node_freertos_ecg,node_freertos_inertial,node_freertos_kalman toneAmber
class node_peak,node_bpm_pipeline,node_queue_tool,node_filter_pipeline toneMint
class node_feature_stage,node_state_stage,node_digital_twin,node_decision toneRose
class node_wearer,node_operator toneIndigo
```

## Components

### Signal Simulation

- [ECG Simulator](https://github.com/sushantaman108durgadas/weartwin/blob/main/src/ecgsim.chip.c): `src/ecgsim.chip.c`
- [Wokwi API](https://github.com/sushantaman108durgadas/weartwin/blob/main/src/wokwi-api.h): `src/wokwi-api.h`
- [ECG Simulator](https://github.com/sushantaman108durgadas/weartwin/blob/main/WearTwin_FreeRTOS/ecgsim.chip.c): `WearTwin_FreeRTOS/ecgsim.chip.c`
- [Wokwi API](https://github.com/sushantaman108durgadas/weartwin/blob/main/WearTwin_FreeRTOS/wokwi-api.h): `WearTwin_FreeRTOS/wokwi-api.h`

### Embedded Firmware

- [Firmware Sketch](https://github.com/sushantaman108durgadas/weartwin/blob/main/src/src.ino): `src/src.ino`
- [ECG Analysis](https://github.com/sushantaman108durgadas/weartwin/blob/main/src/CardialState.cpp): `src/CardialState.cpp`
- [Inertial Processing](https://github.com/sushantaman108durgadas/weartwin/blob/main/src/InertialState.cpp): `src/InertialState.cpp`
- [Kalman Filter](https://github.com/sushantaman108durgadas/weartwin/blob/main/src/KalmanFilter.cpp): `src/KalmanFilter.cpp`
- [RTOS Firmware Sketch](https://github.com/sushantaman108durgadas/weartwin/blob/main/WearTwin_FreeRTOS/WearTwin_FreeRTOS.ino): `WearTwin_FreeRTOS/WearTwin_FreeRTOS.ino`
- [RTOS ECG Analysis](https://github.com/sushantaman108durgadas/weartwin/blob/main/WearTwin_FreeRTOS/CardialState.cpp): `WearTwin_FreeRTOS/CardialState.cpp`
- [RTOS Inertial Processing](https://github.com/sushantaman108durgadas/weartwin/blob/main/WearTwin_FreeRTOS/InertialState.cpp): `WearTwin_FreeRTOS/InertialState.cpp`
- [RTOS Kalman Filter](https://github.com/sushantaman108durgadas/weartwin/blob/main/WearTwin_FreeRTOS/KalmanFilter.cpp): `WearTwin_FreeRTOS/KalmanFilter.cpp`

### ECG Processing

- [Peak Detection](https://github.com/sushantaman108durgadas/weartwin/blob/main/ECG_processing/cscripts/derivative_peak_detection.c): `ECG_processing/cscripts/derivative_peak_detection.c`
- [BPM Pipeline](https://github.com/sushantaman108durgadas/weartwin/blob/main/ECG_processing/cscripts/peak_detection_bpm_pipeline.c): `ECG_processing/cscripts/peak_detection_bpm_pipeline.c`
- [ECG Queue Tool](https://github.com/sushantaman108durgadas/weartwin/blob/main/ECG_processing/cscripts/dequeue.c): `ECG_processing/cscripts/dequeue.c`
- [Filter Experiments](https://github.com/sushantaman108durgadas/weartwin/blob/main/ECG_processing/octavescripts/FIR_pipeline.m): `ECG_processing/octavescripts/FIR_pipeline.m`

### Twin Architecture

- **Feature Extraction**
- **State Estimation**
- **Digital Twin State**
- **Decision Layer**

### Other components

- **Wearable Sensors**
- **Medic / Commander**

## Connections

- ECG Simulator → Wokwi API: writes simulated signal (evidence: `src/ecgsim.chip.c`)
- ECG Simulator → Wokwi API: writes simulated signal (evidence: `WearTwin_FreeRTOS/ecgsim.chip.c`)
- Wearable Sensors → Firmware Sketch: provides sensor data (evidence: `README.md`)
- Firmware Sketch → ECG Analysis: routes ECG samples (evidence: `README.md`)
- Firmware Sketch → Inertial Processing: routes IMU readings (evidence: `README.md`)
- Inertial Processing → Kalman Filter: uses filter
- Wearable Sensors → RTOS Firmware Sketch: provides sensor data (evidence: `README.md`)
- RTOS Firmware Sketch → RTOS ECG Analysis: routes ECG samples (evidence: `README.md`)
- RTOS Firmware Sketch → RTOS Inertial Processing: routes IMU readings (evidence: `README.md`)
- RTOS Inertial Processing → RTOS Kalman Filter: uses filter
- ECG Analysis → Feature Extraction: yields ECG metrics (evidence: `README.md`)
- Inertial Processing → Feature Extraction: yields orientation (evidence: `README.md`)
- Feature Extraction → State Estimation: feeds features (evidence: `README.md`)
- State Estimation → Digital Twin State: updates state (evidence: `README.md`)
- Digital Twin State → Decision Layer: informs decisions (evidence: `README.md`)
- Decision Layer → Medic / Commander: presents triage (evidence: `README.md`)
- Peak Detection → BPM Pipeline: supports BPM analysis
