Skill Tracer
Skills › Scientific Agent Skills › neurokit2 › rsp.md

rsp.md

212 lines · skills/neurokit2/references/rsp.md at 5f2bc03

Open on GitHub
1# Respiration
2
3Checked **2026-10-01** against NeuroKit2 0.2.13 stable runtime/source,
4the official RSP API/examples, and cardiorespiratory interpretation guidance.
5

Respiration

Checked 2026-10-01 against NeuroKit2 0.2.13 stable runtime/source, the official RSP API/examples, and cardiorespiratory interpretation guidance.

Raw lines 1 to 5
6## Acquisition contract and polarity
7
8Record sensor type (belt, airflow, capnography, impedance, derived proxy), placement,
9gain/range, physical unit, native rate, clock, hardware filters, calibration, and
10annotations for speech, cough, sigh, breath hold, swallowing, movement, and detachment.
12A belt/impedance amplitude is not tidal volume unless calibrated and validated.
13Different devices have opposite polarity. NeuroKit2's documented convention labels:
15- `RSP_Peaks`: exhalation onsets;
16- `RSP_Troughs`: inhalation onsets; and
17- `RSP_Phase`: `1` inspiration, `0` expiration.
19Verify these labels against the actual device and a known breath. Invert or relabel
20explicitly before interpretation if needed.

Acquisition contract and polarity

Record sensor type (belt, airflow, capnography, impedance, derived proxy), placement, gain/range, physical unit, native rate, clock, hardware filters, calibration, and annotations for speech, cough, sigh, breath hold, swallowing, movement, and detachment.

A belt/impedance amplitude is not tidal volume unless calibrated and validated. Different devices have opposite polarity. NeuroKit2's documented convention labels:

  • RSP_Peaks: exhalation onsets;
  • RSP_Troughs: inhalation onsets; and
  • RSP_Phase: 1 inspiration, 0 expiration.

Verify these labels against the actual device and a known breath. Invert or relabel explicitly before interpretation if needed.

Raw lines 6 to 21
22## Stable high-level pipeline
24```python
25signals, info = nk.rsp_process(
26 rsp,
27 sampling_rate=50,
28 method="khodadad2018",
29 method_rvt="harrison2021",
31```
33Pinned default columns:
35```text
36RSP_Raw, RSP_Clean, RSP_Amplitude, RSP_Rate, RSP_RVT,
37RSP_Phase, RSP_Phase_Completion,
38RSP_Symmetry_PeakTrough, RSP_Symmetry_RiseDecay,
39RSP_Peaks, RSP_Troughs
40```
42`info` contained `RSP_Peaks`, `RSP_Troughs`, and `sampling_rate`. This is a
43default schema observation, not a universal contract.

Stable high-level pipeline

signals, info = nk.rsp_process(
    rsp,
    sampling_rate=50,
    method="khodadad2018",
    method_rvt="harrison2021",
)

Pinned default columns:

RSP_Raw, RSP_Clean, RSP_Amplitude, RSP_Rate, RSP_RVT,
RSP_Phase, RSP_Phase_Completion,
RSP_Symmetry_PeakTrough, RSP_Symmetry_RiseDecay,
RSP_Peaks, RSP_Troughs

info contained RSP_Peaks, RSP_Troughs, and sampling_rate. This is a default schema observation, not a universal contract.

Raw lines 22 to 44
45## Cleaning and extrema
47```python
48clean = nk.rsp_clean(rsp, sampling_rate=50, method="khodadad2018")
49markers, extrema = nk.rsp_peaks(
50 clean,
51 sampling_rate=50,
52 method="khodadad2018",
54```
56Stable peak methods include `khodadad2018`, `biosppy`, `scipy`, and
57`schafer2008`. `rsp_fixpeaks()` is currently documented as a placeholder that does
58not correct respiration extrema.
60Validate extrema during irregular breathing, pauses, speech, motion, and changing
61amplitude. A smooth sinusoidal simulation is not enough.

Cleaning and extrema

clean = nk.rsp_clean(rsp, sampling_rate=50, method="khodadad2018")
markers, extrema = nk.rsp_peaks(
    clean,
    sampling_rate=50,
    method="khodadad2018",
)

Stable peak methods include khodadad2018, biosppy, scipy, and schafer2008. rsp_fixpeaks() is currently documented as a placeholder that does not correct respiration extrema.

Validate extrema during irregular breathing, pauses, speech, motion, and changing amplitude. A smooth sinusoidal simulation is not enough.

