diff --git a/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/display.m b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/display.m new file mode 100644 index 0000000000000000000000000000000000000000..c997c67c4d0c63f4aec59a44445200847e0d28e6 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/display.m @@ -0,0 +1,16 @@ +function display(this); + + disp(inputname(1)); + if length(this) == 1 + struct(this.EEG) + else + TMP = struct(this); + + TMP2 = TMP(1).EEG; + fieldorder = fieldnames(TMP2); + for index = 2:length(TMP) + TMP2(index) = orderfields(TMP(index).EEG, fieldorder); + end; + TMP2 + end; + diff --git a/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/eegobj.m b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/eegobj.m new file mode 100644 index 0000000000000000000000000000000000000000..7f3ad6139d6792268231aaa8d46bab6bc25ef70b --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/eegobj.m @@ -0,0 +1,14 @@ +function this = eegobj(EEG); + + if nargin == 1 + if isa(EEG, 'eegobj') + this = EEG; + return; + end; + for index = 1:length(EEG) + TMP(index).EEG = EEG(index); + end; + else + TMP.EEG = eeg_emptyset; + end; + this = class(TMP, 'eegobj'); diff --git a/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/fieldnames.m b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/fieldnames.m new file mode 100644 index 0000000000000000000000000000000000000000..ca2a00a17e7f878a79727f94c5f3ee29126e0d50 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/fieldnames.m @@ -0,0 +1,3 @@ +function res = fieldnames(this); + + res = fieldnames(this(1).EEG); diff --git a/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/horzcat2.m b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/horzcat2.m new file mode 100644 index 0000000000000000000000000000000000000000..51b051b4a3f950654319c719e6f02056e9b20c82 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/horzcat2.m @@ -0,0 +1,5 @@ +function this = horzcat(varargin); + this = varargin{1}; + for index = 2:length(varargin) + this.EEG(index) = varargin{index}.EEG; + end; diff --git a/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/isfield.m b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/isfield.m new file mode 100644 index 0000000000000000000000000000000000000000..1341b8e65af9b1c706f6fae6d67434344d3e6128 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/isfield.m @@ -0,0 +1,3 @@ +function res = isfield(this, vals); + + res = isfield(struct(this(1).EEG), vals); diff --git a/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/isstruct.m b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/isstruct.m new file mode 100644 index 0000000000000000000000000000000000000000..05cc0cf988d722d343c1fc566349094ac951c742 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/isstruct.m @@ -0,0 +1,3 @@ +function res = isstruct(this); + + res = 1; diff --git a/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/length.m b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/length.m new file mode 100644 index 0000000000000000000000000000000000000000..08943fee317da179c93914c882316e4810d47181 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/length.m @@ -0,0 +1,14 @@ +function res = length(this); + + tmp = struct(this); + %if any(cellfun(@length, { tmp.EEG }) > 1) + % error('EEG structure in object with more than 1 element') + %end; + try + res = length(tmp.EEG); + catch + res = length(tmp); + return; + end; + if res > 1, error('EEG structure in object with more than 1 element'); end; + res = length(tmp); diff --git a/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/orderfields.m b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/orderfields.m new file mode 100644 index 0000000000000000000000000000000000000000..ce9da6a9de5dc52468d2229741193624370554a0 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/orderfields.m @@ -0,0 +1,5 @@ +function this = orderfields(this, vals); + + for index = 1:length(this) + this(index).EEG = orderfields(this(index).EEG, vals); + end; diff --git a/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/rmfield.m b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/rmfield.m new file mode 100644 index 0000000000000000000000000000000000000000..4ce7320f6aeeec31e59f4c07e680f68a9d205392 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/rmfield.m @@ -0,0 +1,4 @@ +function this = rmfield(this, vals); + + this.EEG = rmfield(this.EEG, vals); + \ No newline at end of file diff --git a/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/simpletest.m b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/simpletest.m new file mode 100644 index 0000000000000000000000000000000000000000..ace35dc1a5836e68218614df0de05a5ef3314343 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/simpletest.m @@ -0,0 +1,4 @@ +% simple dataset tests +p = fileparts(which('eeglab')); +EEG = pop_loadset('filename','eeglab_data_epochs_ica.set','filepath',fullfile(p, 'sample_data')); + diff --git a/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/subsasgn.m b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/subsasgn.m new file mode 100644 index 0000000000000000000000000000000000000000..18ec5c95cfe8dc1f3499cd70644531bb6ba1dec5 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/subsasgn.m @@ -0,0 +1,68 @@ +function this = subsasgn(this,index,c) + + if isempty(this) + this = eegobj; + end; + + % mulitple dataset + if strcmpi(index(1).type, '()') && length(index) == 1 % dataset assignement + if isempty(c) % suppression + this(index.subs{1}) = []; + else + % create empty structures if necessary + % not optimized for speed but compatible Octave 3.4 and Matlab + allfieldsori = fieldnames( this ); + allSetIndices = [ [(length(this)+1):(min(index.subs{1})-1)] index.subs{1} ]; + this(max(index.subs{1})) = this(1); + for j = 1:length(allfieldsori) + for i = allSetIndices + this(i).EEG.(allfieldsori{j}) = []; + end; + end; + + % create empty structure, replaces the code above but + % only compatible under Matlab + %allfieldsori = fieldnames( this ); + %tmpfields = allfieldsori; + %tmpfields(:,2) = cell(size(tmpfields)); + %tmpfields = tmpfields'; + %tmp = struct(tmpfields{:}) + %this(index.subs{1}) = tmp; + + % dealing with input object and making it a compatible + % structure + if isa(c, 'eegobj') + c2 = struct(c); + c = c2(1).EEG; + fieldorder = fieldnames(c); + for cIndexe = 2:length(c2) + c(cIndexe) = orderfields(c2(cIndexe).EEG, fieldorder); + end; + end; + + allfields = fieldnames( c ); + for i=1:length( allfields ) + for j = 1:length(index.subs{1}) + this(index.subs{1}(j)).EEG.(allfields{i}) = c(min(j, length(c))).(allfields{i}); + end; + %this(index.subs(1)).EEG = setfield(this(index.subs(1)).EEG, getfield(c, allfields{i}), allfields{i}); + %eval( ['this(' int2str(index.subs{1}) ').' allfields{i} ' = c.' allfields{i} ';' ]); + end; + %if ~isfield(c, 'datfile') & isfield(this, 'datfile') + % this(index.subs{1}).datfile = ''; + %end; + end; + elseif strcmpi(index(1).type, '()') + if length(index(1).subs{1}) > 1 + error('Unsuported object feature - a.field or a([x y]).field is not supported for object arrays'); + elseif length(this) < index(1).subs{1} + this(index(1).subs{1}) = eegobj; + end; + this(index(1).subs{1}).EEG = builtin('subsasgn', this(index(1).subs{1}).EEG, index(2:end), c); + elseif strcmpi(index(1).type, '.') + if length(this) > 1 + error('Unsuported object feature - a.field or a([x y]).field is not supported for object arrays'); + else + this.EEG = builtin('subsasgn', this.EEG, index, c); + end; + end; diff --git a/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/subsref.m b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/subsref.m new file mode 100644 index 0000000000000000000000000000000000000000..d4ba37ccc913d030c8efc27435101120a2268831 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/subsref.m @@ -0,0 +1,45 @@ +function varargout = subsref(this,s) + +if strcmpi(s(1).type, '()') && length(this) > 1 + %if length(s(1).subs{1}) + % error('Unsuported object feature - a.field or a([x y]).field is not supported for object arrays'); + %end; + +% if length(s) == 1 +% b = this(s(1).subs{1}); +% else +% b = builtin('subsref', this(s(1).subs{1}).EEG, s(2:end)); +% end; + + if length(s) == 1 + varargout{1} = this(s(1).subs{1}); + elseif length(s(1).subs{1}) > 1 + for index = 1:length(s(1).subs{1}) + varargout{1}{index} = builtin('subsref', this(s(1).subs{1}(index)).EEG, s(2:end)); + end; + else + varargout{1} = builtin('subsref', this(s(1).subs{1}).EEG, s(2:end)); + end; +elseif strcmpi(s(1).type, '.') && length(this) > 1 + for index = 1:length(this) + varargout{index} = builtin('subsref', this(index).EEG, s); + end; + %if length(s) > 1 && iscell(s(2).subs) && length(s(2).subs{1}) + % error('Unsuported object feature - a.field or a([x y]).field is not supported for object arrays'); + %end; +else + varargout{1} = builtin('subsref', this.EEG, s); +end; + + +% return; +% +% % SUBSREF +% switch s.type +% case '()' +% b = getfield(a.rawbit, s.subs); +% case '.' +% b = getfield(struct(a), s.subs); +% otherwise +% error('Wrong class argument') +% end diff --git a/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/display.m b/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/display.m new file mode 100644 index 0000000000000000000000000000000000000000..fc815aef2a934e6878137791814333506e0dcb98 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/display.m @@ -0,0 +1,36 @@ +% display() - display an EEG data class underlying structure +% +% Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 + +% Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function b = display(a) + + i.type = '()'; + i.subs = { ':' ':' ':' }; + b = subsref(a, i); % note that subsref cannot be called directly + return; + + + %struct(a) + %return; + + if ~strcmpi(a.fileformat, 'transposed') + a.data.data.x; + else + permute(a, [3 1 2]); + end; diff --git a/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/double.m b/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/double.m new file mode 100644 index 0000000000000000000000000000000000000000..36031d573968180f10989db95896f02dde7f95c9 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/double.m @@ -0,0 +1,3 @@ +function res = double(a); + +res = double(a.data.data.x); \ No newline at end of file diff --git a/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/end.m b/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/end.m new file mode 100644 index 0000000000000000000000000000000000000000..2e726d445642743ead904f0bcf07f808c6bfff4e --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/end.m @@ -0,0 +1,23 @@ +% end() - last index to memmapdata array +% +% Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 + +% Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function s = end(a, k, n); + + s = size(a, k); diff --git a/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/isnumeric.m b/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/isnumeric.m new file mode 100644 index 0000000000000000000000000000000000000000..ffd3d7447f60f357292fd34901fb9e71c1fe8449 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/isnumeric.m @@ -0,0 +1,23 @@ +% isnumeric() - returns 1 +% +% Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 + +% Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function r = isnumeric(a) + + r = 1; diff --git a/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/length.m b/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/length.m new file mode 100644 index 0000000000000000000000000000000000000000..e8a3250cf43d563819073a3e0c02d2bea5e551b1 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/length.m @@ -0,0 +1,23 @@ +% length() - length of memory mapped underlying array +% +% Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 + +% Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function s = length(a) + + s = size(a,1); diff --git a/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/msize.m b/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/msize.m new file mode 100644 index 0000000000000000000000000000000000000000..8c4210fb41c47a2bfe49d94b6c2716bf2f5ab8b0 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/msize.m @@ -0,0 +1,3 @@ +function s = msize(a); + + asdfdsa; diff --git a/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/ndims.m b/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/ndims.m new file mode 100644 index 0000000000000000000000000000000000000000..f77b01ca0183e5014c123f769a4aa46ab3939553 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/ndims.m @@ -0,0 +1,31 @@ +% ndims() - number of dimension of memory mapped underlying array +% +% Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008 + +% Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function s = ndims(a) + + if ~strcmpi(a.fileformat, 'transposed') + if a.data.Format{2}(3) == 1, s = 2; + else s = 3; + end; + else + if a.data.Format{2}(2) == 1, s = 2; + else s = 3; + end; + end; diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/CVS/Entries b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/CVS/Entries new file mode 100644 index 0000000000000000000000000000000000000000..38977adcdc6a86a1eb1ab69df7470ed90c7bf6ce --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/CVS/Entries @@ -0,0 +1,20 @@ +/Contents.m/1.7/Wed Oct 19 13:05:33 2005// +/demosig.m/1.2/Sat Apr 5 14:23:57 2003// +/dispsig.m/1.2/Sat Apr 5 14:23:57 2003// +/fastica.m/1.14/Wed Oct 19 13:05:34 2005// +/fasticag.m/1.5/Wed Oct 19 13:05:34 2005// +/fpica.m/1.7/Thu Jun 16 12:52:55 2005// +/gui_adv.m/1.4/Tue Jul 27 13:09:26 2004// +/gui_advc.m/1.3/Mon Sep 8 11:28:58 2003// +/gui_cb.m/1.5/Wed Sep 10 10:33:41 2003// +/gui_cg.m/1.2/Sat Apr 5 14:23:57 2003// +/gui_help.m/1.6/Wed Oct 19 13:05:34 2005// +/gui_l.m/1.4/Tue Jul 27 13:09:26 2004// +/gui_lc.m/1.4/Thu Sep 11 12:01:19 2003// +/gui_s.m/1.4/Tue Jul 27 13:09:26 2004// +/gui_sc.m/1.3/Mon Sep 8 11:28:59 2003// +/icaplot.m/1.2/Sat Apr 5 14:23:58 2003// +/pcamat.m/1.5/Mon Dec 15 18:24:32 2003// +/remmean.m/1.2/Sat Apr 5 14:23:58 2003// +/whitenv.m/1.3/Sun Oct 12 09:04:43 2003// +D diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/CVS/Repository b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/CVS/Repository new file mode 100644 index 0000000000000000000000000000000000000000..92b6beebf87b118af80716655c47b83f6334df4c --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/CVS/Repository @@ -0,0 +1 @@ +FastICA diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/CVS/Root b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/CVS/Root new file mode 100644 index 0000000000000000000000000000000000000000..c2b4f374964cebb1fda0d64e44ce3c43c69ab50d --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/CVS/Root @@ -0,0 +1 @@ +/share/video/cvsroot diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/Contents.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/Contents.m new file mode 100644 index 0000000000000000000000000000000000000000..fd6853f6f662cf1dcce6620f67afa85e7e6e0e26 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/Contents.m @@ -0,0 +1,40 @@ +% FastICA for Matlab 7.x and 6.x +% Version 2.5, October 19 2005 +% Copyright (c) Hugo Gävert, Jarmo Hurri, Jaakko Särelä, and Aapo Hyvärinen. +% +% Type fasticag to launch the graphical user interface +% +% Please refer to your Matlab documentation on how to add FastICA to your +% Matlab search path. (One place to start is the path-command) +% +% FastICA programs: +% FASTICAG - Graphical user interface for FastICA +% FASTICA - command line version of FastICA +% +% Separate functions used by FastICA programs. +% FPICA - main algorithm for calculating ICA +% WHITENV - function for whitening data +% PCAMAT - calculates the PCA for data +% REMMEAN - function for removing mean +% +% GUI_CB - needed by fasticag +% GUI_ADV - needed by fasticag +% GUI_ADVC - needed by fasticag +% GUI_L - needed by fasticag +% GUI_LC - needed by fasticag +% GUI_S - needed by fasticag +% GUI_SC - needed by fasticag +% GUI_CG - needed by fasticag +% GUI_HELP - needed by fasticag +% +% ICAPLOT - for plotting the signals +% (also used by fastica and fasticag) +% +% Misc. +% DEMOSIG - generates some test signals +% +% Deprecated +% dispsig - plots the data vectors +% replaced by icaplot + +% @(#)$Id: Contents.m,v 1.7 2005/10/19 13:05:33 jarmo Exp $ \ No newline at end of file diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/demosig.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/demosig.m new file mode 100644 index 0000000000000000000000000000000000000000..d8950637b10e92280ffd8efe93b9faf23e6d628b --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/demosig.m @@ -0,0 +1,32 @@ +function [sig,mixedsig]=demosig(); +% +% function [sig,mixedsig]=demosig(); +% +% Returns artificially generated test signals, sig, and mixed +% signals, mixedsig. Signals are row vectors of +% matrices. Input mixedsig to FastICA to see how it works. + +% @(#)$Id: demosig.m,v 1.2 2003/04/05 14:23:57 jarmo Exp $ + +%create source signals (independent components) +N=500; %data size + +v=[0:N-1]; +sig=[]; +sig(1,:)=sin(v/2); %sinusoid +sig(2,:)=((rem(v,23)-11)/9).^5; %funny curve +sig(3,:)=((rem(v,27)-13)/9); %saw-tooth +sig(4,:)=((rand(1,N)<.5)*2-1).*log(rand(1,N)); %impulsive noise + +for t=1:4 +sig(t,:)=sig(t,:)/std(sig(t,:)); +end + +%remove mean (not really necessary) + +[sig mean]=remmean(sig); + +%create mixtures + +Aorig=rand(size(sig,1)); +mixedsig=(Aorig*sig); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/dispsig.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/dispsig.m new file mode 100644 index 0000000000000000000000000000000000000000..257458bb68d95f3c87f702db80bf0ebe3ea4e7d3 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/dispsig.m @@ -0,0 +1,15 @@ +function dispsig(signalMatrix, range, titlestr); +%DISPSIG - deprecated! +% +% Please use icaplot instead. +% +% See also ICAPLOT + +% @(#)$Id: dispsig.m,v 1.2 2003/04/05 14:23:57 jarmo Exp $ + +fprintf('\nNote: DISPSIG is now deprecated! Please use ICAPLOT.\n'); + +if nargin < 3, titlestr = ''; end +if nargin < 2, range = 1:size(signalMatrix, 1); end + +icaplot('dispsig',signalMatrix',0,range,range,titlestr); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/fastica.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/fastica.m new file mode 100644 index 0000000000000000000000000000000000000000..886f93f84f398d51a99d655e5bff56ba5f1d1885 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/fastica.m @@ -0,0 +1,519 @@ +function [Out1, Out2, Out3] = fastica(mixedsig, varargin) +%FASTICA - Fast Independent Component Analysis +% +% FastICA for Matlab 7.x and 6.x +% Version 2.5, October 19 2005 +% Copyright (c) Hugo Gävert, Jarmo Hurri, Jaakko Särelä, and Aapo Hyvärinen. +% +% FASTICA(mixedsig) estimates the independent components from given +% multidimensional signals. Each row of matrix mixedsig is one +% observed signal. FASTICA uses Hyvarinen's fixed-point algorithm, +% see http://www.cis.hut.fi/projects/ica/fastica/. Output from the +% function depends on the number output arguments: +% +% [icasig] = FASTICA (mixedsig); the rows of icasig contain the +% estimated independent components. +% +% [icasig, A, W] = FASTICA (mixedsig); outputs the estimated separating +% matrix W and the corresponding mixing matrix A. +% +% [A, W] = FASTICA (mixedsig); gives only the estimated mixing matrix +% A and the separating matrix W. +% +% Some optional arguments induce other output formats, see below. +% +% A graphical user interface for FASTICA can be launched by the +% command FASTICAG +% +% FASTICA can be called with numerous optional arguments. Optional +% arguments are given in parameter pairs, so that first argument is +% the name of the parameter and the next argument is the value for +% that parameter. Optional parameter pairs can be given in any order. +% +% OPTIONAL PARAMETERS: +% +% Parameter name Values and description +% +%====================================================================== +% --Basic parameters in fixed-point algorithm: +% +% 'approach' (string) The decorrelation approach used. Can be +% symmetric ('symm'), i.e. estimate all the +% independent component in parallel, or +% deflation ('defl'), i.e. estimate independent +% component one-by-one like in projection pursuit. +% Default is 'defl'. +% +% 'numOfIC' (integer) Number of independent components to +% be estimated. Default equals the dimension of data. +% +%====================================================================== +% --Choosing the nonlinearity: +% +% 'g' (string) Chooses the nonlinearity g used in +% the fixed-point algorithm. Possible values: +% +% Value of 'g': Nonlinearity used: +% 'pow3' (default) g(u)=u^3 +% 'tanh' g(u)=tanh(a1*u) +% 'gauss g(u)=u*exp(-a2*u^2/2) +% 'skew' g(u)=u^2 +% +% 'finetune' (string) Chooses the nonlinearity g used when +% fine-tuning. In addition to same values +% as for 'g', the possible value 'finetune' is: +% 'off' fine-tuning is disabled. +% +% 'a1' (number) Parameter a1 used when g='tanh'. +% Default is 1. +% 'a2' (number) Parameter a2 used when g='gaus'. +% Default is 1. +% +% 'mu' (number) Step size. Default is 1. +% If the value of mu is other than 1, then the +% program will use the stabilized version of the +% algorithm (see also parameter 'stabilization'). +% +% +% 'stabilization' (string) Values 'on' or 'off'. Default 'off'. +% This parameter controls wether the program uses +% the stabilized version of the algorithm or +% not. If the stabilization is on, then the value +% of mu can momentarily be halved if the program +% senses that the algorithm is stuck between two +% points (this is called a stroke). Also if there +% is no convergence before half of the maximum +% number of iterations has been reached then mu +% will be halved for the rest of the rounds. +% +%====================================================================== +% --Controlling convergence: +% +% 'epsilon' (number) Stopping criterion. Default is 0.0001. +% +% 'maxNumIterations' (integer) Maximum number of iterations. +% Default is 1000. +% +% 'maxFinetune' (integer) Maximum number of iterations in +% fine-tuning. Default 100. +% +% 'sampleSize' (number) [0 - 1] Percentage of samples used in +% one iteration. Samples are chosen in random. +% Default is 1 (all samples). +% +% 'initGuess' (matrix) Initial guess for A. Default is random. +% You can now do a "one more" like this: +% [ica, A, W] = fastica(mix, 'numOfIC',3); +% [ica2, A2, W2] = fastica(mix, 'initGuess', A, 'numOfIC', 4); +% +%====================================================================== +% --Graphics and text output: +% +% 'verbose' (string) Either 'on' or 'off'. Default is +% 'on': report progress of algorithm in text format. +% +% 'displayMode' (string) Plot running estimates of independent +% components: 'signals', 'basis', 'filters' or +% 'off'. Default is 'off'. +% +% 'displayInterval' Number of iterations between plots. +% Default is 1 (plot after every iteration). +% +%====================================================================== +% --Controlling reduction of dimension and whitening: +% +% Reduction of dimension is controlled by 'firstEig' and 'lastEig', or +% alternatively by 'interactivePCA'. +% +% 'firstEig' (integer) This and 'lastEig' specify the range for +% eigenvalues that are retained, 'firstEig' is +% the index of largest eigenvalue to be +% retained. Default is 1. +% +% 'lastEig' (integer) This is the index of the last (smallest) +% eigenvalue to be retained. Default equals the +% dimension of data. +% +% 'interactivePCA' (string) Either 'on' or 'off'. When set 'on', the +% eigenvalues are shown to the user and the +% range can be specified interactively. Default +% is 'off'. Can also be set to 'gui'. Then the user +% can use the same GUI that's in FASTICAG. +% +% If you already know the eigenvalue decomposition of the covariance +% matrix, you can avoid computing it again by giving it with the +% following options: +% +% 'pcaE' (matrix) Eigenvectors +% 'pcaD' (matrix) Eigenvalues +% +% If you already know the whitened data, you can give it directly to +% the algorithm using the following options: +% +% 'whiteSig' (matrix) Whitened signal +% 'whiteMat' (matrix) Whitening matrix +% 'dewhiteMat' (matrix) dewhitening matrix +% +% If values for all the 'whiteSig', 'whiteSig' and 'dewhiteMat' are +% supplied, they will be used in computing the ICA. PCA and whitening +% are not performed. Though 'mixedsig' is not used in the main +% algorithm it still must be entered - some values are still +% calculated from it. +% +% Performing preprocessing only is possible by the option: +% +% 'only' (string) Compute only PCA i.e. reduction of +% dimension ('pca') or only PCA plus whitening +% ('white'). Default is 'all': do ICA estimation +% as well. This option changes the output +% format accordingly. For example: +% +% [whitesig, WM, DWM] = FASTICA(mixedsig, +% 'only', 'white') +% returns the whitened signals, the whitening matrix +% (WM) and the dewhitening matrix (DWM). (See also +% WHITENV.) In FastICA the whitening matrix performs +% whitening and the reduction of dimension. Dewhitening +% matrix is the pseudoinverse of whitening matrix. +% +% [E, D] = FASTICA(mixedsig, 'only', 'pca') +% returns the eigenvector (E) and diagonal +% eigenvalue (D) matrices containing the +% selected subspaces. +% +%====================================================================== +% EXAMPLES +% +% [icasig] = FASTICA (mixedsig, 'approach', 'symm', 'g', 'tanh'); +% Do ICA with tanh nonlinearity and in parallel (like +% maximum likelihood estimation for supergaussian data). +% +% [icasig] = FASTICA (mixedsig, 'lastEig', 10, 'numOfIC', 3); +% Reduce dimension to 10, and estimate only 3 +% independent components. +% +% [icasig] = FASTICA (mixedsig, 'verbose', 'off', 'displayMode', 'off'); +% Don't output convergence reports and don't plot +% independent components. +% +% +% A graphical user interface for FASTICA can be launched by the +% command FASTICAG +% +% See also FASTICAG + +% @(#)$Id: fastica.m,v 1.14 2005/10/19 13:05:34 jarmo Exp $ + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Check some basic requirements of the data +if nargin == 0, + error ('You must supply the mixed data as input argument.'); +end + +if length (size (mixedsig)) > 2, + error ('Input data can not have more than two dimensions.'); +end + +if any (any (isnan (mixedsig))), + error ('Input data contains NaN''s.'); +end + +if ~isa (mixedsig, 'double') + fprintf ('Warning: converting input data into regular (double) precision.\n'); + mixedsig = double (mixedsig); +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Remove the mean and check the data + +[mixedsig, mixedmean] = remmean(mixedsig); + +[Dim, NumOfSampl] = size(mixedsig); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Default values for optional parameters + +% All +verbose = 'on'; + +% Default values for 'pcamat' parameters +firstEig = 1; +lastEig = Dim; +interactivePCA = 'off'; + +% Default values for 'fpica' parameters +approach = 'defl'; +numOfIC = Dim; +g = 'pow3'; +finetune = 'off'; +a1 = 1; +a2 = 1; +myy = 1; +stabilization = 'off'; +epsilon = 0.0001; +maxNumIterations = 1000; +maxFinetune = 5; +initState = 'rand'; +guess = 0; +sampleSize = 1; +displayMode = 'off'; +displayInterval = 1; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Parameters for fastICA - i.e. this file + +b_verbose = 1; +jumpPCA = 0; +jumpWhitening = 0; +only = 3; +userNumOfIC = 0; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Read the optional parameters + +if (rem(length(varargin),2)==1) + error('Optional parameters should always go by pairs'); +else + for i=1:2:(length(varargin)-1) + if ~ischar (varargin{i}), + error (['Unknown type of optional parameter name (parameter' ... + ' names must be strings).']); + end + % change the value of parameter + switch lower (varargin{i}) + case 'stabilization' + stabilization = lower (varargin{i+1}); + case 'maxfinetune' + maxFinetune = varargin{i+1}; + case 'samplesize' + sampleSize = varargin{i+1}; + case 'verbose' + verbose = lower (varargin{i+1}); + % silence this program also + if strcmp (verbose, 'off'), b_verbose = 0; end + case 'firsteig' + firstEig = varargin{i+1}; + case 'lasteig' + lastEig = varargin{i+1}; + case 'interactivepca' + interactivePCA = lower (varargin{i+1}); + case 'approach' + approach = lower (varargin{i+1}); + case 'numofic' + numOfIC = varargin{i+1}; + % User has supplied new value for numOfIC. + % We'll use this information later on... + userNumOfIC = 1; + case 'g' + g = lower (varargin{i+1}); + case 'finetune' + finetune = lower (varargin{i+1}); + case 'a1' + a1 = varargin{i+1}; + case 'a2' + a2 = varargin{i+1}; + case {'mu', 'myy'} + myy = varargin{i+1}; + case 'epsilon' + epsilon = varargin{i+1}; + case 'maxnumiterations' + maxNumIterations = varargin{i+1}; + case 'initguess' + % no use setting 'guess' if the 'initState' is not set + initState = 'guess'; + guess = varargin{i+1}; + case 'displaymode' + displayMode = lower (varargin{i+1}); + case 'displayinterval' + displayInterval = varargin{i+1}; + case 'pcae' + % calculate if there are enought parameters to skip PCA + jumpPCA = jumpPCA + 1; + E = varargin{i+1}; + case 'pcad' + % calculate if there are enought parameters to skip PCA + jumpPCA = jumpPCA + 1; + D = varargin{i+1}; + case 'whitesig' + % calculate if there are enought parameters to skip PCA and whitening + jumpWhitening = jumpWhitening + 1; + whitesig = varargin{i+1}; + case 'whitemat' + % calculate if there are enought parameters to skip PCA and whitening + jumpWhitening = jumpWhitening + 1; + whiteningMatrix = varargin{i+1}; + case 'dewhitemat' + % calculate if there are enought parameters to skip PCA and whitening + jumpWhitening = jumpWhitening + 1; + dewhiteningMatrix = varargin{i+1}; + case 'only' + % if the user only wants to calculate PCA or... + switch lower (varargin{i+1}) + case 'pca' + only = 1; + case 'white' + only = 2; + case 'all' + only = 3; + end + + otherwise + % Hmmm, something wrong with the parameter string + error(['Unrecognized parameter: ''' varargin{i} '''']); + end; + end; +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% print information about data +if b_verbose + fprintf('Number of signals: %d\n', Dim); + fprintf('Number of samples: %d\n', NumOfSampl); +end + +% Check if the data has been entered the wrong way, +% but warn only... it may be on purpose + +if Dim > NumOfSampl + if b_verbose + fprintf('Warning: '); + fprintf('The signal matrix may be oriented in the wrong way.\n'); + fprintf('In that case transpose the matrix.\n\n'); + end +end + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Calculating PCA + +% We need the results of PCA for whitening, but if we don't +% need to do whitening... then we dont need PCA... +if jumpWhitening == 3 + if b_verbose, + fprintf ('Whitened signal and corresponding matrises supplied.\n'); + fprintf ('PCA calculations not needed.\n'); + end; +else + + % OK, so first we need to calculate PCA + % Check to see if we already have the PCA data + if jumpPCA == 2, + if b_verbose, + fprintf ('Values for PCA calculations supplied.\n'); + fprintf ('PCA calculations not needed.\n'); + end; + else + % display notice if the user entered one, but not both, of E and D. + if (jumpPCA > 0) & (b_verbose), + fprintf ('You must suply all of these in order to jump PCA:\n'); + fprintf ('''pcaE'', ''pcaD''.\n'); + end; + + % Calculate PCA + [E, D]=pcamat(mixedsig, firstEig, lastEig, interactivePCA, verbose); + end +end + +% skip the rest if user only wanted PCA +if only > 1 + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % Whitening the data + + % Check to see if the whitening is needed... + if jumpWhitening == 3, + if b_verbose, + fprintf ('Whitening not needed.\n'); + end; + else + + % Whitening is needed + % display notice if the user entered some of the whitening info, but not all. + if (jumpWhitening > 0) & (b_verbose), + fprintf ('You must suply all of these in order to jump whitening:\n'); + fprintf ('''whiteSig'', ''whiteMat'', ''dewhiteMat''.\n'); + end; + + % Calculate the whitening + [whitesig, whiteningMatrix, dewhiteningMatrix] = whitenv ... + (mixedsig, E, D, verbose); + end + +end % if only > 1 + +% skip the rest if user only wanted PCA and whitening +if only > 2 + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % Calculating the ICA + + % Check some parameters + % The dimension of the data may have been reduced during PCA calculations. + % The original dimension is calculated from the data by default, and the + % number of IC is by default set to equal that dimension. + + Dim = size(whitesig, 1); + + % The number of IC's must be less or equal to the dimension of data + if numOfIC > Dim + numOfIC = Dim; + % Show warning only if verbose = 'on' and user supplied a value for 'numOfIC' + if (b_verbose & userNumOfIC) + fprintf('Warning: estimating only %d independent components\n', numOfIC); + fprintf('(Can''t estimate more independent components than dimension of data)\n'); + end + end + + % Calculate the ICA with fixed point algorithm. + [A, W] = fpica (whitesig, whiteningMatrix, dewhiteningMatrix, approach, ... + numOfIC, g, finetune, a1, a2, myy, stabilization, epsilon, ... + maxNumIterations, maxFinetune, initState, guess, sampleSize, ... + displayMode, displayInterval, verbose); + + % Check for valid return + if ~isempty(W) + % Add the mean back in. + if b_verbose + fprintf('Adding the mean back to the data.\n'); + end + icasig = W * mixedsig + (W * mixedmean) * ones(1, NumOfSampl); + %icasig = W * mixedsig; + if b_verbose & ... + (max(abs(W * mixedmean)) > 1e-9) & ... + (strcmp(displayMode,'signals') | strcmp(displayMode,'on')) + fprintf('Note that the plots don''t have the mean added.\n'); + end + else + icasig = []; + end + +end % if only > 2 + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% The output depends on the number of output parameters +% and the 'only' parameter. + +if only == 1 % only PCA + Out1 = E; + Out2 = D; +elseif only == 2 % only PCA & whitening + if nargout == 2 + Out1 = whiteningMatrix; + Out2 = dewhiteningMatrix; + else + Out1 = whitesig; + Out2 = whiteningMatrix; + Out3 = dewhiteningMatrix; + end +else % ICA + if nargout == 2 + Out1 = A; + Out2 = W; + else + Out1 = icasig; + Out2 = A; + Out3 = W; + end +end diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/fasticag.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/fasticag.m new file mode 100644 index 0000000000000000000000000000000000000000..cf63ac1ff04219a1731de072aac6eabe63c85d34 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/fasticag.m @@ -0,0 +1,667 @@ +function fasticag(mixedsig, InitialGuess) +%FASTICAG - Fast Independent Component Analysis, the Graphical User Interface +% +% FASTICAG gives a graphical user interface for performing independent +% component analysis by the FastICA package. No arguments are +% necessary in the function call. +% +% Optional arguments can be given in the form: +% FASTICAG(mixedsig, initialGuess) where the matrix mixedsig contains the +% multidimensional signals as row vectors, and initialGuess gives the +% initial value for the mixing matrix used in the algorithm. +% +% FASTICA uses the fixed-point algorithm developed by Aapo Hyvarinen, +% see http://www.cis.hut.fi/projects/ica/fastica/. The Matlab package +% was programmed by Hugo Gavert, Jarmo Hurri, Jaakko Sarela, and Aapo +% Hyvarinen. +% +% +% See also FASTICA + +% @(#)$Id: fasticag.m,v 1.5 2005/10/19 13:05:34 jarmo Exp $ + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Global values + +% Handle to this main figure +global hf_FastICA_MAIN; + +% Check to see if GUI is already running +% Can't have more than one copy - otherwise the global +% variables and handles can get mixed up. +if ~isempty(hf_FastICA_MAIN) + error('FastICA GUI already running!'); +end + + +% Handles to other controls in this main window +global ht_FastICA_mixedStatus; +global ht_FastICA_dim; +global ht_FastICA_numOfSamp; +global ht_FastICA_newDim; +global ht_FastICA_whiteStatus; +global ht_FastICA_icaStatus; +global hpm_FastICA_approach; +global he_FastICA_numOfIC; +global hpm_FastICA_g; +global hpm_FastICA_stabilization; + +% These global variables are used to store all the values +% I used to use the 'UserData' field of components, but +% that got too complex, so I decided to put everything +% in global variables +global g_FastICA_mixedsig; +global g_FastICA_pca_D; +global g_FastICA_pca_E; +global g_FastICA_white_sig; +global g_FastICA_white_wm; +global g_FastICA_white_dwm; +global g_FastICA_ica_sig; +global g_FastICA_ica_A; +global g_FastICA_ica_W; +global g_FastICA_initGuess; +global g_FastICA_approach; +global g_FastICA_numOfIC; +global g_FastICA_g; +global g_FastICA_finetune; +global g_FastICA_a1; +global g_FastICA_a2; +global g_FastICA_myy; +global g_FastICA_stabilization; +global g_FastICA_epsilon; +global g_FastICA_maxNumIte; +global g_FastICA_maxFinetune; +global g_FastICA_sampleSize; +global g_FastICA_initState; +global g_FastICA_displayMo; +global g_FastICA_displayIn; +global g_FastICA_verbose; + +% initial values for them: +% All the initial values are set here - even for +% variables that are not used in this file + +if nargin < 2 + g_FastICA_initGuess = 1; + % The user didn't enter initial guess so we default + % back to random initial state. + g_FastICA_initState = 1; % see below for string values +else + g_FastICA_initGuess = InitialGuess; + % If initial guess was entered, then the user probably + % wan't to use it, eh? + g_FastICA_initState = 2; % see below for string values +end + +if nargin < 1 + g_FastICA_mixedsig = []; +else + g_FastICA_mixedsig = mixedsig; % We'll remove mean +end % the first time we + % use this. + +% Global variable for stopping the ICA calculations +global g_FastICA_interrupt; + +g_FastICA_pca_D = []; +g_FastICA_pca_E = []; +g_FastICA_white_sig = []; +g_FastICA_white_wm = []; +g_FastICA_white_dwm = []; +g_FastICA_ica_sig = []; +g_FastICA_ica_A = []; +g_FastICA_ica_W = []; +g_FastICA_approach = 1; % see below for string values +g_FastICA_numOfIC = 0; +g_FastICA_g = 1; % see below for string values +g_FastICA_finetune = 5; % see below for string values +g_FastICA_a1 = 1; +g_FastICA_a2 = 1; +g_FastICA_myy = 1; +g_FastICA_stabilization = 2; % see below for string values +g_FastICA_epsilon = 0.0001; +g_FastICA_maxNumIte = 1000; +g_FastICA_maxFinetune = 100; +g_FastICA_sampleSize = 1; +g_FastICA_displayMo = 1; % see below for string values +g_FastICA_displayIn = 1; +g_FastICA_verbose = 1; % see below for string values + +% These are regarded as constants and are used to store +% the strings for the popup menus the current value is +% seen in the variables above +% D - refers to strings that are displayed +% V - refers to string values that are used in FPICA +global c_FastICA_appr_strD; +global c_FastICA_appr_strV; +global c_FastICA_g1_strD; +global c_FastICA_g1_strV; +global c_FastICA_g2_strD; +global c_FastICA_g2_strV; +global c_FastICA_finetune_strD; +global c_FastICA_finetune_strV; +global c_FastICA_stabili_strD; +global c_FastICA_stabili_strV; +global c_FastICA_iSta_strD; +global c_FastICA_iSta_strV; +global c_FastICA_dMod_strD; +global c_FastICA_dMod_strV; +global c_FastICA_verb_strD; +global c_FastICA_verb_strV; + +% All the values for these are set here - even for +% variables that are not used in this file + +c_FastICA_appr_strD = 'deflation|symmetric'; +c_FastICA_appr_strV = ['defl';'symm']; +% The 'g1' and 'g2' below correspond to the values of approach (1 or 2) +% Deflation and Symmetric used to have a bit different selection +% of available nonlinearities. +c_FastICA_g1_strD = 'pow3|tanh|gauss|skew'; +c_FastICA_g1_strV = ['pow3';'tanh';'gaus';'skew']; +c_FastICA_g2_strD = 'pow3|tanh|gauss|skew'; +c_FastICA_g2_strV = ['pow3';'tanh';'gaus';'skew']; +c_FastICA_finetune_strD = 'pow3|tanh|gauss|skew|off'; +c_FastICA_finetune_strV = ['pow3';'tanh';'gaus';'skew';'off ']; +c_FastICA_stabili_strD = 'on|off'; +c_FastICA_stabili_strV = ['on ';'off']; +c_FastICA_iSta_strD = 'random|guess'; +c_FastICA_iSta_strV = ['rand ';'guess']; +c_FastICA_dMod_strD = 'signals|basis|filters|off'; +c_FastICA_dMod_strV = ['signals';'basis ';'filters';'off ']; +c_FastICA_verb_strD = 'on|off'; +c_FastICA_verb_strV = ['on ';'off']; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Configuration options +FIGURENAME = 'FastICA'; +FIGURETAG = 'f_FastICA'; +SCREENSIZE = get(0,'ScreenSize'); +FIGURESIZE = [round(0.1*SCREENSIZE(3)) (SCREENSIZE(4)-round(0.1*SCREENSIZE(4))-370) 530 370]; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Create the figure +a = figure('Color',[0.8 0.8 0.8], ... + 'PaperType','a4letter', ... + 'Name', FIGURENAME, ... + 'NumberTitle', 'off', ... + 'Tag', FIGURETAG, ... + 'Position', FIGURESIZE, ... + 'MenuBar', 'none'); +% Resizing has to be denied after the window has been created - +% otherwise the window shows only as a tiny window in Windows XP. +set (a, 'Resize', 'off'); + +hf_FastICA_MAIN = a; + +set(hf_FastICA_MAIN, 'HandleVisibility', 'callback'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% From here on it get's ugly as I have not had time to clean it up + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Create the frames +pos_l=2; +pos_w=FIGURESIZE(3)-4; +pos_h=FIGURESIZE(4)-4; +pos_t=FIGURESIZE(4)-2-pos_h; +h_f_background = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'Style','frame', ... + 'Tag','f_background'); + +pos_l=4; +pos_w=400; +pos_h=106; +pos_t=FIGURESIZE(4)-4-pos_h; +h_f_mixed = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'Style','frame', ... + 'Tag','f_mixed'); + +pos_h=90; +pos_t=FIGURESIZE(4)-(106+4+2)-pos_h; +h_f_white = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'Style','frame', ... + 'Tag','f_white'); + +pos_h=pos_t - 4 - 2; +pos_t=4; +h_f_ica = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'Style','frame', ... + 'Tag','f_ica'); + +pos_w=120; +pos_l=FIGURESIZE(3)-(pos_w+2+2); +pos_h=FIGURESIZE(4)-2*4; +pos_t=FIGURESIZE(4)-(4)-pos_h; +h_f_side = uicontrol('Parent',a, ... + 'BackgroundColor',[0.5 0.5 0.5], ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'Style','frame', ... + 'Tag','f_side'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Controls in f_mixed +bgc = get(h_f_mixed, 'BackgroundColor'); + +pos_vspace = 6; +pos_hspace = 6; + +pos_frame=get(h_f_mixed, 'Position'); +pos_l = pos_frame(1) + 6; +pos_h = 16; +pos_t = pos_frame(2) + pos_frame(4) - pos_h - 6; +pos_w = 150; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Mixed signals:', ... + 'FontWeight', 'bold', ... + 'Style','text', ... + 'Tag','t_mixed'); + +pos_l = pos_l + pos_w; +pos_w = 120; +ht_FastICA_mixedStatus = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Not loaded yet', ... + 'Style','text', ... + 'Tag','t_mixedstatus'); + +% Vähän väliä +pos_t = pos_t - 8; + +pos_l = pos_frame(1) + 6; +pos_t = pos_t - pos_h; +pos_w = 150; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Number of signals:', ... + 'Style','text', ... + 'Tag','t_2'); + +pos_l = pos_l + pos_w; +pos_w = 50; +ht_FastICA_dim = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','', ... + 'Style','text', ... + 'Tag','t_dim'); + +pos_l = pos_frame(1) + 6; +pos_t = pos_t - pos_h; +pos_w = 150; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Number of samples:', ... + 'Style','text', ... + 'Tag','t_3'); + +pos_l = pos_l + pos_w; +pos_w = 50; +ht_FastICA_numOfSamp = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','', ... + 'Style','text', ... + 'Tag','t_numOfSamp'); + + +% Buttons +pos_l = pos_frame(1) + pos_hspace; +pos_w = 110; +pos_h = 30; +pos_t = pos_frame(2) + pos_vspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_cb Transpose', ... + 'Interruptible', 'off', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Transpose', ... + 'Tag','b_Transpose'); + +pos_w = 130; +pos_l = pos_frame(1) + pos_frame(3) - pos_hspace - pos_w; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_cb ShowMixed', ... + 'Interruptible', 'off', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Plot data', ... + 'Tag','b_ShowMixed'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Controls in f_white +pos_frame=get(h_f_white, 'Position'); +pos_l = pos_frame(1) + 6; +pos_h = 16; +pos_t = pos_frame(2) + pos_frame(4) - pos_h - 6; +pos_w = 150; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Dimension control:', ... + 'FontWeight', 'bold', ... + 'Style','text', ... + 'Tag','t_white'); + +pos_l = pos_l + pos_w; +pos_w = 120; +ht_FastICA_whiteStatus = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','', ... + 'Style','text', ... + 'Tag','t_whiteStatus'); + +% Vähän väliä +pos_t = pos_t - 8; + +pos_l = pos_frame(1) + 6; +pos_t = pos_t - pos_h; +pos_w = 150; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Reduced dimension:', ... + 'Style','text', ... + 'Tag','t_4'); + +pos_l = pos_l + pos_w; +pos_w = 50; +ht_FastICA_newDim = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','', ... + 'Style','text', ... + 'Tag','t_newDim'); + + +% buttons + +pos_l = pos_frame(1) + pos_hspace; +pos_w = 110; +pos_h = 30; +pos_t = pos_frame(2) + pos_vspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_cb DoPCA', ... + 'Interruptible', 'off', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Reduce dim.', ... + 'Tag','b_DoPCA'); + +pos_l = pos_l + pos_w + pos_hspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_cb OrigDim', ... + 'Interruptible', 'off', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Original dim.', ... + 'Tag','b_OrigDim'); + +pos_w = 130; +pos_h = 30; +pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w; +pos_t = pos_frame(2) + 6; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_cb ShowWhite', ... + 'Interruptible', 'off', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Plot whitened', ... + 'Tag','b_ShowWhite'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Controls in f_ica +pos_frame=get(h_f_ica, 'Position'); +pos_l = pos_frame(1) + 6; +pos_h = 20; +pos_t = pos_frame(2) + pos_frame(4) - pos_h - 6; +pos_w = 150; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Fixed point ICA:', ... + 'FontWeight', 'bold', ... + 'Style','text', ... + 'Tag','t_white'); + +pos_l = pos_l + pos_w; +pos_w = 120; +ht_FastICA_icaStatus = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Not yet done', ... + 'Style','text', ... + 'Tag','t_icaStatus'); + +% Vähän väliä +pos_t = pos_t - 8; + +%pos_l = pos_frame(1) + 6; +pos_l = pos_frame(1) + 6 + 150; +pos_t = pos_t - pos_h; +%pos_w = 260; +pos_w = 120; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Approach:', ... + 'Style','text', ... + 'Tag','t_5'); + +pos_w = 100; +%pos_t = pos_t - 4; +pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w; +hpm_FastICA_approach = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'Callback','gui_cb ChangeApproach', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String',c_FastICA_appr_strD, ... + 'Style','popupmenu', ... + 'Tag','pm_approach', ... + 'Value',g_FastICA_approach); + +%pos_t = pos_t - 4; +%pos_l = pos_frame(1) + 6; +pos_l = pos_frame(1) + 6 + 150; +pos_t = pos_t - pos_h; +%pos_w = 260; +pos_w = 120; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Number of ICs:', ... + 'Style','text', ... + 'Tag','t_6'); + +pos_w = 100; +pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w; +he_FastICA_numOfIC = uicontrol('Parent',a, ... + 'BackgroundColor',[1 1 1], ... + 'Callback','gui_cb ChangeNumOfIC', ... + 'HorizontalAlignment','right', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','0', ... + 'Style','edit', ... + 'Tag','e_numOfIC'); + +%pos_t = pos_t - 4; +%pos_l = pos_frame(1) + 6; +pos_l = pos_frame(1) + 6 + 150; +pos_t = pos_t - pos_h; +%pos_w = 260; +pos_w = 120; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Nonlinearity (g):', ... + 'Style','text', ... + 'Tag','t_71'); + +%pos_t = pos_t - 4; +pos_w = 100; +pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w; +hpm_FastICA_g = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'Callback','gui_cb ChangeG', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String',c_FastICA_g1_strD, ... + 'Style','popupmenu', ... + 'Tag','pm_g', ... + 'Value',g_FastICA_g); + +%pos_t = pos_t - 4; +%pos_l = pos_frame(1) + 6; +pos_l = pos_frame(1) + 6 + 150; +pos_t = pos_t - pos_h; +%pos_w = 260; +pos_w = 120; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Stabilization:', ... + 'Style','text', ... + 'Tag','t_71a'); + +%pos_t = pos_t - 4; +pos_w = 100; +pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w; +hpm_FastICA_stabilization = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'Callback','gui_cb ChangeStab', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String',c_FastICA_stabili_strD, ... + 'Style','popupmenu', ... + 'Tag','pm_stab', ... + 'Value',g_FastICA_stabilization); + + + +pos_l = pos_frame(1) + pos_vspace; +pos_w = 110; +pos_h = 30; +pos_t = pos_frame(2) + pos_hspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_cb AdvOpt', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Adv. options >>', ... + 'Tag','b_advOpt'); + +pos_w = 130; +pos_h = 30; +pos_l = pos_frame(1) + pos_frame(3) - pos_vspace - pos_w; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_cb ShowICASig', ... + 'Interruptible', 'on', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Plot ICs', ... + 'Tag','b_ShowICASig'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Controls in f_side +pos_vspace = 6; +pos_hspace = 10; +pos_temp=get(h_f_side, 'Position'); +pos_l=pos_temp(1)+pos_hspace; +pos_w=100; +pos_h=30; +pos_t=pos_temp(2)+pos_temp(4)-pos_vspace-pos_h; + +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_cb LoadData', ... + 'Interruptible', 'off', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Load data', ... + 'Tag','b_LoadData'); + + +pos_t=pos_t-pos_h-pos_vspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_cb DoFPICA', ... + 'Interruptible', 'on', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Do ICA', ... + 'Tag','b_DoFPICA'); + +pos_t=pos_t-pos_h-pos_vspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_cb SaveData', ... + 'Interruptible', 'off', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Save results', ... + 'Tag','b_SaveData'); + +pos_t=pos_t-pos_h-pos_vspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_cb Quit', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Quit', ... + 'Tag','b_Quit'); + +pos_t=pos_t-pos_h-pos_vspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_cb Interrupt', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Interrupt', ... + 'Visible','off', ... + 'Tag','b_Interrupt'); + +pos_t = pos_frame(2) + pos_vspace + pos_h + pos_vspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_cb About', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','About...', ... + 'Tag','b_About'); + +pos_t = pos_frame(2) + pos_vspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_cb Help', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Help', ... + 'Tag','b_Help'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Do rest of the initialization... + gui_cb InitAll; + diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/fpica.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/fpica.m new file mode 100644 index 0000000000000000000000000000000000000000..325b60170c52cddd41d5fb6d001f361eda3109e6 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/fpica.m @@ -0,0 +1,905 @@ +function [A, W] = fpica(X, whiteningMatrix, dewhiteningMatrix, approach, ... + numOfIC, g, finetune, a1, a2, myy, stabilization, ... + epsilon, maxNumIterations, maxFinetune, initState, ... + guess, sampleSize, displayMode, displayInterval, ... + s_verbose); +%FPICA - Fixed point ICA. Main algorithm of FASTICA. +% +% [A, W] = fpica(whitesig, whiteningMatrix, dewhiteningMatrix, approach, +% numOfIC, g, finetune, a1, a2, mu, stabilization, epsilon, +% maxNumIterations, maxFinetune, initState, guess, sampleSize, +% displayMode, displayInterval, verbose); +% +% Perform independent component analysis using Hyvarinen's fixed point +% algorithm. Outputs an estimate of the mixing matrix A and its inverse W. +% +% whitesig :the whitened data as row vectors +% whiteningMatrix :can be obtained with function whitenv +% dewhiteningMatrix :can be obtained with function whitenv +% approach [ 'symm' | 'defl' ] :the approach used (deflation or symmetric) +% numOfIC [ 0 - Dim of whitesig ] :number of independent components estimated +% g [ 'pow3' | 'tanh' | :the nonlinearity used +% 'gaus' | 'skew' ] +% finetune [same as g + 'off'] :the nonlinearity used in finetuning. +% a1 :parameter for tuning 'tanh' +% a2 :parameter for tuning 'gaus' +% mu :step size in stabilized algorithm +% stabilization [ 'on' | 'off' ] :if mu < 1 then automatically on +% epsilon :stopping criterion +% maxNumIterations :maximum number of iterations +% maxFinetune :maximum number of iteretions for finetuning +% initState [ 'rand' | 'guess' ] :initial guess or random initial state. See below +% guess :initial guess for A. Ignored if initState = 'rand' +% sampleSize [ 0 - 1 ] :percentage of the samples used in one iteration +% displayMode [ 'signals' | 'basis' | :plot running estimate +% 'filters' | 'off' ] +% displayInterval :number of iterations we take between plots +% verbose [ 'on' | 'off' ] :report progress in text format +% +% EXAMPLE +% [E, D] = pcamat(vectors); +% [nv, wm, dwm] = whitenv(vectors, E, D); +% [A, W] = fpica(nv, wm, dwm); +% +% +% This function is needed by FASTICA and FASTICAG +% +% See also FASTICA, FASTICAG, WHITENV, PCAMAT + +% @(#)$Id: fpica.m,v 1.7 2005/06/16 12:52:55 jarmo Exp $ + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Global variable for stopping the ICA calculations from the GUI +global g_FastICA_interrupt; +if isempty(g_FastICA_interrupt) + clear global g_FastICA_interrupt; + interruptible = 0; +else + interruptible = 1; +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Default values + +if nargin < 3, error('Not enough arguments!'); end +[vectorSize, numSamples] = size(X); +if nargin < 20, s_verbose = 'on'; end +if nargin < 19, displayInterval = 1; end +if nargin < 18, displayMode = 'on'; end +if nargin < 17, sampleSize = 1; end +if nargin < 16, guess = 1; end +if nargin < 15, initState = 'rand'; end +if nargin < 14, maxFinetune = 100; end +if nargin < 13, maxNumIterations = 1000; end +if nargin < 12, epsilon = 0.0001; end +if nargin < 11, stabilization = 'on'; end +if nargin < 10, myy = 1; end +if nargin < 9, a2 = 1; end +if nargin < 8, a1 = 1; end +if nargin < 7, finetune = 'off'; end +if nargin < 6, g = 'pow3'; end +if nargin < 5, numOfIC = vectorSize; end % vectorSize = Dim +if nargin < 4, approach = 'defl'; end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Checking the data + +if ~isreal(X) + error('Input has an imaginary part.'); +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Checking the value for verbose + +switch lower(s_verbose) + case 'on' + b_verbose = 1; + case 'off' + b_verbose = 0; + otherwise + error(sprintf('Illegal value [ %s ] for parameter: ''verbose''\n', s_verbose)); +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Checking the value for approach + +switch lower(approach) + case 'symm' + approachMode = 1; + case 'defl' + approachMode = 2; + otherwise + error(sprintf('Illegal value [ %s ] for parameter: ''approach''\n', approach)); +end +if b_verbose, fprintf('Used approach [ %s ].\n', approach); end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Checking the value for numOfIC + +if vectorSize < numOfIC + error('Must have numOfIC <= Dimension!'); +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Checking the sampleSize +if sampleSize > 1 + sampleSize = 1; + if b_verbose + fprintf('Warning: Setting ''sampleSize'' to 1.\n'); + end +elseif sampleSize < 1 + if (sampleSize * numSamples) < 1000 + sampleSize = min(1000/numSamples, 1); + if b_verbose + fprintf('Warning: Setting ''sampleSize'' to %0.3f (%d samples).\n', ... + sampleSize, floor(sampleSize * numSamples)); + end + end +end +if b_verbose + if b_verbose & (sampleSize < 1) + fprintf('Using about %0.0f%% of the samples in random order in every step.\n',sampleSize*100); + end +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Checking the value for nonlinearity. + +switch lower(g) + case 'pow3' + gOrig = 10; + case 'tanh' + gOrig = 20; + case {'gaus', 'gauss'} + gOrig = 30; + case 'skew' + gOrig = 40; + otherwise + error(sprintf('Illegal value [ %s ] for parameter: ''g''\n', g)); +end +if sampleSize ~= 1 + gOrig = gOrig + 2; +end +if myy ~= 1 + gOrig = gOrig + 1; +end + +if b_verbose, + fprintf('Used nonlinearity [ %s ].\n', g); +end + +finetuningEnabled = 1; +switch lower(finetune) + case 'pow3' + gFine = 10 + 1; + case 'tanh' + gFine = 20 + 1; + case {'gaus', 'gauss'} + gFine = 30 + 1; + case 'skew' + gFine = 40 + 1; + case 'off' + if myy ~= 1 + gFine = gOrig; + else + gFine = gOrig + 1; + end + finetuningEnabled = 0; + otherwise + error(sprintf('Illegal value [ %s ] for parameter: ''finetune''\n', ... + finetune)); +end + +if b_verbose & finetuningEnabled + fprintf('Finetuning enabled (nonlinearity: [ %s ]).\n', finetune); +end + +switch lower(stabilization) + case 'on' + stabilizationEnabled = 1; + case 'off' + if myy ~= 1 + stabilizationEnabled = 1; + else + stabilizationEnabled = 0; + end + otherwise + error(sprintf('Illegal value [ %s ] for parameter: ''stabilization''\n', ... + stabilization)); +end + +if b_verbose & stabilizationEnabled + fprintf('Using stabilized algorithm.\n'); +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Some other parameters +myyOrig = myy; +% When we start fine-tuning we'll set myy = myyK * myy +myyK = 0.01; +% How many times do we try for convergence until we give up. +failureLimit = 5; + + +usedNlinearity = gOrig; +stroke = 0; +notFine = 1; +long = 0; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Checking the value for initial state. + +switch lower(initState) + case 'rand' + initialStateMode = 0; + case 'guess' + if size(guess,1) ~= size(whiteningMatrix,2) + initialStateMode = 0; + if b_verbose + fprintf('Warning: size of initial guess is incorrect. Using random initial guess.\n'); + end + else + initialStateMode = 1; + if size(guess,2) < numOfIC + if b_verbose + fprintf('Warning: initial guess only for first %d components. Using random initial guess for others.\n', size(guess,2)); + end + guess(:, size(guess, 2) + 1:numOfIC) = ... + rand(vectorSize,numOfIC-size(guess,2))-.5; + elseif size(guess,2)>numOfIC + guess=guess(:,1:numOfIC); + fprintf('Warning: Initial guess too large. The excess column are dropped.\n'); + end + if b_verbose, fprintf('Using initial guess.\n'); end + end + otherwise + error(sprintf('Illegal value [ %s ] for parameter: ''initState''\n', initState)); +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Checking the value for display mode. + +switch lower(displayMode) + case {'off', 'none'} + usedDisplay = 0; + case {'on', 'signals'} + usedDisplay = 1; + if (b_verbose & (numSamples > 10000)) + fprintf('Warning: Data vectors are very long. Plotting may take long time.\n'); + end + if (b_verbose & (numOfIC > 25)) + fprintf('Warning: There are too many signals to plot. Plot may not look good.\n'); + end + case 'basis' + usedDisplay = 2; + if (b_verbose & (numOfIC > 25)) + fprintf('Warning: There are too many signals to plot. Plot may not look good.\n'); + end + case 'filters' + usedDisplay = 3; + if (b_verbose & (vectorSize > 25)) + fprintf('Warning: There are too many signals to plot. Plot may not look good.\n'); + end + otherwise + error(sprintf('Illegal value [ %s ] for parameter: ''displayMode''\n', displayMode)); +end + +% The displayInterval can't be less than 1... +if displayInterval < 1 + displayInterval = 1; +end + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if b_verbose, fprintf('Starting ICA calculation...\n'); end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% SYMMETRIC APPROACH +if approachMode == 1, + + % set some parameters more... + usedNlinearity = gOrig; + stroke = 0; + notFine = 1; + long = 0; + + A = zeros(vectorSize, numOfIC); % Dewhitened basis vectors. + if initialStateMode == 0 + % Take random orthonormal initial vectors. + B = orth (randn (vectorSize, numOfIC)); + elseif initialStateMode == 1 + % Use the given initial vector as the initial state + B = whiteningMatrix * guess; + end + + BOld = zeros(size(B)); + BOld2 = zeros(size(B)); + + % This is the actual fixed-point iteration loop. + for round = 1:maxNumIterations + 1, + if round == maxNumIterations + 1, + fprintf('No convergence after %d steps\n', maxNumIterations); + fprintf('Note that the plots are probably wrong.\n'); + if ~isempty(B) + % Symmetric orthogonalization. + B = B * real(inv(B' * B)^(1/2)); + + W = B' * whiteningMatrix; + A = dewhiteningMatrix * B; + else + W = []; + A = []; + end + return; + end + + if (interruptible & g_FastICA_interrupt) + if b_verbose + fprintf('\n\nCalculation interrupted by the user\n'); + end + if ~isempty(B) + W = B' * whiteningMatrix; + A = dewhiteningMatrix * B; + else + W = []; + A = []; + end + return; + end + + + % Symmetric orthogonalization. + B = B * real(inv(B' * B)^(1/2)); + + % Test for termination condition. Note that we consider opposite + % directions here as well. + minAbsCos = min(abs(diag(B' * BOld))); + minAbsCos2 = min(abs(diag(B' * BOld2))); + + if (1 - minAbsCos < epsilon) + if finetuningEnabled & notFine + if b_verbose, fprintf('Initial convergence, fine-tuning: \n'); end; + notFine = 0; + usedNlinearity = gFine; + myy = myyK * myyOrig; + BOld = zeros(size(B)); + BOld2 = zeros(size(B)); + + else + if b_verbose, fprintf('Convergence after %d steps\n', round); end + + % Calculate the de-whitened vectors. + A = dewhiteningMatrix * B; + break; + end + elseif stabilizationEnabled + if (~stroke) & (1 - minAbsCos2 < epsilon) + if b_verbose, fprintf('Stroke!\n'); end; + stroke = myy; + myy = .5*myy; + if mod(usedNlinearity,2) == 0 + usedNlinearity = usedNlinearity + 1; + end + elseif stroke + myy = stroke; + stroke = 0; + if (myy == 1) & (mod(usedNlinearity,2) ~= 0) + usedNlinearity = usedNlinearity - 1; + end + elseif (~long) & (round>maxNumIterations/2) + if b_verbose, fprintf('Taking long (reducing step size)\n'); end; + long = 1; + myy = .5*myy; + if mod(usedNlinearity,2) == 0 + usedNlinearity = usedNlinearity + 1; + end + end + end + + BOld2 = BOld; + BOld = B; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % Show the progress... + if b_verbose + if round == 1 + fprintf('Step no. %d\n', round); + else + fprintf('Step no. %d, change in value of estimate: %.3g \n', round, 1 - minAbsCos); + end + end + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % Also plot the current state... + switch usedDisplay + case 1 + if rem(round, displayInterval) == 0, + % There was and may still be other displaymodes... + % 1D signals + icaplot('dispsig',(X'*B)'); + drawnow; + end + case 2 + if rem(round, displayInterval) == 0, + % ... and now there are :-) + % 1D basis + A = dewhiteningMatrix * B; + icaplot('dispsig',A'); + drawnow; + end + case 3 + if rem(round, displayInterval) == 0, + % ... and now there are :-) + % 1D filters + W = B' * whiteningMatrix; + icaplot('dispsig',W); + drawnow; + end + otherwise + end + + switch usedNlinearity + % pow3 + case 10 + B = (X * (( X' * B) .^ 3)) / numSamples - 3 * B; + case 11 + % optimoitu - epsilonin kokoisia eroja + % tämä on optimoitu koodi, katso vanha koodi esim. + % aikaisemmista versioista kuten 2.0 beta3 + Y = X' * B; + Gpow3 = Y .^ 3; + Beta = sum(Y .* Gpow3); + D = diag(1 ./ (Beta - 3 * numSamples)); + B = B + myy * B * (Y' * Gpow3 - diag(Beta)) * D; + case 12 + Xsub=X(:, getSamples(numSamples, sampleSize)); + B = (Xsub * (( Xsub' * B) .^ 3)) / size(Xsub,2) - 3 * B; + case 13 + % Optimoitu + Ysub=X(:, getSamples(numSamples, sampleSize))' * B; + Gpow3 = Ysub .^ 3; + Beta = sum(Ysub .* Gpow3); + D = diag(1 ./ (Beta - 3 * size(Ysub', 2))); + B = B + myy * B * (Ysub' * Gpow3 - diag(Beta)) * D; + + % tanh + case 20 + hypTan = tanh(a1 * X' * B); + B = X * hypTan / numSamples - ... + ones(size(B,1),1) * sum(1 - hypTan .^ 2) .* B / numSamples * ... + a1; + case 21 + % optimoitu - epsilonin kokoisia + Y = X' * B; + hypTan = tanh(a1 * Y); + Beta = sum(Y .* hypTan); + D = diag(1 ./ (Beta - a1 * sum(1 - hypTan .^ 2))); + B = B + myy * B * (Y' * hypTan - diag(Beta)) * D; + case 22 + Xsub=X(:, getSamples(numSamples, sampleSize)); + hypTan = tanh(a1 * Xsub' * B); + B = Xsub * hypTan / size(Xsub, 2) - ... + ones(size(B,1),1) * sum(1 - hypTan .^ 2) .* B / size(Xsub, 2) * a1; + case 23 + % Optimoitu + Y = X(:, getSamples(numSamples, sampleSize))' * B; + hypTan = tanh(a1 * Y); + Beta = sum(Y .* hypTan); + D = diag(1 ./ (Beta - a1 * sum(1 - hypTan .^ 2))); + B = B + myy * B * (Y' * hypTan - diag(Beta)) * D; + + % gauss + case 30 + U = X' * B; + Usquared=U .^ 2; + ex = exp(-a2 * Usquared / 2); + gauss = U .* ex; + dGauss = (1 - a2 * Usquared) .*ex; + B = X * gauss / numSamples - ... + ones(size(B,1),1) * sum(dGauss)... + .* B / numSamples ; + case 31 + % optimoitu + Y = X' * B; + ex = exp(-a2 * (Y .^ 2) / 2); + gauss = Y .* ex; + Beta = sum(Y .* gauss); + D = diag(1 ./ (Beta - sum((1 - a2 * (Y .^ 2)) .* ex))); + B = B + myy * B * (Y' * gauss - diag(Beta)) * D; + case 32 + Xsub=X(:, getSamples(numSamples, sampleSize)); + U = Xsub' * B; + Usquared=U .^ 2; + ex = exp(-a2 * Usquared / 2); + gauss = U .* ex; + dGauss = (1 - a2 * Usquared) .*ex; + B = Xsub * gauss / size(Xsub,2) - ... + ones(size(B,1),1) * sum(dGauss)... + .* B / size(Xsub,2) ; + case 33 + % Optimoitu + Y = X(:, getSamples(numSamples, sampleSize))' * B; + ex = exp(-a2 * (Y .^ 2) / 2); + gauss = Y .* ex; + Beta = sum(Y .* gauss); + D = diag(1 ./ (Beta - sum((1 - a2 * (Y .^ 2)) .* ex))); + B = B + myy * B * (Y' * gauss - diag(Beta)) * D; + + % skew + case 40 + B = (X * ((X' * B) .^ 2)) / numSamples; + case 41 + % Optimoitu + Y = X' * B; + Gskew = Y .^ 2; + Beta = sum(Y .* Gskew); + D = diag(1 ./ (Beta)); + B = B + myy * B * (Y' * Gskew - diag(Beta)) * D; + case 42 + Xsub=X(:, getSamples(numSamples, sampleSize)); + B = (Xsub * ((Xsub' * B) .^ 2)) / size(Xsub,2); + case 43 + % Uusi optimoitu + Y = X(:, getSamples(numSamples, sampleSize))' * B; + Gskew = Y .^ 2; + Beta = sum(Y .* Gskew); + D = diag(1 ./ (Beta)); + B = B + myy * B * (Y' * Gskew - diag(Beta)) * D; + + otherwise + error('Code for desired nonlinearity not found!'); + end + end + + + % Calculate ICA filters. + W = B' * whiteningMatrix; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % Also plot the last one... + switch usedDisplay + case 1 + % There was and may still be other displaymodes... + % 1D signals + icaplot('dispsig',(X'*B)'); + drawnow; + case 2 + % ... and now there are :-) + % 1D basis + icaplot('dispsig',A'); + drawnow; + case 3 + % ... and now there are :-) + % 1D filters + icaplot('dispsig',W); + drawnow; + otherwise + end +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% DEFLATION APPROACH +if approachMode == 2 + + B = zeros(vectorSize); + + % The search for a basis vector is repeated numOfIC times. + round = 1; + + numFailures = 0; + + while round <= numOfIC, + myy = myyOrig; + usedNlinearity = gOrig; + stroke = 0; + notFine = 1; + long = 0; + endFinetuning = 0; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % Show the progress... + if b_verbose, fprintf('IC %d ', round); end + + % Take a random initial vector of lenght 1 and orthogonalize it + % with respect to the other vectors. + if initialStateMode == 0 + w = randn (vectorSize, 1); + elseif initialStateMode == 1 + w=whiteningMatrix*guess(:,round); + end + w = w - B * B' * w; + w = w / norm(w); + + wOld = zeros(size(w)); + wOld2 = zeros(size(w)); + + % This is the actual fixed-point iteration loop. + % for i = 1 : maxNumIterations + 1 + i = 1; + gabba = 1; + while i <= maxNumIterations + gabba + if (usedDisplay > 0) + drawnow; + end + if (interruptible & g_FastICA_interrupt) + if b_verbose + fprintf('\n\nCalculation interrupted by the user\n'); + end + return; + end + + % Project the vector into the space orthogonal to the space + % spanned by the earlier found basis vectors. Note that we can do + % the projection with matrix B, since the zero entries do not + % contribute to the projection. + w = w - B * B' * w; + w = w / norm(w); + + if notFine + if i == maxNumIterations + 1 + if b_verbose + fprintf('\nComponent number %d did not converge in %d iterations.\n', round, maxNumIterations); + end + round = round - 1; + numFailures = numFailures + 1; + if numFailures > failureLimit + if b_verbose + fprintf('Too many failures to converge (%d). Giving up.\n', numFailures); + end + if round == 0 + A=[]; + W=[]; + end + return; + end + % numFailures > failurelimit + break; + end + % i == maxNumIterations + 1 + else + % if notFine + if i >= endFinetuning + wOld = w; % So the algorithm will stop on the next test... + end + end + % if notFine + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % Show the progress... + if b_verbose, fprintf('.'); end; + + + % Test for termination condition. Note that the algorithm has + % converged if the direction of w and wOld is the same, this + % is why we test the two cases. + if norm(w - wOld) < epsilon | norm(w + wOld) < epsilon + if finetuningEnabled & notFine + if b_verbose, fprintf('Initial convergence, fine-tuning: '); end; + notFine = 0; + gabba = maxFinetune; + wOld = zeros(size(w)); + wOld2 = zeros(size(w)); + usedNlinearity = gFine; + myy = myyK * myyOrig; + + endFinetuning = maxFinetune + i; + + else + numFailures = 0; + % Save the vector + B(:, round) = w; + + % Calculate the de-whitened vector. + A(:,round) = dewhiteningMatrix * w; + % Calculate ICA filter. + W(round,:) = w' * whiteningMatrix; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % Show the progress... + if b_verbose, fprintf('computed ( %d steps ) \n', i); end + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % Also plot the current state... + switch usedDisplay + case 1 + if rem(round, displayInterval) == 0, + % There was and may still be other displaymodes... + % 1D signals + temp = X'*B; + icaplot('dispsig',temp(:,1:numOfIC)'); + drawnow; + end + case 2 + if rem(round, displayInterval) == 0, + % ... and now there are :-) + % 1D basis + icaplot('dispsig',A'); + drawnow; + end + case 3 + if rem(round, displayInterval) == 0, + % ... and now there are :-) + % 1D filters + icaplot('dispsig',W); + drawnow; + end + end + % switch usedDisplay + break; % IC ready - next... + end + %if finetuningEnabled & notFine + elseif stabilizationEnabled + if (~stroke) & (norm(w - wOld2) < epsilon | norm(w + wOld2) < ... + epsilon) + stroke = myy; + if b_verbose, fprintf('Stroke!'); end; + myy = .5*myy; + if mod(usedNlinearity,2) == 0 + usedNlinearity = usedNlinearity + 1; + end + elseif stroke + myy = stroke; + stroke = 0; + if (myy == 1) & (mod(usedNlinearity,2) ~= 0) + usedNlinearity = usedNlinearity - 1; + end + elseif (notFine) & (~long) & (i > maxNumIterations / 2) + if b_verbose, fprintf('Taking long (reducing step size) '); end; + long = 1; + myy = .5*myy; + if mod(usedNlinearity,2) == 0 + usedNlinearity = usedNlinearity + 1; + end + end + end + + wOld2 = wOld; + wOld = w; + + switch usedNlinearity + % pow3 + case 10 + w = (X * ((X' * w) .^ 3)) / numSamples - 3 * w; + case 11 + EXGpow3 = (X * ((X' * w) .^ 3)) / numSamples; + Beta = w' * EXGpow3; + w = w - myy * (EXGpow3 - Beta * w) / (3 - Beta); + case 12 + Xsub=X(:,getSamples(numSamples, sampleSize)); + w = (Xsub * ((Xsub' * w) .^ 3)) / size(Xsub, 2) - 3 * w; + case 13 + Xsub=X(:,getSamples(numSamples, sampleSize)); + EXGpow3 = (Xsub * ((Xsub' * w) .^ 3)) / size(Xsub, 2); + Beta = w' * EXGpow3; + w = w - myy * (EXGpow3 - Beta * w) / (3 - Beta); + % tanh + case 20 + hypTan = tanh(a1 * X' * w); + w = (X * hypTan - a1 * sum(1 - hypTan .^ 2)' * w) / numSamples; + case 21 + hypTan = tanh(a1 * X' * w); + Beta = w' * X * hypTan; + w = w - myy * ((X * hypTan - Beta * w) / ... + (a1 * sum((1-hypTan .^2)') - Beta)); + case 22 + Xsub=X(:,getSamples(numSamples, sampleSize)); + hypTan = tanh(a1 * Xsub' * w); + w = (Xsub * hypTan - a1 * sum(1 - hypTan .^ 2)' * w) / size(Xsub, 2); + case 23 + Xsub=X(:,getSamples(numSamples, sampleSize)); + hypTan = tanh(a1 * Xsub' * w); + Beta = w' * Xsub * hypTan; + w = w - myy * ((Xsub * hypTan - Beta * w) / ... + (a1 * sum((1-hypTan .^2)') - Beta)); + % gauss + case 30 + % This has been split for performance reasons. + u = X' * w; + u2=u.^2; + ex=exp(-a2 * u2/2); + gauss = u.*ex; + dGauss = (1 - a2 * u2) .*ex; + w = (X * gauss - sum(dGauss)' * w) / numSamples; + case 31 + u = X' * w; + u2=u.^2; + ex=exp(-a2 * u2/2); + gauss = u.*ex; + dGauss = (1 - a2 * u2) .*ex; + Beta = w' * X * gauss; + w = w - myy * ((X * gauss - Beta * w) / ... + (sum(dGauss)' - Beta)); + case 32 + Xsub=X(:,getSamples(numSamples, sampleSize)); + u = Xsub' * w; + u2=u.^2; + ex=exp(-a2 * u2/2); + gauss = u.*ex; + dGauss = (1 - a2 * u2) .*ex; + w = (Xsub * gauss - sum(dGauss)' * w) / size(Xsub, 2); + case 33 + Xsub=X(:,getSamples(numSamples, sampleSize)); + u = Xsub' * w; + u2=u.^2; + ex=exp(-a2 * u2/2); + gauss = u.*ex; + dGauss = (1 - a2 * u2) .*ex; + Beta = w' * Xsub * gauss; + w = w - myy * ((Xsub * gauss - Beta * w) / ... + (sum(dGauss)' - Beta)); + % skew + case 40 + w = (X * ((X' * w) .^ 2)) / numSamples; + case 41 + EXGskew = (X * ((X' * w) .^ 2)) / numSamples; + Beta = w' * EXGskew; + w = w - myy * (EXGskew - Beta*w)/(-Beta); + case 42 + Xsub=X(:,getSamples(numSamples, sampleSize)); + w = (Xsub * ((Xsub' * w) .^ 2)) / size(Xsub, 2); + case 43 + Xsub=X(:,getSamples(numSamples, sampleSize)); + EXGskew = (Xsub * ((Xsub' * w) .^ 2)) / size(Xsub, 2); + Beta = w' * EXGskew; + w = w - myy * (EXGskew - Beta*w)/(-Beta); + + otherwise + error('Code for desired nonlinearity not found!'); + end + + % Normalize the new w. + w = w / norm(w); + i = i + 1; + end + round = round + 1; + end + if b_verbose, fprintf('Done.\n'); end + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % Also plot the ones that may not have been plotted. + if (usedDisplay > 0) & (rem(round-1, displayInterval) ~= 0) + switch usedDisplay + case 1 + % There was and may still be other displaymodes... + % 1D signals + temp = X'*B; + icaplot('dispsig',temp(:,1:numOfIC)'); + drawnow; + case 2 + % ... and now there are :-) + % 1D basis + icaplot('dispsig',A'); + drawnow; + case 3 + % ... and now there are :-) + % 1D filters + icaplot('dispsig',W); + drawnow; + otherwise + end + end +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% In the end let's check the data for some security +if ~isreal(A) + if b_verbose, fprintf('Warning: removing the imaginary part from the result.\n'); end + A = real(A); + W = real(W); +end + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Subfunction +% Calculates tanh simplier and faster than Matlab tanh. +function y=tanh(x) +y = 1 - 2 ./ (exp(2 * x) + 1); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function Samples = getSamples(max, percentage) +Samples = find(rand(1, max) < percentage); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_adv.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_adv.m new file mode 100644 index 0000000000000000000000000000000000000000..1f31689735c6e4ab9bcb119010eb5b753eb85d3e --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_adv.m @@ -0,0 +1,441 @@ +function gui_adv(x, y) +% +% This file is needed by FASTICAG + +% This is the advanced options -dialog + +% @(#)$Id: gui_adv.m,v 1.4 2004/07/27 13:09:26 jarmo Exp $ + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Global variables + +% Handle to the window +global hf_FastICA_AdvOpt; + +% Handles to some of the controls in window +global hpm_FastICA_finetune; +global he_FastICA_a1; +global he_FastICA_a2; +global he_FastICA_myy; +global he_FastICA_epsilon; +global he_FastICA_maxIterations; +global he_FastICA_maxFinetune; +global he_FastICA_sampleSize +global hpm_FastICA_initState; +global hb_FastICA_initGuess; +global ht_FastICA_initGuess; +global hpm_FastICA_displayMode; +global he_FastICA_displayInterval; +global hpm_FastICA_verbose; + +% Some of the main variables needed +global g_FastICA_initGuess; +global g_FastICA_finetune; +global g_FastICA_a1; +global g_FastICA_a2; +global g_FastICA_myy; +global g_FastICA_epsilon; +global g_FastICA_maxNumIte; +global g_FastICA_maxFinetune; +global g_FastICA_initState; +global g_FastICA_sampleSize; +global g_FastICA_displayMo; +global g_FastICA_displayIn; +global g_FastICA_verbose; + +global c_FastICA_appr_strD; +global c_FastICA_appr_strV; +global c_FastICA_finetune_strD; +global c_FastICA_finetune_strV; +global c_FastICA_iSta_strD; +global c_FastICA_iSta_strV; +global c_FastICA_dMod_strD; +global c_FastICA_dMod_strV; +global c_FastICA_verb_strD; +global c_FastICA_verb_strV; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Configuration options +FIGURENAME = 'FastICA: advanced options'; +FIGURETAG = 'f_FastICAAdvOpt'; +FIGURESIZE = [x y 450 280]; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Check to see if this figure is already open - it should not! +% Can't have more than one copy - otherwise the global +% variables and handles can get mixed up. +if ~isempty(findobj('Tag',FIGURETAG)) + error('Error: advanced options dialog already open!'); +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Initialize some of the controls' values + +% Did we already load some initial guess +pm_initState_Value = g_FastICA_initState; +if isempty(g_FastICA_initGuess) | (g_FastICA_initGuess == 1) + t_initGuess_String = 'Not loaded'; +else + t_initGuess_String = 'Loaded'; +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Create the figure +a = figure('Color',[0.8 0.8 0.8], ... + 'PaperType','a4letter', ... + 'Name', FIGURENAME, ... + 'NumberTitle', 'off', ... + 'Tag', FIGURETAG, ... + 'Position', FIGURESIZE, ... + 'MenuBar', 'none'); +set (a, 'Resize', 'off'); + +hf_FastICA_AdvOpt = a; + +set(hf_FastICA_AdvOpt, 'HandleVisibility', 'callback'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% From here on it get's ugly as I have not had time to clean it up + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Create the frames +pos_l=2; +pos_w=FIGURESIZE(3)-4; +pos_h=FIGURESIZE(4)-4; +pos_t=2; +h_f_adv_background = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'Style','frame', ... + 'Tag','f_adv_background'); + +pos_w=120; +pos_l=FIGURESIZE(3)-(pos_w+2+2); +pos_h=FIGURESIZE(4)-2*4; +pos_t=4; +h_f_adv_side = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'Style','frame', ... + 'Tag','f_adv_side'); + +pos_l=4; +pos_w=FIGURESIZE(3)-8-pos_w-2; +pos_h=FIGURESIZE(4)-8; +pos_t=4; +h_f_advopt = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'Style','frame', ... + 'Tag','f_advopt'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Controls in f_advopt +bgc = get(h_f_advopt, 'BackgroundColor'); + +pos_w1=230; +pos_w2=70; + +pos_frame=get(h_f_advopt, 'Position'); +pos_h = 20; +pos_t = pos_frame(2) + pos_frame(4) - pos_h - 6; +pos_l = pos_frame(1) + 6; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w1 pos_h], ... + 'String','Fine-tune (g)', ... + 'Style','text', ... + 'Tag','t_727'); + +pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2; +hpm_FastICA_finetune = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'Position',[pos_l pos_t pos_w2 pos_h], ... + 'String',c_FastICA_finetune_strD, ... + 'Style','popupmenu', ... + 'Tag','pm_finetune', ... + 'Value',g_FastICA_finetune); + +pos_t = pos_t - pos_h; +pos_l = pos_frame(1) + 6; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w1 pos_h], ... + 'String','Parameter a1 (g = ''tanh'')', ... + 'Style','text', ... + 'Tag','t_22'); + +pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2; +he_FastICA_a1 = uicontrol('Parent',a, ... + 'BackgroundColor',[1 1 1], ... + 'HorizontalAlignment','right', ... + 'Callback','gui_advc Checka1', ... + 'Position',[pos_l pos_t pos_w2 pos_h], ... + 'String',num2str(g_FastICA_a1), ... + 'Style','edit', ... + 'Tag','e_a1'); + +pos_t = pos_t - pos_h; +pos_l = pos_frame(1) + 6; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w1 pos_h], ... + 'String','Parameter a2 (g = ''gauss'')', ... + 'Style','text', ... + 'Tag','t_222'); + +pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2; +he_FastICA_a2 = uicontrol('Parent',a, ... + 'BackgroundColor',[1 1 1], ... + 'HorizontalAlignment','right', ... + 'Callback','gui_advc Checka2', ... + 'Position',[pos_l pos_t pos_w2 pos_h], ... + 'String',num2str(g_FastICA_a2), ... + 'Style','edit', ... + 'Tag','e_a2'); + +pos_t = pos_t - pos_h; +pos_l = pos_frame(1) + 6; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w1 pos_h], ... + 'String','mu (step size)', ... + 'Style','text', ... + 'Tag','t_223'); + +pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2; +he_FastICA_myy = uicontrol('Parent',a, ... + 'BackgroundColor',[1 1 1], ... + 'HorizontalAlignment','right', ... + 'Callback','gui_advc CheckMyy', ... + 'Position',[pos_l pos_t pos_w2 pos_h], ... + 'String',num2str(g_FastICA_myy), ... + 'Style','edit', ... + 'Tag','e_myy'); + +pos_t = pos_t - pos_h; +pos_l = pos_frame(1) + 6; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w1 pos_h], ... + 'String','epsilon (stopping criterion)', ... + 'Style','text', ... + 'Tag','t_23'); + +pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2; +he_FastICA_epsilon = uicontrol('Parent',a, ... + 'BackgroundColor',[1 1 1], ... + 'HorizontalAlignment','right', ... + 'Position',[pos_l pos_t pos_w2 pos_h], ... + 'String',num2str(g_FastICA_epsilon), ... + 'Style','edit', ... + 'Tag','e_epsilon'); + +pos_t = pos_t - pos_h; +pos_l = pos_frame(1) + 6; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w1 pos_h], ... + 'String','Maximum number of iterations', ... + 'Style','text', ... + 'Tag','t_24'); + +pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2; +he_FastICA_maxIterations = uicontrol('Parent',a, ... + 'BackgroundColor',[1 1 1], ... + 'HorizontalAlignment','right', ... + 'Position',[pos_l pos_t pos_w2 pos_h], ... + 'String',num2str(g_FastICA_maxNumIte), ... + 'Style','edit', ... + 'Tag','e_maxIterations'); + +pos_t = pos_t - pos_h; +pos_l = pos_frame(1) + 6; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w1 pos_h], ... + 'String','Maximum iterations in fine-tuning', ... + 'Style','text', ... + 'Tag','t_2412'); + +pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2; +he_FastICA_maxFinetune = uicontrol('Parent',a, ... + 'BackgroundColor',[1 1 1], ... + 'HorizontalAlignment','right', ... + 'Position',[pos_l pos_t pos_w2 pos_h], ... + 'String',num2str(g_FastICA_maxFinetune), ... + 'Style','edit', ... + 'Tag','e_maxFinetune'); + +pos_t = pos_t - pos_h; +pos_l = pos_frame(1) + 6; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w1 pos_h], ... + 'String','Sample size (proportion)', ... + 'Style','text', ... + 'Tag','t_224'); + +pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2; +he_FastICA_sampleSize = uicontrol('Parent',a, ... + 'BackgroundColor',[1 1 1], ... + 'HorizontalAlignment','right', ... + 'Callback','gui_advc CheckSampleSize', ... + 'Position',[pos_l pos_t pos_w2 pos_h], ... + 'String',num2str(g_FastICA_sampleSize), ... + 'Style','edit', ... + 'Tag','e_sampleSize'); + +pos_t = pos_t - pos_h; +pos_l = pos_frame(1) + 6; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w1 pos_h], ... + 'String','Initial state', ... + 'Style','text', ... + 'Tag','t_25'); + +pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2; +hpm_FastICA_initState = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'Position',[pos_l pos_t pos_w2 pos_h], ... + 'String',c_FastICA_iSta_strD, ... + 'Style','popupmenu', ... + 'Tag','pm_initState', ... + 'Value',pm_initState_Value); + +pos_t = pos_t - pos_h; +pos_l = pos_frame(1) + 6; +hb_FastICA_initGuess = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_advc loadGuess', ... + 'Position',[pos_l pos_t (pos_w1-60) pos_h], ... + 'String','Load initial guess', ... + 'UserData', g_FastICA_initGuess, ... + 'Tag','b_LoadGuess'); + +pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2; +ht_FastICA_initGuess = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[(pos_l) pos_t (pos_w2) pos_h], ... + 'String',t_initGuess_String, ... + 'Style','text', ... + 'Tag','t_initGuess'); + +pos_t = pos_t - pos_h; +pos_l = pos_frame(1) + 6; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w1 pos_h], ... + 'String','Display mode', ... + 'Style','text', ... + 'Tag','t_27'); + +pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2; +hpm_FastICA_displayMode = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'Position',[pos_l pos_t pos_w2 pos_h], ... + 'String',c_FastICA_dMod_strD, ... + 'Style','popupmenu', ... + 'Tag','pm_displayMode', ... + 'Value',g_FastICA_displayMo); + +pos_t = pos_t - pos_h; +pos_l = pos_frame(1) + 6; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w1 pos_h], ... + 'String','Iterations between displays', ... + 'Style','text', ... + 'Tag','t_28'); + +pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2; +he_FastICA_displayInterval = uicontrol('Parent',a, ... + 'BackgroundColor',[1 1 1], ... + 'HorizontalAlignment','right', ... + 'Position',[pos_l pos_t pos_w2 pos_h], ... + 'String',num2str(g_FastICA_displayIn), ... + 'Style','edit', ... + 'Tag','e_displayInterval'); + +pos_t = pos_t - pos_h; +pos_l = pos_frame(1) + 6; +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w1 pos_h], ... + 'String','Verbose', ... + 'Style','text', ... + 'Tag','t_29'); + +pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2; +hpm_FastICA_verbose = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'Position',[pos_l pos_t pos_w2 pos_h], ... + 'String',c_FastICA_verb_strD, ... + 'Style','popupmenu', ... + 'Tag','pm_verbose', ... + 'Value',g_FastICA_verbose); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Controls in f_adv_side +pos_vspace = 6; +pos_hspace = 10; +pos_frame = get(h_f_adv_side, 'Position'); +pos_w = 100; +pos_h = 30; +pos_l = pos_frame(1) + pos_hspace; +pos_t = pos_frame(2) + pos_frame(4) - pos_h - pos_vspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_advc OK', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','OK', ... + 'Tag','b_advOK'); + +pos_t=pos_t-pos_h-pos_vspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_advc Cancel', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Cancel', ... + 'Tag','b_advCancel'); + +pos_t=pos_t-pos_h-pos_vspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_advc Default', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Default', ... + 'Tag','b_advDefault'); + +pos_t=pos_t-pos_h-pos_vspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_advc Apply', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Apply', ... + 'Tag','b_advApply'); + +pos_t = pos_frame(2) + pos_vspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_advc Help', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Help', ... + 'Tag','b_advHelp'); + diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_advc.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_advc.m new file mode 100644 index 0000000000000000000000000000000000000000..86a74fc61dee66af779a12d7a541c36dc49b42e5 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_advc.m @@ -0,0 +1,256 @@ +function gui_advc (action) +% +% This file is needed by FASTICAG + +% This file holds the callbacks for advanced options -dialog + +% @(#)$Id: gui_advc.m,v 1.3 2003/09/08 11:28:58 jarmo Exp $ + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Global variables + +% Handle to the window +global hf_FastICA_AdvOpt; + +% Handles to some of the controls in window +global hpm_FastICA_finetune; +global he_FastICA_a1; +global he_FastICA_a2; +global he_FastICA_myy; +global he_FastICA_epsilon; +global he_FastICA_maxIterations; +global he_FastICA_maxFinetune; +global he_FastICA_sampleSize; +global hpm_FastICA_initState; +global hb_FastICA_initGuess; +global ht_FastICA_initGuess; +global hpm_FastICA_displayMode; +global he_FastICA_displayInterval; +global hpm_FastICA_verbose; + +% Needed handles to the main window +global hf_FastICA_MAIN; +global ht_FastICA_icaStatus; +global ht_FastICA_numOfSamp; +global hpm_FastICA_stabilization; + +% Some of the main variables needed +global g_FastICA_initGuess; +global g_FastICA_numOfIC; +global g_FastICA_finetune; +global g_FastICA_a1; +global g_FastICA_a2; +global g_FastICA_myy; +global g_FastICA_epsilon; +global g_FastICA_maxNumIte; +global g_FastICA_maxFinetune; +global g_FastICA_initState; +global g_FastICA_sampleSize; +global g_FastICA_displayMo; +global g_FastICA_displayIn; +global g_FastICA_verbose; + +global c_FastICA_iSta_strV; + +% What is the load type of load dialog +global g_FastICA_loadType; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% This should not take long... +watchonInFigure = watchon; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +switch action +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'Checka1' + + e_a1_val = str2num(get(he_FastICA_a1, 'String')); + if e_a1_val <= 0 + set(he_FastICA_a1, 'String', '0.1'); + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'Checka2' + + e_a2_val = str2num(get(he_FastICA_a2, 'String')); + if e_a2_val <= 0 + set(he_FastICA_a2, 'String', '0.1'); + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'CheckMyy' + + e_myy_val = str2num(get(he_FastICA_myy, 'String')); + if e_myy_val <= 0 + set(he_FastICA_myy, 'String', '0.1'); + elseif e_myy_val > 1 + set(he_FastICA_myy, 'String', '1'); + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'CheckSampleSize' + + e_sampleSize_val = str2num(get(he_FastICA_sampleSize, 'String')); + if e_sampleSize_val > 1 + set(he_FastICA_sampleSize, 'String', '1'); + else + numOfSamp = str2num(get(ht_FastICA_numOfSamp, 'String')); + if numOfSamp < 1000 + set(he_FastICA_sampleSize, 'String', '1'); + fprintf('Can''t reduce sample size. Already less than 1000 samples.\n'); + elseif (e_sampleSize_val * numOfSamp) < 1000 + fprintf('Can''t reduce sample size to less than 1000 samples.\n'); + set(he_FastICA_sampleSize, 'String', sprintf('%0.3f',1000/numOfSamp)); + end + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'loadGuess' + + handle = findobj('Tag','f_FastICALoad'); % Check if the window is already + if isempty(handle) % open. If not then open it. + pos = get(hf_FastICA_MAIN, 'Position'); + gui_l(pos(1), pos(2)); + else + if strcmp(g_FastICA_loadType, 'guess') % Check if it was the same load + figure(handle); % window. If it wasn't then + else % close the other window first + close(handle); % and then open the load window + fprintf('''Load data'' -dialog closed!\n'); + pos = get(hf_FastICA_MAIN, 'Position'); + gui_l(pos(1), pos(2)); + end + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'OK' + + gui_advc Apply; + + close(hf_FastICA_AdvOpt); + + % Use return to avoid reaching the watchoff statement at the end + % (There used to be a 'break' statement here, but it resulted in + % errors in more recent version of Matlab -- jarmo) + return; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'Apply' + + newValues = 0; + + val = g_FastICA_finetune; + g_FastICA_finetune = get(hpm_FastICA_finetune, 'Value'); + if (g_FastICA_finetune ~= val) + newValues = 1; + end + + val = g_FastICA_a1; + g_FastICA_a1 = str2num(get(he_FastICA_a1, 'String')); + if (g_FastICA_a1 ~= val) + newValues = 1; + end + + val = g_FastICA_a2; + g_FastICA_a2 = str2num(get(he_FastICA_a2, 'String')); + if (g_FastICA_a2 ~= val) + newValues = 1; + end + + val = g_FastICA_myy; + g_FastICA_myy = str2num(get(he_FastICA_myy, 'String')); + if (g_FastICA_myy ~= val) + newValues = 1; + end + + % If myy < 1 then will use stabilazed code, and we don't care + % about the parameter stabilization :-) + if (g_FastICA_myy == 1) + set(hpm_FastICA_stabilization, 'Enable', 'on'); + else + set(hpm_FastICA_stabilization, 'Enable', 'off'); + end + + val = g_FastICA_epsilon; + g_FastICA_epsilon = str2num(get(he_FastICA_epsilon, 'String')); + if (g_FastICA_epsilon ~= val) + newValues = 1; + end + + val = g_FastICA_maxNumIte; + g_FastICA_maxNumIte = str2num(get(he_FastICA_maxIterations, 'String')); + if (g_FastICA_maxNumIte ~= val) + newValues = 1; + end + + val = g_FastICA_maxFinetune; + g_FastICA_maxFinetune = str2num(get(he_FastICA_maxFinetune, 'String')); + if (g_FastICA_maxFinetune ~= val) + newValues = 1; + end + + val = g_FastICA_sampleSize; + g_FastICA_sampleSize = str2num(get(he_FastICA_sampleSize, 'String')); + if (g_FastICA_sampleSize ~= val) + newValues = 1; + end + + val = g_FastICA_initState; + g_FastICA_initState = get(hpm_FastICA_initState, 'Value'); + if (g_FastICA_initState ~= val) + newValues = 1; + end + + val = g_FastICA_initGuess; + g_FastICA_initGuess = get(hb_FastICA_initGuess, 'UserData'); + if min(size(val) == size(g_FastICA_initGuess)) == 0 + newValues = 1; + else + if (g_FastICA_initGuess ~= val) + newValues = 1; + end + end + + g_FastICA_displayMo = get(hpm_FastICA_displayMode, 'Value'); + g_FastICA_displayIn = str2num(get(he_FastICA_displayInterval, 'String')); + g_FastICA_verbose = get(hpm_FastICA_verbose, 'Value'); + + if newValues == 1 + gui_cb NullICA; + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'Cancel' + + close(hf_FastICA_AdvOpt); + + % Use return to avoid reaching the watchoff statement at the end + % (There used to be a 'break' statement here, but it resulted in + % errors in more recent version of Matlab -- jarmo) + return; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'Default' + + % set default values to controls + set(hpm_FastICA_finetune, 'Value',5); + set(he_FastICA_a1, 'String','1'); + set(he_FastICA_a2, 'String','1'); + set(he_FastICA_myy, 'String','1'); + set(he_FastICA_epsilon, 'String','0.0001'); + set(he_FastICA_maxIterations, 'String','1000'); + set(he_FastICA_sampleSize, 'String','1'); + set(hpm_FastICA_initState, 'Value',1); + set(hpm_FastICA_displayMode, 'Value',1); + set(he_FastICA_displayInterval, 'String','1'); + set(hpm_FastICA_verbose, 'Value',1); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'Help' + + gui_help('gui_advc'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +end % switch + +watchoff (watchonInFigure); \ No newline at end of file diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_cb.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_cb.m new file mode 100644 index 0000000000000000000000000000000000000000..80a2ee03d6d84899d86e1524e9f01cacc7fa0015 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_cb.m @@ -0,0 +1,581 @@ +function gui_cb(action) +% +% This file is used by FASTICAG + +% This file holds the callbacks to the main window + +% @(#)$Id: gui_cb.m,v 1.5 2003/09/10 10:33:41 jarmo Exp $ + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Global variables + +% Handle to the main figure +global hf_FastICA_MAIN; + +% Handles for needed controls in main figure; +global ht_FastICA_mixedStatus; +global ht_FastICA_dim; +global ht_FastICA_numOfSamp; +global ht_FastICA_newDim; +global ht_FastICA_whiteStatus; +global ht_FastICA_icaStatus; +global hpm_FastICA_approach; +global he_FastICA_numOfIC; +global hpm_FastICA_g; +global hpm_FastICA_stabilization; + +% Main values are stored here +global g_FastICA_mixedsig; +global g_FastICA_mixedmean; +global g_FastICA_pca_D; +global g_FastICA_pca_E; +global g_FastICA_white_sig; +global g_FastICA_white_wm; +global g_FastICA_white_dwm; +global g_FastICA_ica_sig; +global g_FastICA_ica_A; +global g_FastICA_ica_W; +global g_FastICA_initGuess; +global g_FastICA_approach; +global g_FastICA_numOfIC; +global g_FastICA_g; +global g_FastICA_finetune; +global g_FastICA_a1; +global g_FastICA_a2; +global g_FastICA_myy; +global g_FastICA_stabilization; +global g_FastICA_epsilon; +global g_FastICA_maxNumIte; +global g_FastICA_maxFinetune; +global g_FastICA_sampleSize; +global g_FastICA_initState; +global g_FastICA_displayMo; +global g_FastICA_displayIn; +global g_FastICA_verbose; + +% String values are here +global c_FastICA_appr_strV; +global c_FastICA_g1_strD; +global c_FastICA_g1_strV; +global c_FastICA_g2_strD; +global c_FastICA_g2_strV; +global c_FastICA_finetune_strD; +global c_FastICA_finetune_strV; +global c_FastICA_stabili_strV; +global c_FastICA_iSta_strV; +global c_FastICA_dMod_strV; +global c_FastICA_verb_strV; + +% What is the load type of load dialog +global g_FastICA_loadType; + +% Global variable for stopping the ICA calculations +global g_FastICA_interrupt; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% What ever we do, it will take some time... not much, but some :-) +watchonInFigure = watchon; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +switch action +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'InitAll' + + % If the data is already loaded, then get the information from data + % and show to the user (also set g_FastICA_numOfIC) + if ~isempty(g_FastICA_mixedsig) + set(ht_FastICA_mixedStatus, 'String', ''); + [dim, numofsamp] = size(g_FastICA_mixedsig); + set(ht_FastICA_dim, 'String', int2str(dim)); + set(ht_FastICA_numOfSamp, 'String', int2str(numofsamp)); + set(ht_FastICA_newDim, 'String', int2str(dim)); + set(he_FastICA_numOfIC, 'String', int2str(dim)); + g_FastICA_numOfIC = dim; + g_FastICA_mixedmean = []; + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'LoadData' + + handle = findobj('Tag','f_FastICALoad'); % Check if the window is already + if isempty(handle) % open. If not then open it. + pos = get(hf_FastICA_MAIN, 'Position'); + % Based on the feedback obtained from some users, it seems + % that at least in some systems, pos can sometimes be empty. A + % similar check is done a few lines below. + if ~isempty (pos), + gui_l(pos(1), pos(2)); + else + gui_l (0, 0); + end + else + if strcmp(g_FastICA_loadType, 'data') % Check if it was the same load + figure(handle); % window. If it wasn't then + else % close the other window first + close(handle); % and then open the load window + fprintf('''Load initial guess'' -dialog closed!\n'); + pos = get(hf_FastICA_MAIN, 'Position'); + if ~isempty (pos), + gui_l(pos(1), pos(2)); + else + gui_l (0, 0); + end + end + end + + % gui_cb NewData; - is called from the load function if not canceled... + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'NewData' + + % New data is loaded or the old data changed. We need to find out + % somethings about the new data... and do some other stuff also... + [dim, numofsamp] = size(g_FastICA_mixedsig); + set(ht_FastICA_dim, 'String', dim); + set(ht_FastICA_newDim, 'String', dim); + set(ht_FastICA_numOfSamp, 'String', numofsamp); + set(he_FastICA_numOfIC, 'String', int2str(dim)); + + g_FastICA_numOfIC = dim; % Default for numOfIC = the new dimension + % PCA needs to be calculated again. + g_FastICA_pca_E = []; % We use this to check if PCA is calculated + gui_cb NullWhite; % Whitening needs to be done again also + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'NullWhite' + + % Whitening needs to done again next time it's needed + g_FastICA_white_sig = []; % We use this to check if whitening is calculated + gui_cb NullICA; % The FPICA must be calculated again + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'NullICA' + + % If IC's are needed they have to bee calculated again + g_FastICA_ica_sig = []; % We use this to check if FPICA is calculated + set(ht_FastICA_icaStatus,'String','Not yet done'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'Transpose' + + if isempty(g_FastICA_mixedmean) + g_FastICA_mixedsig = g_FastICA_mixedsig'; + else + g_FastICA_mixedsig = (g_FastICA_mixedsig + ... + g_FastICA_mixedmean * ... + ones(1,size(g_FastICA_mixedsig, 2)))'; + g_FastICA_mixedmean = []; + end + gui_cb NewData; % Data has been changed + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'DoPCA' + + if ~isempty(g_FastICA_mixedsig) + % We'll remove mean of the data here also just in case... + if isempty(g_FastICA_mixedmean) + [g_FastICA_mixedsig, g_FastICA_mixedmean] = remmean(g_FastICA_mixedsig); + end + + % Do PCA interactively: ask the user for eigenvalues + [g_FastICA_pca_E, g_FastICA_pca_D] = pcamat(g_FastICA_mixedsig, ... + 0, 0, 'gui', ... + deblank(c_FastICA_verb_strV(g_FastICA_verbose,:))); + + newdim = size(g_FastICA_pca_D, 1); + set(ht_FastICA_newDim, 'String', int2str(newdim)); + set(he_FastICA_numOfIC, 'String', int2str(newdim)); + g_FastICA_numOfIC = newdim; + gui_cb NullWhite; % Whitening needs to be done again also + % but we'll do it when it's needed. + else + fprintf('Data not loaded yet!\n\n'); + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'OrigDim' + + gui_cb NewData; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'ShowMixed' + + if ~isempty(g_FastICA_mixedsig) + handle = findobj('Tag','f_FastICA_mix'); % Check if the window is already + if isempty(handle) % open. If not then open it. + figure('Tag', 'f_FastICA_mix', ... + 'Name', 'FastICA: Plot data', ... + 'NumberTitle', 'off'); + else + figure(handle); + clf; % clear the figure for next plots + end + if isempty(g_FastICA_mixedmean) + icaplot('dispsig',g_FastICA_mixedsig, 0, 0, 0, 'Mixed signals'); + else + icaplot('dispsig',g_FastICA_mixedsig + g_FastICA_mixedmean * ... + ones(1, size(g_FastICA_mixedsig, 2)), 0, 0, 0, 'Mixed signals'); + end + else + fprintf('Data not loaded yet!\n\n'); + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'ShowWhite' + + if ~isempty(g_FastICA_mixedsig) + if isempty(g_FastICA_white_sig) % if whitening is not done, we need to + gui_cb Whiten; % do it before we can display the + end % whitened signals + + handle = findobj('Tag','f_FastICA_white'); % Check if the window is already + if isempty(handle) % open. If not then open it. + figure('Tag', 'f_FastICA_white', ... + 'Name', 'FastICA: Plot whitened', ... + 'NumberTitle', 'off'); + else + figure(handle); + clf; % clear the figure for next plots + end + icaplot('dispsig',g_FastICA_white_sig,0,0,0,'Whitened signals'); + else + fprintf('Data not loaded yet!\n\n'); + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'Whiten' + + set(ht_FastICA_whiteStatus,'String','Computing...'); + + % If PCA is not calculated, we'll have to calculate it now, + % we'll do it without guestions - we don't reduce the dimension + % here - but PCAMAT might reduce the dimension automatically. + if isempty(g_FastICA_pca_E) + % We'll remove mean of the data here also just in case... + if isempty(g_FastICA_mixedmean) + [g_FastICA_mixedsig, g_FastICA_mixedmean] = remmean(g_FastICA_mixedsig); + end + + [g_FastICA_pca_E, g_FastICA_pca_D] = pcamat(g_FastICA_mixedsig, 1, ... + size(g_FastICA_mixedsig, ... + 1), 'off', ... + deblank(c_FastICA_verb_strV(g_FastICA_verbose,:))); + + % Check if the dimension was reduced automatically + newdim = size(g_FastICA_pca_D, 1); + set(ht_FastICA_newDim, 'String', int2str(newdim)); + % Check if the numOfIC now has illegal value entered + % We do that by telling the program that there is new value + % entered for NumOfIC. + gui_cb ChangeNumOfIC; + end + + % And now we can calculate whitening... + [g_FastICA_white_sig, g_FastICA_white_wm, g_FastICA_white_dwm] = ... + whitenv(g_FastICA_mixedsig, g_FastICA_pca_E, g_FastICA_pca_D, deblank(c_FastICA_verb_strV(g_FastICA_verbose,:))); + + set (ht_FastICA_whiteStatus,'String',''); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'ChangeApproach' + + % Get the old value for g + eval(['g_str = c_FastICA_g' int2str(g_FastICA_approach) '_strV;']); + old_g = deblank(g_str(g_FastICA_g,:)); + + % Get and set the new value for approach + g_FastICA_approach = get(hpm_FastICA_approach, 'Value'); + + % The possible values for g depend on the value of approach... + eval(['g_str = c_FastICA_g' int2str(g_FastICA_approach) '_strD;']); + set(hpm_FastICA_g, 'String', g_str); + + % Match the old g value from the new g values so that if the + % old_g can be found from the new values (anywhere), then set new g + % to that value, and if it's not found then set the new value to 1. + match = 0; + eval(['g_str = c_FastICA_g' int2str(g_FastICA_approach) '_strV;']); + for i=1:size(g_str,1) + if strcmp(old_g, deblank(g_str(i,:))) + match = i; + end + end + if match == 0 + match = 1; % the old g is not availabe anymore, set g = 1. + end + g_FastICA_g = match; + set(hpm_FastICA_g, 'Value', match); + + gui_cb NullICA; % The options are changed so we must calculate ICA again + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'ChangeNumOfIC' + + % Get the new value... and store it later on after some checks + numofic = str2num(get(he_FastICA_numOfIC, 'String')); + + % The number of IC can't be less than 1 or more than the reduced dimension. + numoficmax = str2num(get(ht_FastICA_newDim, 'String')); + if numofic < 1 + set(he_FastICA_numOfIC, 'String', '1'); + g_FastICA_numOfIC = 1; + elseif numofic > numoficmax + set(he_FastICA_numOfIC, 'String', int2str (numoficmax)); + g_FastICA_numOfIC = numoficmax; + else + g_FastICA_numOfIC = numofic; + end + + gui_cb NullICA; % The options are changed so we must calculate ICA again + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'ChangeG' + + % Get the new value for g. + g_FastICA_g = get(hpm_FastICA_g, 'Value'); + + gui_cb NullICA; % The options are changed so we must calculate ICA again + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'ChangeStab' + + % Get the new value for g. + g_FastICA_stabilization = get(hpm_FastICA_stabilization, 'Value'); + + gui_cb NullICA; % The options are changed so we must calculate ICA again + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'AdvOpt' + + handle = findobj('Tag','f_FastICAAdvOpt'); + if isempty(handle) % Check to see if the window is + pos = get(hf_FastICA_MAIN, 'Position'); % already open... + if ~isempty (pos), + gui_adv(pos(1), pos(2)); + else + gui_adv(0, 0); + end + else + figure(handle) + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'ShowICASig' + + if ~isempty(g_FastICA_mixedsig) + % If the IC's are not already calculated, we'll do it now + if isempty(g_FastICA_ica_sig) + gui_cb DoFPICA; + end + + % The signals may have been already displaued by the FPICA function + % BUT the FPICA may also have shown either the basis of the filters + % so the signals still need to be shown - besides the mean was added + % in only later after FPICA + + % Also notice that in this version if there was something wrong in FPICA + % Then the results are []. - We don't try to plot them! + if ~isempty(g_FastICA_ica_sig') + handle = findobj('Tag','f_FastICA_ica'); % Check if the window is already + if isempty(handle) % open. If not then open it. + figure('Tag', 'f_FastICA_ica', ... + 'Name', 'FastICA: Plot ICs', ... + 'NumberTitle', 'off'); + else + figure(handle); + clf; % clear the figure for next plots + end + + icaplot('dispsig', g_FastICA_ica_sig, 0, ... + 0, 0, 'Independent components'); + end + else + fprintf('Data not loaded yet!\n\n'); + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'DoFPICA' + + gui_cb DisableButtons; + g_FastICA_interrupt = 0; + + if ~isempty(g_FastICA_mixedsig) + if isempty(g_FastICA_white_sig) % We need the whitened signal here + gui_cb Whiten; + end + + set(ht_FastICA_icaStatus,'String','Computing...'); + + % The possible values for g depend on approach + eval(['g_str = c_FastICA_g' int2str(g_FastICA_approach) '_strV;']); + + % We'll contruct a command string which we'll later on evaluate... + % This is where the Fixed point algorithm is used. + command_str = ['[g_FastICA_ica_A,g_FastICA_ica_W]=' ... + 'fpica(g_FastICA_white_sig,' ... + 'g_FastICA_white_wm,' ... + 'g_FastICA_white_dwm,' ... + '''' deblank(c_FastICA_appr_strV(g_FastICA_approach,:)) ... + ''',' ... + 'g_FastICA_numOfIC,' ... + '''' deblank(g_str(g_FastICA_g,:)) ''',' ... + '''' ... + deblank(c_FastICA_finetune_strV(g_FastICA_finetune,:)) ... + ''',' ... + 'g_FastICA_a1,' ... + 'g_FastICA_a2,' ... + 'g_FastICA_myy,' ... + '''' ... + deblank(c_FastICA_stabili_strV(g_FastICA_stabilization,:)) ... + ''',' ... + 'g_FastICA_epsilon,' ... + 'g_FastICA_maxNumIte,' ... + 'g_FastICA_maxFinetune,' ... + '''' deblank(c_FastICA_iSta_strV(g_FastICA_initState,:)) ... + ''',' ... + 'g_FastICA_initGuess,' ... + 'g_FastICA_sampleSize,' ... + '''' deblank(c_FastICA_dMod_strV(g_FastICA_displayMo,:)) ... + ''',' ... + 'g_FastICA_displayIn,' ... + '''' deblank(c_FastICA_verb_strV(g_FastICA_verbose,:)) ... + ''');']; + + + % If the user wants to plot while computing... + % let's at least plot it to the right figure then + if ~strcmp(deblank(c_FastICA_dMod_strV(g_FastICA_displayMo,:)),'off') + handle = findobj('Tag','f_FastICA_ica'); % Check if the window is already + if isempty(handle) % open. If not then open it. + figure('Tag', 'f_FastICA_ica', ... + 'Name', 'FastICA: Plot ICs', ... + 'NumberTitle', 'off'); + else + figure(handle); + clf; % clear the figure for next plots + end + end + + % ... and so let's do it... + eval(command_str); + + % Also notice that in this version if there was something wrong in FPICA + % Then the results are []. + if ~isempty(g_FastICA_ica_W) + % Add the mean back in. + g_FastICA_ica_sig = g_FastICA_ica_W * g_FastICA_mixedsig ... + + (g_FastICA_ica_W * g_FastICA_mixedmean) ... + * ones(1,size(g_FastICA_mixedsig, 2)); + set (ht_FastICA_icaStatus,'String','Done'); + else + gui_cb NullICA; % set icasig=[] and do what ever needs to be done then + end + + if ~(g_FastICA_interrupt) + gui_cb EnableButtons; + end + else + fprintf('Data not loaded yet!\n\n'); + end + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'Interrupt' + g_FastICA_interrupt = 1; + set(ht_FastICA_icaStatus,'String','Interrupted'); + gui_cb EnableButtons; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'DisableButtons' + set(findobj('Tag','b_Transpose'),'Enable','off'); + set(findobj('Tag','b_ShowMixed'),'Enable','off'); + set(findobj('Tag','b_DoPCA'),'Enable','off'); + set(findobj('Tag','b_OrigDim'),'Enable','off'); + set(findobj('Tag','b_ShowWhite'),'Enable','off'); + set(findobj('Tag','b_advOpt'),'Enable','off'); + set(findobj('Tag','b_ShowICASig'),'Enable','off'); + set(findobj('Tag','b_LoadData'),'Enable','off'); + set(findobj('Tag','b_DoFPICA'),'Enable','off'); + set(findobj('Tag','b_SaveData'),'Enable','off'); + set(findobj('Tag','b_Quit'),'Enable','off'); + set(findobj('Tag','b_Interrupt'),'Visible','on'); + drawnow; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'EnableButtons' + set(findobj('Tag','b_Transpose'),'Enable','on'); + set(findobj('Tag','b_ShowMixed'),'Enable','on'); + set(findobj('Tag','b_DoPCA'),'Enable','on'); + set(findobj('Tag','b_OrigDim'),'Enable','on'); + set(findobj('Tag','b_ShowWhite'),'Enable','on'); + set(findobj('Tag','b_advOpt'),'Enable','on'); + set(findobj('Tag','b_ShowICASig'),'Enable','on'); + set(findobj('Tag','b_LoadData'),'Enable','on'); + set(findobj('Tag','b_DoFPICA'),'Enable','on'); + set(findobj('Tag','b_SaveData'),'Enable','on'); + set(findobj('Tag','b_Quit'),'Enable','on'); + set(findobj('Tag','b_Interrupt'),'Visible','off'); + drawnow; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'SaveData' + + handle = findobj('Tag','f_FastICASave'); % Check if the window is already + if isempty(handle) % open. If not then open it. + pos = get(hf_FastICA_MAIN, 'Position'); + if ~isempty (pos), + gui_s(pos(1), pos(2)); + else + gui_s(0, 0); + end + else + figure(handle); % window. If it wasn't then + end + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'Quit' + + % We'll close the other dialogs if they are open. + Tags = ['f_FastICALoad ' + 'f_FastICAAdvOpt' + 'f_FastICASave ' + 'f_FastICA_mix ' + 'f_FastICA_white' + 'f_FastICA_ica ']; + for i=1:size(Tags,1) + handle = findobj('Tag', deblank(Tags(i,:))); + if ~isempty(handle) + close(handle); + end + end + + % Close this window + close(hf_FastICA_MAIN); + + % Clear the used global variables. + gui_cg; + + % Use return to avoid reaching the watchoff statement at the end + % (There used to be a 'break' statement here, but it resulted in + % errors in more recent version of Matlab -- jarmo) + return; + % ... and we're done. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'About' + + gui_help('gui_cb_about'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'Help' + + gui_help('gui_cb_help'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +end % switch + +watchoff (watchonInFigure); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_cg.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_cg.m new file mode 100644 index 0000000000000000000000000000000000000000..e66cf81c69ab06a0a34f5bf49814b68e806b3874 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_cg.m @@ -0,0 +1,84 @@ +function gui_cg() +% +% This function is needed by FASTICAG + +% This file just removes the global variables +% that are used in FASTICAG from the memory + +% @(#)$Id: gui_cg.m,v 1.2 2003/04/05 14:23:57 jarmo Exp $ + +clear global c_FastICA_appr_strD; +clear global c_FastICA_appr_strV; +clear global c_FastICA_dMod_strD; +clear global c_FastICA_dMod_strV; +clear global c_FastICA_finetune_strD; +clear global c_FastICA_finetune_strV; +clear global c_FastICA_g1_strD; +clear global c_FastICA_g1_strV; +clear global c_FastICA_g2_strD; +clear global c_FastICA_g2_strV; +clear global c_FastICA_iSta_strD; +clear global c_FastICA_iSta_strV; +clear global c_FastICA_stabili_strD; +clear global c_FastICA_stabili_strV; +clear global c_FastICA_verb_strD; +clear global c_FastICA_verb_strV; +clear global g_FastICA_a1; +clear global g_FastICA_a2; +clear global g_FastICA_approach; +clear global g_FastICA_displayIn; +clear global g_FastICA_displayMo; +clear global g_FastICA_epsilon; +clear global g_FastICA_finetune; +clear global g_FastICA_g; +clear global g_FastICA_ica_A; +clear global g_FastICA_ica_W; +clear global g_FastICA_ica_sig; +clear global g_FastICA_initGuess; +clear global g_FastICA_initState; +clear global g_FastICA_interrupt; +clear global g_FastICA_loadType; +clear global g_FastICA_maxFinetune; +clear global g_FastICA_maxNumIte; +clear global g_FastICA_mixedmean; +clear global g_FastICA_mixedsig; +clear global g_FastICA_myy; +clear global g_FastICA_numOfIC; +clear global g_FastICA_pca_D; +clear global g_FastICA_pca_E; +clear global g_FastICA_sampleSize; +clear global g_FastICA_stabilization; +clear global g_FastICA_verbose; +clear global g_FastICA_white_dwm; +clear global g_FastICA_white_sig; +clear global g_FastICA_white_wm; +clear global hb_FastICA_initGuess; +clear global he_FastICA_a1; +clear global he_FastICA_a2; +clear global he_FastICA_displayInterval; +clear global he_FastICA_epsilon; +clear global he_FastICA_file; +clear global he_FastICA_suffix; +clear global he_FastICA_maxFinetune; +clear global he_FastICA_maxIterations; +clear global he_FastICA_myy; +clear global he_FastICA_numOfIC; +clear global he_FastICA_sampleSize; +clear global hf_FastICA_MAIN; +clear global hf_FastICA_AdvOpt; +clear global hf_FastICA_Load; +clear global hf_FastICA_Save; +clear global hpm_FastICA_approach; +clear global hpm_FastICA_displayMode; +clear global hpm_FastICA_finetune; +clear global hpm_FastICA_g; +clear global hpm_FastICA_initState; +clear global hpm_FastICA_stabilization; +clear global hpm_FastICA_verbose; +clear global ht_FastICA_dim; +clear global ht_FastICA_icaStatus; +clear global ht_FastICA_initGuess; +clear global ht_FastICA_mixedStatus; +clear global ht_FastICA_newDim; +clear global ht_FastICA_numOfSamp; +clear global ht_FastICA_whiteStatus; diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_help.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_help.m new file mode 100644 index 0000000000000000000000000000000000000000..da88f3a18173ea5f071aef50fcbd02502f3e0de6 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_help.m @@ -0,0 +1,224 @@ +function gui_help(which_help) +% +% Used by FASTICAG + +% All the help texts and title used by GUI are stored here. +% Make changes here. +% Also displays the helpwindow with the selected text + +% @(#)$Id: gui_help.m,v 1.6 2005/10/19 13:05:34 jarmo Exp $ + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +switch which_help +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'pcamat' + + helptitle = 'FastICA: Reduce dimension'; + helptext=[ ... + 'You may reduce the dimension of the data by selecting only the ' + 'subspace corresponding to certain eigenvalues of the covariance ' + 'matrix of the data. Give the indices of the first and last ' + 'eigenvalues (sorted in descending order) to be included (all ' + 'eigenvalues in between will be included as well). The eigenvalues ' + 'and their indices can be seen in the graphical plot now on the ' + 'screen. The heights of the bars give the eigenvalues, with indices ' + 'below. ' + ' ' + 'For example, give ''1'' and ''n'' if you want to reduce the dimension ' + 'to n by principal component analysis, which means discarding the ' + 'subspaces corresponding to the smallest eigenvalues. Such a ' + 'dimension reduction may reduce noise and improve the performance of' + 'ICA. ']; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'gui_cb_about' + + helptitle='About FastICA'; + helptext =[ ... + 'FastICA for Matlab 7.x and 6.x ' + 'Version 2.5, October 19 2005 ' + 'Copyright (c) Hugo Gävert, Jarmo Hurri, Jaakko Särelä, and Aapo Hyvärinen.' + ' ' + 'For more information please see: ' + 'http://www.cis.hut.fi/projects/ica/fastica/ ']; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'gui_cb_help' + + helptitle='FastICA GUI'; + helptext = [... + 'Basic function: ' + ' ' + '- Click LOAD DATA and give the name of the variable that contains ' + ' the data. ' + ' ' + '- Click DO ICA to perform the analysis. ' + ' ' + '- Click SAVE RESULTS to store the results for future use. ' + ' ' + 'Options: ' + ' ' + 'If the input matrix contains the signals as column vectors instead of ' + 'row vectors, click on TRANSPOSE to transpose the data matrix. ' + ' ' + 'Click on PLOT DATA to see the data as 1-D time signals. ' + ' ' + 'Clicking REDUCE DIM gives you a graphical plot of the eigenvalue ' + 'structure of the covariance matrix of the data. You can then reduce ' + 'the dimension of the data by retaining only the subspaces corresponding to ' + 'the largest (or smallest) eigenvalues (i.e. variances). To undo this ' + 'operation click ORIGINAL DIM. You can plot the whitened (preprocessed ' + 'data) by PLOT WHITENED. ' + ' ' + 'Click on DO ICA to perform independent component analysis. ' + 'Clicking on PLOT ICS has the same effect, except that DO ICA forces ' + 'recomputation of ICA. ' + ' ' + 'You can choose the decorrelation approach by the ''Approach'' drop-down menu:' + 'deflation means that the independent components are estimated ' + 'one-by-one, whereas in the symmetric approach they are estimated in ' + 'parallel. You can now choose the number of independent components to be ' + 'estimated in both deflation and symmetric approaches. ' + ' ' + 'You have a choice of three nonlinearities: ' + ' ' + '''pow3'' (default) : g(u)=u^3 ' + '''tanh'' : g(u)=tanh(u) ' + '''gauss'' : g(u)=u*exp(-u^2/2) ' + '''skew'' : g(u)=u^2 ' + ' ' + 'For example, you could choose approach=''symmetric'' and nonlinearity=''tanh'' ' + 'to perform maximum likelihood ICA estimation for supergaussian data. ' + ' ' + 'If the algorithm does not seem to converge, you can use the stabilized ' + 'version of the fixed-point algorithm. To use the stabilized version, ' + 'choose ''on'' from the drop-down menu ''Stabilization''. ' + 'If you have specified a value less than 1 for the parameter ''mu'' from ' + 'the ''Advanced Options'' menu then the ''Stabilization'' drop-down menu is ' + 'not active. This is because if the parameter ''mu'' is less than 1 then the ' + 'program will use the stabilized code. Please see the help for ' + 'Advanced Options for more information about stabilization. ' + ' ' + 'The ADVANCED OPTIONS menu has its own HELP button. ' + ' ' + 'During computations, an INTERRUPT button appears. Clicking the button ' + 'interrupts the computations. ']; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'gui_advc' + + helptitle='FastICA GUI: Advanced options'; + helptext = [... + 'Advanced options: ' + ' ' + 'In some cases, it may be desired to improve the statistical ' + 'performance of the algorithm by using a fine-tuning procedure. This ' + 'means that after (initial) convergence, the algorithm is run ' + '(possibly) with a different nonlinearity, and using a smaller step ' + 'size and the stabilized version of the fixed-point algorithm. ' + 'You can specify the nonlinearity that will then be used with the ' + 'parameter ''Finetune''. If you set the the finetuning to ''off'', then the' + 'fine-tuning won''t be done. ' + ' ' + 'You can also fine-tune the nonlinearities used in the fixed-point ' + 'algorithm. ' + 'The nonlinearities tanh and gauss contain parameters a1 and a2, so ' + 'that the nonlinearities are in fact defined as: ' + '''tanh'' : g(u)=tanh(a1*u) ' + '''gauss'' : g(u)=u*exp(-a2*u^2/2) ' + 'The default values of a1 and a2 are 1, in which case they effectively ' + 'disappear from the definitions. ' + ' ' + 'If the algorithm does not seem to converge, you can use the stabilized' + 'version of the fixed-point algorithm. There are two ways of doing ' + 'this. The first one is to explicitly specify the value of the step ' + 'size parameter ''mu''. The default value is 1. Choosing a value that ' + 'is smaller than 1 implies that the computations are made using the ' + 'stabilized fixed-point algorithm. The second way to use the stabilized' + 'version is simpler: choose ''on'' in the drop-down menu ''stabilization'' ' + '(on the main menu page). Then the value of mu will be changed ' + 'automatically during the ICA calculations. If the program senses that ' + 'the algorithm is stuck between two points, it will halve the value of ' + 'mu (.5 * mu) for duration of one round. (This is called a ''stroke.''). ' + 'Also if there is no convergence before half of the maximum number of ' + 'iterations has been reached then the mu will be halved for the rest ' + 'of the rounds. ' + ' ' + 'The parameter ''epsilon'' is used to decide if the algorithm has ' + 'converged. A larger epsilon makes the convergence test less strict. ' + 'Note that if you use finetuning or stabilization, epsilon may need to ' + 'be reduced accordingly. ' + ' ' + '''Maximum number of iterations'' gives the absolute maximum of ' + 'iterations used in the estimation procedure. In the deflation ' + 'approach, this is iterations per component. ' + ' ' + 'You can input the ''Initial state'' of the algorithm, i.e. the initial ' + 'value for A. Choose ''guess'' in the drop-down menu ''Initial state'', ' + 'click on ''Load Initial guess'', and give the name of the variable in ' + 'Matlab workspace that contains the initial value. ' + ' ' + 'In the drop-down menu ''Display mode'' you can choose if the results are' + 'plotted during computations. You may wish to switch this off ' + 'especially if you have lots of data which takes a long time to plot. ' + '''Iteration between displays'' tells how often the running estimates of ' + 'the independent components are plotted: A value of 1 means after every' + 'iteration. ' + ' ' + 'If the data vector is very long (more than 10 000 points), it may be ' + 'advisable to use only a part of the data at every iteration. The ' + 'option ''Sample size'' allows you to give the proportion (0-1) of the ' + 'data that is used at every step. The sample is chosen randomly at ' + 'every step. ' + ' ' + 'Click on DEFAULT to return to default values for all advanced options.' + 'You can make the new values take effect without closing the window by ' + 'clicking APPLY. ']; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'gui_lc_data' + + helptitle='FastICA GUI: Load data'; + helptext = [... + 'Input the name of the variable in Matlab workspace that contains the ' + 'data. The data must be in a single matrix, each row (or column) giving' + 'the values of one signal. If the signals are in column vectors, click ' + 'TRANSPOSE after loading the data to transpose the data matrix. ' + ' ' + 'If the data is in a file, load it to Matlab workspace first. ']; + +case 'gui_lc_guess' + + helptitle='FastICA GUI: Load guess'; + helptext = [... + 'Input the name of the variable in Matlab workspace that contains the' + 'initial value for the mixing matrix A, and click OK. If the initial ' + 'value is in a file, load it to Matlab workspace first. ']; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'gui_sc' + + helptitle='FastICA GUI: Save results'; + helptext = [... + 'The results will be saved as variables in Matlab workspace. ' + 'You give a suffix that identifies the variables. For example, if you ' + 'give ''_FASTICA'', the results will be stored in the following variables:' + ' ' + 'W_FASTICA : estimate of the separating matrix ' + 'A_FASTICA : estimate of the mixing matrix ' + 'IC_FASTICA : estimated independent components (row vectors) ' + ' ' + 'Additional results related to preprocessing: ' + 'D_FASTICA and E_FASTICA : give the eigenvalue decomposition of the ' + ' covariance matrix ' + 'whiteningMatrix_FASTICA : matrix performing whitening and dimension ' + ' reduction ' + 'dewhiteningMatrix_FASTICA : the pseudoinverse of the whitening matrix ' + 'whitesig_FASTICA : whitened (i.e. preprocessed) signals. ']; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +end + +helpwin(helptext, helptitle); \ No newline at end of file diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_l.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_l.m new file mode 100644 index 0000000000000000000000000000000000000000..be9e3e12bc024618f259c213ce53127397917b86 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_l.m @@ -0,0 +1,180 @@ +function gui_l (x, y) +% +% This file is needed by FASTICAG + +% The load dialog for loading new data +% and new initial guess. + +% @(#)$Id: gui_l.m,v 1.4 2004/07/27 13:09:26 jarmo Exp $ + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Global variables + +% Handle to the window +global hf_FastICA_Load; + +% Handles to some of the controls in window +global he_FastICA_file; + +% What is the load type of load dialog +global g_FastICA_loadType; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Configuration options +FIGURENAME = 'FastICA: Load'; +FIGURETAG = 'f_FastICALoad'; +FIGURESIZE = [x y 450 150]; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Check to see if this figure is already open - it should not! +% Can't have more than one copy - otherwise the global +% variables and handles can get mixed up. +if ~isempty(findobj('Tag',FIGURETAG)) + error('Error: load dialog already open!'); +end + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Initialize some of the controls' values + +% What are we loading - who is calling? +caller = get(gcf, 'CurrentObject'); + +switch get(caller, 'Tag') + case 'b_LoadData' % Do we load new data... + loadString = 'Load data from variable in Matlab.'; + g_FastICA_loadType = 'data'; + FIGURENAME = 'FastICA: Load data'; + + case 'b_LoadGuess' % ... or new initial guess? + loadString = 'Load initial guess for mixing matrix A from variable in Matlab.'; + g_FastICA_loadType = 'guess'; + FIGURENAME = 'FastICA: Load initial guess'; +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Create the figure +a = figure('Color',[0.8 0.8 0.8], ... + 'PaperType','a4letter', ... + 'Name', FIGURENAME, ... + 'NumberTitle', 'off', ... + 'Tag', FIGURETAG, ... + 'Position', FIGURESIZE, ... + 'MenuBar', 'none'); +set (a, 'Resize', 'off'); + +hf_FastICA_Load = a; + +set(hf_FastICA_Load, 'HandleVisibility', 'callback'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% From here on it get's ugly as I have not had time to clean it up + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Create the frames +pos_l=2; +pos_w=FIGURESIZE(3)-4; +pos_h=FIGURESIZE(4)-4; +pos_t=2; +h_f_load_background = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'Style','frame', ... + 'Tag','f_load_background'); + +pos_w=120; +pos_l=FIGURESIZE(3)-(pos_w+2+2); +pos_h=FIGURESIZE(4)-2*4; +pos_t=4; +h_f_load_side = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'Style','frame', ... + 'Tag','f_load_side'); + +pos_l=4; +pos_w=FIGURESIZE(3)-8-pos_w-2; +pos_h=FIGURESIZE(4)-8; +pos_t=4; +h_f_load = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'Style','frame', ... + 'Tag','f_load'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Controls in f_load +bgc = get(h_f_load, 'BackgroundColor'); + +pos_w=230; + +pos_frame=get(h_f_load, 'Position'); +pos_h = 40; +pos_t = pos_frame(2) + pos_frame(4) - pos_h - 6; +pos_l = pos_frame(1) + 6; + +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String',loadString, ... + 'Style','text', ... + 'Tag','t_93'); + +pos_h = 20; +pos_t = pos_t - pos_h - 10; +pos_l = pos_frame(1) + 6; + +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Name of the variable:', ... + 'Style','text', ... + 'Tag','t_92'); + +pos_w = 200; +pos_l = pos_l + 30; +pos_t = pos_t - pos_h; +he_FastICA_file = uicontrol('Parent',a, ... + 'BackgroundColor',[1 1 1], ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','', ... + 'Style','edit', ... + 'Tag','e_file'); + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Controls in f_load_side +pos_vspace = 6; +pos_hspace = 10; +pos_frame = get(h_f_load_side, 'Position'); +pos_w = 100; +pos_h = 30; +pos_l = pos_frame(1) + pos_hspace; +pos_t = pos_frame(2) + pos_frame(4) - pos_h - pos_vspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_lc Load', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Load', ... + 'Tag','b_lLoad'); + +pos_t=pos_t-pos_h-pos_vspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_lc Cancel', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Cancel', ... + 'Tag','b_lCancel'); + +pos_t = pos_frame(2) + pos_vspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_lc Help', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Help', ... + 'Tag','b_lHelp'); + diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_lc.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_lc.m new file mode 100644 index 0000000000000000000000000000000000000000..9caaf8a4e1f572434e4baa97f899ce4567fc3e72 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_lc.m @@ -0,0 +1,112 @@ +function gui_lc (action) +% +% This file is used by FASTICAG + +% This file holds the callbacks for load-dialog + +% @(#)$Id: gui_lc.m,v 1.4 2003/09/11 12:01:19 jarmo Exp $ + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Global variables + +% Handle to the window +global hf_FastICA_Load; + +% Handles to some of the controls in window +global he_FastICA_file; + +% Needed handles from the main figure +global ht_FastICA_mixedStatus; + +% Needed handles from the advOpt figure +global hb_FastICA_initGuess; +global ht_FastICA_initGuess; +global hpm_FastICA_initState; + +% The needed main variables +global g_FastICA_mixedsig; +global g_FastICA_mixedmean; + +% What is the load type of load dialog +global g_FastICA_loadType; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% This should not take long... +watchonInFigure = watchon; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +switch action +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'Load' + + varName = get(he_FastICA_file, 'String'); % The name of the variable to be loaded + command=['evalin(''base'',''assignin(''''caller'''',''''data'''',' varName ')'')']; + eval(command,'fprintf(''Variable not found in MATLAB workspace, data not loaded!\n'');data=[];'); % Variable is copyed to 'data' + if length (size (data)) > 2, + fprintf (['Input data can not have more than two dimensions, data' ... + ' not loaded.\n']); + data = []; + end + + if any (any (isnan (data))), + fprintf ('Input data contains NaN''s, data not loaded.\n'); + data = []; + end + + + if isempty(data) % if there was no name given... + watchoff (watchonInFigure); + % There used to be a 'break' statement here, but it resulted in + % errors in more recent version of Matlab -- jarmo + return; + end + switch g_FastICA_loadType + case 'data' % New data + g_FastICA_mixedsig = data; + if ~isa (g_FastICA_mixedsig, 'double') + fprintf ('Warning: converting input data into regular (double) precision.\n'); + g_FastICA_mixedsig = double (g_FastICA_mixedsig); + end + + set(ht_FastICA_mixedStatus, 'String', ''); + g_FastICA_mixedmean = []; % New data - so that means ... + gui_cb NewData; + + case 'guess' % New initial guess + set(hb_FastICA_initGuess, 'UserData', data); % Since we loaded new initial + set(ht_FastICA_initGuess, 'String', 'Loaded'); % guess, we wan't to use it too + set(hpm_FastICA_initState, 'Value', 2); % ... set initState to 'guess' + end + + close(hf_FastICA_Load); % close the dialog + + % Use return to avoid reaching the watchoff statement at the end + % (There used to be a 'break' statement here, but it resulted in + % errors in more recent version of Matlab -- jarmo) + return; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'Cancel' + + close(hf_FastICA_Load); % do nothing just exit + + % Use return to avoid reaching the watchoff statement at the end + % (There used to be a 'break' statement here, but it resulted in + % errors in more recent version of Matlab -- jarmo) + return; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'Help' + + % Which help do we show? + switch g_FastICA_loadType + case 'data' + gui_help('gui_lc_data'); + case 'guess' + gui_help('gui_lc_guess'); + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +end % switch + +watchoff (watchonInFigure); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_s.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_s.m new file mode 100644 index 0000000000000000000000000000000000000000..01a962163fcaa9c5bbc3480863d055bd5e1252ae --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_s.m @@ -0,0 +1,177 @@ +function gui_s (x, y) +% +% This file is used by FASTICAG + +% The save dialog for saving the results + +% @(#)$Id: gui_s.m,v 1.4 2004/07/27 13:09:26 jarmo Exp $ + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Global variables + +% Handle to the window +global hf_FastICA_Save; + +% Handles to some of the controls in window +global he_FastICA_suffix; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Configuration options +FIGURENAME = 'FastICA: Save results'; +FIGURETAG = 'f_FastICASave'; +FIGURESIZE = [x y 450 150]; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Check to see if this figure is already open - it should not! +% Can't have more than one copy - otherwise the global +% variables and handles can get mixed up. +if ~isempty(findobj('Tag',FIGURETAG)) + error('Error: load dialog already open!'); +end + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Initialize some of the controls' values + +saveString = 'Save results as variables in MATLAB workspace.'; +promptString = 'Suffix to identify the results:'; +helpString = 'If you give e.g. ''_FastICA'', the variables will be called A_FastICA, W_FastICA, etc.'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Create the figure +a = figure('Color',[0.8 0.8 0.8], ... + 'PaperType','a4letter', ... + 'Name', FIGURENAME, ... + 'NumberTitle', 'off', ... + 'Tag', FIGURETAG, ... + 'Position', FIGURESIZE, ... + 'MenuBar', 'none'); +set (a, 'Resize', 'off'); + +hf_FastICA_Save = a; + +set(hf_FastICA_Save, 'HandleVisibility', 'callback'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% From here on it get's ugly as I have not had time to clean it up + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Create the frames +pos_l=2; +pos_w=FIGURESIZE(3)-4; +pos_h=FIGURESIZE(4)-4; +pos_t=2; +h_f_save_background = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'Style','frame', ... + 'Tag','f_save_background'); + +pos_w=120; +pos_l=FIGURESIZE(3)-(pos_w+2+2); +pos_h=FIGURESIZE(4)-2*4; +pos_t=4; +h_f_save_side = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'Style','frame', ... + 'Tag','f_save_side'); + +pos_l=4; +pos_w=FIGURESIZE(3)-8-pos_w-2; +pos_h=FIGURESIZE(4)-8; +pos_t=4; +h_f_save = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'Style','frame', ... + 'Tag','f_save'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Controls in f_save +bgc = get(h_f_save, 'BackgroundColor'); + +pos_w=230; + +pos_frame=get(h_f_save, 'Position'); +pos_h = 40; +pos_t = pos_frame(2) + pos_frame(4) - pos_h - 6; +pos_l = pos_frame(1) + 6; + +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String',saveString, ... + 'Style','text', ... + 'Tag','t_93'); + +pos_h = 20; +pos_t = pos_t - pos_h - 10; +pos_l = pos_frame(1) + 6; + +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String',promptString, ... + 'Style','text', ... + 'Tag','t_92'); + +pos_w = 200; +pos_l = pos_l + 30; +pos_t = pos_t - pos_h; +he_FastICA_suffix = uicontrol('Parent',a, ... + 'BackgroundColor',[1 1 1], ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','', ... + 'Style','edit', ... + 'Tag','e_suffix'); + +pos_w = pos_frame(3) - 12; +pos_h = 30; +pos_t = pos_frame(2) + 6; +pos_l = pos_frame(1) + 6; + +b = uicontrol('Parent',a, ... + 'BackgroundColor',bgc, ... + 'HorizontalAlignment','left', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String',helpString, ... + 'Style','text', ... + 'Tag','t_97'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Controls in f_save_side +pos_vspace = 6; +pos_hspace = 10; +pos_frame = get(h_f_save_side, 'Position'); +pos_w = 100; +pos_h = 30; +pos_l = pos_frame(1) + pos_hspace; +pos_t = pos_frame(2) + pos_frame(4) - pos_h - pos_vspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_sc Save', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Save', ... + 'Tag','b_sSave'); + +pos_t=pos_t-pos_h-pos_vspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_sc Cancel', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Cancel', ... + 'Tag','b_sCancel'); + +pos_t = pos_frame(2) + pos_vspace; +b = uicontrol('Parent',a, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Callback','gui_sc Help', ... + 'Position',[pos_l pos_t pos_w pos_h], ... + 'String','Help', ... + 'Tag','b_sHelp'); + diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_sc.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_sc.m new file mode 100644 index 0000000000000000000000000000000000000000..cf65bc54643f909594ccfc6b1df79e4c9229578a --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_sc.m @@ -0,0 +1,74 @@ +function gui_sc (action) +% +% This file is used by FASTICAG + +% This file holds the callbacks for save-dialog + +% @(#)$Id: gui_sc.m,v 1.3 2003/09/08 11:28:59 jarmo Exp $ + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Global variables + +% Handle to the window +global hf_FastICA_Save; + +% Handles to some of the controls in window +global he_FastICA_suffix; + +% The needed main variables +global g_FastICA_ica_sig; +global g_FastICA_ica_A; +global g_FastICA_ica_W; +global g_FastICA_white_sig; +global g_FastICA_white_wm; +global g_FastICA_white_dwm; +global g_FastICA_pca_E; +global g_FastICA_pca_D; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% This should not take long... +watchonInFigure = watchon; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +switch action +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'Save' + + suffix = deblank(get(he_FastICA_suffix, 'String')); % The suffix for the variables + + fprintf('Saving results in variables in Matlab workspace.\n'); + assignin('base',['IC' suffix],g_FastICA_ica_sig); + assignin('base',['A' suffix],g_FastICA_ica_A); + assignin('base',['W' suffix],g_FastICA_ica_W); + assignin('base',['whitesig' suffix],g_FastICA_white_sig); + assignin('base',['whiteningMatrix' suffix],g_FastICA_white_wm); + assignin('base',['dewhiteningMatrix' suffix],g_FastICA_white_dwm); + assignin('base',['E' suffix],g_FastICA_pca_E); + assignin('base',['D' suffix],g_FastICA_pca_D); + + close(hf_FastICA_Save); % close the dialog + + % Use return to avoid reaching the watchoff statement at the end + % (There used to be a 'break' statement here, but it resulted in + % errors in more recent version of Matlab -- jarmo) + return; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'Cancel' + + close(hf_FastICA_Save); % do nothing just exit + + % Use return to avoid reaching the watchoff statement at the end + % (There used to be a 'break' statement here, but it resulted in + % errors in more recent version of Matlab -- jarmo) + return; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +case 'Help' + + gui_help('gui_sc'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +end % switch + +watchoff (watchonInFigure); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/icaplot.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/icaplot.m new file mode 100644 index 0000000000000000000000000000000000000000..9126f1ad293601b928ee3c9934cca103edcdd635 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/icaplot.m @@ -0,0 +1,397 @@ +function icaplot(mode, varargin); +%ICAPLOT - plot signals in various ways +% +% ICAPLOT is mainly for plottinf and comparing the mixed signals and +% separated ica-signals. +% +% ICAPLOT has many different modes. The first parameter of the function +% defines the mode. Other parameters and their order depends on the +% mode. The explanation for the more common parameters is in the end. +% +% Classic +% icaplot('classic', s1, n1, range, xrange, titlestr) +% +% Plots the signals in the same manner as the FASTICA and FASTICAG +% programs do. All the signals are plotted in their own axis. +% +% Complot +% icaplot('complot', s1, n1, range, xrange, titlestr) +% +% The signals are plotted on the same axis. This is good for +% visualization of the shape of the signals. The scale of the signals +% has been altered so that they all fit nicely. +% +% Histogram +% icaplot('histogram', s1, n1, range, bins, style) +% +% The histogram of the signals is plotted. The number of bins can be +% specified with 'bins'-parameter. The style for the histograms can +% be either 'bar' (default) of 'line'. +% +% Scatter +% icaplot('scatter', s1, n1, s2, n2, range, titlestr, s1label, +% s2label, markerstr) +% +% A scatterplot is plotted so that the signal 1 is the 'X'-variable +% and the signal 2 is the 'Y'-variable. The 'markerstr' can be used +% to specify the maker used in the plot. The format for 'markerstr' +% is the same as for Matlab's PLOT. +% +% Compare +% icaplot('compare', s1, n1, s2, n2, range, xrange, titlestr, +% s1label, s2label) +% +% This for for comparing two signals. The main used in this context +% would probably be to see how well the separated ICA-signals explain +% the observed mixed signals. The s2 signals are first scaled with +% REGRESS function. +% +% Compare - Sum +% icaplot('sum', s1, n1, s2, n2, range, xrange, titlestr, s1label, +% s2label) +% +% The same as Compare, but this time the signals in s2 (specified by +% n2) are summed together. +% +% Compare - Sumerror +% icaplot('sumerror', s1, n1, s2, n2, range, xrange, titlestr, +% s1label, s2label) +% +% The same as Compare - Sum, but also the 'error' between the signal +% 1 and the summed IC's is plotted. +% +% +% More common parameters +% The signals to be plotted are in matrices s1 and s2. The n1 and n2 +% are used to tell the index of the signal or signals to be plotted +% from s1 or s2. If n1 or n2 has a value of 0, then all the signals +% from corresponding matrix will be plotted. The values for n1 and n2 +% can also be vectors (like: [1 3 4]) In some casee if there are more +% than 1 signal to be plotted from s1 or s2 then the plot will +% contain as many subplots as are needed. +% +% The range of the signals to be plotted can be limited with +% 'range'-parameter. It's value is a vector ( 10000:15000 ). If range +% is 0, then the whole range will be plotted. +% +% The 'xrange' is used to specify only the labels used on the +% x-axis. The value of 'xrange' is a vector containing the x-values +% for the plots or [start end] for begin and end of the range +% ( 10000:15000 or [10 15] ). If xrange is 0, then value of range +% will be used for x-labels. +% +% You can give a title for the plot with 'titlestr'. Also the +% 's1label' and 's2label' are used to give more meaningfull label for +% the signals. +% +% Lastly, you can omit some of the arguments from the and. You will +% have to give values for the signal matrices (s1, s2) and the +% indexes (n1, n2) + +% @(#)$Id: icaplot.m,v 1.2 2003/04/05 14:23:58 jarmo Exp $ + +switch mode +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % 'dispsig' is to replace the old DISPSIG + % '' & 'classic' are just another names - '' quite short one :-) + case {'', 'classic', 'dispsig'} + % icaplot(mode, s1, n1, range, xrange, titlestr) + if length(varargin) < 1, error('Not enough arguments.'); end + if length(varargin) < 5, titlestr = '';else titlestr = varargin{5}; end + if length(varargin) < 4, xrange = 0;else xrange = varargin{4}; end + if length(varargin) < 3, range = 0;else range = varargin{3}; end + if length(varargin) < 2, n1 = 0;else n1 = varargin{2}; end + s1 = varargin{1}; + range=chkrange(range, s1); + xrange=chkxrange(xrange, range); + n1=chkn(n1, s1); + + clf; + + numSignals = size(n1, 2); + for i = 1:numSignals, + subplot(numSignals, 1, i); + plot(xrange, s1(n1(i), range)); + end + subplot(numSignals,1, 1); + if (~isempty(titlestr)) + title(titlestr); + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + case 'complot' + % icaplot(mode, s1, n1, range, xrange, titlestr) + if length(varargin) < 1, error('Not enough arguments.'); end + if length(varargin) < 5, titlestr = '';else titlestr = varargin{5}; end + if length(varargin) < 4, xrange = 0;else xrange = varargin{4}; end + if length(varargin) < 3, range = 0;else range = varargin{3}; end + if length(varargin) < 2, n1 = 0;else n1 = varargin{2}; end + s1 = remmean(varargin{1}); + range=chkrange(range, s1); + xrange=chkxrange(xrange, range); + n1=chkn(n1, s1); + + for i = 1:size(n1, 2) + S1(i, :) = s1(n1(i), range); + end + + alpha = mean(max(S1')-min(S1')); + for i = 1:size(n1,2) + S2(i,:) = S1(i,:) - alpha*(i-1)*ones(size(S1(1,:))); + end + + plot(xrange, S2'); + axis([min(xrange) max(xrange) min(min(S2)) max(max(S2)) ]); + + set(gca,'YTick',(-size(S1,1)+1)*alpha:alpha:0); + set(gca,'YTicklabel',fliplr(n1)); + + if (~isempty(titlestr)) + title(titlestr); + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + case 'histogram' + % icaplot(mode, s1, n1, range, bins, style) + if length(varargin) < 1, error('Not enough arguments.'); end + if length(varargin) < 5, style = 'bar';else style = varargin{5}; end + if length(varargin) < 4, bins = 10;else bins = varargin{4}; end + if length(varargin) < 3, range = 0;else range = varargin{3}; end + if length(varargin) < 2, n1 = 0;else n1 = varargin{2}; end + s1 = varargin{1}; + range = chkrange(range, s1); + n1 = chkn(n1, s1); + + numSignals = size(n1, 2); + rows = floor(sqrt(numSignals)); + columns = ceil(sqrt(numSignals)); + while (rows * columns < numSignals) + columns = columns + 1; + end + + switch style + case {'', 'bar'} + for i = 1:numSignals, + subplot(rows, columns, i); + hist(s1(n1(i), range), bins); + title(int2str(n1(i))); + drawnow; + end + + case 'line' + for i = 1:numSignals, + subplot(rows, columns, i); + [Y, X]=hist(s1(n1(i), range), bins); + plot(X, Y); + title(int2str(n1(i))); + drawnow; + end + otherwise + fprintf('Unknown style.\n') + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + case 'scatter' + % icaplot(mode, s1, n1, s2, n2, range, titlestr, xlabelstr, ylabelstr, markerstr) + if length(varargin) < 4, error('Not enough arguments.'); end + if length(varargin) < 9, markerstr = '.';else markerstr = varargin{9}; end + if length(varargin) < 8, ylabelstr = 'Signal 2';else ylabelstr = varargin{8}; end + if length(varargin) < 7, xlabelstr = 'Signal 1';else xlabelstr = varargin{7}; end + if length(varargin) < 6, titlestr = '';else titlestr = varargin{6}; end + if length(varargin) < 5, range = 0;else range = varargin{5}; end + n2 = varargin{4}; + s2 = varargin{3}; + n1 = varargin{2}; + s1 = varargin{1}; + range = chkrange(range, s1); + n1 = chkn(n1, s1); + n2 = chkn(n2, s2); + + rows = size(n1, 2); + columns = size(n2, 2); + for r = 1:rows + for c = 1:columns + subplot(rows, columns, (r-1)*columns + c); + plot(s1(n1(r), range),s2(n2(c), range),markerstr); + if (~isempty(titlestr)) + title(titlestr); + end + if (rows*columns == 1) + xlabel(xlabelstr); + ylabel(ylabelstr); + else + xlabel([xlabelstr ' (' int2str(n1(r)) ')']); + ylabel([ylabelstr ' (' int2str(n2(c)) ')']); + end + drawnow; + end + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + case {'compare', 'sum', 'sumerror'} + % icaplot(mode, s1, n1, s2, n2, range, xrange, titlestr, s1label, s2label) + if length(varargin) < 4, error('Not enough arguments.'); end + if length(varargin) < 9, s2label = 'IC';else s2label = varargin{9}; end + if length(varargin) < 8, s1label = 'Mix';else s1label = varargin{8}; end + if length(varargin) < 7, titlestr = '';else titlestr = varargin{7}; end + if length(varargin) < 6, xrange = 0;else xrange = varargin{6}; end + if length(varargin) < 5, range = 0;else range = varargin{5}; end + s1 = varargin{1}; + n1 = varargin{2}; + s2 = varargin{3}; + n2 = varargin{4}; + range = chkrange(range, s1); + xrange = chkxrange(xrange, range); + n1 = chkn(n1, s1); + n2 = chkn(n2, s2); + + numSignals = size(n1, 2); + if (numSignals > 1) + externalLegend = 1; + else + externalLegend = 0; + end + + rows = floor(sqrt(numSignals+externalLegend)); + columns = ceil(sqrt(numSignals+externalLegend)); + while (rows * columns < (numSignals+externalLegend)) + columns = columns + 1; + end + + clf; + + for j = 1:numSignals + subplot(rows, columns, j); + switch mode + case 'compare' + plotcompare(s1, n1(j), s2,n2, range, xrange); + [legendtext,legendstyle]=legendcompare(n1(j),n2,s1label,s2label,externalLegend); + case 'sum' + plotsum(s1, n1(j), s2,n2, range, xrange); + [legendtext,legendstyle]=legendsum(n1(j),n2,s1label,s2label,externalLegend); + case 'sumerror' + plotsumerror(s1, n1(j), s2,n2, range, xrange); + [legendtext,legendstyle]=legendsumerror(n1(j),n2,s1label,s2label,externalLegend); + end + + if externalLegend + title([titlestr ' (' s1label ' ' int2str(n1(j)) ')']); + else + legend(char(legendtext)); + if (~isempty(titlestr)) + title(titlestr); + end + end + end + + if (externalLegend) + subplot(rows, columns, numSignals+1); + legendsize = size(legendtext, 2); + hold on; + for i=1:legendsize + plot([0 1],[legendsize-i legendsize-i], char(legendstyle(i))); + text(1.5, legendsize-i, char(legendtext(i))); + end + hold off; + axis([0 6 -1 legendsize]); + axis off; + end + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function plotcompare(s1, n1, s2, n2, range, xrange); + style=getStyles; + K = regress(s1(n1,:)',s2'); + plot(xrange, s1(n1,range), char(style(1))); + hold on + for i=1:size(n2,2) + plotstyle=char(style(i+1)); + plot(xrange, K(n2(i))*s2(n2(i),range), plotstyle); + end + hold off + +function [legendText, legendStyle]=legendcompare(n1, n2, s1l, s2l, externalLegend); + style=getStyles; + if (externalLegend) + legendText(1)={[s1l ' (see the titles)']}; + else + legendText(1)={[s1l ' ', int2str(n1)]}; + end + legendStyle(1)=style(1); + for i=1:size(n2, 2) + legendText(i+1) = {[s2l ' ' int2str(n2(i))]}; + legendStyle(i+1) = style(i+1); + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function plotsum(s1, n1, s2, n2, range, xrange); + K = diag(regress(s1(n1,:)',s2')); + sigsum = sum(K(:,n2)*s2(n2,:)); + plot(xrange, s1(n1, range),'k-', ... + xrange, sigsum(range), 'b-'); + +function [legendText, legendStyle]=legendsum(n1, n2, s1l, s2l, externalLegend); + if (externalLegend) + legendText(1)={[s1l ' (see the titles)']}; + else + legendText(1)={[s1l ' ', int2str(n1)]}; + end + legendText(2)={['Sum of ' s2l ': ', int2str(n2)]}; + legendStyle={'k-';'b-'}; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function plotsumerror(s1, n1, s2, n2, range, xrange); + K = diag(regress(s1(n1,:)',s2')); + sigsum = sum(K(:,n2)*s2(n2,:)); + plot(xrange, s1(n1, range),'k-', ... + xrange, sigsum(range), 'b-', ... + xrange, s1(n1, range)-sigsum(range), 'r-'); + +function [legendText, legendStyle]=legendsumerror(n1, n2, s1l, s2l, externalLegend); + if (externalLegend) + legendText(1)={[s1l ' (see the titles)']}; + else + legendText(1)={[s1l ' ', int2str(n1)]}; + end + legendText(2)={['Sum of ' s2l ': ', int2str(n2)]}; + legendText(3)={'"Error"'}; + legendStyle={'k-';'b-';'r-'}; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function style=getStyles; + color = {'k','r','g','b','m','c','y'}; + line = {'-',':','-.','--'}; + for i = 0:size(line,2)-1 + for j = 1:size(color, 2) + style(j + i*size(color, 2)) = strcat(color(j), line(i+1)); + end + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function range=chkrange(r, s) + if r == 0 + range = 1:size(s, 2); + else + range = r; + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function xrange=chkxrange(xr,r); + if xr == 0 + xrange = r; + elseif size(xr, 2) == 2 + xrange = xr(1):(xr(2)-xr(1))/(size(r,2)-1):xr(2); + elseif size(xr, 2)~=size(r, 2) + error('Xrange and range have different sizes.'); + else + xrange = xr; + end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function n=chkn(n,s) + if n == 0 + n = 1:size(s, 1); + end \ No newline at end of file diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/pcamat.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/pcamat.m new file mode 100644 index 0000000000000000000000000000000000000000..a91b0c88df2f8edee67d7b8d9088950257f3448e --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/pcamat.m @@ -0,0 +1,358 @@ +function [E, D] = pcamat(vectors, firstEig, lastEig, s_interactive, ... + s_verbose); +%PCAMAT - Calculates the pca for data +% +% [E, D] = pcamat(vectors, firstEig, lastEig, ... +% interactive, verbose); +% +% Calculates the PCA matrices for given data (row) vectors. Returns +% the eigenvector (E) and diagonal eigenvalue (D) matrices containing the +% selected subspaces. Dimensionality reduction is controlled with +% the parameters 'firstEig' and 'lastEig' - but it can also be done +% interactively by setting parameter 'interactive' to 'on' or 'gui'. +% +% ARGUMENTS +% +% vectors Data in row vectors. +% firstEig Index of the largest eigenvalue to keep. +% Default is 1. +% lastEig Index of the smallest eigenvalue to keep. +% Default is equal to dimension of vectors. +% interactive Specify eigenvalues to keep interactively. Note that if +% you set 'interactive' to 'on' or 'gui' then the values +% for 'firstEig' and 'lastEig' will be ignored, but they +% still have to be entered. If the value is 'gui' then the +% same graphical user interface as in FASTICAG will be +% used. Default is 'off'. +% verbose Default is 'on'. +% +% +% EXAMPLE +% [E, D] = pcamat(vectors); +% +% Note +% The eigenvalues and eigenvectors returned by PCAMAT are not sorted. +% +% This function is needed by FASTICA and FASTICAG + +% For historical reasons this version does not sort the eigenvalues or +% the eigen vectors in any ways. Therefore neither does the FASTICA or +% FASTICAG. Generally it seams that the components returned from +% whitening is almost in reversed order. (That means, they usually are, +% but sometime they are not - depends on the EIG-command of matlab.) + +% @(#)$Id: pcamat.m,v 1.5 2003/12/15 18:24:32 jarmo Exp $ + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Default values: +if nargin < 5, s_verbose = 'on'; end +if nargin < 4, s_interactive = 'off'; end +if nargin < 3, lastEig = size(vectors, 1); end +if nargin < 2, firstEig = 1; end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Check the optional parameters; +switch lower(s_verbose) + case 'on' + b_verbose = 1; + case 'off' + b_verbose = 0; + otherwise + error(sprintf('Illegal value [ %s ] for parameter: ''verbose''\n', s_verbose)); +end + +switch lower(s_interactive) + case 'on' + b_interactive = 1; + case 'off' + b_interactive = 0; + case 'gui' + b_interactive = 2; + otherwise + error(sprintf('Illegal value [ %s ] for parameter: ''interactive''\n', ... + s_interactive)); +end + +oldDimension = size (vectors, 1); +if ~(b_interactive) + if lastEig < 1 | lastEig > oldDimension + error(sprintf('Illegal value [ %d ] for parameter: ''lastEig''\n', lastEig)); + end + if firstEig < 1 | firstEig > lastEig + error(sprintf('Illegal value [ %d ] for parameter: ''firstEig''\n', firstEig)); + end +end + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Calculate PCA + +% Calculate the covariance matrix. +if b_verbose, fprintf ('Calculating covariance...\n'); end +covarianceMatrix = cov(vectors', 1); + +% Calculate the eigenvalues and eigenvectors of covariance +% matrix. +[E, D] = eig (covarianceMatrix); + +% The rank is determined from the eigenvalues - and not directly by +% using the function rank - because function rank uses svd, which +% in some cases gives a higher dimensionality than what can be used +% with eig later on (eig then gives negative eigenvalues). +rankTolerance = 1e-7; +maxLastEig = sum (diag (D) > rankTolerance); +if maxLastEig == 0, + fprintf (['Eigenvalues of the covariance matrix are' ... + ' all smaller than tolerance [ %g ].\n' ... + 'Please make sure that your data matrix contains' ... + ' nonzero values.\nIf the values are very small,' ... + ' try rescaling the data matrix.\n'], rankTolerance); + error ('Unable to continue, aborting.'); +end + +% Sort the eigenvalues - decending. +eigenvalues = flipud(sort(diag(D))); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Interactive part - command-line +if b_interactive == 1 + + % Show the eigenvalues to the user + hndl_win=figure; + bar(eigenvalues); + title('Eigenvalues'); + + % ask the range from the user... + % ... and keep on asking until the range is valid :-) + areValuesOK=0; + while areValuesOK == 0 + firstEig = input('The index of the largest eigenvalue to keep? (1) '); + lastEig = input(['The index of the smallest eigenvalue to keep? (' ... + int2str(oldDimension) ') ']); + % Check the new values... + % if they are empty then use default values + if isempty(firstEig), firstEig = 1;end + if isempty(lastEig), lastEig = oldDimension;end + % Check that the entered values are within the range + areValuesOK = 1; + if lastEig < 1 | lastEig > oldDimension + fprintf('Illegal number for the last eigenvalue.\n'); + areValuesOK = 0; + end + if firstEig < 1 | firstEig > lastEig + fprintf('Illegal number for the first eigenvalue.\n'); + areValuesOK = 0; + end + end + % close the window + close(hndl_win); +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Interactive part - GUI +if b_interactive == 2 + + % Show the eigenvalues to the user + hndl_win = figure('Color',[0.8 0.8 0.8], ... + 'PaperType','a4letter', ... + 'Units', 'normalized', ... + 'Name', 'FastICA: Reduce dimension', ... + 'NumberTitle','off', ... + 'Tag', 'f_eig'); + h_frame = uicontrol('Parent', hndl_win, ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'Units', 'normalized', ... + 'Position',[0.13 0.05 0.775 0.17], ... + 'Style','frame', ... + 'Tag','f_frame'); + +b = uicontrol('Parent',hndl_win, ... + 'Units','normalized', ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'HorizontalAlignment','left', ... + 'Position',[0.142415 0.0949436 0.712077 0.108507], ... + 'String','Give the indices of the largest and smallest eigenvalues of the covariance matrix to be included in the reduced data.', ... + 'Style','text', ... + 'Tag','StaticText1'); +e_first = uicontrol('Parent',hndl_win, ... + 'Units','normalized', ... + 'Callback',[ ... + 'f=round(str2num(get(gcbo, ''String'')));' ... + 'if (f < 1), f=1; end;' ... + 'l=str2num(get(findobj(''Tag'',''e_last''), ''String''));' ... + 'if (f > l), f=l; end;' ... + 'set(gcbo, ''String'', int2str(f));' ... + ], ... + 'BackgroundColor',[1 1 1], ... + 'HorizontalAlignment','right', ... + 'Position',[0.284831 0.0678168 0.12207 0.0542535], ... + 'Style','edit', ... + 'String', '1', ... + 'Tag','e_first'); +b = uicontrol('Parent',hndl_win, ... + 'Units','normalized', ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'HorizontalAlignment','left', ... + 'Position',[0.142415 0.0678168 0.12207 0.0542535], ... + 'String','Range from', ... + 'Style','text', ... + 'Tag','StaticText2'); +e_last = uicontrol('Parent',hndl_win, ... + 'Units','normalized', ... + 'Callback',[ ... + 'l=round(str2num(get(gcbo, ''String'')));' ... + 'lmax = get(gcbo, ''UserData'');' ... + 'if (l > lmax), l=lmax; fprintf([''The selected value was too large, or the selected eigenvalues were close to zero\n'']); end;' ... + 'f=str2num(get(findobj(''Tag'',''e_first''), ''String''));' ... + 'if (l < f), l=f; end;' ... + 'set(gcbo, ''String'', int2str(l));' ... + ], ... + 'BackgroundColor',[1 1 1], ... + 'HorizontalAlignment','right', ... + 'Position',[0.467936 0.0678168 0.12207 0.0542535], ... + 'Style','edit', ... + 'String', int2str(maxLastEig), ... + 'UserData', maxLastEig, ... + 'Tag','e_last'); +% in the first version oldDimension was used instead of +% maxLastEig, but since the program would automatically +% drop the eigenvalues afte maxLastEig... +b = uicontrol('Parent',hndl_win, ... + 'Units','normalized', ... + 'BackgroundColor',[0.701961 0.701961 0.701961], ... + 'HorizontalAlignment','left', ... + 'Position',[0.427246 0.0678168 0.0406901 0.0542535], ... + 'String','to', ... + 'Style','text', ... + 'Tag','StaticText3'); +b = uicontrol('Parent',hndl_win, ... + 'Units','normalized', ... + 'Callback','uiresume(gcbf)', ... + 'Position',[0.630697 0.0678168 0.12207 0.0542535], ... + 'String','OK', ... + 'Tag','Pushbutton1'); +b = uicontrol('Parent',hndl_win, ... + 'Units','normalized', ... + 'Callback',[ ... + 'gui_help(''pcamat'');' ... + ], ... + 'Position',[0.767008 0.0678168 0.12207 0.0542535], ... + 'String','Help', ... + 'Tag','Pushbutton2'); + + h_axes = axes('Position' ,[0.13 0.3 0.775 0.6]); + set(hndl_win, 'currentaxes',h_axes); + bar(eigenvalues); + title('Eigenvalues'); + + uiwait(hndl_win); + firstEig = str2num(get(e_first, 'String')); + lastEig = str2num(get(e_last, 'String')); + + % close the window + close(hndl_win); +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% See if the user has reduced the dimension enought + +if lastEig > maxLastEig + lastEig = maxLastEig; + if b_verbose + fprintf('Dimension reduced to %d due to the singularity of covariance matrix\n',... + lastEig-firstEig+1); + end +else + % Reduce the dimensionality of the problem. + if b_verbose + if oldDimension == (lastEig - firstEig + 1) + fprintf ('Dimension not reduced.\n'); + else + fprintf ('Reducing dimension...\n'); + end + end +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Drop the smaller eigenvalues +if lastEig < oldDimension + lowerLimitValue = (eigenvalues(lastEig) + eigenvalues(lastEig + 1)) / 2; +else + lowerLimitValue = eigenvalues(oldDimension) - 1; +end + +lowerColumns = diag(D) > lowerLimitValue; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Drop the larger eigenvalues +if firstEig > 1 + higherLimitValue = (eigenvalues(firstEig - 1) + eigenvalues(firstEig)) / 2; +else + higherLimitValue = eigenvalues(1) + 1; +end +higherColumns = diag(D) < higherLimitValue; + +% Combine the results from above +selectedColumns = lowerColumns & higherColumns; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% print some info for the user +if b_verbose + fprintf ('Selected [ %d ] dimensions.\n', sum (selectedColumns)); +end +if sum (selectedColumns) ~= (lastEig - firstEig + 1), + error ('Selected a wrong number of dimensions.'); +end + +if b_verbose + fprintf ('Smallest remaining (non-zero) eigenvalue [ %g ]\n', eigenvalues(lastEig)); + fprintf ('Largest remaining (non-zero) eigenvalue [ %g ]\n', eigenvalues(firstEig)); + fprintf ('Sum of removed eigenvalues [ %g ]\n', sum(diag(D) .* ... + (~selectedColumns))); +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Select the colums which correspond to the desired range +% of eigenvalues. +E = selcol(E, selectedColumns); +D = selcol(selcol(D, selectedColumns)', selectedColumns); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Some more information +if b_verbose + sumAll=sum(eigenvalues); + sumUsed=sum(diag(D)); + retained = (sumUsed / sumAll) * 100; + fprintf('[ %g ] %% of (non-zero) eigenvalues retained.\n', retained); +end + + + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function newMatrix = selcol(oldMatrix, maskVector); + +% newMatrix = selcol(oldMatrix, maskVector); +% +% Selects the columns of the matrix that marked by one in the given vector. +% The maskVector is a column vector. + +% 15.3.1998 + +if size(maskVector, 1) ~= size(oldMatrix, 2), + error ('The mask vector and matrix are of uncompatible size.'); +end + +numTaken = 0; + +for i = 1 : size (maskVector, 1), + if maskVector(i, 1) == 1, + takingMask(1, numTaken + 1) = i; + numTaken = numTaken + 1; + end +end + +newMatrix = oldMatrix(:, takingMask); \ No newline at end of file diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/remmean.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/remmean.m new file mode 100644 index 0000000000000000000000000000000000000000..1160b7a55b53cab24e285c95e3072b586d58186b --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/remmean.m @@ -0,0 +1,15 @@ +function [newVectors, meanValue] = remmean(vectors); +%REMMEAN - remove the mean from vectors +% +% [newVectors, meanValue] = remmean(vectors); +% +% Removes the mean of row vectors. +% Returns the new vectors and the mean. +% +% This function is needed by FASTICA and FASTICAG + +% @(#)$Id: remmean.m,v 1.2 2003/04/05 14:23:58 jarmo Exp $ + +newVectors = zeros (size (vectors)); +meanValue = mean (vectors')'; +newVectors = vectors - meanValue * ones (1,size (vectors, 2)); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/whitenv.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/whitenv.m new file mode 100644 index 0000000000000000000000000000000000000000..5c1609c32b9292f1773788be8336a351d3f78f44 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/whitenv.m @@ -0,0 +1,82 @@ +function [newVectors, whiteningMatrix, dewhiteningMatrix] = whitenv ... + (vectors, E, D, s_verbose); +%WHITENV - Whitenv vectors. +% +% [newVectors, whiteningMatrix, dewhiteningMatrix] = ... +% whitenv(vectors, E, D, verbose); +% +% Whitens the data (row vectors) and reduces dimension. Returns +% the whitened vectors (row vectors), whitening and dewhitening matrices. +% +% ARGUMENTS +% +% vectors Data in row vectors. +% E Eigenvector matrix from function 'pcamat' +% D Diagonal eigenvalue matrix from function 'pcamat' +% verbose Optional. Default is 'on' +% +% EXAMPLE +% [E, D] = pcamat(vectors); +% [nv, wm, dwm] = whitenv(vectors, E, D); +% +% +% This function is needed by FASTICA and FASTICAG +% +% See also PCAMAT + +% @(#)$Id: whitenv.m,v 1.3 2003/10/12 09:04:43 jarmo Exp $ + +% ======================================================== +% Default value for 'verbose' +if nargin < 4, s_verbose = 'on'; end + +% Check the optional parameter verbose; +switch lower(s_verbose) + case 'on' + b_verbose = 1; + case 'off' + b_verbose = 0; + otherwise + error(sprintf('Illegal value [ %s ] for parameter: ''verbose''\n', s_verbose)); +end + +% ======================================================== +% In some cases, rounding errors in Matlab cause negative +% eigenvalues (elements in the diagonal of D). Since it +% is difficult to know when this happens, it is difficult +% to correct it automatically. Therefore an error is +% signalled and the correction is left to the user. +if any (diag (D) < 0), + error (sprintf (['[ %d ] negative eigenvalues computed from the' ... + ' covariance matrix.\nThese are due to rounding' ... + ' errors in Matlab (the correct eigenvalues are\n' ... + 'probably very small).\nTo correct the situation,' ... + ' please reduce the number of dimensions in the' ... + ' data\nby using the ''lastEig'' argument in' ... + ' function FASTICA, or ''Reduce dim.'' button\nin' ... + ' the graphical user interface.'], ... + sum (diag (D) < 0))); +end + +% ======================================================== +% Calculate the whitening and dewhitening matrices (these handle +% dimensionality simultaneously). +whiteningMatrix = inv (sqrt (D)) * E'; +dewhiteningMatrix = E * sqrt (D); + +% Project to the eigenvectors of the covariance matrix. +% Whiten the samples and reduce dimension simultaneously. +if b_verbose, fprintf ('Whitening...\n'); end +newVectors = whiteningMatrix * vectors; + +% ======================================================== +% Just some security... +if ~isreal(newVectors) + error ('Whitened vectors have imaginary values.'); +end + +% Print some information to user +if b_verbose + fprintf ('Check: covariance differs from identity by [ %g ].\n', ... + max (max (abs (cov (newVectors', 1) - eye (size (newVectors, 1)))))); +end diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/eegplugin_bva_io.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/eegplugin_bva_io.m new file mode 100644 index 0000000000000000000000000000000000000000..516cb4c98cdb05a5a94ae81ea117ba822351fb7f --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/eegplugin_bva_io.m @@ -0,0 +1,77 @@ +% eegplugin_bva_io() - EEGLAB plugin for importing Brainvision +% .vhdr data files. +% +% Usage: +% >> eegplugin_bva_io(fig, trystrs, catchstrs); +% +% Inputs: +% fig - [integer] EEGLAB figure +% trystrs - [struct] "try" strings for menu callbacks. +% catchstrs - [struct] "catch" strings for menu callbacks. +% +% Author: Andreas Widmann for binary import, 2004 +% Arnaud Delorme for Matlab import and EEGLAB interface +% +% See also: pop_loadbv() + +% Copyright (C) 2004 Andreas Widmann & Arnaud Delorme +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +% $Id: eegplugin_bva_io.m 53 2010-05-22 21:57:38Z arnodelorme $ + +function vers = eegplugin_bva_io(fig, trystrs, catchstrs) + + vers = 'bva_io1.5.13'; + if nargin < 3 + error('eegplugin_bva_io requires 3 arguments'); + end; + + % add folder to path + % ------------------ + if ~exist('eegplugin_bva_io') + p = which('eegplugin_bva_io.m'); + p = p(1:findstr(p,'eegplugin_bva_io.m')-1); + addpath( p ); + end; + + % find import data menu + % --------------------- + menui = findobj(fig, 'tag', 'import data'); + menuo = findobj(fig, 'tag', 'export'); + + % menu callbacks + % -------------- + icadefs; + versiontype = 1; + if exist('EEGLAB_VERSION') + if EEGLAB_VERSION(1) == '4' + versiontype = 0; + end; + end; + if versiontype == 0 + comcnt1 = [ trystrs.no_check '[EEGTMP LASTCOM] = pop_loadbv;' catchstrs.new_non_empty ]; + comcnt2 = [ trystrs.no_check '[EEGTMP LASTCOM] = pop_loadbva;' catchstrs.new_non_empty ]; + else + comcnt1 = [ trystrs.no_check '[EEG LASTCOM] = pop_loadbv;' catchstrs.new_non_empty ]; + comcnt2 = [ trystrs.no_check '[EEG LASTCOM] = pop_loadbva;' catchstrs.new_non_empty ]; + end; + comcnt3 = [ trystrs.no_check 'LASTCOM = pop_writebva(EEG);' catchstrs.add_to_hist ]; + + % create menus + % ------------ + uimenu( menui, 'label', 'From Brain Vis. Rec. .vhdr file', 'callback', comcnt1, 'separator', 'on' ); + uimenu( menui, 'label', 'From Brain Vis. Anal. Matlab file', 'callback', comcnt2 ); + uimenu( menuo, 'label', 'Write Brain Vis. exchange format file', 'callback', comcnt3, 'separator', 'on' ); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/loadbvef.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/loadbvef.m new file mode 100644 index 0000000000000000000000000000000000000000..31f0a3ac5d448885bc81071d6d216aa131bc40a9 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/loadbvef.m @@ -0,0 +1,71 @@ +% loadbvef() - Load BrainVision electrode location file +% +% Usage: +% >> chanlocs = loadbvef( filename ); +% +% Inputs: +% filename - filename incl. filepath +% +% Outputs: +% chanlocs - EEGLAB chanlocs structure +% +% References: +% http://de.mathworks.com/help/matlab/import_export/importing-xml-documents.html +% +% Author: Andreas Widmann, University of Leipzig, 2015 + +%123456789012345678901234567890123456789012345678901234567890123456789012 + +% Copyright (C) 2015 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function [ chanlocs ] = loadbvef( filename ) + +% Import/export tag/field name mapping +fieldNames = { 'Name', 'labels', 1; 'Theta', 'sph_theta_besa', 0; 'Phi', 'sph_phi_besa', 0; 'Radius', 'sph_radius', 0 }; + +% Read file +xDoc = xmlread( filename ); + +% Loop over electrodes +allListitems = xDoc.getElementsByTagName( 'Electrode' ); + +for k = 0:allListitems.getLength - 1 + + thisListitem = allListitems.item( k ); + + % Loop over fields + for iField = 1:size( fieldNames, 1 ) + + thisList = thisListitem.getElementsByTagName( fieldNames{ iField, 1 } ); + thisElement = thisList.item( 0 ); + + % String or numeric + if fieldNames{ iField, 3 } + chanlocs( k + 1 ).( fieldNames{ iField, 2 } ) = char( thisElement.getFirstChild.getData ); %#ok + else + chanlocs( k + 1 ).( fieldNames{ iField, 2 } ) = str2double( thisElement.getFirstChild.getData ); %#ok + end + + end + +end + +% Convert from BESA +chanlocs = convertlocs( chanlocs, 'sphbesa2all' ); +chanlocs = rmfield( chanlocs, { 'sph_phi_besa', 'sph_theta_besa' } ); + +end \ No newline at end of file diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/parsebvmrk.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/parsebvmrk.m new file mode 100644 index 0000000000000000000000000000000000000000..6c662f1755875a92d6dc4e52735b28d6c591833f --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/parsebvmrk.m @@ -0,0 +1,48 @@ +% parsebvmrk() - convert Brain Vision Data Exchange format marker +% configuration structure to EEGLAB event structure +% +% Usage: +% >> EVENT = parsebvmrk(MRK); +% +% Inputs: +% MRK - marker configuration structure +% +% Outputs: +% EVENT - EEGLAB event structure +% +% Author: Andreas Widmann, University of Leipzig, 2007 + +% Copyright (C) 2007 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +% $Id: parsebvmrk.m 37 2007-06-26 12:56:17Z andreaswidmann $ + +function EVENT = parsebvmrk(MRK) + +for idx = 1:size(MRK.markerinfos, 1) + [mrkType mrkDesc EVENT(idx).latency EVENT(idx).duration EVENT(idx).channel EVENT(idx).bvtime] = ... + strread(MRK.markerinfos{idx, 1}, '%s%s%f%d%d%d', 'delimiter', ','); + EVENT(idx).bvmknum = MRK.markerinfos{idx, 2}; + + if strcmpi(mrkType, 'New Segment') || strcmpi(mrkType, 'DC Correction') + EVENT(idx).type = 'boundary'; + else + EVENT(idx).type = char(mrkDesc); + end + + EVENT(idx).code = char(mrkType); + EVENT(idx).urevent = idx; +end diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/pop_loadbv.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/pop_loadbv.m new file mode 100644 index 0000000000000000000000000000000000000000..4644a67ca5ee710e239ddb6de78d9b37e4e56bbf --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/pop_loadbv.m @@ -0,0 +1,423 @@ +% pop_loadbv() - load Brain Vision Data Exchange format dataset and +% return EEGLAB EEG structure +% +% Usage: +% >> [EEG, com] = pop_loadbv; % pop-up window mode +% >> [EEG, com] = pop_loadbv(path, hdrfile); +% >> [EEG, com] = pop_loadbv(path, hdrfile, srange); +% >> [EEG, com] = pop_loadbv(path, hdrfile, [], chans); +% >> [EEG, com] = pop_loadbv(path, hdrfile, srange, chans); +% +% Optional inputs: +% path - path to files +% hdrfile - name of Brain Vision vhdr-file (incl. extension) +% srange - scalar first sample to read (up to end of file) or +% vector first and last sample to read (e.g., [7 42]; +% default: all) +% chans - vector channels channels to read (e.g., [1:2 4]; +% default: all) +% +% Outputs: +% EEG - EEGLAB EEG structure +% com - history string +% +% Note: +% Import "Brain Vision Data Exchange" format files with this function. +% Brain Vision Data Exchange files consist of a set of 3 files, a header +% file (.vhdr), a marker file (.vmrk), and a data file. Export from +% BrainVision Analyzer with "Generic Data" export. Select header and +% marker file for export (text format; XML format is not yet supported). +% Binary and text data formats, in both multiplexed and vectorized data +% orientation are supported. Binary data formats offer higher precision +% and faster file import. +% +% Author: Andreas Widmann & Arnaud Delorme, 2004- + +% Copyright (C) 2004 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +% $Id: pop_loadbv.m 53 2010-05-22 21:57:38Z arnodelorme $ +% Revision 1.5 2010/03/23 21:19:52 roy +% added some lines so that the function can deal with the space lines in the ASCII multiplexed data file + +function [EEG, com] = pop_loadbv(path, hdrfile, srange, chans) + +com = ''; +EEG = []; + +if nargin < 2 + [hdrfile path] = uigetfile2('*.vhdr', 'Select Brain Vision vhdr-file - pop_loadbv()'); + if hdrfile(1) == 0, return; end + + drawnow; + uigeom = {[1 0.5] [1 0.5]}; + uilist = {{ 'style' 'text' 'string' 'Interval (samples; e.g., [7 42]; default: all):'} ... + { 'style' 'edit' 'string' ''} ... + { 'style' 'text' 'string' 'Channels (e.g., [1:2 4]; default: all):'} ... + { 'style' 'edit' 'string' ''}}; + result = inputgui(uigeom, uilist, 'pophelp(''pop_loadbv'')', 'Load a Brain Vision Data Exchange format dataset'); + if isempty(result), return, end + if ~isempty(result{1}), + srange = str2num(result{1}); + end + if ~isempty(result{2}), + chans = str2num(result{2}); + end +end + +% Header file +disp('pop_loadbv(): reading header file'); +hdr = readbvconf(path, hdrfile); + +% Common Infos +try + EEG = eeg_emptyset; +catch +end +EEG.comments = ['Original file: ' hdr.commoninfos.datafile]; +hdr.commoninfos.numberofchannels = str2double(hdr.commoninfos.numberofchannels); +EEG.srate = 1000000 / str2double(hdr.commoninfos.samplinginterval); + +% Binary Infos +if strcmpi(hdr.commoninfos.dataformat, 'binary') + switch lower(hdr.binaryinfos.binaryformat) + case 'int_16', binformat = 'int16'; bps = 2; + case 'uint_16', binformat = 'uint16'; bps = 2; + case 'ieee_float_32', binformat = 'float32'; bps = 4; + otherwise, error('Unsupported binary format'); + end +end + +% Channel Infos +if ~exist('chans', 'var') + chans = 1:hdr.commoninfos.numberofchannels; + EEG.nbchan = hdr.commoninfos.numberofchannels; +elseif isempty(chans) + chans = 1:hdr.commoninfos.numberofchannels; + EEG.nbchan = hdr.commoninfos.numberofchannels; +else + EEG.nbchan = length(chans); +end +if any(chans < 1) || any(chans > hdr.commoninfos.numberofchannels) + error('chans out of available channel range'); +end +if isfield(hdr, 'channelinfos') + for chan = 1:length(chans) + try + [EEG.chanlocs(chan).labels, chanlocs(chan).ref, chanlocs(chan).scale, chanlocs(chan).unit] = strread(hdr.channelinfos{chans(chan)}, '%s%s%s%s', 1, 'delimiter', ','); + catch % Octave compatible code below + str = hdr.channelinfos{chans(chan)}; + [EEG.chanlocs(chan).labels str] = strtok(str, ','); + [chanlocs(chan).ref str] = strtok(str, ','); + [chanlocs(chan).scale str] = strtok(str, ','); + [chanlocs(chan).unit str] = strtok(str, ','); + end; + EEG.chanlocs(chan).labels = char(EEG.chanlocs(chan).labels); + chanlocs(chan).scale = str2double(char(chanlocs(chan).scale)); +% chanlocs(chan).unit = native2unicode(double(char(chanlocs(chan).scale)), 'UTF-8'); +% EEG.chanlocs(chan).datachan = chans(chan); + end + if isempty([chanlocs.scale]) + chanlocs = rmfield(chanlocs, 'scale'); + end +end; +% [EEG.chanlocs.type] = deal([]); + +% Coordinates +if isfield(hdr, 'coordinates') + hdr.coordinates(end+1:length(chans)) = { [] }; + onenon0channel = 0; + for chan = 1:length(chans) + if ~isempty(hdr.coordinates{chans(chan)}) + if ismatlab, + [EEG.chanlocs(chan).sph_radius, theta, phi] = strread(hdr.coordinates{chans(chan)}, '%f%f%f', 'delimiter', ','); + else + str = hdr.coordinates{chans(chan)}; + [EEG.chanlocs(chan).sph_radius str] = strtok(str, ','); EEG.chanlocs(chan).sph_radius = str2num(EEG.chanlocs(chan).sph_radius); + [theta str] = strtok(str, ','); theta = str2num(theta); + [phi str] = strtok(str, ','); phi = str2num(phi); + end; + if EEG.chanlocs(chan).sph_radius == 0 && theta == 0 && phi == 0 + EEG.chanlocs(chan).sph_radius = []; + EEG.chanlocs(chan).sph_theta = []; + EEG.chanlocs(chan).sph_phi = []; + else + onenon0channel = 1; + EEG.chanlocs(chan).sph_theta = phi - 90 * sign(theta); + EEG.chanlocs(chan).sph_phi = -abs(theta) + 90; + end + end; + end + try, + if onenon0channel + [EEG.chanlocs, EEG.chaninfo] = pop_chanedit(EEG.chanlocs, 'convert', 'sph2topo'); + [EEG.chanlocs, EEG.chaninfo] = pop_chanedit(EEG.chanlocs, 'convert', 'sph2cart'); + end; + catch, end +end + +% Open data file and find the number of data points +% ------------------------------------------------- +disp('pop_loadbv(): reading EEG data'); +[IN, message] = fopen(fullfile(path, hdr.commoninfos.datafile), 'r'); +if IN == -1 + [IN, message] = fopen(fullfile(path, lower(hdr.commoninfos.datafile))); + if IN == -1 + error(message) + end; +end +if isfield( hdr.commoninfos, 'datapoints' ) && ~isempty( hdr.commoninfos.datapoints ) && isnumeric( str2double( hdr.commoninfos.datapoints ) ) && str2double( hdr.commoninfos.datapoints ) > 0 + hdr.commoninfos.datapoints = str2double(hdr.commoninfos.datapoints); +elseif strcmpi( hdr.commoninfos.dataformat, 'binary' ) + fseek( IN, 0, 'eof' ); + hdr.commoninfos.datapoints = ftell( IN ) / ( hdr.commoninfos.numberofchannels * bps ); + fseek( IN, 0, 'bof' ); +else + hdr.commoninfos.datapoints = NaN; +end + +if ~strcmpi(hdr.commoninfos.dataformat, 'binary') % ASCII + % tmppoint = hdr.commoninfos.datapoints; + tmpchan = fscanf(IN, '%s', 1); + + % AW: Determination of number of datapoints will not work for files without chanlabels and/or multiplexed dataformat. Suggest trusting in header. + % tmpdata = fscanf(IN, '%f', inf); + % hdr.commoninfos.datapoints = length(tmpdata); + % chanlabels = 1; + if isnan(str2double(tmpchan)) + % hdr.commoninfos.datapoints = hdr.commoninfos.datapoints+1; + chanlabels = 1; + else + chanlabels = 0; + end +end + +% Sample range +if ~exist('srange', 'var') || isempty(srange) + srange = [ 1 hdr.commoninfos.datapoints]; + EEG.pnts = hdr.commoninfos.datapoints; +elseif length(srange) == 1 + EEG.pnts = hdr.commoninfos.datapoints - srange(1) + 1; +else + EEG.pnts = srange(2) - srange(1) + 1; +end +if any(srange < 1) || any(srange > hdr.commoninfos.datapoints) + error('srange out of available data range'); +end + +% Read data +if strcmpi(hdr.commoninfos.dataformat, 'binary') + switch lower(hdr.commoninfos.dataorientation) + case 'multiplexed' + if EEG.nbchan == hdr.commoninfos.numberofchannels % Read all channels + fseek(IN, (srange(1) - 1) * EEG.nbchan * bps, 'bof'); + EEG.data = fread(IN, [EEG.nbchan, EEG.pnts], [binformat '=>float32']); + else % Read channel subset + EEG.data = repmat(single(0), [EEG.nbchan, EEG.pnts]); % Preallocate memory + for chan = 1:length(chans) + fseek(IN, (srange(1) - 1) * hdr.commoninfos.numberofchannels * bps + (chans(chan) - 1) * bps, 'bof'); + EEG.data(chan, :) = fread(IN, [1, EEG.pnts], [binformat '=>float32'], (hdr.commoninfos.numberofchannels - 1) * bps); + end + end + case 'vectorized' + if isequal(EEG.pnts, hdr.commoninfos.datapoints) && EEG.nbchan == hdr.commoninfos.numberofchannels % Read entire file + EEG.data = fread(IN, [EEG.pnts, EEG.nbchan], [binformat '=>float32']).'; + else % Read fraction of file + EEG.data = repmat(single(0), [EEG.nbchan, EEG.pnts]); % Preallocate memory + for chan = 1:length(chans) + fseek(IN, ((chans(chan) - 1) * hdr.commoninfos.datapoints + srange(1) - 1) * bps, 'bof'); + EEG.data(chan, :) = fread(IN, [1, EEG.pnts], [binformat '=>float32']); + end + end + otherwise + error('Unsupported data orientation') + end +else % ASCII data +% disp('If this function does not work, export your data in binary format'); +% EEG.data = repmat(single(0), [EEG.nbchan, EEG.pnts]); +% if strcmpi(lower(hdr.commoninfos.dataorientation), 'vectorized') +% count = 1; +% fseek(IN, 0, 'bof'); +% len = inf; +% for chan = 1:hdr.commoninfos.numberofchannels +% if chanlabels, tmpchan = fscanf(IN, '%s', 1); end; +% tmpdata = fscanf(IN, '%f', len); len = length(tmpdata); +% if ismember(chan, chans) +% EEG.data(count, :) = tmpdata(srange(1):srange(2))'; +% count = count + 1; +% end; +% end; +% elseif strcmpi(lower(hdr.commoninfos.dataorientation), 'multiplexed') +% % fclose(IN); +% % error('ASCII multiplexed reading not implemeted yet; export as a different format'); +% if EEG.nbchan == hdr.commoninfos.numberofchannels % Read all channels +% tmpchan= fgetl(IN); +% count = 1; +% while ~feof(IN) +% tmpstr = fgetl(IN); +% if ~isempty(tmpstr) +% temp_ind = tmpstr==','; +% tmpstr(temp_ind) = '.'; +% tmpdata = strread(tmpstr); +% EEG.data(:,count) = tmpdata'; +% count = count + 1; +% end; +% end; +% EEG.pnts = count - 1; +% else +% +% end; +% end; + + % Rewritten by AW, 2013-10-02. Old version by Arno did no longer work. MATLAB changes? + tmpdata = zeros([hdr.commoninfos.numberofchannels, hdr.commoninfos.datapoints], 'single'); + fseek(IN, 0, 'bof'); + switch lower(hdr.commoninfos.dataorientation) + + case 'vectorized' + if chanlabels || (isfield(hdr, 'asciiinfos') && isfield(hdr.asciiinfos, 'decimalsymbol') && ~strcmp(hdr.asciiinfos.decimalsymbol, '.')) % Read line by line + + for iChan = 1:hdr.commoninfos.numberofchannels + tmpstr = fgetl(IN); + if chanlabels + [tmpchan, count, errmsg, nextindex] = sscanf(tmpstr, '%s', 1); + tmpstr = tmpstr(nextindex:end); + end + if isfield(hdr, 'asciiinfos') && isfield(hdr.asciiinfos, 'decimalsymbol') && ~strcmp(hdr.asciiinfos.decimalsymbol, '.') + tmpdata(iChan, :) = sscanf(regexprep(tmpstr, hdr.asciiinfos.decimalsymbol, '.'), '%f', inf); + else + tmpdata(iChan, :) = sscanf(tmpstr, '%f', inf); + end + end + + else + tmpdata = fscanf(IN, '%f', inf); + tmpdata = reshape(tmpdata, hdr.commoninfos.datapoints, hdr.commoninfos.numberofchannels)'; + end + + case 'multiplexed' + if chanlabels + tmpchan = fgetl(IN); + end + if isfield(hdr, 'asciiinfos') && isfield(hdr.asciiinfos, 'decimalsymbol') && ~strcmp(hdr.asciiinfos.decimalsymbol, '.') % Read line by line + for iPnt = 1:hdr.commoninfos.datapoints + tmpstr = fgetl(IN); + tmpdata(:, iPnt) = sscanf(regexprep(tmpstr, hdr.asciiinfos.decimalsymbol, '.'), '%f', inf); + end + else + tmpdata = fscanf(IN, '%f', inf); + tmpdata = reshape(tmpdata, hdr.commoninfos.numberofchannels, hdr.commoninfos.datapoints); + end + + otherwise + error('Unknown data orientation') + + end + + EEG.data = tmpdata(chans, srange(1):srange(2)); + +end + +fclose(IN); +EEG.trials = 1; +EEG.xmin = 0; +EEG.xmax = (EEG.pnts - 1) / EEG.srate; + +% Convert to EEG.data to double for MATLAB < R14 +if str2double(version('-release')) < 14 + EEG.data = double(EEG.data); +end + +% Scale data +if exist('chanlocs', 'var') && isfield(chanlocs, 'scale') + disp('pop_loadbv(): scaling EEG data'); + for chan = 1:EEG.nbchan + if ~isnan(chanlocs(chan).scale) + EEG.data(chan, :) = EEG.data(chan, :) * chanlocs(chan).scale; + end; + end +end + +% Marker file +if isfield(hdr.commoninfos, 'markerfile') + disp('pop_loadbv(): reading marker file'); + MRK = readbvconf(path, hdr.commoninfos.markerfile); + + if hdr.commoninfos.datafile ~= MRK.commoninfos.datafile + disp('pop_loadbv() warning: data files in header and marker files inconsistent.'); + end + + % Marker infos + if isfield(MRK, 'markerinfos') + EEG.event = parsebvmrk(MRK); + + % Correct event latencies by first sample offset + tmpevent = EEG.event; + for index = 1:length(EEG.event) + tmpevent(index).latency = tmpevent(index).latency - srange(1) + 1; + end; + EEG.event = tmpevent; + + % Remove unreferenced events + EEG.event = EEG.event([tmpevent.latency] >= 1 & [tmpevent.latency] <= EEG.pnts); + + % Copy event structure to urevent structure + EEG.urevent = rmfield(EEG.event, 'urevent'); + + % find if boundaries at homogenous intervals + % ------------------------------------------ + tmpevent = EEG.event; + boundaries = strmatch('boundary', {tmpevent.type}); + boundlats = unique([tmpevent(boundaries).latency]); + if (isfield(hdr.commoninfos, 'segmentationtype') && (strcmpi(hdr.commoninfos.segmentationtype, 'markerbased') || strcmpi(hdr.commoninfos.segmentationtype, 'fixtime'))) && length(boundaries) > 1 && length(unique(diff([boundlats EEG.pnts + 1]))) == 1 + EEG.trials = length(boundlats); + EEG.pnts = EEG.pnts / EEG.trials; + EEG.event(boundaries) = []; + + % adding epoch field + % ------------------ + tmpevent = EEG.event; + for index = 1:length(EEG.event) + EEG.event(index).epoch = ceil(tmpevent(index).latency / EEG.pnts); + end + + % finding minimum time + % -------------------- + tles = strmatch('time 0', lower({tmpevent.code}))'; + if ~isempty(tles) + for iTLE = tles(:)' + EEG.event(iTLE).type ='TLE'; + end + EEG.xmin = -(tmpevent(tles(1)).latency - 1) / EEG.srate; + end + else + for index = 1:length(boundaries) + EEG.event(boundaries(index)).duration = NaN; + end; + end + end +end + +EEG.ref = 'common'; + +try + EEG = eeg_checkset(EEG); +catch +end + +if nargout == 2 + com = sprintf('EEG = pop_loadbv(''%s'', ''%s'', %s, %s);', path, hdrfile, mat2str(srange), mat2str(chans)); +end diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/pop_loadbva.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/pop_loadbva.m new file mode 100644 index 0000000000000000000000000000000000000000..6ba2090c1007e72512b0a2f682958af7f6ea2e31 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/pop_loadbva.m @@ -0,0 +1,140 @@ +% pop_loadbva() - import a Matlab file from brain vision analyser +% software. +% +% Usage: +% >> OUTEEG = pop_loadbva( filename ); +% +% Inputs: +% filename - file name +% +% Outputs: +% OUTEEG - EEGLAB data structure +% +% Author: Arnaud Delorme, SCCN/INC/UCSD, Dec 2003 +% +% See also: eeglab() + +% Copyright (C) 2003 Arnaud Delorme, Salk Institute, arno@salk.edu +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function [EEG, com] = pop_loadbva(filename) + + EEG = []; + com = ''; + + if nargin < 1 + [tmpfilename, filepath] = uigetfile('*.mat;*.MAT', 'Choose a Matlab file from Brain Vision Analyser -- pop_loadbva'); + if tmpfilename == 0 return; end; + filename = [ filepath tmpfilename ]; + end; + + disp('Importing data'); + EEG = eeg_emptyset; + bva = load(filename, '-mat'); + allfields = fieldnames(bva); + chanstruct = bva.Channels; + channames = lower({ chanstruct.Name }); + for index = 1:length(allfields) + switch lower(allfields{index}) + case { 't' 'markercount' 'markers' 'samplerate' 'segmentcount' 'channelcount' 'channels' }, + otherwise + count1 = strmatch(lower(allfields{index}), channames, 'exact'); + count2 = strmatch(lower(allfields{index}(2:end)), channames, 'exact'); + if ~isempty(count1) | ~isempty(count2) + count = [ count1 count2 ]; + count = count(1); + else + disp(['Warning: channel ''' lower(allfields{index}) ''' not in channel location structure']); + count = length(chanstruct)+1; + chanstruct(end+1).Name = allfields{index}; + chanstruct(end+1).Phi = []; + chanstruct(end+1).Theta = []; + chanstruct(end+1).Radius = []; + end; + if bva.SegmentCount > 1 + EEG.data(count,:,:) = getfield(bva, allfields{index})'; + bva = rmfield(bva, allfields{index}); + else + EEG.data(count,:) = getfield(bva, allfields{index}); + bva = rmfield(bva, allfields{index}); + end; + end; + end; + + EEG.nbchan = size(EEG.data,1); + EEG.srate = bva.SampleRate; + EEG.xmin = bva.t(1)/1000; + EEG.xmax = bva.t(end)/1000; + EEG.pnts = size(EEG.data,2); + EEG.trials = size(EEG.data,3); + EEG.setname = 'Brain Vision Analyzer file'; + EEG.comments = [ 'Original file: ' filename ]; + + % convert channel location structure + % ---------------------------------- + disp('Importing channel location information'); + for index = 1:length(chanstruct) + EEG.chanlocs(index).labels = chanstruct(index).Name; + if chanstruct(index).Radius ~= 0 + EEG.chanlocs(index).sph_theta_besa = chanstruct(index).Theta; + EEG.chanlocs(index).sph_phi_besa = chanstruct(index).Phi; + EEG.chanlocs(index).sph_radius = chanstruct(index).Radius; + else + EEG.chanlocs(index).sph_theta_besa = []; + EEG.chanlocs(index).sph_phi_besa = []; + EEG.chanlocs(index).sph_radius = []; + end; + end; + EEG.chanlocs = convertlocs(EEG.chanlocs, 'sphbesa2all'); + EEG.chanlocs = rmfield(EEG.chanlocs, 'sph_theta_besa'); + EEG.chanlocs = rmfield(EEG.chanlocs, 'sph_phi_besa'); + + % convert event information + % ------------------------- + disp('Importing events'); + index = 0; + if isfield(bva, 'Markers') + for index1 = 1:size(bva.Markers,1) + for index2 = 0:size(bva.Markers,2)-1 + if ~isempty(bva.Markers(index2*size(bva.Markers,1)+index1).Description) + index = index + 1; + EEG.event(index).type = bva.Markers(index2*size(bva.Markers,1)+index1).Description; + EEG.event(index).latency = bva.Markers(index2*size(bva.Markers,1)+index1).Position; + EEG.event(index).Points = bva.Markers(index2*size(bva.Markers,1)+index1).Points; + try + EEG.event(index).bvatype = bva.Markers(index2*size(bva.Markers,1)+index1).Type; + EEG.event(index).description = bva.Markers(index2*size(bva.Markers,1)+index1).Description; + catch, end; + try + EEG.event(index).chan = bva.Markers(index2*size(bva.Markers,1)+index1).Chan; + catch, end; + try + EEG.event(index).channelnumber = bva.Markers(index2*size(bva.Markers,1)+index1).ChannelNumber; + catch, end; + if bva.SegmentCount > 1 + EEG.event(index).epoch = index1; + EEG.event(index).latency = bva.Markers(index2*size(bva.Markers,1)+index1).Position+(index1-1)*EEG.pnts; + else + EEG.event(index).latency = bva.Markers(index2*size(bva.Markers,1)+index1).Position; + end; + end; + end; + end; + end + EEG = eeg_checkset(EEG, 'makeur'); + EEG = eeg_checkset(EEG, 'eventconsistency'); + + com = sprintf('EEG = pop_loadbva(''%s'');', filename); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/pop_writebva.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/pop_writebva.m new file mode 100644 index 0000000000000000000000000000000000000000..1d91be598704fe060382308ad7f19d4535cb20f6 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/pop_writebva.m @@ -0,0 +1,204 @@ +% pop_writebva() - export EEG dataset +% +% Usage: +% >> EEG = pop_writebva(EEG); % a window pops up +% >> EEG = pop_writebva(EEG, filename); +% +% Inputs: +% EEG - eeglab dataset +% filename - file name +% +% Author: Arnaud Delorme, SCCN, INC, UCSD, 2005- + +% Copyright (C) 2005, Arnaud Delorme, SCCN, INC, UCSD, arno@salk.edu +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function com = pop_writebva(EEG, filename); + +com = ''; +if nargin < 1 + help pop_writebva; + return; +end; + +if nargin < 2 + [filename, filepath] = uiputfile('*', 'Output file'); + if length( filepath ) == 0 return; end; + filename = [ filepath filename ]; +end; + +% remove extension if any +% ----------------------- +posdot = find(filename == '.'); +if ~isempty(posdot), filename = filename(1:posdot(end)-1); end; + +% open output file +% ---------------- +fid1 = fopen( [ filename '.vhdr' ], 'w' ); +fid2 = fopen( [ filename '.vmrk' ], 'w' ); +fid3 = fopen( [ filename '.dat' ], 'wb', 'ieee-le'); +[ tmppath basename ] = fileparts( filename ); + +% write data +% ---------- +for index = 1:EEG.nbchan + fwrite(fid3, EEG.data(index,:), 'float' ); +end; + +% write header +% ------------ +fprintf(fid1, 'Brain Vision Data Exchange Header File Version 1.0\n'); +fprintf(fid1, '; Data created from the EEGLAB software\n'); +fprintf(fid1, '\n'); +fprintf(fid1, '[Common Infos]\n'); +fprintf(fid1, 'DataFile=%s\n', [ basename '.dat' ]); +if ~isempty(EEG.event) + fprintf(fid1, 'MarkerFile=%s\n', [ basename '.vmrk' ]); +end; +fprintf(fid1, 'DataFormat=BINARY\n'); +fprintf(fid1, '; Data orientation: VECTORIZED=ch1,pt1, ch1,pt2..., MULTIPLEXED=ch1,pt1, ch2,pt1 ...\n'); +fprintf(fid1, 'DataOrientation=VECTORIZED\n'); +fprintf(fid1, 'DataType=TIMEDOMAIN\n'); +fprintf(fid1, 'NumberOfChannels=%d\n', EEG.nbchan); +fprintf(fid1, 'DataPoints=%d\n', EEG.pnts*EEG.trials); +fprintf(fid1, '; Sampling interval in microseconds if time domain (convert to Hertz:\n'); +fprintf(fid1, '; 1000000 / SamplingInterval) or in Hertz if frequency domain:\n'); +fprintf(fid1, 'SamplingInterval=%d\n', 1000000/EEG.srate); +if EEG.trials > 1 + fprintf(fid1, 'SegmentationType=MARKERBASED\n'); +end; +fprintf(fid1, '\n'); +fprintf(fid1, '[Binary Infos]\n'); +fprintf(fid1, 'BinaryFormat=IEEE_FLOAT_32\n'); +fprintf(fid1, '\n'); +if ~isempty(EEG.chanlocs) + fprintf(fid1, '[Channel Infos]\n'); + fprintf(fid1, '; Each entry: Ch=,,\n'); + fprintf(fid1, '; ,=,,\n'); + % loc = convertlocs(EEG.chanlocs, 'sph2sphbesa'); + % for index = 1:EEG.nbchan + % fprintf(fid1, 'Ch%d=%d,%d,%d\n', index, round(loc(index).sph_theta_besa), ... + % round(loc(index).sph_phi_besa), 0); + % end; + %end; +end; + +% export event information +% ------------------------ +if ~isempty(EEG.event) + fprintf(fid2, 'Brain Vision Data Exchange Marker File, Version 1.0\n'); + fprintf(fid2, '; Data created from the EEGLAB software\n'); + fprintf(fid2, '; The channel numbers are related to the channels in the exported file.\n'); + fprintf(fid2, '\n'); + fprintf(fid2, '[Common Infos]\n'); + fprintf(fid2, 'DataFile=%s\n', [ basename '.dat' ]); + fprintf(fid2, '\n'); + fprintf(fid2, '[Marker Infos]\n'); + fprintf(fid2, '; Each entry: Mk=,,,\n'); + fprintf(fid2, '; , ,\n'); + fprintf(fid2, '; \n'); + fprintf(fid2, '; Fields are delimited by commas, some fields might be omited (empty).\n'); + fprintf(fid2, '; Commas in type or description text are coded as "\1".\n'); + + % rename type and comments + % ------------------------ + for index = 1:length(EEG.event) + EEG.event(index).comment = EEG.event(index).type; + EEG.event(index).type = 'Stimulus'; + end; + + % make event cell array + % --------------------- + for index = 1:EEG.trials + EEG.event(end+1).type = 'New Segment'; + EEG.event(end ).latency = (index-1)*EEG.pnts+1; + end; + tmpevent = EEG.event; + [tmp latorder ] = sort( [ tmpevent.latency ] ); + EEG.event = EEG.event(latorder); + + % Recode boundary events + % ---------------------- + bndArray = find(strcmp('boundary', {tmpevent.comment})); % Find boundary events + isDupArray = ismember([tmpevent(bndArray).latency], [tmpevent(strcmp('New Segment', {tmpevent.type})).latency]); % Find already existing New Segment events with identical latency + notduplist = bndArray(~isDupArray); + duplist = bndArray(isDupArray); + for index = 1:length(notduplist) + EEG.event(notduplist(index)).type = 'New Segment'; % Recode boundary event type + EEG.event(notduplist(index)).comment = ''; % Recode boundary event comment + end; + EEG.event(duplist) = []; % Remove duplicate New Segment events + + % rename latency events + % --------------------- + time0ind = []; + for index = 1:length(EEG.event) + if mod( EEG.event(index).latency, EEG.pnts) == -EEG.xmin*EEG.srate+1 + time0ind = [ time0ind index ]; + end; + end; + for index = length(time0ind):-1:1 + EEG.event(time0ind(index)+1:end+1) = EEG.event(time0ind(index):end); + EEG.event(time0ind(index)).type = 'Time 0'; + EEG.event(time0ind(index)).comment = ''; + end; + + % write events + % ------------ + e = EEG.event; + for index = 1:length(e) + + % duration field + % -------------- + if isfield(e, 'duration') + if ~isempty(e(index).duration) + tmpdur = e(index).duration; + else tmpdur = 0; + end; + else tmpdur = 0; + end; + + % comment field + % ------------- + if isfield(e, 'comment') + if ~isempty(e(index).comment) + tmpcom = e(index).comment; + else tmpcom = ''; + end; + else tmpcom = num2str(e(index).type); + end; + + fprintf(fid2, 'Mk%d=%s,%s,%d,%d,0,0\n', index, num2str(e(index).type), num2str(tmpcom), round(e(index).latency), tmpdur); + end; +end +fclose(fid1); +fclose(fid2); +fclose(fid3); + +com = sprintf('pop_writebva(%s,''%s'');', inputname(1), filename); +return; diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/readbvconf.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/readbvconf.m new file mode 100644 index 0000000000000000000000000000000000000000..d79984c7b8301b82250ae1900f02f01e0a7841ad --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/readbvconf.m @@ -0,0 +1,93 @@ +% readbvconf() - read Brain Vision Data Exchange format configuration +% file +% +% Usage: +% >> CONF = readbvconf(pathname, filename); +% +% Inputs: +% pathname - path to file +% filename - filename +% +% Outputs: +% CONF - structure configuration +% +% Author: Andreas Widmann, University of Leipzig, 2007 + +% Copyright (C) 2007 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +% $Id: readbvconf.m 44 2009-11-12 02:00:56Z arnodelorme $ + +function CONF = readbvconf(pathname, filename) + +if nargin < 2 + error('Not enough input arguments'); +end + +% Open and read file +[IN, message] = fopen(fullfile(pathname, filename), 'r'); +if IN == -1 + [IN, message] = fopen(fullfile(pathname, lower(filename))); + if IN == -1 + error(message) + end; +end +raw={}; +while ~feof(IN) + raw = [raw; {fgetl(IN)}]; +end +fclose(IN); + +% Remove comments and empty lines +raw(strmatch(';', raw)) = []; +raw(cellfun('isempty', raw) == true) = []; + +% Find sections +sectionArray = [strmatch('[', raw)' length(raw) + 1]; +for iSection = 1:length(sectionArray) - 1 + + % Convert section name + tmpstr = deblank(raw{sectionArray(iSection)}); + fieldName = lower(tmpstr(2:end-1)); + %fieldName = lower(char(strread(tmpstr(2:end), '[%s', 'delimiter', ']'))); + fieldName(isspace(fieldName) == true) = []; + + % Fill structure with parameter value pairs + switch fieldName + case {'commoninfos' 'binaryinfos' 'asciiinfos'} + for line = sectionArray(iSection) + 1:sectionArray(iSection + 1) - 1 + splitArray = strfind(raw{line}, '='); + CONF.(fieldName).(lower(raw{line}(1:splitArray(1) - 1))) = raw{line}(splitArray(1) + 1:end); + end + case {'channelinfos' 'coordinates'} + for line = sectionArray(iSection) + 1:sectionArray(iSection + 1) - 1 + splitArray = strfind(raw{line}, '='); + CONF.(fieldName)(str2double(raw{line}(3:splitArray(1) - 1))) = {raw{line}(splitArray(1) + 1:end)}; + end + case {'markerinfos'} % Allow discontinuity for markers (but not channelinfos and coordinates!) + for line = sectionArray(iSection) + 1:sectionArray(iSection + 1) - 1 + splitArray = strfind(raw{line}, '='); + CONF.(fieldName)(line - sectionArray(iSection), :) = {raw{line}(splitArray(1) + 1:end) str2double(raw{line}(3:splitArray(1) - 1))}; + end + if ~all(1:size(CONF.(fieldName), 1) == [CONF.(fieldName){:, 2}]) + warning('Marker number discontinuity.') + end + case 'comment' + CONF.(fieldName) = raw(sectionArray(iSection) + 1:sectionArray(iSection + 1) - 1); + otherwise + fprintf('Unrecognized entry: %s\n', fieldName); + end +end diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/README.txt b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..d0db488195f44e7d9c2d6c168148558d470968f5 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/README.txt @@ -0,0 +1,2 @@ +v2.3 versus v2.2 +- added the function adjustcylinder2.m diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/adjustcylinder2.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/adjustcylinder2.m new file mode 100644 index 0000000000000000000000000000000000000000..5c1655236b5b2856e7517b5c054dd31b0ee67a38 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/adjustcylinder2.m @@ -0,0 +1,60 @@ +% adjustcylinder() - Adjust 3d object coordinates to match a pair of points +% +% Usage: +% >> [x y z] = adjustcylinder( x, y, z, pos1, pos2); +% +% Inputs: +% x,y,z - 3-D point coordinates +% pos1 - position of first point [x y z] +% pos2 - position of second point [x y z] +% +% Outputs: +% x,y,z - updated 3-D point coordinates +% +% Author: Arnaud Delorme, CNL / Salk Institute, 30 Mai 2003 + +% Copyright (C) 2003 Arnaud Delorme +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function [x, y, z] = adjustcylinder2( h, pos1, pos2); + + % figure; plot3(x(2,:),y(2,:),z(2,:)); [ x(2,:)' y(2,:)' z(2,:)'] + + % stretch z coordinates to match for vector length + % ------------------------------------------------ + dist = sqrt(sum((pos1-pos2).^2)); + z = get(h, 'zdata'); + zrange = max(z(:)) - min(z(:)); + set(h, 'zdata', get(h, 'zdata') /zrange*dist); + + % rotate in 3-D to match vector angle [0 0 1] -> vector angle) + % only have to rotate in the x-z and y-z plane + % -------------------------------------------- + vectrot = [ pos2(1)-pos1(1) pos2(2)-pos1(2) pos2(3)-pos1(3)]; + [thvect phivect] = cart2sph( vectrot(1), vectrot(2), vectrot(3) ); + + rotatematlab(h, [0 0 1], thvect/pi*180, [0 0 0]); + rotatematlab(h, [thvect+pi/2 0]/pi*180, (pi/2-phivect)/pi*180, [0 0 0]); + + x = get(h, 'xdata') + pos1(1); + y = get(h, 'ydata') + pos1(2); + z = get(h, 'zdata') + pos1(3); + + set(h, 'xdata', x); + set(h, 'ydata', y); + set(h, 'zdata', z); + return; + diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/channelselection.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/channelselection.m new file mode 100644 index 0000000000000000000000000000000000000000..5cd4567ab8d3898f6ad7c3b8574f1606e5d389e3 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/channelselection.m @@ -0,0 +1,310 @@ +function [channel] = channelselection(channel, datachannel) + +% CHANNELSELECTION for EEG and MEG labels +% +% This function translates the user-specified list of channels into channel +% labels as they occur in the data. This channel selection procedure can +% be used throughout fieldtrip. +% +% You can specify a mixture of real channel labels and of special strings, +% or index numbers that will be replaced by the corresponding channel +% labels. Channels that are not present in the raw datafile are +% automatically removed from the channel list. +% +% E.g. +% 'gui' a graphical user interface will pop up to select the channels +% 'all' is replaced by all channels in the datafile +% 'MEG' is replaced by all channels in the CTF datafile starting with 'M' +% 'EEG' is replaced by all channels in the CTF datafile starting with 'EEG' +% 'EEG1020' is replaced by 'Fp1', 'Fpz', 'Fp2', 'F7', 'F3', ... +% 'EOG' is replaced by all recognized EOG channels +% 'EMG' is replaced by all channels in the datafile starting with 'EMG' +% 'lfp' is replaced by all channels in the datafile starting with 'lfp' +% 'mua' is replaced by all channels in the datafile starting with 'mua' +% 'spike' is replaced by all channels in the datafile starting with 'spike' +% 10 is replaced by the 10th channel in the datafile +% +% Other channel groups are +% 'EEG1010' with approximately 90 electrodes +% 'EEG1005' with approximately 350 electrodes +% 'EEGCHWILLA' for Dorothee Chwilla's electrode caps (used at the NICI) +% 'EEGBHAM' for the 128 channel EEG system used in Birmingham +% 'EEGREF' for mastoid and ear electrodes (M1, M2, LM, RM, A1, A2) +% 'MZ' for MEG central +% 'ML' for MEG left +% 'MR' for MEG right +% 'MLx', 'MRx' and 'MZx' with x=C,F,O,P,T for left/right central, frontal, +% occipital, parietal and temporal +% +% You can also exclude channels or channel groups using the following syntax +% {'all', '-POz', '-Fp1', -EOG'} + +% Copyright (C) 2003-2007, Robert Oostenveld +% +% $Log: channelselection.m,v $ +% Revision 1.1 2009/01/30 04:02:01 arno +% *** empty log message *** +% +% Revision 1.19 2007/05/30 13:22:01 roboos +% concatenate indices as column instead of row vector +% +% Revision 1.18 2007/01/22 10:32:28 roboos +% added 'gui' option for graphical user interface, thanks to Vladimir +% +% Revision 1.17 2006/06/06 16:28:54 ingnie +% added option channel is numeric; channel index replaced by channel name +% +% Revision 1.16 2006/05/03 15:08:56 roboos +% already remove double channels prior to the translation of the channel groups +% +% Revision 1.15 2006/03/23 22:26:18 roboos +% added channel groups for lfp, mua and spike +% +% Revision 1.14 2005/12/16 14:03:20 roboos +% added two VEOG channels +% added the EEGBHAM channel group +% +% Revision 1.13 2005/09/14 12:32:24 roboos +% small change in help +% +% Revision 1.12 2005/05/23 09:33:43 roboos +% return immediately if input is empty +% +% Revision 1.11 2004/10/22 16:10:07 roboos +% replaced all occurences of strmatch with strncmp, which runs much faster +% +% Revision 1.10 2004/03/10 15:03:08 roberto +% made selection of EOG channels more general +% +% Revision 1.9 2004/02/24 17:21:34 roberto +% slightly different implementation to undo the channel name sorting +% +% Revision 1.8 2004/02/24 16:53:44 roberto +% added 2 lines that unbdo the alphabetical sorting, the labels are now +% sorted according to their occurence in the data +% +% Revision 1.7 2004/01/26 11:54:47 roberto +% fixed recursion bug in bad channels +% added a line to remove double occurences of channels +% +% Revision 1.6 2004/01/22 21:41:12 roberto +% added support for excluding bad channels or channel groups +% +% Revision 1.5 2004/01/15 17:01:35 roberto +% added channel groups for MZx, with x=f,c,p,o +% +% Revision 1.4 2004/01/09 15:17:33 roberto +% added EEGCHWILLA as channel group (for NICI/Eric Maris) +% added LM and RM to to reference electrodes +% +% Revision 1.3 2003/12/08 12:32:10 roberto +% added 2 channels for eog +% +% Revision 1.2 2003/11/12 07:50:14 roberto +% added separate group for EEG reference electrodes (mastoid, ear) +% +% Revision 1.1 2003/10/28 15:09:27 roberto +% previously known under misc/translate_channel_list.m +% added label to EOG group +% +% Revision 1.2 2003/09/11 21:55:32 roberto +% added labels for 10-10 and for 10-5 (5%) electrode system +% +% Revision 1.1 2003/06/16 15:32:58 roberto +% new implementation, starting from code in preprocessing +% + +if any(size(channel) == 0) + % there is nothing to do if it is empty + return +end + +if isnumeric(channel) + % change index into channelname + channel = datachannel(channel); + return +end + +if ~iscell(channel) + % ensure that a single input argument like 'all' also works + channel = {channel}; +end + +% ensure that both inputs are column vectors +channel = channel(:); +datachannel = datachannel(:); + +% remove channels that occur more than once, this sorts the channels alphabetically +[channel, indx] = unique(channel); +% undo the sorting, make the order identical to that of the data channels +[dum, indx] = sort(indx); +channel = channel(indx); + +% define the known groups with channel labels +labelall = datachannel; +label1020 = {'Fp1', 'Fpz', 'Fp2', 'F7', 'F3', 'Fz', 'F4', 'F8', 'T7', 'C3', 'Cz', 'C4', 'T8', 'P7', 'P3', 'Pz', 'P4', 'P8', 'O1', 'Oz', 'O2'}'; +label1010 = {'Fp1', 'Fpz', 'Fp2', 'AF9', 'AF7', 'AF5', 'AF3', 'AF1', 'AFz', 'AF2', 'AF4', 'AF6', 'AF8', 'AF10', 'F9', 'F7', 'F5', 'F3', 'F1', 'Fz', 'F2', 'F4', 'F6', 'F8', 'F10', 'FT9', 'FT7', 'FC5', 'FC3', 'FC1', 'FCz', 'FC2', 'FC4', 'FC6', 'FT8', 'FT10', 'T9', 'T7', 'C5', 'C3', 'C1', 'Cz', 'C2', 'C4', 'C6', 'T8', 'T10', 'TP9', 'TP7', 'CP5', 'CP3', 'CP1', 'CPz', 'CP2', 'CP4', 'CP6', 'TP8', 'TP10', 'P9', 'P7', 'P5', 'P3', 'P1', 'Pz', 'P2', 'P4', 'P6', 'P8', 'P10', 'PO9', 'PO7', 'PO5', 'PO3', 'PO1', 'POz', 'PO2', 'PO4', 'PO6', 'PO8', 'PO10', 'O1', 'Oz', 'O2', 'I1', 'Iz', 'I2'}'; +label1005 = {'Fp1', 'Fpz', 'Fp2', 'AF9', 'AF7', 'AF5', 'AF3', 'AF1', 'AFz', 'AF2', 'AF4', 'AF6', 'AF8', 'AF10', 'F9', 'F7', 'F5', 'F3', 'F1', 'Fz', 'F2', 'F4', 'F6', 'F8', 'F10', 'FT9', 'FT7', 'FC5', 'FC3', 'FC1', 'FCz', 'FC2', 'FC4', 'FC6', 'FT8', 'FT10', 'T9', 'T7', 'C5', 'C3', 'C1', 'Cz', 'C2', 'C4', 'C6', 'T8', 'T10', 'TP9', 'TP7', 'CP5', 'CP3', 'CP1', 'CPz', 'CP2', 'CP4', 'CP6', 'TP8', 'TP10', 'P9', 'P7', 'P5', 'P3', 'P1', 'Pz', 'P2', 'P4', 'P6', 'P8', 'P10', 'PO9', 'PO7', 'PO5', 'PO3', 'PO1', 'POz', 'PO2', 'PO4', 'PO6', 'PO8', 'PO10', 'O1', 'Oz', 'O2', 'I1', 'Iz', 'I2', 'AFp9h', 'AFp7h', 'AFp5h', 'AFp3h', 'AFp1h', 'AFp2h', 'AFp4h', 'AFp6h', 'AFp8h', 'AFp10h', 'AFF9h', 'AFF7h', 'AFF5h', 'AFF3h', 'AFF1h', 'AFF2h', 'AFF4h', 'AFF6h', 'AFF8h', 'AFF10h', 'FFT9h', 'FFT7h', 'FFC5h', 'FFC3h', 'FFC1h', 'FFC2h', 'FFC4h', 'FFC6h', 'FFT8h', 'FFT10h', 'FTT9h', 'FTT7h', 'FCC5h', 'FCC3h', 'FCC1h', 'FCC2h', 'FCC4h', 'FCC6h', 'FTT8h', 'FTT10h', 'TTP9h', 'TTP7h', 'CCP5h', 'CCP3h', 'CCP1h', 'CCP2h', 'CCP4h', 'CCP6h', 'TTP8h', 'TTP10h', 'TPP9h', 'TPP7h', 'CPP5h', 'CPP3h', 'CPP1h', 'CPP2h', 'CPP4h', 'CPP6h', 'TPP8h', 'TPP10h', 'PPO9h', 'PPO7h', 'PPO5h', 'PPO3h', 'PPO1h', 'PPO2h', 'PPO4h', 'PPO6h', 'PPO8h', 'PPO10h', 'POO9h', 'POO7h', 'POO5h', 'POO3h', 'POO1h', 'POO2h', 'POO4h', 'POO6h', 'POO8h', 'POO10h', 'OI1h', 'OI2h', 'Fp1h', 'Fp2h', 'AF9h', 'AF7h', 'AF5h', 'AF3h', 'AF1h', 'AF2h', 'AF4h', 'AF6h', 'AF8h', 'AF10h', 'F9h', 'F7h', 'F5h', 'F3h', 'F1h', 'F2h', 'F4h', 'F6h', 'F8h', 'F10h', 'FT9h', 'FT7h', 'FC5h', 'FC3h', 'FC1h', 'FC2h', 'FC4h', 'FC6h', 'FT8h', 'FT10h', 'T9h', 'T7h', 'C5h', 'C3h', 'C1h', 'C2h', 'C4h', 'C6h', 'T8h', 'T10h', 'TP9h', 'TP7h', 'CP5h', 'CP3h', 'CP1h', 'CP2h', 'CP4h', 'CP6h', 'TP8h', 'TP10h', 'P9h', 'P7h', 'P5h', 'P3h', 'P1h', 'P2h', 'P4h', 'P6h', 'P8h', 'P10h', 'PO9h', 'PO7h', 'PO5h', 'PO3h', 'PO1h', 'PO2h', 'PO4h', 'PO6h', 'PO8h', 'PO10h', 'O1h', 'O2h', 'I1h', 'I2h', 'AFp9', 'AFp7', 'AFp5', 'AFp3', 'AFp1', 'AFpz', 'AFp2', 'AFp4', 'AFp6', 'AFp8', 'AFp10', 'AFF9', 'AFF7', 'AFF5', 'AFF3', 'AFF1', 'AFFz', 'AFF2', 'AFF4', 'AFF6', 'AFF8', 'AFF10', 'FFT9', 'FFT7', 'FFC5', 'FFC3', 'FFC1', 'FFCz', 'FFC2', 'FFC4', 'FFC6', 'FFT8', 'FFT10', 'FTT9', 'FTT7', 'FCC5', 'FCC3', 'FCC1', 'FCCz', 'FCC2', 'FCC4', 'FCC6', 'FTT8', 'FTT10', 'TTP9', 'TTP7', 'CCP5', 'CCP3', 'CCP1', 'CCPz', 'CCP2', 'CCP4', 'CCP6', 'TTP8', 'TTP10', 'TPP9', 'TPP7', 'CPP5', 'CPP3', 'CPP1', 'CPPz', 'CPP2', 'CPP4', 'CPP6', 'TPP8', 'TPP10', 'PPO9', 'PPO7', 'PPO5', 'PPO3', 'PPO1', 'PPOz', 'PPO2', 'PPO4', 'PPO6', 'PPO8', 'PPO10', 'POO9', 'POO7', 'POO5', 'POO3', 'POO1', 'POOz', 'POO2', 'POO4', 'POO6', 'POO8', 'POO10', 'OI1', 'OIz', 'OI2'}'; +labelchwilla = {'Fz', 'Cz', 'Pz', 'F7', 'F8', 'LAT', 'RAT', 'LT', 'RT', 'LTP', 'RTP', 'OL', 'OR', 'FzA', 'Oz', 'F7A', 'F8A', 'F3A', 'F4A', 'F3', 'F4', 'P3', 'P4', 'T5', 'T6', 'P3P', 'P4P'}'; +labelbham = {'P9', 'PPO9h', 'PO7', 'PPO5h', 'PPO3h', 'PO5h', 'POO9h', 'PO9', 'I1', 'OI1h', 'O1', 'POO1', 'PO3h', 'PPO1h', 'PPO2h', 'POz', 'Oz', 'Iz', 'I2', 'OI2h', 'O2', 'POO2', 'PO4h', 'PPO4h', 'PO6h', 'POO10h', 'PO10', 'PO8', 'PPO6h', 'PPO10h', 'P10', 'P8', 'TPP9h', 'TP7', 'TTP7h', 'CP5', 'TPP7h', 'P7', 'P5', 'CPP5h', 'CCP5h', 'CP3', 'P3', 'CPP3h', 'CCP3h', 'CP1', 'P1', 'Pz', 'CPP1h', 'CPz', 'CPP2h', 'P2', 'CPP4h', 'CP2', 'CCP4h', 'CP4', 'P4', 'P6', 'CPP6h', 'CCP6h', 'CP6', 'TPP8h', 'TP8', 'TPP10h', 'T7', 'FTT7h', 'FT7', 'FC5', 'FCC5h', 'C5', 'C3', 'FCC3h', 'FC3', 'FC1', 'C1', 'CCP1h', 'Cz', 'FCC1h', 'FCz', 'FFC1h', 'Fz', 'FFC2h', 'FC2', 'FCC2h', 'CCP2h', 'C2', 'C4', 'FCC4h', 'FC4', 'FC6', 'FCC6h', 'C6', 'TTP8h', 'T8', 'FTT8h', 'FT8', 'FT9', 'FFT9h', 'F7', 'FFT7h', 'FFC5h', 'F5', 'AFF7h', 'AF7', 'AF5h', 'AFF5h', 'F3', 'FFC3h', 'F1', 'AF3h', 'Fp1', 'Fpz', 'Fp2', 'AFz', 'AF4h', 'F2', 'FFC4h', 'F4', 'AFF6h', 'AF6h', 'AF8', 'AFF8h', 'F6', 'FFC6h', 'FFT8h', 'F8', 'FFT10h', 'FT10'}; +labelref = {'M1', 'M2', 'LM', 'RM', 'A1', 'A2'}'; +labeleog = datachannel(strncmp('EOG', datachannel, length('EOG'))); % anything that starts with EOG +labeleog = {labeleog{:} 'HEOG', 'VEOG', 'VEOG-L', 'VEOG-R'}'; % or any of these +labelemg = datachannel(strncmp('EMG', datachannel, length('EMG'))); +labeleeg = datachannel(strncmp('EEG', datachannel, length('EEG'))); +labelmeg = datachannel(strncmp('M' , datachannel, length('M' ))); % all MEG channels start with "M" +labelmz = datachannel(strncmp('MZ' , datachannel, length('MZ' ))); % central MEG channels +labelml = datachannel(strncmp('ML' , datachannel, length('ML' ))); % left MEG channels +labelmr = datachannel(strncmp('MR' , datachannel, length('MR' ))); % right MEG channels +labelmlc = datachannel(strncmp('MLC', datachannel, length('MLC'))); +labelmlf = datachannel(strncmp('MLF', datachannel, length('MLF'))); +labelmlo = datachannel(strncmp('MLO', datachannel, length('MLO'))); +labelmlp = datachannel(strncmp('MLP', datachannel, length('MLP'))); +labelmlt = datachannel(strncmp('MLT', datachannel, length('MLT'))); +labelmrc = datachannel(strncmp('MRC', datachannel, length('MRC'))); +labelmrf = datachannel(strncmp('MRF', datachannel, length('MRF'))); +labelmro = datachannel(strncmp('MRO', datachannel, length('MRO'))); +labelmrp = datachannel(strncmp('MRP', datachannel, length('MRP'))); +labelmrt = datachannel(strncmp('MRT', datachannel, length('MRT'))); +labelmzc = datachannel(strncmp('MZC', datachannel, length('MZC'))); +labelmzf = datachannel(strncmp('MZF', datachannel, length('MZF'))); +labelmzo = datachannel(strncmp('MZO', datachannel, length('MZO'))); +labelmzp = datachannel(strncmp('MZP', datachannel, length('MZP'))); +labellfp = datachannel(strncmp('lfp', datachannel, length('lfp'))); +labelmua = datachannel(strncmp('mua', datachannel, length('mua'))); +labelspike = datachannel(strncmp('spike', datachannel, length('spike'))); + +% figure out if there are bad channels or channel groups that should be excluded +findbadchannel = strncmp('-', channel, length('-')); % bad channels start with '-' +badchannel = channel(findbadchannel); +if ~isempty(badchannel) + for i=1:length(badchannel) + badchannel{i} = badchannel{i}(2:end); % remove the '-' from the channel label + end + badchannel = channelselection(badchannel, datachannel); % support exclusion of channel groups + channel(findbadchannel) = []; % remove them from the channels to be processed +end + +% determine if any of the known groups is mentioned in the channel list +findall = find(strcmp(channel, 'all')); +findmeg = find(strcmp(channel, 'MEG')); +findemg = find(strcmp(channel, 'EMG')); +findeeg = find(strcmp(channel, 'EEG')); +findeeg1020 = find(strcmp(channel, 'EEG1020')); +findeeg1010 = find(strcmp(channel, 'EEG1010')); +findeeg1005 = find(strcmp(channel, 'EEG1005')); +findeegchwilla = find(strcmp(channel, 'EEGCHWILLA')); +findeegbham = find(strcmp(channel, 'EEGBHAM')); +findeegref = find(strcmp(channel, 'EEGREF')); +findeog = find(strcmp(channel, 'EOG')); +findmz = find(strcmp(channel, 'MZ' )); +findml = find(strcmp(channel, 'ML' )); +findmr = find(strcmp(channel, 'MR' )); +findmlc = find(strcmp(channel, 'MLC')); +findmlf = find(strcmp(channel, 'MLF')); +findmlo = find(strcmp(channel, 'MLO')); +findmlp = find(strcmp(channel, 'MLP')); +findmlt = find(strcmp(channel, 'MLT')); +findmrc = find(strcmp(channel, 'MRC')); +findmrf = find(strcmp(channel, 'MRF')); +findmro = find(strcmp(channel, 'MRO')); +findmrp = find(strcmp(channel, 'MRP')); +findmrt = find(strcmp(channel, 'MRT')); +findmzc = find(strcmp(channel, 'MZC')); +findmzf = find(strcmp(channel, 'MZF')); +findmzo = find(strcmp(channel, 'MZO')); +findmzp = find(strcmp(channel, 'MZP')); +findlfp = find(strcmp(channel, 'lfp')); +findmua = find(strcmp(channel, 'mua')); +findspike = find(strcmp(channel, 'spike')); +findgui = find(strcmp(channel, 'gui')); + +% remove any occurences of groups in the channel list +channel([ + findall + findmeg + findemg + findeeg + findeeg1020 + findeeg1010 + findeeg1005 + findeegchwilla + findeegbham + findeegref + findeog + findmz + findml + findmr + findmlc + findmlf + findmlo + findmlp + findmlt + findmrc + findmrf + findmro + findmrp + findmrt + findmzc + findmzf + findmzo + findmzp + findlfp + findmua + findspike + findgui +]) = []; + +% add the full channel labels to the channel list +if findall, channel = [channel; labelall]; end +if findmeg, channel = [channel; labelmeg]; end +if findemg, channel = [channel; labelemg]; end +if findeeg, channel = [channel; labeleeg]; end +if findeeg1020, channel = [channel; label1020]; end +if findeeg1010, channel = [channel; label1010]; end +if findeeg1005, channel = [channel; label1005]; end +if findeegchwilla, channel = [channel; labelchwilla]; end +if findeegbham, channel = [channel; labelbham]; end +if findeegref, channel = [channel; labelref]; end +if findeog, channel = [channel; labeleog]; end +if findmz , channel = [channel; labelmz ]; end +if findml , channel = [channel; labelml ]; end +if findmr , channel = [channel; labelmr ]; end +if findmlc, channel = [channel; labelmlc]; end +if findmlf, channel = [channel; labelmlf]; end +if findmlo, channel = [channel; labelmlo]; end +if findmlp, channel = [channel; labelmlp]; end +if findmlt, channel = [channel; labelmlt]; end +if findmrc, channel = [channel; labelmrc]; end +if findmrf, channel = [channel; labelmrf]; end +if findmro, channel = [channel; labelmro]; end +if findmrp, channel = [channel; labelmrp]; end +if findmrt, channel = [channel; labelmrt]; end +if findmzc, channel = [channel; labelmzc]; end +if findmzf, channel = [channel; labelmzf]; end +if findmzo, channel = [channel; labelmzo]; end +if findmzp, channel = [channel; labelmzp]; end +if findlfp, channel = [channel; labellfp]; end +if findmua, channel = [channel; labelmua]; end +if findspike, channel = [channel; labelspike]; end + +% remove channel labels that have been excluded by the user +badindx = match_str(channel, badchannel); +channel(badindx) = []; + +% remove channel labels that are not present in the data +chanindx = match_str(channel, datachannel); + +channel = channel(chanindx); + +if findgui + indx = select_channel_list(datachannel, match_str(datachannel, channel), 'Select channels'); + channel = datachannel(indx); +end + +% remove channels that occur more than once, this sorts the channels alphabetically +[channel, indx] = unique(channel); + +% undo the sorting, make the order identical to that of the data channels +[dum, indx] = sort(indx); +channel = channel(indx); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipfit_1_to_2.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipfit_1_to_2.m new file mode 100644 index 0000000000000000000000000000000000000000..e9441185ed09ce92ae0c000684348742005d8a52 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipfit_1_to_2.m @@ -0,0 +1,60 @@ +% dipfit_1_to_2() - convert dipfit 1 structure to dipfit 2 structure. +% +% Usage: +% >> EEG.dipfit = dipfit_1_to_2(EEG.dipfit); +% +% Note: +% For non-standard BESA models (where the radii or the conductances +% have been modified, users must create a new model in Dipfit2 from +% the default BESA model. +% +% Author: Arnaud Delorme, SCCN, La Jolla 2005 + +% Copyright (C) Arnaud Delorme, SCCN, La Jolla 2005 +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function newdipfit = dipfit_1_to_2( dipfit ); + + if isfield( dipfit, 'model') + newdipfit.model = dipfit.model; + end; + if isfield( dipfit, 'chansel') + newdipfit.chansel = dipfit.chansel; + end; + + ind = 1; % use first template (BESA) + newdipfit.coordformat = template_models(ind).coordformat; + newdipfit.mrifile = template_models(ind).mrifile; + newdipfit.chanfile = template_models(ind).chanfile; + + if ~isfield(dipfit, 'vol') + newdipfit.hdmfile = template_models(ind).hdmfile; + else + newdipfit.vol = dipfit.vol; + + %if length(dipfit.vol) == 4 + %if ~all(dipfit.vol == [85-6-7-1 85-6-7 85-6 85]) | ... + % ~all(dipfit.c == [0.33 1.00 0.0042 0.33]) | ... + % ~all(dipfit.o = [0 0 0]) + % disp('Warning: Conversion from dipfit 1 to dipfit 2 can only deal'); + % disp(' with standard (not modified) BESA model'); + % disp(' See "help dipfit_1_to_2" to convert this model'); + % newdipfit = []; + %end; + %end; + end; + + diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipfit_erpeeg.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipfit_erpeeg.m new file mode 100644 index 0000000000000000000000000000000000000000..3fe7fb7b59e25b9d5fbbb491d769d7ed97960377 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipfit_erpeeg.m @@ -0,0 +1,94 @@ +% dipfit_erpeeg - fit multiple component dipoles using DIPFIT +% +% Usage: +% >> [ dipole model EEG] = dipfit_erpeeg(data, chanlocs, 'key', 'val', ...); +% +% Inputs: +% data - input data [channel x point]. One dipole per point is +% returned. +% chanlocs - channel location structure (returned by readlocs()). +% +% Optional inputs: +% 'settings' - [cell array] dipfit settings (arguments to the +% pop_dipfit_settings() function). Default is none. +% 'dipoles' - [1|2] use either 1 dipole or 2 dipoles contrain in +% symetry. Default is 1. +% 'dipplot' - ['on'|'off'] plot dipoles. Default is 'off'. +% 'plotopt' - [cell array] dipplot() 'key', 'val' options. Default is +% 'normlen', 'on', 'image', 'fullmri' +% +% Outputs: +% dipole - dipole structure ('posxyz' field is the position; 'momxyz' +% field is the moment and 'rv' the residual variance) +% model - structure containing model information ('vol.r' field is +% radius, 'vol.c' conductances, 'vol.o' the 3-D origin and +% 'chansel', the selected channels). +% EEG - faked EEG structure containing erp activation at the place +% of ICA components but allowing to plot ERP dipoles. +% +% Note: residual variance is set to NaN if Dipfit does not converge +% +% Author: Arnaud Delorme, SCCN/INC/UCSD, La Jolla, Nov. 2003 + +% Copyright (C) 10/2003 Arnaud Delorme, SCCN/INC/UCSD, arno@sccn.ucsd.edu +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function [dipoles, model, EEG] = dipfit_erpeeg(DATA, chanlocs, varargin); + + if nargin < 1 + help dipfit_erpeeg; + return; + end; + + ncomps = size(DATA,2); + if size(DATA,1) ~= length(chanlocs) + error('# of row in ''DATA'' must equal # of channels in ''chanlocs'''); + end; + + % faking an EEG dataset + % --------------------- + EEG = eeg_emptyset; + EEG.data = rand(size(DATA,1), 1000); + EEG.nbchan = size(DATA,1); + EEG.pnts = 1000; + EEG.trials = 1; + EEG.chanlocs = chanlocs; + EEG.icawinv = [ DATA DATA ]; + EEG.icaweights = zeros(size([ DATA DATA ]))'; + EEG.icasphere = zeros(size(DATA,1), size(DATA,1)); + %EEG = eeg_checkset(EEG); + EEG.icaact = EEG.icaweights*EEG.icasphere*EEG.data(:,:); + EEG.icaact = reshape( EEG.icaact, size(EEG.icaact,1), size(EEG.data,2), size(EEG.data,3)); + + % uses mutlifit to fit dipoles + % ---------------------------- + EEG = pop_multifit(EEG, [1:ncomps], varargin{:}); + + % process outputs + % --------------- + dipoles = EEG.dipfit.model; + if isfield(dipoles, 'active') + dipoles = rmfield(dipoles, 'active'); + end; + if isfield(dipoles, 'select') + dipoles = rmfield(dipoles, 'select'); + end; + model = EEG.dipfit; + if isfield(model, 'model') + model = rmfield(model, 'model'); + end; + return; + diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipfit_gridsearch.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipfit_gridsearch.m new file mode 100644 index 0000000000000000000000000000000000000000..a630bb2970cd4cd125e3e7b466bd518b23d3509d --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipfit_gridsearch.m @@ -0,0 +1,115 @@ +% dipfit_gridsearch() - do initial batch-like dipole scan and fit to all +% data components and return a dipole model with a +% single dipole for each component. +% +% Usage: +% >> EEGOUT = dipfit_gridsearch( EEGIN, varargin) +% +% Inputs: +% ... +% +% Optional inputs: +% 'component' - vector with integers, ICA components to scan +% 'xgrid' - vector with floats, grid positions along x-axis +% 'ygrid' - vector with floats, grid positions along y-axis +% 'zgrid' - vector with floats, grid positions along z-axis +% +% Output: +% ... +% +% Author: Robert Oostenveld, SMI/FCDC, Nijmegen 2003, load/save by +% Arnaud Delorme +% Thanks to Nicolas Robitaille for his help on the CTF MEG +% implementation + +% SMI, University Aalborg, Denmark http://www.smi.auc.dk/ +% FC Donders Centre, University Nijmegen, the Netherlands http://www.fcdonders.kun.nl + +% Copyright (C) 2003 Robert Oostenveld, SMI/FCDC roberto@smi.auc.dk +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function [EEGOUT] = dipfit_gridsearch(EEG, varargin) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% convert the optional arguments into a configuration structure that can be +% understood by FIELDTRIPs dipolefitting function +if nargin>2 + cfg = struct(varargin{:}); +else + help dipfit_gridsearch + return +end + +% specify the FieldTrip DIPOLEFITTING configuration +cfg.model = 'moving'; +cfg.gridsearch = 'yes'; +cfg.nonlinear = 'no'; +% add some additional settings from EEGLAB to the configuration +tmpchanlocs = EEG.chanlocs; +cfg.channel = { tmpchanlocs(EEG.dipfit.chansel).labels }; +if isfield(EEG.dipfit, 'vol') + cfg.vol = EEG.dipfit.vol; +elseif isfield(EEG.dipfit, 'hdmfile') + cfg.hdmfile = EEG.dipfit.hdmfile; +else + error('no head model in EEG.dipfit') +end +if isfield(EEG.dipfit, 'elecfile') & ~isempty(EEG.dipfit.elecfile) + cfg.elecfile = EEG.dipfit.elecfile; +end +if isfield(EEG.dipfit, 'gradfile') & ~isempty(EEG.dipfit.gradfile) + cfg.gradfile = EEG.dipfit.gradfile; +end + +% convert the EEGLAB data structure into a structure that looks as if it +% was computed using FIELDTRIPs componentanalysis function +comp = eeglab2fieldtrip(EEG, 'componentanalysis', 'dipfit'); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Added code to handle CTF data with multipleSphere head model % +% This code is copy-pasted in dipfit_gridSearch, dipfit_nonlinear % +% The flag .isMultiSphere is used by dipplot % +% Nicolas Robitaille, January 2007. % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%Do some trick to force fieldtrip to use the multiple sphere model +if strcmpi(EEG.dipfit.coordformat, 'CTF') + cfg = rmfield(cfg, 'channel'); + comp = rmfield(comp, 'elec'); + cfg.gradfile = EEG.dipfit.chanfile; +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% END % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if ~isfield(cfg, 'component') + % default is to scan all components + cfg.component = 1:size(comp.topo,2); +end + +% for each component scan the whole brain with dipoles using FIELDTRIPs +% dipolefitting function +source = ft_dipolefitting(cfg, comp); + +% reformat the output dipole sources into EEGLABs data structure +for i=1:length(cfg.component) + EEG.dipfit.model(cfg.component(i)).posxyz = source.dip(i).pos; + EEG.dipfit.model(cfg.component(i)).momxyz = reshape(source.dip(i).mom, 3, length(source.dip(i).mom)/3)'; + EEG.dipfit.model(cfg.component(i)).rv = source.dip(i).rv; +end + +EEGOUT = EEG; diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipfit_nonlinear.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipfit_nonlinear.m new file mode 100644 index 0000000000000000000000000000000000000000..ce62f77b6f20225170761141ccbbfae242e0fd96 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipfit_nonlinear.m @@ -0,0 +1,130 @@ +% dipfit_nonlinear() - perform nonlinear dipole fit on one of the components +% to improve the initial dipole model. Only selected dipoles +% will be fitted. +% +% Usage: +% >> EEGOUT = dipfit_nonlinear( EEGIN, optarg) +% +% Inputs: +% ... +% +% Optional inputs are specified in key/value pairs and can be: +% ... +% +% Output: +% ... +% +% Author: Robert Oostenveld, SMI/FCDC, Nijmegen 2003 +% Thanks to Nicolas Robitaille for his help on the CTF MEG +% implementation + +% SMI, University Aalborg, Denmark http://www.smi.auc.dk/ +% FC Donders Centre, University Nijmegen, the Netherlands http://www.fcdonders.kun.nl + +% Copyright (C) 2003 Robert Oostenveld, SMI/FCDC roberto@smi.auc.dk +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function [EEGOUT] = dipfit_nonlinear( EEG, varargin ) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% convert the optional arguments into a configuration structure that can be +% understood by FIELDTRIPs dipolefitting function +if nargin>2 + cfg = struct(varargin{:}); +else + help dipfit_nonlinear + return +end + +% specify the FieldTrip DIPOLEFITTING configuration +cfg.model = 'moving'; +cfg.gridsearch = 'no'; +if ~isfield(cfg, 'nonlinear') + % if this flag is set to 'no', only the dipole moment will be fitted + cfg.nonlinear = 'yes'; +end +% add some additional settings from EEGLAB to the configuration +tmpchanlocs = EEG.chanlocs; +cfg.channel = { tmpchanlocs(EEG.dipfit.chansel).labels }; +if isfield(EEG.dipfit, 'vol') + cfg.vol = EEG.dipfit.vol; +elseif isfield(EEG.dipfit, 'hdmfile') + cfg.hdmfile = EEG.dipfit.hdmfile; +else + error('no head model in EEG.dipfit') +end + +if isfield(EEG.dipfit, 'elecfile') & ~isempty(EEG.dipfit.elecfile) + cfg.elecfile = EEG.dipfit.elecfile; +end +if isfield(EEG.dipfit, 'gradfile') & ~isempty(EEG.dipfit.gradfile) + cfg.gradfile = EEG.dipfit.gradfile; +end + +% set up the initial dipole model based on the one in the EEG structure +cfg.dip.pos = EEG.dipfit.model(cfg.component).posxyz; +cfg.dip.mom = EEG.dipfit.model(cfg.component).momxyz'; +cfg.dip.mom = cfg.dip.mom(:); + +% convert the EEGLAB data structure into a structure that looks as if it +% was computed using FIELDTRIPs componentanalysis function +comp = eeglab2fieldtrip(EEG, 'componentanalysis', 'dipfit'); +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Added code to handle CTF data with multipleSphere head model % +% This code is copy-pasted in dipfit_gridSearch, dipfit_nonlinear % +% The flag .isMultiSphere is used by dipplot % +% Nicolas Robitaille, January 2007. % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%Do some trick to force fieldtrip to use the multiple sphere model +if strcmpi(EEG.dipfit.coordformat, 'CTF') + cfg = rmfield(cfg, 'channel'); + comp = rmfield(comp, 'elec'); + cfg.gradfile = EEG.dipfit.chanfile; +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% END % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% fit the dipoles to the ICA component(s) of interest using FIELDTRIPs +% dipolefitting function + +currentPath = pwd; +ptmp = which('ft_prepare_vol_sens'); +ptmp = fileparts(ptmp); +if isempty(ptmp), error('Path to "forward" folder of Fieldtrip missing'); end; +cd(fullfile(ptmp, 'private')); +try, + source = ft_dipolefitting(cfg, comp); +catch, + cd(currentPath); + lasterr + error(lasterr); +end; +cd(currentPath); + +% reformat the output dipole sources into EEGLABs data structure +EEG.dipfit.model(cfg.component).posxyz = source.dip.pos; +EEG.dipfit.model(cfg.component).momxyz = reshape(source.dip.mom, 3, length(source.dip.mom)/3)'; +EEG.dipfit.model(cfg.component).diffmap = source.Vmodel - source.Vdata; +EEG.dipfit.model(cfg.component).sourcepot = source.Vmodel; +EEG.dipfit.model(cfg.component).datapot = source.Vdata; +EEG.dipfit.model(cfg.component).rv = source.dip.rv; +%EEG.dipfit.model(cfg.component).rv = sum((source.Vdata - source.Vmodel).^2) / sum( source.Vdata.^2 ); + +EEGOUT = EEG; diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipfit_reject.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipfit_reject.m new file mode 100644 index 0000000000000000000000000000000000000000..7dda49771e29f09c41949f002db2484cba3353b5 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipfit_reject.m @@ -0,0 +1,54 @@ +% dipfit_reject() - remove dipole models with a poor fit +% +% Usage: +% >> dipout = dipfit_reject( model, reject ) +% +% Inputs: +% model struct array with a dipole model for each component +% +% Outputs: +% dipout struct array with a dipole model for each component +% +% Author: Robert Oostenveld, SMI/FCDC, Nijmegen 2003 + +% SMI, University Aalborg, Denmark http://www.smi.auc.dk/ +% FC Donders Centre, University Nijmegen, the Netherlands http://www.fcdonders.kun.nl/ + +% Copyright (C) 2003 Robert Oostenveld, SMI/FCDC roberto@miba.auc.dk +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function [dipout] = dipfit_reject(model, reject) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +if nargin < 1 + help dipfit_reject; + return; +end; + +for i=1:length(model) + if model(i).rv>reject + % reject this dipole model by replacing it by an empty model + dipout(i).posxyz = []; + dipout(i).momxyz = []; + dipout(i).rv = 1; + else + dipout(i).posxyz = model(i).posxyz; + dipout(i).momxyz = model(i).momxyz; + dipout(i).rv = model(i).rv; + end +end + diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipfitdefs.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipfitdefs.m new file mode 100644 index 0000000000000000000000000000000000000000..bfeace5db4dd33c4335d4bd45004b27967b1b271 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipfitdefs.m @@ -0,0 +1,153 @@ +% dipfitdefs() - default settings and filenames for dipolefitting +% to source in the ICA/ERP package functions. +% Insert local dir reference below. +% +% Note: Edit this file to change local directories under Unix and Windows +% +% Author: Robert Oostenveld, SMI/FCDC, Nijmegen 2003 + +% SMI, University Aalborg, Denmark http://www.smi.auc.dk/ +% FC Donders Centre, University Nijmegen, the Netherlands http://www.fcdonders.kun.nl + +% Copyright (C) 2003 Robert Oostenveld, SMI/FCDC roberto@miba.auc.dk +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% this file is not a function but a script and is included in the dipfit_XXX functions +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +try, + if ~isfield(EEG, 'chanlocs') + error('No electrode locations defined'); + end + + if ~isfield(EEG, 'icawinv') + error('No ICA components present'); + end + nchan = length(EEG(1).chanlocs); + ncomp = size(EEG(1).icawinv, 2); +catch, nchan = 0; end; + +% create one-sphere model +% defaultvolume.r = meanradius; +% defaultvolume.c = 0.33http://www.google.com/; +% defaultvolume.o = [0 0 0]; + +% create three-sphere model +% defaultvolume.r = meanradius * [0.0 0.92 0.88]; +% defaultvolume.c = [0.33 0.0042 0.33]; +% defaultvolume.o = [0 0 0]; + +% create four-sphere model that is identical to the default of besa +defaultvolume.r = [85-6-7-1 85-6-7 85-6 85]; % in mm +defaultvolume.c = [0.33 1.00 0.0042 0.33]; % brain/csf/skull/skin +defaultvolume.o = [0 0 0]; + +% default file locations +% ---------------------- +if ~iseeglabdeployed + folder = which('pop_dipfit_settings'); + folder = folder(1:end-21); +else + folder = eeglabexefolder; +end; +try, + delim = folder(end); + template_models(1).name = 'Spherical Four-Shell (BESA)'; + template_models(1).hdmfile = fullfile(folder, 'standard_BESA', 'standard_BESA.mat'); + template_models(1).mrifile = fullfile(folder, 'standard_BESA', 'avg152t1.mat'); + template_models(1).chanfile = fullfile(folder, 'standard_BESA', 'standard-10-5-cap385.elp'); + template_models(1).coordformat = 'spherical'; + template_models(1).coord_transform(1).transform = [ ]; + template_models(1).coord_transform(1).keywords = { 'standard-10-5-cap385' }; + template_models(1).coord_transform(2).transform = [ 13.4299 0.746361 -0.654923 0.000878113 -0.0818352 0.0023747 0.852832 0.941595 0.85887]; + template_models(1).coord_transform(2).keywords = { 'standard_1005' }; + template_models(1).coord_transform(3).transform = [ -0.254232 0 -8.4081 0 0.00272526 0 8.59463 -10.9643 10.4963 ]; + template_models(1).coord_transform(3).keywords = { 'gsn' 'sfp' }; + template_models(1).coord_transform(4).transform = [ 0 0 0 0 0.02 0 85 85 85 ]; + template_models(1).coord_transform(4).keywords = { 'egi' 'elp' }; + + template_models(2).name = 'Boundary Element Model (MNI)'; + template_models(2).hdmfile = fullfile(folder, 'standard_BEM', 'standard_vol.mat' ); + template_models(2).mrifile = fullfile(folder, 'standard_BEM', 'standard_mri.mat' ); + template_models(2).chanfile = fullfile(folder, 'standard_BEM', 'elec', 'standard_1005.elc' ); + template_models(2).coordformat = 'MNI'; + template_models(2).coord_transform(1).transform = [ 0 0 0 0 0 -pi/2 1 1 1]; + template_models(2).coord_transform(1).keywords = { 'standard_1005' }; + template_models(2).coord_transform(2).transform = [ 0.832146 -15.6287 2.41142 0.0812144 0.000937391 -1.5732 1.17419 1.06011 1.14846]; + template_models(2).coord_transform(2).keywords = { 'standard-10-5-cap385' }; + template_models(2).coord_transform(3).transform = [ 0.0547605 -17.3653 -8.13178 0.0755019 0.00318357 -1.56963 11.7138 12.7933 12.213 ]; + template_models(2).coord_transform(3).keywords = { 'gsn' 'sfp' }; + template_models(2).coord_transform(4).transform = [ 0 -15 0 0.08 0 -1.571 102 93 100 ]; + template_models(2).coord_transform(4).keywords = { 'egi' 'elp' }; + + template_models(3).name = 'Spherical Four-Shell (custom conductances - see DIPFIT wiki)'; + template_models(3).hdmfile = fullfile(folder, 'standard_BESA', 'standard_SCCN.mat'); + template_models(3).mrifile = fullfile(folder, 'standard_BESA', 'avg152t1.mat'); + template_models(3).chanfile = fullfile(folder, 'standard_BESA', 'standard-10-5-cap385.elp'); + template_models(3).coordformat = 'spherical'; + template_models(3).coord_transform(1).transform = [ ]; + template_models(3).coord_transform(1).keywords = { 'standard-10-5-cap385' }; + template_models(3).coord_transform(2).transform = [ 13.4299 0.746361 -0.654923 0.000878113 -0.0818352 0.0023747 0.852832 0.941595 0.85887]; + template_models(3).coord_transform(2).keywords = { 'standard_1005' }; + template_models(3).coord_transform(3).transform = [ -0.254232 0 -8.4081 0 0.00272526 0 8.59463 -10.9643 10.4963 ]; + template_models(3).coord_transform(3).keywords = { 'gsn' 'sfp' }; + template_models(3).coord_transform(4).transform = [ 0 0 0 0 0.02 0 85 85 85 ]; + template_models(3).coord_transform(4).keywords = { 'egi' 'elp' }; + + template_models(4).name = 'Boundary Element Model (custom conductances - see DIPFIT wiki)'; + template_models(4).hdmfile = fullfile(folder, 'standard_BEM', 'standard_vol_SCCN.mat' ); + template_models(4).mrifile = fullfile(folder, 'standard_BEM', 'standard_mri.mat' ); + template_models(4).chanfile = fullfile(folder, 'standard_BEM', 'elec', 'standard_1005.elc' ); + template_models(4).coordformat = 'MNI'; + template_models(4).coord_transform(1).transform = [ 0 0 0 0 0 -pi/2 1 1 1]; + template_models(4).coord_transform(1).keywords = { 'standard_1005' }; + template_models(4).coord_transform(2).transform = [ 0.832146 -15.6287 2.41142 0.0812144 0.000937391 -1.5732 1.17419 1.06011 1.14846]; + template_models(4).coord_transform(2).keywords = { 'standard-10-5-cap385' }; + template_models(4).coord_transform(3).transform = [ 0.0547605 -17.3653 -8.13178 0.0755019 0.00318357 -1.56963 11.7138 12.7933 12.213 ]; + template_models(4).coord_transform(3).keywords = { 'gsn' 'sfp' }; + template_models(4).coord_transform(4).transform = [ 0 -15 0 0.08 0 -1.571 102 93 100 ]; + template_models(4).coord_transform(4).keywords = { 'egi' 'elp' }; + +catch, + disp('Warning: problem when setting paths for dipole localization'); +end; + +template_models(5).name = 'CTF MEG'; +template_models(5).coordformat = 'CTF'; +template_models(6).name = 'Custom model files'; +template_models(6).coordformat = 'MNI'; % custom model + +% constrain electrode to sphere +% ----------------------------- +meanradius = defaultvolume.r(4); + +% defaults for GUI pop_dipfit_settings dialog +defaultelectrodes = sprintf('1:%d', nchan); + +% these settings determine the symmetry constraint that can be toggled on +% for the second dipole +%defaultconstraint = 'y'; % symmetry along x-axis +% PROBLEM: change with respect to the model used. Now just assume perpendicular to nose + +% defaults for GUI pop_dipfit_batch dialogs +rejectstr = '40'; % in percent +xgridstr = sprintf('linspace(-%d,%d,11)', floor(meanradius), floor(meanradius)); +ygridstr = sprintf('linspace(-%d,%d,11)', floor(meanradius), floor(meanradius)); +zgridstr = sprintf('linspace(0,%d,6)', floor(meanradius)); + +% Set DipoleDensity path +DIPOLEDENSITY_STDBEM = fullfile(folder, 'standard_BEM', 'standard_vol.mat'); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipplot.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipplot.m new file mode 100644 index 0000000000000000000000000000000000000000..253906b4e254ba5bf300c98711dde2d0f3f958ac --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/dipplot.m @@ -0,0 +1,1281 @@ +% dipplot() - Visualize EEG equivalent-dipole locations and orientations +% in the MNI average MRI head or in the BESA spherical head model. +% Usage: +% >> dipplot( sources, 'key', 'val', ...); +% >> [sources X Y Z XE YE ZE] = dipplot( sources, 'key', 'val', ...); +% +% Inputs: +% sources - structure array of dipole information: can contain +% either BESA or DIPFIT dipole information. BESA dipole +% information are still supported but may disapear in the +% future. For DIPFIT +% sources.posxyz: contains 3-D location of dipole in each +% column. 2 rows indicate 2 dipoles. +% sources.momxyz: contains 3-D moments for dipoles above. +% sources.rv : residual variance from 0 to 1. +% other fields : used for graphic interface. +% +% Optional input: +% 'rvrange' - [min max] or [max] Only plot dipoles with residual variace +% within the given range. Default: plot all dipoles. +% 'summary' - ['on'|'off'|'3d'] Build a summary plot with three views (top, +% back, side). {default: 'off'} +% 'mri' - Matlab file containing an MRI volume and a 4-D transformation +% matrix to go from voxel space to electrode space: +% mri.anatomy contains a 3-D anatomical data array +% mri.transfrom contains a 4-D homogenous transformation matrix. +% 'coordformat' - ['MNI'|'spherical'] Consider that dipole coordinates are in +% MNI or spherical coordinates (for spherical, the radius of the +% head is assumed to be 85 (mm)). See also function sph2spm(). +% 'transform' - [real array] traditional transformation matrix to convert +% dipole coordinates to MNI space. Default is assumed from +% 'coordformat' input above. Type help traditional for more +% information. +% 'image' - ['besa'|'mri'] Background image. +% 'mri' (or 'fullmri') uses mean-MRI brain images from the Montreal +% Neurological Institute. This option can also contain a 3-D MRI +% volume (dim 1: left to right; dim 2: anterior-posterior; dim 3: +% superior-inferior). Use 'coregist' to coregister electrodes +% with the MRI. {default: 'mri'} +% 'verbose' - ['on'|'off'] comment on operations on command line {default: +% 'on'}. +% 'plot' - ['on'|'off'] only return outputs {default: 'off'}. +% +% Plotting options: +% 'color' - [cell array of color strings or (1,3) color arrays]. For +% exemple { 'b' 'g' [1 0 0] } gives blue, green and red. +% Dipole colors will rotate through the given colors if +% the number given is less than the number of dipoles to plot. +% A single number will be used as color index in the jet colormap. +% 'view' - 3-D viewing angle in cartesian coords., +% [0 0 1] gives a sagittal view, [0 -1 0] a view from the rear; +% [1 0 0] gives a view from the side of the head. +% 'mesh' - ['on'|'off'] Display spherical mesh. {Default is 'on'} +% 'meshdata' - [cell array|'file_name'] Mesh data in a cell array { 'vertices' +% data 'faces' data } or a boundary element model filename (the +% function will plot the 3rd mesh in the 'bnd' sub-structure). +% 'axistight' - ['on'|'off'] For MRI only, display the closest MRI +% slide. {Default is 'off'} +% 'gui' - ['on'|'off'] Display controls. {Default is 'on'} If gui 'off', +% a new figure is not created. Useful for incomporating a dipplot +% into a complex figure. +% 'num' - ['on'|'off'] Display component number. Take into account +% dipole size. {Default: 'off'} +% 'cornermri' - ['on'|'off'] force MRI images to the corner of the MRI volume +% (usefull when background is not black). Default: 'off'. +% 'drawedges' - ['on'|'off'] draw edges of the 3-D MRI (black in axistight, +% white otherwise.) Default is 'off'. +% 'projimg' - ['on'|'off'] Project dipole(s) onto the 2-D images, for use +% in making 3-D plots {Default 'off'} +% 'projlines' - ['on'|'off'] Plot lines connecting dipole with 2-D projection. +% Color is dashed black for BESA head and dashed black for the +% MNI brain {Default 'off'} +% 'projcol' - [color] color for the projected line {Default is same as dipole} +% 'dipolesize' - Size of the dipole sphere(s). This option may also contain one +% value per dipole {Default: 30} +% 'dipolelength' - Length of the dipole bar(s) {Default: 1} +% 'pointout' - ['on'|'off'] Point the dipoles outward. {Default: 'off'} +% 'sphere' - [float] radius of sphere corresponding to the skin. Default is 1. +% 'spheres' - ['on'|'off'] {default: 'off'} plot dipole markers as 3-D spheres. +% Does not yet interact with gui buttons, produces non-gui mode. +% 'spheresize' - [real>0] size of spheres (if 'on'). {default: 5} +% 'normlen' - ['on'|'off'] Normalize length of all dipoles. {Default: 'off'} +% 'dipnames' - [cell array] cell array of string with a name for each dipole (or +% pair of dipole). +% 'holdon' - ['on'|'off'] create a new dipplot figure or plot dipoles within an +% an existing figure. Default is 'off'. +% 'camera' - ['auto'|'set'] camera position. 'auto' is the default and +% an option using camera zoom. 'set' is a fixed view that +% does not depend on the content being plotted. +% +% Outputs: +% sources - EEG.source structure with two extra fiels 'mnicoord' and 'talcoord' +% containing the MNI and talairach coordinates of the dipoles. Note +% that for the BEM model, dipoles are already in MNI coordinates. +% X,Y,Z - Locations of dipole heads (Cartesian coordinates in MNI space). +% If there is more than one dipole per components, the last dipole +% is returned. +% XE,YE,ZE - Locations of dipole ends (Cartesian coordinates). The same +% remark as above applies. +% +% Author: Arnaud Delorme, CNL / Salk Institute, 1st July 2002 +% +% Notes: See DIPFIT web tutorial at sccn.ucsd.edu/eeglab/dipfittut/dipfit.html +% for more details about MRI co-registration etc... +% +% Example: +% % define dipoles +% sources(1).posxyz = [-59 48 -28]; % position for the first dipole +% sources(1).momxyz = [ 0 58 -69]; % orientation for the first dipole +% sources(1).rv = 0.036; % residual variance for the first dipole +% sources(2).posxyz = [74 -4 -38]; % position for the second dipole +% sources(2).momxyz = [43 -38 -16]; % orientation for the second dipole +% sources(2).rv = 0.027; % residual variance for the second dipole +% +% % plot of the two dipoles (first in green, second in blue) +% dipplot( sources, 'color', { 'g' 'b' }); +% +% % To make a stereographic plot +% figure( 'position', [153 553 1067 421]; +% subplot(1,3,1); dipplot( sources, 'view', [43 10], 'gui', 'off'); +% subplot(1,3,3); dipplot( sources, 'view', [37 10], 'gui', 'off'); +% +% % To make a summary plot +% dipplot( sources, 'summary', 'on', 'num', 'on'); +% +% See also: eeglab(), dipfit() + +% old options +% ----------- +% 'std' - [cell array] plot standard deviation of dipoles. i.e. +% { [1:6] [7:12] } plot two elipsoids that best fit all the dipoles +% from 1 to 6 and 7 to 12 with radius 1 standard deviation. +% { { [1:6] 2 'linewidth' 2 } [7:12] } do the same but now the +% first elipsoid is 2 standard-dev and the lines are thicker. + +% Copyright (C) 2002 Arnaud Delorme +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +% README -- Plotting strategy: +% - All buttons have a tag 'tmp' so they can be removed +% - The component-number buttons have 'userdata' equal to 'editor' and +% can be found easily by other buttons find('userdata', 'editor') +% - All dipoles have a tag 'dipoleX' (X=their number) and can be made +% visible/invisible +% - The gcf object 'userdat' field stores the handle of the dipole that +% is currently being modified +% - Gca 'userdata' stores imqge names and position + +function [outsources, XX, YY, ZZ, XO, YO, ZO] = dipplot( sourcesori, varargin ) + + DEFAULTVIEW = [0 0 1]; + + if nargin < 1 + help dipplot; + return; + end; + + % reading and testing arguments + % ----------------------------- + sources = sourcesori; + if ~isstruct(sources) + updatedipplot(sources(1)); + % sources countain the figure handler + return + end; + + % key type range default + g = finputcheck( varargin, { 'color' '' [] []; + 'axistight' 'string' { 'on' 'off' } 'off'; + 'camera' 'string' { 'auto' 'set' } 'auto'; + 'coordformat' 'string' { 'MNI' 'spherical' 'CTF' 'auto' } 'auto'; + 'drawedges' 'string' { 'on' 'off' } 'off'; + 'mesh' 'string' { 'on' 'off' } 'off'; + 'gui' 'string' { 'on' 'off' } 'on'; + 'summary' 'string' { 'on2' 'on' 'off' '3d' } 'off'; + 'verbose' 'string' { 'on' 'off' } 'on'; + 'view' 'real' [] [0 0 1]; + 'rvrange' 'real' [0 Inf] []; + 'transform' 'real' [0 Inf] []; + 'normlen' 'string' { 'on' 'off' } 'off'; + 'num' 'string' { 'on' 'off' } 'off'; + 'cornermri' 'string' { 'on' 'off' } 'off'; + 'mri' { 'string' 'struct' } [] ''; + 'dipnames' 'cell' [] {}; + 'projimg' 'string' { 'on' 'off' } 'off'; + 'projcol' '' [] []; + 'projlines' 'string' { 'on' 'off' } 'off'; + 'pointout' 'string' { 'on' 'off' } 'off'; + 'holdon' 'string' { 'on' 'off' } 'off'; + 'dipolesize' 'real' [0 Inf] 30; + 'dipolelength' 'real' [0 Inf] 1; + 'sphere' 'real' [0 Inf] 1; + 'spheres' 'string' {'on' 'off'} 'off'; + 'links' 'real' [] []; + 'image' { 'string' 'real' } [] 'mri'; + 'plot' 'string' { 'on' 'off' } 'on'; + 'meshdata' { 'string' 'cell' } [] '' }, 'dipplot'); + % 'std' 'cell' [] {}; + % 'coreg' 'real' [] []; + + if isstr(g), error(g); end; + if strcmpi(g.holdon, 'on'), g.gui = 'off'; end; + if length(g.dipolesize) == 1, g.dipolesize = repmat(g.dipolesize, [1 length(sourcesori)]); end; + + g.zoom = 1500; + + if strcmpi(g.image, 'besa') + error('BESA image not supported any more. Use EEGLAB version 4.512 or earlier. (BESA dipoles can still be plotted in MNI brain.)'); + end; + + % trying to determine coordformat + % ------------------------------- + if ~isfield(sources, 'momxyz') + g.coordformat = 'spherical'; + end; + if strcmpi(g.coordformat, 'auto') + if ~isempty(g.meshdata) + g.coordformat = 'MNI'; + if strcmpi(g.verbose, 'on'), + disp('Coordinate format unknown: using ''MNI'' since mesh data was provided as input'); + end + else + maxdiplen = 0; + for ind = 1:length(sourcesori) + maxdiplen = max(maxdiplen, max(abs(sourcesori(ind).momxyz(:)))); + end; + if maxdiplen>2000 + if strcmpi(g.verbose, 'on'), + disp('Coordinate format unknown: using ''MNI'' because of large dipole moments'); + end + else + g.coordformat = 'spherical'; + if strcmpi(g.verbose, 'on'), + disp('Coordinate format unknown: using ''spherical'' since no mesh data was provided as input'); + end + end; + end; + end; + + % axis image and limits + % --------------------- + dat.axistight = strcmpi(g.axistight, 'on'); + dat.drawedges = g.drawedges; + dat.cornermri = strcmpi(g.cornermri, 'on'); + radius = 85; + + % look up an MRI file if necessary + % -------------------------------- + if isempty(g.mri) + if strcmpi(g.verbose, 'on'), + disp('No MRI file given as input. Looking up one.'); + end + dipfitdefs; + g.mri = template_models(1).mrifile; + end; + + % read anatomical MRI using Fieldtrip and SPM2 functons + % ----------------------------------------------------- + if isstr(g.mri); + try, + g.mri = load('-mat', g.mri); + g.mri = g.mri.mri; + catch, + disp('Failed to read Matlab file. Attempt to read MRI file using function ft_read_mri'); + try, + warning off; + g.mri = ft_read_mri(g.mri); + %g.mri.anatomy(find(g.mri.anatomy > 255)) = 255; + %g.mri.anatomy = uint8(g.mri.anatomy); + g.mri.anatomy = round(gammacorrection( g.mri.anatomy, 0.8)); + g.mri.anatomy = uint8(round(g.mri.anatomy/max(reshape(g.mri.anatomy, prod(g.mri.dim),1))*255)); + % WARNING: if using double instead of int8, the scaling is different + % [-128 to 128 and 0 is not good] + % WARNING: the transform matrix is not 1, 1, 1 on the diagonal, some slices may be + % misplaced + warning on; + catch, + error('Cannot load file using ft_read_mri'); + end; + end; + end; + + if strcmpi(g.coordformat, 'spherical') + dat.sph2spm = sph2spm; + elseif strcmpi(g.coordformat, 'CTF') + dat.sph2spm = traditionaldipfit([0 0 0 0 0 0 10 -10 10]); + else + dat.sph2spm = []; %traditional([0 0 0 0 0 pi 1 1 1]); + end; + + if ~isempty(g.transform), dat.sph2spm = traditionaldipfit(g.transform); + end; + if isfield(g.mri, 'anatomycol') + dat.imgs = g.mri.anatomycol; + else + dat.imgs = g.mri.anatomy; + end; + dat.transform = g.mri.transform; + + % MRI coordinates for slices + % -------------------------- + if ~isfield(g.mri, 'xgrid') + g.mri.xgrid = [1:size(dat.imgs,1)]; + g.mri.ygrid = [1:size(dat.imgs,2)]; + g.mri.zgrid = [1:size(dat.imgs,3)]; + end; + if strcmpi(g.coordformat, 'CTF') + g.mri.zgrid = g.mri.zgrid(end:-1:1); + end; + + dat.imgcoords = { g.mri.xgrid g.mri.ygrid g.mri.zgrid }; + dat.maxcoord = [max(dat.imgcoords{1}) max(dat.imgcoords{2}) max(dat.imgcoords{3})]; + COLORMESH = 'w'; + BACKCOLOR = 'k'; + + % point 0 + % ------- + [xx yy zz] = transform(0, 0, 0, dat.sph2spm); % nothing happens for BEM since dat.sph2spm is empty + dat.zeroloc = [ xx yy zz ]; + + % conversion + % ---------- + if strcmpi(g.normlen, 'on') + if isfield(sources, 'besaextori') + sources = rmfield(sources, 'besaextori'); + end; + end; + if ~isfield(sources, 'besathloc') & strcmpi(g.image, 'besa') & ~is_sccn + error(['For copyright reasons, it is not possible to use the BESA ' ... + 'head model to plot non-BESA dipoles']); + end; + + if isfield(sources, 'besathloc') + sources = convertbesaoldformat(sources); + end; + if ~isfield(sources, 'posxyz') + sources = computexyzforbesa(sources); + end; + if ~isfield(sources, 'component') + if strcmpi(g.verbose, 'on'), + disp('No component indices, making incremental ones...'); + end + for index = 1:length(sources) + sources(index).component = index; + end; + end; + + % find non-empty sources + % ---------------------- + noempt = cellfun('isempty', { sources.posxyz } ); + sources = sources( find(~noempt) ); + + % transform coordinates + % --------------------- + outsources = sources; + for index = 1:length(sources) + sources(index).momxyz = sources(index).momxyz/1000; + end; + + % remove 0 second dipoles if any + % ------------------------------ + for index = 1:length(sources) + if size(sources(index).momxyz,1) == 2 + if all(sources(index).momxyz(2,:) == 0) + sources(index).momxyz = sources(index).momxyz(1,:); + sources(index).posxyz = sources(index).posxyz(1,:); + end; + end; + end; + + % remove sources with out of bound Residual variance + % -------------------------------------------------- + if isfield(sources, 'rv') & ~isempty(g.rvrange) + if length(g.rvrange) == 1, g.rvrange = [ 0 g.rvrange ]; end; + for index = length(sources):-1:1 + if sources(index).rv < g.rvrange(1)/100 | sources(index).rv > g.rvrange(2)/100 + sources(index) = []; + end; + end; + end; + + % color array + % ----------- + if isempty(g.color) + g.color = { 'g' 'b' 'r' 'm' 'c' 'y' }; + if strcmp(BACKCOLOR, 'w'), g.color = { g.color{:} 'k' }; end; + end; + g.color = g.color(mod(0:length(sources)-1, length(g.color)) +1); + if ~isempty(g.color) + g.color = strcol2real( g.color, jet(64) ); + end; + if ~isempty(g.projcol) + g.projcol = strcol2real( g.projcol, jet(64) ); + g.projcol = g.projcol(mod(0:length(sources)-1, length(g.projcol)) +1); + else + g.projcol = g.color; + for index = 1:length(g.color) + g.projcol{index} = g.projcol{index}/2; + end; + end; + + % build summarized figure + % ----------------------- + if strcmpi(g.summary, 'on') | strcmpi(g.summary, 'on2') + figure; + options = { 'gui', 'off', 'dipolesize', g.dipolesize/1.5,'dipolelength', g.dipolelength, 'sphere', g.sphere ... + 'color', g.color, 'mesh', g.mesh, 'num', g.num, 'image', g.image 'normlen' g.normlen ... + 'coordformat' g.coordformat 'mri' g.mri 'meshdata' g.meshdata 'axistight' g.axistight }; + pos1 = [0 0 0.5 0.5]; + pos2 = [0 0.5 0.5 .5]; + pos3 = [.5 .5 0.5 .5]; if strcmp(g.summary, 'on2'), tmp = pos1; pos1 =pos3; pos3 = tmp; end; + axes('position', pos1); newsources = dipplot(sourcesori, 'view', [1 0 0] , options{:}); axis off; + axes('position', pos2); newsources = dipplot(sourcesori, 'view', [0 0 1] , options{:}); axis off; + axes('position', pos3); newsources = dipplot(sourcesori, 'view', [0 -1 0], options{:}); axis off; + axes('position', [0.5 0 0.5 0.5]); + colorcount = 1; + if isfield(newsources, 'component') + for index = 1:length(newsources) + if isempty(g.dipnames), tmpname = sprintf( 'Comp. %d', newsources(index).component); + else tmpname = char(g.dipnames{index}); + end; + talpos = newsources(index).talcoord; + if strcmpi(g.coordformat, 'CTF') + textforgui(colorcount) = { sprintf( [ tmpname ' (RV:%3.2f%%)' ], 100*newsources(index).rv) }; + elseif size(talpos,1) == 1 + textforgui(colorcount) = { sprintf( [ tmpname ' (RV:%3.2f%%; Tal:%d,%d,%d)' ], ... + 100*newsources(index).rv, ... + round(talpos(1,1)), round(talpos(1,2)), round(talpos(1,3))) }; + else + textforgui(colorcount) = { sprintf( [ tmpname ' (RV:%3.2f%%; Tal:%d,%d,%d & %d,%d,%d)' ], ... + 100*newsources(index).rv, ... + round(talpos(1,1)), round(talpos(1,2)), round(talpos(1,3)), ... + round(talpos(2,1)), round(talpos(2,2)), round(talpos(2,3))) }; + end; + colorcount = colorcount+1; + end; + colorcount = colorcount-1; + allstr = strvcat(textforgui{:}); + h = text(0,0.45, allstr); + if colorcount >= 15, set(h, 'fontsize', 8);end; + if colorcount >= 20, set(h, 'fontsize', 6);end; + if strcmp(BACKCOLOR, 'k'), set(h, 'color', 'w'); end; + end; + axis off; + return; + elseif strcmpi(g.summary, '3d') + options = { 'gui', 'off', 'dipolesize', g.dipolesize/1.5,'dipolelength', g.dipolelength, 'sphere', g.sphere, 'spheres', g.spheres ... + 'color', g.color, 'mesh', g.mesh, 'num', g.num, 'image', g.image 'normlen' g.normlen ... + 'coordformat' g.coordformat 'mri' g.mri 'meshdata' g.meshdata 'axistight' g.axistight }; + figure('position', [ 100 600 600 200 ]); + axes('position', [-0.1 -0.1 1.2 1.2], 'color', 'k'); axis off; blackimg = zeros(10,10,3); image(blackimg); + axes('position', [0 0 1/3 1], 'tag', 'rear'); dipplot(sourcesori, options{:}, 'holdon', 'on'); view([0 -1 0]); + axes('position', [1/3 0 1/3 1], 'tag', 'top' ); dipplot(sourcesori, options{:}, 'holdon', 'on'); view([0 0 1]); + axes('position', [2/3 0 1/3 1], 'tag', 'side'); dipplot(sourcesori, options{:}, 'holdon', 'on'); view([1 -0.01 0]); + set(gcf, 'paperpositionmode', 'auto'); + return; + end; + + % plot head graph in 3D + % --------------------- + if strcmp(g.gui, 'on') + fig = figure('visible', g.plot); + pos = get(gca, 'position'); + set(gca, 'position', [pos(1)+0.05 pos(2:end)]); + end; + indx = ceil(dat.imgcoords{1}(end)/2); + indy = ceil(dat.imgcoords{2}(end)/2); + indz = ceil(dat.imgcoords{3}(end)/2); + if strcmpi(g.holdon, 'off') + plotimgs( dat, [indx indy indz], dat.transform); + + set(gca, 'color', BACKCOLOR); + %warning off; a = imread('besaside.pcx'); warning on; + % BECAUSE OF A BUG IN THE WARP FUNCTION, THIS DOES NOT WORK (11/02) + %hold on; warp([], wy, wz, a); + % set camera target + % ----------------- + + % format axis (BESA or MRI) + axis equal; + set(gca, 'cameraviewanglemode', 'manual'); % disable change size + camzoom(1.2^2); + if strcmpi(g.coordformat, 'CTF'), g.view(2:3) = -g.view(2:3); end; + view(g.view); + %set(gca, 'cameratarget', dat.zeroloc); % disable change size + %set(gca, 'cameraposition', dat.zeroloc+g.view*g.zoom); % disable change size + axis off; + end; + + % plot sphere mesh and nose + % ------------------------- + if strcmpi(g.holdon, 'off') + if isempty(g.meshdata) + SPHEREGRAIN = 20; % 20 is also Matlab default + [x y z] = sphere(SPHEREGRAIN); + hold on; + [xx yy zz] = transform(x*0.085, y*0.085, z*0.085, dat.sph2spm); + [xx yy zz] = transform(x*85 , y*85 , z*85 , dat.sph2spm); + %xx = x*100; + %yy = y*100; + %zz = z*100; + if strcmpi(COLORMESH, 'w') + hh = mesh(xx, yy, zz, 'cdata', ones(21,21,3), 'tag', 'mesh'); hidden off; + else + hh = mesh(xx, yy, zz, 'cdata', zeros(21,21,3), 'tag', 'mesh'); hidden off; + end; + else + try, + if isstr(g.meshdata) + tmp = load('-mat', g.meshdata); + g.meshdata = { 'vertices' tmp.vol.bnd(1).pnt 'faces' tmp.vol.bnd(1).tri }; + end; + hh = patch(g.meshdata{:}, 'facecolor', 'none', 'edgecolor', COLORMESH, 'tag', 'mesh'); + catch, disp('Unrecognize model file (probably CTF)'); end; + end; + end; + + %x = x*100*scaling; y = y*100*scaling; z=z*100*scaling; + %h = line(xx,yy,zz); set(h, 'color', COLORMESH, 'linestyle', '--', 'tag', 'mesh'); + %h = line(xx,zz,yy); set(h, 'color', COLORMESH, 'linestyle', '--', 'tag', 'mesh'); + %h = line([0 0;0 0],[-1 -1.2; -1.2 -1], [-0.3 -0.7; -0.7 -0.7]); + %set(h, 'color', COLORMESH, 'linewidth', 3, 'tag', 'noze'); + + % determine max length if besatextori exist + % ----------------------------------------- + sizedip = []; + for index = 1:length(sources) + sizedip = [ sizedip sources(index).momxyz(3) ]; + end; + maxlength = max(sizedip); + + % diph = gca; % DEBUG + % colormap('jet'); + % cbar + % axes(diph); + + for index = 1:length(sources) + nbdip = 1; + if size(sources(index).posxyz, 1) > 1 & any(sources(index).posxyz(2,:)) nbdip = 2; end; + + % reorder dipoles for plotting + if nbdip == 2 + if sources(index).posxyz(1,1) > sources(index).posxyz(2,1) + tmp = sources(index).posxyz(2,:); + sources(index).posxyz(2,:) = sources(index).posxyz(1,:); + sources(index).posxyz(1,:) = tmp; + tmp = sources(index).momxyz(2,:); + sources(index).momxyz(2,:) = sources(index).momxyz(1,:); + sources(index).momxyz(1,:) = tmp; + end; + if isfield(sources, 'active'), + nbdip = length(sources(index).active); + end; + end; + + % dipole length + % ------------- + multfactor = 1; + if strcmpi(g.normlen, 'on') + if nbdip == 1 + len = sqrt(sum(sources(index).momxyz(1,:).^2)); + else + len1 = sqrt(sum(sources(index).momxyz(1,:).^2)); + len2 = sqrt(sum(sources(index).momxyz(2,:).^2)); + len = mean([len1 len2]); + end; + if strcmpi(g.coordformat, 'CTF'), len = len*10; end; + if len ~= 0, multfactor = 15/len; end; + else + if strcmpi(g.coordformat, 'spherical') + multfactor = 100; + else multfactor = 1.5; + end; + end; + + for dip = 1:nbdip + + x = sources(index).posxyz(dip,1); + y = sources(index).posxyz(dip,2); + z = sources(index).posxyz(dip,3); + + xo = sources(index).momxyz(dip,1)*g.dipolelength*multfactor; + yo = sources(index).momxyz(dip,2)*g.dipolelength*multfactor; + zo = sources(index).momxyz(dip,3)*g.dipolelength*multfactor; + + xc = 0; + yc = 0; + zc = 0; + + centvec = [xo-xc yo-yc zo-zc]; % vector pointing into center + dipole_orient = [x+xo y+yo z+zo]/norm([x+xo y+yo z+zo]); + c = dot(centvec, dipole_orient); + + if strcmpi(g.pointout,'on') + if (c < 0) | (abs([x+xo,y+yo,z+zo]) < abs([x,y,z])) + xo1 = x-xo; % make dipole point outward from head center + yo1 = y-yo; + zo1 = z-zo; + %fprintf('invert because: %e \n', c); + else + xo1 = x+xo; + yo1 = y+yo; + zo1 = z+zo; + %fprintf('NO invert because: %e \n', c); + end + else + xo1 = x+xo; + yo1 = y+yo; + zo1 = z+zo; + %fprintf('NO invert because: %e \n', c); + end + + % + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% draw dipole bar %%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % + tag = [ 'dipole' num2str(index) ]; + + % from spherical to electrode space + % --------------------------------- + [xx yy zz] = transform(x, y, z, dat.sph2spm); % nothing happens for BEM + [xxo1 yyo1 zzo1] = transform(xo1, yo1, zo1, dat.sph2spm); % because dat.sph2spm = [] + + if ~strcmpi(g.spheres,'on') % plot dipole direction lines + h1 = line( [xx xxo1]', [yy yyo1]', [zz zzo1]'); + + elseif g.dipolelength>0 % plot dipole direction cylinders with end cap patch + + [xc yc zc] = cylinder( 2, 10); + [xs ys zs] = sphere(10); + xc = [ xc; -xs(7:11,:)*2 ]; + yc = [ yc; -ys(7:11,:)*2 ]; + zc = [ zc; zs(7:11,:)/5+1 ]; + + colorarray = repmat(reshape(g.color{index}, 1,1,3), [size(zc,1) size(zc,2) 1]); + handles = surf(xc, yc, zc, colorarray, 'tag', tag, 'edgecolor', 'none', ... + 'backfacelighting', 'lit', 'facecolor', 'interp', 'facelighting', ... + 'phong', 'ambientstrength', 0.3); + [xc yc zc] = adjustcylinder2( handles, [xx yy zz], [xxo1 yyo1 zzo1] ); + + cx = mean(xc,2); %cx = [(3*cx(1)+cx(2))/4; (cx(1)+3*cx(2))/4]; + cy = mean(yc,2); %cy = [(3*cy(1)+cy(2))/4; (cy(1)+3*cy(2))/4]; + cz = mean(zc,2); %cz = [(3*cz(1)+cz(2))/4; (cz(1)+3*cz(2))/4]; + tmpx = xc - repmat(cx, [1 size(xc, 2)]); + tmpy = yc - repmat(cy, [1 size(xc, 2)]); + tmpz = zc - repmat(cz, [1 size(xc, 2)]); + l=sqrt(tmpx.^2+tmpy.^2+tmpz.^2); + warning('off', 'MATLAB:divideByZero'); % this is due to a Matlab 2008b (or later) + normals = reshape([tmpx./l tmpy./l tmpz./l],[size(tmpx) 3]); % in the rotate function in adjustcylinder2 + warning('off', 'MATLAB:divideByZero'); % one of the z (the last row is not rotated) + set( handles, 'vertexnormals', normals); + + end + + [xxmri yymri zzmri ] = transform(xx, yy, zz, pinv(dat.transform)); + [xxmrio1 yymrio1 zzmrio1] = transform(xxo1, yyo1, zzo1, pinv(dat.transform)); + dipstruct.mricoord = [xxmri yymri zzmri]; % Coordinates in MRI space + dipstruct.eleccoord = [ xx yy zz ]; % Coordinates in elec space + dipstruct.posxyz = sources(index).posxyz; % Coordinates in spherical space + outsources(index).eleccoord(dip,:) = [xx yy zz]; + outsources(index).mnicoord(dip,:) = [xx yy zz]; + outsources(index).mricoord(dip,:) = [xxmri yymri zzmri]; + outsources(index).talcoord(dip,:) = mni2tal([xx yy zz]')'; + dipstruct.talcoord = mni2tal([xx yy zz]')'; + + % copy for output + % --------------- + XX(index) = xxmri; + YY(index) = yymri; + ZZ(index) = zzmri; + XO(index) = xxmrio1; + YO(index) = yymrio1; + ZO(index) = zzmrio1; + + if isempty(g.dipnames) + dipstruct.rv = sprintf('%3.2f', sources(index).rv*100); + dipstruct.name = sources(index).component; + else + dipstruct.rv = sprintf('%3.2f', sources(index).rv*100); + dipstruct.name = g.dipnames{index}; + end; + if ~strcmpi(g.spheres,'on') % plot disk markers + set(h1,'userdata',dipstruct,'tag',tag,'color','k','linewidth',g.dipolesize(index)/7.5); + if strcmp(BACKCOLOR, 'k'), set(h1, 'color', g.color{index}); end; + end + + % + %%%%%%%%%%%%%%%%%%%%%%%%%%%%% draw sphere or disk marker %%%%%%%%%%%%%%%%%%%%%%%%% + % + hold on; + if strcmpi(g.spheres,'on') % plot spheres + if strcmpi(g.projimg, 'on') + if strcmpi(g.verbose, 'on'), + disp('Warning: projections cannot be plotted for 3-D sphere'); + end + %tmpcolor = g.color{index} / 2; + %h = plotsphere([xx yy zz], g.dipolesize/6, 'color', g.color{index}, 'proj', ... + % [dat.imgcoords{1}(1) dat.imgcoords{2}(end) dat.imgcoords{3}(1)]*97/100, 'projcol', tmpcolor); + + %set(h(2:end), 'userdata', 'proj', 'tag', tag); + else + %h = plotsphere([xx yy zz], g.dipolesize/6, 'color', g.color{index}); + end; + h = plotsphere([xx yy zz], g.dipolesize(index)/6, 'color', g.color{index}); + set(h(1), 'userdata', dipstruct, 'tag', tag); + else % plot dipole markers + h = plot3(xx, yy, zz); + set(h, 'userdata', dipstruct, 'tag', tag, ... + 'marker', '.', 'markersize', g.dipolesize(index), 'color', g.color{index}); + end + + % + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% project onto images %%%%%%%%%%%%%%%%%%%%%%%%% + % + [tmp1xx tmp1yy tmp1zz ] = transform( xxmri , yymri , dat.imgcoords{3}(1), dat.transform); + [tmp1xxo1 tmp1yyo1 tmp1zzo1] = transform( xxmrio1, yymrio1, dat.imgcoords{3}(1), dat.transform); + [tmp2xx tmp2yy tmp2zz ] = transform( xxmri , dat.imgcoords{2}(end), zzmri , dat.transform); + [tmp2xxo1 tmp2yyo1 tmp2zzo1] = transform( xxmrio1, dat.imgcoords{2}(end), zzmrio1, dat.transform); + [tmp3xx tmp3yy tmp3zz ] = transform( dat.imgcoords{1}(1), yymri , zzmri , dat.transform); + [tmp3xxo1 tmp3yyo1 tmp3zzo1] = transform( dat.imgcoords{1}(1), yymrio1, zzmrio1, dat.transform); + + if strcmpi(g.projimg, 'on') & strcmpi(g.spheres, 'off') + tmpcolor = g.projcol{index}; + + % project onto z axis + tag = [ 'dipole' num2str(index) ]; + if ~strcmpi(g.image, 'besa') + h = line( [tmp1xx tmp1xxo1]', [tmp1yy tmp1yyo1]', [tmp1zz tmp1zzo1]'); + set(h, 'userdata', 'proj', 'tag', tag, 'color','k', 'linewidth', g.dipolesize(index)/7.5); + end; + if strcmp(BACKCOLOR, 'k'), set(h, 'color', tmpcolor); end; + h = plot3(tmp1xx, tmp1yy, tmp1zz); + set(h, 'userdata', 'proj', 'tag', tag, ... + 'marker', '.', 'markersize', g.dipolesize(index), 'color', tmpcolor); + + % project onto y axis + tag = [ 'dipole' num2str(index) ]; + if ~strcmpi(g.image, 'besa') + h = line( [tmp2xx tmp2xxo1]', [tmp2yy tmp2yyo1]', [tmp2zz tmp2zzo1]'); + set(h, 'userdata', 'proj', 'tag', tag, 'color','k', 'linewidth', g.dipolesize(index)/7.5); + end; + if strcmp(BACKCOLOR, 'k'), set(h, 'color', tmpcolor); end; + h = plot3(tmp2xx, tmp2yy, tmp2zz); + set(h, 'userdata', 'proj', 'tag', tag, ... + 'marker', '.', 'markersize', g.dipolesize(index), 'color', tmpcolor); + + % project onto x axis + tag = [ 'dipole' num2str(index) ]; + if ~strcmpi(g.image, 'besa') + h = line( [tmp3xx tmp3xxo1]', [tmp3yy tmp3yyo1]', [tmp3zz tmp3zzo1]'); + set(h, 'userdata', 'proj', 'tag', tag, 'color','k', 'linewidth', g.dipolesize(index)/7.5); + end; + if strcmp(BACKCOLOR, 'k'), set(h, 'color', tmpcolor); end; + h = plot3(tmp3xx, tmp3yy, tmp3zz); + set(h, 'userdata', 'proj', 'tag', tag, ... + 'marker', '.', 'markersize', g.dipolesize(index), 'color', tmpcolor); + end; + + % + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% project onto axes %%%%%%%%%%%%%%%%%%%%%%%%% + % + if strcmpi(g.projlines, 'on') + clear h; + % project onto z axis + tag = [ 'dipole' num2str(index) ]; + h(1) = line( [xx tmp1xx]', [yy tmp1yy]', [zz tmp1zz]); + set(h(1), 'userdata', 'proj', 'linestyle', '--', ... + 'tag', tag, 'color', g.color{index}, 'linewidth', g.dipolesize(index)/7.5/5); + + % project onto x axis + tag = [ 'dipole' num2str(index) ]; + h(2) = line( [xx tmp2xx]', [yy tmp2yy]', [zz tmp2zz]); + set(h(2), 'userdata', 'proj', 'linestyle', '--', ... + 'tag', tag, 'color', g.color{index}, 'linewidth', g.dipolesize(index)/7.5/5); + + % project onto y axis + tag = [ 'dipole' num2str(index) ]; + h(3) = line( [xx tmp3xx]', [yy tmp3yy]', [zz tmp3zz]); + set(h(3), 'userdata', 'proj', 'linestyle', '--', ... + 'tag', tag, 'color', g.color{index}, 'linewidth', g.dipolesize(index)/7.5/5); + if ~isempty(g.projcol) + set(h, 'color', g.projcol{index}); + end; + end; + % + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% draw text %%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % + if isfield(sources, 'component') + if strcmp(g.num, 'on') + h = text(xx, yy, zz, [ ' ' int2str(sources(index).component)]); + set(h, 'userdata', dipstruct, 'tag', tag, 'fontsize', g.dipolesize(index)/2 ); + if ~strcmpi(g.image, 'besa'), set(h, 'color', 'w'); end; + end; + end; + end; + end; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3-D settings + if strcmpi(g.spheres, 'on') + lighting phong; + material shiny; + camlight left; + camlight right; + end; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% draw elipse for group of dipoles %%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % does not work because of new scheme, have to be reprogrammed + + %if ~isempty(g.std) + % for index = 1:length(g.std) + % if ~iscell(g.std{index}) + % plotellipse(sources, g.std{index}, 1, dat.tcparams, dat.coreg); + % else + % sc = plotellipse(sources, g.std{index}{1}, g.std{index}{2}, dat.tcparams, dat.coreg); + % if length( g.std{index} ) > 2 + % set(sc, g.std{index}{3:end}); + % end; + % end; + % end; + % end; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% buttons %%%%%%%%%%%%%%%%%%%%%%%%%%%%% + nbsrc = int2str(length(sources)); + cbmesh = [ 'if get(gcbo, ''userdata''), ' ... + ' set(findobj(''parent'', gca, ''tag'', ''mesh''), ''visible'', ''off'');' ... + ' set(gcbo, ''string'', ''Mesh on'');' ... + ' set(gcbo, ''userdata'', 0);' ... + 'else,' ... + ' set(findobj(''parent'', gca, ''tag'', ''mesh''), ''visible'', ''on'');' ... + ' set(gcbo, ''string'', ''Mesh off'');' ... + ' set(gcbo, ''userdata'', 1);' ... + 'end;' ]; + cbplot = [ 'if strcmpi(get(gcbo, ''string''), ''plot one''),' ... + ' for tmpi = 1:' nbsrc ',' ... + ' set(findobj(''parent'', gca, ''tag'', [ ''dipole'' int2str(tmpi) ]), ''visible'', ''off'');' ... + ' end; clear tmpi;' ... + ' dipplot(gcbf);' ... + ' set(gcbo, ''string'', ''Plot all'');' ... + 'else,' ... + ' for tmpi = 1:' nbsrc ',' ... + ' set(findobj(''parent'', gca, ''tag'', [ ''dipole'' int2str(tmpi) ]), ''visible'', ''on'');' ... + ' end; clear tmpi;' ... + ' set(gcbo, ''string'', ''Plot one'');' ... + 'end;' ]; + cbview = [ 'tmpuserdat = get(gca, ''userdata'');' ... + 'if tmpuserdat.axistight, ' ... + ' set(gcbo, ''string'', ''Tight view'');' ... + 'else,' ... + ' set(gcbo, ''string'', ''Loose view'');' ... + 'end;' ... + 'tmpuserdat.axistight = ~tmpuserdat.axistight;' ... + 'set(gca, ''userdata'', tmpuserdat);' ... + 'clear tmpuserdat;' ... + 'dipplot(gcbf);' ]; + viewstring = fastif(dat.axistight, 'Loose view', 'Tight view'); + enmesh = fastif(isempty(g.meshdata) & strcmpi(g.coordformat, 'MNI'), 'off', 'on'); + if strcmpi(g.coordformat, 'CTF'), viewcor = 'view([0 1 0]);'; viewtop = 'view([0 0 -1]);'; vis = 'off'; + else viewcor = 'view([0 -1 0]);'; viewtop = 'view([0 0 1]);'; vis = 'on'; + end; + + h = uicontrol( 'unit', 'normalized', 'position', [0 0 .15 1], 'tag', 'tmp', ... + 'style', 'text', 'string',' '); + h = uicontrol( 'unit', 'normalized', 'position', [0 0 .15 .05], 'tag', 'tmp', ... + 'style', 'pushbutton', 'fontweight', 'bold', 'string', 'No controls', 'callback', ... + 'set(findobj(''parent'', gcbf, ''tag'', ''tmp''), ''visible'', ''off'');'); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.05 .15 .05], 'tag', 'tmp', ... + 'style', 'pushbutton', 'string', 'Top view', 'callback', viewtop); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.1 .15 .05], 'tag', 'tmp', ... + 'style', 'pushbutton', 'string', 'Coronal view', 'callback', viewcor); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.15 .15 .05], 'tag', 'tmp', ... + 'style', 'pushbutton', 'string', 'Sagittal view', 'callback', 'view([1 0 0]);'); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.2 .15 .05], 'tag', 'tmp', ... + 'style', 'pushbutton', 'string', viewstring, 'callback', cbview); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.25 .15 .05], 'tag', 'tmp', ... + 'style', 'pushbutton', 'string', 'Mesh on', 'userdata', 0, 'callback', ... + cbmesh, 'enable', enmesh, 'visible', vis ); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.3 .15 .05], 'tag', 'tmp', ... + 'style', 'text', 'string', 'Display:','fontweight', 'bold' ); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.35 .15 .02], 'tag', 'tmp',... + 'style', 'text', 'string', ''); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.37 .15 .05], 'tag', 'tmp','userdata', 'z',... + 'style', 'text', 'string', 'Z:', 'visible', vis ); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.42 .15 .05], 'tag', 'tmp','userdata', 'y', ... + 'style', 'text', 'string', 'Y:', 'visible', vis ); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.47 .15 .05], 'tag', 'tmp', 'userdata', 'x',... + 'style', 'text', 'string', 'X:', 'visible', vis ); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.52 .15 .05], 'tag', 'tmp', 'userdata', 'rv',... + 'style', 'text', 'string', 'RV:' ); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.57 .15 .05], 'tag', 'tmp', 'userdata', 'comp', ... + 'style', 'text', 'string', ''); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.62 .15 .05], 'tag', 'tmp', 'userdata', 'editor', ... + 'style', 'edit', 'string', '1', 'callback', ... + [ 'dipplot(gcbf);' ] ); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.67 .15 .05], 'tag', 'tmp', ... + 'style', 'pushbutton', 'string', 'Keep|Prev', 'callback', ... + [ 'editobj = findobj(''parent'', gcf, ''userdata'', ''editor'');' ... + 'set(editobj, ''string'', num2str(str2num(get(editobj, ''string''))-1));' ... + 'tmpobj = get(gcf, ''userdata'');' ... + 'eval(get(editobj, ''callback''));' ... + 'set(tmpobj, ''visible'', ''on'');' ... + 'clear editobj tmpobj;' ]); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.72 .15 .05], 'tag', 'tmp', ... + 'style', 'pushbutton', 'string', 'Prev', 'callback', ... + [ 'editobj = findobj(''parent'', gcf, ''userdata'', ''editor'');' ... + 'set(editobj, ''string'', num2str(str2num(get(editobj, ''string''))-1));' ... + 'eval(get(editobj, ''callback''));' ... + 'clear editobj;' ]); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.77 .15 .05], 'tag', 'tmp', ... + 'style', 'pushbutton', 'string', 'Next', 'callback', ... + [ 'editobj = findobj(''parent'', gcf, ''userdata'', ''editor'');' ... + 'set(editobj, ''string'', num2str(str2num(get(editobj, ''string''))+1));' ... + 'dipplot(gcbf);' ... + 'clear editobj;' ]); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.82 .15 .05], 'tag', 'tmp', ... + 'style', 'pushbutton', 'string', 'Keep|Next', 'callback', ... + [ 'editobj = findobj(''parent'', gcf, ''userdata'', ''editor'');' ... + 'set(editobj, ''string'', num2str(str2num(get(editobj, ''string''))+1));' ... + 'tmpobj = get(gcf, ''userdata'');' ... + 'dipplot(gcbf);' ... + 'set(tmpobj, ''visible'', ''on'');' ... + 'clear editobj tmpobj;' ]); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.87 .15 .05], 'tag', 'tmp', ... + 'style', 'pushbutton', 'string', 'Plot one', 'callback', cbplot); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.92 .15 .05], 'tag', 'tmp', ... + 'style', 'text', 'string', [num2str(length(sources)) ' dipoles:'], 'fontweight', 'bold' ); + h = uicontrol( 'unit', 'normalized', 'position', [0 0.97 .15 .05], 'tag', 'tmp', ... + 'style', 'text', 'string', ''); + set(gcf, 'userdata', findobj('parent', gca, 'tag', 'dipole1')); + + dat.nbsources = length(sources); + set(gca, 'userdata', dat ); % last param=1 for MRI view tight/loose + set(gcf, 'color', BACKCOLOR); + + if strcmp(g.gui, 'off') | strcmpi(g.holdon, 'on') + set(findobj('parent', gcf, 'tag', 'tmp'), 'visible', 'off'); + end; + if strcmp(g.mesh, 'off') + set(findobj('parent', gca, 'tag', 'mesh'), 'visible', 'off'); + end; + + updatedipplot(gcf); + + rotate3d on; + + % close figure if necessary + if strcmpi(g.plot, 'off') + try, close(fig); catch, end; + end; + + if strcmpi(g.holdon, 'on') + box off; + axis equal; + axis off; + end; + + % set camera positon + if strcmpi(g.camera, 'set') + set(gca, 'CameraPosition', [2546.94 -894.981 689.613], ... + 'CameraPositionMode', 'manual', ... + 'CameraTarget', [0 -18 18], ... + 'CameraTargetMode', 'manual', ... + 'CameraUpVector', [0 0 1], ... + 'CameraUpVectorMode', 'manual', ... + 'CameraViewAngle', [3.8815], ... + 'CameraViewAngleMode', 'manual'); + end; + +return; + +% electrode space to MRI space +% ============================ +function [x,y,z] = transform(x, y, z, transmat); + + if isempty(transmat), return; end; + for i = 1:size(x,1) + for j = 1:size(x,2) + tmparray = transmat * [ x(i,j) y(i,j) z(i,j) 1 ]'; + x(i,j) = tmparray(1); + y(i,j) = tmparray(2); + z(i,j) = tmparray(3); + end; + end; + + +% does not work any more +% ---------------------- +function sc = plotellipse(sources, ind, nstd, TCPARAMS, coreg); + + for i = 1:length(ind) + tmpval(1,i) = -sources(ind(i)).posxyz(1); + tmpval(2,i) = -sources(ind(i)).posxyz(2); + tmpval(3,i) = sources(ind(i)).posxyz(3); + [tmpval(1,i) tmpval(2,i) tmpval(3,i)] = transform(tmpval(1,i), tmpval(2,i), tmpval(3,i), TCPARAMS); + end; + + % mean and covariance + C = cov(tmpval'); + M = mean(tmpval,2); + [U,L] = eig(C); + + % For N standard deviations spread of data, the radii of the eliipsoid will + % be given by N*SQRT(eigenvalues). + radii = nstd*sqrt(diag(L)); + + % generate data for "unrotated" ellipsoid + [xc,yc,zc] = ellipsoid(0,0,0,radii(1),radii(2),radii(3), 10); + + % rotate data with orientation matrix U and center M + a = kron(U(:,1),xc); b = kron(U(:,2),yc); c = kron(U(:,3),zc); + data = a+b+c; n = size(data,2); + x = data(1:n,:)+M(1); y = data(n+1:2*n,:)+M(2); z = data(2*n+1:end,:)+M(3); + + % now plot the rotated ellipse + c = ones(size(z)); + sc = mesh(x,y,z); + alpha(0.5) + +function newsrc = convertbesaoldformat(src); + newsrc = []; + count = 1; + countdip = 1; + if ~isfield(src, 'besaextori'), src(1).besaextori = []; end; + for index = 1:length(src) + + % convert format + % -------------- + if isempty(src(index).besaextori), src(index).besaextori = 300; end; % 20 mm + newsrc(count).possph(countdip,:) = [ src(index).besathloc src(index).besaphloc src(index).besaexent]; + newsrc(count).momsph(countdip,:) = [ src(index).besathori src(index).besaphori src(index).besaextori/300]; + + % copy other fields + % ----------------- + if isfield(src, 'stdX') + newsrc(count).stdX = -src(index).stdY; + newsrc(count).stdY = src(index).stdX; + newsrc(count).stdZ = src(index).stdZ; + end; + if isfield(src, 'rv') + newsrc(count).rv = src(index).rv; + end; + if isfield(src, 'elecrv') + newsrc(count).rvelec = src(index).elecrv; + end; + if isfield(src, 'component') + newsrc(count).component = src(index).component; + if index ~= length(src) & src(index).component == src(index+1).component + countdip = countdip + 1; + else + count = count + 1; countdip = 1; + end; + else + count = count + 1; countdip = 1; + end; + end; + +function src = computexyzforbesa(src); + + for index = 1:length( src ) + for index2 = 1:size( src(index).possph, 1 ) + + % compute coordinates + % ------------------- + postmp = src(index).possph(index2,:); + momtmp = src(index).momsph(index2,:); + + phi = postmp(1)+90; %% %%%%%%%%%%%%%%% USE BESA COORDINATES %%%%% + theta = postmp(2); %% %%%%%%%%%%%%%%% USE BESA COORDINATES %%%%% + phiori = momtmp(1)+90; %% %%%%%%%%%%%% USE BESA COORDINATES %%%%% + thetaori = momtmp(2); %% %%%%%%%%%%%% USE BESA COORDINATES %%%%% + % exentricities are in % of the radius of the head sphere + [x y z] = sph2cart(theta/180*pi, phi/180*pi, postmp(3)/1.2); + [xo yo zo] = sph2cart(thetaori/180*pi, phiori/180*pi, momtmp(3)*5); % exentricity scaled for compatibility with DIPFIT + src(index).posxyz(index2,:) = [-y x z]; + src(index).momxyz(index2,:) = [-yo xo zo]; + + end; + end; + +% update dipplot (callback call) +% ------------------------------ +function updatedipplot(fig) + + % find current dipole index and test for authorized range + % ------------------------------------------------------- + dat = get(gca, 'userdata'); + editobj = findobj('parent', fig, 'userdata', 'editor'); + tmpnum = str2num(get(editobj(end), 'string')); + if tmpnum < 1, tmpnum = 1; end; + if tmpnum > dat.nbsources, tmpnum = dat.nbsources; end; + set(editobj(end), 'string', num2str(tmpnum)); + + % hide current dipole, find next dipole and show it + % ------------------------------------------------- + set(get(gcf, 'userdata'), 'visible', 'off'); + newdip = findobj('parent', gca, 'tag', [ 'dipole' get(editobj(end), 'string')]); + set(newdip, 'visible', 'on'); + set(gcf, 'userdata', newdip); + + % find all dipolar structures + % --------------------------- + index = 1; + count = 1; + for index = 1:length(newdip) + if isstruct( get(newdip(index), 'userdata') ) + dip_mricoord(count,:) = getfield(get(newdip(index), 'userdata'), 'mricoord'); + count = count+1; + foundind = index; + end; + end; + + % get residual variance + % --------------------- + if exist('foundind') + tmp = get(newdip(foundind), 'userdata'); + tal = tmp.talcoord; + if ~isstr( tmp.name ) + tmprvobj = findobj('parent', fig, 'userdata', 'comp'); set( tmprvobj(end), 'string', [ 'Comp: ' int2str(tmp.name) ] ); + else tmprvobj = findobj('parent', fig, 'userdata', 'comp'); set( tmprvobj(end), 'string', tmp.name ); + end; + tmprvobj = findobj('parent', fig, 'userdata', 'rv'); set( tmprvobj(end), 'string', [ 'RV: ' tmp.rv '%' ] ); + tmprvobj = findobj('parent', fig, 'userdata', 'x'); set( tmprvobj(end), 'string', [ 'X tal: ' int2str(round(tal(1))) ]); + tmprvobj = findobj('parent', fig, 'userdata', 'y'); set( tmprvobj(end), 'string', [ 'Y tal: ' int2str(round(tal(2))) ]); + tmprvobj = findobj('parent', fig, 'userdata', 'z'); set( tmprvobj(end), 'string', [ 'Z tal: ' int2str(round(tal(3))) ]); + end + + % adapt the MRI to the dipole depth + % --------------------------------- + delete(findobj('parent', gca, 'tag', 'img')); + + tmpdiv1 = dat.imgcoords{1}(2)-dat.imgcoords{1}(1); + tmpdiv2 = dat.imgcoords{2}(2)-dat.imgcoords{2}(1); + tmpdiv3 = dat.imgcoords{3}(2)-dat.imgcoords{3}(1); + if ~dat.axistight + [xx yy zz] = transform(0,0,0, pinv(dat.transform)); % elec -> MRI space + indx = minpos(dat.imgcoords{1}-zz); + indy = minpos(dat.imgcoords{2}-yy); + indz = minpos(dat.imgcoords{3}-xx); + else + if ~dat.cornermri + indx = minpos(dat.imgcoords{1} - mean(dip_mricoord(:,1))) - 3*tmpdiv1; + indy = minpos(dat.imgcoords{2} - mean(dip_mricoord(:,2))) + 3*tmpdiv2; + indz = minpos(dat.imgcoords{3} - mean(dip_mricoord(:,3))) - 3*tmpdiv3; + else % no need to shift slice if not ploted close to the dipole + indx = minpos(dat.imgcoords{1} - mean(dip_mricoord(:,1))); + indy = minpos(dat.imgcoords{2} - mean(dip_mricoord(:,2))); + indz = minpos(dat.imgcoords{3} - mean(dip_mricoord(:,3))); + end; + end; + + % middle of the brain + % ------------------- + plotimgs( dat,min(max([indx indy indz],1),size(dat.imgs)), dat.transform); + %end; + +% plot images (transmat is the uniform matrix MRI coords -> elec coords) +% ---------------------------------------------------------------------- +function plotimgs(dat, mricoord, transmat); + + % loading images + % -------------- + if ndims(dat.imgs) == 4 % true color data + img1(:,:,3) = rot90(squeeze(dat.imgs(mricoord(1),:,:,3))); + img2(:,:,3) = rot90(squeeze(dat.imgs(:,mricoord(2),:,3))); + img3(:,:,3) = rot90(squeeze(dat.imgs(:,:,mricoord(3),3))); + img1(:,:,2) = rot90(squeeze(dat.imgs(mricoord(1),:,:,2))); + img2(:,:,2) = rot90(squeeze(dat.imgs(:,mricoord(2),:,2))); + img3(:,:,2) = rot90(squeeze(dat.imgs(:,:,mricoord(3),2))); + img1(:,:,1) = rot90(squeeze(dat.imgs(mricoord(1),:,:,1))); + img2(:,:,1) = rot90(squeeze(dat.imgs(:,mricoord(2),:,1))); + img3(:,:,1) = rot90(squeeze(dat.imgs(:,:,mricoord(3),1))); + else + img1 = rot90(squeeze(dat.imgs(mricoord(1),:,:))); + img2 = rot90(squeeze(dat.imgs(:,mricoord(2),:))); + img3 = rot90(squeeze(dat.imgs(:,:,mricoord(3)))); + + if ndims(img1) == 2, img1(:,:,3) = img1; img1(:,:,2) = img1(:,:,1); end; + if ndims(img2) == 2, img2(:,:,3) = img2; img2(:,:,2) = img2(:,:,1); end; + if ndims(img3) == 2, img3(:,:,3) = img3; img3(:,:,2) = img3(:,:,1); end; + end; + + % computing coordinates for planes + % -------------------------------- + wy1 = [min(dat.imgcoords{2}) max(dat.imgcoords{2}); min(dat.imgcoords{2}) max(dat.imgcoords{2})]; + wz1 = [min(dat.imgcoords{3}) min(dat.imgcoords{3}); max(dat.imgcoords{3}) max(dat.imgcoords{3})]; + wx2 = [min(dat.imgcoords{1}) max(dat.imgcoords{1}); min(dat.imgcoords{1}) max(dat.imgcoords{1})]; + wz2 = [min(dat.imgcoords{3}) min(dat.imgcoords{3}); max(dat.imgcoords{3}) max(dat.imgcoords{3})]; + wx3 = [min(dat.imgcoords{1}) max(dat.imgcoords{1}); min(dat.imgcoords{1}) max(dat.imgcoords{1})]; + wy3 = [min(dat.imgcoords{2}) min(dat.imgcoords{2}); max(dat.imgcoords{2}) max(dat.imgcoords{2})]; + if dat.axistight & ~dat.cornermri + wx1 = [ 1 1; 1 1]*dat.imgcoords{1}(mricoord(1)); + wy2 = [ 1 1; 1 1]*dat.imgcoords{2}(mricoord(2)); + wz3 = [ 1 1; 1 1]*dat.imgcoords{3}(mricoord(3)); + else + wx1 = [ 1 1; 1 1]*dat.imgcoords{1}(1); + wy2 = [ 1 1; 1 1]*dat.imgcoords{2}(end); + wz3 = [ 1 1; 1 1]*dat.imgcoords{3}(1); + end; + + % transform MRI coordinates to electrode space + % -------------------------------------------- + [ elecwx1 elecwy1 elecwz1 ] = transform( wx1, wy1, wz1, transmat); + [ elecwx2 elecwy2 elecwz2 ] = transform( wx2, wy2, wz2, transmat); + [ elecwx3 elecwy3 elecwz3 ] = transform( wx3, wy3, wz3, transmat); + + % ploting surfaces + % ---------------- + options = { 'FaceColor','texturemap', 'EdgeColor','none', 'CDataMapping', ... + 'direct','tag','img', 'facelighting', 'none' }; + hold on; + surface(elecwx1, elecwy1, elecwz1, img1(end:-1:1,:,:), options{:}); + surface(elecwx2, elecwy2, elecwz2, img2(end:-1:1,:,:), options{:}); + surface(elecwx3, elecwy3, elecwz3, img3(end:-1:1,:,:), options{:}); + %xlabel('x'); ylabel('y'); zlabel('z'); axis equal; dsaffd + + if strcmpi(dat.drawedges, 'on') + % removing old edges if any + delete(findobj( gcf, 'tag', 'edges')); + if dat.axistight & ~dat.cornermri, col = 'k'; else col = [0.5 0.5 0.5]; end; + h(1) = line([elecwx3(1) elecwx3(2)]', [elecwy3(1) elecwy2(1)]', [elecwz1(1) elecwz1(2)]'); % sagittal-transverse + h(2) = line([elecwx3(1) elecwx2(3)]', [elecwy2(1) elecwy2(2)]', [elecwz1(1) elecwz1(2)]'); % coronal-tranverse + h(3) = line([elecwx3(1) elecwx3(2)]', [elecwy2(1) elecwy2(2)]', [elecwz3(1) elecwz1(1)]'); % sagittal-coronal + set(h, 'color', col, 'linewidth', 2, 'tag', 'edges'); + end; + + %%fill3([-2 -2 2 2], [-2 2 2 -2], wz(:)-1, BACKCOLOR); + %%fill3([-2 -2 2 2], wy(:)-1, [-2 2 2 -2], BACKCOLOR); + rotate3d on + +function index = minpos(vals); + vals(find(vals < 0)) = inf; + [tmp index] = min(vals); + +function scalegca(multfactor) + xl = xlim; xf = ( xl(2) - xl(1) ) * multfactor; + yl = ylim; yf = ( yl(2) - yl(1) ) * multfactor; + zl = zlim; zf = ( zl(2) - zl(1) ) * multfactor; + xlim( [ xl(1)-xf xl(2)+xf ]); + ylim( [ yl(1)-yf yl(2)+yf ]); + zlim( [ zl(1)-zf zl(2)+zf ]); + +function color = strcol2real(colorin, colmap) + if ~iscell(colorin) + for index = 1:length(colorin) + color{index} = colmap(colorin(index),:); + end; + else + color = colorin; + for index = 1:length(colorin) + if isstr(colorin{index}) + switch colorin{index} + case 'r', color{index} = [1 0 0]; + case 'g', color{index} = [0 1 0]; + case 'b', color{index} = [0 0 1]; + case 'c', color{index} = [0 1 1]; + case 'm', color{index} = [1 0 1]; + case 'y', color{index} = [1 1 0]; + case 'k', color{index} = [0 0 0]; + case 'w', color{index} = [1 1 1]; + otherwise, error('Unknown color'); + end; + end; + end; + end; + +function x = gammacorrection(x, gammaval); + x = 255 * (double(x)/255).^ gammaval; + % image is supposed to be scaled from 0 to 255 + % gammaval = 1 is identity of course + diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/eeglab2fieldtrip.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/eeglab2fieldtrip.m new file mode 100644 index 0000000000000000000000000000000000000000..f6fb7b0f8db93757a341e2ef15f2d6e744137522 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/eeglab2fieldtrip.m @@ -0,0 +1,161 @@ +% eeglab2fieldtrip() - do this ... +% +% Usage: >> data = eeglab2fieldtrip( EEG, fieldbox, transform ); +% +% Inputs: +% EEG - [struct] EEGLAB structure +% fieldbox - ['preprocessing'|'freqanalysis'|'timelockanalysis'|'companalysis'] +% transform - ['none'|'dipfit'] transform channel locations for DIPFIT +% using the transformation matrix in the field +% 'coord_transform' of the dipfit substructure of the EEG +% structure. +% Outputs: +% data - FIELDTRIP structure +% +% Author: Robert Oostenveld, F.C. Donders Centre, May, 2004. +% Arnaud Delorme, SCCN, INC, UCSD +% +% See also: + +% Copyright (C) 2004 Robert Oostenveld, F.C. Donders Centre, roberto@smi.auc.dk +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function data = eeglab2fieldtrip(EEG, fieldbox, transform) + +if nargin < 2 + help eeglab2fieldtrip + return; +end; + +% start with an empty data object +data = []; + +% add the objects that are common to all fieldboxes +tmpchanlocs = EEG.chanlocs; +data.label = { tmpchanlocs(EEG.icachansind).labels }; +data.fsample = EEG.srate; + +% get the electrode positions from the EEG structure: in principle, the number of +% channels can be more or less than the number of channel locations, i.e. not +% every channel has a position, or the potential was not measured on every +% position. This is not supported by EEGLAB, but it is supported by FIELDTRIP. + +if strcmpi(fieldbox, 'chanloc_withfid') + % insert "no data channels" in channel structure + % ---------------------------------------------- + if isfield(EEG.chaninfo, 'nodatchans') && ~isempty( EEG.chaninfo.nodatchans ) + chanlen = length(EEG.chanlocs); + fields = fieldnames( EEG.chaninfo.nodatchans ); + for index = 1:length(EEG.chaninfo.nodatchans) + ind = chanlen+index; + for f = 1:length( fields ) + EEG.chanlocs = setfield(EEG.chanlocs, { ind }, fields{f}, ... + getfield( EEG.chaninfo.nodatchans, { index }, fields{f})); + end; + end; + end; +end; + +data.elec.pnt = zeros(length( EEG.chanlocs ), 3); +for ind = 1:length( EEG.chanlocs ) + data.elec.label{ind} = EEG.chanlocs(ind).labels; + if ~isempty(EEG.chanlocs(ind).X) + data.elec.pnt(ind,1) = EEG.chanlocs(ind).X; + data.elec.pnt(ind,2) = EEG.chanlocs(ind).Y; + data.elec.pnt(ind,3) = EEG.chanlocs(ind).Z; + else + data.elec.pnt(ind,:) = [0 0 0]; + end; +end; + +if nargin > 2 + if strcmpi(transform, 'dipfit') + if ~isempty(EEG.dipfit.coord_transform) + disp('Transforming electrode coordinates to match head model'); + transfmat = traditionaldipfit(EEG.dipfit.coord_transform); + data.elec.pnt = transfmat * [ data.elec.pnt ones(size(data.elec.pnt,1),1) ]'; + data.elec.pnt = data.elec.pnt(1:3,:)'; + else + disp('Warning: no transformation of electrode coordinates to match head model'); + end; + end; +end; + +switch fieldbox + case 'preprocessing' + for index = 1:EEG.trials + data.trial{index} = EEG.data(:,:,index); + data.time{index} = linspace(EEG.xmin, EEG.xmax, EEG.pnts); % should be checked in FIELDTRIP + end; + data.label = { tmpchanlocs(1:EEG.nbchan).labels }; + + + case 'timelockanalysis' + data.avg = mean(EEG.data, 3); + data.var = std(EEG.data, [], 3).^2; + data.time = linspace(EEG.xmin, EEG.xmax, EEG.pnts); % should be checked in FIELDTRIP + data.label = { tmpchanlocs(1:EEG.nbchan).labels }; + + case 'componentanalysis' + if isempty(EEG.icaact) + icaacttmp = eeg_getica(EEG); + end + for index = 1:EEG.trials + % the trials correspond to the raw data trials, except that they + % contain the component activations + try + if isempty(EEG.icaact) + data.trial{index} = icaacttmp(:,:,index); % Using icaacttmp to not change EEG structure + else + data.trial{index} = EEG.icaact(:,:,index); + end + catch + + end; + data.time{index} = linspace(EEG.xmin, EEG.xmax, EEG.pnts); % should be checked in FIELDTRIP + end; + data.label = []; + for comp = 1:size(EEG.icawinv,2) + % the labels correspond to the component activations that are stored in data.trial + data.label{comp} = sprintf('ica_%03d', comp); + end + % get the spatial distribution and electrode positions + tmpchanlocs = EEG.chanlocs; + data.topolabel = { tmpchanlocs(EEG.icachansind).labels }; + data.topo = EEG.icawinv; + + case { 'chanloc' 'chanloc_withfid' } + + case 'freqanalysis' + error('freqanalysis fieldbox not implemented yet') + + otherwise + error('unsupported fieldbox') +end + +try + % get the full name of the function + data.cfg.version.name = mfilename('fullpath'); +catch + % required for compatibility with Matlab versions prior to release 13 (6.5) + [st, i] = dbstack; + data.cfg.version.name = st(i); +end + +% add the version details of this function call to the configuration +data.cfg.version.id = '$Id: eeglab2fieldtrip.m,v 1.6 2009-07-02 23:39:29 arno Exp $'; + +return diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/eegplugin_dipfit.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/eegplugin_dipfit.m new file mode 100644 index 0000000000000000000000000000000000000000..899dd0052ac19484ca073d79320926f2774ac69f --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/eegplugin_dipfit.m @@ -0,0 +1,86 @@ +% eegplugin_dipfit() - DIPFIT plugin version 2.0 for EEGLAB menu. +% DIPFIT is the dipole fitting Matlab Toolbox of +% Robert Oostenveld (in collaboration with A. Delorme). +% +% Usage: +% >> eegplugin_dipfit(fig, trystrs, catchstrs); +% +% Inputs: +% fig - [integer] eeglab figure. +% trystrs - [struct] "try" strings for menu callbacks. +% catchstrs - [struct] "catch" strings for menu callbacks. +% +% Notes: +% To create a new plugin, simply create a file beginning with "eegplugin_" +% and place it in your eeglab folder. It will then be automatically +% detected by eeglab. See also this source code internal comments. +% For eeglab to return errors and add the function's results to +% the eeglab history, menu callback must be nested into "try" and +% a "catch" strings. For more information on how to create eeglab +% plugins, see http://www.sccn.ucsd.edu/eeglab/contrib.html +% +% Author: Arnaud Delorme, CNL / Salk Institute, 22 February 2003 +% +% See also: eeglab() + +% Copyright (C) 2003 Arnaud Delorme, Salk Institute, arno@salk.edu +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1.07 USA + +function vers = eegplugin_dipfit(fig, trystrs, catchstrs) + + vers = 'dipfit2.2'; + if nargin < 3 + error('eegplugin_dipfit requires 3 arguments'); + end; + + % find tools menu + % --------------- + menu = findobj(fig, 'tag', 'tools'); + % tag can be + % 'import data' -> File > import data menu + % 'import epoch' -> File > import epoch menu + % 'import event' -> File > import event menu + % 'export' -> File > export + % 'tools' -> tools menu + % 'plot' -> plot menu + + % command to check that the '.source' is present in the EEG structure + % ------------------------------------------------------------------- + check_dipfit = [trystrs.no_check 'if ~isfield(EEG, ''dipfit''), error(''Run the dipole setting first''); end;' ... + 'if isempty(EEG.dipfit), error(''Run the dipole setting first''); end;' ]; + check_dipfitnocheck = [ trystrs.no_check 'if ~isfield(EEG, ''dipfit''), error(''Run the dipole setting first''); end; ' ]; + check_chans = [ '[EEG tmpres] = eeg_checkset(EEG, ''chanlocs_homogeneous'');' ... + 'if ~isempty(tmpres), eegh(tmpres), end; clear tmpres;' ]; + + % menu callback commands + % ---------------------- + comsetting = [ trystrs.check_ica check_chans '[EEG LASTCOM]=pop_dipfit_settings(EEG);' catchstrs.store_and_hist ]; + combatch = [ check_dipfit check_chans '[EEG LASTCOM] = pop_dipfit_gridsearch(EEG);' catchstrs.store_and_hist ]; + comfit = [ check_dipfitnocheck check_chans [ 'EEG = pop_dipfit_nonlinear(EEG); ' ... + 'LASTCOM = ''% === History not supported for manual dipole fitting ==='';' ] catchstrs.store_and_hist ]; + comauto = [ check_dipfit check_chans '[EEG LASTCOM] = pop_multifit(EEG);' catchstrs.store_and_hist ]; + % preserve the '=" sign in the comment above: it is used by EEGLAB to detect appropriate LASTCOM + complot = [ check_dipfit check_chans 'LASTCOM = pop_dipplot(EEG);' catchstrs.add_to_hist ]; + + + % create menus + % ------------ + submenu = uimenu( menu, 'Label', 'Locate dipoles using DIPFIT 2.x', 'separator', 'on'); + uimenu( submenu, 'Label', 'Head model and settings' , 'CallBack', comsetting); + uimenu( submenu, 'Label', 'Coarse fit (grid scan)' , 'CallBack', combatch); + uimenu( submenu, 'Label', 'Fine fit (iterative)' , 'CallBack', comfit); + uimenu( submenu, 'Label', 'Autofit (coarse fit, fine fit & plot)', 'CallBack', comauto); + uimenu( submenu, 'Label', 'Plot component dipoles' , 'CallBack', complot, 'separator', 'on'); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/electroderealign.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/electroderealign.m new file mode 100644 index 0000000000000000000000000000000000000000..905d364e968b4c89459fcd92dba044b0c20d7d89 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/electroderealign.m @@ -0,0 +1,720 @@ +function [norm] = electroderealign(cfg); + +% ELECTRODEREALIGN rotates and translates electrode positions to +% template electrode positions or towards the head surface. It can +% either perform a rigid body transformation, in which only the +% coordinate system is changed, or it can apply additional deformations +% to the input electrodes. +% +% Use as +% [elec] = electroderealign(cfg) +% +% Three different methods for aligning the input electrodes are implemented: +% based on a warping method, based on the fiducials or interactive with a +% graphical user interface. Each of these approaches is described below. +% +% 1) You can apply a spatial deformation method (i.e. 'warp') that +% automatically minimizes the distance between the electrodes and the +% averaged standard. The warping methods use a non-linear search to +% optimize the error between input and template electrodes or the +% head surface. +% +% 2) You can apply a rigid body realignment based on three fiducial locations. +% Realigning using the fiducials only ensures that the fiducials (typically +% nose, left and right ear) are along the same axes in the input electrode +% set as in the template electrode set. +% +% 3) You can display the electrode positions together with the skin surface, +% and manually (using the graphical user interface) adjust the rotation, +% translation and scaling parameters, so that the two match. +% +% The configuration can contain the following options +% cfg.method = different methods for aligning the electrodes +% 'rigidbody' apply a rigid-body warp +% 'globalrescale' apply a rigid-body warp with global rescaling +% 'traditional' apply a rigid-body warp with individual axes rescaling +% 'nonlin1' apply a 1st order non-linear warp +% 'nonlin2' apply a 2nd order non-linear warp +% 'nonlin3' apply a 3rd order non-linear warp +% 'nonlin4' apply a 4th order non-linear warp +% 'nonlin5' apply a 5th order non-linear warp +% 'realignfiducial' realign the fiducials +% 'interactive' manually using graphical user interface +% cfg.channel = Nx1 cell-array with selection of channels (default = 'all'), +% see CHANNELSELECTION for details +% cfg.fiducial = cell-array with the name of three fiducials used for +% realigning (default = {'nasion', 'lpa', 'rpa'}) +% cfg.casesensitive = 'yes' or 'no', determines whether string comparisons +% between electrode labels are case sensitive (default = 'yes') +% cfg.feedback = 'yes' or 'no' (default = 'no') +% +% The electrode set that will be realigned is specified as +% cfg.elecfile = string with filename, or alternatively +% cfg.elec = structure with electrode definition +% +% If you want to align the electrodes to a single template electrode set +% or to multiple electrode sets (which will be averaged), you should +% specify the template electrode sets as +% cfg.template = single electrode set that serves as standard +% or +% cfg.template{1..N} = list of electrode sets that are averaged into the standard +% The template electrode sets can be specified either as electrode +% structures (i.e. when they are already read in memory) or as electrode +% files. +% +% If you want to align the electrodes to the head surface as obtained from +% an anatomical MRI (using one of the warping methods), you should specify +% the head surface +% cfg.headshape = a filename containing headshape, a structure containing a +% single triangulated boundary, or a Nx3 matrix with surface +% points +% +% In case you only want to realign the fiducials, the template electrode +% set only has to contain the three fiducials, e.g. +% cfg.template.pnt(1,:) = [110 0 0] % location of the nose +% cfg.template.pnt(2,:) = [0 90 0] % left ear +% cfg.template.pnt(3,:) = [0 -90 0] % right ear +% cfg.template.label = {''nasion', 'lpa', 'rpa'} +% +% See also READ_FCDC_ELEC, VOLUMEREALIGN + +% Copyright (C) 2005-2006, Robert Oostenveld +% +% $Log: electroderealign.m,v $ +% Revision 1.1 2009/01/30 04:02:02 arno +% *** empty log message *** +% +% Revision 1.6 2007/08/06 09:20:14 roboos +% added support for bti_hs +% +% Revision 1.5 2007/07/26 08:00:09 roboos +% also deal with cfg.headshape if specified as surface, set of points or ctf_hs file. +% the construction of the tri is now done consistently for all headshapes if tri is missing +% +% Revision 1.4 2007/02/13 15:12:51 roboos +% removed cfg.plot3d option +% +% Revision 1.3 2006/12/12 11:28:33 roboos +% moved projecttri subfunction into seperate function +% +% Revision 1.2 2006/10/04 07:10:07 roboos +% updated documentation +% +% Revision 1.1 2006/09/13 07:20:06 roboos +% renamed electrodenormalize to electroderealign, added "deprecated"-warning to the old function +% +% Revision 1.10 2006/09/13 07:09:24 roboos +% Implemented support for cfg.method=interactive, using GUI for specifying and showing transformations. Sofar only for electrodes+headsurface. +% +% Revision 1.9 2006/09/12 15:26:06 roboos +% implemented support for aligning electrodes to the skin surface, extended and improved documentation +% +% Revision 1.8 2006/04/20 09:58:34 roboos +% updated documentation +% +% Revision 1.7 2006/04/19 15:42:53 roboos +% replaced call to warp_pnt with new function name warp_optim +% +% Revision 1.6 2006/03/14 08:16:00 roboos +% changed function call to warp3d into warp_apply (thanks to Arno) +% +% Revision 1.5 2005/05/17 17:50:37 roboos +% changed all "if" occurences of & and | into && and || +% this makes the code more compatible with Octave and also seems to be in closer correspondence with Matlab documentation on shortcircuited evaluation of sequential boolean constructs +% +% Revision 1.4 2005/03/21 15:49:43 roboos +% added cfg.casesensitive for string comparison of electrode labels +% added cfg.feedback and cfg.plot3d option for debugging +% changed output: now ALL electrodes of the input are rerurned, after applying the specified transformation +% fixed small bug in feedback regarding distarnce prior/after realignfiducials) +% added support for various warping strategies, a.o. traditional, rigidbody, nonlin1-5, etc. +% +% Revision 1.3 2005/03/16 09:18:56 roboos +% fixed bug in fprintf feedback, instead of giving mean squared distance it should give mean distance before and after normalization +% +% Revision 1.2 2005/01/18 12:04:39 roboos +% improved error handling of missing fiducials +% added other default fiducials +% changed debugging output +% +% Revision 1.1 2005/01/17 14:56:06 roboos +% new implementation +% + +% set the defaults +if ~isfield(cfg, 'channel'), cfg.channel = 'all'; end +if ~isfield(cfg, 'feedback'), cfg.feedback = 'no'; end +if ~isfield(cfg, 'casesensitive'), cfg.casesensitive = 'yes'; end +if ~isfield(cfg, 'headshape'), cfg.headshape = []; end +if ~isfield(cfg, 'template'), cfg.template = []; end + +% this is a common mistake which can be accepted +if strcmp(cfg.method, 'realignfiducials') + cfg.method = 'realignfiducial'; +end + +if strcmp(cfg.method, 'warp') + % rename the default warp to one of the method recognized by the warping toolbox + cfg.method = 'traditional'; +end + +if strcmp(cfg.feedback, 'yes') + % use the global fb field to tell the warping toolbox to print feedback + global fb + fb = 1; +else + global fb + fb = 0; +end + +usetemplate = isfield(cfg, 'template') && ~isempty(cfg.template); +useheadshape = isfield(cfg, 'headshape') && ~isempty(cfg.headshape); + +if usetemplate + % get the template electrode definitions + if ~iscell(cfg.template) + cfg.template = {cfg.template}; + end + Ntemplate = length(cfg.template); + for i=1:Ntemplate + if isstruct(cfg.template{i}) + template(i) = cfg.template{i}; + else + template(i) = read_fcdc_elec(cfg.template{i}); + end + end +elseif useheadshape + % get the surface describing the head shape + if isstruct(cfg.headshape) && isfield(cfg.headshape, 'pnt') + % use the headshape surface specified in the configuration + headshape = cfg.headshape; + elseif isnumeric(cfg.headshape) && size(cfg.headshape,2)==3 + % use the headshape points specified in the configuration + headshape.pnt = cfg.headshape; + elseif ischar(cfg.headshape) && filetype(cfg.headshape, 'ctf_shape') + % read the headshape from file + headshape = read_ctf_shape(cfg.headshape); + elseif ischar(cfg.headshape) && filetype(cfg.headshape, '4d_hs') + % read the headshape from file + headshape = []; + headshape.pnt = read_bti_hs(cfg.headshape); + else + error('cfg.headshape is not specified correctly') + end + if ~isfield(headshape, 'tri') + % generate a closed triangulation from the surface points + headshape.tri = projecttri(headshape.pnt); + end +else + error('you should either specify template electrode positions, template fiducials or a head shape'); +end + +% get the electrode definition that should be warped +if isfield(cfg, 'elec') + elec = cfg.elec; +else + elec = read_fcdc_elec(cfg.elecfile); +end + +% remember the original electrode locations and labels +orig = elec; + +% convert all labels to lower case for string comparisons +% this has to be done AFTER keeping the original labels and positions +if strcmp(cfg.casesensitive, 'no') + for i=1:length(elec.label) + elec.label{i} = lower(elec.label{i}); + end + for j=1:length(template) + for i=1:length(template(j).label) + template(j).label{i} = lower(template(j).label{i}); + end + end +end + +if strcmp(cfg.feedback, 'yes') + % create an empty figure, continued below... + figure + axis equal + axis vis3d + hold on + xlabel('x') + ylabel('y') + zlabel('z') +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if usetemplate && any(strcmp(cfg.method, {'rigidbody', 'globalrescale', 'traditional', 'nonlin1', 'nonlin2', 'nonlin3', 'nonlin4', 'nonlin5'})) + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + % determine electrode selection and overlapping subset for warping + cfg.channel = channelselection(cfg.channel, elec.label); + for i=1:Ntemplate + cfg.channel = channelselection(cfg.channel, template(i).label); + end + + % make subselection of electrodes + [cfgsel, datsel] = match_str(cfg.channel, elec.label); + elec.label = elec.label(datsel); + elec.pnt = elec.pnt(datsel,:); + for i=1:Ntemplate + [cfgsel, datsel] = match_str(cfg.channel, template(i).label); + template(i).label = template(i).label(datsel); + template(i).pnt = template(i).pnt(datsel,:); + end + + % compute the average of the template electrode positions + all = []; + for i=1:Ntemplate + all = cat(3, all, template(i).pnt); + end + avg = mean(all,3); + stderr = std(all, [], 3); + + fprintf('warping electrodes to template... '); % the newline comes later + [norm.pnt, norm.m] = warp_optim(elec.pnt, avg, cfg.method); + norm.label = elec.label; + + dpre = mean(sqrt(sum((avg - elec.pnt).^2, 2))); + dpost = mean(sqrt(sum((avg - norm.pnt).^2, 2))); + fprintf('mean distance prior to warping %f, after warping %f\n', dpre, dpost); + + if strcmp(cfg.feedback, 'yes') + % plot all electrodes before warping + my_plot3(elec.pnt, 'r.'); + my_plot3(elec.pnt(1,:), 'r*'); + my_plot3(elec.pnt(2,:), 'r*'); + my_plot3(elec.pnt(3,:), 'r*'); + my_text3(elec.pnt(1,:), elec.label{1}, 'color', 'r'); + my_text3(elec.pnt(2,:), elec.label{2}, 'color', 'r'); + my_text3(elec.pnt(3,:), elec.label{3}, 'color', 'r'); + + % plot all electrodes after warping + my_plot3(norm.pnt, 'm.'); + my_plot3(norm.pnt(1,:), 'm*'); + my_plot3(norm.pnt(2,:), 'm*'); + my_plot3(norm.pnt(3,:), 'm*'); + my_text3(norm.pnt(1,:), norm.label{1}, 'color', 'm'); + my_text3(norm.pnt(2,:), norm.label{2}, 'color', 'm'); + my_text3(norm.pnt(3,:), norm.label{3}, 'color', 'm'); + + % plot the template electrode locations + my_plot3(avg, 'b.'); + my_plot3(avg(1,:), 'b*'); + my_plot3(avg(2,:), 'b*'); + my_plot3(avg(3,:), 'b*'); + my_text3(avg(1,:), norm.label{1}, 'color', 'b'); + my_text3(avg(2,:), norm.label{2}, 'color', 'b'); + my_text3(avg(3,:), norm.label{3}, 'color', 'b'); + + % plot lines connecting the input/warped electrode locations with the template locations + my_line3(elec.pnt, avg, 'color', 'r'); + my_line3(norm.pnt, avg, 'color', 'm'); + end + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +elseif useheadshape && any(strcmp(cfg.method, {'rigidbody', 'globalrescale', 'traditional', 'nonlin1', 'nonlin2', 'nonlin3', 'nonlin4', 'nonlin5'})) + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + % determine electrode selection and overlapping subset for warping + cfg.channel = channelselection(cfg.channel, elec.label); + + % make subselection of electrodes + [cfgsel, datsel] = match_str(cfg.channel, elec.label); + elec.label = elec.label(datsel); + elec.pnt = elec.pnt(datsel,:); + + fprintf('warping electrodes to head shape... '); % the newline comes later + [norm.pnt, norm.m] = warp_optim(elec.pnt, headshape, cfg.method); + norm.label = elec.label; + + dpre = warp_error([], elec.pnt, headshape, cfg.method); + dpost = warp_error(norm.m, elec.pnt, headshape, cfg.method); + fprintf('mean distance prior to warping %f, after warping %f\n', dpre, dpost); + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +elseif strcmp(cfg.method, 'realignfiducial') + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + % try to determine the fiducials automatically if not specified + option1 = {'nasion' 'left' 'right'}; + option2 = {'nasion' 'lpa' 'rpa'}; + option3 = {'nz' 'lpa' 'rpa'}; + if ~isfield(cfg, 'fiducial') + if length(match_str(elec.label, option1))==3 + cfg.fiducial = option1; + elseif length(match_str(elec.label, option2))==3 + cfg.fiducial = option2; + elseif length(match_str(elec.label, option3))==3 + cfg.fiducial = option3; + else + error('could not determine three fiducials, please specify cfg.fiducial') + end + end + fprintf('using fiducials {''%s'', ''%s'', ''%s''}\n', cfg.fiducial{1}, cfg.fiducial{2}, cfg.fiducial{3}); + + % determine electrode selection + cfg.channel = channelselection(cfg.channel, elec.label); + [cfgsel, datsel] = match_str(cfg.channel, elec.label); + elec.label = elec.label(datsel); + elec.pnt = elec.pnt(datsel,:); + + if length(cfg.fiducial)~=3 + error('you must specify three fiducials'); + end + + % do case-insensitive search for fiducial locations + nas_indx = match_str(lower(elec.label), lower(cfg.fiducial{1})); + lpa_indx = match_str(lower(elec.label), lower(cfg.fiducial{2})); + rpa_indx = match_str(lower(elec.label), lower(cfg.fiducial{3})); + if length(nas_indx)~=1 || length(lpa_indx)~=1 || length(rpa_indx)~=1 + error('not all fiducials were found in the electrode set'); + end + elec_nas = elec.pnt(nas_indx,:); + elec_lpa = elec.pnt(lpa_indx,:); + elec_rpa = elec.pnt(rpa_indx,:); + + % find the matching fiducials in the template and average them + templ_nas = []; + templ_lpa = []; + templ_rpa = []; + for i=1:Ntemplate + nas_indx = match_str(lower(template(i).label), lower(cfg.fiducial{1})); + lpa_indx = match_str(lower(template(i).label), lower(cfg.fiducial{2})); + rpa_indx = match_str(lower(template(i).label), lower(cfg.fiducial{3})); + if length(nas_indx)~=1 || length(lpa_indx)~=1 || length(rpa_indx)~=1 + error(sprintf('not all fiducials were found in template %d', i)); + end + templ_nas(end+1,:) = template(i).pnt(nas_indx,:); + templ_lpa(end+1,:) = template(i).pnt(lpa_indx,:); + templ_rpa(end+1,:) = template(i).pnt(rpa_indx,:); + end + templ_nas = mean(templ_nas,1); + templ_lpa = mean(templ_lpa,1); + templ_rpa = mean(templ_rpa,1); + + % realign both to a common coordinate system + elec2common = headcoordinates(elec_nas, elec_lpa, elec_rpa); + templ2common = headcoordinates(templ_nas, templ_lpa, templ_rpa); + + % compute the combined transform and realign the electrodes to the template + norm = []; + norm.m = elec2common * inv(templ2common); + norm.pnt = warp_apply(norm.m, elec.pnt, 'homogeneous'); + norm.label = elec.label; + + nas_indx = match_str(lower(elec.label), lower(cfg.fiducial{1})); + lpa_indx = match_str(lower(elec.label), lower(cfg.fiducial{2})); + rpa_indx = match_str(lower(elec.label), lower(cfg.fiducial{3})); + dpre = mean(sqrt(sum((elec.pnt([nas_indx lpa_indx rpa_indx],:) - [templ_nas; templ_lpa; templ_rpa]).^2, 2))); + nas_indx = match_str(lower(norm.label), lower(cfg.fiducial{1})); + lpa_indx = match_str(lower(norm.label), lower(cfg.fiducial{2})); + rpa_indx = match_str(lower(norm.label), lower(cfg.fiducial{3})); + dpost = mean(sqrt(sum((norm.pnt([nas_indx lpa_indx rpa_indx],:) - [templ_nas; templ_lpa; templ_rpa]).^2, 2))); + fprintf('mean distance between fiducials prior to realignment %f, after realignment %f\n', dpre, dpost); + + if strcmp(cfg.feedback, 'yes') + % plot the first three electrodes before transformation + my_plot3(elec.pnt(1,:), 'r*'); + my_plot3(elec.pnt(2,:), 'r*'); + my_plot3(elec.pnt(3,:), 'r*'); + my_text3(elec.pnt(1,:), elec.label{1}, 'color', 'r'); + my_text3(elec.pnt(2,:), elec.label{2}, 'color', 'r'); + my_text3(elec.pnt(3,:), elec.label{3}, 'color', 'r'); + + % plot the template fiducials + my_plot3(templ_nas, 'b*'); + my_plot3(templ_lpa, 'b*'); + my_plot3(templ_rpa, 'b*'); + my_text3(templ_nas, ' nas', 'color', 'b'); + my_text3(templ_lpa, ' lpa', 'color', 'b'); + my_text3(templ_rpa, ' rpa', 'color', 'b'); + + % plot all electrodes after transformation + my_plot3(norm.pnt, 'm.'); + my_plot3(norm.pnt(1,:), 'm*'); + my_plot3(norm.pnt(2,:), 'm*'); + my_plot3(norm.pnt(3,:), 'm*'); + my_text3(norm.pnt(1,:), norm.label{1}, 'color', 'm'); + my_text3(norm.pnt(2,:), norm.label{2}, 'color', 'm'); + my_text3(norm.pnt(3,:), norm.label{3}, 'color', 'm'); + end + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +elseif strcmp(cfg.method, 'interactive') + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % open a figure + fig = figure; + % add the data to the figure + set(fig, 'CloseRequestFcn', @cb_close); + setappdata(fig, 'elec', elec); + setappdata(fig, 'transform', eye(4)); + if useheadshape + setappdata(fig, 'surf', headshape); + end + if usetemplate + % FIXME interactive realigning to template electrodes is not yet supported + % this requires a consistent handling of channel selection etc. + setappdata(fig, 'template', template); + end + % add the GUI elements + cb_creategui(gca); + cb_redraw(gca); + rotate3d on + waitfor(fig); + % get the data from the figure that was left behind as global variable + global norm + tmp = norm; + clear global norm + norm = tmp; + clear tmp + +else + error('unknown method'); +end + +% apply the spatial transformation to all electrodes, and replace the +% electrode labels by their case-sensitive original values +if any(strcmp(cfg.method, {'rigidbody', 'globalrescale', 'traditional', 'nonlin1', 'nonlin2', 'nonlin3', 'nonlin4', 'nonlin5'})) + norm.pnt = warp_apply(norm.m, orig.pnt, cfg.method); +else + norm.pnt = warp_apply(norm.m, orig.pnt, 'homogenous'); +end +norm.label = orig.label; + +% add version information to the configuration +try + % get the full name of the function + cfg.version.name = mfilename('fullpath'); +catch + % required for compatibility with Matlab versions prior to release 13 (6.5) + [st, i] = dbstack; + cfg.version.name = st(i); +end +cfg.version.id = '$Id: electroderealign.m,v 1.1 2009/01/30 04:02:02 arno Exp $'; + +% remember the configuration +norm.cfg = cfg; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% some simple SUBFUNCTIONs that facilitate 3D plotting +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function h = my_plot3(xyz, varargin) +h = plot3(xyz(:,1), xyz(:,2), xyz(:,3), varargin{:}); +function h = my_text3(xyz, varargin) +h = text(xyz(:,1), xyz(:,2), xyz(:,3), varargin{:}); +function my_line3(xyzB, xyzE, varargin) +for i=1:size(xyzB,1) + line([xyzB(i,1) xyzE(i,1)], [xyzB(i,2) xyzE(i,2)], [xyzB(i,3) xyzE(i,3)], varargin{:}) +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% SUBFUNCTION to layout a moderately complex graphical user interface +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function h = layoutgui(fig, geometry, position, style, string, value, tag, callback); +horipos = geometry(1); % lower left corner of the GUI part in the figure +vertpos = geometry(2); % lower left corner of the GUI part in the figure +width = geometry(3); % width of the GUI part in the figure +height = geometry(4); % height of the GUI part in the figure +horidist = 0.05; +vertdist = 0.05; +options = {'units', 'normalized', 'HorizontalAlignment', 'center'}; % 'VerticalAlignment', 'middle' +Nrow = size(position,1); +h = cell(Nrow,1); +for i=1:Nrow + if isempty(position{i}) + continue; + end + position{i} = position{i} ./ sum(position{i}); + Ncol = size(position{i},2); + ybeg = (Nrow-i )/Nrow + vertdist/2; + yend = (Nrow-i+1)/Nrow - vertdist/2; + for j=1:Ncol + xbeg = sum(position{i}(1:(j-1))) + horidist/2; + xend = sum(position{i}(1:(j ))) - horidist/2; + pos(1) = xbeg*width + horipos; + pos(2) = ybeg*height + vertpos; + pos(3) = (xend-xbeg)*width; + pos(4) = (yend-ybeg)*height; + h{i}{j} = uicontrol(fig, ... + options{:}, ... + 'position', pos, ... + 'style', style{i}{j}, ... + 'string', string{i}{j}, ... + 'tag', tag{i}{j}, ... + 'value', value{i}{j}, ... + 'callback', callback{i}{j} ... + ); + end +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function cb_creategui(hObject, eventdata, handles); +% define the position of each GUI element +position = { + [2 1 1 1] + [2 1 1 1] + [2 1 1 1] + [1] + [1] + [1] + [1] + [1 1] + }; + +% define the style of each GUI element +style = { + {'text' 'edit' 'edit' 'edit'} + {'text' 'edit' 'edit' 'edit'} + {'text' 'edit' 'edit' 'edit'} + {'pushbutton'} + {'pushbutton'} + {'toggle'} + {'toggle'} + {'text' 'edit'} + }; + +% define the descriptive string of each GUI element +string = { + {'rotate' 0 0 0} + {'translate' 0 0 0} + {'scale' 1 1 1} + {'redisplay'} + {'apply'} + {'toggle grid'} + {'toggle axes'} + {'alpha' 0.7} + }; + +% define the value of each GUI element +value = { + {[] [] [] []} + {[] [] [] []} + {[] [] [] []} + {[]} + {[]} + {0} + {0} + {[] []} + }; + +% define a tag for each GUI element +tag = { + {'' 'rx' 'ry' 'rz'} + {'' 'tx' 'ty' 'tz'} + {'' 'sx' 'sy' 'sz'} + {''} + {''} + {'toggle grid'} + {'toggle axes'} + {'' 'alpha'} + }; + +% define the callback function of each GUI element +callback = { + {[] @cb_redraw @cb_redraw @cb_redraw} + {[] @cb_redraw @cb_redraw @cb_redraw} + {[] @cb_redraw @cb_redraw @cb_redraw} + {@cb_redraw} + {@cb_apply} + {@cb_redraw} + {@cb_redraw} + {[] @cb_redraw} + }; + +fig = get(hObject, 'parent'); +layoutgui(fig, [0.7 0.05 0.25 0.50], position, style, string, value, tag, callback); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function cb_redraw(hObject, eventdata, handles); +fig = get(hObject, 'parent'); +surf = getappdata(fig, 'surf'); +elec = getappdata(fig, 'elec'); +template = getappdata(fig, 'template'); +% get the transformation details +rx = str2num(get(findobj(fig, 'tag', 'rx'), 'string')); +ry = str2num(get(findobj(fig, 'tag', 'ry'), 'string')); +rz = str2num(get(findobj(fig, 'tag', 'rz'), 'string')); +tx = str2num(get(findobj(fig, 'tag', 'tx'), 'string')); +ty = str2num(get(findobj(fig, 'tag', 'ty'), 'string')); +tz = str2num(get(findobj(fig, 'tag', 'tz'), 'string')); +sx = str2num(get(findobj(fig, 'tag', 'sx'), 'string')); +sy = str2num(get(findobj(fig, 'tag', 'sy'), 'string')); +sz = str2num(get(findobj(fig, 'tag', 'sz'), 'string')); +R = rotate ([rx ry rz]); +T = translate([tx ty tz]); +S = scale ([sx sy sz]); +H = S * T * R; +elec.pnt = warp_apply(H, elec.pnt); +axis vis3d; cla +xlabel('x') +ylabel('y') +zlabel('z') +if ~isempty(surf) + triplot(surf.pnt, surf.tri, [], 'faces_skin'); + alpha(str2num(get(findobj(fig, 'tag', 'alpha'), 'string'))); +end +if ~isempty(template) + triplot(template.pnt, [], [], 'nodes_blue') +end +triplot(elec.pnt, [], [], 'nodes'); +if isfield(elec, 'line') + triplot(elec.pnt, elec.line, [], 'edges'); +end +if get(findobj(fig, 'tag', 'toggle axes'), 'value') + axis on +else + axis off +end +if get(findobj(fig, 'tag', 'toggle grid'), 'value') + grid on +else + grid off +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function cb_apply(hObject, eventdata, handles); +fig = get(hObject, 'parent'); +elec = getappdata(fig, 'elec'); +transform = getappdata(fig, 'transform'); +% get the transformation details +rx = str2num(get(findobj(fig, 'tag', 'rx'), 'string')); +ry = str2num(get(findobj(fig, 'tag', 'ry'), 'string')); +rz = str2num(get(findobj(fig, 'tag', 'rz'), 'string')); +tx = str2num(get(findobj(fig, 'tag', 'tx'), 'string')); +ty = str2num(get(findobj(fig, 'tag', 'ty'), 'string')); +tz = str2num(get(findobj(fig, 'tag', 'tz'), 'string')); +sx = str2num(get(findobj(fig, 'tag', 'sx'), 'string')); +sy = str2num(get(findobj(fig, 'tag', 'sy'), 'string')); +sz = str2num(get(findobj(fig, 'tag', 'sz'), 'string')); +R = rotate ([rx ry rz]); +T = translate([tx ty tz]); +S = scale ([sx sy sz]); +H = S * T * R; +elec.pnt = warp_apply(H, elec.pnt); +transform = H * transform; +set(findobj(fig, 'tag', 'rx'), 'string', 0); +set(findobj(fig, 'tag', 'ry'), 'string', 0); +set(findobj(fig, 'tag', 'rz'), 'string', 0); +set(findobj(fig, 'tag', 'tx'), 'string', 0); +set(findobj(fig, 'tag', 'ty'), 'string', 0); +set(findobj(fig, 'tag', 'tz'), 'string', 0); +set(findobj(fig, 'tag', 'sx'), 'string', 1); +set(findobj(fig, 'tag', 'sy'), 'string', 1); +set(findobj(fig, 'tag', 'sz'), 'string', 1); +setappdata(fig, 'elec', elec); +setappdata(fig, 'transform', transform); +cb_redraw(hObject); + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function cb_close(hObject, eventdata, handles); +% make the current transformation permanent and subsequently allow deleting the figure +cb_apply(gca); +% get the updated electrode from the figure +fig = hObject; +% hmmm, this is ugly +global norm +norm = getappdata(fig, 'elec'); +norm.m = getappdata(fig, 'transform'); +set(fig, 'CloseRequestFcn', @delete); +delete(fig); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/fieldtripchan2eeglab.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/fieldtripchan2eeglab.m new file mode 100644 index 0000000000000000000000000000000000000000..8a14b7a8f1e338728cc675d015231f14457174a8 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/fieldtripchan2eeglab.m @@ -0,0 +1,43 @@ +% fieldtripchan2eeglab() - convert Fieldtrip channel location structure +% to EEGLAB channel location structure +% +% Usage: +% >> chanlocs = fieldtripchan2eeglab( fieldlocs ); +% +% Inputs: +% fieldlocs - Fieldtrip channel structure. See help readlocs() +% +% Outputs: +% chanlocs - EEGLAB channel location structure. +% +% Author: Arnaud Delorme, SCCN, INC, UCSD, 2006- +% +% See also: readlocs() + +% Copyright (C) 2003 Arnaud Delorme, Salk Institute, arno@salk.edu +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function chanlocs = fieldtripchan2eeglab( loc ); + + if nargin < 1 + help fieldtripchan2eeglab; + return; + end; + + chanlocs = struct('labels', loc.label(:)', 'X', mattocell(loc.pnt(:,1)'), ... + 'Y', mattocell(loc.pnt(:,2)'), ... + 'Z', mattocell(loc.pnt(:,3)')); + chanlocs = convertlocs(chanlocs, 'cart2all'); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/headcoordinates.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/headcoordinates.m new file mode 100644 index 0000000000000000000000000000000000000000..cf3013aa75422c063d6abad4b72e84cd2d0d81fe --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/headcoordinates.m @@ -0,0 +1,83 @@ +function [h] = headcoordinates(nas, lpa, rpa, flag); + +% HEADCOORDINATES returns the homogenous coordinate transformation matrix +% that converts the specified fiducials in any coordinate system (e.g. MRI) +% into the rotated and translated headccordinate system. +% +% [h] = headcoordinates(nas, lpa, rpa, flag) or +% [h] = headcoordinates(pt1, pt2, pt3, flag) +% +% The optional flag determines how the origin should be specified +% according to CTF conventions: flag = 0 (default) +% according to ASA conventions: flag = 1 +% according to FTG conventions: flag = 2 +% +% The headcoordinate system in CTF is defined as follows: +% the origin is exactly between lpa and rpa +% the X-axis goes towards nas +% the Y-axis goes approximately towards lpa, orthogonal to X and in the plane spanned by the fiducials +% the Z-axis goes approximately towards the vertex, orthogonal to X and Y +% +% The headcoordinate system in ASA is defined as follows: +% the origin is at the orthogonal intersection of the line from rpa-rpa and the line trough nas +% the X-axis goes towards nas +% the Y-axis goes through rpa and lpa +% the Z-axis goes approximately towards the vertex, orthogonal to X and Y +% +% The headcoordinate system in FTG is defines as: +% the origin corresponds with pt1 +% the x-axis is along the line from pt1 to pt2 +% the z-axis is orthogonal to the plane spanned by pt1, pt2 and pt3 +% +% See also WARPING, WARP3D + +% Copyright (C) 2003 Robert Oostenveld +% +if nargin<4 + flag=0; +end + +% ensure that they are row vectors +lpa = lpa(:)'; +rpa = rpa(:)'; +nas = nas(:)'; + +% compute the origin and direction of the coordinate axes in MRI coordinates +if flag==0 + % follow CTF convention + origin = [lpa+rpa]/2; + dirx = nas-origin; + dirx = dirx/norm(dirx); + dirz = cross(dirx,lpa-rpa); + dirz = dirz/norm(dirz); + diry = cross(dirz,dirx); +elseif flag==1 + % follow ASA convention + dirz = cross(nas-rpa, lpa-rpa); + diry = lpa-rpa; + dirx = cross(diry,dirz); + dirz = dirz/norm(dirz); + diry = diry/norm(diry); + dirx = dirx/norm(dirx); + origin = rpa + dot(nas-rpa,diry)*diry; +elseif flag==2 + % rename the marker points for convenience + pt1 = nas; pt2 = lpa; pt3 = rpa; + % follow FTG conventions + origin = pt1; + dirx = pt2-origin; + dirx = dirx/norm(dirx); + diry = pt3-origin; + dirz = cross(dirx,diry); + dirz = dirz/norm(dirz); + diry = cross(dirz,dirx); +end + +% compute the rotation matrix +rot = eye(4); +rot(1:3,1:3) = inv(eye(3) / [dirx; diry; dirz]); +% compute the translation matrix +tra = eye(4); +tra(1:4,4) = [-origin(:); 1]; +% compute the full homogenous transformation matrix from these two +h = rot * tra; diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/homogenous2traditional.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/homogenous2traditional.m new file mode 100644 index 0000000000000000000000000000000000000000..24eefd902a9f14ca861fba823fe5cc683d8c47f3 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/homogenous2traditional.m @@ -0,0 +1,193 @@ +function f = homogenous2traditional(H) + +% HOMOGENOUS2TRADITIONAL estimates the traditional translation, rotation +% and scaling parameters from a homogenous transformation matrix. It will +% give an error if the homogenous matrix also describes a perspective +% transformation. +% +% Use as +% f = homogenous2traditional(H) +% where H is a 4x4 homogenous transformation matrix and f is a vector with +% nine elements describing +% x-shift +% y-shift +% z-shift +% followed by the +% pitch (rotation around x-axis) +% roll (rotation around y-axis) +% yaw (rotation around z-axis) +% followed by the +% x-rescaling factor +% y-rescaling factor +% z-rescaling factor +% +% The order in which the transformations would be done is exactly opposite +% as the list above, i.e. first z-rescale ... and finally x-shift. + +% Copyright (C) 2005, Robert Oostenveld +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +% remember the input homogenous transformation matrix +Horg = H; + +% The homogenous transformation matrix is built up according to +% H = T * R * S +% where +% R = Rx * Ry * Rz + +% estimate the translation +tx = H(1,4); +ty = H(2,4); +tz = H(3,4); +T = [ + 1 0 0 tx + 0 1 0 ty + 0 0 1 tz + 0 0 0 1 + ]; +% recompute the homogenous matrix excluding the translation +H = inv(T) * H; + +% estimate the scaling +sx = norm(H(1:3,1)); +sy = norm(H(1:3,2)); +sz = norm(H(1:3,3)); +S = [ + sx 0 0 0 + 0 sy 0 0 + 0 0 sz 0 + 0 0 0 1 + ]; +% recompute the homogenous matrix excluding the scaling +H = H * inv(S); + +% the difficult part is to determine the rotations +% the order of the rotations matters + +% compute the rotation using a probe point on the z-axis +p = H * [0 0 1 0]'; +% the rotation around the y-axis is resulting in an offset in the positive x-direction +ry = asin(p(1)); + +% the rotation around the x-axis can be estimated by the projection on the yz-plane +if abs(p(2))= 0): +% +% X'= 0.9900X +% +% Y'= 0.9688Y +0.0460Z +% +% Z'= -0.0485Y +0.9189Z +% +% +% Below the AC (Z < 0): +% +% X'= 0.9900X +% +% Y'= 0.9688Y +0.0420Z +% +% Z'= -0.0485Y +0.8390Z +% +% +% The matlab function mni2tal.m implements these transforms. +% It returns estimated Talairach coordinates, from the +% transformations above, for given points in the MNI brain. +% To use it, save as mni2tal.m somewhere on your matlab path. +% +% So, taking our example point in the MNI brain, X = 10mm, Y = 12mm, Z = 14mm: +% +% With the mni2tal.m function above on your path, you could +% type the following at the matlab prompt: +% +% +% mni2tal([10 12 14]) +% +% Which would give the following output (see above): +% +% +% ans = +% +% 9.9000 12.2692 12.2821 +% +% +% which is, again, an estimate of the equivalent X, Y and Z +% coordinates in the Talairach brain. +% +% The inverse function, tal2mni.m, gives MNI coordinates for +% given Talairach coordinates, using the same algorithm. +% +% We could of course do a more complex transform to attempt +% to make a closer match between the two brains. The approach +% above is only intended to be preliminary. It does have the +% advantage that it is very simple, and therefore the distortions +% involved are easy to visualise, and unlikely to have dramatic +% unexpected effects. +% +% Incidentally, if you use the above transform, and you want to +% cite it, I suggest that you cite this web address. The transform +% is also mentioned briefly in the following papers: Duncan, J., +% Seitz, R.J., Kolodny, J., Bor, D., Herzog, H., Ahmed, A., Newell, F.N., +% Emslie, H. "A neural basis for General Intelligence", Science (21 July +% 2000), 289 (5478), 457-460; Calder, A.J., Lawrence, A.D. and +% Young,A.W. "Neuropsychology of Fear and Loathing" Nature Reviews +% Neuroscience (2001), Vol.2 No.5 352-363 +% diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_dipfit_batch.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_dipfit_batch.m new file mode 100644 index 0000000000000000000000000000000000000000..534877664dbd1682b6a6effedf18bed8f06dc53b --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_dipfit_batch.m @@ -0,0 +1,57 @@ +% pop_dipfit_batch() - interactively do batch scan of all ICA components +% with a single dipole +% Function deprecated. Use pop_dipfit_gridsearch() +% instead +% +% Usage: +% >> OUTEEG = pop_dipfit_batch( INEEG ); % pop up interactive window +% >> OUTEEG = pop_dipfit_batch( INEEG, comps ); +% >> OUTEEG = pop_dipfit_batch( INEEG, comps, xgrid, ygrid, zgrid, thresh ) +% +% Inputs: +% INEEG - input dataset +% comps - [integer array] component indices +% xgrid - [float array] x-grid. Default is 10 elements between +% -1 and 1. +% ygrid - [float array] y-grid. Default is 10 elements between +% -1 and 1. +% zgrid - [float array] z-grid. Default is 10 elements between +% -1 and 1. +% threshold - [float] threshold in percent. Default 40. +% +% Outputs: +% OUTEEG output dataset +% +% Authors: Robert Oostenveld, SMI/FCDC, Nijmegen 2003 +% Arnaud Delorme, SCCN, La Jolla 2003 + +% SMI, University Aalborg, Denmark http://www.smi.auc.dk/ +% FC Donders Centre, University Nijmegen, the Netherlands http://www.fcdonders.kun.nl/ + +% Copyright (C) 2003 Robert Oostenveld, SMI/FCDC roberto@miba.auc.dk +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function [OUTEEG, com] = pop_dipfit_batch( varargin ) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +if nargin<1 + help pop_dipfit_batch; + return +else + disp('Warning: pop_dipfit_manual is outdated. Use pop_dipfit_nonlinear instead'); + [OUTEEG, com] = pop_dipfit_gridsearch( varargin{:} ); +end; diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_dipfit_gridsearch.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_dipfit_gridsearch.m new file mode 100644 index 0000000000000000000000000000000000000000..cbebbeabc3b756c3b53b6a0e7c0648b7aceb313c --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_dipfit_gridsearch.m @@ -0,0 +1,143 @@ +% pop_dipfit_gridsearch() - scan all ICA components with a single dipole +% on a regular grid spanning the whole brain. Any dipoles that explains +% a component with a too large relative residual variance is removed. +% +% Usage: +% >> EEGOUT = pop_dipfit_gridsearch( EEGIN ); % pop up interactive window +% >> EEGOUT = pop_dipfit_gridsearch( EEGIN, comps ); +% >> EEGOUT = pop_dipfit_gridsearch( EEGIN, comps, xgrid, ygrid, zgrid, thresh ) +% +% Inputs: +% EEGIN - input dataset +% comps - [integer array] component indices +% xgrid - [float array] x-grid. Default is 10 elements between +% -1 and 1. +% ygrid - [float array] y-grid. Default is 10 elements between +% -1 and 1. +% zgrid - [float array] z-grid. Default is 10 elements between +% -1 and 1. +% thresh - [float] threshold in percent. Default 40. +% +% Outputs: +% EEGOUT output dataset +% +% Authors: Robert Oostenveld, SMI/FCDC, Nijmegen 2003 +% Arnaud Delorme, SCCN, La Jolla 2003 +% Thanks to Nicolas Robitaille for his help on the CTF MEG +% implementation + +% SMI, University Aalborg, Denmark http://www.smi.auc.dk/ +% FC Donders Centre, University Nijmegen, the Netherlands http://www.fcdonders.kun.nl/ + +% Copyright (C) 2003 Robert Oostenveld, SMI/FCDC roberto@smi.auc.dk +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function [EEGOUT, com] = pop_dipfit_gridsearch(EEG, select, xgrid, ygrid, zgrid, reject ); +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +if nargin < 1 + help pop_dipfit_gridsearch; + return; +end; + +if ~plugin_askinstall('Fieldtrip-lite', 'ft_sourceanalysis'), return; end; + +EEGOUT = EEG; +com = ''; + +if ~isfield(EEG, 'chanlocs') + error('No electrodes present'); +end + +if ~isfield(EEG, 'icawinv') + error('No ICA components to fit'); +end + +if ~isfield(EEG, 'dipfit') + error('General dipolefit settings not specified'); +end + +if ~isfield(EEG.dipfit, 'vol') & ~isfield(EEG.dipfit, 'hdmfile') + error('Dipolefit volume conductor model not specified'); +end + +dipfitdefs +if strcmpi(EEG.dipfit.coordformat, 'CTF') + maxrad = 8.5; + xgridstr = sprintf('linspace(-%2.1f,%2.1f,11)', maxrad, maxrad); + ygridstr = sprintf('linspace(-%2.1f,%2.1f,11)', maxrad, maxrad); + zgridstr = sprintf('linspace(0,%2.1f,6)', maxrad); +end; +if nargin < 2 + % get the default values and filenames + promptstr = { 'Component(s) (not faster if few comp.)', ... + 'Grid in X-direction', ... + 'Grid in Y-direction', ... + 'Grid in Z-direction', ... + 'Rejection threshold RV(%)' }; + + inistr = { + [ '1:' int2str(size(EEG.icawinv,2)) ], ... + xgridstr, ... + ygridstr, ... + zgridstr, ... + rejectstr }; + + result = inputdlg2( promptstr, 'Batch dipole fit -- pop_dipfit_gridsearch()', 1, inistr, 'pop_dipfit_gridsearch'); + + if length(result)==0 + % user pressed cancel + return + end + + select = eval( [ '[' result{1} ']' ]); + xgrid = eval( result{2} ); + ygrid = eval( result{3} ); + zgrid = eval( result{4} ); + reject = eval( result{5} ) / 100; % string is in percent + options = { }; + else + if nargin < 2 + select = [1:size(EEG.icawinv,2)]; + end; + if nargin < 3 + xgrid = eval( xgridstr ); + end; + if nargin < 4 + ygrid = eval( ygridstr ); + end; + if nargin < 5 + zgrid = eval( zgridstr ); + end; + if nargin < 6 + reject = eval( rejectstr ); + end; + options = { 'waitbar' 'none' }; + end; + + % perform batch fit with single dipole for all selected channels and components + % warning off; + warning backtrace off; + EEGOUT = dipfit_gridsearch(EEG, 'component', select, 'xgrid', xgrid, 'ygrid', ygrid, 'zgrid', zgrid, options{:}); + warning backtrace on; + EEGOUT.dipfit.model = dipfit_reject(EEGOUT.dipfit.model, reject); + + % FIXME reject is not being used at the moment + disp('Done'); + com = sprintf('%s = pop_dipfit_gridsearch(%s, %s);', ... + inputname(1), inputname(1), vararg2str( { select xgrid, ygrid, zgrid reject })); + diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_dipfit_manual.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_dipfit_manual.m new file mode 100644 index 0000000000000000000000000000000000000000..35f89b7b813bb7e5ea6795bd774d6cc3eea542c0 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_dipfit_manual.m @@ -0,0 +1,45 @@ +% pop_dipfit_manual() - interactively do dipole fit of selected ICA components +% Function deprecated. Use pop_dipfit_nonlinear() +% instead +% Usage: +% >> OUTEEG = pop_dipfit_manual( INEEG ) +% +% Inputs: +% INEEG input dataset +% +% Outputs: +% OUTEEG output dataset +% +% Author: Robert Oostenveld, SMI/FCDC, Nijmegen 2003 +% Arnaud Delorme, SCCN, La Jolla 2003 + +% SMI, University Aalborg, Denmark http://www.smi.auc.dk/ +% FC Donders Centre, University Nijmegen, the Netherlands http://www.fcdonders.kun.nl/ + +% Copyright (C) 2003 Robert Oostenveld, SMI/FCDC roberto@miba.auc.dk +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function [OUTEEG, com] = pop_dipfit_manual( varargin ) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +if nargin<1 + help pop_dipfit_manual; + return +else + disp('Warning: pop_dipfit_manual is outdated. Use pop_dipfit_nonlinear instead'); + [OUTEEG, com] = pop_dipfit_nonlinear( varargin{:} ); +end; diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_dipfit_nonlinear.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_dipfit_nonlinear.m new file mode 100644 index 0000000000000000000000000000000000000000..08fc736e5d8aa31496844540b18b0e9564ee0d02 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_dipfit_nonlinear.m @@ -0,0 +1,414 @@ +% pop_dipfit_nonlinear() - interactively do dipole fit of selected ICA components +% +% Usage: +% >> EEGOUT = pop_dipfit_nonlinear( EEGIN ) +% +% Inputs: +% EEGIN input dataset +% +% Outputs: +% EEGOUT output dataset +% +% Author: Robert Oostenveld, SMI/FCDC, Nijmegen 2003 +% Arnaud Delorme, SCCN, La Jolla 2003 +% Thanks to Nicolas Robitaille for his help on the CTF MEG +% implementation + +% SMI, University Aalborg, Denmark http://www.smi.auc.dk/ +% FC Donders Centre, University Nijmegen, the Netherlands http://www.fcdonders.kun.nl/ + +% Copyright (C) 2003 Robert Oostenveld, SMI/FCDC roberto@smi.auc.dk +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function [EEGOUT, com] = pop_dipfit_nonlinear( EEG, subfunction, parent, dipnum ) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% the code for this interactive dialog has 4 major parts +% - draw the graphical user interface +% - synchronize the gui with the data +% - synchronize the data with the gui +% - execute the actual dipole analysis + +% the subfunctions that perform handling of the gui are +% - dialog_selectcomponent +% - dialog_checkinput +% - dialog_setvalue +% - dialog_getvalue +% - dialog_plotmap +% - dialog_plotcomponent +% - dialog_flip +% the subfunctions that perform the fitting are +% - dipfit_position +% - dipfit_moment + +if ~plugin_askinstall('Fieldtrip-lite', 'ft_sourceanalysis'), return; end; + +if nargin<1 + help pop_dipfit_nonlinear; + return +elseif nargin==1 + + EEGOUT = EEG; + com = ''; + + if ~isfield(EEG, 'chanlocs') + error('No electrodes present'); + end + + if ~isfield(EEG, 'icawinv') + error('No ICA components to fit'); + end + + if ~isfield(EEG, 'dipfit') + error('General dipolefit settings not specified'); + end + + if ~isfield(EEG.dipfit, 'vol') & ~isfield(EEG.dipfit, 'hdmfile') + error('Dipolefit volume conductor model not specified'); + end + + % select all ICA components as 'fitable' + select = 1:size(EEG.icawinv,2); + if ~isfield(EEG.dipfit, 'current') + % select the first component as the current component + EEG.dipfit.current = 1; + end + + % verify the presence of a dipole model + if ~isfield(EEG.dipfit, 'model') + % create empty dipole model for each component + for i=select + EEG.dipfit.model(i).posxyz = zeros(2,3); + EEG.dipfit.model(i).momxyz = zeros(2,3); + EEG.dipfit.model(i).rv = 1; + EEG.dipfit.model(i).select = [1]; + end + end + + % verify the size of each dipole model + for i=select + if ~isfield(EEG.dipfit.model, 'posxyz') | length(EEG.dipfit.model) < i | isempty(EEG.dipfit.model(i).posxyz) + % replace all empty dipole models with a two dipole model, of which one is active + EEG.dipfit.model(i).select = [1]; + EEG.dipfit.model(i).rv = 1; + EEG.dipfit.model(i).posxyz = zeros(2,3); + EEG.dipfit.model(i).momxyz = zeros(2,3); + elseif size(EEG.dipfit.model(i).posxyz,1)==1 + % replace all one dipole models with a two dipole model + EEG.dipfit.model(i).select = [1]; + EEG.dipfit.model(i).posxyz = [EEG.dipfit.model(i).posxyz; [0 0 0]]; + EEG.dipfit.model(i).momxyz = [EEG.dipfit.model(i).momxyz; [0 0 0]]; + elseif size(EEG.dipfit.model(i).posxyz,1)>2 + % replace all more-than-two dipole models with a two dipole model + warning('pruning dipole model to two dipoles'); + EEG.dipfit.model(i).select = [1]; + EEG.dipfit.model(i).posxyz = EEG.dipfit.model(i).posxyz(1:2,:); + EEG.dipfit.model(i).momxyz = EEG.dipfit.model(i).momxyz(1:2,:); + end + end + + % default is not to use symmetry constraint + constr = []; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % construct the graphical user interface + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + % define the callback functions for the interface elements + cb_plotmap = 'pop_dipfit_nonlinear(EEG, ''dialog_plotmap'', gcbf);'; + cb_selectcomponent = 'pop_dipfit_nonlinear(EEG, ''dialog_selectcomponent'', gcbf);'; + cb_checkinput = 'pop_dipfit_nonlinear(EEG, ''dialog_checkinput'', gcbf);'; + cb_fitposition = 'pop_dipfit_nonlinear(EEG, ''dialog_getvalue'', gcbf); pop_dipfit_nonlinear(EEG, ''dipfit_position'', gcbf); pop_dipfit_nonlinear(EEG, ''dialog_setvalue'', gcbf);'; + cb_fitmoment = 'pop_dipfit_nonlinear(EEG, ''dialog_getvalue'', gcbf); pop_dipfit_nonlinear(EEG, ''dipfit_moment'' , gcbf); pop_dipfit_nonlinear(EEG, ''dialog_setvalue'', gcbf);'; + cb_close = 'close(gcbf)'; + cb_help = 'pophelp(''pop_dipfit_nonlinear'');'; + cb_ok = 'uiresume(gcbf);'; + cb_plotdip = 'pop_dipfit_nonlinear(EEG, ''dialog_plotcomponent'', gcbf);'; + cb_flip1 = 'pop_dipfit_nonlinear(EEG, ''dialog_flip'', gcbf, 1);'; + cb_flip2 = 'pop_dipfit_nonlinear(EEG, ''dialog_flip'', gcbf, 2);'; + cb_sym = [ 'set(findobj(gcbf, ''tag'', ''dip2sel''), ''value'', 1);' cb_checkinput ]; + + % vertical layout for each line + geomvert = [1 1 1 1 1 1 1 1 1]; + + % horizontal layout for each line + geomhoriz = { + [0.8 0.5 0.8 1 1] + [1] + [0.7 0.7 2 2 1] + [0.7 0.5 0.2 2 2 1] + [0.7 0.5 0.2 2 2 1] + [1] + [1 1 1] + [1] + [1 1 1] + }; + + % define each individual graphical user element + elements = { ... + { 'style' 'text' 'string' 'Component to fit' } ... + { 'style' 'edit' 'string' 'dummy' 'tag' 'component' 'callback' cb_selectcomponent } ... + { 'style' 'pushbutton' 'string' 'Plot map' 'callback' cb_plotmap } ... + { 'style' 'text' 'string' 'Residual variance = ' } ... + { 'style' 'text' 'string' 'dummy' 'tag' 'relvar' } ... + { } ... + { 'style' 'text' 'string' 'dipole' } ... + { 'style' 'text' 'string' 'fit' } ... + { 'style' 'text' 'string' 'position' } ... + { 'style' 'text' 'string' 'moment' } ... + { } ... + ... + { 'style' 'text' 'string' '#1' 'tag' 'dip1' } ... + { 'style' 'checkbox' 'string' '' 'tag' 'dip1sel' 'callback' cb_checkinput } { } ... + { 'style' 'edit' 'string' '' 'tag' 'dip1pos' 'callback' cb_checkinput } ... + { 'style' 'edit' 'string' '' 'tag' 'dip1mom' 'callback' cb_checkinput } ... + { 'style' 'pushbutton' 'string' 'Flip (in|out)' 'callback' cb_flip1 } ... + ... + { 'style' 'text' 'string' '#2' 'tag' 'dip2' } ... + { 'style' 'checkbox' 'string' '' 'tag' 'dip2sel' 'callback' cb_checkinput } { } ... + { 'style' 'edit' 'string' '' 'tag' 'dip2pos' 'callback' cb_checkinput } ... + { 'style' 'edit' 'string' '' 'tag' 'dip2mom' 'callback' cb_checkinput } ... + { 'style' 'pushbutton' 'string' 'Flip (in|out)' 'callback' cb_flip2 } ... + ... + { } { 'style' 'checkbox' 'string' 'Symmetry constrain for dipole #2' 'tag' 'dip2sym' 'callback' cb_sym 'value' 1 } ... + { } { } { } ... + { 'style' 'pushbutton' 'string' 'Fit dipole(s)'' position & moment' 'callback' cb_fitposition } ... + { 'style' 'pushbutton' 'string' 'OR fit only dipole(s)'' moment' 'callback' cb_fitmoment } ... + { 'style' 'pushbutton' 'string' 'Plot dipole(s)' 'callback' cb_plotdip } ... + }; + + % add the cancel, help and ok buttons at the bottom + + geomvert = [geomvert 1 1]; + + geomhoriz = {geomhoriz{:} [1] [1 1 1]}; + + elements = { elements{:} ... + { } ... + { 'Style', 'pushbutton', 'string', 'Cancel', 'callback', cb_close } ... + { 'Style', 'pushbutton', 'string', 'Help', 'callback', cb_help } ... + { 'Style', 'pushbutton', 'string', 'OK', 'callback', cb_ok } ... + }; + + % activate the graphical interface + supergui(0, geomhoriz, geomvert, elements{:}); + dlg = gcf; + set(gcf, 'name', 'Manual dipole fit -- pop_dipfit_nonlinear()'); + set(gcf, 'userdata', EEG); + pop_dipfit_nonlinear(EEG, 'dialog_setvalue', dlg); + uiwait(dlg); + if ishandle(dlg) + pop_dipfit_nonlinear(EEG, 'dialog_getvalue', dlg); + % FIXME, rv is undefined since the user may have changed dipole parameters + % FIXME, see also dialog_getvalue subfucntion + EEGOUT = get(dlg, 'userdata'); + close(dlg); + end + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % implement all subfunctions through a switch-yard + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +elseif nargin>=3 + + %disp(subfunction) + EEG = get(parent, 'userdata'); + + switch subfunction + + case 'dialog_selectcomponent' + current = get(findobj(parent, 'tag', 'component'), 'string'); + current = str2num(current); + current = current(1); + current = min(current, size(EEG.icaweights,1)); + current = max(current, 1); + set(findobj(parent, 'tag', 'component'), 'string', int2str(current)); + EEG.dipfit.current = current; + % reassign the global EEG object back to the dialogs userdata + set(parent, 'userdata', EEG); + % redraw the dialog with the current model + pop_dipfit_nonlinear(EEG, 'dialog_setvalue', parent); + + case 'dialog_plotmap' + current = str2num(get(findobj(parent, 'tag', 'component'), 'string')); + figure; pop_topoplot(EEG, 0, current, [ 'IC ' num2str(current) ], [1 1], 1); + title([ 'IC ' int2str(current) ]); + + case 'dialog_plotcomponent' + current = get(findobj(parent, 'tag', 'component'), 'string'); + EEG.dipfit.current = str2num(current); + if ~isempty( EEG.dipfit.current ) + pop_dipplot(EEG, 'DIPFIT', EEG.dipfit.current, 'normlen', 'on', 'projlines', 'on', 'mri', EEG.dipfit.mrifile); + end; + + case 'dialog_checkinput' + if get(findobj(parent, 'tag', 'dip1sel'), 'value') & ~get(findobj(parent, 'tag', 'dip1act'), 'value') + set(findobj(parent, 'tag', 'dip1act'), 'value', 1); + end + if get(findobj(parent, 'tag', 'dip2sel'), 'value') & ~get(findobj(parent, 'tag', 'dip2act'), 'value') + set(findobj(parent, 'tag', 'dip2act'), 'value', 1); + end + if ~all(size(str2num(get(findobj(parent, 'tag', 'dip1pos'), 'string')))==[1 3]) + set(findobj(parent, 'tag', 'dip1pos'), 'string', sprintf('%0.3f %0.3f %0.3f', EEG.dipfit.model(EEG.dipfit.current).posxyz(1,:))); + else + EEG.dipfit.model(EEG.dipfit.current).posxyz(1,:) = str2num(get(findobj(parent, 'tag', 'dip1pos'), 'string')); + end + if ~all(size(str2num(get(findobj(parent, 'tag', 'dip2pos'), 'string')))==[1 3]) + set(findobj(parent, 'tag', 'dip2pos'), 'string', sprintf('%0.3f %0.3f %0.3f', EEG.dipfit.model(EEG.dipfit.current).posxyz(2,:))); + else + EEG.dipfit.model(EEG.dipfit.current).posxyz(2,:) = str2num(get(findobj(parent, 'tag', 'dip2pos'), 'string')); + end + if ~all(size(str2num(get(findobj(parent, 'tag', 'dip1mom'), 'string')))==[1 3]) + set(findobj(parent, 'tag', 'dip1mom'), 'string', sprintf('%0.3f %0.3f %0.3f', EEG.dipfit.model(EEG.dipfit.current).momxyz(1,:))); + else + EEG.dipfit.model(EEG.dipfit.current).momxyz(1,:) = str2num(get(findobj(parent, 'tag', 'dip1mom'), 'string')); + end + if ~all(size(str2num(get(findobj(parent, 'tag', 'dip2mom'), 'string')))==[1 3]) + set(findobj(parent, 'tag', 'dip2mom'), 'string', sprintf('%0.3f %0.3f %0.3f', EEG.dipfit.model(EEG.dipfit.current).momxyz(2,:))); + else + EEG.dipfit.model(EEG.dipfit.current).momxyz(2,:) = str2num(get(findobj(parent, 'tag', 'dip2mom'), 'string')); + end + if get(findobj(parent, 'tag', 'dip2sel'), 'value') & get(findobj(parent, 'tag', 'dip2sym'), 'value') & ~get(findobj(parent, 'tag', 'dip1sel'), 'value') + set(findobj(parent, 'tag', 'dip2sel'), 'value', 0); + end + set(parent, 'userdata', EEG); + + case 'dialog_setvalue' + % synchronize the gui with the data + set(findobj(parent, 'tag', 'component'), 'string', EEG.dipfit.current); + set(findobj(parent, 'tag', 'relvar' ), 'string', sprintf('%0.2f%%', EEG.dipfit.model(EEG.dipfit.current).rv * 100)); + set(findobj(parent, 'tag', 'dip1sel'), 'value', ismember(1, EEG.dipfit.model(EEG.dipfit.current).select)); + set(findobj(parent, 'tag', 'dip2sel'), 'value', ismember(2, EEG.dipfit.model(EEG.dipfit.current).select)); + set(findobj(parent, 'tag', 'dip1pos'), 'string', sprintf('%0.3f %0.3f %0.3f', EEG.dipfit.model(EEG.dipfit.current).posxyz(1,:))); + if strcmpi(EEG.dipfit.coordformat, 'CTF') + set(findobj(parent, 'tag', 'dip1mom'), 'string', sprintf('%f %f %f', EEG.dipfit.model(EEG.dipfit.current).momxyz(1,:))); + else set(findobj(parent, 'tag', 'dip1mom'), 'string', sprintf('%0.3f %0.3f %0.3f', EEG.dipfit.model(EEG.dipfit.current).momxyz(1,:))); + end; + Ndipoles = size(EEG.dipfit.model(EEG.dipfit.current).posxyz, 1); + if Ndipoles>=2 + set(findobj(parent, 'tag', 'dip2pos'), 'string', sprintf('%0.3f %0.3f %0.3f', EEG.dipfit.model(EEG.dipfit.current).posxyz(2,:))); + if strcmpi(EEG.dipfit.coordformat, 'CTF') + set(findobj(parent, 'tag', 'dip2mom'), 'string', sprintf('%f %f %f', EEG.dipfit.model(EEG.dipfit.current).momxyz(2,:))); + else set(findobj(parent, 'tag', 'dip2mom'), 'string', sprintf('%0.3f %0.3f %0.3f', EEG.dipfit.model(EEG.dipfit.current).momxyz(2,:))); + end; + end + + case 'dialog_getvalue' + % synchronize the data with the gui + if get(findobj(parent, 'tag', 'dip1sel'), 'value'); select = [1]; else select = []; end; + if get(findobj(parent, 'tag', 'dip2sel'), 'value'); select = [select 2]; end; + posxyz(1,:) = str2num(get(findobj(parent, 'tag', 'dip1pos'), 'string')); + posxyz(2,:) = str2num(get(findobj(parent, 'tag', 'dip2pos'), 'string')); + momxyz(1,:) = str2num(get(findobj(parent, 'tag', 'dip1mom'), 'string')); + momxyz(2,:) = str2num(get(findobj(parent, 'tag', 'dip2mom'), 'string')); + % assign the local values to the global EEG object + EEG.dipfit.model(EEG.dipfit.current).posxyz = posxyz; + EEG.dipfit.model(EEG.dipfit.current).momxyz = momxyz; + EEG.dipfit.model(EEG.dipfit.current).select = select; + % FIXME, rv is undefined after a manual change of parameters + % FIXME, this should either be undated continuously or upon OK buttonpress + % EEG.dipfit.model(EEG.dipfit.current).rv = nan; + + % reassign the global EEG object back to the dialogs userdata + set(parent, 'userdata', EEG); + + case 'dialog_flip' + % flip the orientation of the dipole + current = EEG.dipfit.current; + moment = EEG.dipfit.model(current).momxyz; + EEG.dipfit.model(current).momxyz(dipnum,:) = [ -moment(dipnum,1) -moment(dipnum,2) -moment(dipnum,3)]; + set(findobj(parent, 'tag', ['dip' int2str(dipnum) 'mom']), 'string', ... + sprintf('%0.3f %0.3f %0.3f', EEG.dipfit.model(current).momxyz(dipnum,:))); + set(parent, 'userdata', EEG); + + case {'dipfit_moment', 'dipfit_position'} + % determine the selected dipoles and components + current = EEG.dipfit.current; + select = find([get(findobj(parent, 'tag', 'dip1sel'), 'value') get(findobj(parent, 'tag', 'dip2sel'), 'value')]); + if isempty(select) + warning('no dipoles selected for fitting'); + return + end + % remove the dipoles from the model that are not selected, but keep + % the original dipole model (to keep the GUI consistent) + model_before_fitting = EEG.dipfit.model(current); + EEG.dipfit.model(current).posxyz = EEG.dipfit.model(current).posxyz(select,:); + EEG.dipfit.model(current).momxyz = EEG.dipfit.model(current).momxyz(select,:); + if strcmp(subfunction, 'dipfit_moment') + % the default is 'yes' which should only be overruled for fitting dipole moment + cfg.nonlinear = 'no'; + end + dipfitdefs; + if get(findobj(parent, 'tag', 'dip2sym'), 'value') & get(findobj(parent, 'tag', 'dip2sel'), 'value') + if strcmpi(EEG.dipfit.coordformat,'MNI') + cfg.symmetry = 'x'; + else + cfg.symmetry = 'y'; + end; + else + cfg.symmetry = []; + end + + cfg.component = current; + % convert structure into list of input arguments + arg = [fieldnames(cfg)' ; struct2cell(cfg)']; + arg = arg(:)'; + + % make a dialog to interrupt the fitting procedure + fig = figure('visible', 'off'); + supergui( fig, {1 1}, [], ... + {'style' 'text' 'string' 'Press button below to stop fitting' }, ... + {'style' 'pushbutton' 'string' 'Interupt' 'callback' 'figure(gcbf); set(gcbf, ''tag'', ''stop'');' } ); + drawnow; + % start the dipole fitting + try + warning backtrace off; + EEG = dipfit_nonlinear(EEG, arg{:}); + warning backtrace on; + catch, + disp('Dipole localization failed'); + end; + + % should the following string be put into com? ->NOT SUPPORTED + % -------------------------------------------------------- + com = sprintf('%s = dipfit_nonlinear(%s,%s)\n', inputname(1), inputname(1), vararg2str(arg)); + + % this GUI always requires two sources in the dipole model + % first put the original model back in and then replace the dipole parameters that have been fitted + model_after_fitting = EEG.dipfit.model(current); + newfields = fieldnames( EEG.dipfit.model ); + for index = 1:length(newfields) + eval( ['EEG.dipfit.model(' int2str(current) ').' newfields{index} ' = model_after_fitting.' newfields{index} ';' ]); + end; + EEG.dipfit.model(current).posxyz(select,:) = model_after_fitting.posxyz; + EEG.dipfit.model(current).momxyz(select,:) = model_after_fitting.momxyz; + EEG.dipfit.model(current).rv = model_after_fitting.rv; + %EEG.dipfit.model(current).diffmap = model_after_fitting.diffmap; + + % reassign the global EEG object back to the dialogs userdata + set(parent, 'userdata', EEG); + % close the interrupt dialog + if ishandle(fig) + close(fig); + end + + otherwise + error('unknown subfunction for pop_dipfit_nonlinear'); + end % switch subfunction + + end % if nargin + + diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_dipfit_settings.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_dipfit_settings.m new file mode 100644 index 0000000000000000000000000000000000000000..b99516a85b96de8d09d05e0b5c47e7ea6678e8d1 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_dipfit_settings.m @@ -0,0 +1,371 @@ +% pop_dipfit_settings() - select global settings for dipole fitting through a pop up window +% +% Usage: +% >> OUTEEG = pop_dipfit_settings ( INEEG ); % pop up window +% >> OUTEEG = pop_dipfit_settings ( INEEG, 'key1', 'val1', 'key2', 'val2' ... ) +% +% Inputs: +% INEEG input dataset +% +% Optional inputs: +% 'hdmfile' - [string] file containing a head model compatible with +% the Fieldtrip dipolefitting() function ("vol" entry) +% 'mrifile' - [string] file containing an anatomical MR head image. +% The MRI must be normalized to the MNI brain. See the .mat +% files used by the sphere and boundary element models +% (For instance, select the sphere model and study 'EEG.dipfit'). +% If SPM2 software is installed, dipfit will be able to read +% most MRI file formats for plotting purposes (.mnc files, etc...). +% To plot dipoles in a subject MRI, first normalize the MRI +% to the MNI brain using SPM2. +% 'coordformat' - ['MNI'|'Spherical'] Coordinates returned by the selected +% head model. May be MNI coordinates or spherical coordinates +% (For spherical coordinates, the head radius is assumed to be 85 mm. +% 'chanfile' - [string] template channel locations file. (This function will +% check whether your channel locations file is compatible with +% your selected head model). +% 'chansel' - [integer vector] indices of channels to use for dipole fitting. +% {default: all} +% 'coord_transform' - [float array] Talairach transformation matrix for +% aligning the dataset channel locations to the selected +% head model. +% 'electrodes' - [integer array] indices of channels to include +% in the dipole model. {default: all} +% Outputs: +% OUTEEG output dataset +% +% Author: Arnaud Delorme, SCCN, La Jolla 2003- +% Robert Oostenveld, SMI/FCDC, Nijmegen 2003 + +% MEG flag: +% 'gradfile' - [string] file containing gradiometer locations +% ("gradfile" parameter in Fieldtrip dipolefitting() function) + +% SMI, University Aalborg, Denmark http://www.smi.auc.dk/ +% FC Donders Centre, University Nijmegen, the Netherlands http://www.fcdonders.kun.nl + +% Copyright (C) 2003 arno@salk.edu, Arnaud Delorme, SCCN, La Jolla 2003-2005 +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function [OUTEEG, com] = pop_dipfit_settings ( EEG, varargin ) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +if nargin < 1 + help pop_dipfit_settings; + return; +end; + +if ~plugin_askinstall('Fieldtrip-lite', 'ft_sourceanalysis'), return; end; + +OUTEEG = EEG; +com = ''; + +% get the default values and filenames +dipfitdefs; + +if nargin < 2 + + if isstr(EEG) % setmodel + tmpdat = get(gcf, 'userdata'); + chanfile = tmpdat.chanfile; + tmpdat = tmpdat.template_models; + tmpval = get(findobj(gcf, 'tag', 'listmodels'), 'value'); + set(findobj(gcf, 'tag', 'model'), 'string', char(tmpdat(tmpval).hdmfile)); + set(findobj(gcf, 'tag', 'coord'), 'value' , fastif(strcmpi(tmpdat(tmpval).coordformat,'MNI'),2, ... + fastif(strcmpi(tmpdat(tmpval).coordformat,'CTF'),3,1))); + set(findobj(gcf, 'tag', 'mri' ), 'string', char(tmpdat(tmpval).mrifile)); + set(findobj(gcf, 'tag', 'meg'), 'string', char(tmpdat(tmpval).chanfile)); + set(findobj(gcf, 'tag', 'coregcheckbox'), 'value', 0); + if tmpval < 3, + set(findobj(gcf, 'userdata', 'editable'), 'enable', 'off'); + else, + set(findobj(gcf, 'userdata', 'editable'), 'enable', 'on'); + end; + if tmpval == 3, + set(findobj(gcf, 'tag', 'headstr'), 'string', 'Subject CTF head model file (default.htm)'); + set(findobj(gcf, 'tag', 'mristr'), 'string', 'Subject MRI (coregistered with CTF head)'); + set(findobj(gcf, 'tag', 'chanstr'), 'string', 'CTF Res4 file'); + set(findobj(gcf, 'tag', 'manualcoreg'), 'enable', 'off'); + set(findobj(gcf, 'userdata', 'coreg'), 'enable', 'off'); + else, + set(findobj(gcf, 'tag', 'headstr'), 'string', 'Head model file'); + set(findobj(gcf, 'tag', 'mristr'), 'string', 'MRI file'); + set(findobj(gcf, 'tag', 'chanstr'), 'string', 'Model template channel locations file'); + set(findobj(gcf, 'tag', 'manualcoreg'), 'enable', 'on'); + set(findobj(gcf, 'userdata', 'coreg'), 'enable', 'on'); + end; + tmpl = tmpdat(tmpval).coord_transform; + set(findobj(gcf, 'tag', 'coregtext'), 'string', ''); + set(findobj(gcf, 'tag', 'coregcheckbox'), 'value', 0); + [allkeywordstrue transform] = lookupchantemplate(chanfile, tmpl); + if allkeywordstrue, + set(findobj(gcf, 'tag', 'coregtext'), 'string', char(vararg2str({ transform }))); + if isempty(transform) + set(findobj(gcf, 'tag', 'coregcheckbox'), 'value', 1); + else set(findobj(gcf, 'tag', 'coregcheckbox'), 'value', 0); + end; + end; + return; + end; + + % detect DIPFIT1.0x structure + % --------------------------- + if isfield(EEG.dipfit, 'vol') + str = [ 'Dipole information structure from DIPFIT v1.02 detected.' ... + 'Keep or erase the old dipole information including dipole locations? ' ... + 'In either case, a new dipole model can be constructed.' ]; + + tmpButtonName=questdlg2( strmultiline(str, 60), 'Old DIPFIT structure', 'Keep', 'Erase', 'Keep'); + if strcmpi(tmpButtonName, 'Keep'), return; end; + + elseif isfield(EEG.dipfit, 'hdmfile') + % detect previous DIPFIT structure + % -------------------------------- + str = [ 'Dipole information and settings are present in the dataset. ' ... + 'Keep or erase this information?' ]; + tmpButtonName=questdlg2( strmultiline(str, 60), 'Old DIPFIT structure', 'Keep', 'Erase', 'Keep'); + if strcmpi(tmpButtonName, 'Keep'), return; end; + end; + + % define the callbacks for the buttons + % ------------------------------------- + cb_selectelectrodes = [ 'tmplocs = EEG.chanlocs; tmp = select_channel_list({tmplocs.label}, ' ... + 'eval(get(findobj(gcbf, ''tag'', ''elec''), ''string'')));' ... + 'set(findobj(gcbf, ''tag'', ''elec''), ''string'',[''['' num2str(tmp) '']'']); clear tmplocs;' ]; % did not work + cb_selectelectrodes = 'tmplocs = EEG.chanlocs; set(findobj(gcbf, ''tag'', ''elec''), ''string'', int2str(pop_chansel({tmplocs.labels}))); clear tmplocs;'; + cb_volmodel = [ 'tmpdat = get(gcbf, ''userdata'');' ... + 'tmpind = get(gcbo, ''value'');' ... + 'set(findobj(gcbf, ''tag'', ''radii''), ''string'', num2str(tmpdat{tmpind}.r,3));' ... + 'set(findobj(gcbf, ''tag'', ''conduct''), ''string'', num2str(tmpdat{tmpind}.c,3));' ... + 'clear tmpdat tmpind;' ]; + cb_changeradii = [ 'tmpdat = get(gcbf, ''userdata'');' ... + 'tmpdat.vol.r = str2num(get(gcbo, ''string''));' ... + 'set(gcf, ''userdata'', tmpdat)' ]; + cb_changeconduct = [ 'tmpdat = get(gcbf, ''userdata'');' ... + 'tmpdat.vol.c = str2num(get(gcbo, ''string''));' ... + 'set(gcf, ''userdata'', tmpdat)' ]; + cb_changeorigin = [ 'tmpdat = get(gcbf, ''userdata'');' ... + 'tmpdat.vol.o = str2num(get(gcbo, ''string''));' ... + 'set(gcf, ''userdata'', tmpdat)' ]; + % cb_fitelec = [ 'if get(gcbo, ''value''),' ... + % ' set(findobj(gcbf, ''tag'', ''origin''), ''enable'', ''off'');' ... + % 'else' ... + % ' set(findobj(gcbf, ''tag'', ''origin''), ''enable'', ''on'');' ... + % 'end;' ]; + valmodel = 1; + userdata = []; + if isfield(EEG.chaninfo, 'filename') + if ~isempty(findstr(lower(EEG.chaninfo.filename), 'standard-10-5-cap385')), valmodel = 1; end; + if ~isempty(findstr(lower(EEG.chaninfo.filename), 'standard_1005')), valmodel = 2; end; + end; + + geomvert = [3 1 1 1 1 1 1 1 1 1 1]; + + geomhorz = { + [1 2] + [1] + [1 1.3 0.5 0.5 ] + [1 1.3 0.9 0.1 ] + [1 1.3 0.5 0.5 ] + [1 1.3 0.5 0.5 ] + [1 1.3 0.5 0.5 ] + [1 1.3 0.5 0.5 ] + [1] + [1] + [1] }; + + % define each individual graphical user element + comhelp1 = [ 'warndlg2(strvcat(''The two default head models are in ''standard_BEM'' and ''standard_BESA'''',' ... + ''' sub-folders in the DIPFIT2 plugin folder, and may be modified there.''), ''Model type'');' ]; + comhelp3 = [ 'warndlg2(strvcat(''Any MR image normalized to the MNI brain model may be used for plotting'',' ... + '''(see the DIPFIT 2.0 tutorial for more information)''), ''Model type'');' ]; + comhelp2 = [ 'warndlg2(strvcat(''The template location file associated with the head model'',' ... + '''you are using must be entered (see tutorial).''), ''Template location file'');' ]; + commandload1 = [ '[filename, filepath] = uigetfile(''*'', ''Select a text file'');' ... + 'if filename ~=0,' ... + ' set(findobj(''parent'', gcbf, ''tag'', ''model''), ''string'', [ filepath filename ]);' ... + 'end;' ... + 'clear filename filepath tagtest;' ]; + commandload2 = [ '[filename, filepath] = uigetfile(''*'', ''Select a text file'');' ... + 'if filename ~=0,' ... + ' set(findobj(''parent'', gcbf, ''tag'', ''meg''), ''string'', [ filepath filename ]);' ... + 'end;' ... + 'clear filename filepath tagtest;' ]; + commandload3 = [ '[filename, filepath] = uigetfile(''*'', ''Select a text file'');' ... + 'if filename ~=0,' ... + ' set(findobj(''parent'', gcbf, ''tag'', ''mri''), ''string'', [ filepath filename ]);' ... + 'end;' ... + 'clear filename filepath tagtest;' ]; + cb_selectcoreg = [ 'tmpmodel = get( findobj(gcbf, ''tag'', ''model''), ''string'');' ... + 'tmploc2 = get( findobj(gcbf, ''tag'', ''meg'') , ''string'');' ... + 'tmploc1 = get( gcbo, ''userdata'');' ... + 'tmptransf = get( findobj(gcbf, ''tag'', ''coregtext''), ''string'');' ... + '[tmp tmptransf] = coregister(tmploc1{1}, tmploc2, ''mesh'', tmpmodel,' ... + ' ''transform'', str2num(tmptransf), ''chaninfo1'', tmploc1{2}, ''helpmsg'', ''on'');' ... + 'if ~isempty(tmptransf), set( findobj(gcbf, ''tag'', ''coregtext''), ''string'', num2str(tmptransf)); end;' ... + 'clear tmpmodel tmploc2 tmploc1 tmp tmptransf;' ]; + setmodel = [ 'pop_dipfit_settings(''setmodel'');' ]; + + dipfitdefs; % contains template_model + + templatenames = { template_models.name }; + elements = { ... + { 'style' 'text' 'string' [ 'Head model (click to select)' 10 '' ] } ... + { 'style' 'listbox' 'string' strvcat(templatenames{:}) ... + 'callback' setmodel 'value' valmodel 'tag' 'listmodels' } { } ... + { 'style' 'text' 'string' '________' 'tag' 'headstr' } ... + { 'style' 'edit' 'string' '' 'tag' 'model' 'userdata' 'editable' 'enable' 'off'} ... + { 'style' 'pushbutton' 'string' 'Browse' 'callback' commandload1 'userdata' 'editable' 'enable' 'off' } ... + { 'style' 'pushbutton' 'string' 'Help' 'callback' comhelp1 } ... + { 'style' 'text' 'string' 'Output coordinates' } ... + { 'style' 'popupmenu' 'string' 'spherical (head radius 85 mm)|MNI|CTF' 'tag' 'coord' ... + 'value' 1 'userdata' 'editable' 'enable' 'off'} ... + { 'style' 'text' 'string' 'Click to select' } { } ... + { 'style' 'text' 'string' '________' 'tag' 'mristr' } ... + { 'style' 'edit' 'string' '' 'tag' 'mri' } ... + { 'style' 'pushbutton' 'string' 'Browse' 'callback' commandload3 } ... + { 'style' 'pushbutton' 'string' 'Help' 'callback' comhelp3 } ... + { 'style' 'text' 'string' '________', 'tag', 'chanstr' } ... + { 'style' 'edit' 'string' '' 'tag' 'meg' 'userdata' 'editable' 'enable' 'off'} ... + { 'style' 'pushbutton' 'string' 'Browse' 'callback' commandload2 'userdata' 'editable' 'enable' 'off'} ... + { 'style' 'pushbutton' 'string' 'Help' 'callback' comhelp2 } ... + { 'style' 'text' 'string' 'Co-register chan. locs. with head model' 'userdata' 'coreg' } ... + { 'style' 'edit' 'string' '' 'tag' 'coregtext' 'userdata' 'coreg' } ... + { 'style' 'pushbutton' 'string' 'Manual Co-Reg.' 'tag' 'manualcoreg' 'callback' cb_selectcoreg 'userdata' { EEG.chanlocs,EEG.chaninfo } } ... + { 'style' 'checkbox' 'string' 'No Co-Reg.' 'tag' 'coregcheckbox' 'value' 0 'userdata' 'coreg' } ... + { 'style' 'text' 'string' 'Channels to omit from dipole fitting' } ... + { 'style' 'edit' 'string' '' 'tag' 'elec' } ... + { 'style' 'pushbutton' 'string' 'List' 'callback' cb_selectelectrodes } { } ... + { } ... + { 'style' 'text' 'string' 'Note: For EEG, check that the channel locations are on the surface of the head model' } ... + { 'style' 'text' 'string' '(To do this: ''Set head radius'' to about 85 in the channel editor).' } ... + }; + + % plot GUI and protect parameters + % ------------------------------- + userdata.template_models = template_models; + if isfield(EEG.chaninfo, 'filename') + userdata.chanfile = lower(EEG.chaninfo.filename); + else userdata.chanfile = ''; + end; + optiongui = { 'geometry', geomhorz, 'uilist', elements, 'helpcom', 'pophelp(''pop_dipfit_settings'')', ... + 'title', 'Dipole fit settings - pop_dipfit_settings()', ... + 'userdata', userdata, 'geomvert', geomvert 'eval' 'pop_dipfit_settings(''setmodel'');' }; + [result, userdat2, strhalt, outstruct] = inputgui( 'mode', 'noclose', optiongui{:}); + if isempty(result), return; end; + if ~isempty(get(0, 'currentfigure')) currentfig = gcf; else return; end; + + while test_wrong_parameters(currentfig) + [result, userdat2, strhalt, outstruct] = inputgui( 'mode', currentfig, optiongui{:}); + if isempty(result), return; end; + end; + close(currentfig); + + % decode GUI inputs + % ----------------- + options = {}; + options = { options{:} 'hdmfile' result{2} }; + options = { options{:} 'coordformat' fastif(result{3} == 2, 'MNI', fastif(result{3} == 1, 'Spherical', 'CTF')) }; + options = { options{:} 'mrifile' result{4} }; + options = { options{:} 'chanfile' result{5} }; + if ~result{7}, options = { options{:} 'coord_transform' str2num(result{6}) }; end; + options = { options{:} 'chansel' setdiff(1:EEG.nbchan, str2num(result{8})) }; + +else + options = varargin; +end + +g = finputcheck(options, { 'hdmfile' 'string' [] ''; + 'mrifile' 'string' [] ''; + 'chanfile' 'string' [] ''; + 'chansel' 'integer' [] [1:EEG.nbchan]; + 'electrodes' 'integer' [] []; + 'coord_transform' 'real' [] []; + 'coordformat' 'string' { 'MNI','spherical','CTF' } 'MNI' }); +if isstr(g), error(g); end; + +OUTEEG = rmfield(OUTEEG, 'dipfit'); +OUTEEG.dipfit.hdmfile = g.hdmfile; +OUTEEG.dipfit.mrifile = g.mrifile; +OUTEEG.dipfit.chanfile = g.chanfile; +OUTEEG.dipfit.chansel = g.chansel; +OUTEEG.dipfit.coordformat = g.coordformat; +OUTEEG.dipfit.coord_transform = g.coord_transform; +if ~isempty(g.electrodes), OUTEEG.dipfit.chansel = g.electrodes; end; + +% removing channels with no coordinates +% ------------------------------------- +[tmpeloc labels Th Rd indices] = readlocs(EEG.chanlocs); +if length(indices) < length(EEG.chanlocs) + disp('Warning: Channels removed from dipole fitting no longer have location coordinates!'); + OUTEEG.dipfit.chansel = intersect( OUTEEG.dipfit.chansel, indices); +end; + +% checking electrode configuration +% -------------------------------- +if 0 + disp('Checking the electrode configuration'); + tmpchan = readlocs(OUTEEG.dipfit.chanfile); + [tmp1 ind1 ind2] = intersect( lower({ tmpchan.labels }), lower({ OUTEEG.chanlocs.labels })); + if isempty(tmp1) + disp('No channel labels in common found between template and dataset channels'); + if ~isempty(findstr(OUTEEG.dipfit.hdmfile, 'BESA')) + disp('Use the channel editor to fit a head sphere to your channel locations.'); + disp('Check for inconsistency in dipole info.'); + else + disp('Results using standard BEM model are INACCURATE when the chan locations are not on the head surface!'); + end; + else % common channels: performing best transformation + TMP = OUTEEG; + elec1 = eeglab2fieldtrip(TMP, 'elec'); + elec1 = elec1.elec; + TMP.chanlocs = tmpchan; + elec2 = eeglab2fieldtrip(TMP, 'elec'); + elec2 = elec2.elec; + cfg.elec = elec1; + cfg.template = elec2; + cfg.method = 'warp'; + elec3 = electrodenormalize(cfg); + + % convert back to EEGLAB format + OUTEEG.chanlocs = struct( 'labels', elec3.label, ... + 'X' , mat2cell(elec3.pnt(:,1)'), ... + 'Y' , mat2cell(elec3.pnt(:,2)'), ... + 'Z' , mat2cell(elec3.pnt(:,3)') ); + OUTEEG.chanlocs = convertlocs(OUTEEG.chanlocs, 'cart2all'); + end; + +end; + +com = sprintf('%s = pop_dipfit_settings( %s, %s);', inputname(1), inputname(1), vararg2str(options)); + +% test for wrong parameters +% ------------------------- +function bool = test_wrong_parameters(hdl) + + coreg1 = get( findobj( hdl, 'tag', 'coregtext') , 'string' ); + coreg2 = get( findobj( hdl, 'tag', 'coregcheckbox'), 'value' ); + meg = get( findobj( hdl, 'tag', 'coord'), 'value' ); + + bool = 0; + if meg == 3, return; end; + if coreg2 == 0 & isempty(coreg1) + bool = 1; warndlg2(strvcat('You must co-register your channel locations', ... + 'with the head model (Press buttun, "Manual Co-Reg".', ... + 'and follow instructions); To bypass co-registration,', ... + 'check the checkbox " No Co-Reg".'), 'Error'); + end; diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_dipplot.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_dipplot.m new file mode 100644 index 0000000000000000000000000000000000000000..1e859e7ea0adcef4d39dbdc7f5dad9f2af8d6fc6 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_dipplot.m @@ -0,0 +1,196 @@ +% pop_dipplot() - plot dipoles. +% +% Usage: +% >> pop_dipplot( EEG ); % pop up interactive window +% >> pop_dipplot( EEG, comps, 'key1', 'val1', 'key2', 'val2', ...); +% +% Graphic interface: +% "Components" - [edit box] enter component number to plot. By +% all the localized components are plotted. Command +% line equivalent: components. +% "Background image" - [edit box] MRI background image. This image +% has to be normalized to the MNI brain using SPM2 for +% instance. Dipplot() command line equivalent: 'image'. +% "Summary mode" - [Checkbox] when checked, plot the 3 views of the +% head model and dipole locations. Dipplot() equivalent +% is 'summary' and 'num'. +% "Plot edges" - [Checkbox] plot edges at the intersection between +% MRI slices. Diplot() equivalent is 'drawedges'. +% "Plot closest MRI slide" - [Checkbox] plot closest MRI slice to +% dipoles although not using the 'tight' view mode. +% Dipplot() equivalent is 'cornermri' and 'axistight'. +% "Plot dipole's 2-D projections" - [Checkbox] plot a dimed dipole +% projection on each 2-D MRI slice. Dipplot() equivalent +% is 'projimg'. +% "Plot projection lines" - [Checkbox] plot lines originating from +% dipoles and perpendicular to each 2-D MRI slice. +% Dipplot() equivalent is 'projline'. +% "Make all dipole point out" - [Checkbox] make all dipole point +% toward outside the brain. Dipplot() equivalent is +% 'pointout'. +% "Normalized dipole length" - [Checkbox] normalize the length of +% all dipoles. Dipplot() command line equivalent: 'normlen'. +% "Additionnal dipfit() options" - [checkbox] enter additionnal +% sequence of 'key', 'val' argument in this edit box. +% +% Inputs: +% EEG - Input dataset +% comps - [integer array] plot component indices. If empty +% all the localized components are plotted. +% +% Optional inputs: +% 'key','val' - same as dipplot() +% +% Author: Arnaud Delorme, CNL / Salk Institute, 26 Feb 2003- +% +% See also: dipplot() + +% "Use dipoles from" - [list box] use dipoles from BESA or from the +% DIPFIT toolbox. Command line equivalent: type. + +% Copyright (C) 2003 Arnaud Delorme, Salk Institute, arno@salk.edu +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function [com] = pop_dipplot( EEG, comps, varargin); + +com =''; +if nargin < 1 + help pop_dipplot; + return; +end; + +% check input structure +% --------------------- +if ~isfield(EEG, 'dipfit') & ~isfield(EEG, 'sources') + if ~isfield(EEG.dipfit.hdmfile) & ~isfield(EEG, 'sources') + error('No dipole information in dataset'); + end; + error('No dipole information in dataset'); +end; +if ~isfield(EEG.dipfit, 'model') + error('No dipole information in dataset'); +end; + +typedip = 'nonbesa'; +if nargin < 2 + % popup window parameters + % ----------------------- + commandload = [ '[filename, filepath] = uigetfile(''*'', ''Select a text file'');' ... + 'if filename ~=0,' ... + ' set(findobj(''parent'', gcbf, ''tag'', ''mrifile''), ''string'', [ filepath filename ]);' ... + 'end;' ... + 'clear filename filepath tagtest;' ]; + + geometry = { [2 1] [2 1] [0.8 0.3 1.5] [2.05 0.26 .75] [2.05 0.26 .75] [2.05 0.26 .75] ... + [2.05 0.26 .75] [2.05 0.26 .75] [2.05 0.26 .75] [2.05 0.26 .75] [2 1] }; + uilist = { { 'style' 'text' 'string' 'Components indices ([]=all avaliable)' } ... + { 'style' 'edit' 'string' '' } ... + { 'style' 'text' 'string' 'Plot dipoles within RV (%) range ([min max])' } ... + { 'style' 'edit' 'string' '' } ... + { 'style' 'text' 'string' 'Background image' } ... + { 'style' 'pushbutton' 'string' '...' 'callback' commandload } ... + { 'style' 'edit' 'string' EEG.dipfit.mrifile 'tag' 'mrifile' } ... + { 'style' 'text' 'string' 'Plot summary mode' } ... + { 'style' 'checkbox' 'string' '' } {} ... + { 'style' 'text' 'string' 'Plot edges' } ... + { 'style' 'checkbox' 'string' '' } {} ... + { 'style' 'text' 'string' 'Plot closest MRI slide' } ... + { 'style' 'checkbox' 'string' '' } {} ... + { 'style' 'text' 'string' 'Plot dipole''s 2-D projections' } ... + { 'style' 'checkbox' 'string' '' } {} ... + { 'style' 'text' 'string' 'Plot projection lines' } ... + { 'style' 'checkbox' 'string' '' 'value' 0 } {} ... + { 'style' 'text' 'string' 'Make all dipoles point out' } ... + { 'style' 'checkbox' 'string' '' } {} ... + { 'style' 'text' 'string' 'Normalized dipole length' } ... + { 'style' 'checkbox' 'string' '' 'value' 1 } {} ... + { 'style' 'text' 'string' 'Additionnal dipplot() options' } ... + { 'style' 'edit' 'string' '' } }; + + result = inputgui( geometry, uilist, 'pophelp(''pop_dipplot'')', 'Plot dipoles - pop_dipplot'); + if length(result) == 0 return; end; + + % decode parameters + % ----------------- + options = {}; + if ~isempty(result{1}), comps = eval( [ '[' result{1} ']' ] ); else comps = []; end; + if ~isempty(result{2}), options = { options{:} 'rvrange' eval( [ '[' result{2} ']' ] ) }; end; + options = { options{:} 'mri' result{3} }; + if result{4} == 1, options = { options{:} 'summary' 'on' 'num' 'on' }; end; + if result{5} == 1, options = { options{:} 'drawedges' 'on' }; end; + if result{6} == 1, options = { options{:} 'cornermri' 'on' 'axistight' 'on' }; end; + if result{7} == 1, options = { options{:} 'projimg' 'on' }; end; + if result{8} == 1, options = { options{:} 'projlines' 'on' }; end; + if result{9} == 1, options = { options{:} 'pointout' 'on' }; end; + if result{10} == 1, options = { options{:} 'normlen' 'on' }; end; + if ~isempty( result{11} ), tmpopt = eval( [ '{' result{11} '}' ] ); options = { options{:} tmpopt{:} }; end; +else + if isstr(comps) + typedip = comps; + options = varargin(2:end); + comps = varargin{1}; + else + options = varargin; + end; +end; + +if strcmpi(typedip, 'besa') + if ~isfield(EEG, 'sources'), error('No BESA dipole information in dataset');end; + if ~isempty(comps) + [tmp1 int] = intersect( [ EEG.sources.component ], comps); + if isempty(int), error ('Localization not found for selected components'); end; + dipplot(EEG.sources(int), 'sphere', 1, options{:}); + else + dipplot(EEG.sources, options{:}); + end; +else + if ~isfield(EEG, 'dipfit'), error('No DIPFIT dipole information in dataset');end; + + % components to plot + % ------------------ + if ~isempty(comps) + if ~isfield(EEG.dipfit.model, 'component') + for index = double(comps(:)') + EEG.dipfit.model(index).component = index; + end; + end; + else + % find localized dipoles + comps = []; + for index2 = 1:length(EEG.dipfit.model) + if ~isempty(EEG.dipfit.model(index2).posxyz) ~= 0 + comps = [ comps index2 ]; + EEG.dipfit.model(index2).component = index2; + end; + end; + end; + + % plotting + % -------- + tmpoptions = { options{:} 'coordformat', EEG.dipfit.coordformat }; + if strcmpi(EEG.dipfit.coordformat, 'spherical') + dipplot(EEG.dipfit.model(comps), tmpoptions{:}); + elseif strcmpi(EEG.dipfit.coordformat, 'CTF') + dipplot(EEG.dipfit.model(comps), tmpoptions{:}); + else + dipplot(EEG.dipfit.model(comps), 'meshdata', EEG.dipfit.hdmfile, tmpoptions{:}); + end; +end; + +if nargin < 3 + com = sprintf('pop_dipplot( %s,%s);', inputname(1), vararg2str({ comps options{:}})); +end; +return; diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_multifit.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_multifit.m new file mode 100644 index 0000000000000000000000000000000000000000..b300cd40ef6983f40635d187421510a7624cb1dc --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/pop_multifit.m @@ -0,0 +1,243 @@ +% pop_multifit() - fit multiple component dipoles using DIPFIT +% +% Usage: +% >> EEG = pop_multifit(EEG); % pop-up graphical interface +% >> EEG = pop_multifit(EEG, comps, 'key', 'val', ...); +% +% Inputs: +% EEG - input EEGLAB dataset. +% comps - indices component to fit. Empty is all components. +% +% Optional inputs: +% 'dipoles' - [1|2] use either 1 dipole or 2 dipoles contrain in +% symmetry. Default is 1. +% 'dipplot' - ['on'|'off'] plot dipoles. Default is 'off'. +% 'plotopt' - [cell array] dipplot() 'key', 'val' options. Default is +% 'normlen', 'on', 'image', 'fullmri' +% 'rmout' - ['on'|'off'] remove dipoles outside the head. Artifactual +% component often localize outside the head. Default is 'off'. +% 'threshold' - [float] rejection threshold during component scan. +% Default is 40 (residual variance above 40%). +% +% Outputs: +% EEG - output dataset with updated "EEG.dipfit" field +% +% Note: residual variance is set to NaN if DIPFIT does not converge +% +% Author: Arnaud Delorme, SCCN/INC/UCSD, La Jolla, Oct. 2003 + +% Copyright (C) 9/2003 Arnaud Delorme, SCCN/INC/UCSD, arno@salk.edu +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function [EEG, com] = pop_multifit(EEG, comps, varargin); + + if nargin < 1 + help pop_multifit; + return; + end; + + com = []; + ncomps = size(EEG.icaweights,1); + if ncomps == 0, error('you must run ICA first'); end; + + if nargin<2 + cb_chans = 'tmplocs = EEG.chanlocs; set(findobj(gcbf, ''tag'', ''chans''), ''string'', int2str(pop_chansel({tmplocs.labels}))); clear tmplocs;'; + + uilist = { { 'style' 'text' 'string' 'Component indices' } ... + { 'style' 'edit' 'string' [ '1:' int2str(ncomps) ] } ... + { 'style' 'text' 'string' 'Rejection threshold RV (%)' } ... + { 'style' 'edit' 'string' '100' } ... + { 'style' 'text' 'string' 'Remove dipoles outside the head' } ... + { 'style' 'checkbox' 'string' '' 'value' 0 } {} ... + { 'style' 'text' 'string' 'Fit bilateral dipoles (check)' } ... + { 'style' 'checkbox' 'string' '' 'value' 0 } {} ... + { 'style' 'text' 'string' 'Plot resulting dipoles (check)' } ... + { 'style' 'checkbox' 'string' '' 'value' 0 } {} ... + { 'style' 'text' 'string' 'dipplot() plotting options' } ... + { 'style' 'edit' 'string' '''normlen'' ''on''' } ... + { 'style' 'pushbutton' 'string' 'Help' 'callback' 'pophelp(''dipplot'')' } }; + + results = inputgui( { [1.91 2.8] [1.91 2.8] [3.1 0.8 1.6] [3.1 0.8 1.6] [3.1 0.8 1.6] [2.12 2.2 0.8]}, ... + uilist, 'pophelp(''pop_multifit'')', ... + 'Fit multiple ICA components -- pop_multifit()'); + if length(results) == 0 return; end; + comps = eval( [ '[' results{1} ']' ] ); + + % selecting model + % --------------- + options = {}; + if ~isempty(results{2}) + options = { options{:} 'threshold' eval( results{2} ) }; + end; + if results{3}, options = { options{:} 'rmout' 'on' }; end; + if results{4}, options = { options{:} 'dipoles' 2 }; end; + if results{5}, options = { options{:} 'dipplot' 'on' }; end; + options = { options{:} 'plotopt' eval( [ '{ ' results{6} ' }' ]) }; + else + options = varargin; + end; + + % checking parameters + % ------------------- + if isempty(comps), comps = [1:size(EEG.icaweights,1)]; end; + g = finputcheck(options, { 'settings' { 'cell' 'struct' } [] {}; % deprecated + 'dipoles' 'integer' [1 2] 1; + 'threshold' 'float' [0 100] 40; + 'dipplot' 'string' { 'on' 'off' } 'off'; + 'rmout' 'string' { 'on' 'off' } 'off'; + 'plotopt' 'cell' {} {'normlen' 'on' }}); + + if isstr(g), error(g); end; + EEG = eeg_checkset(EEG, 'chanlocs_homogeneous'); + + % dipfit settings + % --------------- + if isstruct(g.settings) + EEG.dipfit = g.settings; + elseif ~isempty(g.settings) + EEG = pop_dipfit_settings( EEG, g.settings{:}); % will probably not work but who knows + end; + + % Scanning dipole locations + % ------------------------- + dipfitdefs; + skipscan = 0; + try + alls = cellfun('size', { EEG.dipfit.model.posxyz }, 2); + if length(alls) == ncomps + if all(alls == 3) + skipscan = 1; + end; + end; + catch, end; + if skipscan + disp('Skipping scanning since all dipoles have non-null starting positions.'); + else + disp('Scanning dipolar grid to find acceptable starting positions...'); + xg = linspace(-floor(meanradius), floor(meanradius),11); + yg = linspace(-floor(meanradius), floor(meanradius),11); + zg = linspace(0 , floor(meanradius), 6); + EEG = pop_dipfit_gridsearch( EEG, [1:ncomps], ... + eval(xgridstr), eval(ygridstr), eval(zgridstr), 100); + disp('Scanning terminated. Refining dipole locations...'); + end; + + % set symmetry constraint + % ---------------------- + if strcmpi(EEG.dipfit.coordformat,'MNI') + defaultconstraint = 'x'; + else + defaultconstraint = 'y'; + end; + + % Searching dipole localization + % ----------------------------- + disp('Searching dipoles locations...'); + chansel = EEG.dipfit.chansel; + %elc = getelecpos(EEG.chanlocs, EEG.dipfit); + plotcomps = []; + for i = comps(:)' + if i <= length(EEG.dipfit.model) & ~isempty(EEG.dipfit.model(i).posxyz) + if g.dipoles == 2, + % try to find a good origin for automatic dipole localization + EEG.dipfit.model(i).active = [1 2]; + EEG.dipfit.model(i).select = [1 2]; + if isempty(EEG.dipfit.model(i).posxyz) + EEG.dipfit.model(i).posxyz = zeros(1,3); + EEG.dipfit.model(i).momxyz = zeros(2,3); + else + EEG.dipfit.model(i).posxyz(2,:) = EEG.dipfit.model(i).posxyz; + if strcmpi(EEG.dipfit.coordformat, 'MNI') + EEG.dipfit.model(i).posxyz(:,1) = [-40;40]; + else EEG.dipfit.model(i).posxyz(:,2) = [-40;40]; + end; + EEG.dipfit.model(i).momxyz(2,:) = EEG.dipfit.model(i).momxyz; + end; + else + EEG.dipfit.model(i).active = [1]; + EEG.dipfit.model(i).select = [1]; + end; + warning backtrace off; + try, + if g.dipoles == 2, + EEG = dipfit_nonlinear(EEG, 'component', i, 'symmetry', defaultconstraint); + else + EEG = dipfit_nonlinear(EEG, 'component', i, 'symmetry', []); + end; + catch, EEG.dipfit.model(i).rv = NaN; disp('Maximum number of iterations reached. Fitting failed'); + end; + warning backtrace on; + plotcomps = [ plotcomps i ]; + end; + end; + + % set RV to 1 for dipole with higher than 40% residual variance + % ------------------------------------------------------------- + EEG.dipfit.model = dipfit_reject(EEG.dipfit.model, g.threshold/100); + + % removing dipoles outside the head + % --------------------------------- + if strcmpi(g.rmout, 'on') & strcmpi(EEG.dipfit.coordformat, 'spherical') + rmdip = []; + for index = plotcomps + if ~isempty(EEG.dipfit.model(index).posxyz) + if any(sqrt(sum(EEG.dipfit.model(index).posxyz.^2,2)) > 85) + rmdip = [ rmdip index]; + EEG.dipfit.model(index).posxyz = []; + EEG.dipfit.model(index).momxyz = []; + EEG.dipfit.model(index).rv = 1; + end; + end; + end; + plotcomps = setdiff(plotcomps, rmdip); + if length(rmdip) > 0 + fprintf('%d out of cortex dipoles removed (usually artifacts)\n', length(rmdip)); + end; + end; + + % plotting dipoles + % ---------------- + if strcmpi(g.dipplot, 'on') + pop_dipplot(EEG, 'DIPFIT', plotcomps, g.plotopt{:}); + end; + + com = sprintf('%s = pop_multifit(%s, %s);', inputname(1), inputname(1), vararg2str({ comps options{:}})); + return; + +% get electrode positions from eeglag +% ----------------------------------- +function elc = getelecpos(chanlocs, dipfitstruct); + try, + elc = [ [chanlocs.X]' [chanlocs.Y]' [chanlocs.Z]' ]; + catch + disp('No 3-D carthesian coordinates; re-computing them from 2-D polar coordinates'); + EEG.chanlocs = convertlocs(EEG.chanlocs, 'topo2all'); + elc = [ [chanlocs.X]' [chanlocs.Y]' [chanlocs.Z]' ]; + end; + % constrain electrode to sphere + % ----------------------------- + disp('Constraining electrodes to sphere'); + elc = elc - repmat( dipfitstruct.vol.o, [size(elc,1) 1]); % recenter + % (note the step above is not needed since the origin should always be 0) + elc = elc ./ repmat( sqrt(sum(elc.*elc,2)), [1 3]); % normalize + elc = elc * max(dipfitstruct.vol.r); % head size + + %for index= 1:size(elc,1) + % elc(index,:) = max(dipfitstruct.vol.r) * elc(index,:) /norm(elc(index,:)); + %end; + + + diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/globalrescale.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/globalrescale.m new file mode 100644 index 0000000000000000000000000000000000000000..c4a7c2686ee67f9dfc6fb7cdd88ffa5b1f82c450 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/globalrescale.m @@ -0,0 +1,60 @@ +function [H] = globalrescale(f); + +% GLOBALRESCALE creates the homogenous spatial transformation matrix +% for a 7 parameter rigid-body transformation with global rescaling +% +% Use as +% [H] = globalrescale(f) +% +% The transformation vector f should contain the +% x-shift +% y-shift +% z-shift +% followed by the +% pitch (rotation around x-axis) +% roll (rotation around y-axis) +% yaw (rotation around z-axis) +% followed by the +% global rescaling factor + +% Copyright (C) 2000-2005, Robert Oostenveld +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +% $Log: globalrescale.m,v $ +% Revision 1.1 2009/01/30 04:02:06 arno +% *** empty log message *** +% +% Revision 1.3 2005/08/15 08:15:32 roboos +% reimplemented the rotate function, which contained an error (the error is in the AIR technical reference) +% changed all functions to be dependent on the rotate, translate and scale function +% all functions now behave consistenly, which also means that they are not compleetly backward compatible w.r.t. the order of the rotations +% +% Revision 1.2 2004/05/19 09:57:07 roberto +% added GPL copyright statement, added CVS log item +% + +% compute the homogenous transformation matrix for the translation +T = translate(f([1 2 3])); + +% compute the homogenous transformation matrix for the rotation +R = rotate(f([4 5 6])); + +% compute the homogenous transformation matrix for the global scaling +S = scale(f([7 7 7])); + +% compute the homogenous transformation matrix for the combination +H = T*R*S; + diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/match_str.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/match_str.m new file mode 100644 index 0000000000000000000000000000000000000000..f7aad939e77ca03158df1405838f416b9b9cb7fd --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/match_str.m @@ -0,0 +1,79 @@ +function [sel1, sel2] = match_str(a, b); + +% MATCH_STR looks for matching labels in two listst of strings +% and returns the indices into both the 1st and 2nd list of the matches. +% They will be ordered according to the first input argument. +% +% [sel1, sel2] = match_str(strlist1, strlist2) +% +% The strings can be stored as a char matrix or as an vertical array of +% cells, the matching is done for each row. + +% Copyright (C) 2000, Robert Oostenveld +% +% $Log: match_str.m,v $ +% Revision 1.1 2009/01/30 04:02:07 arno +% *** empty log message *** +% +% Revision 1.6 2006/11/06 21:11:45 roboos +% also deal with empty [] input +% +% Revision 1.5 2004/11/10 17:11:40 roboos +% reverted to original implementation and reimplemented the speed up +% from scratch. The previous two revisions both were incompatible +% with the original implementation. +% +% Revision 1.4 2004/11/09 15:28:57 roboos +% fixed incompatibility that was introduced by previous speed increase: +% the original version gave back double occurences, and other fieldtrip +% functions (sourceanalysis) rely on this. The previously commited +% version only gave back one occurence of each hit, this is fixed by jansch +% in this version +% +% Revision 1.3 2004/10/22 15:59:41 roboos +% large speed increase by replacing 2 nested for loops by a standard matlab function (intersect) +% +% Revision 1.2 2003/03/17 10:37:28 roberto +% improved general help comments and added copyrights + +% ensure that both are cell-arrays +if isempty(a) + a = {}; +elseif ~iscell(a) + a = cellstr(a); +end +if isempty(b) + b = {}; +elseif ~iscell(b) + b = cellstr(b); +end + +% ensure that both are column vectors +a = a(:); +b = b(:); + +% regardless of what optimizations are implemented, the code should remain +% functionally compatible to the original, which is +% for i=1:length(a) +% for j=1:length(b) +% if strcmp(a(i),b(j)) +% sel1 = [sel1; i]; +% sel2 = [sel2; j]; +% end +% end +% end + +% replace all unique strings by a unique number and use the fact that +% numeric comparisons are much faster than string comparisons +[dum1, dum2, c] = unique([a; b]); +a = c(1:length(a)); +b = c((length(a)+1):end); + +sel1 = []; +sel2 = []; +for i=1:length(a) + % s = find(strcmp(a(i), b)); % for string comparison + s = find(a(i)==b); % for numeric comparison + sel1 = [sel1; repmat(i, size(s))]; + sel2 = [sel2; s]; +end diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/rigidbody.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/rigidbody.m new file mode 100644 index 0000000000000000000000000000000000000000..d29766bea0be6998ae18ed5399c494dc0158ff17 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/rigidbody.m @@ -0,0 +1,58 @@ +function [H] = rigidbody(f); + +% RIGIDBODY creates the homogenous spatial transformation matrix +% for a 6 parameter rigid-body transformation +% +% Use as +% [H] = rigidbody(f) +% +% The transformation vector f should contain the +% x-shift +% y-shift +% z-shift +% followed by the +% pitch (rotation around x-axis) +% roll (rotation around y-axis) +% yaw (rotation around z-axis) + +% Copyright (C) 2000-2005, Robert Oostenveld +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +% $Log: rigidbody.m,v $ +% Revision 1.1 2009/01/30 04:02:11 arno +% *** empty log message *** +% +% Revision 1.4 2006/04/13 10:37:38 roboos +% added a ; to the end of a line +% +% Revision 1.3 2005/08/15 08:15:32 roboos +% reimplemented the rotate function, which contained an error (the error is in the AIR technical reference) +% changed all functions to be dependent on the rotate, translate and scale function +% all functions now behave consistenly, which also means that they are not compleetly backward compatible w.r.t. the order of the rotations +% +% Revision 1.2 2004/05/19 09:57:07 roberto +% added GPL copyright statement, added CVS log item +% + +% compute the homogenous transformation matrix for the translation +T = translate(f([1 2 3])); + +% compute the homogenous transformation matrix for the rotation +R = rotate(f([4 5 6])); + +% compute the homogenous transformation matrix for the combination +H = T*R; + diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/rotate.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/rotate.m new file mode 100644 index 0000000000000000000000000000000000000000..94bb5e17f5c813c15adad96d1e230e42c5fc4e2e --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/rotate.m @@ -0,0 +1,118 @@ +function [H] = rotate(D); + +% ROTATE returns the homogenous coordinate transformation matrix +% corresponding to a rotation around the x, y and z-axis. The direction of +% the rotation is according to the right-hand rule. +% +% Use as +% [H] = rotate(R) +% where +% R [rx, ry, rz] in degrees +% H corresponding homogenous transformation matrix +% +% Note that the order in which the rotations are performs matters. The +% rotation is first done around the z-axis, then the y-axis and finally the +% x-axis. + +% Copyright (C) 2000-2005, Robert Oostenveld +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +% $Log: rotate.m,v $ +% Revision 1.1 2009/01/30 04:02:11 arno +% *** empty log message *** +% +% Revision 1.5 2006/09/12 13:35:28 roboos +% convert input rotation from degrees (according to documentation) into radians (needed for computations) +% +% Revision 1.4 2005/08/15 08:15:33 roboos +% reimplemented the rotate function, which contained an error (the error is in the AIR technical reference) +% changed all functions to be dependent on the rotate, translate and scale function +% all functions now behave consistenly, which also means that they are not compleetly backward compatible w.r.t. the order of the rotations +% +% Revision 1.3 2004/05/19 09:57:07 roberto +% added GPL copyright statement, added CVS log item +% + +% convert degrees to radians +R = D*pi/180; + +% get the individual angles (in radians) +rx = R(1); +ry = R(2); +rz = R(3); + +% precompute the sin/cos values of the angles +cX = cos(rx); +cY = cos(ry); +cZ = cos(rz); +sX = sin(rx); +sY = sin(ry); +sZ = sin(rz); + +% according to Roger Woods' http://bishopw.loni.ucla.edu/AIR5/homogenous.html +% it should be this, but I cannot reproduce his rotation matrix +% H = eye(4,4); +% H(1,1) = cZ*cY + sZ*sX*sY; +% H(1,2) = sZ*cY - cZ*sX*sY; +% H(1,3) = cX*sY; +% H(2,1) = -sZ*cX; +% H(2,2) = cZ*cX; +% H(2,3) = sX; +% H(3,1) = sZ*sX*cY - cZ*sY; +% H(3,2) = -cZ*sX*cY - sZ*sY; +% H(3,3) = cX*cY; + +% instead, the following rotation matrix does work according my +% expectations. It rotates according to the right hand rule and first +% rotates around z, then y and then x axis +H = [ + cZ*cY, -sZ*cY, sY, 0 + cZ*sY*sX+sZ*cX, -sZ*sY*sX+cZ*cX, -cY*sX, 0 + -cZ*sY*cX+sZ*sX, sZ*sY*cX+cZ*sX, cY*cX, 0 + 0, 0, 0, 1 +]; + +if 0 +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% The following code can be used to construct the combined rotation matrix +% for either xyz or zyx ordering (using the Matlab symbolic math toolbox) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + syms sX sY sZ cX cY cZ + % this is for only rotating around x + Rx = [ + 1 0 0 0 + 0 cX -sX 0 + 0 sX cX 0 + 0 0 0 1 + ]; + % this is for only rotating around y + Ry = [ + cY 0 sY 0 + 0 1 0 0 + -sY 0 cY 0 + 0 0 0 1 + ]; + % this is for only rotating around z + Rz = [ + cZ -sZ 0 0 + sZ cZ 0 0 + 0 0 1 0 + 0 0 0 1 + ]; + % combine them + Rzyx = Rz * Ry * Rx % rotate around x, y, then z + Rxyz = Rx * Ry * Rz % rotate around z, y, then x +end diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/scale.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/scale.m new file mode 100644 index 0000000000000000000000000000000000000000..1a43b88f187f9d85ba68ec57a619e7167d65abcb --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/scale.m @@ -0,0 +1,48 @@ +function [H] = scale(S); + +% SCALE returns the homogenous coordinate transformation matrix +% corresponding to a scaling along the x, y and z-axis +% +% Use as +% [H] = translate(S) +% where +% S [sx, sy, sz] scaling along each of the axes +% H corresponding homogenous transformation matrix + +% Copyright (C) 2000-2005, Robert Oostenveld +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +% $Log: scale.m,v $ +% Revision 1.1 2009/01/30 04:02:11 arno +% *** empty log message *** +% +% Revision 1.2 2005/08/15 08:15:33 roboos +% reimplemented the rotate function, which contained an error (the error is in the AIR technical reference) +% changed all functions to be dependent on the rotate, translate and scale function +% all functions now behave consistenly, which also means that they are not compleetly backward compatible w.r.t. the order of the rotations +% +% Revision 1.1 2004/05/19 09:57:07 roberto +% added GPL copyright statement, added CVS log item +% + +H = [ + S(1) 0 0 0 + 0 S(2) 0 0 + 0 0 S(3) 0 + 0 0 0 1 + ]; + + \ No newline at end of file diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/traditional.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/traditional.m new file mode 100644 index 0000000000000000000000000000000000000000..f132f96157346540d3294837ea9ccf17e32ba985 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/traditional.m @@ -0,0 +1,70 @@ +function [H] = traditional(f); + +% TRADITIONAL creates the homogenous spatial transformation matrix +% for a 9 parameter traditional "Talairach-model" transformation +% +% Use as +% [H] = traditional(f) +% +% The transformation vector f should contain the +% x-shift +% y-shift +% z-shift +% followed by the +% pitch (rotation around x-axis) +% roll (rotation around y-axis) +% yaw (rotation around z-axis) +% followed by the +% x-rescaling factor +% y-rescaling factor +% z-rescaling factor +% +% The order in which the transformations are done is exactly opposite as +% the list above, i.e. first z-rescale, ... and finally x-shift. + +% Copyright (C) 2000-2005, Robert Oostenveld +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +% $Log: traditional.m,v $ +% Revision 1.1 2009/01/30 04:02:12 arno +% *** empty log message *** +% +% Revision 1.5 2005/08/15 08:15:33 roboos +% reimplemented the rotate function, which contained an error (the error is in the AIR technical reference) +% changed all functions to be dependent on the rotate, translate and scale function +% all functions now behave consistenly, which also means that they are not compleetly backward compatible w.r.t. the order of the rotations +% +% Revision 1.4 2005/08/11 07:57:14 roboos +% fixed bug in y-rotation +% +% Revision 1.3 2005/04/21 08:28:45 roboos +% fixed bug in rotation matrix (thanks to Arno) +% +% Revision 1.2 2004/05/19 09:57:07 roberto +% added GPL copyright statement, added CVS log item +% + +% compute the homogenous transformation matrix for the translation +T = translate(f([1 2 3])); + +% compute the homogenous transformation matrix for the rotation +R = rotate(f([4 5 6])); + +% compute the homogenous transformation matrix for the scaling +S = scale(f([7 8 9])); + +% compute the homogenous transformation matrix for the combination +H = T*R*S; diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/translate.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/translate.m new file mode 100644 index 0000000000000000000000000000000000000000..b291ea181232bfb904c7a970982ce8aba7cd4685 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/translate.m @@ -0,0 +1,46 @@ +function [H] = translate(T); + +% TRANSLATE returns the homogenous coordinate transformation matrix +% corresponding to a translation along the x, y and z-axis +% +% Use as +% [H] = translate(T) +% where +% T [tx, ty, tz] translation along each of the axes +% H corresponding homogenous transformation matrix + +% Copyright (C) 2000-2005, Robert Oostenveld +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +% $Log: translate.m,v $ +% Revision 1.1 2009/01/30 04:02:12 arno +% *** empty log message *** +% +% Revision 1.4 2005/08/15 08:15:33 roboos +% reimplemented the rotate function, which contained an error (the error is in the AIR technical reference) +% changed all functions to be dependent on the rotate, translate and scale function +% all functions now behave consistenly, which also means that they are not compleetly backward compatible w.r.t. the order of the rotations +% +% Revision 1.3 2004/05/19 09:57:07 roberto +% added GPL copyright statement, added CVS log item +% + +H = [ + 1 0 0 T(1) + 0 1 0 T(2) + 0 0 1 T(3) + 0 0 0 1 + ]; diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/warp_apply.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/warp_apply.m new file mode 100644 index 0000000000000000000000000000000000000000..83bbd1fee79c1958fefa7f9d7b01e07749a7a6df --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/warp_apply.m @@ -0,0 +1,164 @@ +function [warped] = warp_apply(M, input, method); + +% WARP_APPLY performs a 3D linear or nonlinear transformation on the input +% coordinates, similar to those in AIR 3.08. You can find technical +% documentation on warping in general at http://bishopw.loni.ucla.edu/AIR3 +% +% Use as +% [warped] = warp_apply(M, input, method) +% where +% M mvector or matrix with warping parameters +% input Nx3 matrix with coordinates +% warped Nx3 matrix with coordinates +% method string describing the warping method +% +% The methods 'nonlin0', 'nonlin2' ... 'nonlin5' specify a +% polynomial transformation. The size of the transformation matrix +% depends on the order of the warp +% zeroth order : 1 parameter per coordinate (translation) +% first order : 4 parameters per coordinate (total 12, affine) +% second order : 10 parameters per coordinate +% third order : 20 parameters per coordinate +% fourth order : 35 parameters per coordinate +% fifth order : 56 parameters per coordinate (total 168) +% The size of M should be 3xP, where P is the number of parameters +% per coordinate. Alternatively, you can specify the method to be +% 'nonlinear', where the order will be determined from teh size of +% the matrix M. +% +% If the method 'homogeneous' is selected, the input matrix M should be +% a 4x4 homogenous transformation matrix. +% +% If any other method is selected, it is assumed that it specifies +% the name of an auxiliary function that will, when given the input +% parameter vector M, return an 4x4 homogenous transformation +% matrix. Supplied functions in teh warping toolbox are translate, +% rotate, scale, rigidbody, globalrescale, traditional, affine, +% perspective. + +% Copyright (C) 2000-2005, Robert Oostenveld +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +% $Log: warp_apply.m,v $ +% Revision 1.1 2009/01/30 04:02:13 arno +% *** empty log message *** +% +% Revision 1.2 2006/09/13 09:47:41 roboos +% auto-detect homogeneous transformation if method not given +% +% Revision 1.1 2005/08/15 08:10:07 roboos +% renamed warp3d into warp_apply +% +% Revision 1.5 2005/03/21 15:35:38 roboos +% added support for nonlin0 up to nonlin5 as method-string (equivalent to nonlinear) +% extended help, added some comments and error checks +% +% Revision 1.4 2004/05/19 09:57:07 roberto +% added GPL copyright statement, added CVS log item +% +% Revision 1.3 2004/05/19 09:48:01 roberto +% *** empty log message *** +% +% Revision 1.2 2003/03/12 16:07:18 roberto +% improved help documentation +% + +if nargin<3 && all(size(M)==4) + % no specific transformation mode has been selected + % it looks like a homogenous transformation matrix + method = 'homogenous'; +elseif nargin<3 + % the default method is 'nonlinear' + method = 'nonlinear'; +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% nonlinear warping +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if any(strcmp(method, {'nonlinear', 'nonlin0', 'nonlin1', 'nonlin2', 'nonlin3', 'nonlin4', 'nonlin5'})) + x = input(:,1); + y = input(:,2); + z = input(:,3); + s = size(M); + + if s(1)~=3 + error('invalid size of nonlinear transformation matrix'); + elseif strcmp(method, 'nonlin0') & s(2)~=1 + error('invalid size of nonlinear transformation matrix'); + elseif strcmp(method, 'nonlin1') & s(2)~=4 + error('invalid size of nonlinear transformation matrix'); + elseif strcmp(method, 'nonlin2') & s(2)~=10 + error('invalid size of nonlinear transformation matrix'); + elseif strcmp(method, 'nonlin3') & s(2)~=20 + error('invalid size of nonlinear transformation matrix'); + elseif strcmp(method, 'nonlin4') & s(2)~=35 + error('invalid size of nonlinear transformation matrix'); + elseif strcmp(method, 'nonlin5') & s(2)~=56 + error('invalid size of nonlinear transformation matrix'); + end + + if s(2)==1 + % this is a translation, which in a strict sense is not the 0th order nonlinear transformation + xx = M(1,1) + x; + yy = M(2,1) + y; + zz = M(3,1) + z; + elseif s(2)==4 + xx = M(1,1) + M(1,2)*x + M(1,3)*y + M(1,4)*z; + yy = M(2,1) + M(2,2)*x + M(2,3)*y + M(2,4)*z; + zz = M(3,1) + M(3,2)*x + M(3,3)*y + M(3,4)*z; + elseif s(2)==10 + xx = M(1,1) + M(1,2)*x + M(1,3)*y + M(1,4)*z + M(1,5)*x.*x + M(1,6)*x.*y + M(1,7)*x.*z + M(1,8)*y.*y + M(1,9)*y.*z + M(1,10)*z.*z; + yy = M(2,1) + M(2,2)*x + M(2,3)*y + M(2,4)*z + M(2,5)*x.*x + M(2,6)*x.*y + M(2,7)*x.*z + M(2,8)*y.*y + M(2,9)*y.*z + M(2,10)*z.*z; + zz = M(3,1) + M(3,2)*x + M(3,3)*y + M(3,4)*z + M(3,5)*x.*x + M(3,6)*x.*y + M(3,7)*x.*z + M(3,8)*y.*y + M(3,9)*y.*z + M(3,10)*z.*z; + elseif s(2)==20 + xx = M(1,1) + M(1,2)*x + M(1,3)*y + M(1,4)*z + M(1,5)*x.*x + M(1,6)*x.*y + M(1,7)*x.*z + M(1,8)*y.*y + M(1,9)*y.*z + M(1,10)*z.*z + M(1,11)*x.*x.*x + M(1,12)*x.*x.*y + M(1,13)*x.*x.*z + M(1,14)*x.*y.*y + M(1,15)*x.*y.*z + M(1,16)*x.*z.*z + M(1,17)*y.*y.*y + M(1,18)*y.*y.*z + M(1,19)*y.*z.*z + M(1,20)*z.*z.*z; + yy = M(2,1) + M(2,2)*x + M(2,3)*y + M(2,4)*z + M(2,5)*x.*x + M(2,6)*x.*y + M(2,7)*x.*z + M(2,8)*y.*y + M(2,9)*y.*z + M(2,10)*z.*z + M(2,11)*x.*x.*x + M(2,12)*x.*x.*y + M(2,13)*x.*x.*z + M(2,14)*x.*y.*y + M(2,15)*x.*y.*z + M(2,16)*x.*z.*z + M(2,17)*y.*y.*y + M(2,18)*y.*y.*z + M(2,19)*y.*z.*z + M(2,20)*z.*z.*z; + zz = M(3,1) + M(3,2)*x + M(3,3)*y + M(3,4)*z + M(3,5)*x.*x + M(3,6)*x.*y + M(3,7)*x.*z + M(3,8)*y.*y + M(3,9)*y.*z + M(3,10)*z.*z + M(3,11)*x.*x.*x + M(3,12)*x.*x.*y + M(3,13)*x.*x.*z + M(3,14)*x.*y.*y + M(3,15)*x.*y.*z + M(3,16)*x.*z.*z + M(3,17)*y.*y.*y + M(3,18)*y.*y.*z + M(3,19)*y.*z.*z + M(3,20)*z.*z.*z; + elseif s(2)==35 + xx = M(1,1) + M(1,2)*x + M(1,3)*y + M(1,4)*z + M(1,5)*x.*x + M(1,6)*x.*y + M(1,7)*x.*z + M(1,8)*y.*y + M(1,9)*y.*z + M(1,10)*z.*z + M(1,11)*x.*x.*x + M(1,12)*x.*x.*y + M(1,13)*x.*x.*z + M(1,14)*x.*y.*y + M(1,15)*x.*y.*z + M(1,16)*x.*z.*z + M(1,17)*y.*y.*y + M(1,18)*y.*y.*z + M(1,19)*y.*z.*z + M(1,20)*z.*z.*z + M(1,21)*x.*x.*x.*x + M(1,22)*x.*x.*x.*y + M(1,23)*x.*x.*x.*z + M(1,24)*x.*x.*y.*y + M(1,25)*x.*x.*y.*z + M(1,26)*x.*x.*z.*z + M(1,27)*x.*y.*y.*y + M(1,28)*x.*y.*y.*z + M(1,29)*x.*y.*z.*z + M(1,30)*x.*z.*z.*z + M(1,31)*y.*y.*y.*y + M(1,32)*y.*y.*y.*z + M(1,33)*y.*y.*z.*z + M(1,34)*y.*z.*z.*z + M(1,35)*z.*z.*z.*z; + yy = M(2,1) + M(2,2)*x + M(2,3)*y + M(2,4)*z + M(2,5)*x.*x + M(2,6)*x.*y + M(2,7)*x.*z + M(2,8)*y.*y + M(2,9)*y.*z + M(2,10)*z.*z + M(2,11)*x.*x.*x + M(2,12)*x.*x.*y + M(2,13)*x.*x.*z + M(2,14)*x.*y.*y + M(2,15)*x.*y.*z + M(2,16)*x.*z.*z + M(2,17)*y.*y.*y + M(2,18)*y.*y.*z + M(2,19)*y.*z.*z + M(2,20)*z.*z.*z + M(2,21)*x.*x.*x.*x + M(2,22)*x.*x.*x.*y + M(2,23)*x.*x.*x.*z + M(2,24)*x.*x.*y.*y + M(2,25)*x.*x.*y.*z + M(2,26)*x.*x.*z.*z + M(2,27)*x.*y.*y.*y + M(2,28)*x.*y.*y.*z + M(2,29)*x.*y.*z.*z + M(2,30)*x.*z.*z.*z + M(2,31)*y.*y.*y.*y + M(2,32)*y.*y.*y.*z + M(2,33)*y.*y.*z.*z + M(2,34)*y.*z.*z.*z + M(2,35)*z.*z.*z.*z; + zz = M(3,1) + M(3,2)*x + M(3,3)*y + M(3,4)*z + M(3,5)*x.*x + M(3,6)*x.*y + M(3,7)*x.*z + M(3,8)*y.*y + M(3,9)*y.*z + M(3,10)*z.*z + M(3,11)*x.*x.*x + M(3,12)*x.*x.*y + M(3,13)*x.*x.*z + M(3,14)*x.*y.*y + M(3,15)*x.*y.*z + M(3,16)*x.*z.*z + M(3,17)*y.*y.*y + M(3,18)*y.*y.*z + M(3,19)*y.*z.*z + M(3,20)*z.*z.*z + M(3,21)*x.*x.*x.*x + M(3,22)*x.*x.*x.*y + M(3,23)*x.*x.*x.*z + M(3,24)*x.*x.*y.*y + M(3,25)*x.*x.*y.*z + M(3,26)*x.*x.*z.*z + M(3,27)*x.*y.*y.*y + M(3,28)*x.*y.*y.*z + M(3,29)*x.*y.*z.*z + M(3,30)*x.*z.*z.*z + M(3,31)*y.*y.*y.*y + M(3,32)*y.*y.*y.*z + M(3,33)*y.*y.*z.*z + M(3,34)*y.*z.*z.*z + M(3,35)*z.*z.*z.*z; + elseif s(2)==56 + xx = M(1,1) + M(1,2)*x + M(1,3)*y + M(1,4)*z + M(1,5)*x.*x + M(1,6)*x.*y + M(1,7)*x.*z + M(1,8)*y.*y + M(1,9)*y.*z + M(1,10)*z.*z + M(1,11)*x.*x.*x + M(1,12)*x.*x.*y + M(1,13)*x.*x.*z + M(1,14)*x.*y.*y + M(1,15)*x.*y.*z + M(1,16)*x.*z.*z + M(1,17)*y.*y.*y + M(1,18)*y.*y.*z + M(1,19)*y.*z.*z + M(1,20)*z.*z.*z + M(1,21)*x.*x.*x.*x + M(1,22)*x.*x.*x.*y + M(1,23)*x.*x.*x.*z + M(1,24)*x.*x.*y.*y + M(1,25)*x.*x.*y.*z + M(1,26)*x.*x.*z.*z + M(1,27)*x.*y.*y.*y + M(1,28)*x.*y.*y.*z + M(1,29)*x.*y.*z.*z + M(1,30)*x.*z.*z.*z + M(1,31)*y.*y.*y.*y + M(1,32)*y.*y.*y.*z + M(1,33)*y.*y.*z.*z + M(1,34)*y.*z.*z.*z + M(1,35)*z.*z.*z.*z + M(1,36)*x.*x.*x.*x.*x + M(1,37)*x.*x.*x.*x.*y + M(1,38)*x.*x.*x.*x.*z + M(1,39)*x.*x.*x.*y.*y + M(1,40)*x.*x.*x.*y.*z + M(1,41)*x.*x.*x.*z.*z + M(1,42)*x.*x.*y.*y.*y + M(1,43)*x.*x.*y.*y.*z + M(1,44)*x.*x.*y.*z.*z + M(1,45)*x.*x.*z.*z.*z + M(1,46)*x.*y.*y.*y.*y + M(1,47)*x.*y.*y.*y.*z + M(1,48)*x.*y.*y.*z.*z + M(1,49)*x.*y.*z.*z.*z + M(1,50)*x.*z.*z.*z.*z + M(1,51)*y.*y.*y.*y.*y + M(1,52)*y.*y.*y.*y.*z + M(1,53)*y.*y.*y.*z.*z + M(1,54)*y.*y.*z.*z.*z + M(1,55)*y.*z.*z.*z.*z + M(1,56)*z.*z.*z.*z.*z; + yy = M(2,1) + M(2,2)*x + M(2,3)*y + M(2,4)*z + M(2,5)*x.*x + M(2,6)*x.*y + M(2,7)*x.*z + M(2,8)*y.*y + M(2,9)*y.*z + M(2,10)*z.*z + M(2,11)*x.*x.*x + M(2,12)*x.*x.*y + M(2,13)*x.*x.*z + M(2,14)*x.*y.*y + M(2,15)*x.*y.*z + M(2,16)*x.*z.*z + M(2,17)*y.*y.*y + M(2,18)*y.*y.*z + M(2,19)*y.*z.*z + M(2,20)*z.*z.*z + M(2,21)*x.*x.*x.*x + M(2,22)*x.*x.*x.*y + M(2,23)*x.*x.*x.*z + M(2,24)*x.*x.*y.*y + M(2,25)*x.*x.*y.*z + M(2,26)*x.*x.*z.*z + M(2,27)*x.*y.*y.*y + M(2,28)*x.*y.*y.*z + M(2,29)*x.*y.*z.*z + M(2,30)*x.*z.*z.*z + M(2,31)*y.*y.*y.*y + M(2,32)*y.*y.*y.*z + M(2,33)*y.*y.*z.*z + M(2,34)*y.*z.*z.*z + M(2,35)*z.*z.*z.*z + M(2,36)*x.*x.*x.*x.*x + M(2,37)*x.*x.*x.*x.*y + M(2,38)*x.*x.*x.*x.*z + M(2,39)*x.*x.*x.*y.*y + M(2,40)*x.*x.*x.*y.*z + M(2,41)*x.*x.*x.*z.*z + M(2,42)*x.*x.*y.*y.*y + M(2,43)*x.*x.*y.*y.*z + M(2,44)*x.*x.*y.*z.*z + M(2,45)*x.*x.*z.*z.*z + M(2,46)*x.*y.*y.*y.*y + M(2,47)*x.*y.*y.*y.*z + M(2,48)*x.*y.*y.*z.*z + M(2,49)*x.*y.*z.*z.*z + M(2,50)*x.*z.*z.*z.*z + M(2,51)*y.*y.*y.*y.*y + M(2,52)*y.*y.*y.*y.*z + M(2,53)*y.*y.*y.*z.*z + M(2,54)*y.*y.*z.*z.*z + M(2,55)*y.*z.*z.*z.*z + M(2,56)*z.*z.*z.*z.*z; + zz = M(3,1) + M(3,2)*x + M(3,3)*y + M(3,4)*z + M(3,5)*x.*x + M(3,6)*x.*y + M(3,7)*x.*z + M(3,8)*y.*y + M(3,9)*y.*z + M(3,10)*z.*z + M(3,11)*x.*x.*x + M(3,12)*x.*x.*y + M(3,13)*x.*x.*z + M(3,14)*x.*y.*y + M(3,15)*x.*y.*z + M(3,16)*x.*z.*z + M(3,17)*y.*y.*y + M(3,18)*y.*y.*z + M(3,19)*y.*z.*z + M(3,20)*z.*z.*z + M(3,21)*x.*x.*x.*x + M(3,22)*x.*x.*x.*y + M(3,23)*x.*x.*x.*z + M(3,24)*x.*x.*y.*y + M(3,25)*x.*x.*y.*z + M(3,26)*x.*x.*z.*z + M(3,27)*x.*y.*y.*y + M(3,28)*x.*y.*y.*z + M(3,29)*x.*y.*z.*z + M(3,30)*x.*z.*z.*z + M(3,31)*y.*y.*y.*y + M(3,32)*y.*y.*y.*z + M(3,33)*y.*y.*z.*z + M(3,34)*y.*z.*z.*z + M(3,35)*z.*z.*z.*z + M(3,36)*x.*x.*x.*x.*x + M(3,37)*x.*x.*x.*x.*y + M(3,38)*x.*x.*x.*x.*z + M(3,39)*x.*x.*x.*y.*y + M(3,40)*x.*x.*x.*y.*z + M(3,41)*x.*x.*x.*z.*z + M(3,42)*x.*x.*y.*y.*y + M(3,43)*x.*x.*y.*y.*z + M(3,44)*x.*x.*y.*z.*z + M(3,45)*x.*x.*z.*z.*z + M(3,46)*x.*y.*y.*y.*y + M(3,47)*x.*y.*y.*y.*z + M(3,48)*x.*y.*y.*z.*z + M(3,49)*x.*y.*z.*z.*z + M(3,50)*x.*z.*z.*z.*z + M(3,51)*y.*y.*y.*y.*y + M(3,52)*y.*y.*y.*y.*z + M(3,53)*y.*y.*y.*z.*z + M(3,54)*y.*y.*z.*z.*z + M(3,55)*y.*z.*z.*z.*z + M(3,56)*z.*z.*z.*z.*z; + else + error('invalid size of nonlinear transformation matrix'); + end + + warped = [xx yy zz]; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% linear warping using homogenous coordinate transformation matrix +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +elseif strcmp(method, 'homogenous') | strcmp(method, 'homogeneous') + warped = [input'; ones(1, size(input, 1))]; + warped = M * warped; + warped = warped(1:3,:)'; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% using external function that returns a homogenous transformation matrix +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +elseif exist(method) + input = [input'; ones(1, size(input, 1))]; + H = feval(method, M); + warped = H * input; + warped = warped(1:3,:)'; + +else + error('unrecognized transformation method'); +end + diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/warp_error.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/warp_error.m new file mode 100644 index 0000000000000000000000000000000000000000..e9fbe246140b9dd0a15733fc26032df4a4f0874b --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/warp_error.m @@ -0,0 +1,82 @@ +function [dist] = warp_error(M, input, target, varargin); + +% WARP_ERROR computes the mean distance after linear or non-linear warping +% and can be used as the goalfunction in a 3D warping minimalisation +% +% Use as +% [dist] = warp_error(M, input, target, 'method') +% +% It returns the mean Euclidian distance (residu) when attempting to +% transform the input towards the target using transformation M +% and using the specified warping method. + +% Copyright (C) 2000-2005, Robert Oostenveld +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +% $Log: warp_error.m,v $ +% Revision 1.1 2009/01/30 04:02:13 arno +% *** empty log message *** +% +% Revision 1.4 2006/09/12 15:20:02 roboos +% added support for warping the input points to a triangulated surface +% +% Revision 1.3 2006/04/13 10:50:34 roboos +% renamed calls to warp3d into warp_apply +% +% Revision 1.2 2006/04/13 10:46:09 roboos +% updated the documentation +% +% Revision 1.1 2005/08/15 08:11:20 roboos +% Renamed warpfun into warp_error, which is a better description of +% its use. This is a companion function for warp_optim. +% +% Revision 1.2 2004/05/19 09:57:08 roberto +% added GPL copyright statement, added CVS log item +% + +if ~isempty(M) + % apply the warp to the input positions + input = warp_apply(M, input, varargin{:}); +end + +if isstruct(target) + % project points onto target surface and compute distance between points and surface + % this is done here in one step, but can also be done in seperate steps (see example code below) + el = project_elec(input, target.pnt, target.tri); + dist = mean(el(:,4)); + % the following example code is more elaborate, and can be used for detailled testing + if 0 + Npnt = size(input,1); + prj = zeros(Npnt, 3); + % step 1: project each input point onto the triangulated surface + el = project_elec(input, target.pnt, target.tri); + % step 2: compute the projected point on the triangulated surface + for i=1:Npnt + v1 = target.pnt(target.tri(el(i,1),1),:); % position of vertex 1 + v2 = target.pnt(target.tri(el(i,1),2),:); % position of vertex 2 + v3 = target.pnt(target.tri(el(i,1),3),:); % position of vertex 3 + prj(i,:) = routlm(v1, v2, v3, el(i,2), el(i,3)); + end + % step 3: compute the distance + dif = input - prj; + dist = mean(sqrt(sum(dif' .^2))); + end +else + % compute distance between input points and target points + dif = input - target; + dist = mean(sqrt(sum(dif' .^2))); +end + diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/warp_optim.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/warp_optim.m new file mode 100644 index 0000000000000000000000000000000000000000..e294cb1e2ea53f7b77540891e24515d7ff2d6e63 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/private/warp_optim.m @@ -0,0 +1,207 @@ +function [result, M] = warp_pnt(input, target, method); + +% WARP_PNT determine intermediate positions using warping (deformation) +% the input cloud of points is warped to match the target. +% The strategy is to start with simpelest linear warp, followed by a more +% elaborate linear warp, which then is followed by the nonlinear warps up +% to the desired order. +% +% [result, M] = warp_pnt(input, target, method) +% input contains the Nx3 measured 3D positions +% target contains the Nx3 template 3D positions +% method should be empty or any of 'nonlin1', 'nonlin2' ... 'nonlin5' +% +% The default is a traditional linear warp with rescaling in each +% dimension. Optionally you can select a nonlinear warp of the 1st (affine) +% up to the 5th order. +% +% This function depends on the OPTIM and WARPING toolboxes. + +% Copyright (C) 2000-2005, Robert Oostenveld +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +% $Log: warp_optim.m,v $ +% Revision 1.1 2009/01/30 04:02:13 arno +% *** empty log message *** +% +% Revision 1.7 2006/11/23 11:34:51 roboos +% use optimization toolbox if possible, othewise use the standard fminsearch function +% +% Revision 1.6 2006/09/13 09:55:58 roboos +% fixed bug (typo) in rigidbody +% +% Revision 1.5 2006/04/13 12:55:45 roboos +% added a str2func to solve a problem with feval and private +% +% Revision 1.4 2006/04/13 10:50:34 roboos +% renamed calls to warp3d into warp_apply +% +% Revision 1.3 2006/04/13 10:47:39 roboos +% renamed all calls to warpfun into warp_error +% +% Revision 1.2 2006/04/13 10:38:24 roboos +% fixed a problem due to find/strmatch +% +% Revision 1.1 2005/08/15 08:12:40 roboos +% Renamed warp_pnt into warp_optim for consistency with other functions. +% Also changed the code, the subsequent ordering of the simple to +% more complex warps is handled more clean. +% +% Revision 1.4 2005/03/21 15:43:42 roboos +% fixed bug in output for nonlinear warping +% added support for rigidbody or globalrescale warp +% +% Revision 1.3 2004/05/19 09:57:08 roberto +% added GPL copyright statement, added CVS log item +% + +global fb; + +if nargin<3 + method='traditional'; +end + +pos1 = input; +pos2 = target; + +% The warp_error function might be located in the private subdirectory fo +% fieldtrip, i.e. only available to functions in the fieldtrip toolbox. +% The following line ensures that the function can also be found by the +% feval that is executed by the optimalization toolbox. +warp_error = str2func('warp_error'); + +% set the options for the minimalisation routine +if exist('fminunc') + % use the optimization toolbox + optimfun = @fminunc; + options = optimset('fminunc'); + options = optimset(options, 'Display', 'off'); + options = optimset(options, 'MaxIter', 1500); + % options = optimset(options, 'MaxFunEvals', '1000*numberOfVariables'); + options = optimset(options, 'TolFun', 1e-4); + options = optimset(options, 'LargeScale', 'off'); +else + % use a standard matlab function, this function converges slower + optimfun = @fminsearch; + options = optimset('fminsearch'); + options = optimset(options, 'Display', 'off'); + options = optimset(options, 'MaxIter', 4500); +end + +if fb; fprintf('distance = %f\n', warp_error([0 0 0 0 0 0], pos1, pos2, 'rigidbody')); end + +% the warp is done in steps, starting simple and progressively getting more complex +level = find(strcmp(method, { + 'rigidbody' % 1 + 'globalrescale' % 2 + 'traditional' % 3 + 'nonlin1' % 4 + 'nonlin2' % 5 + 'nonlin3' % 6 + 'nonlin4' % 7 + 'nonlin5' % 8 + })); + +if isempty(method) + error('incorrect warping method specified'); +end + +if level>=1 + % do a rigid-body transformation (6 parameters) + if fb; disp('rigidbody...'); end + ri = [0 0 0 0 0 0]; + rf = optimfun(warp_error, ri, options, pos1, pos2, 'rigidbody'); + if fb; fprintf('distance = %f\n', warp_error(rf, pos1, pos2, 'rigidbody')); end +end + +if level>=2 + % do a rigid-body + global rescaling transformation (7 parameters) + if fb; disp('rigidbody + global rescaling...'); end + gi = [rf 1]; + gf = optimfun(warp_error, gi, options, pos1, pos2, 'globalrescale'); + if fb; fprintf('distance = %f\n', warp_error(gf, pos1, pos2, 'globalrescale')); end +end + +if level>=3 + % do a rigid-body + individual rescaling transformation (9 parameters) + if fb; disp('rigidbody + individual rescaling...'); end + ti = [gf gf(7) gf(7)]; + tf = optimfun(warp_error, ti, options, pos1, pos2, 'traditional'); + if fb; fprintf('distance = %f\n', warp_error(tf, pos1, pos2, 'traditional')); end +end + +if level>=4 + % do a first order nonlinear transformation, + if fb; disp('1st order nonlinear...'); end + e1i = traditional(tf); + e1i = [e1i(1:3,4) e1i(1:3,1:3)]; % reshuffle from homogenous into nonlinear + e1f = optimfun(warp_error, e1i, options, pos1, pos2); + if fb; fprintf('distance = %f\n', warp_error(e1f, pos1, pos2, 'nonlinear')); end +end + +if level>=5 + % do a second order nonlinear transformation, + if fb; disp('2nd order nonlinear...'); end + e2i = [e1f zeros(3,6)]; + e2f = optimfun(warp_error, e2i, options, pos1, pos2); + if fb; fprintf('distance = %f\n', warp_error(e2f, pos1, pos2, 'nonlinear')); end +end + +if level>=6 + % do a third order nonlinear transformation, + if fb; disp('3rd order nonlinear...'); end + e3i = [e2f zeros(3,10)]; + e3f = optimfun(warp_error, e3i, options, pos1, pos2); + if fb; fprintf('distance = %f\n', warp_error(e3f, pos1, pos2, 'nonlinear')); end +end + +if level>=7 + % do a fourth order nonlinear transformation, + if fb; disp('4th order nonlinear...'); end + e4i = [e3f zeros(3,10)]; + e4f = optimfun(warp_error, e4i, options, pos1, pos2); + if fb; fprintf('distance = %f\n', warp_error(e4f, pos1, pos2, 'nonlinear')); end +end + +if level>=8 + % do a fifth order nonlinear transformation, + if fb; disp('5th order nonlinear...'); end + e5i = [e4f zeros(3,10)]; + e5f = optimfun(warp_error, e5i, options, pos1, pos2); + if fb; fprintf('distance = %f\n', warp_error(e5f, pos1, pos2, 'nonlinear')); end +end + +% return the estimated parameters of the highest level warp +% and compute the warped points +switch level + case 1 + M = rf; + case 2 + M = gf; + case 3 + M = tf; + case 4 + M = e1f; + case 5 + M = e2f; + case 6 + M = e3f; + case 7 + M = e4f; + case 8 + M = e5f; +end +result = warp_apply(M, input, method); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/sph2spm.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/sph2spm.m new file mode 100644 index 0000000000000000000000000000000000000000..72d37e2f406132c5c418d515463b19d1b5a4c26d --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/sph2spm.m @@ -0,0 +1,90 @@ +% sph2spm() - compute homogenous transformation matrix from +% BESA spherical coordinates to SPM 3-D coordinate +% +% Usage: +% >> trans = sph2spm; +% +% Outputs: +% trans - homogenous transformation matrix +% +% Note: head radius for spherical model is assumed to be 85 mm. +% +% Author: Robert Oostenveld, SMI/FCDC, Nijmegen 2005 +% Arnaud Delorme, SCCN, La Jolla 2005 + +% SMI, University Aalborg, Denmark http://www.smi.auc.dk/ +% FC Donders Centre, University Nijmegen, the Netherlands http://www.fcdonders.kun.nl/ + +% Copyright (C) 2003 Robert Oostenveld, SMI/FCDC roberto@smi.auc.dk +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function besa2SPM_result = besa2SPM; + +if 0 + % original transformation: problem occipital part of the haed did not + % fit + + % NAS, Left EAR, Right EAR coordinates in BESA + besa_NAS = [0.0000 0.0913 -0.0407]; + besa_LPA = [-0.0865 0.0000 -0.0500]; + besa_RPA = [0.0865 0.0000 -0.0500]; + + % NAS, Left EAR, Right EAR coordinates in SPM average + SPM_NAS = [0 84 -48]; + SPM_LPA = [-82 -32 -54]; + SPM_RPA = [82 -32 -54]; + + % transformation to CTF coordinate system + % --------------------------------------- + SPM2common = headcoordinates(SPM_NAS , SPM_LPA , SPM_RPA, 0); + besa2common = headcoordinates(besa_NAS, besa_LPA, besa_RPA, 0); + + nazcommon1 = besa2common * [ besa_NAS 1]'; + nazcommon2 = SPM2common * [ SPM_NAS 1]'; + ratiox = nazcommon1(1)/nazcommon2(1); + + lpacommon1 = besa2common * [ besa_LPA 1]'; + lpacommon2 = SPM2common * [ SPM_LPA 1]'; + ratioy = lpacommon1(2)/lpacommon2(2); + + scaling = eye(4); + scaling(1,1) = 1/ratiox; + scaling(2,2) = 1/ratioy; + scaling(3,3) = mean([ 1/ratioy 1/ratiox]); + + besa2SPM_result = inv(SPM2common) * scaling * besa2common; +end; + +if 0 + % using electrodenormalize to fit standard BESA electrode (haed radius + % has to be 85) to BEM electrodes + % problem: fit not optimal for temporal electrodes + + % traditional takes as input the .m field returned in the output from + % electrodenormalize + besa2SPM_result = traditionaldipfit([0.5588 -14.5541 1.8045 0.0004 0.0000 -1.5623 1.1889 1.0736 132.6198]) +end; + +% adapted manualy from above for temporal electrodes (see factor 0.94 +% instead of 1.1889 and x shift of -18.0041 instead of -14.5541) +%traditionaldipfit([0.5588 -18.0041 1.8045 0.0004 0.0000 -1.5623 1.1889 0.94 132.6198]) + +besa2SPM_result = [ + 0.0101 -0.9400 0 0.5588 + 1.1889 0.0080 0.0530 -18.0041 + -0.0005 -0.0000 1.1268 1.8045 + 0 0 0 1.0000 + ]; diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/elec/standard_1005.elc b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/elec/standard_1005.elc new file mode 100644 index 0000000000000000000000000000000000000000..4e695328b358db671ae94329ccaa42f44b80b773 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/elec/standard_1005.elc @@ -0,0 +1,698 @@ +# ASA electrode file +ReferenceLabel avg +UnitPosition mm +NumberPositions= 346 +Positions +-86.0761 -19.9897 -47.9860 +85.7939 -20.0093 -48.0310 +0.0083 86.8110 -39.9830 +-29.4367 83.9171 -6.9900 +0.1123 88.2470 -1.7130 +29.8723 84.8959 -7.0800 +-48.9708 64.0872 -47.6830 +-54.8397 68.5722 -10.5900 +-45.4307 72.8622 5.9780 +-33.7007 76.8371 21.2270 +-18.4717 79.9041 32.7520 +0.2313 80.7710 35.4170 +19.8203 80.3019 32.7640 +35.7123 77.7259 21.9560 +46.5843 73.8078 6.0340 +55.7433 69.6568 -10.7550 +50.4352 63.8698 -48.0050 +-70.1019 41.6523 -49.9520 +-70.2629 42.4743 -11.4200 +-64.4658 48.0353 16.9210 +-50.2438 53.1112 42.1920 +-27.4958 56.9311 60.3420 +0.3122 58.5120 66.4620 +29.5142 57.6019 59.5400 +51.8362 54.3048 40.8140 +67.9142 49.8297 16.3670 +73.0431 44.4217 -12.0000 +72.1141 42.0667 -50.4520 +-84.0759 14.5673 -50.4290 +-80.7750 14.1203 -11.1350 +-77.2149 18.6433 24.4600 +-60.1819 22.7162 55.5440 +-34.0619 26.0111 79.9870 +0.3761 27.3900 88.6680 +34.7841 26.4379 78.8080 +62.2931 23.7228 55.6300 +79.5341 19.9357 24.4380 +81.8151 15.4167 -11.3300 +84.1131 14.3647 -50.5380 +-85.8941 -15.8287 -48.2830 +-84.1611 -16.0187 -9.3460 +-80.2801 -13.7597 29.1600 +-65.3581 -11.6317 64.3580 +-36.1580 -9.9839 89.7520 +0.4009 -9.1670 100.2440 +37.6720 -9.6241 88.4120 +67.1179 -10.9003 63.5800 +83.4559 -12.7763 29.2080 +85.0799 -15.0203 -9.4900 +85.5599 -16.3613 -48.2710 +-85.6192 -46.5147 -45.7070 +-84.8302 -46.0217 -7.0560 +-79.5922 -46.5507 30.9490 +-63.5562 -47.0088 65.6240 +-35.5131 -47.2919 91.3150 +0.3858 -47.3180 99.4320 +38.3838 -47.0731 90.6950 +66.6118 -46.6372 65.5800 +83.3218 -46.1013 31.2060 +85.5488 -45.5453 -7.1300 +86.1618 -47.0353 -45.8690 +-73.0093 -73.7657 -40.9980 +-72.4343 -73.4527 -2.4870 +-67.2723 -76.2907 28.3820 +-53.0073 -78.7878 55.9400 +-28.6203 -80.5249 75.4360 +0.3247 -81.1150 82.6150 +31.9197 -80.4871 76.7160 +55.6667 -78.5602 56.5610 +67.8877 -75.9043 28.0910 +73.0557 -73.0683 -2.5400 +73.8947 -74.3903 -41.2200 +-54.9104 -98.0448 -35.4650 +-54.8404 -97.5279 2.7920 +-48.4244 -99.3408 21.5990 +-36.5114 -100.8529 37.1670 +-18.9724 -101.7680 46.5360 +0.2156 -102.1780 50.6080 +19.8776 -101.7930 46.3930 +36.7816 -100.8491 36.3970 +49.8196 -99.4461 21.7270 +55.6666 -97.6251 2.7300 +54.9876 -98.0911 -35.5410 +-29.4134 -112.4490 8.8390 +0.1076 -114.8920 14.6570 +29.8426 -112.1560 8.8000 +-29.8184 -114.5700 -29.2160 +0.0045 -118.5650 -23.0780 +29.7416 -114.2600 -29.2560 +-43.2897 75.8552 -28.2440 +-38.5517 79.9532 -4.9950 +-27.9857 82.4591 2.7020 +-17.1947 84.8491 10.0270 +-5.9317 86.8780 16.2000 +7.1053 87.0740 16.4690 +18.9233 85.5969 11.4430 +28.6443 82.9759 2.8280 +39.3203 80.6868 -4.7250 +43.8223 76.5418 -28.3070 +-63.2538 53.8573 -30.3160 +-61.3508 58.7992 0.8970 +-50.7998 64.0412 23.0890 +-34.3157 68.3931 41.1880 +-11.4357 70.7561 50.3480 +13.4793 71.2010 51.1750 +36.1833 69.1509 41.2540 +52.3972 65.0708 22.8620 +62.9152 60.0448 0.6300 +64.3342 54.5998 -30.4440 +-79.0669 28.0813 -31.2530 +-74.4999 31.3003 4.8460 +-65.2379 36.4282 36.1440 +-44.4098 40.7622 61.6900 +-15.4238 43.6600 77.6820 +17.5922 44.0540 77.7880 +45.8532 41.6228 60.6470 +67.1281 37.7998 35.2960 +78.0531 32.9817 4.4830 +80.0971 28.5137 -31.3380 +-84.1250 -1.8467 -29.7940 +-82.3550 0.8263 8.5790 +-74.6920 4.3033 45.3070 +-51.0509 7.1772 74.3770 +-18.2190 9.0941 92.5290 +18.7870 9.2479 91.5620 +51.8851 7.7978 73.5070 +77.0020 5.3357 45.3500 +83.8880 1.9457 8.5010 +84.1230 -1.8083 -29.6380 +-86.9731 -32.2157 -27.8480 +-85.5651 -30.6287 11.1530 +-76.4071 -29.7307 49.2170 +-52.9281 -28.9058 80.3040 +-18.3541 -28.3219 98.2200 +20.2199 -28.1481 98.1720 +55.1139 -28.3862 80.4740 +79.0059 -28.9863 49.6280 +85.9999 -29.8203 11.2480 +88.6249 -32.2723 -28.0000 +-78.1602 -60.7567 -23.8240 +-76.6802 -60.8317 12.8800 +-68.1152 -62.9747 47.2520 +-46.9142 -64.6908 75.2960 +-15.8202 -65.5999 91.1640 +19.4198 -65.5950 92.4050 +50.6738 -64.4822 76.1300 +71.0958 -62.6243 47.3280 +78.5198 -60.4323 12.9020 +78.9027 -60.9553 -23.8050 +-64.5973 -87.6558 -19.0140 +-62.9593 -87.5028 12.9520 +-54.0103 -89.8988 37.3320 +-35.8874 -91.6669 55.5040 +-12.0474 -92.6069 65.5080 +13.9226 -92.6940 66.9580 +37.7986 -91.6291 56.7330 +54.6087 -89.6402 37.0350 +63.1117 -87.2282 12.8560 +65.0137 -87.8062 -18.9520 +-42.8624 -108.0730 -13.1510 +-40.1204 -107.1290 12.0610 +-31.9514 -108.2520 23.0470 +-19.8624 -108.9420 29.7600 +-6.9194 -109.2600 32.7100 +6.8036 -109.1630 31.5820 +20.2936 -108.9140 28.9440 +32.1756 -108.2520 22.2550 +41.0976 -107.2450 12.1380 +43.8946 -109.1270 -13.1700 +-14.8504 -117.9870 -6.9200 +15.0946 -118.0180 -6.9330 +-14.8107 87.2351 -4.4770 +15.1623 88.0910 -4.5510 +-54.8298 66.4132 -29.7040 +-51.1757 70.8362 -1.7550 +-39.6407 74.8671 13.6780 +-27.2187 78.7091 28.3750 +-9.1977 80.6051 35.1330 +10.4823 80.8650 35.3590 +28.5803 79.3029 28.4700 +40.9403 75.7399 13.8600 +52.0293 71.8468 -1.9200 +55.7542 67.1698 -29.8240 +-71.5079 41.1193 -30.8540 +-68.5558 45.2843 3.0020 +-58.4878 50.6722 30.1920 +-39.9798 55.2601 52.6000 +-13.3838 57.9021 64.3320 +15.8342 58.4559 64.9920 +41.7942 56.2259 51.4990 +60.0522 52.0858 28.7080 +71.9592 47.1917 2.4750 +72.7981 41.8218 -31.0260 +-82.9559 13.3203 -30.8080 +-80.1139 16.3903 6.8500 +-71.2099 20.8203 41.3240 +-48.5119 24.5292 69.1360 +-17.3439 27.0241 86.9230 +18.4181 27.2709 86.4370 +49.5481 25.2378 68.4300 +73.2191 22.0067 41.2970 +81.5801 17.6837 6.5640 +83.3711 13.5477 -30.7490 +-85.1321 -17.0557 -28.7310 +-82.9461 -14.8827 10.0090 +-75.2941 -12.6397 47.9040 +-51.5811 -10.7548 78.0350 +-18.2790 -9.4319 97.3560 +19.6780 -9.3041 95.7060 +53.8059 -10.1442 77.7300 +78.1249 -11.7353 47.8400 +85.1369 -13.9063 9.8900 +86.0999 -17.0883 -28.7560 +-84.8102 -47.2457 -26.2200 +-82.7042 -46.2977 11.9740 +-73.3012 -46.7917 49.1090 +-51.0492 -47.1758 80.0160 +-17.3542 -47.3419 97.4100 +20.6798 -47.2321 98.0720 +53.9968 -46.8902 80.0770 +76.5498 -46.3733 49.1400 +85.1998 -45.8073 12.1020 +85.4428 -47.2213 -26.1760 +-72.1773 -74.6277 -21.5360 +-70.1133 -74.8677 12.9990 +-61.7283 -77.6238 43.0280 +-41.6733 -79.7528 66.7150 +-13.9613 -81.0029 81.0030 +17.2977 -80.9810 81.6410 +44.7477 -79.6111 67.6550 +63.6267 -77.3022 43.1190 +72.1037 -74.4993 13.0250 +73.2817 -75.0773 -21.5760 +-54.7754 -98.9768 -16.1930 +-51.9284 -98.4438 12.3040 +-43.3424 -100.1629 30.0090 +-28.0074 -101.3610 42.3790 +-9.5034 -102.0600 49.4180 +10.2356 -102.0290 48.9420 +28.6476 -101.3901 42.1380 +44.2206 -100.2191 29.8080 +52.8386 -98.5360 12.2500 +55.8596 -99.8940 -16.2080 +-14.8054 -115.1000 11.8290 +15.1456 -115.1910 11.8330 +-15.1584 -118.2420 -26.0480 +15.1286 -118.1510 -26.0810 +-36.1247 72.3801 -45.8520 +-43.5117 78.5802 -9.2400 +-33.2847 81.2071 -1.1400 +-22.3517 83.5621 6.0710 +-12.2417 86.1941 14.1880 +0.1703 87.3220 17.4420 +13.6223 86.7579 15.3020 +24.1013 84.3769 7.4330 +33.9133 81.8119 -1.0350 +43.9483 79.2958 -9.3000 +37.7123 72.1679 -46.1970 +-59.3398 52.6802 -48.7700 +-63.2618 55.9922 -11.1730 +-55.8198 61.3962 11.8840 +-43.3817 66.3672 32.8110 +-23.5817 69.9171 47.2930 +0.2763 71.2800 52.0920 +25.5583 70.5559 47.8270 +45.1522 67.2748 32.7310 +58.0002 62.5998 11.9000 +64.6732 57.2738 -11.4600 +60.6012 52.2668 -49.0380 +-78.4839 28.7703 -50.5220 +-76.6149 28.6533 -11.5080 +-71.5059 33.9263 20.9930 +-55.9399 38.7162 49.7880 +-30.6548 42.4151 71.0400 +0.3512 44.0740 79.1410 +32.6451 43.1009 70.7950 +57.5042 39.8518 48.8110 +74.2501 35.4997 20.3800 +79.0341 30.3437 -11.9970 +79.9201 28.9417 -50.9140 +-87.3620 -0.5147 -49.8370 +-82.6680 -0.9417 -10.2840 +-80.1330 2.5853 27.3120 +-64.1610 5.8313 60.8850 +-35.7490 8.3091 85.4590 +0.3911 9.5080 95.5600 +36.0700 8.6519 83.8320 +65.1640 6.6198 60.0520 +81.5440 3.6637 27.2010 +83.1680 0.1817 -10.3640 +85.3930 -0.9523 -49.5200 +-86.6321 -31.2377 -47.1780 +-85.9331 -31.0927 -8.4740 +-81.5431 -30.1727 30.2730 +-66.1281 -29.2957 65.8980 +-36.9301 -28.5699 91.7340 +0.3959 -28.1630 101.2690 +38.5399 -28.2251 90.9760 +68.8539 -28.6403 66.4100 +84.5529 -29.3783 30.8780 +85.9999 -30.2803 -8.4350 +86.7619 -31.7313 -47.2530 +-80.7152 -60.6457 -43.5940 +-78.5992 -59.7237 -4.7580 +-73.6642 -61.9227 30.3800 +-59.4112 -63.9248 62.6720 +-32.7283 -65.3199 85.9440 +0.3658 -65.7500 94.0580 +35.8918 -65.1381 85.9800 +62.2558 -63.6152 62.7190 +76.6708 -61.5483 30.5430 +79.3188 -59.3033 -4.8400 +81.5598 -61.2153 -43.8000 +-64.5703 -86.4318 -38.3240 +-64.5833 -86.2218 0.0330 +-58.7123 -88.7048 25.1930 +-46.1603 -90.8878 47.4460 +-24.6483 -92.2919 62.0760 +0.2727 -92.7580 67.3420 +26.4367 -92.2951 63.1990 +47.1437 -90.7122 47.6780 +60.8127 -88.5042 25.6620 +65.1517 -85.9432 -0.0090 +65.0377 -86.7182 -38.4480 +-43.1284 -107.5160 -32.3870 +-42.9764 -106.4930 5.7730 +-36.2344 -107.7160 17.7500 +-25.9844 -108.6160 26.5440 +-13.6644 -109.2660 32.8560 +0.1676 -109.2760 32.7900 +13.6506 -109.1060 30.9360 +26.6636 -108.6680 26.4150 +37.7006 -107.8400 18.0690 +43.6696 -106.5990 5.7260 +43.1766 -107.4440 -32.4630 +-29.3914 -114.5110 -10.0200 +0.0525 -119.3430 -3.9360 +29.5526 -113.6360 -10.0510 +-84.1611 -16.0187 -9.3460 +-72.4343 -73.4527 -2.4870 +85.0799 -15.0203 -9.4900 +73.0557 -73.0683 -2.5400 +-86.0761 -44.9897 -67.9860 + 85.7939 -45.0093 -68.0310 +-86.0761 -24.9897 -67.9860 + 85.7939 -25.0093 -68.0310 +Labels +LPA +RPA +Nz +Fp1 +Fpz +Fp2 +AF9 +AF7 +AF5 +AF3 +AF1 +AFz +AF2 +AF4 +AF6 +AF8 +AF10 +F9 +F7 +F5 +F3 +F1 +Fz +F2 +F4 +F6 +F8 +F10 +FT9 +FT7 +FC5 +FC3 +FC1 +FCz +FC2 +FC4 +FC6 +FT8 +FT10 +T9 +T7 +C5 +C3 +C1 +Cz +C2 +C4 +C6 +T8 +T10 +TP9 +TP7 +CP5 +CP3 +CP1 +CPz +CP2 +CP4 +CP6 +TP8 +TP10 +P9 +P7 +P5 +P3 +P1 +Pz +P2 +P4 +P6 +P8 +P10 +PO9 +PO7 +PO5 +PO3 +PO1 +POz +PO2 +PO4 +PO6 +PO8 +PO10 +O1 +Oz +O2 +I1 +Iz +I2 +AFp9h +AFp7h +AFp5h +AFp3h +AFp1h +AFp2h +AFp4h +AFp6h +AFp8h +AFp10h +AFF9h +AFF7h +AFF5h +AFF3h +AFF1h +AFF2h +AFF4h +AFF6h +AFF8h +AFF10h +FFT9h +FFT7h +FFC5h +FFC3h +FFC1h +FFC2h +FFC4h +FFC6h +FFT8h +FFT10h +FTT9h +FTT7h +FCC5h +FCC3h +FCC1h +FCC2h +FCC4h +FCC6h +FTT8h +FTT10h +TTP9h +TTP7h +CCP5h +CCP3h +CCP1h +CCP2h +CCP4h +CCP6h +TTP8h +TTP10h +TPP9h +TPP7h +CPP5h +CPP3h +CPP1h +CPP2h +CPP4h +CPP6h +TPP8h +TPP10h +PPO9h +PPO7h +PPO5h +PPO3h +PPO1h +PPO2h +PPO4h +PPO6h +PPO8h +PPO10h +POO9h +POO7h +POO5h +POO3h +POO1h +POO2h +POO4h +POO6h +POO8h +POO10h +OI1h +OI2h +Fp1h +Fp2h +AF9h +AF7h +AF5h +AF3h +AF1h +AF2h +AF4h +AF6h +AF8h +AF10h +F9h +F7h +F5h +F3h +F1h +F2h +F4h +F6h +F8h +F10h +FT9h +FT7h +FC5h +FC3h +FC1h +FC2h +FC4h +FC6h +FT8h +FT10h +T9h +T7h +C5h +C3h +C1h +C2h +C4h +C6h +T8h +T10h +TP9h +TP7h +CP5h +CP3h +CP1h +CP2h +CP4h +CP6h +TP8h +TP10h +P9h +P7h +P5h +P3h +P1h +P2h +P4h +P6h +P8h +P10h +PO9h +PO7h +PO5h +PO3h +PO1h +PO2h +PO4h +PO6h +PO8h +PO10h +O1h +O2h +I1h +I2h +AFp9 +AFp7 +AFp5 +AFp3 +AFp1 +AFpz +AFp2 +AFp4 +AFp6 +AFp8 +AFp10 +AFF9 +AFF7 +AFF5 +AFF3 +AFF1 +AFFz +AFF2 +AFF4 +AFF6 +AFF8 +AFF10 +FFT9 +FFT7 +FFC5 +FFC3 +FFC1 +FFCz +FFC2 +FFC4 +FFC6 +FFT8 +FFT10 +FTT9 +FTT7 +FCC5 +FCC3 +FCC1 +FCCz +FCC2 +FCC4 +FCC6 +FTT8 +FTT10 +TTP9 +TTP7 +CCP5 +CCP3 +CCP1 +CCPz +CCP2 +CCP4 +CCP6 +TTP8 +TTP10 +TPP9 +TPP7 +CPP5 +CPP3 +CPP1 +CPPz +CPP2 +CPP4 +CPP6 +TPP8 +TPP10 +PPO9 +PPO7 +PPO5 +PPO3 +PPO1 +PPOz +PPO2 +PPO4 +PPO6 +PPO8 +PPO10 +POO9 +POO7 +POO5 +POO3 +POO1 +POOz +POO2 +POO4 +POO6 +POO8 +POO10 +OI1 +OIz +OI2 +T3 +T5 +T4 +T6 +M1 +M2 +A1 +A2 diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/elec/standard_1020.elc b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/elec/standard_1020.elc new file mode 100644 index 0000000000000000000000000000000000000000..2f68b5147ee5deae20525cf9754f7941dda95a75 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/elec/standard_1020.elc @@ -0,0 +1,200 @@ +# ASA electrode file +ReferenceLabel avg +UnitPosition mm +NumberPositions= 97 +Positions +-86.0761 -19.9897 -47.9860 +85.7939 -20.0093 -48.0310 +0.0083 86.8110 -39.9830 +-29.4367 83.9171 -6.9900 +0.1123 88.2470 -1.7130 +29.8723 84.8959 -7.0800 +-48.9708 64.0872 -47.6830 +-54.8397 68.5722 -10.5900 +-45.4307 72.8622 5.9780 +-33.7007 76.8371 21.2270 +-18.4717 79.9041 32.7520 +0.2313 80.7710 35.4170 +19.8203 80.3019 32.7640 +35.7123 77.7259 21.9560 +46.5843 73.8078 6.0340 +55.7433 69.6568 -10.7550 +50.4352 63.8698 -48.0050 +-70.1019 41.6523 -49.9520 +-70.2629 42.4743 -11.4200 +-64.4658 48.0353 16.9210 +-50.2438 53.1112 42.1920 +-27.4958 56.9311 60.3420 +0.3122 58.5120 66.4620 +29.5142 57.6019 59.5400 +51.8362 54.3048 40.8140 +67.9142 49.8297 16.3670 +73.0431 44.4217 -12.0000 +72.1141 42.0667 -50.4520 +-84.0759 14.5673 -50.4290 +-80.7750 14.1203 -11.1350 +-77.2149 18.6433 24.4600 +-60.1819 22.7162 55.5440 +-34.0619 26.0111 79.9870 +0.3761 27.3900 88.6680 +34.7841 26.4379 78.8080 +62.2931 23.7228 55.6300 +79.5341 19.9357 24.4380 +81.8151 15.4167 -11.3300 +84.1131 14.3647 -50.5380 +-85.8941 -15.8287 -48.2830 +-84.1611 -16.0187 -9.3460 +-80.2801 -13.7597 29.1600 +-65.3581 -11.6317 64.3580 +-36.1580 -9.9839 89.7520 +0.4009 -9.1670 100.2440 +37.6720 -9.6241 88.4120 +67.1179 -10.9003 63.5800 +83.4559 -12.7763 29.2080 +85.0799 -15.0203 -9.4900 +85.5599 -16.3613 -48.2710 +-85.6192 -46.5147 -45.7070 +-84.8302 -46.0217 -7.0560 +-79.5922 -46.5507 30.9490 +-63.5562 -47.0088 65.6240 +-35.5131 -47.2919 91.3150 +0.3858 -47.3180 99.4320 +38.3838 -47.0731 90.6950 +66.6118 -46.6372 65.5800 +83.3218 -46.1013 31.2060 +85.5488 -45.5453 -7.1300 +86.1618 -47.0353 -45.8690 +-73.0093 -73.7657 -40.9980 +-72.4343 -73.4527 -2.4870 +-67.2723 -76.2907 28.3820 +-53.0073 -78.7878 55.9400 +-28.6203 -80.5249 75.4360 +0.3247 -81.1150 82.6150 +31.9197 -80.4871 76.7160 +55.6667 -78.5602 56.5610 +67.8877 -75.9043 28.0910 +73.0557 -73.0683 -2.5400 +73.8947 -74.3903 -41.2200 +-54.9104 -98.0448 -35.4650 +-54.8404 -97.5279 2.7920 +-48.4244 -99.3408 21.5990 +-36.5114 -100.8529 37.1670 +-18.9724 -101.7680 46.5360 +0.2156 -102.1780 50.6080 +19.8776 -101.7930 46.3930 +36.7816 -100.8491 36.3970 +49.8196 -99.4461 21.7270 +55.6666 -97.6251 2.7300 +54.9876 -98.0911 -35.5410 +-29.4134 -112.4490 8.8390 +0.1076 -114.8920 14.6570 +29.8426 -112.1560 8.8000 +-29.8184 -114.5700 -29.2160 +0.0045 -118.5650 -23.0780 +29.7416 -114.2600 -29.2560 +-84.1611 -16.0187 -9.3460 +-72.4343 -73.4527 -2.4870 +85.0799 -15.0203 -9.4900 +73.0557 -73.0683 -2.5400 +-86.0761 -44.9897 -67.9860 + 85.7939 -45.0093 -68.0310 +-86.0761 -24.9897 -67.9860 + 85.7939 -25.0093 -68.0310 +Labels +LPA +RPA +Nz +Fp1 +Fpz +Fp2 +AF9 +AF7 +AF5 +AF3 +AF1 +AFz +AF2 +AF4 +AF6 +AF8 +AF10 +F9 +F7 +F5 +F3 +F1 +Fz +F2 +F4 +F6 +F8 +F10 +FT9 +FT7 +FC5 +FC3 +FC1 +FCz +FC2 +FC4 +FC6 +FT8 +FT10 +T9 +T7 +C5 +C3 +C1 +Cz +C2 +C4 +C6 +T8 +T10 +TP9 +TP7 +CP5 +CP3 +CP1 +CPz +CP2 +CP4 +CP6 +TP8 +TP10 +P9 +P7 +P5 +P3 +P1 +Pz +P2 +P4 +P6 +P8 +P10 +PO9 +PO7 +PO5 +PO3 +PO1 +POz +PO2 +PO4 +PO6 +PO8 +PO10 +O1 +Oz +O2 +O9 +Iz +O10 +T3 +T5 +T4 +T6 +M1 +M2 +A1 +A2 diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/elec/standard_alphabetic.elc b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/elec/standard_alphabetic.elc new file mode 100644 index 0000000000000000000000000000000000000000..55367e427fbb219bc37cb0c18165d91af23ca511 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/elec/standard_alphabetic.elc @@ -0,0 +1,142 @@ +# ASA electrode file +ReferenceLabel avg +UnitPosition mm +NumberPositions= 68 +Positions +-86.0761 -19.9897 -47.9860 +85.7939 -20.0093 -48.0310 +0.0083 86.8110 -39.9830 +-29.4367 83.9171 -6.9900 +0.1123 88.2470 -1.7130 +29.8723 84.8959 -7.0800 +-54.8397 68.5722 -10.5900 +-33.7007 76.8371 21.2270 +0.2313 80.7710 35.4170 +35.7123 77.7259 21.9560 +55.7433 69.6568 -10.7550 +-70.2629 42.4743 -11.4200 +-64.4658 48.0353 16.9210 +-50.2438 53.1112 42.1920 +-27.4958 56.9311 60.3420 +0.3122 58.5120 66.4620 +29.5142 57.6019 59.5400 +51.8362 54.3048 40.8140 +67.9142 49.8297 16.3670 +73.0431 44.4217 -12.0000 +-80.7750 14.1203 -11.1350 +-77.2149 18.6433 24.4600 +-60.1819 22.7162 55.5440 +-34.0619 26.0111 79.9870 +0.3761 27.3900 88.6680 +34.7841 26.4379 78.8080 +62.2931 23.7228 55.6300 +79.5341 19.9357 24.4380 +81.8151 15.4167 -11.3300 +-84.1611 -16.0187 -9.3460 +-80.2801 -13.7597 29.1600 +-65.3581 -11.6317 64.3580 +-36.1580 -9.9839 89.7520 +0.4009 -9.1670 100.2440 +37.6720 -9.6241 88.4120 +67.1179 -10.9003 63.5800 +83.4559 -12.7763 29.2080 +85.0799 -15.0203 -9.4900 +-84.8302 -46.0217 -7.0560 +-79.5922 -46.5507 30.9490 +-63.5562 -47.0088 65.6240 +-35.5131 -47.2919 91.3150 +0.3858 -47.3180 99.4320 +38.3838 -47.0731 90.6950 +66.6118 -46.6372 65.5800 +83.3218 -46.1013 31.2060 +85.5488 -45.5453 -7.1300 +-72.4343 -73.4527 -2.4870 +-67.2723 -76.2907 28.3820 +-53.0073 -78.7878 55.9400 +-28.6203 -80.5249 75.4360 +0.3247 -81.1150 82.6150 +31.9197 -80.4871 76.7160 +55.6667 -78.5602 56.5610 +67.8877 -75.9043 28.0910 +73.0557 -73.0683 -2.5400 +-54.8404 -97.5279 2.7920 +-36.5114 -100.8529 37.1670 +0.2156 -102.1780 50.6080 +36.7816 -100.8491 36.3970 +55.6666 -97.6251 2.7300 +-29.4134 -112.4490 8.8390 +0.1076 -114.8920 14.6570 +29.8426 -112.1560 8.8000 +-86.0761 -44.9897 -67.9860 + 85.7939 -45.0093 -68.0310 +-86.0761 -24.9897 -67.9860 + 85.7939 -25.0093 -68.0310 +Labels +LPA +RPA +Nz +Fp1 +Fpz +Fp2 +B3 +B1 +Bz +B2 +B4 +F7 +F5 +F3 +F1 +Fz +F2 +F4 +F6 +F8 +D7 +D5 +D3 +D1 +Dz +D2 +D4 +D6 +D8 +T3 +C5 +C3 +C1 +Cz +C2 +C4 +C6 +T4 +E7 +E5 +E3 +E1 +Ez +E2 +E4 +E6 +E8 +T5 +P5 +P3 +P1 +Pz +P2 +P4 +P6 +T6 +H3 +H1 +Hz +H2 +H4 +O1 +Oz +O2 +M1 +M2 +A1 +A2 diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/elec/standard_postfixed.elc b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/elec/standard_postfixed.elc new file mode 100644 index 0000000000000000000000000000000000000000..3ed4d32f6fba3d2decab006bb6c6d1b4d130fa0c --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/elec/standard_postfixed.elc @@ -0,0 +1,212 @@ +# ASA electrode file +ReferenceLabel avg +UnitPosition mm +NumberPositions= 103 +Positions +-86.0761 -19.9897 -47.9860 +85.7939 -20.0093 -48.0310 +0.0083 86.8110 -39.9830 +-29.4367 83.9171 -6.9900 +0.1123 88.2470 -1.7130 +29.8723 84.8959 -7.0800 +-54.8397 68.5722 -10.5900 +-45.4307 72.8622 5.9780 +-33.7007 76.8371 21.2270 +-18.4717 79.9041 32.7520 +0.2313 80.7710 35.4170 +19.8203 80.3019 32.7640 +35.7123 77.7259 21.9560 +46.5843 73.8078 6.0340 +55.7433 69.6568 -10.7550 +-70.2629 42.4743 -11.4200 +-64.4658 48.0353 16.9210 +-50.2438 53.1112 42.1920 +-27.4958 56.9311 60.3420 +0.3122 58.5120 66.4620 +29.5142 57.6019 59.5400 +51.8362 54.3048 40.8140 +67.9142 49.8297 16.3670 +73.0431 44.4217 -12.0000 +-80.7750 14.1203 -11.1350 +-77.2149 18.6433 24.4600 +-60.1819 22.7162 55.5440 +-34.0619 26.0111 79.9870 +0.3761 27.3900 88.6680 +34.7841 26.4379 78.8080 +62.2931 23.7228 55.6300 +79.5341 19.9357 24.4380 +81.8151 15.4167 -11.3300 +-84.0759 14.5673 -50.4290 +-80.7750 14.1203 -11.1350 +-77.2149 18.6433 24.4600 +-60.1819 22.7162 55.5440 +-34.0619 26.0111 79.9870 +0.3761 27.3900 88.6680 +34.7841 26.4379 78.8080 +62.2931 23.7228 55.6300 +79.5341 19.9357 24.4380 +81.8151 15.4167 -11.3300 +84.1131 14.3647 -50.5380 +-84.1611 -16.0187 -9.3460 +-80.2801 -13.7597 29.1600 +-65.3581 -11.6317 64.3580 +-36.1580 -9.9839 89.7520 +0.4009 -9.1670 100.2440 +37.6720 -9.6241 88.4120 +67.1179 -10.9003 63.5800 +83.4559 -12.7763 29.2080 +85.0799 -15.0203 -9.4900 +-84.8302 -46.0217 -7.0560 +-79.5922 -46.5507 30.9490 +-63.5562 -47.0088 65.6240 +-35.5131 -47.2919 91.3150 +0.3858 -47.3180 99.4320 +38.3838 -47.0731 90.6950 +66.6118 -46.6372 65.5800 +83.3218 -46.1013 31.2060 +85.5488 -45.5453 -7.1300 +-84.8302 -46.0217 -7.0560 +-79.5922 -46.5507 30.9490 +-63.5562 -47.0088 65.6240 +-35.5131 -47.2919 91.3150 +0.3858 -47.3180 99.4320 +38.3838 -47.0731 90.6950 +66.6118 -46.6372 65.5800 +83.3218 -46.1013 31.2060 +85.5488 -45.5453 -7.1300 +-73.0093 -73.7657 -40.9980 +-72.4343 -73.4527 -2.4870 +-67.2723 -76.2907 28.3820 +-53.0073 -78.7878 55.9400 +-28.6203 -80.5249 75.4360 +0.3247 -81.1150 82.6150 +31.9197 -80.4871 76.7160 +55.6667 -78.5602 56.5610 +67.8877 -75.9043 28.0910 +73.0557 -73.0683 -2.5400 +73.8947 -74.3903 -41.2200 +-54.9104 -98.0448 -35.4650 +-54.8404 -97.5279 2.7920 +-48.4244 -99.3408 21.5990 +-36.5114 -100.8529 37.1670 +-18.9724 -101.7680 46.5360 +0.2156 -102.1780 50.6080 +19.8776 -101.7930 46.3930 +36.7816 -100.8491 36.3970 +49.8196 -99.4461 21.7270 +55.6666 -97.6251 2.7300 +54.9876 -98.0911 -35.5410 +-29.4134 -112.4490 8.8390 +0.1076 -114.8920 14.6570 +29.8426 -112.1560 8.8000 +-29.8184 -114.5700 -29.2160 +0.0045 -118.5650 -23.0780 +29.7416 -114.2600 -29.2560 +-86.0761 -44.9897 -67.9860 + 85.7939 -45.0093 -68.0310 +-86.0761 -24.9897 -67.9860 + 85.7939 -25.0093 -68.0310 +Labels +LPA +RPA +Nz +Fp1 +Fpz +Fp2 +F7a +F5a +F3a +F1a +Fza +F2a +F4a +F6a +F8a +F7 +F5 +F3 +F1 +Fz +F2 +F4 +F6 +F8 +F7p +F5p +F3p +F1p +Fzp +F2p +F4p +F6p +F8p +T1 +T3a +C5a +C3a +C1a +Cza +C2a +C4a +C6a +T4a +T2 +T3 +C5 +C3 +C1 +Cz +C2 +C4 +C6 +T4 +T3p +C5p +C3p +C1p +Czp +C2p +C4p +C6p +T4p +T5a +P5a +P3a +P1a +Pza +P2a +P4a +P6a +T6a +Cb1a +T5 +P5 +P3 +P1 +Pz +P2 +P4 +P6 +T6 +Cb2a +Cb1 +O1a +P5p +P3p +P1p +Pzp +P2p +P4p +P6p +O2a +Cb2 +O1 +Oz +O2 +Cb1p +Iz +Cb2p +M1 +M2 +A1 +A2 diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/elec/standard_prefixed.elc b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/elec/standard_prefixed.elc new file mode 100644 index 0000000000000000000000000000000000000000..67563c00439888ec7a1e7d546a97c58f17cbb19e --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/elec/standard_prefixed.elc @@ -0,0 +1,160 @@ +# ASA electrode file +ReferenceLabel avg +UnitPosition mm +NumberPositions= 77 +Positions +-86.0761 -19.9897 -47.9860 +85.7939 -20.0093 -48.0310 +0.0083 86.8110 -39.9830 +-29.4367 83.9171 -6.9900 +0.1123 88.2470 -1.7130 +29.8723 84.8959 -7.0800 +55.7433 69.6568 -10.7550 +-33.7007 76.8371 21.2270 +0.2313 80.7710 35.4170 +35.7123 77.7259 21.9560 +55.7433 69.6568 -10.7550 +-70.2629 42.4743 -11.4200 +-64.4658 48.0353 16.9210 +-50.2438 53.1112 42.1920 +-27.4958 56.9311 60.3420 +0.3122 58.5120 66.4620 +29.5142 57.6019 59.5400 +51.8362 54.3048 40.8140 +67.9142 49.8297 16.3670 +73.0431 44.4217 -12.0000 +-84.0759 14.5673 -50.4290 +-80.7750 14.1203 -11.1350 +-77.2149 18.6433 24.4600 +-60.1819 22.7162 55.5440 +-34.0619 26.0111 79.9870 +0.3761 27.3900 88.6680 +34.7841 26.4379 78.8080 +62.2931 23.7228 55.6300 +79.5341 19.9357 24.4380 +81.8151 15.4167 -11.3300 +84.1131 14.3647 -50.5380 +-85.8941 -15.8287 -48.2830 +-84.1611 -16.0187 -9.3460 +-80.2801 -13.7597 29.1600 +-65.3581 -11.6317 64.3580 +-36.1580 -9.9839 89.7520 +0.4009 -9.1670 100.2440 +37.6720 -9.6241 88.4120 +67.1179 -10.9003 63.5800 +83.4559 -12.7763 29.2080 +85.0799 -15.0203 -9.4900 +85.5599 -16.3613 -48.2710 +-84.8302 -46.0217 -7.0560 +-79.5922 -46.5507 30.9490 +-63.5562 -47.0088 65.6240 +-35.5131 -47.2919 91.3150 +0.3858 -47.3180 99.4320 +38.3838 -47.0731 90.6950 +66.6118 -46.6372 65.5800 +83.3218 -46.1013 31.2060 +85.5488 -45.5453 -7.1300 +-73.0093 -73.7657 -40.9980 +-72.4343 -73.4527 -2.4870 +-67.2723 -76.2907 28.3820 +-53.0073 -78.7878 55.9400 +-28.6203 -80.5249 75.4360 +0.3247 -81.1150 82.6150 +31.9197 -80.4871 76.7160 +55.6667 -78.5602 56.5610 +67.8877 -75.9043 28.0910 +73.0557 -73.0683 -2.5400 +73.8947 -74.3903 -41.2200 +-54.9104 -98.0448 -35.4650 +-54.8404 -97.5279 2.7920 +-36.5114 -100.8529 37.1670 +0.2156 -102.1780 50.6080 +36.7816 -100.8491 36.3970 +55.6666 -97.6251 2.7300 +54.9876 -98.0911 -35.5410 +-29.4134 -112.4490 8.8390 +0.1076 -114.8920 14.6570 +29.8426 -112.1560 8.8000 +0.0045 -118.5650 -23.0780 +-86.0761 -44.9897 -67.9860 + 85.7939 -45.0093 -68.0310 +-86.0761 -24.9897 -67.9860 + 85.7939 -25.0093 -68.0310 +Labels +LPA +RPA +Nz +Fp1 +Fpz +Fp2 +aF3 +aF1 +aFz +aF2 +aF4 +F7 +F5 +F3 +F1 +Fz +F2 +F4 +F6 +F8 +iT1 +T1 +pF5 +pF3 +pF1 +pFz +pF2 +pF4 +pF6 +T2 +iT2 +iT3 +T3 +C5 +C3 +C1 +Cz +C2 +C4 +C6 +T4 +iT4 +T3A +pC5 +pC3 +pC1 +pCz +pC2 +pC4 +pC6 +T4A +iT5 +T5 +P5 +P3 +P1 +Pz +P2 +P4 +P6 +T6 +iT6 +pO5 +pO3 +pO1 +pOz +pO2 +pO4 +pO6 +O1 +Oz +O2 +Iz +M1 +M2 +A1 +A2 diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/elec/standard_primed.elc b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/elec/standard_primed.elc new file mode 100644 index 0000000000000000000000000000000000000000..00ec918387d2adf8be79f2d14f20ae440c10e6bb --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/elec/standard_primed.elc @@ -0,0 +1,212 @@ +# ASA electrode file +ReferenceLabel avg +UnitPosition mm +NumberPositions= 103 +Positions +-86.0761 -19.9897 -47.9860 +85.7939 -20.0093 -48.0310 +0.0083 86.8110 -39.9830 +-29.4367 83.9171 -6.9900 +0.1123 88.2470 -1.7130 +29.8723 84.8959 -7.0800 +-54.8397 68.5722 -10.5900 +-45.4307 72.8622 5.9780 +-33.7007 76.8371 21.2270 +-18.4717 79.9041 32.7520 +0.2313 80.7710 35.4170 +19.8203 80.3019 32.7640 +35.7123 77.7259 21.9560 +46.5843 73.8078 6.0340 +55.7433 69.6568 -10.7550 +-70.2629 42.4743 -11.4200 +-64.4658 48.0353 16.9210 +-50.2438 53.1112 42.1920 +-27.4958 56.9311 60.3420 +0.3122 58.5120 66.4620 +29.5142 57.6019 59.5400 +51.8362 54.3048 40.8140 +67.9142 49.8297 16.3670 +73.0431 44.4217 -12.0000 +-80.7750 14.1203 -11.1350 +-77.2149 18.6433 24.4600 +-60.1819 22.7162 55.5440 +-34.0619 26.0111 79.9870 +0.3761 27.3900 88.6680 +34.7841 26.4379 78.8080 +62.2931 23.7228 55.6300 +79.5341 19.9357 24.4380 +81.8151 15.4167 -11.3300 +-84.0759 14.5673 -50.4290 +-80.7750 14.1203 -11.1350 +-77.2149 18.6433 24.4600 +-60.1819 22.7162 55.5440 +-34.0619 26.0111 79.9870 +0.3761 27.3900 88.6680 +34.7841 26.4379 78.8080 +62.2931 23.7228 55.6300 +79.5341 19.9357 24.4380 +81.8151 15.4167 -11.3300 +84.1131 14.3647 -50.5380 +-84.1611 -16.0187 -9.3460 +-80.2801 -13.7597 29.1600 +-65.3581 -11.6317 64.3580 +-36.1580 -9.9839 89.7520 +0.4009 -9.1670 100.2440 +37.6720 -9.6241 88.4120 +67.1179 -10.9003 63.5800 +83.4559 -12.7763 29.2080 +85.0799 -15.0203 -9.4900 +-84.8302 -46.0217 -7.0560 +-79.5922 -46.5507 30.9490 +-63.5562 -47.0088 65.6240 +-35.5131 -47.2919 91.3150 +0.3858 -47.3180 99.4320 +38.3838 -47.0731 90.6950 +66.6118 -46.6372 65.5800 +83.3218 -46.1013 31.2060 +85.5488 -45.5453 -7.1300 +-84.8302 -46.0217 -7.0560 +-79.5922 -46.5507 30.9490 +-63.5562 -47.0088 65.6240 +-35.5131 -47.2919 91.3150 +0.3858 -47.3180 99.4320 +38.3838 -47.0731 90.6950 +66.6118 -46.6372 65.5800 +83.3218 -46.1013 31.2060 +85.5488 -45.5453 -7.1300 +-73.0093 -73.7657 -40.9980 +-72.4343 -73.4527 -2.4870 +-67.2723 -76.2907 28.3820 +-53.0073 -78.7878 55.9400 +-28.6203 -80.5249 75.4360 +0.3247 -81.1150 82.6150 +31.9197 -80.4871 76.7160 +55.6667 -78.5602 56.5610 +67.8877 -75.9043 28.0910 +73.0557 -73.0683 -2.5400 +73.8947 -74.3903 -41.2200 +-54.9104 -98.0448 -35.4650 +-54.8404 -97.5279 2.7920 +-48.4244 -99.3408 21.5990 +-36.5114 -100.8529 37.1670 +-18.9724 -101.7680 46.5360 +0.2156 -102.1780 50.6080 +19.8776 -101.7930 46.3930 +36.7816 -100.8491 36.3970 +49.8196 -99.4461 21.7270 +55.6666 -97.6251 2.7300 +54.9876 -98.0911 -35.5410 +-29.4134 -112.4490 8.8390 +0.1076 -114.8920 14.6570 +29.8426 -112.1560 8.8000 +-29.8184 -114.5700 -29.2160 +0.0045 -118.5650 -23.0780 +29.7416 -114.2600 -29.2560 +-86.0761 -44.9897 -67.9860 + 85.7939 -45.0093 -68.0310 +-86.0761 -24.9897 -67.9860 + 85.7939 -25.0093 -68.0310 +Labels +LPA +RPA +Nz +Fp1 +Fpz +Fp2 +F7' +F5' +F3' +F1' +Fz' +F2' +F4' +F6' +F8' +F7 +F5 +F3 +F1 +Fz +F2 +F4 +F6 +F8 +F7'' +F5'' +F3'' +F1'' +Fz'' +F2'' +F4'' +F6'' +F8'' +T1 +T3' +C5' +C3' +C1' +Cz' +C2' +C4' +C6' +T4' +T2 +T3 +C5 +C3 +C1 +Cz +C2 +C4 +C6 +T4 +T3'' +C5'' +C3'' +C1'' +Cz'' +C2'' +C4'' +C6'' +T4'' +T5' +P5' +P3' +P1' +Pz' +P2' +P4' +P6' +T6' +Cb1' +T5 +P5 +P3 +P1 +Pz +P2 +P4 +P6 +T6 +Cb2' +Cb1 +O1' +P5'' +P3'' +P1'' +Pz'' +P2'' +P4'' +P6'' +O2' +Cb2 +O1 +Oz +O2 +Cb1'' +Iz +Cb2'' +M1 +M2 +A1 +A2 diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_1222-1.bnd b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_1222-1.bnd new file mode 100644 index 0000000000000000000000000000000000000000..58f3e47c5c7c4e3ee23a391b9fe1d8509cd73649 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_1222-1.bnd @@ -0,0 +1,11 @@ +# Boundary with 1222 vertices and 2440 polygons with 3 vertices each +Type= Scalp +NumberPositions= 1222 +UnitPosition mm +Positions standard_skin_1222-1.bps +NumberSlices= 32 +Slices +1 6 12 19 24 30 35 40 45 49 53 56 58 60 61 62 62 61 60 58 56 53 49 45 40 35 30 24 19 12 6 1 +NumberPolygons= 2440 +TypePolygons= 3 +Polygons standard_skin_1222-1.bpl diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_1222-1.bpl b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_1222-1.bpl new file mode 100644 index 0000000000000000000000000000000000000000..f580a8f31c5b0b7a84d2a18e91b1a3a4a29b0013 Binary files /dev/null and b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_1222-1.bpl differ diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_1222-1.bps b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_1222-1.bps new file mode 100644 index 0000000000000000000000000000000000000000..79dbf2f4ddfedf57ad412d296f65b32fa78f4c1f Binary files /dev/null and b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_1222-1.bps differ diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_1222.vol b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_1222.vol new file mode 100644 index 0000000000000000000000000000000000000000..cfe8cf13e4b2e6099161dde7dc3cd85d9346ad55 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_1222.vol @@ -0,0 +1,8 @@ +# Volume conductor with 1 boundaries +NumberBoundaries= 1 +UnitConduct S/m +Conductivities +0.33 +WhereInside +0 +Boundary1 standard_skin_1222-1.bnd diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_14038-1.bnd b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_14038-1.bnd new file mode 100644 index 0000000000000000000000000000000000000000..3f178c1ec01bda8e88f0db577f1da0c4fd24f4a8 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_14038-1.bnd @@ -0,0 +1,11 @@ +# Boundary with 14038 vertices and 28072 polygons with 3 vertices each +Type= Scalp +NumberPositions= 14038 +UnitPosition mm +Positions standard_skin_14038-1.bps +NumberSlices= 107 +Slices +1 6 13 19 25 31 37 44 50 56 62 68 74 80 85 91 97 102 108 113 118 123 128 133 138 143 147 152 156 160 164 168 172 175 179 182 185 188 191 193 195 198 200 202 203 205 206 207 208 209 209 210 210 210 210 209 209 208 207 206 205 203 202 200 198 195 193 191 188 185 182 179 175 172 168 164 160 156 152 147 143 138 133 128 123 118 113 108 102 97 91 85 80 74 68 62 56 50 44 37 31 25 19 13 6 0 1 +NumberPolygons= 28072 +TypePolygons= 3 +Polygons standard_skin_14038-1.bpl diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_14038.vol b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_14038.vol new file mode 100644 index 0000000000000000000000000000000000000000..1adbeb97bcc2f08301963acd260e7a2600f75964 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_14038.vol @@ -0,0 +1,8 @@ +# Volume conductor with 1 boundaries +NumberBoundaries= 1 +UnitConduct S/m +Conductivities +0.33 +WhereInside +0 +Boundary1 standard_skin_14038-1.bnd diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_5054-1.bnd b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_5054-1.bnd new file mode 100644 index 0000000000000000000000000000000000000000..f04ea99e2b526792bc57cddb8e1c27d1b145204b --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_5054-1.bnd @@ -0,0 +1,11 @@ +# Boundary with 5054 vertices and 10104 polygons with 3 vertices each +Type= Scalp +NumberPositions= 5054 +UnitPosition mm +Positions standard_skin_5054-1.bps +NumberSlices= 65 +Slices +1 6 13 19 25 31 37 43 49 55 60 66 71 76 81 86 90 94 99 102 106 109 112 115 117 119 121 123 124 125 126 126 126 126 125 124 123 121 119 117 115 112 109 106 102 99 94 90 86 81 76 71 66 60 55 49 43 37 31 25 19 13 6 0 1 +NumberPolygons= 10104 +TypePolygons= 3 +Polygons standard_skin_5054-1.bpl diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_5054-1.bps b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_5054-1.bps new file mode 100644 index 0000000000000000000000000000000000000000..e76d125f2d351a397fb5dc3443098fb80a08de94 Binary files /dev/null and b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_5054-1.bps differ diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_5054.vol b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_5054.vol new file mode 100644 index 0000000000000000000000000000000000000000..e05034edf8375778ec44ba74a048e3b720aec790 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BEM/skin/standard_skin_5054.vol @@ -0,0 +1,8 @@ +# Volume conductor with 1 boundaries +NumberBoundaries= 1 +UnitConduct S/m +Conductivities +0.33 +WhereInside +0 +Boundary1 standard_skin_5054-1.bnd diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/TemplateRed254.loc b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/TemplateRed254.loc new file mode 100644 index 0000000000000000000000000000000000000000..65a73da81ae3ce2cc5024290f266e898275cec13 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/TemplateRed254.loc @@ -0,0 +1,254 @@ +1 -39.993 0.61067 A1 +2 -37.456 0.52976 A2 +3 -37.954 0.45664 A3 +4 -41.082 0.38651 A4 +5 -47.577 0.32415 A5 +6 -59.837 0.27577 A6 +7 -78.493 0.24127 A7 +8 -44.442 0.67591 A8 +9 -47.999 0.6091 A9 +10 -49.044 0.53271 A10 +11 -50.519 0.44863 A11 +12 -58.31 0.37649 A12 +13 -73.747 0.33244 A13 +14 -92.572 0.3159 A14 +15 -51.663 0.72498 A15 +16 -55.519 0.66755 A16 +17 -58.722 0.59937 A17 +18 -63.673 0.51791 A18 +19 -67.389 0.44445 A19 +20 -83.73 0.40267 A20 +21 -100.15 0.39122 A21 +22 -63.68 0.70729 A22 +23 -66.433 0.66235 A23 +24 -73.198 0.58759 A24 +25 -78.033 0.50242 A25 +26 -94.009 0.48113 A26 +27 -108.59 0.47186 A27 +28 -74.998 0.70469 A28 +29 -78.57 0.65566 A29 +30 -87.363 0.57783 A30 +31 -102.72 0.55893 A31 +32 -117.88 0.54031 A32 +33 -43.879 0.24556 B1 +34 -31.979 0.16239 B2 +35 -3.0293 0.19723 B3 +36 30.079 0.17371 B4 +37 38.524 0.26878 B5 +38 -57.577 0.18361 B6 +39 -59.643 0.091678 B7 +40 -4.3228 0.10312 B8 +41 56.25 0.11629 B9 +42 59.41 0.20707 B10 +43 -88.74 0.15607 B11 +44 -90 0.0033889 B12 +45 86.102 0.17859 B13 +46 -103.02 0.24685 B14 +47 -124.44 0.17181 B15 +48 -157.7 0.1659 B16 +49 176.13 0.1131 B17 +50 144.93 0.18232 B18 +51 121.72 0.20569 B19 +52 98.357 0.27707 B20 +53 -127.62 0.27815 B21 +54 -147.89 0.25418 B22 +55 -167.82 0.26797 B23 +56 178.36 0.19454 B24 +57 158.87 0.26381 B25 +58 140.24 0.25896 B26 +59 118.96 0.30331 B27 +60 -139.56 0.33077 B28 +61 -154.68 0.32819 B29 +62 176.98 0.29833 B30 +63 149.81 0.32471 B31 +64 135.25 0.3349 B32 +65 -147.56 0.81654 C1 +66 -164.8 0.81002 C2 +67 -148.68 0.60176 C3 +68 -160.47 0.5831 C4 +69 -170.36 0.54628 C5 +70 179.07 0.5163 C6 +71 167.07 0.55561 C7 +72 156.28 0.5827 C8 +73 144.14 0.59662 C9 +74 167.43 0.80802 C10 +75 147.27 0.83823 C11 +76 -155.37 0.6439 C12 +77 -170.14 0.61535 C13 +78 179.09 0.57583 C14 +79 167.1 0.61834 C15 +80 152.5 0.65293 C16 +81 -152.37 0.70734 C17 +82 -169.55 0.681 C18 +83 178.56 0.6394 C19 +84 165.44 0.67454 C20 +85 148.43 0.71591 C21 +86 -151.8 0.76274 C22 +87 -167.24 0.73459 C23 +88 178.3 0.71064 C24 +89 165.88 0.73544 C25 +90 150.07 0.7742 C26 +91 -150.97 0.79947 C27 +92 -167.59 0.78222 C28 +93 178.38 0.76587 C29 +94 165.64 0.7826 C30 +95 149.82 0.81343 C31 +96 179.68 0.79715 C32 +97 75.838 0.27645 D1 +98 57.716 0.3066 D2 +99 44.874 0.35755 D3 +100 37.777 0.42783 D4 +101 89.218 0.35285 D5 +102 70.779 0.37037 D6 +103 54.33 0.41168 D7 +104 97.902 0.43522 D8 +105 83.673 0.4473 D9 +106 66.118 0.47371 D10 +107 47.578 0.4866 D11 +108 35.228 0.49581 D12 +109 108.17 0.50255 D13 +110 93.612 0.52282 D14 +111 76.539 0.54225 D15 +112 59.914 0.55547 D16 +113 47.164 0.57055 D17 +114 35.648 0.57819 D18 +115 116.41 0.58251 D19 +116 102.27 0.58935 D20 +117 86.808 0.60248 D21 +118 71.587 0.6267 D22 +119 58.273 0.63774 D23 +120 46.196 0.64802 D24 +121 34.367 0.63474 D25 +122 79.869 0.68151 D26 +123 66.608 0.69611 D27 +124 53.752 0.69777 D28 +125 41.219 0.69393 D29 +126 74.211 0.74264 D30 +127 60.631 0.74509 D31 +128 48.281 0.74101 D32 +129 135.45 0.60911 E1 +130 124.93 0.64033 E2 +131 111.43 0.65268 E3 +132 137.75 0.67605 E4 +133 123.99 0.7063 E5 +134 138.35 0.75212 E6 +135 121.66 0.78379 E7 +136 136.2 0.80101 E8 +137 120.27 0.82341 E9 +138 138.99 0.82908 E10 +139 124.2 0.8492 E11 +140 134.59 0.84802 E12 +141 119.99 0.86803 E13 +142 107.96 0.86397 E14 +143 98.893 0.85178 E15 +144 85.638 0.82801 E16 +145 73.549 0.79385 E17 +146 59.153 0.79237 E18 +147 47.058 0.79273 E19 +148 39.25 0.75039 E20 +149 70.906 0.82641 E21 +150 55.222 0.82771 E22 +151 41.602 0.83137 E23 +152 36.069 0.80146 E24 +153 83.262 0.8592 E25 +154 66.467 0.8668 E26 +155 48.82 0.87401 E27 +156 97.023 0.88013 E28 +157 77.4 0.90336 E29 +158 55.993 0.91389 E30 +159 140.97 0.54307 E31 +160 127.97 0.56324 E32 +161 -110.02 0.33025 F1 +162 -127.08 0.35941 F2 +163 -144.39 0.39014 F3 +164 -157.78 0.39311 F4 +165 -166.72 0.34059 F5 +166 178.04 0.37114 F6 +167 161.37 0.33199 F7 +168 152.27 0.3887 F8 +169 139.1 0.37245 F9 +170 120.59 0.37519 F10 +171 105.08 0.3472 F11 +172 119 0.50177 F12 +173 112.47 0.42935 F13 +174 128.06 0.44113 F14 +175 143.39 0.44447 F15 +176 154.51 0.46384 F16 +177 163.24 0.41541 F17 +178 178.02 0.45063 F18 +179 -169.81 0.4131 F19 +180 -160.8 0.46324 F20 +181 -148.09 0.44947 F21 +182 -132.41 0.43097 F22 +183 -117.31 0.41189 F23 +184 -122.95 0.49099 F24 +185 -137.85 0.49018 F25 +186 -150.72 0.50426 F26 +187 -162.52 0.52463 F27 +188 -170.73 0.47993 F28 +189 164.26 0.48709 F29 +190 145.98 0.50559 F30 +191 131.8 0.50192 F31 +192 156.22 0.52801 F32 +193 -38.643 0.7541 G1 +194 -46.226 0.80178 G2 +195 -58.166 0.79237 G3 +196 -72.893 0.77713 G4 +197 -34.367 0.81404 G5 +198 -53.937 0.83848 G6 +199 -69.51 0.82996 G7 +200 -80.256 0.81722 G8 +201 -35.335 0.8479 G9 +202 -44.294 0.88352 G10 +203 -63.035 0.87615 G11 +204 -83.054 0.86841 G12 +205 -53.771 0.92452 G13 +206 -79.631 0.9075 G14 +207 -123.3 0.85986 G15 +208 -96.258 0.8751 G16 +209 -98.491 0.84675 G17 +210 -144.77 0.54827 G18 +211 -111.82 0.85428 G19 +212 -117.98 0.82082 G20 +213 -123.63 0.77312 G21 +214 -127.16 0.70696 G22 +215 -111.51 0.63222 G23 +216 -125.82 0.61955 G24 +217 -139.79 0.6095 G25 +218 -143.25 0.67752 G26 +219 -140.23 0.74021 G27 +220 -138.61 0.79578 G28 +221 -129.63 0.84108 G29 +222 -144.18 0.82212 G30 +223 -132.09 0.54374 G31 +224 -140.79 0.84395 G32 +225 33.252 0.3393 H1 +226 21.201 0.27457 H2 +227 0.20131 0.29697 H3 +228 -18.78 0.2673 H4 +229 -31.626 0.33307 H5 +230 -15.832 0.34614 H6 +231 0.55525 0.37625 H7 +232 16.539 0.34797 H8 +233 26.328 0.39781 H9 +234 13.349 0.41385 H10 +235 25.209 0.46182 H11 +236 13.034 0.47147 H12 +237 0.37298 0.44597 H13 +238 -14.172 0.41134 H14 +239 -27.063 0.3941 H15 +240 -12.782 0.4778 H16 +241 -25.072 0.45432 H17 +242 -13.157 0.52526 H18 +243 -25.442 0.51376 H19 +244 15.085 0.52859 H20 +245 -26.734 0.56861 H21 +246 -0.24975 0.50951 H22 +247 26.031 0.51712 H23 +248 28.336 0.56969 H24 +249 36.2 0.7092 EXG1 +250 21.641 0.71097 EXG2 +251 -10.518 0.7056 EXG3 +252 -28.949 0.7227 EXG4 +253 9.809 0.55873 EXG5 +254 -7.9205 0.55763 EXG6 diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/TemplateRed254.mat b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/TemplateRed254.mat new file mode 100644 index 0000000000000000000000000000000000000000..6ad3f329ea531ec6c5a3c74457052c9d760c2a67 Binary files /dev/null and b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/TemplateRed254.mat differ diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/TemplateYellow254.loc b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/TemplateYellow254.loc new file mode 100644 index 0000000000000000000000000000000000000000..57ebccd7d496acf190b64e9693af314d7494c108 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/TemplateYellow254.loc @@ -0,0 +1,254 @@ +1 -40.515 0.58512 A1 +2 -37.995 0.51163 A2 +3 -38.096 0.45017 A3 +4 -39.001 0.3939 A4 +5 -45.311 0.33006 A5 +6 -58.77 0.27964 A6 +7 -75.776 0.24782 A7 +8 -44.091 0.6562 A8 +9 -48.741 0.57143 A9 +10 -48.173 0.50586 A10 +11 -50.234 0.44388 A11 +12 -57.9 0.38156 A12 +13 -70.368 0.34091 A13 +14 -88.789 0.31702 A14 +15 -51.998 0.72305 A15 +16 -52.424 0.64435 A16 +17 -58.335 0.55646 A17 +18 -59.747 0.48662 A18 +19 -67.719 0.42645 A19 +20 -80.696 0.40194 A20 +21 -98.013 0.39587 A21 +22 -59.733 0.70815 A22 +23 -61.693 0.62886 A23 +24 -70.063 0.54691 A24 +25 -74.493 0.4762 A25 +26 -88.273 0.47581 A26 +27 -104.91 0.48165 A27 +28 -70.511 0.69123 A28 +29 -72.088 0.6234 A29 +30 -83.778 0.53164 A30 +31 -99.441 0.54926 A31 +32 -116.41 0.56491 A32 +33 -40.39 0.23713 B1 +34 -34.699 0.1546 B2 +35 3.2078 0.1921 B3 +36 29.579 0.17022 B4 +37 39.3 0.26669 B5 +38 -62.003 0.19563 B6 +39 -58.471 0.10203 B7 +40 -1.9721 0.10319 B8 +41 59.894 0.10914 B9 +42 60.279 0.22433 B10 +43 -88.234 0.17995 B11 +44 -90 0.01395 B12 +45 83.297 0.18977 B13 +46 -102.1 0.26716 B14 +47 -124.13 0.20665 B15 +48 -155.53 0.17275 B16 +49 179.07 0.10089 B17 +50 145.54 0.21593 B18 +51 119.96 0.22693 B19 +52 96 0.27885 B20 +53 -123.16 0.30686 B21 +54 -146.43 0.27069 B22 +55 -166.16 0.27924 B23 +56 176.21 0.22907 B24 +57 155.75 0.29199 B25 +58 137.35 0.29473 B26 +59 117.84 0.31862 B27 +60 -137.88 0.35483 B28 +61 -154.43 0.35545 B29 +62 176.23 0.32284 B30 +63 150.08 0.36028 B31 +64 131.29 0.36568 B32 +65 -142.01 0.83836 C1 +66 -162.21 0.83675 C2 +67 -148.48 0.62454 C3 +68 -159.27 0.60867 C4 +69 -172.12 0.5778 C5 +70 176.74 0.54965 C6 +71 167.36 0.58722 C7 +72 157.39 0.61531 C8 +73 144.87 0.63681 C9 +74 164.37 0.83741 C10 +75 143.78 0.84268 C11 +76 -158.43 0.66473 C12 +77 -171.05 0.63768 C13 +78 177.78 0.6136 C14 +79 167.43 0.64402 C15 +80 154.48 0.66791 C16 +81 -153.84 0.71082 C17 +82 -169.42 0.69341 C18 +83 178.23 0.66643 C19 +84 166.74 0.70419 C20 +85 151.79 0.71936 C21 +86 -150.48 0.76189 C22 +87 -166.68 0.75087 C23 +88 179.33 0.71944 C24 +89 165.77 0.74997 C25 +90 150.48 0.77129 C26 +91 -144.42 0.80947 C27 +92 -163.76 0.7951 C28 +93 177.92 0.77455 C29 +94 164.25 0.79943 C30 +95 146.11 0.81654 C31 +96 178.63 0.81962 C32 +97 74.936 0.28716 D1 +98 54.291 0.31439 D2 +99 43.584 0.36517 D3 +100 37.82 0.43212 D4 +101 87.229 0.37337 D5 +102 69.162 0.37426 D6 +103 55.516 0.41273 D7 +104 96.217 0.43539 D8 +105 79.771 0.44546 D9 +106 62.946 0.47365 D10 +107 49.091 0.47931 D11 +108 35.094 0.4829 D12 +109 105.12 0.5123 D13 +110 89.533 0.51153 D14 +111 74.646 0.52055 D15 +112 60.053 0.5373 D16 +113 45.813 0.53493 D17 +114 34.618 0.5333 D18 +115 112.19 0.56826 D19 +116 98.426 0.56526 D20 +117 84.163 0.5745 D21 +118 68.976 0.58612 D22 +119 56.545 0.5955 D23 +120 47.751 0.61599 D24 +121 38.479 0.58001 D25 +122 75.333 0.65756 D26 +123 63.332 0.66399 D27 +124 53.576 0.66851 D28 +125 45.888 0.67912 D29 +126 68.847 0.73212 D30 +127 60.63 0.73787 D31 +128 51.681 0.74176 D32 +129 133.48 0.63279 E1 +130 119.05 0.62169 E2 +131 104.43 0.62581 E3 +132 138.54 0.69326 E4 +133 121.55 0.69782 E5 +134 135.65 0.74544 E6 +135 118.28 0.75427 E7 +136 134.12 0.79269 E8 +137 114.45 0.80644 E9 +138 129.1 0.83171 E10 +139 108.35 0.84199 E11 +140 122.45 0.86089 E12 +141 106.32 0.86732 E13 +142 94.35 0.86103 E14 +143 93.562 0.83988 E15 +144 78.045 0.82808 E16 +145 68.216 0.78862 E17 +146 57.755 0.79444 E18 +147 47.183 0.79177 E19 +148 44.532 0.73809 E20 +149 62.25 0.8355 E21 +150 50.11 0.83423 E22 +151 38.049 0.82938 E23 +152 37.676 0.7828 E24 +153 72.268 0.86295 E25 +154 54.825 0.87374 E26 +155 39.024 0.86837 E27 +156 81.419 0.87973 E28 +157 63.678 0.89436 E29 +158 41.2 0.90185 E30 +159 139.45 0.58498 E31 +160 127.15 0.56987 E32 +161 -108.08 0.34491 F1 +162 -125.87 0.38507 F2 +163 -142.5 0.41771 F3 +164 -157.24 0.43151 F4 +165 -169.88 0.37479 F5 +166 175.99 0.41988 F6 +167 162.48 0.37433 F7 +168 152.54 0.43347 F8 +169 138.97 0.41715 F9 +170 120.83 0.39901 F10 +171 103.47 0.37153 F11 +172 120.77 0.51934 F12 +173 110.42 0.45241 F13 +174 129.53 0.4726 F14 +175 146.74 0.48835 F15 +176 156.85 0.51075 F16 +177 166.92 0.46787 F17 +178 178.06 0.48775 F18 +179 -170.91 0.45177 F19 +180 -159.98 0.48921 F20 +181 -144.03 0.4837 F21 +182 -128.6 0.45895 F22 +183 -112.71 0.42785 F23 +184 -118.62 0.50422 F24 +185 -135.81 0.5276 F25 +186 -151.96 0.52897 F26 +187 -162.06 0.55493 F27 +188 -172.21 0.51456 F28 +189 167.04 0.53307 F29 +190 146.06 0.55066 F30 +191 133.91 0.52663 F31 +192 156.95 0.57322 F32 +193 -44.727 0.73477 G1 +194 -51.682 0.77252 G2 +195 -60.989 0.7607 G3 +196 -69.604 0.74798 G4 +197 -39.47 0.78374 G5 +198 -54.756 0.81451 G6 +199 -68.067 0.80277 G7 +200 -79.749 0.79044 G8 +201 -42.878 0.82323 G9 +202 -46.596 0.86733 G10 +203 -60.652 0.86079 G11 +204 -75.023 0.85065 G12 +205 -48.607 0.8987 G13 +206 -65.665 0.88472 G14 +207 -108.62 0.86549 G15 +208 -83.272 0.87044 G16 +209 -93.312 0.8348 G17 +210 -143.45 0.57045 G18 +211 -97.554 0.85159 G19 +212 -114.77 0.79731 G20 +213 -121.91 0.74528 G21 +214 -123.66 0.69316 G22 +215 -112.42 0.6383 G23 +216 -125.28 0.6383 G24 +217 -137.87 0.63532 G25 +218 -140.17 0.6859 G26 +219 -138.24 0.73037 G27 +220 -133.59 0.78007 G28 +221 -114.24 0.83242 G29 +222 -129.51 0.82488 G30 +223 -129.97 0.57174 G31 +224 -125.49 0.85753 G32 +225 31.798 0.3249 H1 +226 17.392 0.24959 H2 +227 1.5947 0.29495 H3 +228 -18.5 0.24316 H4 +229 -33.479 0.29296 H5 +230 -14.628 0.32827 H6 +231 0.91757 0.36891 H7 +232 16.66 0.3339 H8 +233 27.436 0.38358 H9 +234 12.405 0.39816 H10 +235 26.003 0.43352 H11 +236 11.976 0.45035 H12 +237 -1.822 0.42744 H13 +238 -14.745 0.39533 H14 +239 -30.295 0.36704 H15 +240 -14.539 0.45065 H16 +241 -27.892 0.4339 H17 +242 -15.226 0.49438 H18 +243 -27.846 0.48238 H19 +244 13.976 0.50255 H20 +245 -26.663 0.52859 H21 +246 -1.3278 0.4768 H22 +247 25.076 0.49486 H23 +248 26.766 0.53675 H24 +249 28.471 0.6793 EXG1 +250 15.308 0.67787 EXG2 +251 -12.069 0.67666 EXG3 +252 -25.68 0.69429 EXG4 +253 6.9272 0.54823 EXG5 +254 -6.4071 0.54574 EXG6 diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/TemplateYellow254.mat b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/TemplateYellow254.mat new file mode 100644 index 0000000000000000000000000000000000000000..a3d0d5986c21dcb5de26610a17a9f7b8eb2a6f84 Binary files /dev/null and b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/TemplateYellow254.mat differ diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/standard-10-5-cap385.elp b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/standard-10-5-cap385.elp new file mode 100644 index 0000000000000000000000000000000000000000..a258c196a9fab29a57bc43561dd18c1765e380db --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/standard-10-5-cap385.elp @@ -0,0 +1,359 @@ +346 + FID LPA -120.03 0 85 + FID RPA 120.03 0 85 + FID Nz 114.03 90 85 + EEG Fp1 -92.698 -72.074 85 + EEG Fpz 91.204 90 85 + EEG Fp2 92.698 72.074 85 + EEG AF9 -117.54 -54.695 85 + EEG AF7 -94.02 -54.108 85 + EEG AF5 -83.969 -59.461 85 + EEG AF3 -75.803 -67.539 85 + EEG AF1 -70.343 -77.973 85 + EEG AFz 68.39 90 85 + EEG AF2 70.358 78.046 85 + EEG AF4 75.803 67.539 85 + EEG AF6 83.969 59.461 85 + EEG AF8 94.016 54.142 85 + EEG AF10 117.52 54.733 85 + EEG F9 -118.84 -36.687 85 + EEG F7 -95.055 -36.087 85 + EEG F5 -77.687 -40.595 85 + EEG F3 -62.027 -50.053 85 + EEG F1 -50.225 -66.507 85 + EEG Fz 45.608 90 85 + EEG F2 50.181 66.507 85 + EEG F4 62.01 50.103 85 + EEG F6 77.631 40.595 85 + EEG F8 95.052 36.133 85 + EEG F10 118.84 36.687 85 + EEG FT9 -119.68 -18.393 85 + EEG FT7 -95.745 -18.052 85 + EEG FC5 -73.482 -20.668 85 + EEG FC3 -51.88 -27.575 85 + EEG FC1 -32.613 -45.075 85 + EEG FCz 22.792 90 85 + EEG FC2 32.613 45.075 85 + EEG FC4 51.88 27.575 85 + EEG FC6 73.482 20.668 85 + EEG FT8 95.745 18.052 85 + EEG FT10 119.68 18.393 85 + EEG T9 -120.03 0 85 + EEG T7 -95.973 0 85 + EEG C5 -71.982 0 85 + EEG C3 -48.004 0 85 + EEG C1 -23.974 0 85 + EEG Cz 0 90 85 + EEG C2 24.027 0 85 + EEG C4 48 0 85 + EEG C6 71.982 0 85 + EEG T8 95.973 0 85 + EEG T10 120.03 0 85 + EEG TP9 -119.68 18.393 85 + EEG TP7 -95.745 18.052 85 + EEG CP5 -73.482 20.668 85 + EEG CP3 -51.88 27.575 85 + EEG CP1 -32.613 45.075 85 + EEG CPz 22.792 -90 85 + EEG CP2 32.613 -45.075 85 + EEG CP4 51.88 -27.575 85 + EEG CP6 73.482 -20.668 85 + EEG TP8 95.743 -18.107 85 + EEG TP10 119.68 -18.393 85 + EEG P9 -118.84 36.687 85 + EEG P7 -95.055 36.087 85 + EEG P5 -77.687 40.595 85 + EEG P3 -62.027 50.053 85 + EEG P1 -50.225 66.507 85 + EEG Pz 45.608 -90 85 + EEG P2 50.181 -66.507 85 + EEG P4 62.01 -50.103 85 + EEG P6 77.631 -40.595 85 + EEG P8 95.052 -36.133 85 + EEG P10 118.84 -36.687 85 + EEG PO9 -117.54 54.695 85 + EEG PO7 -94.02 54.108 85 + EEG PO5 -83.969 59.461 85 + EEG PO3 -75.803 67.539 85 + EEG PO1 -70.343 77.973 85 + EEG POz 68.39 -90 85 + EEG PO2 70.358 -78.046 85 + EEG PO4 75.803 -67.539 85 + EEG PO6 83.969 -59.461 85 + EEG PO8 94.016 -54.142 85 + EEG PO10 117.52 -54.733 85 + EEG O1 -92.698 72.074 85 + EEG Oz 91.204 -90 85 + EEG O2 92.698 -72.074 85 + EEG I1 -115.86 72.532 85 + EEG O9 -115.86 72.532 85 + EEG Iz 114.03 -90 85 + EEG I2 115.86 -72.532 85 + EEG O10 115.86 -72.532 85 + EEG AFp9h -105.02 -63.355 85 + EEG AFp7h -90.401 -65.641 85 + EEG AFp5h -85.465 -71.565 85 + EEG AFp3h -81.886 -78.451 85 + EEG AFp1h -80.031 -86.097 85 + EEG AFp2h 80.032 86.039 85 + EEG AFp4h 81.886 78.451 85 + EEG AFp6h 85.465 71.565 85 + EEG AFp8h 90.401 65.589 85 + EEG AFp10h 105.03 63.329 85 + EEG AFF9h -106.39 -45.423 85 + EEG AFF7h -87.419 -47.151 85 + EEG AFF5h -74.258 -54.227 85 + EEG AFF3h -63.752 -65.551 85 + EEG AFF1h -57.79 -81.161 85 + EEG AFF2h 57.785 81.228 85 + EEG AFF4h 63.804 65.551 85 + EEG AFF6h 74.267 54.178 85 + EEG AFF8h 87.418 47.193 85 + EEG AFF10h 106.4 45.381 85 + EEG FFT9h -107.42 -27.291 85 + EEG FFT7h -85.294 -28.418 85 + EEG FFC5h -65.525 -34.337 85 + EEG FFC3h -47.97 -47.02 85 + EEG FFC1h -35.992 -72.367 85 + EEG FFC2h 35.992 72.367 85 + EEG FFC4h 47.944 47.077 85 + EEG FFC6h 65.577 34.337 85 + EEG FFT8h 85.294 28.418 85 + EEG FFT10h 107.4 27.263 85 + EEG FTT9h -107.94 -9.1355 85 + EEG FTT7h -84.139 -9.5002 85 + EEG FCC5h -60.628 -11.865 85 + EEG FCC3h -37.497 -18.197 85 + EEG FCC1h -16.49 -44 85 + EEG FCC2h 16.513 43.86 85 + EEG FCC4h 37.497 18.197 85 + EEG FCC6h 60.655 11.851 85 + EEG FTT8h 84.145 9.4907 85 + EEG FTT10h 107.94 9.1355 85 + EEG TTP9h -107.94 9.1355 85 + EEG TTP7h -84.139 9.5002 85 + EEG CCP5h -60.628 11.865 85 + EEG CCP3h -37.497 18.197 85 + EEG CCP1h -16.49 44 85 + EEG CCP2h 16.513 -43.86 85 + EEG CCP4h 37.497 -18.197 85 + EEG CCP6h 60.655 -11.851 85 + EEG TTP8h 84.145 -9.4907 85 + EEG TTP10h 107.94 -9.1355 85 + EEG TPP9h -107.42 27.291 85 + EEG TPP7h -85.294 28.418 85 + EEG CPP5h -65.525 34.337 85 + EEG CPP3h -47.97 47.02 85 + EEG CPP1h -35.992 72.367 85 + EEG CPP2h 35.992 -72.367 85 + EEG CPP4h 47.944 -47.077 85 + EEG CPP6h 65.577 -34.337 85 + EEG TPP8h 85.294 -28.418 85 + EEG TPP10h 107.4 -27.263 85 + EEG PPO9h -106.39 45.423 85 + EEG PPO7h -87.419 47.151 85 + EEG PPO5h -74.258 54.227 85 + EEG PPO3h -63.752 65.551 85 + EEG PPO1h -57.79 81.161 85 + EEG PPO2h 57.785 -81.228 85 + EEG PPO4h 63.804 -65.551 85 + EEG PPO6h 74.267 -54.178 85 + EEG PPO8h 87.418 -47.193 85 + EEG PPO10h 106.4 -45.381 85 + EEG POO9h -105.02 63.355 85 + EEG POO7h -90.401 65.641 85 + EEG POO5h -85.465 71.565 85 + EEG POO3h -81.886 78.451 85 + EEG POO1h -80.031 86.097 85 + EEG POO2h 80.032 -86.039 85 + EEG POO4h 81.886 -78.451 85 + EEG POO6h 85.465 -71.565 85 + EEG POO8h 90.401 -65.589 85 + EEG POO10h 105.03 -63.329 85 + EEG OI1h -103.42 81.128 85 + EEG OI2h 103.43 -81.119 85 + EEG Fp1h -91.951 -81.066 85 + EEG Fp2h 91.951 81.009 85 + EEG AF9h -105.74 -54.393 85 + EEG AF7h -88.796 -56.469 85 + EEG AF5h -79.619 -63.2 85 + EEG AF3h -72.656 -72.496 85 + EEG AF1h -68.886 -83.904 85 + EEG AF2h 68.939 83.904 85 + EEG AF4h 72.651 72.553 85 + EEG AF6h 79.619 63.2 85 + EEG AF8h 88.853 56.517 85 + EEG AF10h 105.74 54.393 85 + EEG F9h -106.98 -36.367 85 + EEG F7h -86.213 -37.789 85 + EEG F5h -69.502 -44.567 85 + EEG F3h -55.454 -57.294 85 + EEG F1h -46.82 -77.642 85 + EEG F2h 46.82 77.642 85 + EEG F4h 55.454 57.294 85 + EEG F6h 69.502 44.567 85 + EEG F8h 86.213 37.789 85 + EEG F10h 106.93 36.367 85 + EEG FT9h -107.72 -18.187 85 + EEG FT7h -84.603 -18.945 85 + EEG FC5h -62.534 -23.385 85 + EEG FC3h -41.758 -34.216 85 + EEG FC1h -25.615 -63.198 85 + EEG FC2h 25.592 63.316 85 + EEG FC4h 41.758 34.216 85 + EEG FC6h 62.534 23.385 85 + EEG FT8h 84.547 18.999 85 + EEG FT10h 107.72 18.187 85 + EEG T9h -108.02 0 85 + EEG T7h -83.97 0 85 + EEG C5h -59.971 0 85 + EEG C3h -35.998 0 85 + EEG C1h -12.007 0 85 + EEG C2h 12.007 0 85 + EEG C4h 35.964 0 85 + EEG C6h 59.971 0 85 + EEG T8h 83.97 0 85 + EEG T10h 108.02 0 85 + EEG TP9h -107.72 18.187 85 + EEG TP7h -84.603 18.945 85 + EEG CP5h -62.534 23.385 85 + EEG CP3h -41.758 34.216 85 + EEG CP1h -25.615 63.198 85 + EEG CP2h 25.592 -63.316 85 + EEG CP4h 41.758 -34.216 85 + EEG CP6h 62.534 -23.385 85 + EEG TP8h 84.604 -18.999 85 + EEG TP10h 107.72 -18.187 85 + EEG P9h -106.98 36.367 85 + EEG P7h -86.213 37.789 85 + EEG P5h -69.502 44.567 85 + EEG P3h -55.454 57.294 85 + EEG P1h -46.82 77.642 85 + EEG P2h 46.82 -77.642 85 + EEG P4h 55.454 -57.294 85 + EEG P6h 69.502 -44.567 85 + EEG P8h 86.213 -37.789 85 + EEG P10h 106.93 -36.367 85 + EEG PO9h -105.74 54.393 85 + EEG PO7h -88.796 56.469 85 + EEG PO5h -79.619 63.2 85 + EEG PO3h -72.656 72.496 85 + EEG PO1h -68.886 83.904 85 + EEG PO2h 68.939 -83.904 85 + EEG PO4h 72.651 -72.553 85 + EEG PO6h 79.619 -63.2 85 + EEG PO8h 88.853 -56.517 85 + EEG PO10h 105.74 -54.393 85 + EEG O1h -91.951 81.066 85 + EEG O2h 91.951 -81.009 85 + EEG I1h -114.91 81.307 85 + EEG I2h 114.91 -81.307 85 + EEG AFp9 -116.7 -63.665 85 + EEG AFp7 -93.384 -63.127 85 + EEG AFp5 -87.764 -68.444 85 + EEG AFp3 -83.447 -74.871 85 + EEG AFp1 -80.728 -82.19 85 + EEG AFpz 79.793 90 85 + EEG AFp2 80.728 82.19 85 + EEG AFp4 83.502 74.927 85 + EEG AFp6 87.764 68.444 85 + EEG AFp8 93.384 63.127 85 + EEG AFp10 116.7 63.665 85 + EEG AFF9 -118.25 -45.782 85 + EEG AFF7 -94.591 -45.122 85 + EEG AFF5 -80.608 -50.187 85 + EEG AFF3 -68.622 -59.353 85 + EEG AFF1 -60.101 -72.946 85 + EEG AFFz 57.01 90 85 + EEG AFF2 60.101 72.946 85 + EEG AFF4 68.579 59.3 85 + EEG AFF6 80.608 50.187 85 + EEG AFF8 94.591 45.122 85 + EEG AFF10 118.25 45.782 85 + EEG FFT9 -119.34 -27.535 85 + EEG FFT7 -95.458 -27.106 85 + EEG FFC5 -75.279 -30.73 85 + EEG FFC3 -56.333 -39.585 85 + EEG FFC1 -40.896 -57.744 85 + EEG FFCz 34.231 90 85 + EEG FFC2 40.859 57.744 85 + EEG FFC4 56.333 39.585 85 + EEG FFC6 75.266 30.76 85 + EEG FFT8 95.453 27.08 85 + EEG FFT10 119.36 27.565 85 + EEG FTT9 -119.94 -9.234 85 + EEG FTT7 -95.914 -9.0265 85 + EEG FCC5 -72.356 -10.402 85 + EEG FCC3 -49.021 -14.202 85 + EEG FCC1 -26.414 -25.873 85 + EEG FCCz 11.377 90 85 + EEG FCC2 26.389 25.873 85 + EEG FCC4 48.978 14.202 85 + EEG FCC6 72.356 10.402 85 + EEG FTT8 95.92 9.0356 85 + EEG FTT10 119.89 9.234 85 + EEG TTP9 -119.94 9.234 85 + EEG TTP7 -95.914 9.0265 85 + EEG CCP5 -72.356 10.402 85 + EEG CCP3 -49.021 14.202 85 + EEG CCP1 -26.414 25.873 85 + EEG CCPz 11.377 -90 85 + EEG CCP2 26.389 -25.873 85 + EEG CCP4 48.978 -14.202 85 + EEG CCP6 72.356 -10.402 85 + EEG TTP8 95.92 -9.0356 85 + EEG TTP10 119.89 -9.234 85 + EEG TPP9 -119.34 27.535 85 + EEG TPP7 -95.458 27.106 85 + EEG CPP5 -75.279 30.73 85 + EEG CPP3 -56.333 39.585 85 + EEG CPP1 -40.896 57.744 85 + EEG CPPz 34.231 -90 85 + EEG CPP2 40.859 -57.744 85 + EEG CPP4 56.333 -39.585 85 + EEG CPP6 75.266 -30.76 85 + EEG TPP8 95.453 -27.08 85 + EEG TPP10 119.36 -27.565 85 + EEG PPO9 -118.25 45.782 85 + EEG PPO7 -94.591 45.122 85 + EEG PPO5 -80.608 50.187 85 + EEG PPO3 -68.622 59.353 85 + EEG PPO1 -60.109 72.883 85 + EEG PPOz 57.01 -90 85 + EEG PPO2 60.101 -72.946 85 + EEG PPO4 68.579 -59.3 85 + EEG PPO6 80.608 -50.187 85 + EEG PPO8 94.591 -45.122 85 + EEG PPO10 118.25 -45.782 85 + EEG POO9 -116.7 63.665 85 + EEG POO7 -93.384 63.127 85 + EEG POO5 -87.764 68.444 85 + EEG POO3 -83.447 74.871 85 + EEG POO1 -80.728 82.19 85 + EEG POOz 79.793 -90 85 + EEG POO2 80.728 -82.19 85 + EEG POO4 83.502 -74.927 85 + EEG POO6 87.764 -68.444 85 + EEG POO8 93.384 -63.127 85 + EEG POO10 116.7 -63.665 85 + EEG OI1 -104.24 72.276 85 + EEG OIz 102.6 -90 85 + EEG OI2 104.26 -72.258 85 + EEG T3 -95.973 0 85 + EEG T5 -95.055 36.087 85 + EEG T4 95.973 0 85 + EEG T6 95.052 -36.133 85 + EEG M1 -134.52 10.419 85 + EEG M2 134.52 -10.419 85 + EEG A1 -135 0 85 + EEG A2 135 0 85 + EOG VEOG 125 63 85 + EOG HEOG -118 -48 85 + EOG EOG1 125 63 85 + EOG EOG2 -118 -48 85 + EOG LO1 -118 -48 85 + EOG LO2 118 48 85 + EOG IO1 -125 -63 85 + EOG IO2 125 63 85 + EOG SO1 -105 -65 85 + EOG SO2 105 65 85 diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/standard_BESA.mat b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/standard_BESA.mat new file mode 100644 index 0000000000000000000000000000000000000000..34a1bec46344282e74add7795d5e2f016f58e224 Binary files /dev/null and b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/standard_BESA.mat differ diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/standard_SCCN.mat b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/standard_SCCN.mat new file mode 100644 index 0000000000000000000000000000000000000000..472c8871a362463ed377bd557f886f2d5356e1d9 Binary files /dev/null and b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/standard_BESA/standard_SCCN.mat differ diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/traditionaldipfit.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/traditionaldipfit.m new file mode 100644 index 0000000000000000000000000000000000000000..120e7009ab153cbbfeabbe5dd93d7e93730a4609 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/traditionaldipfit.m @@ -0,0 +1,90 @@ +function [H] = traditionaldipfit(f); + +% TRADITIONALDIPFIT creates the homogenous spatial transformation matrix +% for a 9 parameter traditionaldipfit "Talairach-model" transformation +% +% H = traditionaldipfit(f) +% +% The transformation vector f should contain the +% x-shift +% y-shift +% z-shift +% (in length-units of the coordinate system used. For the MNI brain +% the unit is mm) +% followed by the +% pitch (rotation around x-axis) +% roll (rotation around y-axis) +% yaw (rotation around z-axis) +% (in radians) +% followed by the +% x-rescaling factor +% y-rescaling factor +% z-rescaling factor +% (in ratio = newscale/oldscale) +% +% H first applies scaling, then rotations, and finally the shifts. +% +% See also fieldtrip*/WARP3D.m + +% Copyright (C) 2000-2004, Robert Oostenveld +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +% compute the homogenous transformation matrix for the translation +if length(f) == 6, f(7:9) = 1; end; + +T = eye(4,4); +if isa( f, 'sym') + T = sym(T); +end; +T(1,4) = f(1); +T(2,4) = f(2); +T(3,4) = f(3); + +% precompute the sin/cos values of the angles +cX = cos(f(4)); +cY = cos(f(5)); +cZ = cos(f(6)); +sX = sin(f(4)); +sY = sin(f(5)); +sZ = sin(f(6)); + +% compute the homogenous transformation matrix for the rotation +R = eye(4,4); +if isa( f, 'sym') + R = sym(R); +end; +R(1,1) = cZ*cY + sZ*sX*sY; +R(1,2) = sZ*cY + cZ*sX*sY; +R(1,3) = cX*sY; +R(2,1) = -sZ*cX; +R(2,2) = cZ*cX; +R(2,3) = sX; +R(3,1) = sZ*sX*cY - cZ*sY; +R(3,2) = -cZ*sX*cY - sZ*sY; +R(3,3) = cX*cY; + +% compute the homogenous transformation matrix for the scaling +S = eye(4,4); +if isa( f, 'sym') + S = sym(S); +end; +S(1,1) = f(7); +S(2,2) = f(8); +S(3,3) = f(9); + +% compute the homogenous coordinate transformation matrix for use by WARP3D +H = T*R*S; + diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/changelog.txt b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/changelog.txt new file mode 100644 index 0000000000000000000000000000000000000000..e5915032dc096f0e1e4711b4c42b07511acce3c3 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/changelog.txt @@ -0,0 +1,57 @@ +Version 1.6 +- ENH: minimum-phase conversion and causal filtering + +Version 1.5.5 +- CHG: menu + +Version 1.5.4 +- CHG: menu order + +Version 1.5.3 +- CHG: new TBW heuristic for pop_eegfiltnew.m + +Version 1.5.2 +- CHG: warning message + +Version 1.5.1 +- CHG: removed dependency on EEGLAB fastif function +- CHG: removed pop_xfirws dependency on EEGLAB for command line use +- BUG: plotting of frequency response with empty window parameters +- BUG: error in firws documentation +- ENH: improved pop_xfirws command line usability + +Version 1.5 +- BUG: pop_firpm compatibility with R14 and earlier. +- CHG: command line progress indicator. + +Version 1.4 +- BUG: duplicate boundary event handling. +- CHG: waitbar replaced by command line progress indicator. + +Version 1.3 +- NEW: pop_eegfiltnew. +- BUG: ETA calculation. + +Version 1.2 +- CHG: filter with double precision. + +Version 1.1 +- NEW: added pop_xfirws to design and export EEProbe compatible filters. +- BUG: compatibility with R14 and earlier. +- NEW: Tukey windows. + +Version 1.0 +- CHG: removed misleading default value for filter order. +- CHG: moved to EEGLAB filter menu. +- CHG: code cleaning and formatting. + +Version 0.92 +- ENH: optimized filter strategy. +- ENH: waitbar. +- CHG: avoid eval function. + +Version 0.91 +- BUG: check for empty boundaries vector. + +Version 0.9 +starting, initial public release. diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/eegplugin_firfilt.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/eegplugin_firfilt.m new file mode 100644 index 0000000000000000000000000000000000000000..164b7a618de327158aaf1aec89f2207bba4431ef --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/eegplugin_firfilt.m @@ -0,0 +1,64 @@ +% eegplugin_firfilt() - EEGLAB plugin for filtering data using linear- +% phase FIR filters +% +% Usage: +% >> eegplugin_firfilt(fig, trystrs, catchstrs); +% +% Inputs: +% fig - [integer] EEGLAB figure +% trystrs - [struct] "try" strings for menu callbacks. +% catchstrs - [struct] "catch" strings for menu callbacks. +% +% Author: Andreas Widmann, University of Leipzig, Germany, 2005 + +%123456789012345678901234567890123456789012345678901234567890123456789012 + +% Copyright (C) 2005 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function vers = eegplugin_firfilt(fig, trystrs, catchstrs) + + vers = 'firfilt1.6.1'; + if nargin < 3 + error('eegplugin_firfilt requires 3 arguments'); + end + + % add folder to path + % ----------------------- + if ~exist('pop_firws') + p = which('eegplugin_firfilt'); + p = p(1:findstr(p,'eegplugin_firfilt.m')-1); + addpath([p vers]); + end + + % find import data menu + % --------------------- + menu = findobj(fig, 'tag', 'filter'); + + % menu callbacks + % -------------- + comfirfiltnew = [trystrs.no_check '[EEG LASTCOM] = pop_eegfiltnew(EEG);' catchstrs.new_and_hist]; + comfirws = [trystrs.no_check '[EEG LASTCOM] = pop_firws(EEG);' catchstrs.new_and_hist]; + comfirpm = [trystrs.no_check '[EEG LASTCOM] = pop_firpm(EEG);' catchstrs.new_and_hist]; + comfirma = [trystrs.no_check '[EEG LASTCOM] = pop_firma(EEG);' catchstrs.new_and_hist]; + + % create menus if necessary + % ------------------------- + uimenu( menu, 'Label', 'Basic FIR filter (new, default)', 'CallBack', comfirfiltnew, 'Separator', 'on', 'position', 1); + uimenu( menu, 'Label', 'Windowed sinc FIR filter', 'CallBack', comfirws, 'position', 2); + uimenu( menu, 'Label', 'Parks-McClellan (equiripple) FIR filter', 'CallBack', comfirpm, 'position', 3); + uimenu( menu, 'Label', 'Moving average FIR filter', 'CallBack', comfirma, 'position', 4); + \ No newline at end of file diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/findboundaries.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/findboundaries.m new file mode 100644 index 0000000000000000000000000000000000000000..843355869c55cfcc7fd7349dd0c3d732f15689bf --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/findboundaries.m @@ -0,0 +1,58 @@ +% findboundaries() - Find boundaries (data discontinuities) in event +% structure of continuous EEG dataset +% +% Usage: +% >> boundaries = findboundaries(EEG.event); +% +% Inputs: +% EEG.event - EEGLAB EEG event structure +% +% Outputs: +% boundaries - scalar or vector of boundary event latencies +% +% Author: Andreas Widmann, University of Leipzig, 2005 + +%123456789012345678901234567890123456789012345678901234567890123456789012 + +% Copyright (C) 2005 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function boundaries = findboundaries(event) + +if isfield(event, 'type') & isfield(event, 'latency') & cellfun('isclass', {event.type}, 'char') + + % Boundary event indices + boundaries = strmatch('boundary', {event.type}); + + % Boundary event latencies + boundaries = [event(boundaries).latency]; + + % Shift boundary events to epoch onset + boundaries = fix(boundaries + 0.5); + + % Remove duplicate boundary events + boundaries = unique(boundaries); + + % Epoch onset at first sample? + if isempty(boundaries) || boundaries(1) ~= 1 + boundaries = [1 boundaries]; + end + +else + + boundaries = 1; + +end diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/firfilt.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/firfilt.m new file mode 100644 index 0000000000000000000000000000000000000000..c28efc679c9490da557592c18f9c454d36f2bd52 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/firfilt.m @@ -0,0 +1,123 @@ +% firfilt() - Pad data with DC constant, filter data with FIR filter, +% and shift data by the filter's group delay +% +% Usage: +% >> EEG = firfilt(EEG, b, nFrames); +% +% Inputs: +% EEG - EEGLAB EEG structure +% b - vector of filter coefficients +% +% Optional inputs: +% nFrames - number of frames to filter per block {default 1000} +% +% Outputs: +% EEG - EEGLAB EEG structure +% +% Note: +% Higher values for nFrames increase speed and working memory +% requirements. +% +% Author: Andreas Widmann, University of Leipzig, 2005 +% +% See also: +% filter, findboundaries + +%123456789012345678901234567890123456789012345678901234567890123456789012 + +% Copyright (C) 2005 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function EEG = firfilt(EEG, b, nFrames) + +if nargin < 2 + error('Not enough input arguments.'); +end +if nargin < 3 || isempty(nFrames) + nFrames = 1000; +end + +% Filter's group delay +if mod(length(b), 2) ~= 1 + error('Filter order is not even.'); +end +groupDelay = (length(b) - 1) / 2; + +% Find data discontinuities and reshape epoched data +if EEG.trials > 1 % Epoched data + EEG.data = reshape(EEG.data, [EEG.nbchan EEG.pnts * EEG.trials]); + dcArray = 1 : EEG.pnts : EEG.pnts * (EEG.trials + 1); +else % Continuous data + dcArray = [findboundaries(EEG.event) EEG.pnts + 1]; +end + +% Initialize progress indicator +nSteps = 20; +step = 0; +fprintf(1, 'firfilt(): |'); +strLength = fprintf(1, [repmat(' ', 1, nSteps - step) '| 0%%']); +tic + +for iDc = 1:(length(dcArray) - 1) + + % Pad beginning of data with DC constant and get initial conditions + ziDataDur = min(groupDelay, dcArray(iDc + 1) - dcArray(iDc)); + [temp, zi] = filter(b, 1, double([EEG.data(:, ones(1, groupDelay) * dcArray(iDc)) ... + EEG.data(:, dcArray(iDc):(dcArray(iDc) + ziDataDur - 1))]), [], 2); + + blockArray = [(dcArray(iDc) + groupDelay):nFrames:(dcArray(iDc + 1) - 1) dcArray(iDc + 1)]; + for iBlock = 1:(length(blockArray) - 1) + + % Filter the data + [EEG.data(:, (blockArray(iBlock) - groupDelay):(blockArray(iBlock + 1) - groupDelay - 1)), zi] = ... + filter(b, 1, double(EEG.data(:, blockArray(iBlock):(blockArray(iBlock + 1) - 1))), zi, 2); + + % Update progress indicator + [step, strLength] = mywaitbar((blockArray(iBlock + 1) - groupDelay - 1), size(EEG.data, 2), step, nSteps, strLength); + end + + % Pad end of data with DC constant + temp = filter(b, 1, double(EEG.data(:, ones(1, groupDelay) * (dcArray(iDc + 1) - 1))), zi, 2); + EEG.data(:, (dcArray(iDc + 1) - ziDataDur):(dcArray(iDc + 1) - 1)) = ... + temp(:, (end - ziDataDur + 1):end); + + % Update progress indicator + [step, strLength] = mywaitbar((dcArray(iDc + 1) - 1), size(EEG.data, 2), step, nSteps, strLength); + +end + +% Reshape epoched data +if EEG.trials > 1 + EEG.data = reshape(EEG.data, [EEG.nbchan EEG.pnts EEG.trials]); +end + +% Deinitialize progress indicator +fprintf(1, '\n') + +end + +function [step, strLength] = mywaitbar(compl, total, step, nSteps, strLength) + +progStrArray = '/-\|'; +tmp = floor(compl / total * nSteps); +if tmp > step + fprintf(1, [repmat('\b', 1, strLength) '%s'], repmat('=', 1, tmp - step)) + step = tmp; + ete = ceil(toc / step * (nSteps - step)); + strLength = fprintf(1, [repmat(' ', 1, nSteps - step) '%s %3d%%, ETE %02d:%02d'], progStrArray(mod(step - 1, 4) + 1), floor(step * 100 / nSteps), floor(ete / 60), mod(ete, 60)); +end + +end diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/firfiltdcpadded.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/firfiltdcpadded.m new file mode 100644 index 0000000000000000000000000000000000000000..4b37c62b0a32b128876377ac2e8e12621fab2e28 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/firfiltdcpadded.m @@ -0,0 +1,75 @@ +% firfiltdcpadded() - Pad data with DC constant and filter +% +% Usage: +% >> data = firfiltdcpadded(data, b, causal); +% +% Inputs: +% data - raw data +% b - vector of filter coefficients +% causal - boolean perform causal filtering {default 0} +% +% Outputs: +% data - smoothed data +% +% Note: +% firfiltdcpadded always operates (pads, filters) along first dimension. +% Not memory optimized. +% +% Author: Andreas Widmann, University of Leipzig, 2013 +% +% See also: +% firfiltsplit + +%123456789012345678901234567890123456789012345678901234567890123456789012 + +% Copyright (C) 2013 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function [ data ] = firfiltdcpadded(b, data, causal) + +% Defaults +if nargin < 3 || isempty(causal) + causal = 0; +end + +% Check arguments +if nargin < 2 + error('Not enough input arguments.'); +end + +% Filter's group delay +if mod(length(b), 2) ~= 1 + error('Filter order is not even.'); +end +groupDelay = (length(b) - 1) / 2; +b = double(b); % Filter with double precision + +% Pad data with DC constant +if causal + startPad = repmat(data(1, :), [2 * groupDelay 1]); + endPad = []; +else + startPad = repmat(data(1, :), [groupDelay 1]); + endPad = repmat(data(end, :), [groupDelay 1]); +end + +% Filter data +data = filter(b, 1, double([startPad; data; endPad])); % Pad and filter with double precision + +% Remove padded data +data = data(2 * groupDelay + 1:end, :); + +end diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/firfiltsplit.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/firfiltsplit.m new file mode 100644 index 0000000000000000000000000000000000000000..55857960659b5284360b36c3a803c291845051bc --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/firfiltsplit.m @@ -0,0 +1,73 @@ +% firfiltsplit() - Split data at discontinuities and forward to dc padded +% filter function +% +% Usage: +% >> EEG = firfiltsplit(EEG, b); +% +% Inputs: +% EEG - EEGLAB EEG structure +% b - vector of filter coefficients +% causal - scalar boolean perform causal filtering {default 0} +% +% Outputs: +% EEG - EEGLAB EEG structure +% +% Note: +% This function is (in combination with firfiltdcpadded) just a +% non-memory optimized version of the firfilt function allowing causal +% filtering. Will possibly replace firfilt in the future. +% +% Author: Andreas Widmann, University of Leipzig, 2013 +% +% See also: +% firfiltdcpadded, findboundaries + +%123456789012345678901234567890123456789012345678901234567890123456789012 + +% Copyright (C) 2013 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function EEG = firfiltsplit(EEG, b, causal) + +if nargin < 3 || isempty(causal) + causal = 0; +end +if nargin < 2 + error('Not enough input arguments.'); +end + +% Find data discontinuities and reshape epoched data +if EEG.trials > 1 % Epoched data + EEG.data = reshape(EEG.data, [EEG.nbchan EEG.pnts * EEG.trials]); + dcArray = 1 : EEG.pnts : EEG.pnts * (EEG.trials + 1); +else % Continuous data + dcArray = [findboundaries(EEG.event) EEG.pnts + 1]; +end + +% Loop over continuous segments +for iDc = 1:(length(dcArray) - 1) + + % Filter segment + EEG.data(:, dcArray(iDc):dcArray(iDc + 1) - 1) = firfiltdcpadded(b, EEG.data(:, dcArray(iDc):dcArray(iDc + 1) - 1)', causal)'; + +end + +% Reshape epoched data +if EEG.trials > 1 + EEG.data = reshape(EEG.data, [EEG.nbchan EEG.pnts EEG.trials]); +end + +end diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/firws.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/firws.m new file mode 100644 index 0000000000000000000000000000000000000000..cbe423e7a3a821d255fc7cf96161bebf9824e181 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/firws.m @@ -0,0 +1,106 @@ +%firws() - Designs windowed sinc type I linear phase FIR filter +% +% Usage: +% >> b = firws(m, f); +% >> b = firws(m, f, w); +% >> b = firws(m, f, t); +% >> b = firws(m, f, t, w); +% +% Inputs: +% m - filter order (mandatory even) +% f - vector or scalar of cutoff frequency/ies (-6 dB; +% pi rad / sample) +% +% Optional inputs: +% w - vector of length m + 1 defining window {default blackman} +% t - 'high' for highpass, 'stop' for bandstop filter {default low-/ +% bandpass} +% +% Output: +% b - filter coefficients +% +% Example: +% fs = 500; cutoff = 0.5; tbw = 1; +% m = pop_firwsord('hamming', fs, tbw); +% b = firws(m, cutoff / (fs / 2), 'high', windows('hamming', m + 1)); +% +% References: +% Smith, S. W. (1999). The scientist and engineer's guide to digital +% signal processing (2nd ed.). San Diego, CA: California Technical +% Publishing. +% +% Author: Andreas Widmann, University of Leipzig, 2005 +% +% See also: +% pop_firws, pop_firwsord, pop_kaiserbeta, windows + +%123456789012345678901234567890123456789012345678901234567890123456789012 + +% Copyright (C) 2005 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function [b a] = firws(m, f, t, w) + + a = 1; + + if nargin < 2 + error('Not enough input arguments'); + end + if length(m) > 1 || ~isnumeric(m) || ~isreal(m) || mod(m, 2) ~= 0 || m < 2 + error('Filter order must be a real, even, positive integer.'); + end + f = f / 2; + if any(f <= 0) || any(f >= 0.5) + error('Frequencies must fall in range between 0 and 1.'); + end + if nargin < 3 || isempty(t) + t = ''; + end + if nargin < 4 || isempty(w) + if ~isempty(t) && ~ischar(t) + w = t; + t = ''; + else + w = windows('blackman', (m + 1)); + end + end + w = w(:)'; % Make window row vector + + b = fkernel(m, f(1), w); + + if length(f) == 1 && strcmpi(t, 'high') + b = fspecinv(b); + end + + if length(f) == 2 + b = b + fspecinv(fkernel(m, f(2), w)); + if isempty(t) || ~strcmpi(t, 'stop') + b = fspecinv(b); + end + end + +% Compute filter kernel +function b = fkernel(m, f, w) + m = -m / 2 : m / 2; + b(m == 0) = 2 * pi * f; % No division by zero + b(m ~= 0) = sin(2 * pi * f * m(m ~= 0)) ./ m(m ~= 0); % Sinc + b = b .* w; % Window + b = b / sum(b); % Normalization to unity gain at DC + +% Spectral inversion +function b = fspecinv(b) + b = -b; + b(1, (length(b) - 1) / 2 + 1) = b(1, (length(b) - 1) / 2 + 1) + 1; diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/minphaserceps.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/minphaserceps.m new file mode 100644 index 0000000000000000000000000000000000000000..9180f2db87b0b4a19fa13990ad743c7f9c7a9c86 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/minphaserceps.m @@ -0,0 +1,46 @@ +% rcepsminphase() - Convert FIR filter coefficient to minimum phase +% +% Usage: +% >> b = minphaserceps(b); +% +% Inputs: +% b - FIR filter coefficients +% +% Outputs: +% bMinPhase - minimum phase FIR filter coefficients +% +% Author: Andreas Widmann, University of Leipzig, 2013 +% +% References: +% [1] Smith III, O. J. (2007). Introduction to Digital Filters with Audio +% Applications. W3K Publishing. Retrieved Nov 11 2013, from +% https://ccrma.stanford.edu/~jos/fp/Matlab_listing_mps_m.html +% [2] Vetter, K. (2013, Nov 11). Long FIR filters with low latency. +% Retrieved Nov 11 2013, from +% http://www.katjaas.nl/minimumphase/minimumphase.html + +function [bMinPhase] = minphaserceps(b) + +% Line vector +b = b(:)'; + +n = length(b); +upsamplingFactor = 1e3; % Impulse response upsampling/zero padding to reduce time-aliasing +nFFT = 2^ceil(log2(n * upsamplingFactor)); % Power of 2 +clipThresh = 1e-8; % -160 dB + +% Spectrum +s = abs(fft(b, nFFT)); +s(s < clipThresh) = clipThresh; % Clip spectrum to reduce time-aliasing + +% Real cepstrum +c = real(ifft(log(s))); + +% Fold +c = [c(1) [c(2:nFFT / 2) 0] + conj(c(nFFT:-1:nFFT / 2 + 1)) zeros(1, nFFT / 2 - 1)]; + +% Minimum phase +bMinPhase = real(ifft(exp(fft(c)))); + +% Remove zero-padding +bMinPhase = bMinPhase(1:n); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/plotfresp.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/plotfresp.m new file mode 100644 index 0000000000000000000000000000000000000000..4a611d5651c03200c8ff48317872a1605864a7e3 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/plotfresp.m @@ -0,0 +1,137 @@ +% plotfresp() - Plot FIR filter's impulse, step, frequency, magnitude, +% and phase response +% +% Usage: +% >> plotfresp(b, a, n, fs); +% +% Inputs: +% b - vector filter coefficients +% +% Optional inputs: +% a - currently unused, reserved for future compatibility with IIR +% filters {default 1} +% n - scalar number of points +% fs - scalar sampling frequency +% +% Author: Andreas Widmann, University of Leipzig, 2005 +% +% See also: +% pop_firws, pop_firpm, pop_firma + +%123456789012345678901234567890123456789012345678901234567890123456789012 + +% Copyright (C) 2005 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function plotfresp(b, a, nfft, fs, causal) + +if nargin < 5 || isempty(causal) + causal = 0; +end +if nargin < 4 || isempty(fs) + fs = 1; +end +if nargin < 3 || isempty(nfft) + nfft = 2^fix(log2(length(b))); + if nfft < 512 + nfft = 512; + end +end +if nargin < 1 + error('Not enough input arguments.'); +end + +n = length(b); +f = (0:1 / nfft:1) * fs / 2; + +% Impulse resonse +if causal, xval = 0:n-1; else xval = -(n - 1) / 2:(n - 1) / 2; end +ax(1) = subplot(2, 3, 1); +stem(xval, b, 'fill') +title('Impulse response'); +ylabel('Amplitude'); + +% Step response +ax(4) = subplot(2, 3, 4); +stem(xval, cumsum(b), 'fill'); +title('Step response'); +foo = ylim; +if foo(2) < -foo(1) + 1; + foo(2) = -foo(1) + 1; + ylim(foo); +end +xMin = []; xMax = []; +children = get(ax(4), 'Children'); +for child =1:length(children) + xData = get(children(child), 'XData'); + xMin = min([xMin min(xData)]); + xMax = max([xMax max(xData)]); +end +set(ax([1 4]), 'xlim', [xMin xMax]); +ylabel('Amplitude'); + +% Frequency response +ax(2) = subplot(2, 3, 2); +m = fix((length(b) - 1) / 2); % Filter order +z = fft(b, nfft * 2); +z = z(1:fix(length(z) / 2) + 1); +% foo = real(abs(z) .* exp(-i * (angle(z) + [0:1 / nfft:1] * m * pi))); % needs further testing +plot(f, abs(z)); +title('Frequency response'); +ylabel('Amplitude'); + +% Magnitude response +ax(5) = subplot(2, 3, 5); +db = abs(z); +db(db < eps^(2 / 3)) = eps^(2 / 3); % Log of zero warning +plot(f, 20 * log10(db)); +title('Magnitude response'); +foo = ylim; +if foo(1) < 20 * log10(eps^(2 / 3)) + foo(1) = 20 * log10(eps^(2 / 3)); +end +ylabel('Magnitude (dB)'); +ylim(foo); + +% Phase response +ax(3) = subplot(2, 3, 3); +z(abs(z) < eps^(2 / 3)) = NaN; % Phase is undefined for magnitude zero +phi = angle(z); +if causal + phi = unwrap(phi); +else + delay = -mod((0:1 / nfft:1) * m * pi + pi, 2 * pi) + pi; % Zero-phase + phi = phi - delay; + phi = phi + 2 * pi * (phi <= -pi + eps ^ (1/3)); % Unwrap +end +plot(f, phi); +title('Phase response'); +ylabel('Phase (rad)'); +% ylim([-pi / 2 1.5 * pi]); + +set(ax(1:5), 'ygrid', 'on', 'xgrid', 'on', 'box', 'on'); +titles = get(ax(1:5), 'title'); +set([titles{:}], 'fontweight', 'bold'); +xlabels = get(ax(1:5), 'xlabel'); +if fs == 1 + set([xlabels{[2 3 5]}], 'String', 'Normalized frequency (2 pi rad / sample)'); +else + set([xlabels{[2 3 5]}], 'String', 'Frequency (Hz)'); +end +set([xlabels{[1 4]}], 'String', 'Sample'); +set(ax([2 3 5]), 'xlim', [0 fs / 2]); +set(ax(1:5), 'colororder', circshift(get(ax(1), 'colororder'), -1)); +set(ax(1:5), 'nextplot', 'add'); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_eegfiltnew.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_eegfiltnew.m new file mode 100644 index 0000000000000000000000000000000000000000..1841d4b75a4fefb83bed1afde3874bfee3d293f9 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_eegfiltnew.m @@ -0,0 +1,234 @@ +% pop_eegfiltnew() - Filter data using Hamming windowed sinc FIR filter +% +% Usage: +% >> [EEG, com, b] = pop_eegfiltnew(EEG); % pop-up window mode +% >> [EEG, com, b] = pop_eegfiltnew(EEG, locutoff, hicutoff, filtorder, +% revfilt, usefft, plotfreqz, minphase); +% +% Inputs: +% EEG - EEGLAB EEG structure +% locutoff - lower edge of the frequency pass band (Hz) +% {[]/0 -> lowpass} +% hicutoff - higher edge of the frequency pass band (Hz) +% {[]/0 -> highpass} +% +% Optional inputs: +% filtorder - filter order (filter length - 1). Mandatory even +% revfilt - [0|1] invert filter (from bandpass to notch filter) +% {default 0 (bandpass)} +% usefft - ignored (backward compatibility only) +% plotfreqz - [0|1] plot filter's frequency and phase response +% {default 0} +% minphase - scalar boolean minimum-phase converted causal filter +% {default false} +% +% Outputs: +% EEG - filtered EEGLAB EEG structure +% com - history string +% b - filter coefficients +% +% Note: +% pop_eegfiltnew is intended as a replacement for the deprecated +% pop_eegfilt function. Required filter order/transition band width is +% estimated with the following heuristic in default mode: transition band +% width is 25% of the lower passband edge, but not lower than 2 Hz, where +% possible (for bandpass, highpass, and bandstop) and distance from +% passband edge to critical frequency (DC, Nyquist) otherwise. Window +% type is hardcoded to Hamming. Migration to windowed sinc FIR filters +% (pop_firws) is recommended. pop_firws allows user defined window type +% and estimation of filter order by user defined transition band width. +% +% Author: Andreas Widmann, University of Leipzig, 2012 +% +% See also: +% firfilt, firws, windows + +%123456789012345678901234567890123456789012345678901234567890123456789012 + +% Copyright (C) 2008 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function [EEG, com, b] = pop_eegfiltnew(EEG, locutoff, hicutoff, filtorder, revfilt, usefft, plotfreqz, minphase) + +com = ''; + +if nargin < 1 + help pop_eegfiltnew; + return +end +if isempty(EEG.data) + error('Cannot filter empty dataset.'); +end + +% GUI +if nargin < 2 + + geometry = {[3, 1], [3, 1], [3, 1], 1, 1, 1, 1}; + geomvert = [1 1 1 2 1 1 1]; + + uilist = {{'style', 'text', 'string', 'Lower edge of the frequency pass band (Hz)'} ... + {'style', 'edit', 'string', ''} ... + {'style', 'text', 'string', 'Higher edge of the frequency pass band (Hz)'} ... + {'style', 'edit', 'string', ''} ... + {'style', 'text', 'string', 'FIR Filter order (Mandatory even. Default is automatic*)'} ... + {'style', 'edit', 'string', ''} ... + {'style', 'text', 'string', {'*See help text for a description of the default filter order heuristic.', 'Manual definition is recommended.'}} ... + {'style', 'checkbox', 'string', 'Notch filter the data instead of pass band', 'value', 0} ... + {'Style', 'checkbox', 'String', 'Use minimum-phase converted causal filter (non-linear!; beta)', 'Value', 0} ... + {'style', 'checkbox', 'string', 'Plot frequency response', 'value', 1}}; + + result = inputgui('geometry', geometry, 'geomvert', geomvert, 'uilist', uilist, 'title', 'Filter the data -- pop_eegfiltnew()', 'helpcom', 'pophelp(''pop_eegfiltnew'')'); + + if isempty(result), return; end + + locutoff = str2num(result{1}); + hicutoff = str2num(result{2}); + filtorder = str2num(result{3}); + revfilt = result{4}; + minphase = result{5}; + plotfreqz = result{6}; + usefft = []; + +else + + if nargin < 3 + hicutoff = []; + end + if nargin < 4 + filtorder = []; + end + if nargin < 5 || isempty(revfilt) + revfilt = 0; + end + if nargin < 6 + usefft = []; + elseif usefft == 1 + error('FFT filtering not supported. Argument is provided for backward compatibility in command line mode only.') + end + if nargin < 7 || isempty(plotfreqz) + plotfreqz = 0; + end + if nargin < 8 || isempty(minphase) + minphase = 0; + end + +end + +% Constants +TRANSWIDTHRATIO = 0.25; +fNyquist = EEG.srate / 2; + +% Check arguments +if locutoff == 0, locutoff = []; end +if hicutoff == 0, hicutoff = []; end +if isempty(hicutoff) % Convert highpass to inverted lowpass + hicutoff = locutoff; + locutoff = []; + revfilt = ~revfilt; +end +edgeArray = sort([locutoff hicutoff]); + +if isempty(edgeArray) + error('Not enough input arguments.'); +end +if any(edgeArray < 0 | edgeArray >= fNyquist) + error('Cutoff frequency out of range'); +end + +if ~isempty(filtorder) && (filtorder < 2 || mod(filtorder, 2) ~= 0) + error('Filter order must be a real, even, positive integer.') +end + +% Max stop-band width +maxTBWArray = edgeArray; % Band-/highpass +if revfilt == 0 % Band-/lowpass + maxTBWArray(end) = fNyquist - edgeArray(end); +elseif length(edgeArray) == 2 % Bandstop + maxTBWArray = diff(edgeArray) / 2; +end +maxDf = min(maxTBWArray); + +% Transition band width and filter order +if isempty(filtorder) + + % Default filter order heuristic + if revfilt == 1 % Highpass and bandstop + df = min([max([maxDf * TRANSWIDTHRATIO 2]) maxDf]); + else % Lowpass and bandpass + df = min([max([edgeArray(1) * TRANSWIDTHRATIO 2]) maxDf]); + end + + filtorder = 3.3 / (df / EEG.srate); % Hamming window + filtorder = ceil(filtorder / 2) * 2; % Filter order must be even. + +else + + df = 3.3 / filtorder * EEG.srate; % Hamming window + filtorderMin = ceil(3.3 ./ ((maxDf * 2) / EEG.srate) / 2) * 2; + filtorderOpt = ceil(3.3 ./ (maxDf / EEG.srate) / 2) * 2; + if filtorder < filtorderMin + error('Filter order too low. Minimum required filter order is %d. For better results a minimum filter order of %d is recommended.', filtorderMin, filtorderOpt) + elseif filtorder < filtorderOpt + warning('firfilt:filterOrderLow', 'Transition band is wider than maximum stop-band width. For better results a minimum filter order of %d is recommended. Reported might deviate from effective -6dB cutoff frequency.', filtorderOpt) + end + +end + +filterTypeArray = {'lowpass', 'bandpass'; 'highpass', 'bandstop (notch)'}; +fprintf('pop_eegfiltnew() - performing %d point %s filtering.\n', filtorder + 1, filterTypeArray{revfilt + 1, length(edgeArray)}) +fprintf('pop_eegfiltnew() - transition band width: %.4g Hz\n', df) +fprintf('pop_eegfiltnew() - passband edge(s): %s Hz\n', mat2str(edgeArray)) + +% Passband edge to cutoff (transition band center; -6 dB) +dfArray = {df, [-df, df]; -df, [df, -df]}; +cutoffArray = edgeArray + dfArray{revfilt + 1, length(edgeArray)} / 2; +fprintf('pop_eegfiltnew() - cutoff frequency(ies) (-6 dB): %s Hz\n', mat2str(cutoffArray)) + +% Window +winArray = windows('hamming', filtorder + 1); + +% Filter coefficients +if revfilt == 1 + filterTypeArray = {'high', 'stop'}; + b = firws(filtorder, cutoffArray / fNyquist, filterTypeArray{length(cutoffArray)}, winArray); +else + b = firws(filtorder, cutoffArray / fNyquist, winArray); +end + +if minphase + disp('pop_eegfiltnew() - converting filter to minimum-phase (non-linear!)'); + b = minphaserceps(b); +end + +% Plot frequency response +if plotfreqz + freqz(b, 1, 8192, EEG.srate); +end + +% Filter +if minphase + disp('pop_eegfiltnew() - filtering the data (causal)'); + EEG = firfiltsplit(EEG, b, 1); +else + disp('pop_eegfiltnew() - filtering the data (zero-phase)'); + EEG = firfilt(EEG, b); +end + + +% History string +com = sprintf('%s = pop_eegfiltnew(%s, %s, %s, %s, %s, %s, %s);', inputname(1), inputname(1), mat2str(locutoff), mat2str(hicutoff), mat2str(filtorder), mat2str(revfilt), mat2str(usefft), mat2str(plotfreqz)); + +end diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_firma.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_firma.m new file mode 100644 index 0000000000000000000000000000000000000000..78322e5f038fbf0b852540a1170c63368441f965 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_firma.m @@ -0,0 +1,103 @@ +% pop_firma() - Filter data using moving average FIR filter +% +% Usage: +% >> [EEG, com] = pop_firma(EEG); % pop-up window mode +% >> [EEG, com] = pop_firma(EEG, 'forder', order); +% +% Inputs: +% EEG - EEGLAB EEG structure +% 'forder' - scalar filter order. Mandatory even +% +% Outputs: +% EEG - filtered EEGLAB EEG structure +% com - history string +% +% Author: Andreas Widmann, University of Leipzig, 2005 +% +% See also: +% firfilt, plotfresp + +%123456789012345678901234567890123456789012345678901234567890123456789012 + +% Copyright (C) 2005 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function [EEG, com] = pop_firma(EEG, varargin) + + com = ''; + if nargin < 1 + help pop_firma; + return; + end + if isempty(EEG.data) + error('Cannot process empty dataset'); + end + + if nargin < 2 + drawnow; + uigeom = {[1 1 1] [1] [1 1 1]}; + uilist = {{'style' 'text' 'string' 'Filter order (mandatory even):'} ... + {'style' 'edit' 'string' '' 'tag' 'forderedit'} {} ... + {} ... + {} {} {'Style' 'pushbutton' 'string' 'Plot filter responses' 'callback' {@complot, EEG.srate}}}; + result = inputgui(uigeom, uilist, 'pophelp(''pop_firma'')', 'Filter the data -- pop_firma()'); + if length(result) == 0, return; end + + if ~isempty(result{1}) + args = [{'forder'} {str2num(result{1})}]; + else + error('Not enough input arguments'); + end + else + args = varargin; + end + + % Convert args to structure + args = struct(args{:}); + + % Filter coefficients + b = ones(1, args.forder + 1) / (args.forder + 1); + + % Filter + disp('pop_firma() - filtering the data'); + EEG = firfilt(EEG, b); + + % History string + com = sprintf('%s = pop_firma(%s', inputname(1), inputname(1)); + for c = fieldnames(args)' + if ischar(args.(c{:})) + com = [com sprintf(', ''%s'', ''%s''', c{:}, args.(c{:}))]; + else + com = [com sprintf(', ''%s'', %s', c{:}, mat2str(args.(c{:})))]; + end + end + com = [com ');']; + +% Callback plot filter properties +function complot(obj, evt, srate) + args.forder = str2num(get(findobj(gcbf, 'tag', 'forderedit'), 'string')); + if isempty(args.forder) + error('Not enough input arguments'); + end + b = ones(1, args.forder + 1) / (args.forder + 1); + H = findobj('tag', 'filter responses', 'type', 'figure'); + if ~isempty(H) + figure(H); + else + H = figure; + set(H, 'color', [.93 .96 1], 'tag', 'filter responses'); + end + plotfresp(b, 1, [], srate); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_firpm.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_firpm.m new file mode 100644 index 0000000000000000000000000000000000000000..4c31f9e42ac077c95d8ba8adf6ee0fee082dc9fa --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_firpm.m @@ -0,0 +1,202 @@ +% pop_firpm() - Filter data using Parks-McClellan FIR filter +% +% Usage: +% >> [EEG, com, b] = pop_firpm(EEG); % pop-up window mode +% >> [EEG, com, b] = pop_firpm(EEG, 'key1', value1, 'key2', ... +% value2, 'keyn', valuen); +% +% Inputs: +% EEG - EEGLAB EEG structure +% 'fcutoff' - vector or scalar of cutoff frequency/ies (~-6 dB; Hz) +% 'ftrans' - scalar transition band width +% 'ftype' - char array filter type. 'bandpass', 'highpass', +% 'lowpass', or 'bandstop' +% 'forder' - scalar filter order. Mandatory even +% +% Optional inputs: +% 'wtpass' - scalar passband weight +% 'wtstop' - scalar stopband weight +% +% Outputs: +% EEG - filtered EEGLAB EEG structure +% com - history string +% b - filter coefficients +% +% Note: +% Requires the signal processing toolbox. +% +% Author: Andreas Widmann, University of Leipzig, 2005 +% +% See also: +% firfilt, pop_firpmord, plotfresp, firpm, firpmord + +%123456789012345678901234567890123456789012345678901234567890123456789012 + +% Copyright (C) 2005 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function [EEG, com, b] = pop_firpm(EEG, varargin) + + if exist('firpm', 'file') ~= 2 + error('Requires the signal processing toolbox.'); + end + + com = ''; + if nargin < 1 + help pop_firpm; + return; + end + if isempty(EEG.data) + error('Cannot process empty dataset'); + end + + if nargin < 2 + drawnow; + ftypes = {'bandpass' 'highpass' 'lowpass' 'bandstop'}; + uigeom = {[1 0.75 0.75] [1 0.75 0.75] [1 0.75 0.75] 1 [1 0.75 0.75] [1 0.75 0.75] [1 0.75 0.75] 1 [1 0.75 0.75]}; + uilist = {{'Style' 'text' 'String' 'Cutoff frequency(ies) [hp lp] (~-6 dB; Hz):'} ... + {'Style' 'edit' 'String' '' 'Tag' 'fcutoffedit'} {} ... + {'Style' 'text' 'String' 'Transition band width:'} ... + {'Style' 'edit' 'String' '' 'Tag' 'ftransedit'} {} ... + {'Style' 'text' 'String' 'Filter type:'} ... + {'Style' 'popupmenu' 'String' ftypes 'Tag' 'ftypepop'} {} ... + {} ... + {'Style' 'text' 'String' 'Passband weight:'} ... + {'Style' 'edit' 'String' '' 'Tag' 'wtpassedit'} {} ... + {'Style' 'text' 'String' 'Stopband weight:'} ... + {'Style' 'edit' 'String' '' 'Tag' 'wtstopedit'} {} ... + {'Style' 'text' 'String' 'Filter order (mandatory even):'} ... + {'Style' 'edit' 'String' '' 'Tag' 'forderedit'} ... + {'Style' 'pushbutton' 'String' 'Estimate' 'Tag' 'orderpush' 'Callback' {@comcb, ftypes, EEG.srate}} ... + {} ... + {} {} {'Style' 'pushbutton' 'String', 'Plot filter responses' 'Tag' 'plotpush' 'Callback' {@comcb, ftypes, EEG.srate}}}; + result = inputgui(uigeom, uilist, 'pophelp(''pop_firpm'')', 'Filter the data -- pop_firpm()'); + if isempty(result), return; end + + args = {}; + if ~isempty(result{1}) + args = [args {'fcutoff'} {str2num(result{1})}]; + end + if ~isempty(result{2}) + args = [args {'ftrans'} {str2double(result{2})}]; + end + args = [args {'ftype'} ftypes(result{3})]; + if ~isempty(result{4}) + args = [args {'wtpass'} {str2double(result{4})}]; + end + if ~isempty(result{5}) + args = [args {'wtstop'} {str2double(result{5})}]; + end + if ~isempty(result{6}) + args = [args {'forder'} {str2double(result{6})}]; + end + else + args = varargin; + end + + % Convert args to structure + args = struct(args{:}); + + c = parseargs(args, EEG.srate); + if ~isfield(args, 'forder') || isempty(args.forder) + error('Not enough input arguments'); + end + b = firpm(args.forder, c{:}); + + % Filter + disp('pop_firpm() - filtering the data'); + EEG = firfilt(EEG, b); + + % History string + com = sprintf('%s = pop_firpm(%s', inputname(1), inputname(1)); + for c = fieldnames(args)' + if ischar(args.(c{:})) + com = [com sprintf(', ''%s'', ''%s''', c{:}, args.(c{:}))]; + else + com = [com sprintf(', ''%s'', %s', c{:}, mat2str(args.(c{:})))]; + end + end + com = [com ');']; + +% Convert structure args to cell array firpm parameters +function c = parseargs(args, srate) + + if ~isfield(args, 'fcutoff') || ~isfield(args, 'ftype') || ~isfield(args, 'ftrans') || isempty(args.fcutoff) || isempty(args.ftype) || isempty(args.ftrans) + error('Not enough input arguments.'); + end + + % Cutoff frequencies + args.fcutoff = [args.fcutoff - args.ftrans / 2 args.fcutoff + args.ftrans / 2]; + args.fcutoff = sort(args.fcutoff / (srate / 2)); % Sorting and normalization + if any(args.fcutoff < 0) + error('Cutoff frequencies - transition band width / 2 must not be < DC'); + elseif any(args.fcutoff > 1) + error('Cutoff frequencies + transition band width / 2 must not be > Nyquist'); + end + c = {[0 args.fcutoff 1]}; + + % Filter type + switch args.ftype + case 'bandpass' + c = [c {[0 0 1 1 0 0]}]; + case 'bandstop' + c = [c {[1 1 0 0 1 1]}]; + case 'highpass' + c = [c {[0 0 1 1]}]; + case 'lowpass' + c = [c {[1 1 0 0]}]; + end + + %Filter weights + if all(isfield(args, {'wtpass', 'wtstop'})) && ~isempty(args.wtpass) && ~isempty(args.wtstop) + w = [args.wtstop args.wtpass]; + c{3} = w(c{2}(1:2:end) + 1); + end + +% Callback +function comcb(obj, evt, ftypes, srate) + + args.fcutoff = str2num(get(findobj(gcbf, 'Tag', 'fcutoffedit'), 'String')); + args.ftype = ftypes{get(findobj(gcbf, 'Tag', 'ftypepop'), 'Value')}; + args.ftrans = str2double(get(findobj(gcbf, 'Tag', 'ftransedit'), 'String')); + args.wtpass = str2double(get(findobj(gcbf, 'Tag', 'wtpassedit'), 'String')); + args.wtstop = str2double(get(findobj(gcbf, 'Tag', 'wtstopedit'), 'String')); + c = parseargs(args, srate); + + switch get(obj, 'Tag') + case 'orderpush' + [args.forder, args.wtpass, args.wtstop] = pop_firpmord(c{1}(2:end - 1), c{2}(1:2:end)); + if ~isempty(args.forder) || ~isempty(args.wtpass) || ~isempty(args.wtstop) + set(findobj(gcbf, 'Tag', 'forderedit'), 'String', ceil(args.forder / 2) * 2); + set(findobj(gcbf, 'Tag', 'wtpassedit'), 'String', args.wtpass); + set(findobj(gcbf, 'Tag', 'wtstopedit'), 'String', args.wtstop); + end + + case 'plotpush' + args.forder = str2double(get(findobj(gcbf, 'Tag', 'forderedit'), 'String')); + if isempty(args.forder) + error('Not enough input arguments'); + end + b = firpm(args.forder, c{:}); + H = findobj('Tag', 'filter responses', 'Type', 'figure'); + if ~isempty(H) + figure(H); + else + H = figure; + set(H, 'color', [.93 .96 1], 'Tag', 'filter responses'); + end + plotfresp(b, 1, [], srate); + end diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_firpmord.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_firpmord.m new file mode 100644 index 0000000000000000000000000000000000000000..34be390df6a1884cdb66646cc061012de65a4f14 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_firpmord.m @@ -0,0 +1,97 @@ +% pop_firpmord() - Estimate Parks-McClellan filter order and weights +% +% Usage: +% >> [m, wtpass, wtstop] = pop_firpmord(f, a); % pop-up window mode +% >> [m, wtpass, wtstop] = pop_firpmord(f, a, dev); +% >> [m, wtpass, wtstop] = pop_firpmord(f, a, dev, fs); +% +% Inputs: +% f - vector frequency band edges +% a - vector desired amplitudes on bands defined by f +% dev - vector allowable deviations on bands defined by f +% +% Optional inputs: +% fs - scalar sampling frequency {default 2} +% +% Output: +% m - scalar estimated filter order +% wtpass - scalar passband weight +% wtstop - scalar stopband weight +% +% Note: +% Requires the signal processing toolbox. Convert passband ripple from +% dev to peak-to-peak dB: rp = 20 * log10((1 + dev) / (1 - dev)). +% Convert stopband attenuation from dev to dB: rs = 20 * log10(dev). +% +% Author: Andreas Widmann, University of Leipzig, 2005 +% +% See also: +% pop_firpm, firpm, firpmord + +%123456789012345678901234567890123456789012345678901234567890123456789012 + +% Copyright (C) 2005 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function [m, wtpass, wtstop] = pop_firpmord(f, a, dev, fs) + +m = []; +wtpass = []; +wtstop = []; + +if exist('firpmord') ~= 2 + error('Requires the signal processing toolbox.'); +end + +if nargin < 2 || isempty(f) || isempty(a) + error('Not enough input arguments'); +end + +% Sampling frequency +if nargin < 4 || isempty(fs) + fs = 2; +end + +% GUI +if nargin < 3 || isempty(dev) + drawnow; + uigeom = {[1 1] [1 1]}; + uilist = {{'style' 'text' 'string' 'Peak-to-peak passband ripple (dB):'} ... + {'style' 'edit'} ... + {'style' 'text' 'string' 'Stopband attenuation (dB):'} ... + {'style' 'edit'}}; + result = inputgui(uigeom, uilist, 'pophelp(''pop_firpmord'')', 'Estimate filter order and weights -- pop_firpmord()'); + if length(result) == 0, return, end + + if ~isempty(result{1}) + rp = str2num(result{1}); + rp = (10^(rp / 20) - 1) / (10^(rp / 20) + 1); + dev(find(a == 1)) = rp; + else + error('Not enough input arguments.'); + end + if ~isempty(result{2}) + rs = str2num(result{2}); + rs = 10^(-abs(rs) / 20); + dev(find(a == 0)) = rs; + else + error('Not enough input arguments.'); + end +end + +[m, fo, ao, w] = firpmord(f, a, dev, fs); +wtpass = w(find(a == 1, 1)); +wtstop = w(find(a == 0, 1)); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_firws.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_firws.m new file mode 100644 index 0000000000000000000000000000000000000000..94cb5cdf494d41de73ec4c6da7c6c65887e2dd19 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_firws.m @@ -0,0 +1,234 @@ +% pop_firws() - Filter data using windowed sinc FIR filter +% +% Usage: +% >> [EEG, com, b] = pop_firws(EEG); % pop-up window mode +% >> [EEG, com, b] = pop_firws(EEG, 'key1', value1, 'key2', ... +% value2, 'keyn', valuen); +% +% Inputs: +% EEG - EEGLAB EEG structure +% 'fcutoff' - vector or scalar of cutoff frequency/ies (-6 dB; Hz) +% 'forder' - scalar filter order. Mandatory even +% +% Optional inputs: +% 'ftype' - char array filter type. 'bandpass', 'highpass', +% 'lowpass', or 'bandstop' {default 'bandpass' or +% 'lowpass', depending on number of cutoff frequencies} +% 'wtype' - char array window type. 'rectangular', 'bartlett', +% 'hann', 'hamming', 'blackman', or 'kaiser' {default +% 'blackman'} +% 'warg' - scalar kaiser beta +% 'minphase' - scalar boolean minimum-phase converted causal filter +% {default false} +% +% Outputs: +% EEG - filtered EEGLAB EEG structure +% com - history string +% b - filter coefficients +% +% Note: +% Window based filters' transition band width is defined by filter +% order and window type/parameters. Stopband attenuation equals +% passband ripple and is defined by the window type/parameters. Refer +% to table below for typical parameters. (Windowed sinc) symmetric FIR +% filters have linear phase and can be made zero phase (non-causal) by +% shifting the data by the filters group delay (what firfilt does by +% default). Pi phase jumps noticable in the phase reponse reflect a +% negative frequency response and only occur in the stopband. pop_firws +% also allows causal filtering with minimum-phase (non-linear!) converted +% filter coefficients with similar properties. Non-linear causal +% filtering is NOT recommended for most use cases. +% +% Beta Max stopband Max passband Max passband Transition width Mainlobe width +% attenuation deviation ripple (dB) (normalized freq) (normalized rad freq) +% (dB) +% Rectangular -21 0.0891 1.552 0.9 / m* 4 * pi / m +% Bartlett -25 0.0562 0.977 8 * pi / m +% Hann -44 0.0063 0.109 3.1 / m 8 * pi / m +% Hamming -53 0.0022 0.038 3.3 / m 8 * pi / m +% Blackman -74 0.0002 0.003 5.5 / m 12 * pi / m +% Kaiser 5.653 -60 0.001 0.017 3.6 / m +% Kaiser 7.857 -80 0.0001 0.002 5.0 / m +% * m = filter order +% +% Author: Andreas Widmann, University of Leipzig, 2005 +% +% See also: +% firfilt, firws, pop_firwsord, pop_kaiserbeta, plotfresp, windows + +%123456789012345678901234567890123456789012345678901234567890123456789012 + +% Copyright (C) 2005 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function [EEG, com, b] = pop_firws(EEG, varargin) + + com = ''; + if nargin < 1 + help pop_firws; + return; + end + if isempty(EEG.data) + error('Cannot process empty dataset'); + end + + if nargin < 2 + drawnow; + ftypes = {'bandpass', 'highpass', 'lowpass', 'bandstop'}; + ftypesStr = {'Bandpass', 'Highpass', 'Lowpass', 'Bandstop'}; + wtypes = {'rectangular', 'bartlett', 'hann', 'hamming', 'blackman', 'kaiser'}; + wtypesStr = {'Rectangular (PB dev=0.089, SB att=-21dB)', 'Bartlett (PB dev=0.056, SB att=-25dB)', 'Hann (PB dev=0.006, SB att=-44dB)', 'Hamming (PB dev=0.002, SB att=-53dB)', 'Blackman (PB dev=0.0002, SB att=-74dB)', 'Kaiser'}; + uigeom = {[1 0.75 0.75] [1 0.75 0.75] 1 [1 0.75 0.75] [1 0.75 0.75] [1 0.75 0.75] [1 1.5] 1 [1 0.75 0.75]}; + uilist = {{'Style' 'text' 'String' 'Cutoff frequency(ies) [hp lp] (-6 dB; Hz):'} ... + {'Style' 'edit' 'String' '' 'Tag' 'fcutoffedit'} {} ... + {'Style' 'text' 'String' 'Filter type:'} ... + {'Style' 'popupmenu' 'String' ftypesStr 'Tag' 'ftypepop'} {} ... + {} ... + {'Style' 'text' 'String' 'Window type:'} ... + {'Style' 'popupmenu' 'String' wtypesStr 'Tag' 'wtypepop' 'Value' 5 'Callback' 'temp = {''off'', ''on''}; set(findobj(gcbf, ''-regexp'', ''Tag'', ''^warg''), ''Enable'', temp{double(get(gcbo, ''Value'') == 6) + 1}), set(findobj(gcbf, ''Tag'', ''wargedit''), ''String'', '''')'} {} ... + {'Style' 'text' 'String' 'Kaiser window beta:' 'Tag' 'wargtext' 'Enable' 'off'} ... + {'Style' 'edit' 'String' '' 'Tag' 'wargedit' 'Enable' 'off'} ... + {'Style' 'pushbutton' 'String' 'Estimate' 'Tag' 'wargpush' 'Enable' 'off' 'Callback' @comwarg} ... + {'Style' 'text' 'String' 'Filter order (mandatory even):'} ... + {'Style' 'edit' 'String' '' 'Tag' 'forderedit'} ... + {'Style' 'pushbutton' 'String' 'Estimate' 'Callback' {@comforder, wtypes, EEG.srate}} ... + {} {'Style' 'checkbox', 'String', 'Use minimum-phase converted causal filter (non-linear!; beta)', 'Tag' 'minphase', 'Value', 0} ... + {'Style' 'edit' 'Tag' 'devedit' 'Visible' 'off'} ... + {} {} {'Style' 'pushbutton' 'String', 'Plot filter responses' 'Callback' {@comfresp, wtypes, ftypes, EEG.srate}}}; + result = inputgui(uigeom, uilist, 'pophelp(''pop_firws'')', 'Filter the data -- pop_firws()'); + if isempty(result), return; end + + args = {}; + if ~isempty(result{1}) + args = [args {'fcutoff'} {str2num(result{1})}]; + end + args = [args {'ftype'} ftypes(result{2})]; + args = [args {'wtype'} wtypes(result{3})]; + if ~isempty(result{4}) + args = [args {'warg'} {str2double(result{4})}]; + end + if ~isempty(result{5}) + args = [args {'forder'} {str2double(result{5})}]; + end + args = [args {'minphase'} result{6}]; + else + args = varargin; + end + + % Convert args to structure + args = struct(args{:}); + + c = parseargs(args, EEG.srate); + b = firws(c{:}); + + % Check arguments + if ~isfield(args, 'minphase') || isempty(args.minphase) + args.minphase = 0; + end + + % Filter + disp('pop_firws() - filtering the data'); + if args.minphase + b = minphaserceps(b); + EEG = firfiltsplit(EEG, b, 1); + else + EEG = firfilt(EEG, b); + end + + % History string + com = sprintf('%s = pop_firws(%s', inputname(1), inputname(1)); + for c = fieldnames(args)' + if ischar(args.(c{:})) + com = [com sprintf(', ''%s'', ''%s''', c{:}, args.(c{:}))]; + else + com = [com sprintf(', ''%s'', %s', c{:}, mat2str(args.(c{:})))]; + end + end + com = [com ');']; + +% Convert structure args to cell array firws parameters +function c = parseargs(args, srate) + + % Filter order and cutoff frequencies + if ~isfield(args, 'fcutoff') || ~isfield(args, 'forder') || isempty(args.fcutoff) || isempty(args.forder) + error('Not enough input arguments.'); + end + c = [{args.forder} {sort(args.fcutoff / (srate / 2))}]; % Sorting and normalization + + % Filter type + if isfield(args, 'ftype') && ~isempty(args.ftype) + if (strcmpi(args.ftype, 'bandpass') || strcmpi(args.ftype, 'bandstop')) && length(args.fcutoff) ~= 2 + error('Not enough input arguments.'); + elseif (strcmpi(args.ftype, 'highpass') || strcmpi(args.ftype, 'lowpass')) && length(args.fcutoff) ~= 1 + error('Too many input arguments.'); + end + switch args.ftype + case 'bandstop' + c = [c {'stop'}]; + case 'highpass' + c = [c {'high'}]; + end + end + + % Window type + if isfield(args, 'wtype') && ~isempty(args.wtype) + if strcmpi(args.wtype, 'kaiser') + if isfield(args, 'warg') && ~isempty(args.warg) + c = [c {windows(args.wtype, args.forder + 1, args.warg)'}]; + else + error('Not enough input arguments.'); + end + else + c = [c {windows(args.wtype, args.forder + 1)'}]; + end + end + +% Callback estimate Kaiser beta +function comwarg(varargin) + [warg, dev] = pop_kaiserbeta; + set(findobj(gcbf, 'Tag', 'wargedit'), 'String', warg); + set(findobj(gcbf, 'Tag', 'devedit'), 'String', dev); + +% Callback estimate filter order +function comforder(obj, evt, wtypes, srate) + wtype = wtypes{get(findobj(gcbf, 'Tag', 'wtypepop'), 'Value')}; + dev = get(findobj(gcbf, 'Tag', 'devedit'), 'String'); + [forder, dev] = pop_firwsord(wtype, srate, [], dev); + set(findobj(gcbf, 'Tag', 'forderedit'), 'String', forder); + set(findobj(gcbf, 'Tag', 'devedit'), 'String', dev); + +% Callback plot filter responses +function comfresp(obj, evt, wtypes, ftypes, srate) + args.fcutoff = str2num(get(findobj(gcbf, 'Tag', 'fcutoffedit'), 'String')); + args.ftype = ftypes{get(findobj(gcbf, 'Tag', 'ftypepop'), 'Value')}; + args.wtype = wtypes{get(findobj(gcbf, 'Tag', 'wtypepop'), 'Value')}; + args.warg = str2num(get(findobj(gcbf, 'Tag', 'wargedit'), 'String')); + args.forder = str2double(get(findobj(gcbf, 'Tag', 'forderedit'), 'String')); + args.minphase = get(findobj(gcbf, 'Tag', 'minphase'), 'Value'); + causal = args.minphase; + c = parseargs(args, srate); + b = firws(c{:}); + if args.minphase + b = minphaserceps(b); + end + H = findobj('Tag', 'filter responses', 'type', 'figure'); + if ~isempty(H) + figure(H); + else + H = figure; + set(H, 'color', [.93 .96 1], 'Tag', 'filter responses'); + end + plotfresp(b, 1, [], srate, causal); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_firwsord.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_firwsord.m new file mode 100644 index 0000000000000000000000000000000000000000..43a1f86bafeed9815c365b110d5228315930fe06 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_firwsord.m @@ -0,0 +1,145 @@ +% pop_firwsord() - Estimate windowed sinc filter order depending on +% window type and requested transition band width +% +% Usage: +% >> [m, dev] = pop_firwsord; % pop-up window mode +% >> m = pop_firwsord(wtype, fs, df); +% >> m = pop_firwsord('kaiser', fs, df, dev); +% +% Inputs: +% wtype - char array window type. 'rectangular', 'bartlett', 'hann', +% 'hamming', {'blackman'}, or 'kaiser' +% fs - scalar sampling frequency {default 2} +% df - scalar requested transition band width +% dev - scalar maximum passband deviation/ripple (Kaiser window +% only) +% +% Output: +% m - scalar estimated filter order +% dev - scalar maximum passband deviation/ripple +% +% References: +% [1] Smith, S. W. (1999). The scientist and engineer's guide to +% digital signal processing (2nd ed.). San Diego, CA: California +% Technical Publishing. +% [2] Proakis, J. G., & Manolakis, D. G. (1996). Digital Signal +% Processing: Principles, Algorithms, and Applications (3rd ed.). +% Englewood Cliffs, NJ: Prentice-Hall +% [3] Ifeachor E. C., & Jervis B. W. (1993). Digital Signal +% Processing: A Practical Approach. Wokingham, UK: Addison-Wesley +% +% Author: Andreas Widmann, University of Leipzig, 2005 +% +% See also: +% pop_firws, firws, pop_kaiserbeta, windows + +%123456789012345678901234567890123456789012345678901234567890123456789012 + +% Copyright (C) 2005 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function [m, dev] = pop_firwsord(wtype, fs, df, dev) + + m = []; + + wtypes = {'rectangular' 'bartlett' 'hann' 'hamming' 'blackman' 'kaiser'}; + + % Window type + if nargin < 1 || isempty(wtype) + wtype = 5; + elseif ~ischar(wtype) || isempty(strmatch(wtype, wtypes)) + error('Unknown window type'); + else + wtype = strmatch(wtype, wtypes); + end + + % Sampling frequency + if nargin < 2 || isempty(fs) + fs = 2; + end + + % Transition band width + if nargin < 3 + df = []; + end + + % Maximum passband deviation/ripple + if nargin < 4 || isempty(dev) + devs = {0.089 0.056 0.0063 0.0022 0.0002 []}; + dev = devs{wtype}; + end + + % GUI + if nargin < 3 || isempty(df) || (wtype == 6 && isempty(dev)) + drawnow; + uigeom = {[1 1] [1 1] [1 1] [1 1]}; + uilist = {{'style' 'text' 'string' 'Sampling frequency:'} ... + {'style' 'edit' 'string' fs} ... + {'style' 'text' 'string' 'Window type:'} ... + {'style' 'popupmenu' 'string' wtypes 'tag' 'wtypepop' 'value' wtype 'callback' {@comwtype, dev}} ... + {'style' 'text' 'string' 'Transition bandwidth (Hz):'} ... + {'style' 'edit' 'string' df} ... + {'style' 'text' 'string' 'Max passband deviation/ripple:' 'tag' 'devtext'} ... + {'style' 'edit' 'tag' 'devedit' 'createfcn' {@comwtype, dev}}}; + result = inputgui(uigeom, uilist, 'pophelp(''pop_firwsord'')', 'Estimate filter order -- pop_firwsord()'); + + if length(result) == 0, return, end + if ~isempty(result{1}) + fs = str2num(result{1}); + else + fs = 2; + end + wtype = result{2}; + if ~isempty(result{3}) + df = str2num(result{3}); + else + error('Not enough input arguments.'); + end + if ~isempty(result{4}) + dev = str2num(result{4}); + elseif wtype == 6 + error('Not enough input arguments.'); + end + end + + if length(fs) > 1 || ~isnumeric(fs) || ~isreal(fs) || fs <= 0 + error('Sampling frequency must be a positive real scalar.'); + end + if length(df) > 1 || ~isnumeric(df) || ~isreal(df) || fs <= 0 + error('Transition bandwidth must be a positive real scalar.'); + end + + df = df / fs; % Normalize transition band width + + if wtype == 6 + if length(dev) > 1 || ~isnumeric(dev) || ~isreal(dev) || dev <= 0 + error('Passband deviation/ripple must be a positive real scalar.'); + end + devdb = -20 * log10(dev); + m = 1 + (devdb - 8) / (2.285 * 2 * pi * df); + else + dfs = [0.9 2.9 3.1 3.3 5.5]; + m = dfs(wtype) / df; + end + + m = ceil(m / 2) * 2; % Make filter order even (type 1) + +function comwtype(obj, evt, dev) + enable = {'off' 'off' 'off' 'off' 'off' 'on'}; + devs = {0.089 0.056 0.0063 0.0022 0.0002 dev}; + wtype = get(findobj(gcbf, 'tag', 'wtypepop'), 'value'); + set(findobj(gcbf, 'tag', 'devtext'), 'enable', enable{wtype}); + set(findobj(gcbf, 'tag', 'devedit'), 'enable', enable{wtype}, 'string', devs{wtype}); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_kaiserbeta.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_kaiserbeta.m new file mode 100644 index 0000000000000000000000000000000000000000..fd94db95d9af75d9a86709ff287e2fef093efe10 --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_kaiserbeta.m @@ -0,0 +1,69 @@ +% pop_kaiserbeta() - Estimate Kaiser window beta +% +% Usage: +% >> [beta, dev] = pop_kaiserbeta; % pop-up window mode +% >> beta = pop_kaiserbeta(dev); +% +% Inputs: +% dev - scalar maximum passband deviation/ripple +% +% Output: +% beta - scalar Kaiser window beta +% dev - scalar maximum passband deviation/ripple +% +% References: +% [1] Proakis, J. G., & Manolakis, D. G. (1996). Digital Signal +% Processing: Principles, Algorithms, and Applications (3rd ed.). +% Englewood Cliffs, NJ: Prentice-Hall +% +% Author: Andreas Widmann, University of Leipzig, 2005 +% +% See also: +% pop_firws, firws, pop_firwsord, windows + +%123456789012345678901234567890123456789012345678901234567890123456789012 + +% Copyright (C) 2005 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function [beta, dev] = pop_kaiserbeta(dev) + + beta = []; + + if nargin < 1 || isempty(dev) + drawnow; + uigeom = {[1 1]}; + uilist = {{'style' 'text' 'string' 'Max passband deviation/ripple:'} ... + {'style' 'edit' 'string' ''}}; + result = inputgui(uigeom, uilist, 'pophelp(''pop_kaiserbeta'')', 'Estimate Kaiser window beta -- pop_kaiserbeta()'); + if length(result) == 0, return, end + if ~isempty(result{1}) + dev = str2num(result{1}); + else + error('Not enough input arguments.'); + end + end + + devdb = -20 * log10(dev); + if devdb > 50 + beta = 0.1102 * (devdb - 8.7); + elseif devdb >= 21 + beta = 0.5842 * (devdb - 21)^0.4 + 0.07886 * (devdb - 21); + else + beta = 0; + end + +end diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_xfirws.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_xfirws.m new file mode 100644 index 0000000000000000000000000000000000000000..938d4fb96f016b0d3482048204fd4e43c089b71e --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/pop_xfirws.m @@ -0,0 +1,249 @@ +% pop_xfirws() - Design and export xfir compatible windowed sinc FIR filter +% +% Usage: +% >> pop_xfirws; % pop-up window mode +% >> [b, a] = pop_xfirws; % pop-up window mode +% >> pop_xfirws('key1', value1, 'key2', value2, 'keyn', valuen); +% >> [b, a] = pop_xfirws('key1', value1, 'key2', value2, 'keyn', valuen); +% +% Inputs: +% 'srate' - scalar sampling rate (Hz) +% 'fcutoff' - vector or scalar of cutoff frequency/ies (-6 dB; Hz) +% 'forder' - scalar filter order. Mandatory even +% +% Optional inputs: +% 'ftype' - char array filter type. 'bandpass', 'highpass', +% 'lowpass', or 'bandstop' {default 'bandpass' or +% 'lowpass', depending on number of cutoff frequencies} +% 'wtype' - char array window type. 'rectangular', 'bartlett', +% 'hann', 'hamming', 'blackman', or 'kaiser' {default +% 'blackman'} +% 'warg' - scalar kaiser beta +% 'filename' - char array export filename +% 'pathname' - char array export pathname {default '.'} +% +% Outputs: +% b - filter coefficients +% a - filter coefficients +% +% Note: +% Window based filters' transition band width is defined by filter +% order and window type/parameters. Stopband attenuation equals +% passband ripple and is defined by the window type/parameters. Refer +% to table below for typical parameters. (Windowed sinc) FIR filters +% are zero phase in passband when shifted by the filters group delay +% (what firfilt does). Pi phase jumps noticable in the phase reponse +% reflect a negative frequency response and only occur in the +% stopband. +% +% Beta Max stopband Max passband Max passband Transition width Mainlobe width +% attenuation deviation ripple (dB) (normalized freq) (normalized rad freq) +% (dB) +% Rectangular -21 0.0891 1.552 0.9 / m* 4 * pi / m +% Bartlett -25 0.0562 0.977 (2.9** / m) 8 * pi / m +% Hann -44 0.0063 0.109 3.1 / m 8 * pi / m +% Hamming -53 0.0022 0.038 3.3 / m 8 * pi / m +% Blackman -74 0.0002 0.003 5.5 / m 12 * pi / m +% Kaiser 5.653 -60 0.001 0.017 3.6 / m +% Kaiser 7.857 -80 0.0001 0.002 5.0 / m +% * m = filter order +% ** estimate for higher m only +% +% Example: +% fs = 500; tbw = 2; dev = 0.001; +% beta = pop_kaiserbeta(dev); +% m = pop_firwsord('kaiser', fs, tbw, dev); +% pop_xfirws('srate', fs, 'fcutoff', [1 25], 'ftype', 'bandpass', 'wtype', 'kaiser', 'warg', beta, 'forder', m, 'filename', 'foo.fir') +% +% Author: Andreas Widmann, University of Leipzig, 2011 +% +% See also: +% firfilt, firws, pop_firwsord, pop_kaiserbeta, plotfresp, windows + +%123456789012345678901234567890123456789012345678901234567890123456789012 + +% Copyright (C) 2011 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function [varargout] = pop_xfirws(varargin) + +% Pop-up window mode +if nargin < 1 + + drawnow; + ftypes = {'bandpass' 'highpass' 'lowpass' 'bandstop'}; + wtypes = {'rectangular' 'bartlett' 'hann' 'hamming' 'blackman' 'kaiser'}; + uigeom = {[1 0.75 0.75] 1 [1 0.75 0.75] [1 0.75 0.75] 1 [1 0.75 0.75] [1 0.75 0.75] [1 0.75 0.75] 1 [1 0.75 0.75]}; + uilist = {{'Style' 'text' 'String' 'Sampling frequency (Hz):'} ... + {'Style' 'edit' 'String' '2' 'Tag' 'srateedit'} {} ... + {} ... + {'Style' 'text' 'String' 'Cutoff frequency(ies) [hp lp] (-6 dB; Hz):'} ... + {'Style' 'edit' 'String' '' 'Tag' 'fcutoffedit'} {} ... + {'Style' 'text' 'String' 'Filter type:'} ... + {'Style' 'popupmenu' 'String' ftypes 'Tag' 'ftypepop'} {} ... + {} ... + {'Style' 'text' 'String' 'Window type:'} ... + {'Style' 'popupmenu' 'String' wtypes 'Tag' 'wtypepop' 'Value' 5 'Callback' 'temp = {''off'', ''on''}; set(findobj(gcbf, ''-regexp'', ''Tag'', ''^warg''), ''Enable'', temp{double(get(gcbo, ''Value'') == 6) + 1}), set(findobj(gcbf, ''Tag'', ''wargedit''), ''String'', '''')'} {} ... + {'Style' 'text' 'String' 'Kaiser window beta:' 'Tag' 'wargtext' 'Enable' 'off'} ... + {'Style' 'edit' 'String' '' 'Tag' 'wargedit' 'Enable' 'off'} ... + {'Style' 'pushbutton' 'String' 'Estimate' 'Tag' 'wargpush' 'Enable' 'off' 'Callback' @comwarg} ... + {'Style' 'text' 'String' 'Filter order (mandatory even):'} ... + {'Style' 'edit' 'String' '' 'Tag' 'forderedit'} ... + {'Style' 'pushbutton' 'String' 'Estimate' 'Callback' {@comforder, wtypes}} ... + {'Style' 'edit' 'Tag' 'devedit' 'Visible' 'off'} ... + {} {} {'Style' 'pushbutton' 'String', 'Plot filter responses' 'Callback' {@comfresp, wtypes, ftypes}}}; + result = inputgui(uigeom, uilist, 'pophelp(''pop_firws'')', 'Filter the data -- pop_firws()'); + if isempty(result), return; end + + Arg = struct; + Arg.srate = str2double(result{1}); + Arg.fcutoff = str2num(result{2}); + Arg.ftype = ftypes{result{3}}; + Arg.wtype = wtypes{result{4}}; + Arg.warg = str2num(result{5}); + Arg.forder = str2double(result{6}); + +% Command line mode +else + Arg = struct(varargin{:}); +end + +% Sampling rate +if ~isfield(Arg, 'srate') || isempty(Arg.srate) % Use default + Arg.srate = 2; +end + +% Filter order and cutoff frequencies +if ~isfield(Arg, 'fcutoff') || ~isfield(Arg, 'forder') || isempty(Arg.fcutoff) || isempty(Arg.forder) + error('Not enough input arguments.'); +end +firwsArgArray = {Arg.forder sort(Arg.fcutoff / Arg.srate * 2)}; % Sorting and normalization + +% Filter type +if ~isfield(Arg, 'ftype') || isempty(Arg.ftype) % Use default + switch length(Arg.fcutoff) + case 1 + Arg.ftype = 'lowpass'; + case 2 + Arg.ftype = 'bandpass'; + otherwise + error('Wrong number of arguments.') + end +else + if any(strcmpi(Arg.ftype, {'bandpass' 'bandstop'})) && length(Arg.fcutoff) ~= 2 + error('Not enough input arguments.'); + elseif any(strcmpi(Arg.ftype, {'highpass' 'lowpass'})) && length(Arg.fcutoff) ~= 1 + error('Too many input arguments.'); + end + switch Arg.ftype + case 'bandstop' + firwsArgArray(end + 1) = {'stop'}; + case 'highpass' + firwsArgArray(end + 1) = {'high'}; + end +end + +% Window type +if ~isfield(Arg, 'wtype') || isempty(Arg.wtype) % Use default + Arg.wtype = 'blackman'; +end + +% Window parameter +if ~isfield(Arg, 'warg') || isempty(Arg.warg) + Arg.warg = []; + firwsArgArray(end + 1) = {windows(Arg.wtype, Arg.forder + 1)}; +else + firwsArgArray(end + 1) = {windows(Arg.wtype, Arg.forder + 1, Arg.warg)}; +end + +b = firws(firwsArgArray{:}); +a = 1; + +if nargout == 0 || isfield(Arg, 'filename') + + % Open file + if ~isfield(Arg, 'filename') || isempty(Arg.filename) + [Arg.filename Arg.pathname] = uiputfile('*.fir', 'Save filter -- pop_xfirws'); + end + if ~isfield(Arg, 'pathname') || isempty(Arg.pathname) + Arg.pathname = '.'; + end + [fid message] = fopen(fullfile(Arg.pathname, Arg.filename), 'w', 'l'); + if fid == -1 + error(message) + end + + % Author + fprintf(fid, '[author]\n'); + fprintf(fid, '%s\n\n', 'pop_xfirws 1.5.1'); + + % FIR design + fprintf(fid, '[fir design]\n'); + fprintf(fid, 'method %s\n', 'fourier'); + fprintf(fid, 'type %s\n', Arg.ftype); + fprintf(fid, 'fsample %f\n', Arg.srate); + fprintf(fid, 'length %d\n', Arg.forder + 1); + fprintf(fid, 'fcrit%d %f\n', [1:length(Arg.fcutoff); Arg.fcutoff]); + fprintf(fid, 'window %s %s\n\n', Arg.wtype, num2str(Arg.warg)); % fprintf bug + + % FIR + fprintf(fid, '[fir]\n'); + fprintf(fid, '%d\n', Arg.forder + 1); + fprintf(fid, '% 18.10e\n', b); + + % Close file + fclose(fid); + +end + +if nargout > 0 + varargout = {b a}; +end + +% Callback estimate Kaiser beta +function comwarg(varargin) + [warg, dev] = pop_kaiserbeta; + set(findobj(gcbf, 'Tag', 'wargedit'), 'String', warg); + set(findobj(gcbf, 'Tag', 'devedit'), 'String', dev); + +% Callback estimate filter order +function comforder(obj, evt, wtypes) + srate = str2double(get(findobj(gcbf, 'Tag', 'srateedit'), 'String')); + wtype = wtypes{get(findobj(gcbf, 'Tag', 'wtypepop'), 'Value')}; + dev = str2double(get(findobj(gcbf, 'Tag', 'devedit'), 'String')); + [forder, dev] = pop_firwsord(wtype, srate, [], dev); + set(findobj(gcbf, 'Tag', 'forderedit'), 'String', forder); + set(findobj(gcbf, 'Tag', 'devedit'), 'String', dev); + +% Callback plot filter responses +function comfresp(obj, evt, wtypes, ftypes) + Arg.srate = str2double(get(findobj(gcbf, 'Tag', 'srateedit'), 'String')); + Arg.fcutoff = str2num(get(findobj(gcbf, 'Tag', 'fcutoffedit'), 'String')); + Arg.ftype = ftypes{get(findobj(gcbf, 'Tag', 'ftypepop'), 'Value')}; + Arg.wtype = wtypes{get(findobj(gcbf, 'Tag', 'wtypepop'), 'Value')}; + Arg.warg = str2num(get(findobj(gcbf, 'Tag', 'wargedit'), 'String')); + Arg.forder = str2double(get(findobj(gcbf, 'Tag', 'forderedit'), 'String')); + xfirwsArgArray(1, :) = fieldnames(Arg); + xfirwsArgArray(2, :) = struct2cell(Arg); + [b a] = pop_xfirws(xfirwsArgArray{:}); + H = findobj('Tag', 'filter responses', 'type', 'figure'); + if ~isempty(H) + figure(H); + else + H = figure; + set(H, 'color', [.93 .96 1], 'Tag', 'filter responses'); + end + plotfresp(b, a, [], Arg.srate); diff --git a/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/windows.m b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/windows.m new file mode 100644 index 0000000000000000000000000000000000000000..cc015a5e85f75e65a5173b31c11705c4381c6a8d --- /dev/null +++ b/scripts/eeglab_current/eeglab14_1_1b/plugins/firfilt1.6.1/windows.m @@ -0,0 +1,114 @@ +% windows() - Returns handle to window function or window +% +% Usage: +% >> h = windows(t); +% >> h = windows(t, m); +% >> h = windows(t, m, a); +% +% Inputs: +% t - char array 'rectangular', 'bartlett', 'hann', 'hamming', +% 'blackman', 'blackmanharris', or 'kaiser' +% +% Optional inputs: +% m - scalar window length +% a - scalar or vector with window parameter(s) +% +% Output: +% h - function handle or column vector window +% +% Author: Andreas Widmann, University of Leipzig, 2005 + +%123456789012345678901234567890123456789012345678901234567890123456789012 + +% Copyright (C) 2005 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation; either version 2 of the License, or +% (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this program; if not, write to the Free Software +% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +function h = windows(t, m, a) + + if nargin < 1 + error('Not enough input arguments.'); + end + h = str2func(t); + switch nargin + case 2 + h = h(m); + case 3 + h = h(m, a); + end +end + +function w = rectangular(m) + w = ones(m, 1); +end + +function w = bartlett(m) + w = 1 - abs(-1:2 / (m - 1):1)'; +end + +% von Hann +function w = hann(m); + w = hamming(m, 0.5); +end + +% Hamming +function w = hamming(m, a) + if nargin < 2 || isempty(a) + a = 25 / 46; + end + m = [0:1 / (m - 1):1]'; + w = a - (1 - a) * cos(2 * pi * m); +end + +% Blackman +function w = blackman(m, a) + if nargin < 2 || isempty(a) + a = [0.42 0.5 0.08 0]; + end + m = [0:1 / (m - 1):1]'; + w = a(1) - a(2) * cos (2 * pi * m) + a(3) * cos(4 * pi * m) - a(4) * cos(6 * pi * m); +end + +% Blackman-Harris +function w = blackmanharris(m) + w = blackman(m, [0.35875 0.48829 0.14128 0.01168]); +end + +% Kaiser +function w = kaiser(m, a) + if nargin < 2 || isempty(a) + a = 0.5; + end + m = [-1:2 / (m - 1):1]'; + w = besseli(0, a * sqrt(1 - m.^2)) / besseli(0, a); +end + +% Tukey +function w = tukey(m, a) + if nargin < 2 || isempty(a) + a = 0.5; + end + if a <= 0 + w = ones(m, 1); + elseif a >= 1 + w = hann(m); + else + a = (m - 1) / 2 * a; + tapArray = (0:a)' / a; + w = [0.5 - 0.5 * cos(pi * tapArray); ... + ones(m - 2 * length(tapArray), 1); ... + 0.5 - 0.5 * cos(pi * tapArray(end:-1:1))]; + end +end