简单的基于信号处理的心电信号ECG特征波分割方法(MATLAB)

正常的心电图中,每个心跳周期内包含三个主要的特征波:P波、QRS波和T波,如下图所示。心电特征波能够反映心脏的生理状态信息,通过对其形状、幅值和持续时间的分析,可以用来辅助诊断心血管疾病。对于常见的ECG异常,如心律失常、房颤等,诊断依赖专家和临床医生对ECG进行目视检查。然而,随着心电数据规模不断扩大,分析大量的数据非常耗时,且受到专业知识的限制,及心电专家个人主观判断和经验的影响。

鉴于此,提出一种基于信号处理的心电信号ECG特征波分割方法,运行环境为MATLAB,分割算法的代码如下:

function [ECG_Struct] = ECG_Segmentation(signal,Fs,ECG_distance_threshold_sensivity,ECG_peak_sensivity,Plot_on)
ECG_Struct =struct;if(nargin<1)ECG_Struct=[];return;
elseif(nargin<2)Fs=1000;
elseif (nargin<3)ECG_distance_threshold_sensivity=5;ECG_peak_sensivity=35;Plot_on=1;
elseif (nargin<4)ECG_peak_sensivity=35;Plot_on=1;
elseif (nargin<5)Plot_on=1;
end
ECG_peak_threshold=round(Fs/100);
ECG_data=signal;
data_len=length(ECG_data);
format long
BL=[1 zeros(1,5) -2 zeros(1,5) 1];      
AL=[32,-64,32];
BH=[-1 zeros(1,15) 32 -32 zeros(1,14) 1];  
AH=[32 -32];
AINT=[8];
BINT=[2 1 0 -1 -2 ]; 
BMOV=ones(1,30)./30; 
AMOV=[1];
min_distance=(Fs/2)-round(Fs/6);
[preB,preA]=butter(4,[2/Fs 60/Fs]);
y=filtfilt(preB,preA,ECG_data);
yL=filter(BL,AL,y);
yH=filter(BH,AH,yL);
yder=filter(BINT,AINT,yH);
ysqu=yder.^2;
yaov=filter(BMOV,AMOV,ysqu);
[pks,locs]=findpeaks(yaov,'MinPeakDistance',Fs);
ECG_range=median(pks)+median(pks)/ECG_distance_threshold_sensivity;
if(max(pks>=ECG_range))pks= pks(~(pks>=ECG_range));locs=locs(~(pks>=ECG_range));
end
Threshold=max(pks)*ECG_peak_sensivity/100;
clear pks locs
[pks,locs]=findpeaks(yaov,'MinPeakHeight',Threshold,'MinPeakDistance',min_distance);
new_locs=zeros([size(locs)]);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
grp_delay = 23;  %  group delay of Pan-Tompkins filters.
if(locs(1,1)>round(Fs/grp_delay))new_locs=locs-round(Fs/grp_delay);
else% new_locs=[locs(1,1) locs(2:end)-round(Fs/23)];new_locs=locs(2:end)-round(Fs/grp_delay);pks=pks(2:end);
end
%%%%%%%%%R peak correction%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=2:length(new_locs)[d,r]=max(abs(ECG_data(new_locs(i)-ECG_peak_threshold : new_locs(i)+ECG_peak_threshold)));new_locs(i)=new_locs(i)-ECG_peak_threshold+r-1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
P_waves=[];
P_wave_locs=[];
T_waves=[];
T_wave_locs=[];
Q_waves=[];
Q_wave_locs=[];
S_waves=[];
S_wave_locs=[];
QT_intervals_locs=[];
PR_intervals_locs=[];
QRS_complex_locs=[];for i=1:length(new_locs)-1isoelectric_line(i)=mean(ECG_data(new_locs(i):new_locs(i+1)));
endfor i=1:length(new_locs)-2duration_coef=round(abs(new_locs(i+1)-new_locs(i)));if(duration_coef<=Fs)Q_T_duration=duration_coef/2;P_R_duration=duration_coef/4;QRS_mid_duration=0.06*duration_coef;elseQ_T_duration=Fs/2;P_R_duration=Fs/4;QRS_mid_duration=0.06*Fs;endx=ECG_data(round(new_locs(i+1)-P_R_duration:new_locs(i+1)-QRS_mid_duration));y=ECG_data(round(new_locs(i+1)+QRS_mid_duration:new_locs(i+1)+Q_T_duration));z=ECG_data(round(new_locs(i+1)-QRS_mid_duration:new_locs(i+1)));h=ECG_data(round(new_locs(i+1):new_locs(i+1)+QRS_mid_duration));P_waves=[P_waves max(x)];k=find(ECG_data==max(x));P_wave_locs=[P_wave_locs k(1,1)];T_waves=[T_waves max(y)];k=find(ECG_data==max(y));T_wave_locs=[T_wave_locs k(1,1)];Q_waves=[Q_waves min(z)];k=find(ECG_data==min(z));Q_wave_locs=[Q_wave_locs k(1,1)];S_waves=[S_waves min(h)];k=find(ECG_data==min(h));S_wave_locs=[S_wave_locs k(1,1)];
endQ_isolation=[];
for(i=1:length(Q_wave_locs))cnt=0;for j=1:duration_coefif(Q_wave_locs(i)-j < 1)break;endif(ECG_data(Q_wave_locs(i))<=isoelectric_line(i))if(ECG_data(Q_wave_locs(i)-j)>=isoelectric_line(i))Q_isolation=[Q_isolation Q_wave_locs(i)-j];cnt=1;break;endelseif(ECG_data(Q_wave_locs(i)-j)<=isoelectric_line(i))Q_isolation=[Q_isolation Q_wave_locs(i)-j];cnt=1;break;endendendif(cnt==0)Q_isolation=[Q_isolation Q_wave_locs(i)-j];end
endS_isolation=[];
for(i=1:length(S_wave_locs))cnt=0;for j=1:duration_coefif(S_wave_locs(i)+j > data_len)break;endif(ECG_data(S_wave_locs(i))<=isoelectric_line(i))if(ECG_data(S_wave_locs(i)+j)>=isoelectric_line(i))S_isolation=[S_isolation S_wave_locs(i)+j];cnt=1;break;endelseif(ECG_data(S_wave_locs(i)+j)<=isoelectric_line(i))S_isolation=[S_isolation S_wave_locs(i)+j];cnt=1;break;endendendif(cnt==0)S_isolation=[S_isolation Q_wave_locs(i)-j];    end
endP_isolation_1=[];
for(i=1:length(P_wave_locs))cnt=0;for j=1:duration_coefif(P_wave_locs(i)-j < 1)break;endif(ECG_data(P_wave_locs(i))<=isoelectric_line(i))if(ECG_data(P_wave_locs(i)-j)>=isoelectric_line(i))P_isolation_1=[P_isolation_1 P_wave_locs(i)-j];cnt=1;break;endelseif(ECG_data(P_wave_locs(i)-j)<=isoelectric_line(i))P_isolation_1=[P_isolation_1 P_wave_locs(i)-j];cnt=1;break;endendendif(cnt==0)P_isolation_1=[P_isolation_1 P_wave_locs(i)-j];end
endP_isolation_2=[];
for(i=1:length(P_wave_locs))cnt=0;for j=1:duration_coefif(P_wave_locs(i)+j > data_len)break;endif(ECG_data(P_wave_locs(i))<=isoelectric_line(i))if(ECG_data(P_wave_locs(i)+j)>=isoelectric_line(i))P_isolation_2=[P_isolation_2 P_wave_locs(i)+j];cnt=1;break;endelseif(ECG_data(P_wave_locs(i)+j)<=isoelectric_line(i))P_isolation_2=[P_isolation_2 P_wave_locs(i)+j];cnt=1;break;endendendif(cnt==0)P_isolation_2=[P_isolation_2 P_wave_locs(i)+j];    end
endT_isolation_1=[];
for(i=1:length(T_wave_locs))cnt=0;for j=1:duration_coefif(T_wave_locs(i)-j < 1)break;endif(ECG_data(T_wave_locs(i))<=isoelectric_line(i))if(ECG_data(T_wave_locs(i)-j)>=isoelectric_line(i))T_isolation_1=[T_isolation_1 T_wave_locs(i)-j];cnt=1;break;endelseif(ECG_data(T_wave_locs(i)-j)<=isoelectric_line(i))T_isolation_1=[T_isolation_1 T_wave_locs(i)-j];cnt=1;break;endendendif(cnt==0)T_isolation_1=[T_isolation_1 T_wave_locs(i)-j];    end
endT_isolation_2=[];
for(i=1:length(T_wave_locs))cnt=0;for j=1:duration_coefif(T_wave_locs(i)+j >data_len)break;endif(ECG_data(T_wave_locs(i))<=isoelectric_line(i))if(ECG_data(T_wave_locs(i)+j)>=isoelectric_line(i))T_isolation_2=[T_isolation_2 T_wave_locs(i)+j];cnt=1;break;endelseif(ECG_data(T_wave_locs(i)+j)<=isoelectric_line(i))T_isolation_2=[T_isolation_2 T_wave_locs(i)+j];cnt=1;break;endendendif(cnt==0)T_isolation_2=[T_isolation_2 T_wave_locs(i)+j];    end
end
clear x y k z h
if (Plot_on >=1)fig=figure('WindowState','maximized');t=1/Fs:1/Fs:length(ECG_data)/Fs;plot(t,ECG_data);hold ontxt = 'P';plot(P_wave_locs/Fs,P_waves,'s');text(P_wave_locs/Fs,P_waves,txt,'FontSize',14)txt = 'T';plot(T_wave_locs/Fs,T_waves,'o')text(T_wave_locs/Fs,T_waves,txt,'FontSize',14)txt = 'Q';plot(Q_wave_locs/Fs,Q_waves,'*')text(Q_wave_locs/Fs,Q_waves,txt,'FontSize',14)txt = 'S';plot(S_wave_locs/Fs,S_waves,'+')text(S_wave_locs/Fs,S_waves,txt,'FontSize',14)txt = 'R';plot(new_locs/Fs,ECG_data(new_locs),'x');text(new_locs/Fs,ECG_data(new_locs),txt,'FontSize',14)%%%%%%%%%%%%P wave%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%for i=1:length(P_isolation_1)plot((P_isolation_1(i):P_isolation_2(i))/Fs,ECG_data(P_isolation_1(i):P_isolation_2(i)),'g');end%%%%%%%%%%%%QRS COMPLEX%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%for i=1:length(Q_isolation)plot((Q_isolation(i):S_isolation(i))/Fs,ECG_data(Q_isolation(i):S_isolation(i)),'r');endQRS_Complex= [Q_isolation;S_isolation];%%%%%%%%%%%%T wave%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%for i=1:length(T_isolation_1)plot((T_isolation_1(i):T_isolation_2(i))/Fs,ECG_data(T_isolation_1(i):T_isolation_2(i)),'y');endline_threshold=mean(ECG_data(new_locs));%%%%%%%%%%%%QT interval%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%for i=1:length(Q_isolation)dump=pks(i)+ones(1,length(Q_isolation(i):T_isolation_2(i))-2)*line_threshold;plot((Q_isolation(i):T_isolation_2(i))/Fs,[line_threshold dump line_threshold],'-r','LineWidth',1.2);endline_threshold=mean(ECG_data(new_locs));%%%%%%%%%%%%PR interval%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%for i=1:length(Q_isolation)%dump=[dump Q_isolation(i):T_isolation(i)];dump=pks(i)+ones(1,length(P_isolation_1(i):Q_isolation(i))-2)*line_threshold;plot((P_isolation_1(i):Q_isolation(i))/Fs,[line_threshold dump line_threshold],'-g','LineWidth',1.2);endline_threshold=mean(ECG_data(new_locs))+mean(ECG_data(new_locs))*0.10;%%%%%%%%%%%%PR Segment%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%for i=1:length(Q_isolation)%dump=[dump Q_isolation(i):T_isolation(i)];dump=pks(i)+ones(1,length(P_isolation_2(i):Q_isolation(i))-2)*line_threshold;if ~isempty(dump)plot((P_isolation_2(i):Q_isolation(i))/Fs,[line_threshold dump line_threshold],'-b','LineWidth',1.2);endendline_threshold=mean(ECG_data(new_locs))+mean(ECG_data(new_locs))*0.10;%%%%%%%%%%%%ST segment interval%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%for i=1:length(Q_isolation)dump=pks(i)+ones(1,length(S_isolation(i):T_isolation_1(i))-2)*line_threshold;if ~isempty(dump)plot((S_isolation(i):T_isolation_1(i))/Fs,[line_threshold dump line_threshold],'-k','LineWidth',1.2);endend
xlabel('Time in Seconds','fontsize',24)
ylabel('12bit Raw ECG','fontsize',24);
title('ECG Segmentation','fontsize',24);
set(gca,'Fontsize',16)
%saveas(fig,'son.png');
%xlim([5,10]);
%saveas(fig,'son2.png');
end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%NEW METHOD OF FICIDUAL POINTS     
%(Her EKG i莽in denenmedi ama 莽o冒unda 莽al媒镁媒yor)R_wave_locs=new_locs(2:length(P_waves)+1)';
R_waves=ECG_data(new_locs(2:length(P_waves)+1))';if(T_isolation_2(end)>length(ECG_data))
T_isolation_2(end)= length(ECG_data);           %脟ok nadir durumlarda T_isolation d媒镁ar媒da kal媒yor. Hatay媒 engellemek i莽in yap媒ld媒.
enddump=[R_waves,S_waves,Q_waves,P_waves,T_waves,ECG_data(T_isolation_1)',ECG_data(T_isolation_2)',ECG_data(P_isolation_1)',ECG_data(P_isolation_2)'];
max_point=max(dump);
min_point=min(dump);r=max_point-min_point;R_waves_normalized=((R_waves-min_point)/r)';
Q_waves_normalized=((Q_waves-min_point)/r)';
S_waves_normalized=((S_waves-min_point)/r)';
P_waves_normalized=((P_waves-min_point)/r)';
T_waves_normalized=((T_waves-min_point)/r)';
V5_points=((((ECG_data(P_isolation_1)'+ECG_data(P_isolation_2)')/2)-min_point)/r)';
V6_points=((((ECG_data(T_isolation_1)'+ECG_data(T_isolation_2)')/2)-min_point)/r)';clear dumpA1=[];
for i=1:length(P_isolation_1)
x2=P_isolation_1(i)/Fs;y2=((ECG_data(P_isolation_1(i))-min_point)/r)';
x1=P_wave_locs(i)/Fs;y1=P_waves_normalized(i);
x3=Q_wave_locs(i)/Fs;y3=Q_waves_normalized(i);
%x2=P_isolation_1(i);y2=ECG_data(P_isolation_1(i));
%x1=P_wave_locs(i);y1=P_waves(i);
%x3=Q_wave_locs(i);y3=Q_waves(i);
A1(i)=Angle_of_2lines(x1,x2,x3,y1,y2,y3);
endA2=[];
for i=1:length(P_isolation_1)
x2=S_wave_locs(i)/Fs;y2=S_waves_normalized(i);
x1=T_wave_locs(i)/Fs;y1=T_waves_normalized(i);
x3=T_isolation_2(i)/Fs;y3=((ECG_data(T_isolation_2(i))-min_point)/r)';
%x2=S_wave_locs(i);y2=S_waves(i);
%x1=T_wave_locs(i);y1=T_waves(i);
%x3=T_isolation_2(i);y3=ECG_data(T_isolation_2(i));
A2(i)=Angle_of_2lines(x1,x2,x3,y1,y2,y3);
endA3=[];
for i=1:length(P_isolation_1)
x2=P_wave_locs(i)/Fs;y2=P_waves_normalized(i);
y1=Q_waves_normalized(i);x1=Q_wave_locs(i)/Fs;
x3=R_wave_locs(i)/Fs;y3=R_waves_normalized(i);
%x2=P_wave_locs(i);y2=P_waves(i);
%y1=Q_waves(i);x1=Q_wave_locs(i);
%x3=R_wave_locs(i);y3=R_waves(i);
A3(i)=Angle_of_2lines(x1,x2,x3,y1,y2,y3);
endA4=[];
for i=1:length(P_isolation_1)
x2=R_wave_locs(i)/Fs;y2=R_waves_normalized(i);
y1=S_waves_normalized(i);x1=S_wave_locs(i)/Fs;
x3=T_wave_locs(i)/Fs;y3=T_waves_normalized(i);
%x2=R_wave_locs(i);y2=R_waves(i);
%y1=S_waves(i);x1=S_wave_locs(i);
%x3=T_wave_locs(i);y3=T_waves(i);
A4(i)=Angle_of_2lines(x1,x2,x3,y1,y2,y3);
endA5=[];
for i=1:length(P_isolation_1)
x2=S_wave_locs(i)/Fs;y2=S_waves_normalized(i);
y1=R_waves_normalized(i);x1=R_wave_locs(i)/Fs;
x3=Q_wave_locs(i)/Fs;y3=Q_waves_normalized(i);
%x2=S_wave_locs(i);y2=S_waves(i);
%y1=R_waves(i);x1=R_wave_locs(i);
%x3=Q_wave_locs(i);y3=Q_waves(i);
A5(i)=Angle_of_2lines(x1,x2,x3,y1,y2,y3);
end%T1->
T1=(P_isolation_2-P_isolation_1);
T1_scaled=ECG_Temp_Normalize(T1,R_wave_locs);
T1_scaled=T1_scaled/Fs;%T2->
T2=(T_isolation_2-T_isolation_1);
T2_scaled=ECG_Temp_Normalize(T2,R_wave_locs);
T2_scaled=T2_scaled/Fs;%T3->
T3=R_wave_locs-Q_wave_locs;
T3_scaled=ECG_Temp_Normalize(T3,R_wave_locs);
T3_scaled=T3_scaled/Fs;%T4->
T4=S_wave_locs-R_wave_locs;
T4_scaled=ECG_Temp_Normalize(T4,R_wave_locs);
T4_scaled=T4_scaled/Fs;%T5->
T5=Q_wave_locs-P_wave_locs;
T5_scaled=ECG_Temp_Normalize(T5,R_wave_locs);
T5_scaled=T5_scaled/Fs;%T6->
T6=T_wave_locs-S_wave_locs;
T6_scaled=ECG_Temp_Normalize(T6,R_wave_locs);
T6_scaled=T6_scaled/Fs;%T7->
T7=Q_wave_locs-P_isolation_1;
T7_scaled=ECG_Temp_Normalize(T7,R_wave_locs);
T7_scaled=T7_scaled/Fs;%T8->
T8=T_isolation_2-S_wave_locs;
T8_scaled=ECG_Temp_Normalize(T8,R_wave_locs);
T8_scaled=T8_scaled/Fs;%T9->
T9=R_wave_locs-P_isolation_2;
T9_scaled=ECG_Temp_Normalize(T9,R_wave_locs);
T9_scaled=T9_scaled/Fs;%T10->
T10=T_isolation_1-R_wave_locs;
T10_scaled=ECG_Temp_Normalize(T10,R_wave_locs);
T10_scaled=T10_scaled/Fs;%T11->
T11=R_wave_locs-P_wave_locs;
T11_scaled=ECG_Temp_Normalize(T11,R_wave_locs);
T11_scaled=T11_scaled/Fs;%T12->
T12=T_wave_locs-R_wave_locs;
T12_scaled=ECG_Temp_Normalize(T12,R_wave_locs);
T12_scaled=T12_scaled/Fs;%T13->
T13=R_wave_locs-P_isolation_1;
T13_scaled=ECG_Temp_Normalize(T13,R_wave_locs);
T13_scaled=T13_scaled/Fs;%T14->
T14=T_isolation_2-R_wave_locs;
T14_scaled=ECG_Temp_Normalize(T14,R_wave_locs);
T14_scaled=T14_scaled/Fs;%T15->
T15=T_wave_locs-P_wave_locs;
T15_scaled=ECG_Temp_Normalize(T15,R_wave_locs);
T15_scaled=T15_scaled/Fs;%V1->
V1=R_waves-Q_waves;
V1_normalized=R_waves_normalized-Q_waves_normalized;
%V2->
V2=R_waves-S_waves;
V2_normalized=R_waves_normalized-S_waves_normalized;
%V3->
V3=P_waves-Q_waves;
V3_normalized=P_waves_normalized-Q_waves_normalized;
%V4->
V4=T_waves-S_waves;
V4_normalized=T_waves_normalized-S_waves_normalized;
%V5->
V5=P_waves-(ECG_data(P_isolation_1)'+ECG_data(P_isolation_2)')/2;
V5_normalized=P_waves_normalized-V5_points;%V6->
V6=T_waves-(ECG_data(T_isolation_1)'+ECG_data(T_isolation_2)')/2;
V6_normalized=T_waves_normalized-V6_points;
%V7->
V7=Q_waves-S_waves;
V7_normalized=Q_waves_normalized-S_waves_normalized;ECG_Struct.Ficidual_Points=[P_waves_normalized,Q_waves_normalized,R_waves_normalized,S_waves_normalized,T_waves_normalized,((ECG_data(P_isolation_1)'-min_point)/r)',((ECG_data(P_isolation_2)'-min_point)/r)',((ECG_data(T_isolation_1)'-min_point)/r)',((ECG_data(T_isolation_2)'-min_point)/r)'];
ECG_Struct.Temporal=[T1_scaled',T2_scaled',T3_scaled',T4_scaled',T5_scaled',T6_scaled',T7_scaled',T8_scaled',T9_scaled',T10_scaled',T11_scaled',T12_scaled',T13_scaled',T14_scaled',T15_scaled'];
ECG_Struct.Amplitudes=[V1_normalized,V2_normalized,V3_normalized,V4_normalized,V5_normalized,V6_normalized,V7_normalized];
ECG_Struct.Angles=[A1',A2',A3',A4',A5'];%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ECG_Struct.ECG_data=ECG_data;
ECG_Struct.P_points=P_waves;
ECG_Struct.P_locs=P_wave_locs;
ECG_Struct.T_points=T_waves;
ECG_Struct.T_locs=T_wave_locs;
ECG_Struct.Q_points=Q_waves;
ECG_Struct.Q_locs=Q_wave_locs;
ECG_Struct.S_points=S_waves;
ECG_Struct.S_locs=S_wave_locs;
ECG_Struct.R_points=ECG_data(new_locs)';
ECG_Struct.R_locs=new_locs';
ECG_Struct.P_wave_interval=[P_isolation_1;P_isolation_2];
ECG_Struct.QRS_Complex_interval=[Q_isolation;S_isolation];
ECG_Struct.T_wave_interval=[T_isolation_1;T_isolation_2];
ECG_Struct.QT_interval=[Q_isolation;T_isolation_2];
ECG_Struct.PR_interval=[P_isolation_1;P_isolation_2];
ECG_Struct.PR_segment=[P_isolation_2;Q_isolation];
ECG_Struct.ST_segment=[S_isolation;T_isolation_1]; % a=length(P_isolation_1);
% b=length(P_isolation_2);
% if(a>b)
% ECG_Struct.P_wave_interval=[P_isolation_1(1:b);P_isolation_2(1:b)];
% else
% ECG_Struct.P_wave_interval=[P_isolation_1(1:a);P_isolation_2(1:a)];    
% end% a=length(Q_isolation);
% b=length(S_isolation);
% if(a>b)
% ECG_Struct.QRS_Complex_interval=[Q_isolation(1:b);S_isolation(1:b)];
% else
% ECG_Struct.QRS_Complex_interval=[Q_isolation(1:a);S_isolation(1:a)];    
% end% a=length(T_isolation_1);
% b=length(T_isolation_2);
% if(a>b)
% ECG_Struct.T_wave_interval=[T_isolation_1(1:b);T_isolation_2(1:b)];
% else
% ECG_Struct.T_wave_interval=[T_isolation_1(1:a);T_isolation_2(1:a)];
% end% a=length(Q_isolation);
% b=length(T_isolation_2);
% if(a>b)
% ECG_Struct.QT_interval=[Q_isolation(1:b);T_isolation_2(1:b)];
% else
% ECG_Struct.QT_interval=[Q_isolation(1:a);T_isolation_2(1:a)];    
% end% a=length(P_isolation_1);
% b=length(P_isolation_2);
% if(a>b)
% ECG_Struct.PR_interval=[P_isolation_1(1:b);P_isolation_2(1:b)];
% else
% ECG_Struct.PR_interval=[P_isolation_1(1:a);P_isolation_2(1:a)];
% end% a=length(P_isolation_2);
% b=length(Q_isolation);
% if(a>b)
% ECG_Struct.PR_segment=[P_isolation_2(1:b);Q_isolation(1:b)];
% else
% ECG_Struct.PR_segment=[P_isolation_2(1:a);Q_isolation(1:a)];
% end% a=length(S_isolation);
% b=length(T_isolation_1);
% if(a>b)
% ECG_Struct.ST_segment=[S_isolation(1:b);T_isolation_1(1:b)];
% else
% ECG_Struct.ST_segment=[S_isolation(1:a);T_isolation_1(1:a)];    
% end%%%%%%%%%%%%%%%%%QRS Complex interval Align%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(ECG_Struct.R_locs(1,1)<ECG_Struct.QRS_Complex_interval(1,1))threshold1=0;       %sa冒a kayd媒rma oran媒threshold2=0;       %sola kayd媒rma oran媒for i=1:length(ECG_Struct.QRS_Complex_interval)-1threshold1=threshold1+floor(ECG_Struct.R_locs(i+1)-ECG_Struct.QRS_Complex_interval(1,i));threshold2=threshold2+floor(ECG_Struct.QRS_Complex_interval(2,i)-ECG_Struct.R_locs(i+1));endthreshold1=floor(threshold1/length(ECG_Struct.QRS_Complex_interval));threshold2=floor(threshold2/length(ECG_Struct.QRS_Complex_interval));for i=1:length(ECG_Struct.QRS_Complex_interval)ECG_Struct.QRS_Complex_interval_align(1,i)=ECG_Struct.R_locs(i+1)-threshold1;ECG_Struct.QRS_Complex_interval_align(2,i)=ECG_Struct.R_locs(i+1)+threshold2;end
elsefor i=1:length(ECG_Struct.QT_interval)threshold1=threshold1+floor(ECG_Struct.R_locs(i)-ECG_Struct.QRS_Complex_interval(1,i));threshold2=threshold2+floor(ECG_Struct.QRS_Complex_interval(2,i)-ECG_Struct.R_locs(i));endthreshold1=floor(threshold1/length(ECG_Struct.QRS_Complex_interval));threshold2=floor(threshold2/length(ECG_Struct.QRS_Complex_interval));for i=1:length(ECG_Struct.QRS_Complex_interval)ECG_Struct.QRS_Complex_interval_align(1,i)=ECG_Struct.R_locs(i)-threshold1;ECG_Struct.QRS_Complex_interval_align(2,i)=ECG_Struct.R_locs(i)+threshold2;end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%P_wave_interval align%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
threshold1=0;
threshold2=0;
for i=1:length(ECG_Struct.P_wave_interval)threshold1=threshold1+floor(ECG_Struct.P_locs(i)-ECG_Struct.P_wave_interval(1,i));threshold2=threshold2+floor(ECG_Struct.P_wave_interval(2,i)-ECG_Struct.P_locs(i));
end
threshold1=floor(threshold1/length(ECG_Struct.P_wave_interval));
threshold2=floor(threshold2/length(ECG_Struct.P_wave_interval));
for i=1:length(ECG_Struct.P_wave_interval)ECG_Struct.P_wave_interval_align(1,i)=ECG_Struct.P_locs(i)-threshold1;ECG_Struct.P_wave_interval_align(2,i)=ECG_Struct.P_locs(i)+threshold2;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%T wave interval align%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
threshold1=0;
threshold2=0;
for i=1:length(ECG_Struct.T_wave_interval)threshold1=threshold1+floor(ECG_Struct.T_locs(i)-ECG_Struct.T_wave_interval(1,i));threshold2=threshold2+floor(ECG_Struct.T_wave_interval(2,i)-ECG_Struct.T_locs(i));
end
threshold1=floor(threshold1/length(ECG_Struct.T_wave_interval));
threshold2=floor(threshold2/length(ECG_Struct.T_wave_interval));
for i=1:length(ECG_Struct.T_wave_interval)ECG_Struct.T_wave_interval_align(1,i)=ECG_Struct.T_locs(i)-threshold1;ECG_Struct.T_wave_interval_align(2,i)=ECG_Struct.T_locs(i)+threshold2;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%QT_interval align%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(ECG_Struct.R_locs(1,1)<ECG_Struct.QT_interval(1,1))threshold1=0;threshold2=0;for i=1:length(ECG_Struct.QT_interval)-1threshold1=threshold1+floor(ECG_Struct.R_locs(i+1)-ECG_Struct.QT_interval(1,i));threshold2=threshold2+floor(ECG_Struct.QT_interval(2,i)-ECG_Struct.R_locs(i+1));endthreshold1=floor(threshold1/length(ECG_Struct.QT_interval));threshold2=floor(threshold2/length(ECG_Struct.QT_interval));for i=1:length(ECG_Struct.QT_interval)ECG_Struct.QT_interval_align(1,i)=ECG_Struct.R_locs(i+1)-threshold1;ECG_Struct.QT_interval_align(2,i)=ECG_Struct.R_locs(i+1)+threshold2;end
elsefor i=1:length(ECG_Struct.QT_interval)threshold1=threshold1+floor(ECG_Struct.R_locs(i)-ECG_Struct.QT_interval(1,i));threshold2=threshold2+floor(ECG_Struct.QT_interval(2,i)-ECG_Struct.R_locs(i));endthreshold1=floor(threshold1/length(ECG_Struct.QT_interval));threshold2=floor(threshold2/length(ECG_Struct.QT_interval));for i=1:length(ECG_Struct.QT_interval)ECG_Struct.QT_interval_align(1,i)=ECG_Struct.R_locs(i)-threshold1;ECG_Struct.QT_interval_align(2,i)=ECG_Struct.R_locs(i)+threshold2;end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%PR_interval align%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
threshold1=0;
threshold2=0;
for i=1:length(ECG_Struct.PR_interval)threshold1=threshold1+floor(ECG_Struct.P_locs(i)-ECG_Struct.PR_interval(1,i));threshold2=threshold2+floor(ECG_Struct.PR_interval(2,i)-ECG_Struct.P_locs(i));
end
threshold1=floor(threshold1/length(ECG_Struct.PR_interval));
threshold2=floor(threshold2/length(ECG_Struct.PR_interval));
for i=1:length(ECG_Struct.PR_interval)ECG_Struct.PR_interval_align(1,i)=ECG_Struct.P_locs(i)-threshold1;ECG_Struct.PR_interval_align(2,i)=ECG_Struct.P_locs(i)+threshold2;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% QRS Complex Fixed Interval       %%%%%%%%%%%%%%%%%%%
threshold1=floor(Fs/8);     %left side of R peaks (125, when Fs=1000)
threshold2=floor(Fs/6.5);   %right side of R peaks (153, when Fs=1000)
if(ECG_Struct.R_locs(1,1)<ECG_Struct.QRS_Complex_interval(1,1))for i=1:length(ECG_Struct.QRS_Complex_interval)ECG_Struct.QRS_Complex_interval_fixed(1,i)=ECG_Struct.R_locs(i+1)-threshold1;ECG_Struct.QRS_Complex_interval_fixed(2,i)=ECG_Struct.R_locs(i+1)+threshold2;end
elsefor i=1:length(ECG_Struct.QRS_Complex_interval)ECG_Struct.QRS_Complex_interval_fixed(1,i)=ECG_Struct.R_locs(i)-threshold1;ECG_Struct.QRS_Complex_interval_fixed(2,i)=ECG_Struct.R_locs(i)+threshold2;end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          P wave interval fixed     %%%%%%%%%%%%%%%%
threshold1=floor(Fs/16);    %left side of P peaks (62, when Fs=1000)
threshold2=floor(Fs/28);    %right side of P peaks (35 when Fs=1000)
for i=1:length(ECG_Struct.P_wave_interval)ECG_Struct.P_wave_interval_fixed(1,i)=ECG_Struct.P_locs(i)-threshold1;ECG_Struct.P_wave_interval_fixed(2,i)=ECG_Struct.P_locs(i)+threshold2;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        T wave interval fixed %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
threshold1=floor(Fs/8.3);   %left side of T peaks (120, when Fs=1000)
threshold2=floor(Fs/11);    %left side of T peaks (90, when Fs=1000)
for i=1:length(ECG_Struct.T_wave_interval)ECG_Struct.T_wave_interval_fixed(1,i)=ECG_Struct.T_locs(i)-threshold1;ECG_Struct.T_wave_interval_fixed(2,i)=ECG_Struct.T_locs(i)+threshold2;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%threshold1=floor(Fs/16);
threshold2=floor(Fs/11);
for i=1:length(ECG_Struct.P_locs)ECG_Struct.P_QRS_T_Complex_interval_fixed(1,i)=ECG_Struct.P_locs(i)-threshold1;ECG_Struct.P_QRS_T_Complex_interval_fixed(2,i)=ECG_Struct.T_locs(i)+threshold2;
end
%%%%%%%%%%%%P-QRS-T interval fixed %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
threshold1=floor(Fs/25)+floor(Fs/8);
threshold2=floor(Fs/6)+floor(Fs/6.5);if(ECG_Struct.R_locs(1,1)<ECG_Struct.QRS_Complex_interval(1,1))for i=1:length(ECG_Struct.QRS_Complex_interval)ECG_Struct.P_QRS_T_interval_fixed(1,i)=ECG_Struct.R_locs(i+1)-threshold1;ECG_Struct.P_QRS_T_interval_fixed(2,i)=ECG_Struct.R_locs(i+1)+threshold2;end
elsefor i=1:length(ECG_Struct.QRS_Complex_interval)ECG_Struct.P_QRS_T_interval_fixed(1,i)=ECG_Struct.R_locs(i)-threshold1;ECG_Struct.P_QRS_T_interval_fixed(2,i)=ECG_Struct.R_locs(i)+threshold2;end
end
%完整代码:mbd.pub/o/bread/mbd-ZJuTl5tt
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end

分割结果示例如下:

图片

图片

图片

图片

工学博士,担任《Mechanical System and Signal Processing》《中国电机工程学报》《控制与决策》等期刊审稿专家,擅长领域:现代信号处理,机器学习,深度学习,数字孪生,时间序列分析,设备缺陷检测、设备异常检测、设备智能故障诊断与健康管理PHM等。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/16597.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

vs2019 c++20 规范的 STL 库的智能指针 shared、unique 、weak 及 make_** 函数的源码注释汇总,和几个结论

智能指针的源码都在 《memory》 头文件中。因为头文件太长&#xff0c;再者本次整理是基于以前的零散的模板分析。故相当于抽取了该头文件中关于智能指针的源码进行分析&#xff0c;注释。 &#xff08;1 探讨一&#xff09;当独占指针指向数组时&#xff0c;其默认的删除器是…

mysql表约束基础 【default | 主键 | 外键 | 唯一键】

博客主页&#xff1a;花果山~程序猿-CSDN博客 文章分栏&#xff1a;MySQL之旅_花果山~程序猿的博客-CSDN博客 关注我一起学习&#xff0c;一起进步&#xff0c;一起探索编程的无限可能吧&#xff01;让我们一起努力&#xff0c;一起成长&#xff01; 目录 一&#xff0c;表的约…

vue3快速入门(局部使用)

目录 前置知识JavaScript-导入导出 入门操作 变量渲染页面 局部使用vue的实现步骤 vue指令 v-for v-bind v-if v-show v-on v-model 生命周期 前置知识JavaScript-导入导出 正常情况在html导入js文件是全部导入&#xff0c;这样会导致性能上的损失 。 JS提供的…

STM32F1之OV7725摄像头·SCCB总线代码编写附带源码详解

STM32F1之OV7725摄像头-CSDN博客 STM32F1之OV7725摄像头像素数据输出时序、FIFO 读写时序以及摄像头的驱动原理详解-CSDN博客 目录 1. 硬件设计 1.1 SCCB 控制相关 1.2 VGA 时序相关 1.3 FIFO 相关 1.4 XCLK 信号 2. 代码设计 2.1 SCCB总线软件实现 2.1.1 宏定…

AI图书推荐:ChatGPT解码—人工智能增强生活指南

《ChatGPT解码—人工智能增强生活指南》&#xff08;ChatGPT Decoded. A Beginners Guide to AI-Enhanced Living &#xff09;是一本由 大卫维恩斯&#xff08;David Wiens &#xff09;所著的书籍&#xff0c;旨在帮助读者了解并有效利用GPT-4语言模型这一强大工具来提升日常…

springmvc Web上下文初始化

Web上下文初始化 web上下文与SerlvetContext的生命周期应该是相同的&#xff0c;springmvc中的web上下文初始化是由ContextLoaderListener来启动的 web上下文初始化流程 在web.xml中配置ContextLoaderListener <listener> <listener-class>org.springframework.…

ncnn 优化量化

问题&#xff1a;发现推理时间过长&#xff0c;需要优化 当前正在做人脸检测部署&#xff0c;发现检测速度有点吓人&#xff0c;以下监测的时间 gpu&#xff1a; cpu&#xff1a; gpu推理大概整体时间200多毫秒&#xff0c;cpu推理时间300多毫秒&#xff0c;这里暂时没去考虑…

Oracle实践|内置函数之字符串函数

&#x1f4eb; 作者简介&#xff1a;「六月暴雪飞梨花」&#xff0c;专注于研究Java&#xff0c;就职于科技型公司后端工程师 &#x1f3c6; 近期荣誉&#xff1a;华为云云享专家、阿里云专家博主、腾讯云优秀创作者、ACDU成员 &#x1f525; 三连支持&#xff1a;欢迎 ❤️关注…

C++模板——函数模板和类模板

目录 泛型编程 函数模板 函数模板概念 函数模板的定义和语法 函数模板的工作原理 函数模板的实例化 隐式实例化 显示实例化 函数模板的匹配原则 类模板 类模板的定义格式 类模板的实例化 泛型编程 什么是泛型编程&#xff1f; 泛型编程&#xff08;Generic Pr…

【Linux-并发与竞争】

Linux-并发与竞争 ■ 原子操作■ 原子操作简介■ 原子整形操作 API 函数■ 原子位操作 API 函数■ 示例一&#xff1a;原子操作实验&#xff0c;使用原子变量来实现对实现设备的互斥访问 ■ 自旋锁■ 自旋锁 API 函数■ 死锁■ 最好的解决死锁方法就是获取锁之前关闭本地中断&a…

LeetCode 124 —— 二叉树中的最大路径和

阅读目录 1. 题目2. 解题思路3. 代码实现 1. 题目 2. 解题思路 二叉树的问题首先我们要想想是否能用递归来解决&#xff0c;本题也不例外&#xff0c;而递归的关键是找到子问题。 我们首先来看看一棵最简单的树&#xff0c;也就是示例 1。这样的一棵树总共有六条路径&#xf…

docker如何拉取nginx最新镜像并运行

要拉取Docker Hub上的最新Nginx镜像&#xff0c;您可以使用以下命令&#xff1a; docker pull nginx 这个命令会从Docker Hub下载最新版本的Nginx镜像。如果您想要拉取特定版本的Nginx镜像&#xff0c;可以指定版本号&#xff0c;例如&#xff1a; docker pull nginx:1.18.0 拉…

详细分析tcping的基本知识以及用法

目录 前言1. 安装配置2. 基本知识3. Demo 前言 针对ping的基本知识推荐阅读&#xff1a;详细分析ping的基本知识以及常见网络故障的诊断&#xff08;图文解析&#xff09; 1. 安装配置 针对Window的下载如下&#xff1a; 安装路径&#xff1a;tcping官网 下载tcping.exe&a…

《微服务王国的守护者:Spring Cloud Dubbo的奇幻冒险》

5. 经典问题与解决方案 5.3 服务追踪与链路监控 在微服务架构的广袤宇宙中&#xff0c;服务间的调用关系错综复杂&#xff0c;如同一张庞大的星系网络。当一个请求穿越这个星系&#xff0c;经过多个服务节点时&#xff0c;如何追踪它的路径&#xff0c;如何监控整个链路的健康…

VUE3 学习笔记(3):VUE模板理念、属性绑定、条件渲染、列表渲染

准备 1.清空不必要的项目文件 项目/src/assets/ 目录文件清空 项目/src/components/ 目录文件清空 删除main.js 的css引用 App.vue 代码如下 <template> </template> <script>//注意这里默认有一个setup 去掉 </script> 运行一下无错误提示就可以了…

Cohere继Command-R+之后发布大模型Aya-23,性能超越 Gemma、Mistral 等,支持中文

前言 近年来&#xff0c;多语言大模型&#xff08;MLLM&#xff09;发展迅速&#xff0c;但大多数模型的性能依然存在显著差距&#xff0c;尤其是在非英语语言方面表现不佳。为了推动多语言自然语言处理技术的发展&#xff0c;Cohere团队发布了新的多语言指令微调模型家族——…

机器学习预测-CNN手写字识别

介绍 这段代码是使用PyTorch实现的卷积神经网络&#xff08;CNN&#xff09;&#xff0c;用于在MNIST数据集上进行图像分类。让我一步步解释&#xff1a; 导入库&#xff1a;代码导入了必要的库&#xff0c;包括PyTorch&#xff08;torch&#xff09;、神经网络模块&#xff0…

shell脚本实战--批量修改文件名

字符串截取 先来了解一下shell字符串相关操作的变量 # 从开头删除匹配最短 ## 从开头删除匹配最长 % 从结尾削除匹配最短 %% 从结尾删除匹配最长#指定字符内容截取 a*c 匹配开头为a&#xff0c;中间任意个字符&#xff0c;结尾为c的字符串 a*C 匹配…

Java—集合Collection(一)

Java—集合Collection&#xff08;一&#xff09; 一、Collection集合1、方法add、addAll2、声明集合特别注意1&#xff1a;添加对象时需要创建对象类 3、总结4、判断方法4.1、总结 5、删除6、总结7、集合的其他方法8、所有代码演练 存放单个数据内容&#xff0c;声明一个变量&…

netcat一键开始瑞士军刀模式(KALI工具系列六)

目录 1、KALI LINUX简介 2、netcat工具简介 3、在KALI中使用netcat 3.1 目标主机IP&#xff08;win&#xff09; 3.2 KALI的IP 4、命令示例 4.1 测试某IP的端口是否打开 4.2 TCP扫描 4.3 UDP扫描 4.4 端口刺探 4.5 直接扫描 5、即时通信 5.1 单击对话互联 5.2 传…