简单的基于信号处理的心电信号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)-1
    isoelectric_line(i)=mean(ECG_data(new_locs(i):new_locs(i+1)));
end

for i=1:length(new_locs)-2
    duration_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;
    else
        Q_T_duration=Fs/2;
        P_R_duration=Fs/4;
        QRS_mid_duration=0.06*Fs;
    end
    x=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)];
end

Q_isolation=[];
for(i=1:length(Q_wave_locs))
    cnt=0;
    for j=1:duration_coef
        
        if(Q_wave_locs(i)-j < 1)
            break;
        end

        if(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;
            end
        else
            if(ECG_data(Q_wave_locs(i)-j)<=isoelectric_line(i))
                Q_isolation=[Q_isolation Q_wave_locs(i)-j];
                cnt=1;
                break;
            end
        end
    end
    if(cnt==0)
    Q_isolation=[Q_isolation Q_wave_locs(i)-j];
    end
end

S_isolation=[];
for(i=1:length(S_wave_locs))
    cnt=0;
    for j=1:duration_coef
        
        if(S_wave_locs(i)+j > data_len)
            break;
        end
        
        if(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;
            end
        else
            if(ECG_data(S_wave_locs(i)+j)<=isoelectric_line(i))
                S_isolation=[S_isolation S_wave_locs(i)+j];
                cnt=1;
                break;
            end
        end
    end
    if(cnt==0)
    S_isolation=[S_isolation Q_wave_locs(i)-j];    
    end
end

P_isolation_1=[];
for(i=1:length(P_wave_locs))
    cnt=0;
    for j=1:duration_coef
        
        if(P_wave_locs(i)-j < 1)
            break;
        end
     
        if(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;
            end
        else
            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;
            end
        end
    end
    if(cnt==0)
    P_isolation_1=[P_isolation_1 P_wave_locs(i)-j];
    end
end


P_isolation_2=[];
for(i=1:length(P_wave_locs))
    cnt=0;
    for j=1:duration_coef
        
        if(P_wave_locs(i)+j > data_len)
            break;
        end
        
        if(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;
            end
        else
            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;
            end
        end
    end
    if(cnt==0)
    P_isolation_2=[P_isolation_2 P_wave_locs(i)+j];    
    end
end

T_isolation_1=[];
for(i=1:length(T_wave_locs))
    cnt=0;
    for j=1:duration_coef
        
        if(T_wave_locs(i)-j < 1)
            break;
        end
        
        if(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;
            end
        else
            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;
            end
        end
    end
    if(cnt==0)
    T_isolation_1=[T_isolation_1 T_wave_locs(i)-j];    
    end
end

T_isolation_2=[];
for(i=1:length(T_wave_locs))
    cnt=0;
    for j=1:duration_coef
        
        if(T_wave_locs(i)+j >data_len)
            break;
        end
        
        if(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;
            end
        else
            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;
            end
        end
    end
    if(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 on
    txt = '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');
    end
    QRS_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');
    end
    line_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);
    end
    line_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);
    end
    line_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);
        end
    end
    line_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);
        end
    end
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媒.
end

dump=[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 dump

A1=[];
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);
end

A2=[];
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);
end

A3=[];
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);
end

A4=[];
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);
end

A5=[];
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)-1
        threshold1=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));
    end
    threshold1=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
else
    for 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));
    end
    threshold1=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)-1
        threshold1=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));
    end
    threshold1=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
else
    for 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));
    end
    threshold1=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
else
    for 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
else
    for 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等。

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

异相(相位不平衡)状态下的合成器效率分析-理论与ADS仿真

异相&#xff08;相位不平衡&#xff09;状态下的合成器效率分析-理论与ADS仿真 12、ADS使用记录之功分器设计中简单介绍了威尔金森功分器的设计方法。一般来讲&#xff0c;功分器反过来就能作为合路器使用&#xff0c;在输入信号相位一致的情况下&#xff0c;各种合路器的效率…

