TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
spatialfilter.m
Go to the documentation of this file.
1 function [W,Label] = spatialfilter(arg1,Mode,s2)
2 % Spatial filter provides different spatial filters.
3 %
4 % W = spatialfilter(NS,...)
5 % W = spatialfilter(s,...)
6 % W = spatialfilter(HDR,...)
7 % W = spatialfilter([.], Mode)
8 % W = spatialfilter(s,'CSP',s2)
9 %
10 % NS number of channels
11 % s data matrix (one column per channel)
12 % Mode 'Mono': monopolar
13 % 'CAR': common average reference
14 % 'Laplace': Hjorth's Laplacian
15 % 'bipolar': all posible combinations of bipolar channels
16 % 'PCA': Principle Component Analysis
17 % 'ICA': Independent Component Analysis
18 % 'CSP': Common Spatial patterns
19 % 'ALL': Combination of all
20 
21 % $Id: spatialfilter.m 2202 2009-10-27 12:06:45Z schloegl $
22 % Copyright (C) 2008 by Alois Schloegl <a.schloegl@ieee.org>
23 % This is part of the BIOSIG-toolbox http://biosig.sf.net/
24 %
25 % BioSig is free software: you can redistribute it and/or modify
26 % it under the terms of the GNU General Public License as published by
27 % the Free Software Foundation, either version 3 of the License, or
28 % (at your option) any later version.
29 %
30 % BioSig is distributed in the hope that it will be useful,
31 % but WITHOUT ANY WARRANTY; without even the implied warranty of
32 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 % GNU General Public License for more details.
34 %
35 % You should have received a copy of the GNU General Public License
36 % along with BioSig. If not, see <http://www.gnu.org/licenses/>.
37 
38 s = [];
39 if any(size(arg1)>1)
40  s = arg1;
41  NS = size(arg1,2);
42 elseif isscalar(arg1)
43  NS = arg1;
44 elseif isstruct(arg1) && isfield(arg1,'NS')
45  NS = arg1.NS;
46 end;
47 
48 if strcmpi(Mode,'bipolar')
49  W = sparse(NS,NS*(NS-1)/2);
50  n = 0;
51  for k1 = 1:NS,
52  for k2 = 1+k1:NS,
53  n = n+1;
54  W([k1,k2],n) = [1,-1];
55  Label{n} = sprintf('Bip #%i-#%i',k1,k2);
56  end;
57  end;
58 
59 elseif strcmpi(Mode,'Mono')
60  W = speye(NS);
61  Label = cellstr(int2str([1:NS]'));
62  for k=1:NS,Label{k} = ['Mono #',int2str(k)]; end;
63 
64 elseif strcmpi(Mode,'CAR')
65  W = [eye(NS) - 1/NS, ones(NS,1)/NS];
66  Label = cellstr(int2str([1:NS]'));
67  for k=1:NS,Label{k} = ['CAR #',int2str(k)]; end;
68  Label{NS+1} = 'CAR REF';
69 
70 elseif strcmpi(Mode,'ICA')
71  W = [];
72  Label = {};
73  warning('ICA not supported yet');
74  %for k=1:size(W,2),Label{k} = ['ICA #',int2str(k)]; end;
75 
76 elseif strcmpi(Mode,'PCA')
77  if isempty(s)
78  error('PCA requires data matrix s')
79  else
80  [W,D] = eig(s'*s);
81  for k=1:size(W,2),Label{k} = ['PCA #',int2str(k)]; end;
82  end;
83 
84 elseif strcmpi(Mode,'CSP')
85  if isempty(s) || nargin<3
86  error('CSP requires data matrix s and s2')
87  else
88  [W,D] = eig(covm(s,'E'),covm(s2,'E'));
89  for k=1:size(W,2),Label{k} = ['CSP #',int2str(k)]; end;
90  end;
91 
92 elseif strcmpi(Mode,'ALL')
93  [W1,L1] = spatialfilter(NS,'Mono');
94  [W2,L2] = spatialfilter(NS,'bipolar');
95  [W3,L3] = spatialfilter(NS,'CAR');
96  W = [W1,W2,W3];
97  Label = [L1(:); L2(:); L3(:)];
98 
99  if ~isempty(s)
100  [W1,L1] = spatialfilter(s,'PCA');
101  [W2,L2] = spatialfilter(s,'ICA');
102  W = [W,W1,W2];
103  Label = [Label; L1(:); L2(:)];
104  end;
105 
106 elseif strcmpi(Mode,'Laplace')
107  error('Laplace not supported yet');
108 
109 else
110  error(sprintf('%s not supported yet',Mode));
111 end;
spatialfilter
function spatialfilter(in arg1, in Mode, in s2)