Raw lines 45 to 62
63## Rate, amplitude, and phase signatures
65These functions do not all accept the same peak object:
67```python
68rate = nk.rsp_rate(
69 clean,
70 troughs=extrema["RSP_Troughs"],
71 sampling_rate=50,
72 method="trough",
74amplitude = nk.rsp_amplitude(
75 clean,
76 peaks=extrema["RSP_Peaks"],
77 troughs=extrema["RSP_Troughs"],
79phase = nk.rsp_phase(
80 extrema["RSP_Peaks"],
81 troughs=extrema["RSP_Troughs"],
82 desired_length=len(clean),
84```
86- `rsp_rate()` takes the cleaned signal first; `method="trough"` uses inhalation
87 onsets, while `method="xcorr"` estimates a windowed principal rate.
88- `rsp_amplitude()` returns a same-length interpolated amplitude series.
89- `rsp_phase()` takes peaks/troughs, not the cleaned signal, and returns a DataFrame
90 with phase and completion.
92Rates are breaths/minute. Amplitude remains in the sensor's arbitrary/calibrated unit.
93Phase accuracy depends on extrema and polarity.

Rate, amplitude, and phase signatures

These functions do not all accept the same peak object:

rate = nk.rsp_rate(
    clean,
    troughs=extrema["RSP_Troughs"],
    sampling_rate=50,
    method="trough",
)
amplitude = nk.rsp_amplitude(
    clean,
    peaks=extrema["RSP_Peaks"],
    troughs=extrema["RSP_Troughs"],
)
phase = nk.rsp_phase(
    extrema["RSP_Peaks"],
    troughs=extrema["RSP_Troughs"],
    desired_length=len(clean),
)
  • rsp_rate() takes the cleaned signal first; method="trough" uses inhalation onsets, while method="xcorr" estimates a windowed principal rate.
  • rsp_amplitude() returns a same-length interpolated amplitude series.
  • rsp_phase() takes peaks/troughs, not the cleaned signal, and returns a DataFrame with phase and completion.

Rates are breaths/minute. Amplitude remains in the sensor's arbitrary/calibrated unit. Phase accuracy depends on extrema and polarity.

Raw lines 63 to 94
95## RRV and RAV
97```python
98rrv = nk.rsp_rrv(
99 signals["RSP_Rate"],
100 troughs=info["RSP_Troughs"],
101 sampling_rate=50,
103rav = nk.rsp_rav(
104 signals["RSP_Amplitude"],
105 peaks=info,
107```
109The pinned `rsp_rrv()` output had 20 columns spanning interval, frequency, Poincaré,
110and entropy metrics (`RRV_RMSSD` through `RRV_SampEn`). The pinned RAV output had
111`RAV_Mean`, `RAV_SD`, `RAV_RMSSD`, and `RAV_CVSD`.
113Do not interpret RRV/RAV from only a few breaths. Choose duration from the lowest
114frequency and nonlinear metric being estimated, and report breath count, usable
115duration, irregular-breath exclusions, and sensitivity. There is no universal
116“higher is healthier” interpretation.

RRV and RAV

rrv = nk.rsp_rrv(
    signals["RSP_Rate"],
    troughs=info["RSP_Troughs"],
    sampling_rate=50,
)
rav = nk.rsp_rav(
    signals["RSP_Amplitude"],
    peaks=info,
)

The pinned rsp_rrv() output had 20 columns spanning interval, frequency, Poincaré, and entropy metrics (RRV_RMSSD through RRV_SampEn). The pinned RAV output had RAV_Mean, RAV_SD, RAV_RMSSD, and RAV_CVSD.

Do not interpret RRV/RAV from only a few breaths. Choose duration from the lowest frequency and nonlinear metric being estimated, and report breath count, usable duration, irregular-breath exclusions, and sensitivity. There is no universal “higher is healthier” interpretation.

Raw lines 95 to 117
118## Respiratory volume per time
120Direct stable signature:
122```text
123rsp_rvt(
124 rsp_signal, sampling_rate=1000, method="power2020",
125 boundaries=[2.0, 0.033333...], iterations=10, ...
127```
129Direct `rsp_rvt()` defaults to `power2020`, while `rsp_process()` defaults its
130`method_rvt` to `harrison2021`. Other stable option: `birn2006`.
132```python
133rvt = nk.rsp_rvt(
134 clean,
135 sampling_rate=50,
136 method="harrison2021",
138```
140RVT is a derived proxy/regressor. It is not calibrated respiratory volume or minute
141ventilation. For fMRI nuisance modeling, match the cited definition, acquisition,
142lag/convolution, resampling, and scanner preprocessing; do not treat one method as
143interchangeable with another.

Respiratory volume per time

Direct stable signature:

rsp_rvt(
  rsp_signal, sampling_rate=1000, method="power2020",
  boundaries=[2.0, 0.033333...], iterations=10, ...
)

Direct rsp_rvt() defaults to power2020, while rsp_process() defaults its method_rvt to harrison2021. Other stable option: birn2006.

rvt = nk.rsp_rvt(
    clean,
    sampling_rate=50,
    method="harrison2021",
)

RVT is a derived proxy/regressor. It is not calibrated respiratory volume or minute ventilation. For fMRI nuisance modeling, match the cited definition, acquisition, lag/convolution, resampling, and scanner preprocessing; do not treat one method as interchangeable with another.

