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

news2024/11/17 21:24:09

正常的心电图中,每个心跳周期内包含三个主要的特征波: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等。

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

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

相关文章

Java顺序表

Java顺序表 前言一、线性表介绍常见线性表总结图解 二、顺序表概念顺序表的分类顺序表的实现throw具体代码 三、顺序表会出现的问题 前言 推荐一个网站给想要了解或者学习人工智能知识的读者&#xff0c;这个网站里内容讲解通俗易懂且风趣幽默&#xff0c;对我帮助很大。我想与…

深入解析BGP与OSPF:互联网与企业网络中的路由协议对比

BGP&#xff08;Border Gateway Protocol&#xff09;和OSPF&#xff08;Open Shortest Path First&#xff09;是两种不同的路由协议&#xff0c;它们在互联网和企业网络中扮演着重要的角色。下面是它们各自特点的详细内容丰富&#xff1a; BGP&#xff08;Border Gateway Pro…

leecode 226 翻转二叉树、101 对称二叉树、104 二叉树的最大深度

leecode 226 翻转二叉树、101 对称二叉树、104 二叉树的最大深度 leecode 226 翻转二叉树 题目链接 &#xff1a;https://leetcode.cn/problems/invert-binary-tree/description/ 题目 给你一棵二叉树的根节点 root &#xff0c;翻转这棵二叉树&#xff0c;并返回其根节点。…

Neovim 配置全面解析(上)

Neovim 配置全面解析&#xff08;上&#xff09; 原文&#xff1a;Neovim 配置全面解析&#xff08;上&#xff09; - 知乎 (zhihu.com) 环境&#xff1a;Ubuntu 20.04 宿主机&#xff1a;windows &#xff08;windows terminal&#xff09;WSL 2 NVIM&#xff1a;v 0.10.0-de…

自从有了可观测性,传统运维如何进行提升?

在 201x 年&#xff0c;随着容器技术的出现&#xff0c;容器的部署方式逐渐被各大互联网公司采用&#xff0c;相比物理机/虚拟机&#xff0c;容器的好处是环境隔离、轻量、快速。 但是管理容器是一件复杂的事情&#xff0c;后来出现了 Kubernetes&#xff0c;成为了事实上的容…

Python编程的黑暗魔法:模块与包的神秘力量!

哈喽&#xff0c;我是阿佑&#xff0c;今天给大家讲讲模块与包~ 文章目录 1. 引言1.1 模块化编程的意义1.2 Python中模块与包的概念概述 2. 背景介绍2.1 Python模块系统模块的定义与作用Python标准库简介 2.2 包的结构与目的包的定义与目录结构包在项目组织中的重要性 3. 创建与…

网络攻击攻击之-远程命令执行/RCE告警运营分析篇

在各种网络安全产品的告警中,远程命令执行是一种非常常见的告警。本文将从远程命令执行的定义,远程命令执行利用的流量数据包示例,远程命令执行的suricata规则,远程命令执行的告分析警研判,远程命令执行的处置建议等几个方面阐述如何通过IDS/NDR,态势感知等流量平台的远程…

Linux系统编程(三)进程间通信(IPC)

本文目录 一、linux 进程之间的通信种类二、管道1. 管道的概述2. 什么是管道文件&#xff1f;3. 管道的特点4. 管道类型&#xff08;1&#xff09;无名管道&#xff08;pipe&#xff09;&#xff08;2&#xff09;有名(命名)管道&#xff08;fifo&#xff09; 三、信号&#xf…

自定义Linux命令,显示docker镜像、容器信息

1、修改环境变量&#xff08;仅对当前用户有效&#xff09; vim ~/.bashrc2、给命令取别名 alias dpsdocker ps --format "table{{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}" alias disdocker images#保存并退出 :wq3、让配置重新生效 source ~/.bashrc4、测试&…

前端设计模式学习记录

