TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
ECG__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 ECG__compute_IBI.m
17 %> @brief Computes the IBI if it is not yet available
18 %> @param ECGSignal: the ECG signal
19 %> @retval ECGSignal: the ECG signal containing the computed IBI signal
20 %
21 %> @author Copyright Guillaume Chanel 2015
22 function ECGSignal = ECG__compute_IBI( ECGSignal )
23 
24 %Compute the signal if it has not been already computed
25 if(isempty(Signal__get_raw(ECGSignal.IBI)))
26 
27  %Get information on the ECG signal
28  rawSignal = Signal__get_raw(ECGSignal);
29  samprate = Signal__get_samprate(ECGSignal);
30 
31  %Compute IBI
32  newfs = 256; %Hz, as needed by rpeakdetect
33  ECG = resample(rawSignal, newfs, samprate); %WARN what happens if samprate/newfs is not a integer ?
34  if size(ECG,1)<size(ECG,2)
35  ECG = ECG';
36  end
37  [hrv, R_t, R_amp, R_index, S_t, S_amp] = rpeakdetect(ECG, newfs); %FIXME: there seem to be a problem with filter side effects (begin and end)
38  [~, IBI, ~, listePeak] = correctBPM(R_index, newfs);
39 
40  %If the number of detected peaks is lower than 2 than IBI cannot be
41  %computed
42  if(length(listePeak) < 2)
43  warning(['A least 2 peaks are needed to compute IBI but ' num2str(length(listePeak)) ' were found: result will be NaN'])
44  ECGSignal.IBI = Signal__set_raw(ECGSignal.IBI,IBI);
45  else
46  %Attribute the computed signal to IBI to check if range is correct
47  % This is done now because this can cause problems in the resampling
48  ECGSignal.IBI = Signal__set_raw(ECGSignal.IBI,IBI);
49  Signal__assert_range(ECGSignal.IBI, 0.25, 1.5, 1);
50 
51  %Resample the signal with the one requested for IBI
52  IBI_samprate = Signal__get_samprate(ECGSignal.IBI);
53  IBI = interpIBI(listePeak/newfs,IBI_samprate,listePeak(end)/newfs)';
54 
55  %Attribute the computed signal to IBI
56  ECGSignal.IBI = Signal__set_raw(ECGSignal.IBI,IBI);
57  end
58 end
59 
60 end
61 
Signal__get_samprate
function Signal__get_samprate(in Signal)
Signal__set_raw
function Signal__set_raw(in Signal, in raw)
Signal__get_raw
function Signal__get_raw(in Signal)
ECG__compute_IBI
function ECG__compute_IBI(in ECGSignal)
interpIBI
function interpIBI(in peaks, in fs, in duration, in silent)
rpeakdetect
function rpeakdetect(in data, in samp_freq, in thresh, in testmode)
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)