Skip to content

This project provides a Python-based toolkit for real-time monitoring, processing, and analysis of ECG (Electrocardiogram) signals.

Notifications You must be signed in to change notification settings

raphaelobinna/monitor-ecg

Repository files navigation

ECG Monitor & Analysis

Overview

This project provides a Python-based toolkit for real-time monitoring, processing, and analysis of ECG (Electrocardiogram) signals. It supports analog-to-digital conversion, beat detection, and advanced ST segment analysis, with both interactive CLI and automated batch modes. Users can process data from the AD8232 sensor, run simulations with built-in or custom test patterns, and analyze results for research, prototyping, or educational purposes in biomedical signal processing.

Features

  • Analog to Digital Signal Processing: Convert raw ECG signals to digital format.
  • Beat Detection & Processing: Identify and process heartbeats from ECG data.
  • ST Segment Analysis: Analyze the ST segment for abnormalities.
  • Data Visualization: Results can be used for personal data visualization and utilize CWT (Continuous Wavelet Transform) with the Morlet wavelet for advanced signal analysis.
  • Test Scripts: Run quick tests to validate functionality.

Input Data

  • Sensor: This project is designed to work exclusively with ECG data collected from the AD8232 sensor.
  • Sampling Rate: The system processes samples at a default rate of 250Hz.
  • Format: Input data should be in the expected digital format as output by the AD8232 sensor.

Data & Results

  • Input Data: The project expects ECG signal data from the AD8232 sensor at 250Hz.
  • Processing: The scripts process the ECG data to detect beats, analyze ST segments, and may output processed signals or diagnostic information.
  • Results: Outputs include processed ECG signals, beat locations, and ST segment analysis results, which can be used for further research or visualization.
  • Sample Output:
    Beat 1: {
      'fiducial_points': {
        'p_peak': np.int64(27),
        'qrs_onset': 39,
        'r_peak': np.int64(51),
        'j_point': 63,
        'qrs_offset': 63,
        't_peak': np.int64(81),
        'qrs_energy': array([...]),
        'beat_number': 0,
        'start_idx': np.int64(16)
      },
      'baseline': np.float64(-5.46),
      'baseline_method': 'PR',
      'all_baselines': [('PR', np.float64(-5.46)), ...],
      'st_measurements': {'st_20ms': np.float64(24.12), ...},
      'st_indices': {'st_20ms': 66, ...},
      'morphology': {'st_slope': np.float64(282.21), ...},
      'st_segment': array([...]),
      'st_bounds': (63, np.int64(75)),
      'abnormalities': [
        {'type': 'ST_ELEVATION', 'measurement': 'st_20ms', 'value': np.float64(24.12), 'severity': 'severe'},
        ...
      ],
      'j_point_quality': 0.5
    }

Setup

  1. Clone the repository
    git clone <repo-url>
    cd monitor_ecg
  2. Create and activate a virtual environment (optional but recommended)
    python3 -m venv venv
    source venv/bin/activate
  3. Install dependencies
    pip install -r requirements.txt

Quick Test / Usage

You can run the test script to generate test sensor results:

python test.py

Or run the main module in batch mode for a quick start (processes 10 seconds of data):

python main.py --mode batch --duration 10

Or run individual modules, for example:

python main.py

Usage Modes

  • CLI Mode (Interactive):

    • Start the program in interactive mode:
      python main.py --mode cli
    • At the prompt, use commands like load, start, simulate, status, analyze, etc.
    • You can load built-in test patterns or input your own ECG data as comma-separated values.
    • Custom Data Input (CLI):
      • In CLI mode, use the load command and choose manual to paste your own ECG data as comma-separated values.
  • Batch Mode (Automated):

    • Run the program for a fixed duration with automatic test pattern loading and simulation:
      python main.py --mode batch --duration 15
    • The program will process and analyze ECG data for the specified duration, then print results.

Example CLI Workflow

$ python main.py --mode cli

ECG> load
Enter 'auto' to use ecg_gen patterns or 'manual' to input custom data: manual
Paste your data: 500,502,501,499,498,500,503,504,502,500

ECG> start
ECG> simulate
ECG> status
ECG> analyze
Enter start time (seconds): 0
Enter end time (seconds): 10
...
ECG> results
ECG> stop
ECG> exit

File Descriptions

  • main.py: Main entry point for ECG processing.
  • analog_digital_signal.py: Handles analog-to-digital conversion of ECG signals.
  • prcocess_beat.py: Processes and detects heartbeats in ECG data.
  • st_analysis.py: Analyzes the ST segment of the ECG.
  • test.py: Script for running tests and demonstrations.
  • requirements.txt: Python dependencies.

Notes

  • Ensure your input ECG data is in the correct format expected by the scripts (AD8232, 250Hz).
  • Modify or extend the scripts as needed for your specific use case.

License

Tag the repo and notify on usage for any commercial use.

About

This project provides a Python-based toolkit for real-time monitoring, processing, and analysis of ECG (Electrocardiogram) signals.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages