Skip to content

This project analyzes **Heart Rate Variability (HRV)** during various meditation and breathing states using the **PhysioNet HRV dataset**. We compare Chi meditation, Kundalini Yoga, sleep, and metronomic breathing based on time-domain HRV metrics and use **machine learning models** to distinguish between these states.

License

Notifications You must be signed in to change notification settings

JKA098/-HRV-Comparison-Across-Meditation-Breathing-Techniques

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

31 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

HRV Comparison Across Meditation & Breathing Techniques πŸ§˜β€β™‚οΈπŸ’“

Python License Focus Theme Data Statistics ML Framework Notebook Editor

πŸ“… Project Overview

This project analyzes Heart Rate Variability (HRV) during various meditation and breathing states using the PhysioNet HRV dataset. We compare Chi meditation, Kundalini Yoga, sleep, and metronomic breathing based on time-domain HRV metrics and use machine learning models to distinguish between these states.


πŸŽ“ Learning Objectives

  • Analyze HRV using time-domain features (Mean HR, SDNN, RMSSD)
  • Compare meditation vs. sleep vs. breathing via statistical tests (t-test, ANOVA)
  • Visualize physiological differences across states using box/violin plots
  • Train ML classifiers (KNN, Random Forest) to classify states
  • Interpret results and draw cardiovascular health insights

🧾 Dataset

Source: PhysioNet: Heart Rate Oscillations During Meditation

Groups

  • Chi Meditation: C1–C8 (pre and med)
  • Kundalini Yoga: Y1–Y4 (pre and med)
  • Normal Sleep: N1–N11
  • Ironman : I1-I9
  • Metronomic Breathing: M1–M14

Columns

  • Elapsed Time (seconds)
  • Instantaneous Heart Rate (bpm)

πŸ—ΊοΈ Data Preprocessing Overview

The following diagrams illustrate the preprocessing steps used:

πŸ“Œ Data Loading Structure

Data Loading Structure

πŸ“Œ Preprocessing Summary Flow

Preprocessing Summary

🧼 Sample Preprocessing Code

πŸ”Ή Load Raw Heart Rate Data

# Define file paths
input_file = r"...\data\chi\C1.pre"
output_file = r"...\dataset\o_0_chi\C1_pre_meditation.csv"

# Load text data
df = pd.read_csv(input_file, sep="\s+", header=None, names=["Time", "HeartRate"])
df["Subject"] = "C1_pre"
df["Group"] = "Chi"
df["State"] = "Pre_Meditation"
df.to_csv(output_file, index=False)

πŸ”Ή Merge Pre/Post Meditation Data

file_pre = r"...\C1_pre_meditation.csv"
file_med = r"...\C1_meditation.csv"

# Merge files
pre = pd.read_csv(file_pre)
med = pd.read_csv(file_med)
c1_merged = pd.concat([pre, med], ignore_index=True)
c1_merged.to_csv("...\C1_merged_data.csv", index=False)

πŸ”Ή Extract R-R Intervals (from .qrs files)

import wfdb, numpy as np, pandas as pd

# Load QRS peaks
def load_qrs_peaks(path):
    annotation = wfdb.rdann(path, 'qrs')
    return annotation.sample

# Compute R-R intervals
r_peaks = load_qrs_peaks("...\C1pre")
time_stamps = r_peaks[1:] / 250
rr_intervals = np.diff(r_peaks) / 250

# Create DataFrame and save
rr_df = pd.DataFrame({"Time": time_stamps, "RR_Interval": rr_intervals})
rr_df["Subject"] = "C1_pre_rr"
rr_df["Group"] = "Chi Meditation"
rr_df["State"] = "Pre-Meditation"
rr_df.to_csv("...\RR_C1_pre.csv", index=False)

πŸ”Ή Combine All RR Intervals for Chi Group

import glob

rr_files = glob.glob(r"...\RR_C*_merged.csv")
df_all_rr = pd.concat([pd.read_csv(f) for f in rr_files], ignore_index=True)
df_all_rr.to_csv(r"...\RR_Chi_meditation_Combined.csv", index=False)

πŸ”¬ Statistical Testing Code (ANOVA + T-test)

from scipy.stats import ttest_rel, f_oneway, shapiro

# Paired T-Test (Chi pre vs. med)
t_stat, p_val = ttest_rel(df_chi_pre["RMSSD"], df_chi_med["RMSSD"])
print("T-test Chi RMSSD: t =", t_stat, "p =", p_val)

# ANOVA (across groups)
f_stat, p_val = f_oneway(df_chi["RMSSD"], df_yoga["RMSSD"], df_sleep["RMSSD"], df_metron["RMSSD"])
print("ANOVA RMSSD: F =", f_stat, "p =", p_val)

# Normality check
shapiro_stat, shapiro_p = shapiro(df_chi_pre["RMSSD"])
print("Shapiro-Wilk p =", shapiro_p)

πŸ”„ Preprocessing Flowchart