Raw lines 118 to 144
145## Missing data and artifacts
147Respiration signals commonly contain nonstationary physiology. Do not automatically
148classify sighs, pauses, speech, coughing, or swallowing as noise. Annotate them according
149to the research question.
151- Segment long gaps/detachment.
152- Do not interpolate across apnea-like pauses or speech and then compute rate.
153- Preserve raw/clean/extrema overlays.
154- Track filter and window edge validity.
155- Quantify missing breaths and altered intervals after exclusions.
156- Verify belt slippage and baseline drift separately from breathing depth.

Missing data and artifacts

Respiration signals commonly contain nonstationary physiology. Do not automatically classify sighs, pauses, speech, coughing, or swallowing as noise. Annotate them according to the research question.

  • Segment long gaps/detachment.
  • Do not interpolate across apnea-like pauses or speech and then compute rate.
  • Preserve raw/clean/extrema overlays.
  • Track filter and window edge validity.
  • Quantify missing breaths and altered intervals after exclusions.
  • Verify belt slippage and baseline drift separately from breathing depth.
Raw lines 145 to 157
158## Event and interval analysis
160```python
161epochs = nk.epochs_create(
162 signals,
163 events,
164 sampling_rate=50,
165 epochs_start=-1,
166 epochs_end=8,
167 baseline_correction=False,
169event_features = nk.rsp_eventrelated(epochs)
170interval_features = nk.rsp_intervalrelated(signals, sampling_rate=50)
171```
173Event-related features are conditional and include rate/amplitude baselines and
174post-event summaries, phase/completion at onset, and RVT fields when present. Interval
175analysis can append RRV/RAV and inspiration/expiration duration features. Inspect the
176runtime schema.
178Baseline subtraction is usually inappropriate for binary phase/peak columns. Prespecify
179which continuous features, if any, are baseline corrected.

Event and interval analysis

epochs = nk.epochs_create(
    signals,
    events,
    sampling_rate=50,
    epochs_start=-1,
    epochs_end=8,
    baseline_correction=False,
)
event_features = nk.rsp_eventrelated(epochs)
interval_features = nk.rsp_intervalrelated(signals, sampling_rate=50)

Event-related features are conditional and include rate/amplitude baselines and post-event summaries, phase/completion at onset, and RVT fields when present. Interval analysis can append RRV/RAV and inspiration/expiration duration features. Inspect the runtime schema.

Baseline subtraction is usually inappropriate for binary phase/peak columns. Prespecify which continuous features, if any, are baseline corrected.

Raw lines 158 to 180
181## RSA and alignment
183For RSA, ECG and respiration need a shared clock and verified lag/drift:
185```python
186rsa = nk.hrv_rsa(
187 ecg_signals,
188 rsp_signals,
189 rpeaks=ecg_info,
190 sampling_rate=common_rate,
191 continuous=False,
193```
195Measure and report respiration; spontaneous or paced breathing changes the estimand.
196RSA can reflect cardiac vagal modulation under suitable conditions but is confounded by
197respiratory parameters, activity, posture, age, and adrenergic influence.

RSA and alignment

For RSA, ECG and respiration need a shared clock and verified lag/drift:

rsa = nk.hrv_rsa(
    ecg_signals,
    rsp_signals,
    rpeaks=ecg_info,
    sampling_rate=common_rate,
    continuous=False,
)

Measure and report respiration; spontaneous or paced breathing changes the estimand. RSA can reflect cardiac vagal modulation under suitable conditions but is confounded by respiratory parameters, activity, posture, age, and adrenergic influence.

Raw lines 181 to 198
199## Interpretation boundary
201Use this module for respiratory time-series research. It is not a validated system for
202apnea detection, capnography, tidal-volume measurement, respiratory diagnosis,
203biofeedback safety, patient/driver monitoring, or ventilatory control.

Interpretation boundary

Use this module for respiratory time-series research. It is not a validated system for apnea detection, capnography, tidal-volume measurement, respiratory diagnosis, biofeedback safety, patient/driver monitoring, or ventilatory control.

Raw lines 199 to 204
205## Sources checked 2026-10-01
207- [Official RSP API](https://neuropsychology.github.io/NeuroKit/functions/rsp.html)
208- [Official RRV example](https://neuropsychology.github.io/NeuroKit/examples/rsp_rrv/rsp_rrv.html)
209- [Stable v0.2.13 RSP source](https://github.com/neuropsychology/NeuroKit/tree/v0.2.13/neurokit2/rsp)
210- [Grossman & Taylor (2007), respiration/RSA caveats](https://doi.org/10.1016/j.biopsycho.2005.11.014)
211- [Berntson et al. (1997), HRV origins/methods/caveats](https://doi.org/10.1111/j.1469-8986.1997.tb02140.x)
212- [Birn et al. (2006), RVT and fMRI](https://doi.org/10.1016/j.neuroimage.2005.11.053)