Table of Contents

....................................................................................................................................... 1
ZERO CROSSING REMOVAL%%%%%% ........................................................................... 2
DETECT R_PEAK ............................................................................................................. 2
Calculate R in the actual Signal ............................................................................................ 2
After R Peak Tracking ... DETCET OTHERS .......................................................................... 3
ONSET ............................................................................................................................. 3
P Peak .............................................................................................................................. 3
Q Detection ....................................................................................................................... 4
S Detection ....................................................................................................................... 4
T Peak .............................................................................................................................. 5
END OF T ........................................................................................................................ 6
CASE OF ST SEGMENT ELEVATION ................................................................................ 7
% Load original 1D signal.
clc;
clear all;
close all;
ELEVATED=[]
[fname path]=uigetfile('*.mat');
fname=strcat(path,fname);
load(fname );
z=zeros(100,1);
A=val(1,:);
v1=val(1,:)-val(1,1);
A=v1;
A=A';
zc=A(1);
A=[z;A;z];

%

s = A(1:1:400);
s = A;
ls = length(s);
figure(1)
plot(s);
title('Actual Signal'),grid on

[c,l]=wavedec(s,4,'db4');
ca1=appcoef(c,l,'db4',1);
ca2=appcoef(c,l,'db4',2);
ca3=appcoef(c,l,'db4',3);
ca4=appcoef(c,l,'db4',4);
figure(2)
plot(c),title('decomposed signal'),grid on
figure(3)

1

