Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
AIM :- To detect the QRS peak using Pan and Tompkins algorithm.
EQUIPMENT/SOFTWARE REQUIRED :- MATLAB R2012a
THEORY :- A real-time QRS detection algorithm developed by Pan and Tompkins (1985)
was further described by Hamilton and Tompkins (1986). It recognizes QRS complexes
based on analyses of the slope, amplitude, and width. Figure shows the various filters
involved in the analysis of the ECG signal. In order to attenuate noise, the signal is passed
through a band pass filter composed of cascaded high-pass and low-pass integer filters.
Subsequent processes are differentiation, squaring, and time averaging of the signal
h=1/8*fs*[-1 -2 0 2 1];
ecg_d=conv(ecg_h,h);
subplot(324);
plot([1:length(ecg_d)]/fs,ecg_d,'black');
xlabel('time(s)');
ylabel('amp(mV)');
axis tight;
title('filtered with derivative filter');
ecg_s=ecg_d.^2;
subplot(325);
plot([1:length(ecg_s)]/fs,ecg_s,'black');
xlabel('time(s)');
ylabel('amp(mV)');
axis tight;
title('squared');
ecg_m=conv(ecg_s,ones(1,round(0.150*fs))/round(0.150*fs));
subplot(326);
plot([1:length(ecg_m)]/fs,ecg_m,'black');
xlabel('time(s)');
ylabel('amp(mV)');
axis tight;
title('averaged');
[pks,locs]=findpeaks(ecg_m,'minpeakdistance',round(0.65*fs));
n=length(locs);
a=zeros(1,n);
for i=1:n
[c,w]=max(ecg_h(locs(i)-150:locs(i)+50));
a(i)=locs(i)-150+w;
end
subplot(3,2,[1 2]);
plot([1:length(y)]/fs,y);
axis tight;
title('raw ecg signal');
xlabel('time(s)');
ylabel('amp(mV)');
hold on;
scatter(a,y(a),85,[0 0 1]);
s=zeros(1,length(y));
for i=1:n
s(a(i)-100:a(i)+80)=ecg_h(a(i)-100:a(i)+80);
end
figure(2)
plot([1:length(s)]/fs,s);
axis tight;
title('qrs waveform');
xlabel('time(s)');
ylabel('amp(mV)');
amp(mV)
1200
1100
1000
900
0.5
1.5
2.5
time(s)
3.5
4.5
1
amp(mV)
amp(mV)
50
0.5
0
0
-50
-0.5
1
3
time(s)
averaged
time(s)
squared
4000
amp(mV)
amp(mV)
5000
3000
2000
1000
1
1000
800
600
400
200
time(s)
3
time(s)
qrs waveform
1
amp(mV)
0.5
-0.5
0.5
1.5
2.5
time(s)
3.5
10
4.5
EXPERIMENT NO .5
THEORY :- TP is based on the concept that ECG signals are normally oversampled at four
or five times faster than the highest frequency present. For example, an ECG used in
monitoring may have a bandwidth of 50 Hz and be sampled at 200 sps in order to easily
visualize the higher-frequency attributes of the QRS complex. Sampling theory tells us that
we can sample such a signal at 100 sps. TP provides a way to reduce the effective sampling
rate by half to 100 sps by selectively saving important signal points (i.e., the peaks and
valleys or turning points). The algorithm processes three data points at a time. It stores the
first sample point and assigns it as the reference point X0. The next two consecutive points
become X1 and X2. The algorithm retains either X1 or X2, depending on which point
preserves the turning point (i.e., slope change) of the original signal.
MATLAB PROGRAM :load('100m.mat');
y=val(1:5000);
ecg=y;
fs=200;
n=length(ecg);
compecg=zeros(1,n/2); %compressed ecg vector
compecg(1)=ecg(1); %save first sample
p=0; %index for compressed ecg
for k=1:2:n-2
s1=sign(ecg(k+1)-ecg(k));
s2=sign(ecg(k+2)-ecg(k+1));
if(s2-s1)>0
compecg(p+1)=ecg(k+1);
else
compecg(p+1)=ecg(k+2);
end
p=p+1;
end
compecg=compecg'; %convert to col vector
rececg=interp(compecg,2); %reconstruct ecg signal
subplot(3,1,1); plot(ecg); legend('Original ECG');
xlabel('Time in s'); ylabel('Amplitude');
subplot(3,1,2); plot(compecg); legend('Compressed signal');
xlabel('Time in s'); ylabel('Amplitude');
subplot(3,1,3); plot(rececg); legend('Reconstructed signal');
xlabel('Time in s'); ylabel('Amplitude');
cr=length(compecg)/length(ecg);
11
n1=length(compecg);
n2=length(rececg);
disp('length of ECG is:'); disp(n); % 388
disp('length of compressed ECG is:'); disp(n1);
disp('length of reconstructed ECG is:'); disp(n2);
OUTPUT PLOTS :-
1400
Amplitude
Original ECG
1200
1000
800
500
1000
1500
2000
2500
Time in s
3000
3500
4000
4500
5000
1500
Amplitude
Compressed signal
1000
500
0
500
1000
1500
2000
2500
Time in s
2000
Amplitude
Reconstructed signal
1000
0
-1000
500
1000
1500
2000
2500
Time in s
3000
3500
4000
4500
5000
12