Source: https://github.com/aipoch/medical-research-skills
When to Use
Use this skill when you need to:
- Run end-to-end ECG/PPG pipelines (cleaning → peak detection → feature extraction) for cardiovascular monitoring and HRV.
- Compute HRV metrics (time/frequency/nonlinear) for autonomic nervous system assessment in resting-state or continuous recordings.
- Analyze EEG for band power, microstates, and complexity measures in cognitive/neuroscience experiments.
- Decompose EDA into tonic/phasic components and quantify SCRs for arousal/stress and psychophysiological paradigms.
- Perform multimodal biosignal processing (e.g., ECG + RSP + EDA + EMG) with unified outputs for integrated analyses.
Reference docs (if available in this skill package): references/ecg_cardiac.md, references/hrv.md, references/eeg.md, references/eda.md, references/rsp.md, references/emg.md, references/eog.md, references/signal_processing.md, references/complexity.md, references/epochs_events.md, references/bio_module.md.
Key Features
- Cardiac (ECG/PPG): cleaning, R-peak detection, delineation, quality assessment, ECG-derived respiration, pulse analysis.
- HRV: comprehensive indices across time, frequency, and nonlinear domains; RSA and advanced metrics (e.g., RQA where applicable).
- EEG: band power, channel utilities, microstate segmentation, and integration patterns commonly used with MNE workflows.
- EDA: tonic/phasic decomposition, SCR detection, sympathetic indices, and event-related EDA analysis.
- Respiration (RSP): breathing rate, variability (RRV), and respiratory volume per time (RVT) style features.
- EMG/EOG: EMG activation/amplitude processing; EOG blink and eye-movement feature extraction.
- General utilities: filtering, peak finding, PSD estimation, resampling/interpolation, and synchronization helpers.
- Event-related analysis: event finding, epoching, baseline correction, and averaging across trials.
- Multimodal integration:
bio_process() / bio_analyze() for consistent multi-signal pipelines.
Dependencies
neurokit2 (latest; install via pip/uv)
- Python 3.x environment (version depends on your runtime)
Installation:
uv pip install neurokit2
Development version:
uv pip install https://github.com/neuropsychology/NeuroKit/zipball/dev
Example Usage
A complete, runnable example that simulates signals, processes them, computes features, and performs event-related epoching:
import neurokit2 as nk
import numpy as np
# -----------------------------
# 1) Simulate example signals
# -----------------------------
sampling_rate = 1000
duration = 60 # seconds
ecg = nk.ecg_simulate(duration=duration, sampling_rate=sampling_rate, heart_rate=70)
rsp = nk.rsp_simulate(duration=duration, sampling_rate=sampling_rate, respiratory_rate=15)
eda = nk.eda_simulate(duration=duration, sampling_rate=sampling_rate, scr_number=8)
# Create a simple trigger channel with 5 events
trigger = np.zeros(len(ecg))
event_times_s = [10, 20, 30, 40, 50]
for t in event_times_s:
trigger[int(t * sampling_rate)] = 1.0
# -----------------------------
# 2) ECG processing + HRV
# -----------------------------
ecg_signals, ecg_info = nk.ecg_process(ecg, sampling_rate=sampling_rate)
rpeaks = ecg_info["ECG_R_Peaks"]
hrv = nk.hrv(rpeaks, sampling_rate=sampling_rate)
# -----------------------------
# 3) Multimodal processing
# -----------------------------
bio_signals, bio_info = nk.bio_process(
ecg=ecg,
rsp=rsp,
eda=eda,
sampling_rate=sampling_rate
)
bio_results = nk.bio_analyze(bio_signals, sampling_rate=sampling_rate)
# -----------------------------
# 4) Event-related epoching
# -----------------------------
events = nk.events_find(trigger, threshold=0.5)
epochs = nk.epochs_create(
bio_signals,
events,
sampling_rate=sampling_rate,
epochs_start=-0.5,
epochs_end=2.0
)
grand_average = nk.epochs_average(epochs)
# -----------------------------
# 5) Minimal outputs
# -----------------------------
print("HRV (first columns):")
print(hrv.iloc[:, :8].round(3))
print("\nBio analysis keys:", list(bio_results.keys())[:10])
print("Grand average shape:", grand_average.shape)
Implementation Details
Processing pipelines (typical pattern)
Most modalities follow a consistent structure:
*_process(signal, sampling_rate=...)
Produces a cleaned signal plus intermediate channels (e.g., peaks, phases) and an info dict with indices/metadata.
*_analyze(processed_signals, sampling_rate=...)
Computes summary features and automatically selects an analysis mode based on recording length.
Examples:
- ECG:
ecg_process() → ecg_analyze() → hrv()
- EDA:
eda_process() → eda_analyze()
- RSP:
rsp_process() → rsp_rrv() / rsp_rvt()
Analysis mode selection (event-related vs interval-related)
Many *_analyze() functions implicitly switch modes based on data duration:
- Event-related (short segments; commonly < ~10 s): stimulus-locked responses, epoch-based summaries.
- Interval-related (longer recordings; commonly ≥ ~10 s): continuous/resting summaries (e.g., HRV over a window).
If you need explicit event-related workflows, use:
events_find() to detect markers
epochs_create() to segment around events
epochs_average() (and modality-specific *_eventrelated() where applicable)
HRV domains and inputs
HRV functions typically require R-peak indices (sample positions) and often a sampling_rate:
- Time-domain: e.g., SDNN, RMSSD, pNN50
- Frequency-domain: band powers/ratios (requires sampling rate and appropriate interpolation assumptions)
- Nonlinear: Poincaré (SD1/SD2), entropy/fractal-style measures
Common calls:
nk.hrv(peaks, sampling_rate=...) (all-in-one)
nk.hrv_time(peaks), nk.hrv_frequency(peaks, sampling_rate=...), nk.hrv_nonlinear(peaks, sampling_rate=...)
Filtering and spectral estimation
General utilities (see references/signal_processing.md) typically expose parameters such as:
sampling_rate
- cutoff frequencies (
lowcut, highcut)
- method-specific options (e.g., filter order/type)
Example:
filtered = nk.signal_filter(x, sampling_rate=1000, lowcut=0.5, highcut=40)
psd = nk.signal_psd(filtered, sampling_rate=1000)
Complexity/entropy measures
Complexity functions (see references/complexity.md) provide:
- Entropy families (approximate, sample, permutation, multiscale, etc.)
- Fractal/DFA variants
- Nonlinear dynamics metrics (e.g., Lyapunov-style measures where supported)
Example:
indices = nk.complexity(x, sampling_rate=1000)
apen = nk.entropy_approximate(x)
dfa = nk.fractal_dfa(x)
1---2name: neurokit3description: Comprehensive biosignal processing for ECG/PPG/EEG/EDA/RSP/EMG/EOG; use when you need to clean, segment, and extract physiological features for HRV, event-related responses, complexity metrics, or multimodal psychophysiology pipelines.4license: MIT5---6> **Source**: [https://github.com/aipoch/medical-research-skills](https://github.com/aipoch/medical-research-skills)
7
8## When to Use
9
10Use this skill when you need to:
11
121. **Run end-to-end ECG/PPG pipelines** (cleaning → peak detection → feature extraction) for cardiovascular monitoring and HRV.
132. **Compute HRV metrics** (time/frequency/nonlinear) for autonomic nervous system assessment in resting-state or continuous recordings.
143. **Analyze EEG** for band power, microstates, and complexity measures in cognitive/neuroscience experiments.
154. **Decompose EDA** into tonic/phasic components and quantify SCRs for arousal/stress and psychophysiological paradigms.
165. **Perform multimodal biosignal processing** (e.g., ECG + RSP + EDA + EMG) with unified outputs for integrated analyses.
17
18Reference docs (if available in this skill package): `references/ecg_cardiac.md`, `references/hrv.md`, `references/eeg.md`, `references/eda.md`, `references/rsp.md`, `references/emg.md`, `references/eog.md`, `references/signal_processing.md`, `references/complexity.md`, `references/epochs_events.md`, `references/bio_module.md`.
19
20## Key Features
21
22- **Cardiac (ECG/PPG)**: cleaning, R-peak detection, delineation, quality assessment, ECG-derived respiration, pulse analysis.
23- **HRV**: comprehensive indices across time, frequency, and nonlinear domains; RSA and advanced metrics (e.g., RQA where applicable).
24- **EEG**: band power, channel utilities, microstate segmentation, and integration patterns commonly used with MNE workflows.
25- **EDA**: tonic/phasic decomposition, SCR detection, sympathetic indices, and event-related EDA analysis.
26- **Respiration (RSP)**: breathing rate, variability (RRV), and respiratory volume per time (RVT) style features.
27- **EMG/EOG**: EMG activation/amplitude processing; EOG blink and eye-movement feature extraction.
28- **General utilities**: filtering, peak finding, PSD estimation, resampling/interpolation, and synchronization helpers.
29- **Event-related analysis**: event finding, epoching, baseline correction, and averaging across trials.
30- **Multimodal integration**: `bio_process()` / `bio_analyze()` for consistent multi-signal pipelines.
31
32## Dependencies
33
34- `neurokit2` (latest; install via pip/uv)
35- Python 3.x environment (version depends on your runtime)
36
37Installation:
38
39```bash
40uv pip install neurokit2
41```
42
43Development version:
44
45```bash
46uv pip install https://github.com/neuropsychology/NeuroKit/zipball/dev
47```
48
49## Example Usage
50
51A complete, runnable example that simulates signals, processes them, computes features, and performs event-related epoching:
52
53```python
54import neurokit2 as nk
55import numpy as np
56
57# -----------------------------
58# 1) Simulate example signals
59# -----------------------------
60sampling_rate = 1000
61duration = 60 # seconds
62
63ecg = nk.ecg_simulate(duration=duration, sampling_rate=sampling_rate, heart_rate=70)
64rsp = nk.rsp_simulate(duration=duration, sampling_rate=sampling_rate, respiratory_rate=15)
65eda = nk.eda_simulate(duration=duration, sampling_rate=sampling_rate, scr_number=8)
66
67# Create a simple trigger channel with 5 events
68trigger = np.zeros(len(ecg))
69event_times_s = [10, 20, 30, 40, 50]
70for t in event_times_s:
71 trigger[int(t * sampling_rate)] = 1.0
72
73# -----------------------------
74# 2) ECG processing + HRV
75# -----------------------------
76ecg_signals, ecg_info = nk.ecg_process(ecg, sampling_rate=sampling_rate)
77rpeaks = ecg_info["ECG_R_Peaks"]
78hrv = nk.hrv(rpeaks, sampling_rate=sampling_rate)
79
80# -----------------------------
81# 3) Multimodal processing
82# -----------------------------
83bio_signals, bio_info = nk.bio_process(
84 ecg=ecg,
85 rsp=rsp,
86 eda=eda,
87 sampling_rate=sampling_rate
88)
89bio_results = nk.bio_analyze(bio_signals, sampling_rate=sampling_rate)
90
91# -----------------------------
92# 4) Event-related epoching
93# -----------------------------
94events = nk.events_find(trigger, threshold=0.5)
95epochs = nk.epochs_create(
96 bio_signals,
97 events,
98 sampling_rate=sampling_rate,
99 epochs_start=-0.5,
100 epochs_end=2.0
101)
102grand_average = nk.epochs_average(epochs)
103
104# -----------------------------
105# 5) Minimal outputs
106# -----------------------------
107print("HRV (first columns):")
108print(hrv.iloc[:, :8].round(3))
109
110print("\nBio analysis keys:", list(bio_results.keys())[:10])
111print("Grand average shape:", grand_average.shape)
112```
113
114## Implementation Details
115
116### Processing pipelines (typical pattern)
117Most modalities follow a consistent structure:
118
1191. `*_process(signal, sampling_rate=...)`
120 Produces a cleaned signal plus intermediate channels (e.g., peaks, phases) and an `info` dict with indices/metadata.
1212. `*_analyze(processed_signals, sampling_rate=...)`
122 Computes summary features and automatically selects an analysis mode based on recording length.
123
124Examples:
125- ECG: `ecg_process()` → `ecg_analyze()` → `hrv()`
126- EDA: `eda_process()` → `eda_analyze()`
127- RSP: `rsp_process()` → `rsp_rrv()` / `rsp_rvt()`
128
129### Analysis mode selection (event-related vs interval-related)
130Many `*_analyze()` functions implicitly switch modes based on data duration:
131
132- **Event-related** (short segments; commonly < ~10 s): stimulus-locked responses, epoch-based summaries.
133- **Interval-related** (longer recordings; commonly ≥ ~10 s): continuous/resting summaries (e.g., HRV over a window).
134
135If you need explicit event-related workflows, use:
136- `events_find()` to detect markers
137- `epochs_create()` to segment around events
138- `epochs_average()` (and modality-specific `*_eventrelated()` where applicable)
139
140### HRV domains and inputs
141HRV functions typically require **R-peak indices** (sample positions) and often a `sampling_rate`:
142
143- Time-domain: e.g., SDNN, RMSSD, pNN50
144- Frequency-domain: band powers/ratios (requires sampling rate and appropriate interpolation assumptions)
145- Nonlinear: Poincaré (SD1/SD2), entropy/fractal-style measures
146
147Common calls:
148- `nk.hrv(peaks, sampling_rate=...)` (all-in-one)
149- `nk.hrv_time(peaks)`, `nk.hrv_frequency(peaks, sampling_rate=...)`, `nk.hrv_nonlinear(peaks, sampling_rate=...)`
150
151### Filtering and spectral estimation
152General utilities (see `references/signal_processing.md`) typically expose parameters such as:
153- `sampling_rate`
154- cutoff frequencies (`lowcut`, `highcut`)
155- method-specific options (e.g., filter order/type)
156
157Example:
158```python
159filtered = nk.signal_filter(x, sampling_rate=1000, lowcut=0.5, highcut=40)
160psd = nk.signal_psd(filtered, sampling_rate=1000)
161```
162
163### Complexity/entropy measures
164Complexity functions (see `references/complexity.md`) provide:
165- Entropy families (approximate, sample, permutation, multiscale, etc.)
166- Fractal/DFA variants
167- Nonlinear dynamics metrics (e.g., Lyapunov-style measures where supported)
168
169Example:
170```python
171indices = nk.complexity(x, sampling_rate=1000)
172apen = nk.entropy_approximate(x)
173dfa = nk.fractal_dfa(x)
174```