systole.utils.heart_rate#
- systole.utils.heart_rate(x: Union[List, ndarray], sfreq: int = 1000, unit: str = 'rr', kind: str = 'cubic', input_type: str = 'peaks') Tuple[ndarray, ndarray][source]#
- Transform peaks data or RR intervals into continuous heart rate time series. - Parameters
- x
- Boolean vector of peaks detection or RR intervals. 
- sfreq
- The sampling frequency of the desired output. 
- unit
- The heart rate unit in use. Can be ‘rr’ (R-R intervals, in ms) or ‘bpm’ (beats per minutes). Default is ‘rr’. 
- kind
- The method to use (parameter of scipy.interpolate.interp1d). The possible relevant methods for instantaneous heart rate are ‘cubic’ (defalut), ‘linear’, ‘previous’ and ‘next’. 
- input_type
- The type of input vector. Default is “peaks” (a boolean vector where 1 represents the occurrence of R waves or systolic peaks). Can also be “rr_s” or “rr_ms” for vectors of RR intervals, or interbeat intervals (IBI), expressed in seconds or milliseconds (respectively). 
 
- Returns
- heartrate
- The heart rate frequency. 
- time
- Time array. 
 
 - Notes - If the input is in the peaks format, it should be a boolean vector encoding the position of R wave, or systolic peaks. - If it is in the form of RR intervals, it can be expressed in seconds or milliseconds, using rr_s and rr_ms parameters, respectively. - The time and heart rate output will have the same length. Values before the first peak and after the last peak will be filled with NaN values. - Examples - From a boolean vector of peaks position: 
 - >>> from systole import import_ppg >>> ppg = import_ppg().ppg.to_numpy() # Import PPG recording >>> _, peaks = ppg_peaks(ppg) # Find systolic peaks >>> heartrate, time = heart_rate(peaks) # Create continuous time series - 2. From a vector of RR intervals (miliseconds): >>> from systole import import_rr >>> rr = import_rr().rr.values >>> heartrate, time = heart_rate(rr, unit=”bpm”, input_type=”rr_ms”)