scientific-skills/neurokit2/references/ppg.md
Photoplethysmography (PPG) measures blood volume changes in microvascular tissue using optical sensors. PPG is widely used in wearable devices, pulse oximeters, and clinical monitors for heart rate, pulse characteristics, and cardiovascular assessment.
Automated PPG signal processing pipeline.
signals, info = nk.ppg_process(ppg_signal, sampling_rate=100, method='elgendi')
Pipeline steps:
Returns:
signals: DataFrame with:
PPG_Clean: Filtered PPG signalPPG_Peaks: Systolic peak markersPPG_Rate: Instantaneous heart rate (BPM)PPG_Quality: Signal quality indicatorinfo: Dictionary with peak indices and parametersMethods:
'elgendi': Elgendi et al. (2013) algorithm (default, robust)'nabian2018': Nabian et al. (2018) approachPrepare raw PPG signal for peak detection.
cleaned_ppg = nk.ppg_clean(ppg_signal, sampling_rate=100, method='elgendi')
Methods:
1. Elgendi (default):
2. Nabian2018:
PPG signal characteristics:
Detect systolic peaks in PPG signal.
peaks, info = nk.ppg_peaks(cleaned_ppg, sampling_rate=100, method='elgendi',
correct_artifacts=False)
Methods:
'elgendi': Two moving averages with dynamic thresholding'bishop': Bishop's algorithm'nabian2018': Nabian's approach'scipy': Simple scipy peak detectionArtifact correction:
correct_artifacts=True for physiological plausibility checksReturns:
'PPG_Peaks' key containing peak indicesTypical inter-beat intervals:
Low-level peak detection with algorithm comparison.
peaks_dict = nk.ppg_findpeaks(cleaned_ppg, sampling_rate=100, method='elgendi')
Use case:
Automatically select event-related or interval-related analysis.
analysis = nk.ppg_analyze(signals, sampling_rate=100)
Mode selection:
Analyze PPG responses to discrete events/stimuli.
results = nk.ppg_eventrelated(epochs)
Computed metrics (per epoch):
PPG_Rate_Baseline: Heart rate before eventPPG_Rate_Min/Max: Minimum/maximum heart rate during epochUse cases:
Analyze extended PPG recordings.
results = nk.ppg_intervalrelated(signals, sampling_rate=100)
Computed metrics:
PPG_Rate_Mean: Average heart ratehrv() functionRecording duration:
Use cases:
Assess signal quality and reliability.
quality = nk.ppg_quality(ppg_signal, sampling_rate=100, method='averageQRS')
Methods:
1. averageQRS (default):
2. dissimilarity:
Use cases:
Common quality issues:
Extract individual pulses for morphological analysis.
pulses = nk.ppg_segment(cleaned_ppg, peaks, sampling_rate=100)
Returns:
Use cases:
Document preprocessing methods used in analysis.
methods_info = nk.ppg_methods(method='elgendi')
Returns:
Generate synthetic PPG signals for testing.
synthetic_ppg = nk.ppg_simulate(duration=60, sampling_rate=100, heart_rate=70,
noise=0.1, random_state=42)
Parameters:
heart_rate: Mean BPM (default: 70)heart_rate_std: HRV magnitudenoise: Gaussian noise levelrandom_state: Reproducibility seedUse cases:
Visualize processed PPG signal.
nk.ppg_plot(signals, info, static=True)
Displays:
Common sites:
Transmittance vs. Reflectance:
Low signal amplitude:
Motion artifacts:
Baseline drift:
Missing peaks:
Standard workflow:
# 1. Clean signal
cleaned = nk.ppg_clean(ppg_raw, sampling_rate=100, method='elgendi')
# 2. Detect peaks with artifact correction
peaks, info = nk.ppg_peaks(cleaned, sampling_rate=100, correct_artifacts=True)
# 3. Assess quality
quality = nk.ppg_quality(cleaned, sampling_rate=100)
# 4. Comprehensive processing (alternative)
signals, info = nk.ppg_process(ppg_raw, sampling_rate=100)
# 5. Analyze
analysis = nk.ppg_analyze(signals, sampling_rate=100)
HRV from PPG:
# Process PPG signal
signals, info = nk.ppg_process(ppg_raw, sampling_rate=100)
# Extract peaks and compute HRV
hrv_indices = nk.hrv(info['PPG_Peaks'], sampling_rate=100)
# PPG-derived HRV is valid but may differ slightly from ECG-derived HRV
# Differences due to pulse arrival time, vascular properties
Wearable health monitoring:
Clinical monitoring:
Cardiovascular assessment:
Autonomic function:
Remote patient monitoring:
Affective computing:
Advantages of PPG:
Disadvantages of PPG:
HRV comparison:
Heart rate from PPG:
Pulse amplitude:
Pulse morphology: