Download Signal Processing Task-1

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts

Quantium Medical Cardiac Output wikipedia , lookup

Electrocardiography wikipedia , lookup

Transcript
Linköping Universitet | TBMT01 Biomedical Signal Processing
Signal Processing Task-1
ECG arrhythmia/ST-shift
November 27th 2015
Danish Bhat (danbh448)
Daniela Koller (danko100)
Fredrik Ekman (freek254)
Word count excluding Matlab code: 1811
Introduction
This report shows a method on how an ECG signal can be processed to detect different types
of arrhythmias, remove baseline wandering and noise or show an ST-shift. Therefore, five
different ECG signals were provided of healthy as well as unhealthy subjects. To be able to
give more detailed information on the given ECG signal helping to make a decision on the
patient, Matlab will be used. In this case, different algorithms have to be written in order to
prepare the original ECG signal in a way that the QRS complex as well as the P and the T peak
can be detected.
Background
StructureofanElectrocardiogram(ECG)
The electrical activity of the heart can be measured by electrodes placed at specific points on
the skin around the heart producing a composite recording in form of a graph. This is called an
Electrocardiogram (ECG). In a healthy heart each heartbeat begins in the right atrium with the
action potential signal originating from the sinoatrial (SA) node. This signal spreads across
both atria causing the muscle cells to depolarize inducing a phase called atrial systole
represented by the P-wave on the ECG. The period of conduction that follows the atrial systole
and proceeds the contraction of the ventricles is represented by the PR-segment. When the
signal leaves the atria it enters the ventricles by the AV node. As the signal spreads through the
ventricles the contractile fibers depolarize and contract very rapidly causing ventricular systole
which is shown by the QRS-complex on the ECG. At this time, atrial repolarization also occurs
whereby this activity is not shown on the ECG. Finally, as the signal passes through the
ventricles the ventricular walls start to relax and recover which is called a ventricular diastole.
The dome shaped T-wave represents this ventricular repolarization. On the ECG the STsegment depicts the period when the ventricles are depolarized. This sequence of events along
with the associated ECG trace repeats every heart beat giving rise to the ECG wave (Sörnmo
& Laguna, 2005).
Figure 1: ECG of a normal human heart. Images obtained from the Wikipedia page of Electrocardiography & LITFL online medical blog
AbnormalitiesfoundintheECG
A normal heartbeat, rate and rhythm is called a normal sinus rhythm. When the hearts rhythm
is too fast, too slow or out of order an arrhythmia also called as a rhythm disorder occurs. In
this task we are addressing the two common types of arrhythmia which are detected in the
ECG, namely Premature Atrial Contraction (PAC) and Premature Ventricular Contraction
(PVC). Heart complications such as myocardial infarctions or ischemic diseases results in STshift complications. These complications are usually categorized as ST-depression or STelevation.
1
PrematureAtrialContraction(PAC)
As the name suggests PAC is a heartbeat which occurs prematurely i.e. the heartbeat occurs
abnormally early. PACs originate at the upper chambers of the heart (atria) thus interfering
with the natural pacemaker of the heart which is the SA node. PACs occur when a particular
defected area in the atria produces a beat much earlier than the regular SA node beat. Since
both the normal and the premature beat originate from the atria it results in an abnormal Pwave. (Catalano).
PrematureVentricularContraction(PVC)
PVCs are premature heartbeats that originate in the ventricles on the heart. These arrhythmia
occur when a particular defected area in the ventricles beats even before the next beat is
delivered from the SA node. Since PVC occurs within the ventricles it can be detected by the
QRS-complex in the ECG. The QRS waveform is either positive or negative depending
whether the irritable area producing the premature beat is in the left or right ventricle
respectively (Catalano).
STshift
An ST-shift can be classified into ST-depression and ST-elevation when compared to the
isoelectric line. An isoelectric line can be detected by an amplitude of zero on the ECG plot.
ST-depression occurs when the ST-segment drops below the isoelectric line whereas STelevation is exactly the opposite of ST-depression where the ST-segment is positioned above
the isoelectric line (Sörnmo & Laguna, 2005).
Method
Initially the obtained ECGs contain noise and a baseline drift. Due to this baseline drift it was
hard to visualize the waveform based on the threshold value. By bringing the baseline drift to
the almost zero the ECG was much more detectable and easy to interpret (Chouhan, 2007). The
noise and baseline drift could be removed by implementing a bandpass (butterworth) filter. For
this specific filter the second order within the cutoff frequencies of 0.5Hz and 40Hz showed
the best results.
To detect the R-peaks the signal is first filtered similarly using a butterworth filter with changed
order and frequency values. The R-peak is then determined if the distance between the two
maximum peaks is greater than 30% and the maximum peak is greater than the previous and
the consecutive value. For every R-peak detected the distance to the previous detected peak
was calculated to see if it is too small or too big. If the gap between the found R-peaks is too
small, it is most likely that the second one found is mistakenly detected as R-peak and therefore
discarded.
In order to detect arrhythmia in the provided ECG signal, the calculated distanced between the
detected R-peaks was used. If the distance between two peaks is smaller than 80% of the mean
R-R distance and the next consecutive R-R distance is greater than 25% of the mean R-R
distance, this ECG segment can be categorized as PVC. Whereas, if the R-R distance is less
than 80% of the mean R-R distance and the consecutive R-R distance is not greater than 25%
of the mean R-R distance, the ECG can be categorized as PAC.
2
In order to find all other necessary PQST-peaks, all the detected R-peaks are used as reference
points. For that reason, two new time points are set up before and after the R peak on the xaxis. Within these time points a minimum or a maximum values is detected which gives the Pand T-peaks.
To detect the ST-shift in the ECG an average value of the PQ- and ST-slope is calculated. If
the ratio of ST- per PQ-slope for each complex keeps on changing then it’s classified as an STshift.
3
Results
ECG 1
Figure 2: Plot of original signal (top) and filtered signal (bottom) for ECG1
Figure 3: All detected R-peaks for ECG1
4
Figure 4: Result for detection of arrhythmia as PVC (red) and PAC (green) for ECG1
Figure 5: Filtered signal for better ST detection due to R-wave suppression (top) and increased R-waves for better R-peak
detection for ECG1
5
Figure 6:ST-shift for each PQRST complex in ECG1
ECG 2
Figure 7: Plot of original signal (top) and filtered signal (bottom) for ECG2
6
Figure 8: All detected R-peaks for ECG2
Figure 9: Result for detection of arrhythmia as PVC (red) and PAC (green) for ECG2
7
Figure 10: Filtered signal for better ST detection due to R-wave suppression (top) and increased R-waves for better R-peak
detection for ECG2
Figure 11:ST-shift for each PQRST complex in ECG2
8
ECG 3
Figure 12: Plot of original signal (top) and filtered signal (bottom) for ECG3
Figure 13: All detected R-peaks for ECG3
9
Figure 14: Result for detection of arrhythmia as PVC (red) and PAC (green) for ECG3
Figure 15: Filtered signal for better ST detection due to R-wave suppression (top) and increased R-waves for better R-peak
detection for ECG3
10
Figure 16:ST-shift for each PQRST complex in ECG3
ECG 4
Figure 17: Plot of original signal (top) and filtered signal (bottom) for ECG4
11
Figure 18: All detected R-peaks for ECG4
Figure 19: Result for detection of arrhythmia as PVC (red) and PAC (green) for ECG4
12
Figure 20: Filtered signal for better ST detection due to R-wave suppression (top) and increased R-waves for better R-peak
detection for ECG4
Figure 21:ST-shift for each PQRST complex in ECG4
13
ECG 5
Figure 22: Plot of original signal (top) and filtered signal (bottom) for ECG5
Figure 23: All detected R-peaks for ECG5
14
Figure 24: Result for detection of arrhythmia as PVC (red) and PAC (green) for ECG5
Figure 25: Filtered signal for better ST detection due to R-wave suppression (top) and increased R-waves for better R-peak
detection for ECG5
15
Figure 26:ST-shift for each PQRST complex in ECG5
Figure 2, Figure 7, Figure 12, Figure 17 and Figure 22 show the original signal and the filtered
signal which has a lower amplitude and is used for further processing. All R-peaks have been
detected and are denoted with red circles as seen in Figure 3, Figure 8, Figure 13, Figure 18 and
Figure 23. ECG signals containing arrhythmia are shown in Figure 4, Figure 9, Figure 14, Figure
19 and Figure 24. Red circles over an R-peak mark the arrhythmia PVC and green circles tag
the R-peak of an arrhythmical PAC signal. The suppressed R-wave signal was used for better
detection of PQST-peaks as visible in Figure 5, Figure 10, Figure 15, Figure 20 and Figure 25.
For comparison the primary filtered signal is shown beneath in the same figure. In Figure 6,
Figure 11, Figure 16, Figure 21 and Figure 26 the ST shift is shown, whereby basically ECG5
shows a greater change and ST shift in some areas of the signal.
Discussion & Conclusion
The given ECG1 appears to be obtained from a healthy person as no PVCs or PACs were
detected. Additionally, the graph shows no baseline wonder or ST-shift. For the second ECG
(ECG2) filtering was necessary as the signal contained a lot of noise and a big baseline drift
which was removed successfully by the butterworth filter. Neither an arrhythmia as PVC or
PAC nor an ST-shift was detected as in the previous ECG.
The obtained ECG3 contains 5 PACs but no PVCs according to the detection algorithm.
Therefore, the patient can be diagnosed with arrhythmia but no ST-shifts was sensed. ECG4
contained 138 PVCs whereby no PACs were detected. However, ECG4 was free of any STshifts, as the previous ECGs. In ECG5 61 PACs were detected but only 1 PVC. Furthermore,
an ST-shift was obtained as visible in the Figure 26.
So far, the Matlab code can be further improved as strongly differing signals as ECG5 are
difficult to analyze. As some T-waves show the same magnitude as the R-wave, it will not get
compressed but can be neglected with defining a specific minimal distance where a next peak
16
can be found. This could cause a problem if QRS complexes follow in a very short distance or
flattering occurs.
Matlab Code
%% Set-up! Clear old stuff, loads, sets parameters, filters for a normal
signal
clear all;
clc;
close all;
nr = 1;
f_ECG=[250,250,360,360,250];
%load TBMT01_ECGdata.mat;
load ECG.mat;
ECG = eval(strcat('EKG',num2str(nr)));
fs=f_ECG(nr); % sampling frequency picked from above
N=length(ECG); % number of samples
t=(0:N-1)/fs; % time, used for plotting
[b,a]=butter(2,[0.5 40]/(fs/2),'bandpass');
filtN=filtfilt(b,a,ECG); %removes wandering and noise
% FIGURE 1
figure(1)
title('Original Signal vs. Filtered Signal')
subplot(2,1,1)
plot(t,ECG); % the original ECG
xlabel('Time [s]')
ylabel('Signal Amplitude [-]')
title('Original Signal')
subplot(2,1,2)
plot(t,filtN); % plots the filtered ECG
xlabel('Time [s]')
ylabel('Signal Amplitude [-]')
title('Filtered Signal')
%% R-wave detection etc
[b,a]=butter(4,[4 40]/(fs/2),'bandpass');
filtR=filtfilt(b,a,ECG); %enhances R
R_time=[];
R_peak=[];
max_R=max(filtR); %used for making a threshold
for i=1:N
if filtR(i)>0.3*max_R && filtR(i)>filtR(i-1) && filtR(i)>filtR(i+1)
R_time(end+1)=(i-1)/fs; %r-peaks time vector
R_peak(end+1)=filtR(i); %r-peaks height vector
if length(R_time)>1 && (R_time(end)-R_time(end-1))<0.3
R_time=R_time(1:end-1);
R_peak=R_peak(1:end-1);
end
end
end
figure (2)
plot(t,filtR, 'b', R_time, R_peak,'or');
xlabel('Time [s]')
17
ylabel('Signal Amplitude [-]')
title('R-Peaks')
%% R-wave distances etc m.m. usw
Rdist_temp=[];
for i=1:length(R_time)-1
Rdist(i)=R_time(i+1)-R_time(i); %calc each r-peak distance
end
for i=1:length(Rdist)
if Rdist(i)<2
Rdist_temp(end+1)=Rdist(i);
end
end
meanRdist=mean(Rdist_temp); %average distance between r-peaks
%% PAC and PVC detection jawohl!
PAC=0;
PVC=0;
time_PVC=[];
time_PAC=[];
peak_PVC=[];
peak_PAC=[];
for i=1:length(Rdist)
if 0.8*meanRdist > Rdist(i) && i~=length(Rdist)
if Rdist(i+1)>1.25*meanRdist
time_PVC(end+1)=R_time(i+1); %time of PVC
peak_PVC(end+1)=R_peak(i+1); %height of PVC
PVC=PVC+1; %amount of PVC:s
else
time_PAC(end+1)=R_time(i+1); %time of PAC
peak_PAC(end+1)=R_peak(i+1); %height of PAC
PAC=PAC+1; %amount of PAC:s
end
end
end
figure(3)
hold on
plot(t,filtR);
plot(time_PVC,peak_PVC,'or');
plot(time_PAC,peak_PAC,'og');
hold off
xlabel('Time [s]')
ylabel('Signal Amplitude [-]')
title('Detected PVC (red) & PAC (green)')
%% Preparation for finding P,Q,S,T peaks
[b,a]=butter(3,6/(fs/2),'low');
filtST=filtfilt(b,a,filtN); %suppress R more and make smoother curves
figure(4)
subplot(2,1,1)
plot(t,filtST);
xlabel('Time [s]')
ylabel('Signal Amplitude [-]')
title('Supressed R-Wave for better ST detection')
subplot(2,1,2)
plot(t,filtR);
xlabel('Time [s]')
ylabel('Signal Amplitude [-]')
title('Increased R-Wave for better R detection')
18
P_time=[];
P_peak=[];
Q_time=[];
Q_peak=[];
S_time=[];
S_peak=[];
T_time=[];
T_peak=[];
S_timepoint1=[];
S_timepoint2=[];
P_timepoint1=[];
P_timepoint2=[];
T_timepoint1=[];
T_timepoint2=[];
Q_timepoint1=[];
Q_timepoint2=[];
for i=1:length(R_time)-1 %Different limits for where to look for the
different peaks.
S_timepoint1(end+1)=R_time(i);
S_timepoint2(end+1)=R_time(i)+meanRdist*0.8;
T_timepoint1(end+1)=R_time(i)+meanRdist*0.15;
T_timepoint2(end+1)=R_time(i)+meanRdist*0.5;
P_timepoint1(end+1)=R_time(i)-meanRdist*0.3;
P_timepoint2(end+1)=R_time(i)-meanRdist*0.1;
Q_timepoint1(end+1)=R_time(i)-meanRdist*0.22;
Q_timepoint2(end+1)=R_time(i);
end
%% P_WAVE - gets the time and height of p-peak
maxVal=[];
for i=1:length(P_timepoint1)
maxVal=max(filtST(t>P_timepoint1(i) & t<P_timepoint2(i)));
for j=1:N
if (filtST(j)==maxVal)
P_time(end+1)=(j-1)/fs; %time for peak
P_peak(end+1)=filtST(j); %height for peak
end
end
maxVal=[];
end
% figure(5)
% hold on
% plot(t,filtST);
% plot(P_time,P_peak,'or');
% hold off
% xlabel('Time [s]')
% ylabel('Signal Amplitude [-]')
%% Q_WAVE - gets the time and height of q-peak
minVal=[];
for i=1:length(Q_timepoint1)
minVal=min(filtST(t>Q_timepoint1(i) & t<Q_timepoint2(i)));
for j=1:N
if (filtST(j)==minVal)
Q_time(end+1)=(j-1)/fs; %time for peak
Q_peak(end+1)=filtST(j); %height for peak
end
end
minVal=[];
end
% figure(6)
% hold on
% plot(t,filtST);
% plot(Q_time,Q_peak,'or');
19
% hold off
% xlabel('Time [s]')
% ylabel('Signal Amplitude [-]')
%% T_WAVE - gets the time and height of t-peak
maxVal=[];
for i=1:length(T_timepoint1)
maxVal=max(filtST(t>T_timepoint1(i) & t<T_timepoint2(i)));
for j=1:N
if (filtST(j)==maxVal)
T_time(end+1)=(j-1)/fs; %time for peak
T_peak(end+1)=filtST(j); %height for peak
end
end
maxVal=[];
end
%
%
%
%
%
%
%
figure(7)
hold on
plot(t,filtST);
plot(T_time,T_peak,'or');
hold off
xlabel('Time [s]')
ylabel('Signal Amplitude [-]')
%% S_WAVE - gets the time and height of s-peak
minVal=[];
for i=1:length(S_timepoint1)
minVal=min(filtST(t>S_timepoint1(i) & t<S_timepoint2(i)));
for j=1:N
if (filtST(j)==minVal)
S_time(end+1)=(j-1)/fs; %time for peak
S_peak(end+1)=filtST(j); %height for peak
end
end
minVal=[];
end
%
%
%
%
%
%
%
figure(8)
hold on
plot(t,filtST);
plot(S_time,S_peak,'or');
hold off
xlabel('Time [s]')
ylabel('Signal Amplitude [-]')
%% ST shift calc
%(s+t)/(p+q)
ST=[];
for i=1:length(S_time)
ST(end+1)=(S_peak(i)+T_peak(i))/(P_peak(i)+Q_peak(i));
end
figure(9)
%plot(t,filtST, 'b',S_time,ST,'r'); %The shift in ST compared to PQ from
ECG-complex to ECG-complex
plot(S_time,ST,'b'); %The shift in ST compared to PQ from ECG-complex to
ECG-complexxlabel('Time [s]')
ylabel('Signal Amplitude [-]')
title('ST Shift')
20
21
Bibliography
Catalano, J. T. (u.d.). Guide to ECG Analysis.
Chouhan, V. (2007). Total Removal of Baseline Drift from ECG Signal. IEEE Xplore Computer
Science, 512-515.
Sörnmo, L., & Laguna, P. (2005). Bioelectrical Signal Processing in Cardiac and Neurological
Applications. Academic Press (Elsevier).
22