0% found this document useful (0 votes)
51 views6 pages

Labwork2 Biomedical Informatics University of Ljubljana, Faculty of Electrical Engineering

This document describes a labwork assignment on electrocardiography (ECG) signal analysis. The main tasks are to download ECG data from an online database, detect peaks in the ECG signal (P, Q, R, S, T waves), calculate heart rate parameters (period, frequency) for each wave, and explain why the binary data file is a certain size. Code is provided in MATLAB to complete the signal processing, detect peaks, and output heart rate statistics for each wave.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views6 pages

Labwork2 Biomedical Informatics University of Ljubljana, Faculty of Electrical Engineering

This document describes a labwork assignment on electrocardiography (ECG) signal analysis. The main tasks are to download ECG data from an online database, detect peaks in the ECG signal (P, Q, R, S, T waves), calculate heart rate parameters (period, frequency) for each wave, and explain why the binary data file is a certain size. Code is provided in MATLAB to complete the signal processing, detect peaks, and output heart rate statistics for each wave.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Labwork2

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

LabWork2: ELECTROCARDIOGRAPHY (ECG)


The main purpose of this lab is to to dowload ECG data from an online database and determine the
basic heart beat parameters (P, Q, R, S, T) by writing a code in matlab.

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;

plot(ecgT,ecgS,'k-'); grid; hold on;

[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

The results of this function can be seen in the upcoming lines.


The mean period of P: iHBavgP = 0.96333 seconds.

The standard derivation of P: 0.0085479 seconds.

The mean frequency of P: 1.0381 hertz.

The standard deviation of P: 0.0092051 hertz.

=====================================================

The mean period of Q: iHBavgQ = 0.96229 seconds.

The standard deviation of Q: 0.0082808 seconds.

The mean frequency of Q: 1.0393 hertz.

The standard deviation of Q: 0.0089866 hertz.

=====================================================

The mean period of R: iHBavgR = 0.96286 seconds.

The standard deviation of R: 0.0071979 seconds.

3
University of Ljubljana, Faculty of Electrical Engineering Koldo Eizmendi Gallastegui
Laboratory of Imaging Technologies
Biomedical informatics 2018/2019

The mean frequency of R: 1.0386 hertz.

The standard deviation of R: 0.0077800 hertz.

=====================================================

The mean period of S: iHBavgS = 0.96286 seconds.

The standard derivation of S: 0.0088587 seconds.

The mean frequency of S: 1.0387 hertz.

The standard deviation of S: 0.0095984 hertz.

=====================================================

The mean period of T: iHBavgT = 0.96133 seconds.

The standard deviation of T: 0.0074476 seconds.

The mean frequency of T: 1.0403 hertz.

The standard deviation of T: 0.0081134 hertz.

=====================================================

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("The mean period of P: "),(iHBavgP),disp(" seconds.")

disp("The standard deviation of P: "),disp(iHBstdP),disp(" seconds.")

disp("The mean frequency of P: "),disp(iHFavgP),disp(" hertz.")

disp("The standard deviation of P: "),disp(iHFstdP),disp(" hertz.")

disp("=====================================================")

disp("The mean period of Q: "),(iHBavgQ),disp(" seconds.")

disp("The standard deviation of Q: "),disp(iHBstdQ),disp(" seconds.")

disp("The mean frequency of Q: "),disp(iHFavgQ),disp(" hertz.")

disp("The standard deviation of Q: "),disp(iHFstdQ),disp(" hertz.")

disp("=====================================================")

disp("The mean period of R: "),(iHBavgR),disp(" seconds.")

disp("The standard deviation of R: "),disp(iHBstdR),disp(" seconds.")

disp("The mean frequency of R: "),disp(iHFavgR),disp(" hertz.")

disp("The standard deviation of R: "),disp(iHFstdR),disp(" hertz.")

disp("=====================================================")

4
University of Ljubljana, Faculty of Electrical Engineering Koldo Eizmendi Gallastegui
Laboratory of Imaging Technologies
Biomedical informatics 2018/2019

disp("The mean period of S: "),(iHBavgS),disp(" seconds.")

disp("The standard deviation of S: "),disp(iHBstdS),disp(" seconds.")

disp("The mean frequency of S: "),disp(iHFavgS),disp(" hertz.")

disp("The standard deviation of S: "),disp(iHFstdS),disp(" hertz.")

disp("=====================================================")

disp("The mean period of T: "),(iHBavgT),disp(" seconds.")

disp("The standard deviation of T: "),disp(iHBstdT),disp(" seconds.")

disp("The mean frequency of T: "),disp(iHFavgT),disp(" hertz.")

disp("The standard deviation of T: "),disp(iHFstdT),disp(" hertz.")

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.

You might also like