Files
Feature-Extraction/heart_rate.py
2025-10-20 22:01:18 +08:00

28 lines
879 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import numpy as np
from global_var import global_var_init
cycle, fs, record_name, data_path = global_var_init()
from ecg_peaks_val import ecg_peaks_val
(P_peaks, Q_peaks, R_peaks, S_peaks, T_peaks,
P_onsets, P_offsets, T_onsets, T_offsets,
P_peaks_values, Q_peaks_values, R_peaks_values, S_peaks_values, T_peaks_values,
P_onsets_values, P_offsets_values, T_onsets_values, T_offsets_values,
PQ_baseline) = ecg_peaks_val()
def compute_interval():
# 1. RR 间期
rr_s = np.diff(R_peaks) / fs # 单位:秒
rr_ms = rr_s * 1000 # 单位:毫秒
# 2. 瞬时心率
hr_inst = 60.0 / rr_s # 单位bpm
# 3. 平均心率
hr_mean = float(np.mean(hr_inst))
# print(f"瞬时心率: {hr_inst.round(1)} ")
print(f"平均心率: {hr_mean:.1f}")
if __name__ == "__main__":
compute_interval()