1 %This file is part of TEAP.
3 %TEAP is free software: you can redistribute it and/or modify
4 %it under the terms of the GNU General Public License as published by
5 %the Free Software Foundation, either version 3 of the License, or
6 %(at your option) any later version.
8 %TEAP is distributed in the hope that it will be useful,
9 %but WITHOUT ANY WARRANTY; without even the implied warranty of
10 %MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 %GNU General Public License
for more details.
13 %You should have received a copy of the GNU General Public License
14 %along with TEAP. If not, see <http://www.gnu.org/licenses/>.
17 %> @brief calcul le heart rate bpm a partir du fichier des donn�es data
18 %> le signal a une frequence d
'echantillonage fe. Search for the upper peak,
19 %> if systolic upstroke is desired, simply negate the signal
21 %> @param data the pletysmograph data
22 %> @param fe sampling frequency
23 %> @param methodPeak detection method for choice in case of many peak (default 'max
')
24 %> 'sharp
': the shapest peak
25 %> 'max: the highest peak
26 %>
'first': the first peak of the two
27 %> @param SizeWindow
for mean filtering, 0-> no fitlering (
default fe/50)
28 %> @param verbose display a graph of the result
if 1 (
default 0)
30 %> @retval bpm Heart rate in bpm
31 %> @retval delta Heart rate in time
32 %> @retval t vecteur contenant les samples central des deux pics ayant servi a
34 %> @retval listePic liste des echantillon ou il y a eu des pics detect�
35 %> Ver 2 : n
'utilise pas les wavlet mais seulement la d�riv�e du signal
36 %> Ver 3 : plus de gros filtrage et choix des pics suivant differetes methodes
38 %> @author Guillaume Chanel 2015
40 function [bpm, delta_t, t, listePic] = PLETtoBPM(data, fe, methodPeak, SizeWindow, verbose)
46 SizeWindow = round(fe/50);
52 data = data - mean(data);
54 dataS = filtfilt(ones(1, SizeWindow)/SizeWindow, 1, [repmat(data(1),SizeWindow,1);data]);
55 dataS = dataS(SizeWindow+1:end);
56 % dataS = medfilt1(data,SizeWindow);
63 %recherche des pics postif : deriv decroissante = 0
65 for(iSpl = 1:length(diffS)-1)
66 if((diffS(iSpl) > 0) & (diffS(iSpl+1) < 0)) %si il y a une derive == 0 sur le dernier sample elle n'est pas prise en compte
67 listePic = [listePic iSpl+(diffS(iSpl) / (diffS(iSpl) - diffS(iSpl+1)))];
68 elseif ((diffS(iSpl)==0) & (diffS(iSpl+1) < 0))
69 listePic = [listePic iSpl];
73 listePic = round(listePic);
76 %Procedure to keep only peaks that are separated by at least 0.5 seconds
77 %other are considered as the same peak and one of the two is selected
78 %according to the choosen method. Also peaks that are lie alone in the
79 %first 0.5 seconds are removed (cannot dentermine wich peak it is...)
80 limit = round(0.5*fe);
82 %Remove too early first peak
83 if((listePic(1) < limit) && (listePic(2) - listePic(1) >= limit))
84 listePic = listePic(2:end);
89 while(iPic<=length(listePic)-1)
90 %If two peaks are too close keep the one depending on the method
91 if( (listePic(iPic+1) - listePic(iPic)) < limit)
94 nbSplFwd = round(0.05*fe);
95 if(listePic(iPic+1)+nbSplFwd > length(dataS))
96 nbSplFwd = length(dataS) - listePic(iPic+1);
97 warning(['Not enough signal to look 0.05s ahead, looking at ' num2str(nbSplFwd/fe) 's ahead'])
99 sharp2 = dataS(listePic(iPic+1)) - dataS(listePic(iPic+1)+nbSplFwd);
100 sharp1 = dataS(listePic(iPic)) - dataS(listePic(iPic)+nbSplFwd);
107 [dummy, choice] = max([data(listePic(iPic)) data(listePic(iPic+1))]);
111 error([methodPeak ' method is unknown']);
114 listePic(iPic+1) = [];
125 if (length(listePic) < 2)
126 error('There should be at least 2 peaks to detect');
129 %Compute bpm from the pic list
130 [bpm delta_t t] =
PICtoBPM(listePic, fe);
137 plot(listePic,data(round(listePic)),'+')
138 plot(listePic,dataS(round(listePic)),'+r')
139 plot(listePic,diffS(round(listePic)),'+g')