Skip to main content
v2026.11,986 entries · CC-BY 4.0

NeuroKit2: Python Toolbox for ECG and HRV Analysis

NeuroKit2 is a free Python toolbox for ECG, EDA, EMG and EEG signals. Install it, run an ECG-to-HRV pipeline and read the output.

Written and maintained by CASRAI Editorial Board

Published · Last updated

On this page

NeuroKit2 is a free, open-source Python toolbox for processing neurophysiological signals: ECG, PPG, respiration, electrodermal activity (EDA), EMG, EOG and EEG. You install it with pip install neurokit2, import it as nk, and go from a raw recording to cleaned signals, detected events and summary features such as heart rate variability (HRV) with a few function calls. This guide covers what it does, how to install it, a worked ECG-to-HRV pipeline, how to read the output, and what to check when results look wrong.

What NeuroKit2 is used for in research

The project documentation describes NeuroKit2 as a toolbox for biosignal processing in Python, aimed at physiological recordings collected in psychology, neuroscience and related laboratory work. The signals it handles, per the current documentation home page, are ECG, PPG, HRV, respiration and respiratory rate variability, EDA, EMG, EOG, EEG (power bands, complexity measures and microstates) and video-based signals. Its function reference is organised into categories: Bio, Signal, Events, Epochs, Complexity and Stats.

According to the project’s GitHub README, the toolbox can simulate ECG (including 12-lead), PPG, respiration, EDA and EMG signals; preprocess ECG, PPG, respiration, EDA, EMG and EOG; run event-related and interval-related analyses with bio_analyze; compute HRV in the time, frequency and nonlinear domains; delineate ECG waves (P, QRS, T); compute entropy and detrended fluctuation measures; and estimate power spectral density with Welch, multitaper, Lomb and Burg methods. Simulation is useful for testing a pipeline before real recordings arrive, because you know the ground truth.

The software is released under the MIT license and the documentation under CC BY 4.0. If you use it in a paper, the maintainers’ citation is Makowski D, Pham T, Lau ZJ, Brammer JC, Lespinasse F, Pham H, Schölzel C, Chen SA (2021), NeuroKit2: A Python toolbox for neurophysiological signal processing, Behavior Research Methods 53(4):1689-1696, doi:10.3758/s13428-020-01516-y. Running nk.cite() prints the reference. Because the toolbox is open-source software, state the exact version you used in your methods section so the analysis is reproducible.

How to install or access it

The installation page of the NeuroKit2 documentation gives three routes, and the PyPI project page states that the current release requires Python 3.10 or newer.

  • pip (stable release): pip install neurokit2
  • conda: conda config --add channels conda-forge followed by conda install neurokit2
  • Development version: pip install -U git+https://github.com/neuropsychology/NeuroKit@dev

After installing, import neurokit2 as nk makes every function available under the nk prefix. PyPI listed version 0.3.0 (released 1 November 2026) when read on 2026-11-15; the documentation site showed a development build of the 0.2.x line at the same time, so check the installed version with pip show neurokit2 and match the documentation to it. If you are setting up a wider Python environment for lab work, the bioinformatics Python setup guide covers environment basics.

Which function handles which signal

The table below maps each signal type to the entry points named in the documentation. Start with the single-signal *_process style functions when you have one channel, and bio_process when you have several channels recorded together.

Task Function (as documented) What it does
Load example data nk.data("bio_resting_5min_100hz") Returns a DataFrame with ECG, PPG and RSP columns for a five-minute resting recording at 100 Hz
Process one ECG channel nk.ecg_process(ecg_signal, sampling_rate=1000, method='neurokit') Cleans the signal, finds R-peaks and returns a signals DataFrame plus an info dictionary
R-peaks only nk.ecg_peaks(ecg_cleaned, sampling_rate=1000, method='neurokit') Returns a peaks DataFrame and a dictionary of R-peak sample indices
Several channels at once nk.bio_process(ecg=..., rsp=..., eda=..., sampling_rate=100) Processes ECG, respiration and EDA in one call
Summarise processed data nk.bio_analyze(processed_data, sampling_rate=100) Event-related or interval-related feature extraction
HRV, all domains nk.hrv(peaks, sampling_rate=100) Time, frequency and nonlinear indices in one table