港股:并不意外的获利了结

中金公司表示&#xff0c;风险偏好驱动的反弹已经较为充分&#xff0c;分歧和获利了结也不意外。接下来或在当前水平震荡盘整&#xff0c;等待更多催化剂。 在持续一个月的大涨后&#xff0c;港股市场上周出现明显回调。此前我们多次提示&#xff0c;市场已经超买&#xff0c;情…

HTML静态网页成品作业(HTML+CSS)——杭州西湖景点介绍网页(3个页面)

&#x1f389;不定期分享源码&#xff0c;关注不丢失哦 文章目录 一、作品介绍二、作品演示三、代码目录四、网站代码HTML部分代码 五、源码获取 一、作品介绍 &#x1f3f7;️本套采用HTMLCSS&#xff0c;未使用Javacsript代码&#xff0c;共有3个页面。 二、作品演示 三、代…

聊聊ChatGPT的本质

这是鼎叔的第九十八篇原创文章。行业大牛和刚毕业的小白&#xff0c;都可以进来聊聊。 阶段性总结下我对ChatGPT的基础理解&#xff0c;算是一篇学习思考笔记吧。其中难免有很多不准确的&#xff0c;或过于简略的地方&#xff0c;将来再迭代学习。 OpenAI做ChatGPT的底层逻辑…

FFmpeg开发笔记(三十一)使用RTMP Streamer开启APP直播推流

RTMP Streamer是一个安卓手机端的开源RTMP直播推流框架&#xff0c;可用于RTMP直播和RTSP直播&#xff0c;其升级版还支持SRT直播&#xff08;腾讯视频云就采用SRT协议&#xff09;。RTMP Streamer支持的视频编码包括H264、H265、AV1等等&#xff0c;支持的音频编码包括AAC、G7…

如何从清空的回收站中恢复已删除的Excel文件?

“嗨&#xff0c;几天前我删除了很多没有备份的Excel文件。回收站已清空。当我意识到我犯了一个大错误时&#xff0c;所有的Excel文件都消失了&#xff0c;回收站里什么都没有。清空回收站后是否可以恢复已删除的 Excel 文件&#xff1f; 回收站是一种工具&#xff0c;可让您在…

爬山算法教程(个人总结版)

背景与简介 爬山算法&#xff08;Hill Climbing Algorithm&#xff09;是一种用于解决优化问题的启发式搜索方法。它是一种局部搜索算法&#xff0c;通过不断尝试从当前解出发&#xff0c;在其邻域内寻找更优的解&#xff0c;直到无法找到更优解为止。该算法得名于其类似于登山…

FullCalendar日历组件集成实战(7)

背景 有一些应用系统或应用功能&#xff0c;如日程管理、任务管理需要使用到日历组件。虽然Element Plus也提供了日历组件&#xff0c;但功能比较简单&#xff0c;用来做数据展现勉强可用。但如果需要进行复杂的数据展示&#xff0c;以及互动操作如通过点击添加事件&#xff0…

java调用科大讯飞在线语音合成API --内附完整项目

科大讯飞语音开放平台基础环境搭建 1.用户注册 注册科大讯飞开放平台账号 2.注册好后先创建一个自己的应用 创建完成后进入应用可以看到我们开发需要的三个参数&#xff1a;APPID&#xff0c;APISecret&#xff0c;APIKey 3.因为平台提供的SDK中只支持了简单的中英两种语言语音…

C语言 | Leetcode C语言题解之第114题二叉树展开为链表

题目&#xff1a; 题解&#xff1a; void flatten(struct TreeNode* root) {struct TreeNode* curr root;while (curr ! NULL) {if (curr->left ! NULL) {struct TreeNode* next curr->left;struct TreeNode* predecessor next;while (predecessor->right ! NULL)…

KingbaseES数据库merge语法

