TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
GSR_feat_extr.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 GSR_feat_extr.m
17 %> @brief Computes GSR features
18 %
19 %> @param GSRsignal: the GSR signal.
20 %> @param varargin: you can choose which features to extract (see featureSelector)
21 %> the list of available features is:
22 %> - nbPeaks: number of GSR peaks per second
23 %> - ampPeaks: average amplitude of peaks
24 %> - riseTime: average rise time of peaks
25 %> - meanGSR: average GSR value
26 %> - stdGSR: variance of GSR
27 %
28 %> @retval GSR_feats: list of features values
29 %> @retval GSR_feats_names: names of the computed features (it is good pratice to
30 %> check this vector since the order of requested features
31 %> can be different than the requested one)
32 %> @author Copyright XXX 2011
33 %> @author Copyright Frank Villaro-Dixon, 2014
34 function [GSR_feats, GSR_feats_names] = GSR_feat_extr(GSRsignal,varargin)
35 
36 % Check inputs and define unknown values
37 narginchk(1, Inf);
38 
39 %Check signals and get sample rate
40 GSRsignal = GSR__assert_type(GSRsignal);
41 if(~Signal__has_preproc_lowpass(GSRsignal))
42  warning(['For the function to work well, you should low-pass the signal' ...
43  '. Preferably with a median filter']);
44 end
45 samprate = Signal__get_samprate(GSRsignal);
46 
47 % Define full feature list and get features selected by user
48 featuresNames = {'nbPeaks', 'ampPeaks', 'riseTime', 'meanGSR', 'stdGSR','firstQuartileGSR','thirdQuartileGSR'};
49 GSR_feats_names = featuresSelector(featuresNames,varargin{:});
50 
51 signalUnit = Signal__get_unit(GSRsignal);
52 
53 if strcmp(signalUnit, 'Ohm')
54  ampThresh = 100;%Ohm
55 elseif strcmp(signalUnit, 'nS')
56  %convert from nano siemens to resistance
57  raw = Signal__get_raw(GSRsignal);
58  raw = 1./(raw*10E9);
59  GSRsignal = Signal__set_raw(GSRsignal, raw);
60  ampThresh = 100;%Ohm
61 else
62  error(['The GSR unit (' ...
63  signalUnit ') is unknown; please fix it - a threshold shall be adjusted to the unit'])
64 end
65 
66 %If some features are selected
67 if(~isempty(GSR_feats_names))
68 
69  if any(strcmp('nbPeaks',GSR_feats_names)) || any(strcmp('ampPeaks',GSR_feats_names)) || any(strcmp('riseTime',GSR_feats_names))
70 
71  [nbPeaks, ampPeaks, riseTime, posPeaks] = GSR_feat_peaks(GSRsignal,ampThresh);
72  nbPeaks = nbPeaks/(length(GSRsignal)/samprate);
73  ampPeaks = mean(ampPeaks);
74  riseTime = mean(riseTime);
75  %TODO what is this good for? posPeaks
76  end
77 
78  %mean computation
79  if any(strcmp('meanGSR',GSR_feats_names))
80  meanGSR = Signal_feat_mean(GSRsignal);
81  end
82 
83  %standard devisation computation
84  if any(strcmp('stdGSR',GSR_feats_names))
85  stdGSR = Signal_feat_std(GSRsignal);
86  end
87  %first quartile
88  if any(strcmp('firstQuartileGSR',GSR_feats_names))
89  firstQuartileGSR = Signal_feat_quant(GSRsignal, 0.25);
90  end
91 
92  %third quartile
93  if any(strcmp('thirdQuartileGSR',GSR_feats_names))
94  thirdQuartileGSR = Signal_feat_quant(GSRsignal, 0.75);
95  end
96 
97 
98  %Write the values to the final vector output
99  for (i = 1:length(GSR_feats_names))
100  eval(['GSR_feats(i) = ' GSR_feats_names{i} ';']);
101  end
102 
103 else %no features selected
104  GSR_feats = [];
105 end
106 
107 end
108 
Signal__get_samprate
function Signal__get_samprate(in Signal)
Signal__has_preproc_lowpass
function Signal__has_preproc_lowpass(in Signal)
Signal_feat_std
function Signal_feat_std(in Signal)
Signal__set_raw
function Signal__set_raw(in Signal, in raw)
Signal_feat_mean
function Signal_feat_mean(in Signal)
Signal__get_raw
function Signal__get_raw(in Signal)
GSR__assert_type
function GSR__assert_type(in Signal)
Signal__get_unit
function Signal__get_unit(in Signal)
GSR_feat_peaks
function GSR_feat_peaks(in GSRsignal, in ampThresh)
GSR_feat_extr
function GSR_feat_extr(in GSRsignal, in varargin)
Signal_feat_quant
function Signal_feat_quant(in Signal, in quant)
featuresSelector
function featuresSelector(in featuresNames, in varargin)
If no Include/exclude statement is specifed all features are returned.