Step-by-step: compute HRV from an ECG

This pipeline follows the NeuroKit2 ECG and HRV example in the official documentation, using the bundled five-minute resting recording sampled at 100 Hz. Run it in a Python session or notebook after installing the package.

  1. Import and load. import neurokit2 as nk, then data = nk.data("bio_resting_5min_100hz"). The result is a DataFrame with the columns ECG, PPG and RSP.
  2. Detect R-peaks. peaks, info = nk.ecg_peaks(data["ECG"], sampling_rate=100). The peaks DataFrame has the same length as the input signal and holds a 1 at each R-peak sample; info is a dictionary containing the R-peak sample indices.
  3. Time-domain HRV. nk.hrv_time(peaks, sampling_rate=100, show=True). With show=True the function also plots the distribution of the intervals between beats.
  4. Frequency-domain HRV. nk.hrv_frequency(peaks, sampling_rate=100, normalize=True). With show=True it plots the power spectral density.
  5. Nonlinear HRV. nk.hrv_nonlinear(peaks, sampling_rate=100). With show=True it draws the Poincaré plot.
  6. Everything together. nk.hrv(peaks, sampling_rate=100) returns all of the above in a single one-row table.

For a multi-channel recording the documentation’s quick example instead calls processed_data, info = nk.bio_process(ecg=data["ECG"], rsp=data["RSP"], eda=data["EDA"], sampling_rate=100) followed by results = nk.bio_analyze(processed_data, sampling_rate=100). The ECG-specific ecg_analyze (default method='auto') chooses event-related analysis when epochs average under 10 seconds and interval-related analysis otherwise.

Output and how to read it

Every HRV function returns a DataFrame with one row per analysed recording and one column per index, prefixed HRV_. In the documentation’s five-minute example the column counts are: hrv_time 25 columns, hrv_frequency 10 columns, hrv_nonlinear 60 columns, and the combined hrv 95 columns. The data table below the guide lists those counts with the indices each function reports, so you can check that your own output has the expected shape before interpreting any value.

Time-domain columns

The time-domain table includes HRV_MeanNN, HRV_SDNN, HRV_RMSSD, HRV_pNN50, HRV_MinNN, HRV_MaxNN and HRV_TINN. NN here means the interval between consecutive normal beats, expressed in milliseconds. In the documentation example the mean interval is about 696 ms and RMSSD about 70 ms; those figures describe that sample recording only and are not reference values for your participants.

Frequency-domain columns

The frequency-domain output contains power in the ULF, VLF, LF, HF and VHF bands, total power (HRV_TP), the LF/HF ratio (HRV_LFHF), normalised LF and HF (HRV_LFn, HRV_HFn) and the log of HF (HRV_LnHF). In the five-minute example HRV_ULF is NaN. The documentation’s example shows this NaN for a five-minute recording, so check which bands your recording length supports before you plan which to report.

Nonlinear columns

The nonlinear table includes Poincaré descriptors (SD1, SD2), the cardiac sympathetic and vagal indices (CSI, CVI) and sample entropy, among others, for 60 columns in total. Report only the indices your research question justifies; with 95 columns available from nk.hrv, selecting indices after seeing the data inflates false-positive findings, so pre-specify them in your analysis plan.

ECG processing output

nk.ecg_process returns a signals DataFrame the same length as the input with 19 columns, among them ECG_Raw, ECG_Clean, ECG_Rate, ECG_Quality, the R, P, Q, S and T peak, onset and offset indicator columns, and the atrial and ventricular phase columns. Peak, onset and offset columns hold 1 at the event sample and 0 elsewhere, which makes them easy to use as masks when you inspect a recording visually.

