Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Health Sensing: Breathing Irregularity Detection

Sleep study analysis pipeline: visualize overnight signals, build labeled 30-second windows, and train a 1D CNN to classify breathing irregularities (e.g. Hypopnea, Obstructive Apnea) using Leave-One-Participant-Out cross-validation.

Project Structure

Data/                 # Raw data per participant (AP01–AP05)
  AP01/
    Flow - *.txt, Thorac - *.txt, SPO2 - *.txt
    Flow Events - *.txt, Sleep profile - *.txt
  AP02/ ... AP05/

Visualizations/       # PDFs from vis.py (one per participant)
Dataset/              # breathing_dataset.csv/.npz, sleep_stage_dataset.csv/.npz
models/               # cnn_model.py (1D CNN)
scripts/
  data_utils.py       # Load signals, flow events, sleep profile
  vis.py              # 8-hour plots with event overlays
  create_dataset.py   # Filter, window, label → Dataset/
  train_model.py      # LOPO-CV training and metrics
requirements.txt
README.md
report.md

Setup

From the project root:

pip install -r requirements.txt

Requirements: numpy, pandas, matplotlib, scipy, scikit-learn, torch.

Data

Download the dataset of participants (raw signals and annotations for AP01–AP05) and extract it so that the Data/ folder contains one subfolder per participant (e.g. Data/AP01/, Data/AP02/, …).

Download participant dataset (internship.zip) — extract the contents into the project’s Data/ directory.

Usage

Run all steps from the project root (E:\assingment or your repo root).

1. Visualizations (Understanding the Data)

Plot Nasal Airflow, Thoracic Movement, and SpO₂ for the full 8-hour recording with annotated breathing events overlaid. Output is saved as PDF in Visualizations/.

python scripts/vis.py -name "Data/AP01"

Generate for all participants:

python scripts/vis.py -name "Data/AP01"
python scripts/vis.py -name "Data/AP02"
python scripts/vis.py -name "Data/AP03"
python scripts/vis.py -name "Data/AP04"
python scripts/vis.py -name "Data/AP05"

2. Dataset Creation (Preprocessing)

Reads signals and annotations from Data/, applies bandpass filter (0.17–0.4 Hz), splits into 30-second windows with 50% overlap, and labels windows from the flow events file (>50% overlap → event label, else Normal). Writes breathing_dataset and sleep_stage_dataset to Dataset/.

python scripts/create_dataset.py -in_dir "Data" -out_dir "Dataset"

3. Training and Evaluation (1D CNN + LOPO-CV)

Trains a 1D CNN on the breathing dataset using Leave-One-Participant-Out cross-validation and reports Accuracy, Precision, Recall, and Confusion Matrix.

python scripts/train_model.py

Uses Dataset/breathing_dataset.npz by default. Run create_dataset.py first if the dataset is missing.

Data Notes

  • Signals: Nasal Airflow and Thoracic Movement at 32 Hz; SpO₂ at 4 Hz. All aligned by timestamp.
  • Events: Flow events file lists Hypopnea, Obstructive Apnea, etc., with start/end times (end time may be time-only; the loader infers the date from the start time).
  • Labels: Classes include Normal, Hypopnea, Obstructive Apnea, and may include Body event, Mixed Apnea depending on annotations.

Outputs

Output Description
Visualizations/<ID>_visualization.pdf 8-hour signals + event overlays per participant
Dataset/breathing_dataset.csv One row per 30s window: participant_id, label, features (f0–f2879)
Dataset/breathing_dataset.npz X, y, participant_ids for training
Dataset/sleep_stage_dataset.csv / .npz Same windows labeled by sleep stage from the sleep profile

Training prints per-fold and overall Accuracy, Precision, Recall, and Confusion Matrix to the console.

About

Detect breathing irregularities (hypopnea, obstructive apnea) in overnight sleep recordings by converting nasal airflow, thoracic movement, and SpO₂ into labeled 30-second windows. Train a 1D CNN with leave-one-participant-out validation and evaluate using accuracy, precision, recall, and confusion matrices.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages