{"data":{"slug":"github-aipoch-medical-research-skills-scientific-skills-data-analysis-neurokit2-5121e455488e","title":"Process and Analyze Biosignals for HRV and Event-Related Responses","summary":"Process ECG, PPG, EEG, EDA, and other biosignals for HRV metrics, event-related analysis, and multimodal integration using the neurokit2 library.","url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-neurokit2-5121e455488e","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-neurokit2-5121e455488e","markdown_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-neurokit2-5121e455488e.md","download_url":"https:\/\/skillshunter.net\/skills\/github-aipoch-medical-research-skills-scientific-skills-data-analysis-neurokit2-5121e455488e\/download","category":{"slug":"data-research","name":"Data & Research"},"editor_note":"Ensure Python 3.x environment is installed and neurokit2 is installed via pip or uv. The user must install the library before running any processing or analysis commands.","instructions":"---\nname: neurokit\ndescription: \"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.\"\nlicense: MIT\nauthor: AIPOCH\n---\n> **Source**: [https:\/\/github.com\/aipoch\/medical-research-skills](https:\/\/github.com\/aipoch\/medical-research-skills)\n\n## When to Use\n\nUse this skill when you need to:\n\n1. **Run end-to-end ECG\/PPG pipelines** (cleaning \u2192 peak detection \u2192 feature extraction) for cardiovascular monitoring and HRV.\n2. **Compute HRV metrics** (time\/frequency\/nonlinear) for autonomic nervous system assessment in resting-state or continuous recordings.\n3. **Analyze EEG** for band power, microstates, and complexity measures in cognitive\/neuroscience experiments.\n4. **Decompose EDA** into tonic\/phasic components and quantify SCRs for arousal\/stress and psychophysiological paradigms.\n5. **Perform multimodal biosignal processing** (e.g., ECG + RSP + EDA + EMG) with unified outputs for integrated analyses.\n\nReference 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`.\n\n## Key Features\n\n- **Cardiac (ECG\/PPG)**: cleaning, R-peak detection, delineation, quality assessment, ECG-derived respiration, pulse analysis.\n- **HRV**: comprehensive indices across time, frequency, and nonlinear domains; RSA and advanced metrics (e.g., RQA where applicable).\n- **EEG**: band power, channel utilities, microstate segmentation, and integration patterns commonly used with MNE workflows.\n- **EDA**: tonic\/phasic decomposition, SCR detection, sympathetic indices, and event-related EDA analysis.\n- **Respiration (RSP)**: breathing rate, variability (RRV), and respiratory volume per time (RVT) style features.\n- **EMG\/EOG**: EMG activation\/amplitude processing; EOG blink and eye-movement feature extraction.\n- **General utilities**: filtering, peak finding, PSD estimation, resampling\/interpolation, and synchronization helpers.\n- **Event-related analysis**: event finding, epoching, baseline correction, and averaging across trials.\n- **Multimodal integration**: `bio_process()` \/ `bio_analyze()` for consistent multi-signal pipelines.\n\n## Dependencies\n\n- `neurokit2` (latest; install via pip\/uv)\n- Python 3.x environment (version depends on your runtime)\n\nInstallation:\n\n```bash\nuv pip install neurokit2\n```\n\nDevelopment version:\n\n```bash\nuv pip install https:\/\/github.com\/neuropsychology\/NeuroKit\/zipball\/dev\n```\n\n## Example Usage\n\nA complete, runnable example that simulates signals, processes them, computes features, and performs event-related epoching:\n\n```python\nimport neurokit2 as nk\nimport numpy as np\n\n# -----------------------------\n# 1) Simulate example signals\n# -----------------------------\nsampling_rate = 1000\nduration = 60  # seconds\n\necg = nk.ecg_simulate(duration=duration, sampling_rate=sampling_rate, heart_rate=70)\nrsp = nk.rsp_simulate(duration=duration, sampling_rate=sampling_rate, respiratory_rate=15)\neda = nk.eda_simulate(duration=duration, sampling_rate=sampling_rate, scr_number=8)\n\n# Create a simple trigger channel with 5 events\ntrigger = np.zeros(len(ecg))\nevent_times_s = [10, 20, 30, 40, 50]\nfor t in event_times_s:\n    trigger[int(t * sampling_rate)] = 1.0\n\n# -----------------------------\n# 2) ECG processing + HRV\n# -----------------------------\necg_signals, ecg_info = nk.ecg_process(ecg, sampling_rate=sampling_rate)\nrpeaks = ecg_info[\"ECG_R_Peaks\"]\nhrv = nk.hrv(rpeaks, sampling_rate=sampling_rate)\n\n# -----------------------------\n# 3) Multimodal processing\n# -----------------------------\nbio_signals, bio_info = nk.bio_process(\n    ecg=ecg,\n    rsp=rsp,\n    eda=eda,\n    sampling_rate=sampling_rate\n)\nbio_results = nk.bio_analyze(bio_signals, sampling_rate=sampling_rate)\n\n# -----------------------------\n# 4) Event-related epoching\n# -----------------------------\nevents = nk.events_find(trigger, threshold=0.5)\nepochs = nk.epochs_create(\n    bio_signals,\n    events,\n    sampling_rate=sampling_rate,\n    epochs_start=-0.5,\n    epochs_end=2.0\n)\ngrand_average = nk.epochs_average(epochs)\n\n# -----------------------------\n# 5) Minimal outputs\n# -----------------------------\nprint(\"HRV (first columns):\")\nprint(hrv.iloc[:, :8].round(3))\n\nprint(\"\\nBio analysis keys:\", list(bio_results.keys())[:10])\nprint(\"Grand average shape:\", grand_average.shape)\n```\n\n## Implementation Details\n\n### Processing pipelines (typical pattern)\nMost modalities follow a consistent structure:\n\n1. `*_process(signal, sampling_rate=...)`\n   Produces a cleaned signal plus intermediate channels (e.g., peaks, phases) and an `info` dict with indices\/metadata.\n2. `*_analyze(processed_signals, sampling_rate=...)`\n   Computes summary features and automatically selects an analysis mode based on recording length.\n\nExamples:\n- ECG: `ecg_process()` \u2192 `ecg_analyze()` \u2192 `hrv()`\n- EDA: `eda_process()` \u2192 `eda_analyze()`\n- RSP: `rsp_process()` \u2192 `rsp_rrv()` \/ `rsp_rvt()`\n\n### Analysis mode selection (event-related vs interval-related)\nMany `*_analyze()` functions implicitly switch modes based on data duration:\n\n- **Event-related** (short segments; commonly < ~10 s): stimulus-locked responses, epoch-based summaries.\n- **Interval-related** (longer recordings; commonly \u2265 ~10 s): continuous\/resting summaries (e.g., HRV over a window).\n\nIf you need explicit event-related workflows, use:\n- `events_find()` to detect markers\n- `epochs_create()` to segment around events\n- `epochs_average()` (and modality-specific `*_eventrelated()` where applicable)\n\n### HRV domains and inputs\nHRV functions typically require **R-peak indices** (sample positions) and often a `sampling_rate`:\n\n- Time-domain: e.g., SDNN, RMSSD, pNN50\n- Frequency-domain: band powers\/ratios (requires sampling rate and appropriate interpolation assumptions)\n- Nonlinear: Poincar\u00e9 (SD1\/SD2), entropy\/fractal-style measures\n\nCommon calls:\n- `nk.hrv(peaks, sampling_rate=...)` (all-in-one)\n- `nk.hrv_time(peaks)`, `nk.hrv_frequency(peaks, sampling_rate=...)`, `nk.hrv_nonlinear(peaks, sampling_rate=...)`\n\n### Filtering and spectral estimation\nGeneral utilities (see `references\/signal_processing.md`) typically expose parameters such as:\n- `sampling_rate`\n- cutoff frequencies (`lowcut`, `highcut`)\n- method-specific options (e.g., filter order\/type)\n\nExample:\n```python\nfiltered = nk.signal_filter(x, sampling_rate=1000, lowcut=0.5, highcut=40)\npsd = nk.signal_psd(filtered, sampling_rate=1000)\n```\n\n### Complexity\/entropy measures\nComplexity functions (see `references\/complexity.md`) provide:\n- Entropy families (approximate, sample, permutation, multiscale, etc.)\n- Fractal\/DFA variants\n- Nonlinear dynamics metrics (e.g., Lyapunov-style measures where supported)\n\nExample:\n```python\nindices = nk.complexity(x, sampling_rate=1000)\napen = nk.entropy_approximate(x)\ndfa = nk.fractal_dfa(x)\n```\n","use_cases":["Run end-to-end ECG\/PPG pipelines for cardiovascular monitoring and HRV analysis.","Compute HRV metrics for autonomic nervous system assessment in resting-state or continuous recordings.","Analyze EEG for band power, microstates, and complexity measures in cognitive experiments."],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/aipoch\/medical-research-skills\/blob\/686e09dfdb45d9fa1a08664f06bb93769b3c9d91\/scientific-skills\/Data%20Analysis\/neurokit2\/SKILL.md","source_commit":"686e09dfdb45d9fa1a08664f06bb93769b3c9d91","license":"MIT","version":null,"listing_approved_at":"2026-11-24","created_at":"2026-11-23T12:14:38.000000Z","updated_at":"2026-11-24T12:17:13.000000Z","seo_title":"Process biosignals for HRV and event-related analysis","seo_description":"Use neurokit2 to process biosignals, extract HRV metrics, and perform event-related analysis for cardiovascular and neurophysiological studies.","seo_keywords":["HRV analysis","ECG processing","event-related analysis","EEG analysis","biosignal processing"]}}