Troubleshooting

  • The sampling rate must match the recording. Functions such as ecg_peaks and ecg_process default to sampling_rate=1000. If your file was recorded at 100 Hz or 500 Hz and you do not pass the real value, the sample indices will be converted to time with the wrong rate and the HRV values will not be meaningful. Pass sampling_rate explicitly in every call, and use the same value for the later hrv_* calls.
  • NaN in a frequency band. A NaN in HRV_ULF on a five-minute recording matches the documentation’s own example, as described above.
  • Installation fails or imports break. The current PyPI release requires Python 3.10 or newer. Check python --version first. For a conda environment, add the conda-forge channel as in the installation page, or use pip inside the environment.
  • Documentation and installed version differ. The documentation site tracks the development line. If a function signature in the docs differs from what your session shows, compare against pip show neurokit2 or install the development version listed above.
  • Method choice. The default method for cleaning and peak detection is 'neurokit'. Other methods are selectable through the method argument; state the method you used when you report results.

Free alternatives and neighbouring tools

NeuroKit2 is aimed at peripheral physiological signals and also offers EEG features, but it is not a full EEG source-analysis environment. For EEG and MEG work, see the guide to MNE-Python, the open-source package for electrophysiology analysis. For audio signal analysis in Python, librosa covers a different signal domain, and for sequence-oriented life-science scripting see Biopython. These tools address different data types rather than substituting for one another, so pick by signal type first.

Frequently asked questions

What is NeuroKit2?

NeuroKit2 is an MIT-licensed Python toolbox for processing and analysing neurophysiological signals including ECG, PPG, respiration, EDA, EMG, EOG and EEG.

How do I install NeuroKit2?

Run pip install neurokit2, or install from the conda-forge channel with conda install neurokit2. The PyPI release requires Python 3.10 or newer.

How do I cite NeuroKit2?

Cite Makowski et al. (2021), Behavior Research Methods 53(4):1689-1696, doi:10.3758/s13428-020-01516-y. The command nk.cite() prints the reference.

Which HRV measures does NeuroKit2 compute?

Time-domain (for example MeanNN, SDNN, RMSSD), frequency-domain (ULF to VHF power, LF/HF) and nonlinear measures (for example SD1, SD2, CSI, CVI, sample entropy), through hrv_time, hrv_frequency, hrv_nonlinear or hrv.

Why is HRV_ULF NaN?

The documentation’s five-minute example returns NaN for the ultra-low-frequency band.

Sources

  • NeuroKit2 documentation home, https://neuropsychology.github.io/NeuroKit/ (read 2026-11-15)
  • NeuroKit2 installation page, https://neuropsychology.github.io/NeuroKit/installation.html (read 2026-11-15)
  • NeuroKit2 ECG function reference, https://neuropsychology.github.io/NeuroKit/functions/ecg.html (read 2026-11-15)
  • NeuroKit2 ECG and HRV example, https://neuropsychology.github.io/NeuroKit/examples/ecg_hrv/ecg_hrv.html (read 2026-11-15)
  • NeuroKit2 GitHub repository and README, https://github.com/neuropsychology/NeuroKit (read 2026-11-15)
  • NeuroKit2 on PyPI, https://pypi.org/project/neurokit2/ (read 2026-11-15)

Data: NeuroKit2 HRV functions: output columns and indices reported (five-minute resting example)

Compares the four NeuroKit2 heart rate variability functions by the number of output columns in the official five-minute, 100 Hz example and the indices each reports, compiled from the NeuroKit2 documentation.

NeuroKit2 HRV functions: output columns and indices reported (five-minute resting example)
FunctionOutput columns (count)Indices named in the documentation
hrv_time25HRV_MeanNN, HRV_SDNN, HRV_RMSSD, HRV_pNN50, HRV_MinNN, HRV_MaxNN, HRV_TINN
hrv_frequency10HRV_ULF, HRV_VLF, HRV_LF, HRV_HF, HRV_VHF, HRV_TP, HRV_LFHF, HRV_LFn, HRV_HFn, HRV_LnHF
hrv_nonlinear60Poincare SD1 and SD2, CSI, CVI, sample entropy and others
hrv95All time, frequency and nonlinear indices combined

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · full access

Ask about NeuroKit2: Python Toolbox for ECG and HRV Analysis

Full access: large monthly usage, up to 10 source passages behind each answer, and MCP and API access for Claude Code, Codex and other CLIs. Cancel any time.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →