Skip to content

Processing respiratory belt and airflow signals with neuroresp

Shane Lindsay

This walkthrough covers the peripheral respiratory tools in neuroresp: cleaning pneumatic and RIP belts, segmenting chest-wall movement states, and analysing direct airflow from spirometers or nasal cannulas.

A recurring issue with respiratory recordings is that sensor artefacts are easy to miss if you go straight to summary metrics. Pneumatic belts hit ceiling and floor limits during deep breaths or slip loose mid-recording. AC-coupled straps drift back towards baseline during breath holds. Filtering can smooth over a flat clipped peak so it looks like an ordinary breath, and chest-wall displacement does not map one-to-one onto airway flow.

We start with a simulated recording where the underlying breath timing and artefacts are known, then run the same workflow on open-access human recordings with simultaneous chest and abdominal bands and calibrated airflow. Install neuroresp in Python 3.11 or newer with python -m pip install neuroresp.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.signal import butter, sosfiltfilt

from neuroresp import analyse_airflow, clean_belt
from phrenic import simulate_respiration

plt.rcParams.update({
    "axes.spines.top": False,
    "axes.spines.right": False,
    "figure.dpi": 140,
})
TEAL = "#086d70"
ORANGE = "#b45125"
SLATE = "#334155"

1. Simulated signals

simulate_respiration() generates coupled 1D traces from a single underlying lung-volume trajectory: calibrated flow, nasal cannula pressure, a DC-coupled RIP band, and an AC-coupled belt. Here we create a 90-second recording with a deep sigh around 18 s (2.2 times normal tidal volume), a 6 s peak hold starting at 42 s, upper-rail clipping on the AC belt at the 92nd percentile, and a 5 s loose-strap flatline starting at 68 s.

sim = simulate_respiration(
    duration_s=90.0,
    fs=100.0,
    rate_bpm=14.0,
    rate_sd_bpm=0.8,
    duty_cycle=0.40,
    inh_pause_s=0.15,
    exp_pause_s=0.45,
    vt_l=0.50,
    vt_cv=0.06,
    sigh_times_s=(18.0,),
    sigh_scale=2.2,
    hold_intervals_s=((42.0, 6.0),),
    hold_phase="peak",
    ac_highpass_hz=0.05,
    belt_clip_quantile=0.92,
    loose_intervals_s=((68.0, 5.0),),
    noise_level=0.01,
    seed=4,
)

t = sim["time_s"]
sim["truth"].head().round(3)
| | start_s | insp_end_s | exp_start_s | exp_end_s | end_s | duration_s | ti_s | te_active_s | inh_pause_s | exp_pause_s | vt_l | is_sigh | |----|----|----|----|----|----|----|----|----|----|----|----|----| | 0 | 0.00 | 1.78 | 1.93 | 4.00 | 4.45 | 4.45 | 1.78 | 2.07 | 0.15 | 0.45 | 0.494 | False | | 1 | 4.45 | 6.01 | 6.16 | 7.91 | 8.36 | 3.91 | 1.56 | 1.75 | 0.15 | 0.45 | 0.519 | False | | 2 | 8.36 | 10.25 | 10.40 | 12.64 | 13.09 | 4.73 | 1.89 | 2.24 | 0.15 | 0.45 | 0.499 | False | | 3 | 13.09 | 14.87 | 15.02 | 17.08 | 17.53 | 4.44 | 1.78 | 2.06 | 0.15 | 0.45 | 0.504 | False | | 4 | 17.53 | 19.42 | 19.57 | 21.80 | 22.25 | 4.72 | 1.89 | 2.23 | 0.15 | 0.45 | 1.114 | True |

The raw signals over 60 to 90 seconds show clipping, drift, and dropouts before any filtering is applied.

fig, axes = plt.subplots(3, 1, figsize=(10, 6.5), sharex=True, constrained_layout=True)

for ax in axes:
    ax.axvspan(16.0, 21.5, color=ORANGE, alpha=0.14)
    ax.axvspan(42.0, 48.0, color=TEAL, alpha=0.14)
    ax.axvspan(68.0, 73.0, color="#64748b", alpha=0.18)

axes[0].plot(t, sim["flow_l_s"], color=SLATE, lw=1.2)
axes[0].axhline(0, color="#94a3b8", lw=0.7, ls="--")
axes[0].set(ylim=(-1.2, 1.55), ylabel="Flow (L/s)", title="Calibrated airway flow")
axes[0].text(18.75, 1.35, "Sigh (16-21.5 s)", ha="center", color=ORANGE, fontweight="bold", fontsize=9)
axes[0].text(45.0, 1.35, "6 s hold (42-48 s)", ha="center", color=TEAL, fontweight="bold", fontsize=9)

ac_aligned = (sim["ac_belt"] - np.median(sim["ac_belt"])) + np.median(sim["rip_volume"])
axes[1].plot(t, sim["rip_volume"], color=TEAL, lw=1.3, label="DC-coupled RIP volume (L)")
axes[1].plot(t, ac_aligned, color=ORANGE, lw=1.1, label="AC-coupled belt (clipped + loose)")
axes[1].set(ylim=(-0.3, 1.62), ylabel="Volume / belt")
axes[1].set_title("DC-coupled volume and AC-coupled belt", loc="left")
axes[1].text(18.75, 1.22, "Belt clips flat", ha="center", color=ORANGE, fontweight="bold", fontsize=8.5)
axes[1].text(45.0, 1.22, "AC belt decays", ha="center", color=TEAL, fontweight="bold", fontsize=8.5)
axes[1].text(70.5, 1.22, "Loose strap (68-73 s)", ha="center", color="#334155", fontweight="bold", fontsize=8.5)
axes[1].legend(frameon=False, loc="upper right", ncol=2, bbox_to_anchor=(1.0, 1.15))

axes[2].plot(t, sim["nasal_pressure"], color="#0f766e", lw=1.1)
axes[2].axhline(0.1, color="#94a3b8", lw=0.7, ls="--")
axes[2].set(xlabel="Time (s)", ylabel="Pressure (a.u.)", title="Nasal cannula pressure")
axes[2].set_xlim(0, 90)
plt.show()

As can be seen in the middle panel, the sigh around 18 s doubles lung volume in the DC trace while the AC belt hits its ceiling and flattens. During the 6 s hold at 42 s, flow is zero and the DC trace stays flat at peak volume, whereas the AC belt decays downwards across the hold. At 68 s, the loose strap freezes the belt while breathing continues.

2. Clipping, filtering, and belt cleaning

A bandpass filter applied directly to a clipped belt rounds off the flat ceiling. The 10 to 30 s zoom below shows how a standard 0.05 to 0.50 Hz bandpass turns the clipped sigh into a smooth peak.

sos = butter(4, (0.05, 0.50), btype="bandpass", fs=sim["fs"], output="sos")
naive_filtered = sosfiltfilt(sos, sim["ac_belt"])

win = (t >= 10) & (t <= 30)
fig, ax = plt.subplots(figsize=(9.5, 3.2), constrained_layout=True)
ax.plot(t[win], sim["ac_belt"][win] - np.median(sim["ac_belt"][win]), color=SLATE, lw=1.2, label="Raw AC belt")
ax.plot(t[win], naive_filtered[win], color=ORANGE, lw=1.4, ls="--", label="Bandpass filtered (0.05-0.50 Hz)")
ax.set(xlabel="Time (s)", ylabel="Belt signal (centred)", title="Effect of bandpass filtering on a clipped sigh")
ax.legend(frameon=False)
plt.show()

If a recording contains one or two sighs and they hit the ceiling, smoothing before checking for saturation hides the clipping and can produce a sigh rate of zero.

