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.
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
From the project root:
pip install -r requirements.txtRequirements: numpy, pandas, matplotlib, scipy, scikit-learn, torch.
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.
Run all steps from the project root (E:\assingment or your repo root).
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"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"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.pyUses Dataset/breathing_dataset.npz by default. Run create_dataset.py first if the dataset is missing.
- 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.
| 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.