TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
Signal_feat_bandEnergy.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 Signal_feat_bandEnergy.m
17 %> @brief Computes the standard deviation of a given signal
18 %> @author Copyright Mohammad Soleymani, 2015
19 %
20 %> @param Signal
21 %> @param bands a 2 x n dimenional array including the bands lower and upper
22 %> bounds
23 %> @retval band energy:it calculates energy in different bands
24 function [powerBands] = Signal_feat_bandEnergy(Signal, bands)
25 
26 
27 Signal__assert_mine(Signal);
28 
29 raw = Signal__get_raw(Signal);
30 
31 fs = Signal__get_samprate(Signal);
32 
33 %signals should be in columns for pwelch to work for a multi-channel case
34 %like when we have more than one EMG signal
35 if size(raw,1)<size(raw,2)
36  raw = raw';
37 end
38 welch_window_size = fs* 10;
39 
40 % to check the first band limit after 0
41 bands_flat = bands(:);
42 if min(bands_flat)==0
43  min_f = bands_flat(find(bands_flat>0,1,'first'));
44 else
45  min_f = min(bands_flat);
46 end
47 
48 if 1/min_f> welch_window_size/fs
49  warning('This welch window size is too small for your bands and the results are incorrect- consider increasing it');
50 end
51 
52 powerBands = nan(min(size(raw)),size(bands,1));
53 
54 if size(raw,1)< welch_window_size +fs
55  warning('singal too short for the welch size');
56 end
57 if size(raw,1)< welch_window_size +1
58  warning('singal too short for the welch size and this method will not work')
59 
60 else
61  for i = 1:size(raw,2)
62  [P(:,i),f] = pwelch(raw(:,i),welch_window_size,[],[],fs);
63  end
64 
65  %features for every band
66  for j = 1:size(raw,2)
67  for i = 1:size(bands,1)
68  powerBands(j,i) = log(sum(P(f> bands(i,1)& f<=bands(i,2),j))+eps);
69  end
70  end
71 
72 end
73 
Signal__get_samprate
function Signal__get_samprate(in Signal)
Signal__get_raw
function Signal__get_raw(in Signal)
Signal__assert_mine
function Signal__assert_mine(in Signal)
Signal_feat_bandEnergy
function Signal_feat_bandEnergy(in Signal, in bands)