clean_belt() checks for rail saturation and loose-strap flatlines before filtering. Here we pass the known upper rail; when rails are omitted on a standard AC belt, it detects flat runs of at least 80 ms at the empirical extrema.

resp_ac, breaths_ac, summary_ac, masks_ac = clean_belt(
    sim["ac_belt"],
    sim["fs"],
    upper_rail=sim["belt_upper_rail"],
)

pd.Series({
    "n_breaths": summary_ac["n_breaths"],
    "n_segments": summary_ac["n_segments"],
    "cycle_rate_median_bpm": round(summary_ac["cycle_rate_median_bpm"], 2),
    "clip_fraction": round(summary_ac["clip_fraction"], 3),
    "loose_fraction": round(summary_ac["loose_fraction"], 3),
    "n_clipped_cycles": summary_ac["n_clipped_cycles"],
    "sigh_rate_censored": summary_ac["sigh_rate_censored"],
    "sigh_rate_per_min": summary_ac["sigh_rate_per_min"],
})
n_breaths                   15
n_segments                   3
cycle_rate_median_bpm    13.45
clip_fraction             0.09
loose_fraction           0.115
n_clipped_cycles             8
sigh_rate_censored        True
sigh_rate_per_min         None
dtype: object

The loose-strap dropout splits the recording into two segments (n_segments = 2), so lagged variability metrics (RMSSD, amp_lsd) are computed within uninterrupted stretches only. Clipped cycles are flagged in breaths_ac, excluded from depth dispersion, and cause sigh_rate_per_min to be set to None (sigh_rate_censored = True) rather than zero. Median breathing rate is still recovered from the clean cycles.

For the DC-coupled trace, passing dc_coupled=True restricts clipping detection to explicit rail bounds so genuine flat holds are not treated as saturation. Because loose-strap detection defaults to 4 s of low excursion, we set loose_min_s=0 to keep the 6 s hold observed, and enable states=True to segment chest-wall expansion, recoil, and dwell.

resp_dc, breaths_dc, summary_dc, _ = clean_belt(
    sim["rip_volume"],
    sim["fs"],
    dc_coupled=True,
    states=True,
    loose_min_s=0,
)

runs = resp_dc.belt_states.runs
runs.loc[(runs["end_s"] >= 40) & (runs["start_s"] <= 50), ["state_name", "start_s", "end_s", "duration_s"]].round(2)
| | state_name | start_s | end_s | duration_s | |-----|--------------|---------|-------|------------| | 36 | trough_dwell | 39.6 | 40.4 | 0.8 | | 37 | expansion | 40.4 | 41.9 | 1.5 | | 38 | peak_dwell | 41.9 | 48.3 | 6.4 | | 39 | recoil | 48.3 | 50.0 | 1.7 | | 40 | trough_dwell | 50.0 | 50.8 | 0.8 |

The hold between 42 and 48 s is recovered as a peak_dwell state on the DC trace.

3. Real data: chest belt, abdominal belt, and airflow

Next we load two recordings from the same participant (Subject_11) in the open-access PhysioNet CPAP dataset (Guy et al., 2023): one minute of normal breathing and one minute of deep breathing at 0 cmH2O, sampled at 100 Hz with chest circumference, abdominal circumference, and calibrated Venturi airflow.

BASE_URL = "https://physionet.org/files/pressure-flow-circum-cpap/1.0.0/processed-data"
df_norm = pd.read_csv(f"{BASE_URL}/0cmH2O_norm/Subject_11_0cmH20_norm_breaths.csv")
df_deep = pd.read_csv(f"{BASE_URL}/0cmH2O_deep/Subject_11_0cmH20_deep_breaths.csv")

