Labwork2 Biomedical Informatics University of Ljubljana, Faculty of Electrical Engineering
Labwork2 Biomedical Informatics University of Ljubljana, Faculty of Electrical Engineering
Biomedical informatics
University of Ljubljana, Faculty of Electrical
Engineering
Autor:
dr. Tomaž Vrtovec Koldo Eizmendi Gallastegui
Laboratory of Imaging Technologies Registration number: 70081273
Academic year: 2018/2019
University of Ljubljana, Faculty of Electrical Engineering Koldo Eizmendi Gallastegui
Laboratory of Imaging Technologies
Biomedical informatics 2018/2019
Question 1
The code used in this first question is almost identical to the one used in the laboratory. In fact,the
unique differences with the code used in the lab are that we have to use our own ECG data with its
own precordial lead and position in the data file. This information has been obtained from the »e.fe«.
The code shown below answers this first question. The changes in the code used in the lab are shown
in orange. On the other side, Figure 1 shows the picture of the ECG signal with the peaks of the Q, R,
S and P waves. Additionally, even though this is not asked till the second question, the peak of the T
wave is also included.
close all; clear all; clc;
ecg=load('ECG_e0111_0_8.mat');
ecgS=ecg.signal2; ecgT=ecg.time;
[iQ,iR,iS]=detectWavePeaksQRS(ecgS);
plot(ecgT(iR),ecgS(iR),'ko','MarkerFaceColor','g');
plot(ecgT(iQ),ecgS(iQ),'ko','MarkerFaceColor','m');
plot(ecgT(iS),ecgS(iS),'ko','MarkerFaceColor','y');
iP=detectWavePeaksP(ecgS,iQ,iS);
plot(ecgT(iP),ecgS(iP),'ko','MarkerFaceColor','r');
xlabel('Time(s)');ylabel('Amplitude (mV)');
1
University of Ljubljana, Faculty of Electrical Engineering Koldo Eizmendi Gallastegui
Laboratory of Imaging Technologies
Biomedical informatics 2018/2019
Figure 1. ECG signal and its peaks. In black: the ECG signal in time. Green dot: R peak. Pink dot: Q
peak. Yellow dot: S peak. Red dot: P peak. Blue dot: T peak
Question 2
This question asks to write a function for searching the peaks of the T wave. The function coded is
very similar to the detectWavePeaksP function programmed in the lab. Therefore, the logic used
when writing the code is the same used in the lab. The unique difference is that instead of searching
the maximum to the left of the Q point, we are looking for the maximum to the right of the S point.
This means that both, the boundaries and the conditions of the loop must be changed. The result can
be observed in Figure 1.
function oIdxT= detectWavePeaksT(iData,iIdxQ,iIdxS)
oIdxT=iIdxS(1:end-1);
for i=1:length(iIdxS)-1
W=iIdxQ(i+1)-iIdxS(i);
W=round(W);
for idx=iIdxS(i):1:iIdxS(i)+W/3
if iData(idx)>iData(oIdxT(i))
oIdxT(i)=idx;
end
end
end
end
2
University of Ljubljana, Faculty of Electrical Engineering Koldo Eizmendi Gallastegui
Laboratory of Imaging Technologies
Biomedical informatics 2018/2019
Question 3
This question asks to write a function that calculates the mean period and the corresponding
standard deviation (in seconds) and the mean frequency and the corresponding standard deviation
(in hertzs) of the occurrence of the peak of a selected wave.
The programme below shows one possible solution to this issue. It basically takes two contiguous
points and calculates the period as the difference between both points in terms of time. That value is
afterwards stored in the vector period. It must be highlighted that as the loop starts with k=2 the first
scalar of the vector period is 0. Therefore, in order to calculate the period properly it is necessary to
eliminate that value. Finally, by using the functions mean() and std() the output vector
[oHBavg,oHBstd,oHFavg,oHFstd] is created.
function [oHBavg,oHBstd,oHFavg,oHFstd] = computeHeartBeat (iTime,iIdx)
for k=2:length(iIdx)
period(k)=iTime(iIdx(k))-iTime(iIdx(k-1));
k=k+1;
end
period(1)=[];
oHBavg=mean(period);
oHBstd=std(period);
freq=1./period;
oHFavg=mean(freq);
oHFstd=std(freq);
end
=====================================================
=====================================================
3
University of Ljubljana, Faculty of Electrical Engineering Koldo Eizmendi Gallastegui
Laboratory of Imaging Technologies
Biomedical informatics 2018/2019
=====================================================
=====================================================
=====================================================
This writing has been achieved thanks to the next code added in the main script:
[iHBavgP,iHBstdP,iHFavgP,iHFstdP]=computeHeartBeat(ecgT,iP);
[iHBavgQ,iHBstdQ,iHFavgQ,iHFstdQ]=computeHeartBeat(ecgT,iQ);
[iHBavgR,iHBstdR,iHFavgR,iHFstdR]=computeHeartBeat(ecgT,iR);
[iHBavgS,iHBstdS,iHFavgS,iHFstdS]=computeHeartBeat(ecgT,iS);
[iHBavgT,iHBstdT,iHFavgT,iHFstdT]=computeHeartBeat(ecgT,iT);
disp("=====================================================")
disp("=====================================================")
disp("=====================================================")
4
University of Ljubljana, Faculty of Electrical Engineering Koldo Eizmendi Gallastegui
Laboratory of Imaging Technologies
Biomedical informatics 2018/2019
disp("=====================================================")
disp("=====================================================")
These results show that with a standard deviation of 0.0095984 hertz , S is the wave with maximum
frequency variation. If we take a look to the .hea we can observe that the patient has Mixed Angina
and 1 vessel disease. These two can be the reasons for such a deviation.
Question 4
This last question asks why the size of the file with binary data (*.dat) is exactly 5,400,000 bytes.
To answer to this question we have to first take into account the properties of the European ST-T
Database. As it is said in the Laboratory work preparation, each record is 2h duration and contains a
total of 2 signals. Furthermore, each signal is represented by 250 samples per secod with a 12 bit
resolution. Each measurement is then represented by 1.5 bytes. Some easy calculations will lead us
to the conclusion that the size of the file .dat is exactly 5,400,000 bytes.