设计模式介绍 概念 设计模式是我们在解决问题的时候针对特定的问题给出的简洁而优化的处理方案在JS设计模式中&#xff0c;最核心的思想&#xff1a;封装变化将变与不变分离&#xff0c;确保变化的部分灵活、不变的部分稳定 注意&#xff1a;下面文章介绍的设计模式&#xff…

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

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

​​​【收录 Hello 算法】10.4 哈希优化策略

目录 10.4 哈希优化策略 10.4.1 线性查找&#xff1a;以时间换空间 10.4.2 哈希查找&#xff1a;以空间换时间 10.4 哈希优化策略 在算法题中&#xff0c;我们常通过将线性查找替换为哈希查找来降低算法的时间复杂度。我们借助一个算法题来加深理解。 Question 给…

LINGO:存贮问题

存贮模型中的基本概念 模型&#xff1a; 基本要素&#xff1a; &#xff08;1&#xff09;需求率&#xff1a;单位时间内对某种物品的需求量&#xff0c;用D表示。 &#xff08;2&#xff09;订货批量&#xff1a;一次订货中&#xff0c;包含某种货物的数量&#xff0c;用 Q表…

AI网络爬虫-从当当网批量获取图书信息

工作任务和目标&#xff1a;用户输入一个图书名称&#xff0c;然后程序自动从当当网批量获取图书信息 查看相关元素在源代码中的位置&#xff1a; 第一步&#xff1a;在deepseek中输入提示词&#xff1a; 你是一个Python爬虫专家&#xff0c;一步步的思考&#xff0c;完成以下…

Linux定时计划

定时计划 一、计划任务种类 突发性&#xff1a;临时决定只执行一次的任务 at&#xff1a;处理执行一次任务就结束定时性&#xff1a;每隔一定时间需要重复执行此命令 crontab&#xff1a;指定任务&#xff0c;按照设定的周期一直循环执行二、作用 定时任务可以用于自动备份…

AI办公自动化:用kimi批量将word文档部分文件名保存到Excel中

文件夹中有很多个word文档&#xff0c;现在只要英文部分的文件名&#xff0c;保存到一个Excel文件中。 可以在kimi中输入提示词&#xff1a; 你是一个Python编程专家&#xff0c;要完成一个编写Python脚本的任务&#xff0c;具体步骤如下&#xff1a; 打开文件夹&#xff1a;…

51单片机-实机演示(LED,呼吸,蜂鸣器)

一&#xff0c;LED点灯 #include "REG52.H"sbit LED P0^0;void main() {LED 1;while (1){} }控制P00输出。 烧录 重启 再换个引脚插入的位置。 二&#xff0c;蜂鸣器 代码&#xff0c;和烧录步骤同上。 只需要换一下&#xff0c;引脚位置即可 三&#xff0c;呼…

jmeter之MD5加密接口请求教程

前言&#xff1a; 有时候在项目中&#xff0c;需要使用MD5加密的方法才可以登录&#xff0c;或者在某一个接口中遇到 登录获取token后才可以进行关联&#xff0c;下面介绍下遇到的常见使用 一、第一种方法&#xff1a;使用jmeter自带的函数助手digest 选择工具&#xff0c;选择…

ssm整合教程

目录 写在前面 目录结构 添加依赖 web.xml jdbc.properties spring.xml mybatis.xml springmvc.xml pom.xml额外配置 last&#xff1a;写个测试样例看看整合成功没。 User.java UserDao.java(接口) UserController.java UserService.java UserServiceImpl.java …

人工智能在鼻咽癌领域的最新应用|【医学AI·论文速递·05-27】

小罗碎碎念 2024-05-27&#xff5c;文献速递 接下来打算把人工智能在主流癌种治疗中的应用&#xff0c;每天和大家做一期推送&#xff0c;方便大家了解各自领域最新的一个进展。 因为小罗的课题是鼻咽癌相关的&#xff0c;所以这一期推文就先从人工智能在鼻咽癌中最新的应用开…