Ecg Extraction Code
Short Description
Download Ecg Extraction Code...
Description
Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.
Contents n
ZERO CROSSING REMOVAL
n
DETECT R_PEAK
n
Calculate R in the actual Signal
n
After R Peak Tracking ... DETCET OTHERS
n
ONSET
n
P Peak
n
Q Detection
n
S Detection
n
T Peak
n
END OF T
% 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]; % Plot Actual Signal s = A(1:1:400); s = A; ls = length(s); figure(1) plot(s); title('Original Signal'),grid on % Perform decomposition at level 8 of s using db4 [c,l]=wavedec(s,8,'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); ca5=appcoef(c,l,'db4',5); ca6=appcoef(c,l,'db4',6); ca7=appcoef(c,l,'db4',7); ca8=appcoef(c,l,'db4',8); %Plot the coefficient figure(2) plot(c),title('decomposed signal'),grid on figure(3) subplot(4,2,1)
plot(ca1),title('1st subplot(4,2,2) plot(ca2),title('2nd subplot(4,2,3) plot(ca3),title('3rd subplot(4,2,4) plot(ca4),title('4th subplot(4,2,5) plot(ca5),title('5th subplot(4,2,6) plot(ca6),title('6th subplot(4,2,7) plot(ca7),title('7th subplot(4,2,8) plot(ca8),title('8th
level approximation'),grid on Generated by Foxit PDF Creator © Foxit Software
http://www.foxitsoftware.com For evaluation only. level approximation'),grid on level approximation'),grid on level approximation'),grid on level approximation'),grid on level approximation'),grid on level approximation'),grid on level approximation'),grid on
% Extract detail coefficients at levels % 1, 2 and 3, from wavelet decomposition % structure [c,l]. [cd1,cd2,cd3,cd4,cd5,cd6,cd7,cd8] = detcoef(c,l,[1 2 3 4 5 6 7 8]); figure(4) subplot(4,2,1) plot(cd1),title('detail subplot(4,2,2) plot(cd2),title('detail subplot(4,2,3) plot(cd3),title('detail subplot(4,2,4) plot(cd4),title('detail subplot(4,2,5) plot(cd5),title('detail subplot(4,2,6) plot(cd6),title('detail subplot(4,2,7) plot(cd7),title('detail subplot(4,2,8) plot(cd8),title('detail
coeff: level 1 cd1'),grid on coeff: level 2 cd2'),grid on coeff: level 3 cd3'),grid on coeff: level 4 cd4'),grid on
coeff: level 5 cd5'),grid on coeff: level 6 cd6'),grid on coeff: level 7 cd7'),grid on coeff: level 8 cd8'),grid on
Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.
Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.
ZERO CROSSING REMOVAL base_corrected=ca2; y=base_corrected-zc; figure(5) plot(y),grid on title('Noise Free signal')
Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.
DETECT R_PEAK y1=y; m1=max(y1)-max(y1)*.60; P=find(y1>=m1); % it will give two two points ... remove one point each P1=P; P2=[]; last=P1(1); P2=[P2 last]; for(i=2:1:length(P1)) if(P1(i)>(last+10)) last=P1(i); P2=[P2 last]; end end Rt=y1(P2); figure(6) plot(y1),grid on,hold on plot(P2,Rt,'*'); title('Rpos in downsampled signal');
Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.
C
te R n t e
t
S n
P3=P2*4; Rpos=[]; for( i=1:1:length(P3)) range= [P3(i)-20:P3(i)+20]; m=max(A(range)); l=find(A(range)==m); pos=range(l); Rpos=[Rpos pos]; end Ramp=A(Rpos); figure(7) plot(A),grid on,hold on plot(Rpos,Ramp,'*'); title('Detected R peak in actual Signal'); R_peaks = length(Rpos)
%disp([num2str(R_peaks) ' peaks'])
R_peaks = 13
Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.
A ter R Pe
Tr
n
DETCET OT ERS
X=Rpos; y1=A; for(i=1:1:1)
for(j=1:1:length(X))
a=X(j)-100:X(j)-50; m=max(y1(a)); b=find(y1(a)==m); b=b(1); b=a(b);
ONSET fnd=0; for k=b-20:+1:b if((y1(k)0)) qon1=k; fnd=1; break end end if(fnd==0) Qrange=b-20:+1:b; qon1=find(y1(Qrange)==max(y1(Qrange))); qon1=Qrange(qon1); end
RON(i,j)=qon1(1); fnd; for k=b:+1:b+20 if((y1(k)0)) qon1=k; fnd=1; break end end if(fnd==0) Qrange=b:+1:b+20; qon1=find(y1(Qrange)==max(y1(Qrange))); qon1=Qrange(qon1); end ROF(i,j)=qon1(1);
P Pe a=Rpos(i,j)-100:Rpos(i,j)-10; m=max(y1(a)); b=find(y1(a)==m); b=b(1); b=a(b); Ppos(i,j)=b; Pamp(i,j)=m;
end
Dete t on a=Rpos(i,j)-50:Rpos(i,j)-10; m=min(y1(a)); b=find(y1(a)==m); b=b(1); b=a(b); Qpos(i,j)=b; Qamp(i,j)=m; %%%%% ONSET fnd=0; for k=b-20:+1:b if((y1(k)0)) qon1=k; fnd=1; break end end if(fnd==0) Qrange=b-20:+1:b; qon1=find(y1(Qrange)==max(y1(Qrange))); qon1=Qrange(qon1); end QON(i,j)=qon1(1); fnd; for k=b:+1:b+20 if((y1(k)0)) qon1=k;
Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.
fnd=1; break end end if(fnd==0) Qrange=b:+1:b+20; qon1=find(y1(Qrange)==max(y1(Qrange))); qon1=Qrange(qon1); end QOF(i,j)=qon1(1);
S Dete t on a=Rpos(i,j)+5:Rpos(i,j)+50; m=min(y1(a)); b=find(y1(a)==m); b=b(1); b=a(b); Spos(i,j)=b; Samp(i,j)=m; %%%% onset off fnd=0; for k=b-5:+1:b if((y1(k)0)) qon1=k; fnd=1; break end end if(fnd==0) Qrange=b-20:+1:b; qon1=find(y1(Qrange)==max(y1(Qrange))); qon1=Qrange(qon1); end SON(i,j)=qon1(1); fnd=0; for k=b:+1:b+20 if((y1(k)0)) qon1=k; fnd=1; break end end if(fnd==0) Qrange=b:+1:b+20; qon1=find(y1(Qrange)==max(y1(Qrange))); qon1=Qrange(qon1); end SOFF(i,j)=qon1(1);
T Pe a=Rpos(i,j)+25:Rpos(i,j)+100; m=max(y1(a)); b=find(y1(a)==m); b=b(1); b=a(b);
Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.
Tpos(i,j)=b; Tamp(i,j)=m; %%%% onset off fnd=0; for k=b-20:+1:b if((y1(k)0)) qon1=k; fnd=1; break end end if(fnd==0) Qrange=b-20:+1:b; qon1=find(y1(Qrange)==max(y1(Qrange))); qon1=Qrange(qon1); end TON(j,i)=qon1(1); fnd=0; for k=b:+1:b+20 if((y1(k)0)) qon1=k; fnd=1; break end end if(fnd==0) Qrange=b:+1:b+20; qon1=find(y1(Qrange)==max(y1(Qrange))); qon1=Qrange(qon1); end TOFF(j,i)=qon1(1); if(Tamp(i,j)6) k=1; figure; end
Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only.
end % Detected no of peaks R_peaks = length(Rpos) P_peaks = length(Ppos) T_peaks = length(Tpos) S_peaks = length(Spos) Q_peaks = length(Qpos) clc; flag=0; if(length(ELEVATED)>ceil(.8*length(Rpos))) disp('T inverted (MI Detected) with T inverted Logic') return; else flag=1; end R_peaks P_peaks T_peaks S_peaks Q_peaks
= = = = =
R_peaks = 13
P_peaks = 13
T_peaks = 13
S_peaks = 13
Q_peaks = 13
R_peaks = 13
length(Rpos) length(Ppos) length(Tpos) length(Spos) length(Qpos)
Generated by Foxit PDF Creator © Foxit Software http://www.foxitsoftware.com For evaluation only. P_peaks = 13
T_peaks = 13
S_peaks = 13
Q_peaks = 13
Published with MATLAB® 7.14
View more...
Comments