fs = round(1.0 / np.median(np.diff(df_norm["Time [s]"])))
print(f"Normal: {len(df_norm)} samples ({len(df_norm)/fs:.1f} s at {fs} Hz)")
print(f"Deep:   {len(df_deep)} samples ({len(df_deep)/fs:.1f} s at {fs} Hz)")
df_norm.head(3).round(3)
Normal: 5466 samples (54.7 s at 100 Hz)
Deep:   5578 samples (55.8 s at 100 Hz)
| | Time \[s\] | Pressure \[cmH2O\] | Flow \[L/s\] | V_tidal \[L\] | Chest \[mm\] | Abd \[mm\] | InspInd | |----|----|----|----|----|----|----|----| | 0 | 0.00 | -0.112 | 0.000 | 0.000 | 916.301 | 885.278 | 1 | | 1 | 0.01 | -0.132 | 0.042 | 0.000 | 916.301 | 885.278 | 410 | | 2 | 0.02 | -0.145 | 0.070 | 0.001 | 916.301 | 885.310 | 841 |

The next plot shows the first 30 seconds of normal breathing across the individual chest and abdominal bands, their centred sum, and the simultaneous airflow signal.

t_n = df_norm["Time [s]"].to_numpy(float)
chest_n = df_norm["Chest [mm]"].to_numpy(float)
abd_n = df_norm["Abd [mm]"].to_numpy(float)
dual_n = (chest_n - np.nanmedian(chest_n)) + (abd_n - np.nanmedian(abd_n))
flow_n = df_norm["Flow [L/s]"].to_numpy(float)

win = t_n <= 30.0
fig, axes = plt.subplots(2, 1, figsize=(10, 5.0), sharex=True, constrained_layout=True)

axes[0].plot(t_n[win], chest_n[win] - np.median(chest_n), color=SLATE, lw=1.0, alpha=0.8, label="Chest band (mm, centred)")
axes[0].plot(t_n[win], abd_n[win] - np.median(abd_n), color=ORANGE, lw=1.0, alpha=0.8, label="Abdomen band (mm, centred)")
axes[0].plot(t_n[win], dual_n[win], color=TEAL, lw=1.5, label="Summed chest + abdomen")
axes[0].set(ylim=(-9, 17.5), ylabel="Circumference (mm)", title="Normal breathing: chest and abdominal bands (Subject 11)")
axes[0].legend(frameon=False, ncol=3, loc="upper right")

axes[1].plot(t_n[win], flow_n[win], color=SLATE, lw=1.2, label="Calibrated airflow (L/s)")
axes[1].axhline(0, color="#94a3b8", lw=0.7, ls="--")
axes[1].set(xlabel="Time (s)", ylabel="Flow (L/s)", title="Simultaneous calibrated airflow")
axes[1].set_xlim(0, 30)
plt.show()

The peaks and troughs of the chest-wall trace match the zero-crossing points of the flow line. In the bottom panel, clear zero-flow expiratory pauses appear between breaths, whereas the circumference traces in the top panel round more gradually through the turnarounds. That mechanical lag and hysteresis is why belt turnarounds are not interchangeable with inline airway timing across participants.

4. Direct airflow analysis

For signed flow or nasal-pressure recordings, analyse_airflow() defines active inspiration and expiration at 10% of each breath’s own peak flow, so phase timing and pause fractions do not depend on overall sensor gain. With calibrated=True, hardware zero is kept intact and tidal volume and minute ventilation are calculated in litres and L/min.

flow_d = df_deep["Flow [L/s]"].to_numpy(float)

af_norm = analyse_airflow(flow_n, fs, calibrated=True)
af_deep = analyse_airflow(flow_d, fs, calibrated=True)

cols = [
    "n_breaths", "cycle_rate_median_bpm", "duty_cycle_median", "ie_ratio_median",
    "tptif_ti_median", "tptef_te_median", "exp_pause_frac_median",
    "vt_median_l", "ve_l_min", "ve_observed_l_min",
]
pd.DataFrame({
    "Normal (0 cmH2O)": {k: af_norm["summary"][k] for k in cols},
    "Deep (0 cmH2O)": {k: af_deep["summary"][k] for k in cols},
}).round(3)
| | Normal (0 cmH2O) | Deep (0 cmH2O) | |-----------------------|------------------|----------------| | n_breaths | 10.000 | 9.000 | | cycle_rate_median_bpm | 12.101 | 10.661 | | duty_cycle_median | 0.327 | 0.389 | | ie_ratio_median | 0.872 | 0.974 | | tptif_ti_median | 0.387 | 0.622 | | tptef_te_median | 0.284 | 0.166 | | exp_pause_frac_median | 0.157 | 0.129 | | vt_median_l | 0.391 | 0.875 | | ve_l_min | 4.980 | 9.452 | | ve_observed_l_min | 4.467 | 8.509 |

In the deep breathing condition, median rate drops slightly (12.1 to 10.7 breaths/min) while median tidal volume increases from 0.39 to 0.88 L and minute ventilation increases from 4.98 to 9.45 L/min. The breath-by-breath table contains the individual phase durations, pauses, peak-flow timing (tptif_ti, tptef_te), contour flatness (flatness_in, flatness_ex), and tidal volume.

af_norm["breaths"][[
    "start_s", "duration_s", "ti_s", "te_active_s", "inh_pause_s", "exp_pause_s",
    "duty_cycle", "tptif_ti", "flatness_in", "vt_l",
]].head().round(3)
| | start_s | duration_s | ti_s | te_active_s | inh_pause_s | exp_pause_s | duty_cycle | tptif_ti | flatness_in | vt_l | |----|----|----|----|----|----|----|----|----|----|----| | 0 | 0.008 | 4.095 | 1.524 | 1.672 | 0.349 | 0.549 | 0.372 | 0.467 | 0.715 | 0.359 | | 1 | 4.103 | 4.303 | 1.502 | 1.654 | 0.516 | 0.631 | 0.349 | 0.438 | 0.767 | 0.374 | | 2 | 8.406 | 4.533 | 1.475 | 1.790 | 0.671 | 0.597 | 0.325 | 0.423 | 0.793 | 0.392 | | 3 | 12.939 | 5.349 | 2.156 | 2.195 | 0.258 | 0.740 | 0.403 | 0.817 | 0.753 | 0.612 | | 4 | 18.288 | 4.661 | 1.508 | 1.914 | 0.655 | 0.584 | 0.323 | 0.373 | 0.806 | 0.413 |

For an uncalibrated nasal pressure cannula, pass sensor="nasal_pressure". The signal is linearised with a signed square root around a volume-balanced baseline, low-rate recordings (such as 6 Hz cannulas) are upsampled with shape-preserving interpolation, and volume fields stay None.

af_cannula = analyse_airflow(sim["nasal_pressure"], sim["fs"], sensor="nasal_pressure")
pd.Series({
    "rate_bpm": round(af_cannula["summary"]["cycle_rate_median_bpm"], 2),
    "duty_cycle": round(af_cannula["summary"]["duty_cycle_median"], 3),
    "exp_pause_frac": round(af_cannula["summary"]["exp_pause_frac_median"], 3),
    "vt_median_l": af_cannula["summary"]["vt_median_l"],
})
rate_bpm          13.620
duty_cycle         0.334
exp_pause_frac     0.187
vt_median_l          NaN
dtype: float64

5. Four-state segmentation on DC-coupled belts

Next we run clean_belt(..., dc_coupled=True, states=True) on the summed chest and abdominal bands from the same normal and deep recordings. The outputs are named after chest-wall movement (expansion_s, recoil_s, peak_dwell_s, trough_dwell_s) rather than airway zero-flow timing, and are intended for within-person comparisons on calibrated DC-coupled bands.

chest_d = df_deep["Chest [mm]"].to_numpy(float)
abd_d = df_deep["Abd [mm]"].to_numpy(float)
dual_d = (chest_d - np.nanmedian(chest_d)) + (abd_d - np.nanmedian(abd_d))