πŸ“ data/
β”œβ”€β”€ 0_0_chi/
β”‚   β”œβ”€β”€ RR_data/
β”‚   β”‚   └── RR_C1-C8_merged_data.csv, RR_Chi_meditation_Combined.csv
β”‚   └── HRV_data/
β”‚       └── C1-C8_merged_data.csv, HRV_Chi_Meditation_Combined.csv
β”œβ”€β”€ 0_1_ironman/
β”‚   β”œβ”€β”€ RR_data/
β”‚   β”‚   └── RR_Ironman_Combined.csv
β”‚   └── HRV_data/
β”‚       └── HRV_Ironman_Meditation_Combined.csv
β”œβ”€β”€ 0_2_metron/
β”‚   β”œβ”€β”€ RR_data/
β”‚   β”‚   └── RR_Metron_Combined.csv
β”‚   └── HRV_data/
β”‚       └── HRV_Metron_Combined.csv
β”œβ”€β”€ 0_3_normal/
β”‚   β”œβ”€β”€ RR_data/
β”‚   β”‚   └── RR_Normal_Combined.csv
β”‚   └── HRV_data/
β”‚       └── HRV_Normal_Combined.csv
β”œβ”€β”€ 0_4_yoga/
β”‚   β”œβ”€β”€ RR_data/
β”‚   β”‚   └── RR_Yoga_Combined.csv
β”‚   └── HRV_data/
β”‚       └── HRV_Yoga_Combined.csv

πŸ“ Merged Files β†’ πŸ“„ o_1_all_hrv_rr_metric_combined.csv

πŸ“Š Statistical Computing:
β”œβ”€β”€ πŸ“„ Mean_HR
β”œβ”€β”€ πŸ“„ SDNN
β”œβ”€β”€ πŸ“„ RMSSD

πŸ“‰ Statistical Tests:
β”œβ”€β”€ πŸ“„ o_3_results_normality_chi
β”œβ”€β”€ πŸ“„ o_4_results_normality_yoga
β”œβ”€β”€ πŸ“„ o_5_t_test_results_chi_yoga
β”œβ”€β”€ πŸ“„ o_2_anova_results_chi_yoga

πŸ”¬ Methodology

βœ… 1. HRV Feature Extraction

Time-domain metrics used:

  • Mean Heart Rate
  • SDNN – Standard Deviation of NN intervals
  • RMSSD – Root Mean Square of Successive Differences

βœ… 2. Statistical Analysis

  • Paired t-tests: Chi/Yoga (pre vs. med)
  • ANOVA: Across meditation, sleep, and breathing
  • Normality check via Shapiro-Wilk
  • Visualizations: Boxplots plots

βœ… 3. Machine Learning

  • Model: KNN and Random Forest
  • Features: Time-domain HRV metrics
  • Evaluation: Accuracy, Confusion Matrix, F1-score

βœ… 4. Tools

  • Language: Python
  • Libraries: pandas, numpy, scipy, matplotlib, seaborn, scikit-learn, wfdb
  • Environment: Jupyter Lab (analysis + code), RStudio (report writing)

πŸ“ˆ Expected Outcomes

  • Identify which meditation technique leads to highest HRV change
  • Assess similarity of meditation-induced HRV to sleep or metronomic breathing
  • Build classifier that can predict state (Chi, Yoga, Sleep, Breathing)
  • Offer insights on HRV as an indicator of relaxation and cardiovascular health

πŸ“‚ Folder Structure

hrv_meditation_analysis/
β”œβ”€β”€ README.md
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ chi/  # C1_pre.txt, C1_med.txt ...
β”‚   β”œβ”€β”€ yoga/  # Y1_pre.txt, Y1_med.txt ...
β”‚   β”œβ”€β”€ sleep/  # N1.txt ...
β”‚   β”œβ”€β”€ metron/  # M1.txt ...
β”œβ”€β”€ merged/
β”‚   └── o_1_all_hrv_rr_metric_combined.csv
β”œβ”€β”€ stats/
β”‚   β”œβ”€β”€ normality/
β”‚   β”‚   β”œβ”€β”€ o_3_results_normality_chi.csv
β”‚   β”‚   └── o_4_results_normality_yoga.csv
β”‚   β”œβ”€β”€ t_tests/o_5_t_test_results_chi_yoga.csv
β”‚   └── anova/o_2_anova_results_chi_yoga.csv
β”œβ”€β”€ notebooks/
β”‚   └── HRV_Comparison.ipynb
β”œβ”€β”€ hrv_utils.py

🧠 Summary

Project: HRV Analysis of Meditation, Sleep, and Breathing

Goal: Quantify and compare HRV effects of Chi meditation, Kundalini Yoga, sleep, and metronomic breathing.

Highlights:

  • Preprocessed HRV data using PhysioNet
  • Computed time-domain HRV features
  • Conducted statistical tests (paired t-test, ANOVA)
  • Visualized HRV across states
  • Trained ML classifiers to identify state

πŸ“ References

  1. Tiwari et al. (2021) – Heart Rate Variability Analysis
  2. Kim et al. (2018) – Stress and HRV
  3. Peng et al. (1999) – Heart Rate Oscillations During Meditation
  4. Goldberger et al. (2000) – PhysioNet Reference

For full dataset access, visit: https://physionet.org/content/meditation/1.0.0/


Feel free to extend the project using wearable HRV devices, deep learning models (e.g., LSTM), or real-time biofeedback systems! πŸ§˜β€β™€οΈπŸ“Š

About

This project analyzes **Heart Rate Variability (HRV)** during various meditation and breathing states using the **PhysioNet HRV dataset**. We compare Chi meditation, Kundalini Yoga, sleep, and metronomic breathing based on time-domain HRV metrics and use **machine learning models** to distinguish between these states.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages