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 Computes the BPM from a BVP signal
19 %> @param BVPSignal: the BVP signal
21 %> @retval BPM: the beats per minute
23 %> @author Copyright Mohammad Soleymani 2013
24 %> @author Copyright Frank Villaro-Dixon, 2014
28 %Make sure we have an BVP signal
32 fs = Signal__get_samprate(BVPSignal);
39 SizeWindow = round(fs/50);
40 data = data - mean(data);
43 dataS = filtfilt(ones(1, SizeWindow)/SizeWindow, 1, ...
44 [repmat(data(1), SizeWindow, 1); data(:)]);
45 dataS = dataS(SizeWindow+1:end);
49 %recherche des pics postif : deriv decroissante = 0
51 for(iSpl = 1:length(diffS)-1)
52 %si il y a une derive == 0 sur le dernier sample elle n'est pas prise en compte
53 if((diffS(iSpl) > 0) && (diffS(iSpl+1) < 0))
54 listePic = [listePic iSpl+(diffS(iSpl) / (diffS(iSpl) - diffS(iSpl+1)))];
55 elseif((diffS(iSpl) == 0) && (diffS(iSpl+1) < 0))
56 listePic = [listePic iSpl];
61 listePic = round(listePic);
64 %Procedure to keep only peaks that are separated by at least 0.5 seconds
65 %other are considered as the same peak and one of the two is selected
66 %according to the chosen method. Also peaks that lie alone in the
67 %first 0.5 seconds are removed (cannot determine which peak it is…)
68 limit = round(0.5*fs);
70 %Remove too early first peakS
71 if((listePic(1) < limit) && (listePic(2) - listePic(1) >= limit))
72 listePic = listePic(2:end);
77 while(iPic <= length(listePic) - 1)
78 %If two peaks are too close keep the one depending on the method
79 if((listePic(iPic+1) - listePic(iPic)) < limit)
80 [dummy, choice] = max([data(listePic(iPic)) data(listePic(iPic+1))]);
83 listePic(iPic+1) = [];
93 if(length(listePic) < 2)
94 error('There should be at least 2 peaks to detect');
97 %Compute bpm from the pic list
98 [BPM delta_t t] =
PICtoBPM(listePic, fs);
100 %%%%%BPM = mean(BPM); %And take it's mean