1、完成了<ECG的R峰算法定位>的重构

2、创建好了<人工纠正>和<体动标注>的界面绘制
This commit is contained in:
Yorusora
2025-04-28 16:18:59 +08:00
parent f928fa4d9c
commit 2a13ceac39
27 changed files with 5552 additions and 312 deletions

View File

@ -29,31 +29,38 @@ def find_TPeak(data,peaks,th=50):
return_peak.append(argmax(data[min_win:max_win])+min_win)
return array(return_peak)
def Rpeak_Detection(raw_ecg,fs,low_cut,high_cut,th1,detector_method):
detectors = Detectors(sampling_frequency=fs)
method_dic = {'pt': detectors.pan_tompkins_detector,
'ta': detectors.two_average_detector,
"Engzee": detectors.engzee_detector,
"Wt": detectors.swt_detector,
"Christov": detectors.christov_detector,
"Hamilton": detectors.hamilton_detector
}
detectormethods = method_dic[detector_method]
def preprocess(raw_ecg, fs, low_cut, high_cut):
# raw_ecg = raw_ecg[200*sample_rate:]
preprocessing = BCG_Operation(sample_rate=fs) # 对ECG做了降采样处理
raw_ecg = preprocessing.Butterworth(raw_ecg, "bandpass", low_cut=low_cut, high_cut=high_cut, order=3) * 4
#######################限制幅值处理############################################
# for i in range(len(raw_ecg)):
# if raw_ecg[i] > 300 or raw_ecg[i] < -300:
# raw_ecg[i] = 0
##############################################################################
return raw_ecg
R_peak = array(detectormethods(raw_ecg)) - 100
# R_peak = np.array(detectors.pan_tompkins_detector(raw_ecg))-100
# 界面会通过这个函数获取方法列表此函数的返回值务必和Rpeak_Detection()中的方法名称对应否则程序或许直接崩溃
def get_method():
return ["pt", "ta", "Engzee", "Wt", "Christov", "Hamilton"]
R_peak = find_TPeak(raw_ecg, R_peak, th=int(th1 * fs / 1000))
R_peak = refinement(raw_ecg, R_peak)
def Rpeak_Detection(ecg,fs,th1,detector_method):
detectors = Detectors(sampling_frequency=fs)
if detector_method == "pt":
detectormethods = detectors.pan_tompkins_detector
elif detector_method == "ta":
detectormethods = detectors.two_average_detector
elif detector_method == "Engzee":
detectormethods = detectors.engzee_detector
elif detector_method == "Wt":
detectormethods = detectors.swt_detector
elif detector_method == "Christov":
detectormethods = detectors.christov_detector
elif detector_method == "Hamilton":
detectormethods = detectors.hamilton_detector
else:
raise Exception
R_peak = array(detectormethods(ecg)) - 100
R_peak = find_TPeak(ecg, R_peak, th=int(th1 * fs / 1000))
R_peak = refinement(ecg, R_peak)
RR_Interval = full(len(R_peak) - 1, nan)
@ -64,7 +71,7 @@ def Rpeak_Detection(raw_ecg,fs,low_cut,high_cut,th1,detector_method):
for i in range(len(RR_Interval) - 1):
RRIV[i] = RR_Interval[i + 1] - RR_Interval[i]
Interval = full(len(raw_ecg), nan)
Interval = full(len(ecg), nan)
for i in range(len(R_peak) - 1):
Interval[R_peak[i]: R_peak[i + 1]] = R_peak[i + 1] - R_peak[i]