TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
EEG_feat_bandENR.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 EEG_feat_bandENR.m
17 %> @brief Computes the band energy (trial/baseline) for the @b EEG signal.
18 %
19 %> @param EEGSignal: the @b EEG signal
20 %
21 %> @retval thetaBand: 1xN vector; N number of electrodes
22 %> @retval alphaBand: 1xN vector; N number of electrodes
23 %> @retval betaBand: 1xN vector; N number of electrodes
24 %> @retval slowAlpha: 1xN vector; N number of electrodes
25 %> @retval gammaBand: 1xN vector; N number of electrodes
26 %
27 %> @author Copyright Mohammad Soleymani 2009
28 %> @author Copyright Frank Villaro-Dixon, 2014
29 function [deltaBand, thetaBand, slowAlphaBand, alphaBand, betaBand, gammaBand] = EEG_feat_bandENR(EEGSignal)
30 config_file;
31 
32 EEGSignal = EEG__assert_type(EEGSignal);
33 
34 fs = Signal__get_samprate(EEGSignal);
35 %default is 15 seconds long
36 welch_window_size = fs*15;
37 %get the signal length
38 
39 sing_length = length(EEG_get_channel(EEGSignal, EEG_get_elname(1)));
40 n_electrodes = length(electrode_labels.EEG);
41 deltaBand = nan(1, n_electrodes);
42 thetaBand = nan(1, n_electrodes);
43 alphaBand = nan(1, n_electrodes);
44 betaBand = nan(1, n_electrodes);
45 slowAlphaBand = nan(1, n_electrodes);
46 gammaBand = nan(1, n_electrodes);
47 
48 if sing_length< welch_window_size +fs
49  warning('singal too short for the welch size')
50 end
51 if sing_length< welch_window_size +1
52  warning('singal too short for the welch size and this method will not work')
53 else
54  for iElec = 1:n_electrodes
55  name = EEG_get_elname(iElec);
56  data = EEG_get_channel(EEGSignal, name);
57  %detrending the EEG signals
58  data = detrend(data);
59  %Welch method to compute energy of the current electrode (trial + BL)
60  [PowerTrial, fTrial] = pwelch(data, welch_window_size , [], [], fs);
61  deltaBand(iElec) = log(sum(PowerTrial(fTrial>0 & fTrial<4)));
62  thetaBand(iElec) = log(sum(PowerTrial(4<=fTrial & fTrial<8)));
63  slowAlphaBand(iElec) = log(sum(PowerTrial(8<=fTrial & fTrial<10)));
64  alphaBand(iElec) = log(sum(PowerTrial(8<=fTrial & fTrial<12)));
65  betaBand(iElec) = log(sum(PowerTrial(12<=fTrial & fTrial<30)));
66  gammaBand(iElec) = log(sum(PowerTrial(30<fTrial)));
67  end
68 end
Signal__get_samprate
function Signal__get_samprate(in Signal)
EEG_get_elname
function EEG_get_elname(in num)
EEG__assert_type
function EEG__assert_type(in Signal)
EEG_feat_bandENR
function EEG_feat_bandENR(in EEGSignal)
EEG_get_channel
function EEG_get_channel(in Signal, in channelName)