hold on plot(P2. m1=max(y1)-max(y1)*. for(i=2:1:length(P1)) if(P1(i)>(last+10)) last=P1(i).2.title('4th level reconstructed').grid on.grid on level reconstructed'). for( i=1:1:length(P3)) range= [P3(i)-20:P3(i)+20]. l=find(A(range)==m).grid on level reconstructed').60. end Ramp=A(Rloc).title('3rd subplot(2. P2=[P2 last]. remove one point each P1=P.grid on level reconstructed'). Rloc=[Rloc pos]. Calculate R in the actual Signal P3=P2*4.3) plot(ca3)..title('2nd subplot(2. Rloc=[]. % it will give two two points . 2 .title('1st subplot(2. y=base_corrected-zc.Rt. last=P1(1).2..2) plot(ca2). P2=[]. P=find(y1>=m1). m=max(A(range)).4) plot(ca4). end end Rt=y1(P2). figure(5) plot(y1). figure(4) plot(y).'*').grid on title('base line corrected and smoothed signal') DETECT R_PEAK y1=y. P2=[P2 last].1) plot(ca1). ZERO CROSSING REMOVAL%%%%%% base_corrected=ca2. pos=range(l).2.2.subplot(2.grid on Error: File: C:\Users\AbdKabeer\Documents\Msc Tel\DSP\ass\Project\ECG\Very Illegal use of reserved keyword "end".

y1=A.grid on. ONSET fnd=0.j)=qon1(1).Ramp. break end end if(fnd==0) Qrange=b:+1:b+20. b=find(y1(a)==m).. b=a(b). P Peak a=Rloc(i. for(i=1:1:1) for(j=1:1:length(X)) a=X(j)-100:X(j)-50. title('Detected R peak in actual Signal') After R Peak Tracking .j)=qon1(1).j)-100:Rloc(i. m=max(y1(a)). qon1=find(y1(Qrange)==max(y1(Qrange))). b=b(1). qon1=Qrange(qon1). for k=b-20:+1:b if((y1(k)<=0) && (y1(k-1)>0)) qon1=k. break end end if(fnd==0) Qrange=b-20:+1:b.hold on plot(Rloc. qon1=find(y1(Qrange)==max(y1(Qrange))). fnd=1.j)-10. DETCET OTHERS X=Rloc. end RON(i. 3 . qon1=Qrange(qon1). end ROF(i. for k=b:+1:b+20 if((y1(k)<=0) && (y1(k-1)>0)) qon1=k. fnd.. fnd=1.'*').figure(6) plot(A).

m=max(y1(a)). fnd=1. qon1=find(y1(Qrange)==max(y1(Qrange))). Qamp(i. end Q Detection a=Rloc(i.j)-50:Rloc(i. break end end if(fnd==0) Qrange=b:+1:b+20. b=find(y1(a)==m).j)=m. b=find(y1(a)==m). b=a(b). m=min(y1(a)). b=a(b). m=min(y1(a)). b=find(y1(a)==m).j)=qon1(1). for k=b-20:+1:b if((y1(k)<=0) && (y1(k-1)>0)) qon1=k. qon1=Qrange(qon1). break end end if(fnd==0) Qrange=b-20:+1:b. fnd. for k=b:+1:b+20 if((y1(k)<=0) && (y1(k-1)>0)) qon1=k. b=b(1).j)=m. end QON(i.j)=b. S Detection a=Rloc(i. 4 . fnd=1. b=b(1). %%%%% ONSET fnd=0. Pamp(i. Qloc(i. Ploc(i.j)+5:Rloc(i.j)+50. qon1=find(y1(Qrange)==max(y1(Qrange))).j)=qon1(1).j)-10.j)=b. qon1=Qrange(qon1). end QOF(i.

fnd=1. b=a(b). fnd=1. Sloc(i. T Peak a=Rloc(i.j)=b. end SON(i. %%%% onset off fnd=0. b=b(1). fnd=1.j)+100.b=b(1). b=a(b). for k=b:+1:b+20 if((y1(k)<=0) && (y1(k-1)>0)) qon1=k. fnd=0. end SOFF(i. Tloc(i. for k=b-20:+1:b if((y1(k)<=0) && (y1(k-1)>0)) qon1=k.j)+25:Rloc(i. m=max(y1(a)). break end end if(fnd==0) 5 .j)=b.j)=m. Tamp(i. %%%% onset off fnd=0. qon1=find(y1(Qrange)==max(y1(Qrange))).j)=qon1(1). for k=b-5:+1:b if((y1(k)<=0) && (y1(k-1)>0)) qon1=k. qon1=Qrange(qon1). qon1=find(y1(Qrange)==max(y1(Qrange))).j)=qon1(1). break end end if(fnd==0) Qrange=b:+1:b+20.j)=m. Samp(i. break end end if(fnd==0) Qrange=b-20:+1:b. qon1=Qrange(qon1). b=find(y1(a)==m).

end TOFF(j. qon1=Qrange(qon1). b=find(y1(a)==m). hold on plot(Tloc(i. end 6 .i)=qon1(1). qon1=find(y1(Qrange)==max(y1(Qrange))). qon1=find(y1(Qrange)==max(y1(Qrange))).j)=m.j)+70.:).:).:). fnd=0.hold on.'*').j)<Pamp(i.:).:).Qrange=b-20:+1:b. if(Tamp(i. figure.j)=b. hold on.j)) a=Rloc(i. b=b(1). plot(Qloc(i.j)+25:Rloc(i. m=min(y1(a)).').:). fnd=1. plot(y1).'. b=a(b). break end end if(fnd==0) Qrange=b:+1:b+20. plot(Ploc(i. ELEVATED=[ELEVATED j]. k=1.1. plot(Rloc(i.'+'). for(i=1:1:1) %subplot(6.hold on. qon1=Qrange(qon1). end END OF T end end figure.:).Pamp(i.:). if(k>6) k=1.Qamp(i. plot(Sloc(i. end TON(j. Tloc(i.hold on.'+').:). for k=b:+1:b+20 if((y1(k)<=0) && (y1(k-1)>0)) qon1=k.Ramp(i.:).Samp(i. Tamp(i.'^') grid on. k=k+1.i)=qon1(1).Tamp(i.k).

:)) ) PRpoint(i. TON=TON'.j)-(TOFF(i. end CASE OF ST SEGMENT ELEVATION x=A. STpoint(i. TOFF=TOFF'.j))/2). else flag=1.j)=ceil(Tloc(i. flag=0.j)= ceil(Rloc(i.j).j)-(SOFF(i. for(i=1:1:1) for(j=1:1:length(Rloc(i.j)-TON(i.i)-x(STpoint(i.j))/2). if(length(ELEVATED)>ceil(.j)=abs(x(PRpoint(i.end clc. x=mean(x). STDeviation(i.j).8*length(Rloc))) disp('T inverted (MI Detected) with T inverted Logic') return.14 7 . end end x=STDeviation/100. if(x>1) disp('MI Detected') else disp('Normal Signal') end Published with MATLAB® 7.i)).j)-QON(i.