Respiratory (RSP)
Respiratory rate is often measured on the chest using a respiration belt or a respiratory inductance plethysmography (RIP) sensor. PhysioKit provides a set of functions to process RSP signals. The functions can be used to generate synthetic RSP signals, clean noisy RSP signals, extract respiratory peaks, compute respiratory rate, and compute dual band metrics.
physiokit.rsp.defines
RspDualMetrics
dataclass
Respiratory dual band metrics.
Source code in physiokit/rsp/defines.py
RspFiducial
physiokit.rsp.clean
clean(data, lowcut=0.05, highcut=3, sample_rate=1000, order=3, axis=-1, forward_backward=True)
Clean respiratory signal using biquad filter.
By default, applies a 3rd order Butterworth filter between 0.05 and 3 Hz.
Parameters:
-
data
(NDArray
) –Signal
-
lowcut
(float
, default:0.05
) –Lower cutoff in Hz. Defaults to 0.05 Hz (3 bpm).
-
highcut
(float
, default:3
) –Upper cutoff in Hz. Defaults to 3 Hz (180 bpm).
-
sample_rate
(float
, default:1000
) –Sample rate in Hz. Defaults to 1000 Hz.
-
order
(int
, default:3
) –Filter order. Defaults to 3 (3rd order Butterworth filter).
-
axis
(int
, default:-1
) –Axis to apply against. Defaults to -1.
-
forward_backward
(bool
, default:True
) –Apply filter forward and backward. Defaults to True.
Returns:
-
NDArray
–npt.NDArray: Cleaned signal
Source code in physiokit/rsp/clean.py
physiokit.rsp.metrics
compute_dual_band_metrics(rc, ab, sample_rate=1000, lowcut=0.05, highcut=3.0, fft_len=None, pwr_threshold=0.8)
Compute respiratory dual band metrics.
Parameters:
-
rc
(array
) –Ribcage band.
-
ab
(array
) –Abdominal band.
-
sample_rate
(float
, default:1000
) –Sampling rate in Hz. Defaults to 1000 Hz.
-
lowcut
(float
, default:0.05
) –Lowcut frequency in Hz. Defaults to 0.05 Hz.
-
highcut
(float
, default:3.0
) –Highcut frequency in Hz. Defaults to 3.0 Hz.
-
fft_len
(int
, default:None
) –FFT length. Defaults to None.
-
pwr_threshold
(float
, default:0.8
) –Power threshold. Defaults to 0.80.
Returns:
-
RspDualMetrics
(RspDualMetrics
) –Respiratory dual band metrics.
Source code in physiokit/rsp/metrics.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
compute_respiratory_rate(data, sample_rate=1000, method='fft', **kwargs)
Compute respiratory rate in BPM from signal.
Parameters:
-
data
(array
) –RSP signal.
-
sample_rate
(float
, default:1000
) –Sampling rate in Hz. Defaults to 1000 Hz.
-
method
(str
, default:'fft'
) –Method to compute respiratory rate. Defaults to 'fft'.
-
**kwargs
(dict
, default:{}
) –Keyword arguments to pass to method.
Returns:
Source code in physiokit/rsp/metrics.py
compute_respiratory_rate_from_fft(data, sample_rate=1000, lowcut=0.05, highcut=3.0)
Compute respiratory rate in BPM from FFT of respiratory signal.
Parameters:
-
data
(array
) –RSP signal.
-
sample_rate
(float
, default:1000
) –Sampling rate in Hz. Defaults to 1000 Hz.
-
lowcut
(float
, default:0.05
) –Lowcut frequency in Hz. Defaults to 0.05 Hz.
-
highcut
(float
, default:3.0
) –Highcut frequency in Hz. Defaults to 3.0 Hz.
Returns:
Source code in physiokit/rsp/metrics.py
compute_respiratory_rate_from_peaks(data, sample_rate=1000, min_rr=0.5, max_rr=20, min_delta=0.5)
Compute respiratory rate in BPM from peaks of PPG signal.
Parameters:
-
data
(array
) –RSP signal.
-
sample_rate
(float
, default:1000
) –Sampling rate in Hz. Defaults to 1000 Hz.
-
min_rr
(float
, default:0.5
) –Minimum RR interval in seconds. Defaults to 0.5 s.
-
max_rr
(float
, default:20
) –Maximum RR interval in seconds. Defaults to 20 s.
-
min_delta
(float
, default:0.5
) –Minimum delta between RR intervals in seconds. Defaults to 0.5 s.
Returns:
Source code in physiokit/rsp/metrics.py
physiokit.rsp.peaks
compute_rr_intervals(peaks)
Compute RR intervals from resp peaks.
Parameters:
-
peaks
(array
) –R peaks.
Returns:
-
NDArray
–npt.NDArray: RR intervals.
Source code in physiokit/rsp/peaks.py
filter_peaks(peaks, sample_rate=1000, min_rr=0.5, max_rr=20, min_delta=0.5)
Filter out peaks with RR intervals outside of normal range.
Parameters:
-
peaks
(array
) –Respiratory peaks.
-
sample_rate
(float
, default:1000
) –Sampling rate in Hz. Defaults to 1000 Hz.
-
min_rr
(float
, default:0.5
) –Minimum RR interval in seconds. Defaults to 0.5 s.
-
max_rr
(float
, default:20
) –Maximum RR interval in seconds. Defaults to 20 s.
-
min_delta
(float
, default:0.5
) –Minimum RR interval delta. Defaults to 0.5.
Returns:
-
NDArray
–npt.NDArray: Filtered peaks.
Source code in physiokit/rsp/peaks.py
filter_rr_intervals(rr_ints, sample_rate=1000, min_rr=0.5, max_rr=20, min_delta=0.5)
Filter out peaks with RR intervals outside of normal range.
Parameters:
-
rr_ints
(array
) –RR intervals.
-
sample_rate
(float
, default:1000
) –Sampling rate in Hz. Defaults to 1000 Hz.
-
min_rr
(float
, default:0.5
) –Minimum RR interval in seconds. Defaults to 0.5 s.
-
max_rr
(float
, default:20
) –Maximum RR interval in seconds. Defaults to 20 s.
-
min_delta
(float
, default:0.5
) –Minimum RR interval delta. Defaults to 0.5.
Returns:
-
NDArray
–npt.NDArray: Filtered RR intervals.
Source code in physiokit/rsp/peaks.py
find_peaks(data, sample_rate=1000, peak_window=0.5, breath_window=2.0, breath_offset=0.05, peak_delay=0.3)
Find peaks in RSP signal.
Assumes input data is bandpass filtered with a lowcut of .05 Hz and a highcut of 3 Hz.
Parameters:
-
data
(array
) –RSP signal.
-
sample_rate
(float
, default:1000
) –Sampling rate in Hz. Defaults to 1000 Hz.
-
peak_window
(float
, default:0.5
) –Peak window in seconds. Defaults to 0.5 s.
-
breath_window
(float
, default:2.0
) –Breath window in seconds. Defaults to 2.0 s.
-
breath_offset
(float
, default:0.05
) –Breath offset in seconds. Defaults to 0.05 s.
-
peak_delay
(float
, default:0.3
) –Peak delay in seconds. Defaults to 0.3 s.
Returns:
-
NDArray
–npt.NDArray: Peak locations.
Source code in physiokit/rsp/peaks.py
physiokit.rsp.synthesize
synthesize(signal_length=10000, sample_rate=1000, respiratory_rate=15)
Generate synthetic respiratory signal using breathmetrics method.
Utilize pk.signal.noise methods to make more realistic.
Parameters:
-
signal_length
(int
, default:10000
) –Signal length in samples. Defaults to 10000.
-
sample_rate
(float
, default:1000
) –Sample rate in Hz. Defaults to 1000 Hz.
-
respiratory_rate
(float
, default:15
) –Respiratory rate in breaths per minute. Defaults to 15 bpm.
Returns:
-
tuple[NDArray, NDArray, NDArray]
–tuple[npt.NDArray, npt.NDArray, npt.NDArray]: Synthetic respiratory signal, segmentation mask, fiducial mask