Technical Tags:
Programming Language:

In this project first a directory is given as input to the program. The directory must contain independent 12 lead ecg data files. One such sample data is provided with the code. The first thing is to extract QRS complex from each lead.
x=[x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12];
Let x be a signal which contans N samples of all 12 leads where x1..x12 are the variables that stores N samples of independent waves.
[COEFF,SCORE] = princomp(x);
%x=SCORE;
p=SCORE(:,1).*SCORE(:,1);
f=find(p<max(p)*.9);
p(f)=0;
Score will be a noisy signal of peaks at possible R locations. But SCORE is a noisy data and extracting R peak information is difficult. Hence a simple logic is applied that extracts pure peaks which occurs at QRS complexes. Even though in all the peaks R locations will be almost same but they will never be at the same place. Hence from the reference of PCA signal, R peak in each lead must be obtained.
we will use a threshold of .9 to extract the R peaks
m=max(p);
r_temp=find(p(25:length(p))>=m*.9);
r_temp=r_temp+25;
r_das=[];
cur=r_temp(1);
r_das=[r_das cur];
There could be more than one location par R peak. But minimum RR-interval is 500. Therefore closely obtained points are removed
for(i=2:1:length(r_temp))
if(r_temp(i)>(cur+500))
cur=r_temp(i);
r_das=[r_das cur];
end
end
r_temp=r_das;
Now from these reference, find R-peaks in each signal.
for(j=1:1:12)
y1=x(:,j);
for(i=1:1:length(r_temp))
cur=r_temp(i);
wind=[cur-25:cur+25];
m=max(y1(wind));
a=find(y1(wind)>=m);
a=a(1);
a=wind(a);
b=a;
Rloc(j,i)=a;
Ramp(j,i)=y1(a);
subplot(3,4,j)
plot(y1);hold on;
plot(Rloc(j,:),Ramp(j,:),'*');end
end
Here from the obtained R locations from PCA, we search 25 samples forth and back in each lead and get the maximum amplitude position. This is R-peak of that corresponding lead.
Once R Peaks are located, remaining peak detection are quite simple and I leave it on the Reader to understand the Logic
.