Skip to content

CryptoJym/eeg-meditation-analysis

Repository files navigation

EEG Meditation Analysis Tools

License: MIT Python

A comprehensive Python toolkit for analyzing EEG data during meditation practice, with special focus on Delta (0.5-4 Hz) and Theta (4-8 Hz) brainwave patterns that indicate deep meditative states.

🧠 Features

  • Advanced Signal Processing: Bandpass filtering, artifact removal, and noise reduction
  • Frequency Band Analysis: Detailed power spectral density analysis across Delta, Theta, Alpha, Beta, and Gamma bands
  • Meditation State Classification: Automatic detection of meditation depth based on brainwave patterns
  • Session Analysis: Sliding window analysis for tracking meditation progression over time
  • Comprehensive Visualization: Multi-panel plots including spectrograms, power spectra, and band distributions
  • Synthetic Data Generation: Create realistic EEG data for testing and development
  • Detailed Reporting: Generate session reports with metrics and recommendations

πŸš€ Quick Start

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/eeg-meditation-analysis.git
cd eeg-meditation-analysis
  1. Install dependencies:
pip install -r requirements.txt

Basic Usage

from eeg_analysis import EEGAnalyzer

# Initialize analyzer
analyzer = EEGAnalyzer(sampling_rate=256)

# Load your EEG data (numpy array)
import numpy as np
eeg_data = np.load('your_eeg_data.npy')

# Analyze meditation state
results = analyzer.analyze_meditation_state(eeg_data)

print(f"Meditation State: {results['state']}")
print(f"Meditation Score: {results['meditation_score']}/100")

# Generate visualization
analyzer.plot_analysis(eeg_data, results, save_path='analysis_report.png')

Generate Sample Data

# Generate sample EEG data for testing
python generate_sample_eeg.py

# Analyze the generated data
python eeg_analysis.py

πŸ“Š Analysis Metrics

The toolkit provides various metrics for meditation assessment:

  • Meditation Score (0-100): Overall meditation depth indicator
  • Delta/Theta Ratio: Higher values indicate deeper meditation
  • Theta/Alpha Ratio: Transition from alert to meditative state
  • Spectral Entropy: Measure of EEG signal complexity
  • Dominant Frequency: Primary frequency component in the signal
  • Band Powers: Absolute and relative power in each frequency band

🧘 Meditation State Classification

The analyzer classifies meditation states into four categories:

  1. Alert/Active: Normal waking consciousness
  2. Light Meditation: Initial relaxation and focus
  3. Moderate Meditation: Sustained meditative state
  4. Deep Meditation: Profound meditative state with high Delta/Theta activity

πŸ“ˆ Session Analysis

Analyze entire meditation sessions with sliding window approach:

# Analyze full session with 30-second windows
session_df = analyzer.analyze_session(eeg_data, window_size=30, overlap=0.5)

# Generate session report
report = analyzer.generate_report(session_df, save_path='session_report.txt')

🎨 Visualizations

The toolkit generates comprehensive visualization panels including:

  • Raw vs. filtered EEG signals
  • Power spectral density plots
  • Band power distributions
  • Time-frequency spectrograms
  • Meditation metrics dashboard
  • Session progression plots

πŸ“ Project Structure

eeg-meditation-analysis/
β”‚
β”œβ”€β”€ eeg_analysis.py          # Main analysis module
β”œβ”€β”€ generate_sample_eeg.py   # Synthetic data generator
β”œβ”€β”€ requirements.txt         # Python dependencies
β”œβ”€β”€ README.md               # This file
β”œβ”€β”€ QUICKSTART.md           # Quick start guide
β”œβ”€β”€ LICENSE                 # MIT License
β”‚
β”œβ”€β”€ analysis_outputs/       # Meditation session analysis results
β”‚   β”œβ”€β”€ nov_09_2025/       # November 9, 2025 session (35.9 min)
β”‚   β”‚   β”œβ”€β”€ eeg_band_powers.png
β”‚   β”‚   β”œβ”€β”€ spectrogram_ch1.png
β”‚   β”‚   β”œβ”€β”€ eeg_summary.csv
β”‚   β”‚   β”œβ”€β”€ eeg_time_resolved_powers.png
β”‚   β”‚   └── eeg_peaks_summary.csv
β”‚   β”œβ”€β”€ nov_10_2025/       # November 10, 2025 session (39.1 min)
β”‚   β”‚   └── [Analysis outputs pending]
β”‚   └── analysis_results.md # Summary of all sessions
β”‚
β”œβ”€β”€ original_recordings/    # Raw EEG CSV recordings
β”‚   β”œβ”€β”€ Mediation_11.9.2025_11:44_AM_8c60b5b975c05b62.csv
β”‚   └── Meditation_11.10.2025_d48c24fccbab626d.csv
β”‚
β”œβ”€β”€ examples/               # Example scripts and notebooks
β”‚   └── ...
β”‚
β”œβ”€β”€ data/                  # Sample data files
β”‚   └── ...
β”‚
└── output/                # Analysis results
    └── ...

🧘 Meditation Session Results

Recent Sessions Analysis

Our analysis has captured two significant meditation sessions with remarkable results:

November 9, 2025 Session (35.9 minutes)

  • Peak Experience: 12-17 minute window showed optimal meditation state
  • Extraordinary Event: At 29 minutes, achieved exceptional Delta wave activity
  • Key Metrics: Strong Delta/Theta dominance indicating deep meditative states
  • View full analysis

November 10, 2025 Session (39.1 minutes)

  • Breakthrough Moment: Significant shift at 4.6 minutes into session
  • Anxiety Reduction: 98% reduction in anxiety-related Beta wave patterns
  • Sustained Deep State: Maintained profound meditation depth throughout
  • View full analysis

For detailed session summaries and comparative analysis, see analysis_results.md

πŸ”¬ Technical Details

Signal Processing Pipeline

  1. Preprocessing:

    • DC offset removal
    • Bandpass filtering (0.5-50 Hz)
    • Notch filter for powerline noise
    • Statistical artifact detection and removal
  2. Frequency Analysis:

    • Welch's method for PSD estimation
    • Frequency band power calculation
    • Relative power computation
  3. Feature Extraction:

    • Time-domain features
    • Frequency-domain features
    • Complexity measures

Supported Input Formats

  • NumPy arrays (.npy, .npz)
  • CSV files with time-series data
  • Raw binary formats (configurable)

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

πŸ“š References

This toolkit is based on established neuroscience research on meditation and EEG analysis:

  • Davidson, R. J., & Lutz, A. (2008). Buddha's brain: Neuroplasticity and meditation
  • Lomas, T., et al. (2015). A systematic review of the neurophysiology of mindfulness on EEG oscillations
  • Lee, D. J., et al. (2018). Review of the neural oscillations underlying meditation

πŸ“„ License

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

πŸ™ Acknowledgments

  • Neuroscience research community for meditation EEG studies
  • Open-source signal processing libraries (NumPy, SciPy, MNE)
  • Contributors and users of this toolkit

πŸ“§ Contact

For questions, suggestions, or collaboration opportunities, please open an issue on GitHub.


Note: This toolkit is intended for research and educational purposes. For clinical or diagnostic use, please consult with qualified medical professionals.

About

Advanced EEG analysis toolkit for meditation practice. Analyzes brainwave patterns with focus on Delta/Theta waves to track meditation depth and provide insights.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages