Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ECG Signal Processing and HRV Analysis

This project presents an educational ECG signal processing workflow using Python. It analyzes two ECG recordings in both the time and frequency domains, identifies noise components, applies digital filters, detects R-peaks, extracts HRV-related features, and performs a simple rule-based comparison between healthy and OSA-like ECG behavior.

The project is designed as a compact biomedical signal processing example using common scientific Python libraries such as NumPy, Pandas, SciPy, and Matplotlib.


Project Overview

Electrocardiogram (ECG) signals often contain different types of noise and artifacts, including baseline wander and power-line interference. In this project, two ECG signals are processed to:

  • Visualize raw ECG signals in the time domain
  • Analyze their frequency content using FFT and Welch PSD
  • Detect dominant spectral peaks
  • Design and apply digital filters
  • Remove baseline wander and power-line interference
  • Detect R-peaks
  • Extract RR interval and HRV-related features
  • Compare the two signals using a simple rule-based OSA candidate identification approach

Methods Used

The notebook includes the following signal processing steps:

  • Time-domain ECG visualization
  • Zoomed ECG waveform inspection
  • Fast Fourier Transform analysis
  • Welch Power Spectral Density estimation
  • Spectral peak detection
  • Butterworth high-pass filtering for baseline wander removal
  • Notch filtering for power-line interference removal
  • Filter frequency response visualization
  • Forward-backward filtering using filtfilt
  • Zero-padding demonstration
  • R-peak detection
  • RR interval extraction
  • HRV feature calculation
  • Rule-based OSA candidate comparison

HRV Features Extracted

The following features are calculated from the detected R-peaks:

Feature Description
Mean RR Average time interval between consecutive R-peaks
STD RR Standard deviation of RR intervals
RMSSD Root mean square of successive RR differences
CV Coefficient of variation of RR intervals
Mean HR Mean heart rate in beats per minute
Number of beats Number of detected R-peaks

These features are used to compare the variability of the two ECG signals.


Data Format

The original ECG dataset is not included in this repository.

To run the notebook, provide a CSV file with the following columns:

Column Description
time Time values in seconds
Signal1 First ECG signal
Signal2 Second ECG signal

Example CSV format:

time,Signal1,Signal2
0.000,0.12,0.10
0.001,0.15,0.11
0.002,0.18,0.14

Place the CSV file in a local data/ folder or update the file path inside the notebook.

Recommended structure:

ecg-signal-processing-hrv/
│
├── ecg_signal_processing_hrv.ipynb
├── README.md
├── requirements.txt
├── .gitignore
│
├── data/
│   └── ecg_signals.csv
│
└── outputs/
    └── generated_figures/

Installation

Clone the repository:

git clone https://github.com/pariaznd/ecg-signal-processing-hrv.git
cd ecg-signal-processing-hrv

Install the required dependencies:

pip install -r requirements.txt

How to Run

Open the Jupyter notebook:

jupyter notebook ecg_signal_processing_hrv.ipynb

Then run the notebook cells in order.

Make sure your ECG CSV file contains the required columns:

time, Signal1, Signal2

Requirements

The project uses the following Python libraries:

numpy
pandas
matplotlib
scipy

These dependencies are listed in requirements.txt.


Main Outputs

The notebook generates visualizations such as:

  • Raw ECG signals
  • Zoomed ECG segments
  • FFT spectra
  • Welch PSD plots
  • Detected spectral peaks
  • Filter frequency responses
  • ECG before and after filtering
  • FFT before and after filtering
  • Zero-padding comparison
  • Detected R-peaks
  • RR interval comparison

Important Note

This project is for educational and signal-processing purposes only. The rule-based OSA candidate identification is a simple comparison based on RR-interval variability and should not be interpreted as a clinical diagnosis.

A proper diagnosis of obstructive sleep apnea requires clinical evaluation and appropriate medical testing.


Skills Demonstrated

This project demonstrates practical experience with:

  • Python programming
  • Biomedical signal processing
  • ECG analysis
  • Frequency-domain analysis
  • Digital filter design
  • HRV feature extraction
  • Data visualization
  • Scientific computing with NumPy, Pandas, SciPy, and Matplotlib

Author

Paria Zandihamedani


About

ECG signal processing project using FFT, filtering, R-peak detection, and HRV analysis.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages