metrics
Functions
compute_heart_rate(data, sample_rate=1000, method='peak', **kwargs)
Compute heart rate from ECG signal.
Parameters:
-
data(NDArray) –ECG signal (1-D).
-
sample_rate(float, default:1000) –Sampling rate in Hz.
-
method(str, default:'peak') –Heart-rate method, currently supports
"peak". -
**kwargs(dict, default:{}) –Additional keyword arguments for the selected method.
Returns:
Example
import numpy as np ecg = np.sin(2 * np.pi * 1.2 * np.arange(0, 2, 1/1000)) bpm, _ = compute_heart_rate(ecg, sample_rate=1000) int(round(bpm)) 72
Source code in physiokit/ecg/metrics.py
compute_heart_rate_from_peaks(data, sample_rate=1000, min_rr=0.3, max_rr=2.0, min_delta=0.3)
Compute heart rate from peaks of ECG signal.
Parameters:
-
data(NDArray) –ECG signal (1-D).
-
sample_rate(float, default:1000) –Sampling rate in Hz.
-
min_rr(float, default:0.3) –Minimum RR interval (s) allowed.
-
max_rr(float, default:2.0) –Maximum RR interval (s) allowed.
-
min_delta(float | None, default:0.3) –Allowed fractional RR deviation;
Noneto skip quotient filtering.
Returns:
Example
import numpy as np ecg = np.sin(2 * np.pi * 1.1 * np.arange(0, 2, 1/250)) bpm, qos = compute_heart_rate_from_peaks(ecg, sample_rate=250) bpm > 60, qos > 0 (True, True)
Source code in physiokit/ecg/metrics.py
compute_pulse_arrival_time(ecg, ppg, sample_rate, min_delay=0.1)
Compute pulse arrival time from ECG and PPG signals.
Parameters:
-
ecg(NDArray) –ECG signal (1-D).
-
ppg(NDArray) –PPG signal (aligned, 1-D).
-
sample_rate(float) –Sampling rate in Hz.
-
min_delay(float, default:0.1) –Minimum delay between ECG and PPG peaks in seconds.
Returns:
-
float(float) –Mean pulse arrival time in samples.
Example
import numpy as np ecg = np.zeros(200); ppg = np.zeros(200) ecg[[50, 150]] = 1; ppg[[55, 155]] = 1 round(compute_pulse_arrival_time(ecg, ppg, sample_rate=100)) 5
Source code in physiokit/ecg/metrics.py
derive_respiratory_rate(peaks, rri=None, sample_rate=1000, method='rifv', lowcut=0.1, highcut=1.0, order=3, threshold=0.85, interpolate_method='linear')
Derive respiratory rate from ECG signal using given method.
Parameters:
-
peaks(NDArray) –QRS peaks (indices).
-
rri(NDArray | None, default:None) –RR intervals; required for
"rifv". -
sample_rate(float, default:1000) –Sampling rate in Hz.
-
method(Literal['rifv'], default:'rifv') –Respiratory method; only
"rifv"supported. -
lowcut(float, default:0.1) –Lowcut frequency in Hz for respiration band.
-
highcut(float, default:1.0) –Highcut frequency in Hz for respiration band.
-
order(int, default:3) –Filter order.
-
threshold(float | None, default:0.85) –Threshold for FFT peak selection;
Noneto keep max only. -
interpolate_method(str, default:'linear') –Interpolation method for resampling the RR-derived signal.
Returns:
Example
import numpy as np peaks = np.arange(0, 500, 50) rri = np.full(peaks.size, 50) derive_respiratory_rate(peaks=peaks, rri=rri, sample_rate=1000) (72.0, np.float64(1.0))