数据库版本&#xff1a;KingbaseES V008R006C008B0014 简介 MERGE 语句是一种用于数据操作的 SQL 语句&#xff0c;它能够根据指定的条件将 INSERT、UPDATE 和 DELETE 操作结合到单个语句中。其主要作用是在目标表和源表之间进行数据比较和同步&#xff0c;根据条件的匹配情况来…

Jmeter插件下载(下载和使用教程)

插件管理器&#xff1a;plugins-manager下载安装和使用 下载&#xff1a; 官网地址&#xff1a;https://jmeter-plugins.org/install/Install/ 步骤1&#xff1a;将下载jmeter-plugins-manager-1.10.jar放到目录apache-jmeter-5.1.1\lib\ext&#xff0c;如下图 步骤2&#x…

安卓开发:相机水印设置

1.更新水印 DecimalFormat DF new DecimalFormat("#"); DecimalFormat DF1 new DecimalFormat("#.#");LocationManager LM (LocationManager)getSystemService(Context.LOCATION_SERVICE); LM.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2…

C++的数论相关算法

数论是数学的一个分支&#xff0c;主要研究整数的性质和关系。在计算机科学中&#xff0c;数论算法对于密码学、优化问题和算法分析等方面都具有重要作用。C作为一种高效的编程语言&#xff0c;非常适合用来实现这些算法。下面我们将介绍几个C中的数论相关算法&#xff0c;包括…

如何学习计算机网络(超详细,方法论)

分享一下学习计算机网络的方法论 首先是看视频&#xff1a; 这里我推荐中科大郑烇、杨坚全套《计算机网络&#xff08;自顶向下方法 第7版》课程 课程目标_哔哩哔哩_bilibili 教材采用神书《计算机网络&#xff08;自顶向下方法&#xff09;》&#xff0c;授课风格更偏向实…

Linux基础 (十):Linux 信号的使用

目录 一、信号的基本概念 二、信号处理常见方式概览 三、修改信号的响应方式 – signal() 3.1 简单复习结束前台进程 3.2 改变SIGINT信号的响应方式 3.3 自定义方式改变进程对信号的响应 3.4 进程对信号作出两种响应 四、发送信号 – kill() 五、利用信号解决僵死进程…

全球点赞最高的人颜廷利:真正的人生目标是什么

在那个充满生机的2024年春天&#xff0c;记者有幸对中国第一起名大师的老师颜廷利教授进行了深入的访谈。带着对其人生哲学的强烈好奇&#xff0c;记者紧张而期待地提出了问题&#xff1a;“颜教授&#xff0c;您在漫长的人生旅途中最追求的是什么&#xff1f;” 宁夏银川、山东…

从容应对亿级QPS访问,Redis还缺少什么?no.29

众所周知&#xff0c;Redis 在线上实际运行时&#xff0c;面对海量数据、高并发访问&#xff0c;会遇到不少问题&#xff0c;需要进行针对性扩展及优化。本课时&#xff0c;我会结合微博在使用 Redis 中遇到的问题&#xff0c;来分析如何在生产环境下对 Redis 进行扩展改造&…

IT廉连看——UniApp——条件渲染

IT廉连看——UniApp——条件渲染 什么是条件渲染&#xff1f; 顾名思义&#xff0c;满足一定的条件他才会进行渲染。 这是我们上节事件绑定保留的代码。 一、现在我有这样一个需求&#xff1a; 增加一个按钮&#xff0c;当我点击这个按钮&#xff0c;这里的文本&#xff0…

2024年上半年系统架构设计师真题-复原程度90%

前言 此次考试监考特别严格&#xff0c;草稿纸不允许带出考场&#xff0c;并且准考证上不允许任何写画&#xff0c;甚至连笔都允许带一支&#xff0c;所以下面的相关题目都是参考一些群友的提供&#xff0c;加上自己的记忆回顾&#xff0c;得到的结果。 其中综合知识部分的题…