resp_b_norm, _, sum_b_norm, _ = clean_belt(dual_n, fs, dc_coupled=True, states=True)
resp_b_deep, _, sum_b_deep, _ = clean_belt(dual_d, fs, dc_coupled=True, states=True)

state_cols = [
    "n_state_cycles", "expansion_s", "recoil_s",
    "peak_dwell_s", "trough_dwell_s", "expansion_recoil_ratio",
]
pd.DataFrame({
    "Normal (dual RIP)": {k: sum_b_norm["belt_states"][k] for k in state_cols},
    "Deep (dual RIP)": {k: sum_b_deep["belt_states"][k] for k in state_cols},
}).round(3)
| | Normal (dual RIP) | Deep (dual RIP) | |------------------------|-------------------|-----------------| | n_state_cycles | 9.000 | 8.000 | | expansion_s | 2.100 | 2.300 | | recoil_s | 2.500 | 2.500 | | peak_dwell_s | 0.000 | 0.450 | | trough_dwell_s | 0.000 | 0.300 | | expansion_recoil_ratio | 0.828 | 0.976 |

Across the two conditions on the summed bands, expansion_recoil_ratio increases from 0.83 to 0.98 (matching the direction of airflow ie_ratio_median, 0.87 to 0.97), and median peak and trough dwells appear in deep breathing (0.45 s and 0.30 s compared with 0.0 s during normal breathing). The plot below overlays the detected dwell intervals on the cleaned contour to check where they land.

seg = resp_b_deep.belt_states
t_s = seg.time_s
runs_d = seg.runs

fig, ax = plt.subplots(figsize=(10, 3.4), constrained_layout=True)
ax.plot(t_s, seg.cleaned, color=TEAL, lw=1.4, label="Cleaned chest + abdomen contour")
for _, row in runs_d.iterrows():
    if row["state_name"] == "peak_dwell":
        ax.axvspan(row["start_s"], row["end_s"], color=TEAL, alpha=0.16)
    elif row["state_name"] == "trough_dwell":
        ax.axvspan(row["start_s"], row["end_s"], color=ORANGE, alpha=0.18)

ax.axvspan(-1, -1, color=TEAL, alpha=0.16, label="Peak dwell")
ax.axvspan(-1, -1, color=ORANGE, alpha=0.18, label="Trough dwell")
ax.set(xlim=(0, 45), ylim=(-15, 19.5), xlabel="Time (s)", ylabel="Summed circumference (mm)",
       title="Deep breathing: four-state segmentation on dual-band RIP (Subject 11)")
ax.legend(frameon=False, loc="upper right", ncol=3)
plt.show()

6. Summary

  • Plot a 30 to 60 s window of the raw signal before filtering so rail clipping, loose-strap dropouts, and AC bleed-back are visible.
  • Check clip_fraction, n_clipped_cycles, and sigh_rate_censored before interpreting amplitude variability or sigh rates.
  • Keep lagged variability measures (RMSSD, amp_lsd) inside contiguous segments (n_segments).
  • Use pneumatic and RIP belts for breathing rate, cycle timing, and within-person contour or dwell changes on calibrated DC bands; use analyse_airflow() when absolute airway timing across people or calibrated volumes in litres are required.

References

  • Guy, E. F. S., Knopp, J., Lerios, T., & Chase, J. G. (2023). Pressure, flow, and dynamic thoraco-abdominal circumferences data for adults breathing under CPAP therapy (version 1.0.0). PhysioNet. https://doi.org/10.13026/25q9-y416
  • Pollard, T., Moody, B. E., Lehman, L., Gow, B., Fernandes, C., Xie, C., Johnson, A., Mark, R. G., & Heldt, T. (2026). PhysioNet as a global platform for biomedical research. Nature Health, 1(8), 792-795. https://doi.org/10.1038/s44360-026-00096-z