TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
BVP__compute_IBI.m
Go to the documentation of this file.
1 %This file is part of TEAP.
2 %
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.
7 %
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.
12 %
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/>.
15 %
16 %> @file BVP__compute_IBI.m
17 %> @brief Computes the IBI if it is not yet available
18 %> @param BVPSignal: the BVP signal
19 %> @retval BVPSignal: the @b BVP signal containing the computed IBI signal
20 %
21 %> @author Copyright Guillaume Chanel 2015
22 function BVPSignal = BVP__compute_IBI( BVPSignal )
23 
24 %Compute the signal if it has not been already computed
25 if(isempty(Signal__get_raw(BVPSignal.IBI)))
26 
27  %Get information on the BVP signal
28  BVP = Signal__get_raw(BVPSignal);
29  samprate = Signal__get_samprate(BVPSignal);
30 
31  %Reshape BVP if needed
32  if size(BVP,1)<size(BVP,2)
33  BVP = BVP';
34  end
35 
36  %Remove trend for better peak detection
37  trend = smooth(BVP,samprate); % TODO: refine the window size ? This size seem to wok well thanks to Mohammad
38  BVP = BVP - trend;
39 
40  %Compute IBI
41  [~, ~, ~, listePeak] = PLETtoBPM(-BVP, samprate); %Negation of signal to find the systolic upstroke
42  [~, IBI, ~, listePeak] = correctBPM(listePeak, samprate);
43 
44  if(length(listePeak) < 2)
45  warning(['A least 2 peaks are needed to compute IBI but ' num2str(length(listePeak)) ' were found: result will be NaN'])
46  BVPSignal.IBI = Signal__set_raw(ECGSignal.IBI,IBI);
47  return
48  else
49 
50  %Attribute the computed signal to IBI to check if range is correct
51  % This is done now because this can cause problems in the resampling
52  BVPSignal.IBI = Signal__set_raw(BVPSignal.IBI,IBI);
53  Signal__assert_range(BVPSignal.IBI, 0.25, 1.5, 1);
54 
55  %Resample the signal with the one requested for IBI
56  IBI_samprate = Signal__get_samprate(BVPSignal.IBI);
57  IBI = interpIBI(listePeak/samprate,IBI_samprate,listePeak(end)/samprate)';
58 
59  %Attribute the computed signal to IBI
60  BVPSignal.IBI = Signal__set_raw(BVPSignal.IBI,IBI);
61 end
62 
63 end
64 
Signal__get_samprate
function Signal__get_samprate(in Signal)
Signal__set_raw
function Signal__set_raw(in Signal, in raw)
BVP__compute_IBI
function BVP__compute_IBI(in BVPSignal)
Signal__get_raw
function Signal__get_raw(in Signal)
PLETtoBPM
function PLETtoBPM(in data, in fe, in methodPeak, in SizeWindow, in verbose)
interpIBI
function interpIBI(in peaks, in fs, in duration, in silent)
Signal__assert_range
function Signal__assert_range(in Signal, in minVal, in maxVal, in soft)
correctBPM
function correctBPM(in listePic_in, in fe, in thresh)