PageRenderTime 26ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/toolboxes/fieldtrip/plotting/private/ft_datatype_sens.m

http://brainstream.googlecode.com/
MATLAB | 171 lines | 60 code | 16 blank | 95 comment | 15 complexity | 520b0698b49885732f57b85a5353694f MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, LGPL-2.0, GPL-3.0, GPL-2.0, LGPL-2.1, LGPL-3.0, BSD-2-Clause
  1. function [sens] = ft_datatype_sens(sens, varargin)
  2. % FT_DATATYPE_SENS describes the FieldTrip structure that represents
  3. % an EEG, ECoG, or MEG sensor array. This structure is commonly called
  4. % "elec" for EEG and "grad" for MEG, or more general "sens" for either
  5. % one.
  6. %
  7. % The structure for MEG gradiometers and/or magnetometers contains
  8. % sens.label = Mx1 cell-array with channel labels
  9. % sens.chanpos = Mx3 matrix with channel positions
  10. % sens.chanori = Mx3 matrix with channel orientations, used for synthetic planar gradient computation
  11. % sens.tra = MxN matrix to combine coils into channels
  12. % sens.coilpos = Nx3 matrix with coil positions
  13. % sens.coilori = Nx3 matrix with coil orientations
  14. % sens.balance = structure containing info about the balancing, See FT_APPLY_MONTAGE
  15. %
  16. % The structure for EEG or ECoG channels contains
  17. % sens.label = Mx1 cell-array with channel labels
  18. % sens.chanpos = Mx3 matrix with channel positions
  19. % sens.tra = MxN matrix to combine electrodes into channels
  20. % sens.elecpos = Nx3 matrix with coil positions
  21. % In case sens.tra is not present in the EEG sensor array, the channels
  22. % are assumed to be average referenced.
  23. %
  24. % The following fields are optional
  25. % sens.type = string with the MEG or EEG acquisition system, see FT_SENSTYPE
  26. % sens.chantype = Mx1 cell-array with the type of the channel, see FT_CHANTYPE
  27. % sens.chanunit = Mx1 cell-array with the units of the channel signal, e.g. 'T', 'fT' or 'fT/cm'
  28. %
  29. % Revision history:
  30. %
  31. % (2011v2/latest) The chantype and chanunit have been added for MEG.
  32. %
  33. % (2011v1) To facilitate determining the position of channels (e.g. for plotting)
  34. % in case of balanced MEG or bipolar EEG, an explicit distinction has been made
  35. % between chanpos+chanori and coilpos+coilori (for MEG) and chanpos and elecpos
  36. % (for EEG). The pnt and ori fields are removed
  37. %
  38. % (2010) Added support for bipolar or otherwise more complex linear combinations
  39. % of EEG electrodes using sens.tra, similar to MEG.
  40. %
  41. % (2009) Noice reduction has been added for MEG systems in the balance field.
  42. %
  43. % (2006) The optional fields sens.type and sens.unit were added.
  44. %
  45. % (2003) The initial version was defined, which looked like this for EEG
  46. % sens.pnt = Mx3 matrix with electrode positions
  47. % sens.label = Mx1 cell-array with channel labels
  48. % and like this for MEG
  49. % sens.pnt = Nx3 matrix with coil positions
  50. % sens.ori = Nx3 matrix with coil orientations
  51. % sens.tra = MxN matrix to combine coils into channels
  52. % sens.label = Mx1 cell-array with channel labels
  53. %
  54. % See also FT_READ_SENS, FT_SENSTYPE, FT_CHANTYPE, FT_APPLY_MONTAGE, CTF2GRAD, FIF2GRAD,
  55. % BTI2GRAD, YOKOGAWA2GRAD, ITAB2GRAD
  56. % Copyright (C) 2011, Robert Oostenveld & Jan-Mathijs Schoffelen
  57. %
  58. % This file is part of FieldTrip, see http://www.ru.nl/neuroimaging/fieldtrip
  59. % for the documentation and details.
  60. %
  61. % FieldTrip is free software: you can redistribute it and/or modify
  62. % it under the terms of the GNU General Public License as published by
  63. % the Free Software Foundation, either version 3 of the License, or
  64. % (at your option) any later version.
  65. %
  66. % FieldTrip is distributed in the hope that it will be useful,
  67. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  68. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  69. % GNU General Public License for more details.
  70. %
  71. % You should have received a copy of the GNU General Public License
  72. % along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
  73. %
  74. % $Id: ft_datatype_sens.m 4923 2011-12-01 21:29:14Z roboos $
  75. % get the optional input arguments, which should be specified as key-value pairs
  76. version = ft_getopt(varargin, 'version', 'latest');
  77. if strcmp(version, 'latest')
  78. version = '2011v2';
  79. end
  80. % there are many cases which deal with either eeg or meg
  81. isgrad = ft_senstype(sens, 'meg');
  82. switch version
  83. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  84. case '2011v2'
  85. if isfield(sens, 'pnt') || isfield(sens, 'ori')
  86. if isgrad
  87. % sensor description is a MEG sensor-array, containing oriented coils
  88. [chanpos, chanori, chanlab] = channelposition(sens, 'channel', 'all');
  89. sens.coilori = sens.ori; sens = rmfield(sens, 'ori');
  90. sens.coilpos = sens.pnt; sens = rmfield(sens, 'pnt');
  91. sens.chanpos = chanpos;
  92. sens.chanori = chanori;
  93. else
  94. % sensor description is something else, EEG/ECoG etc
  95. % note that chanori will be all NaNs
  96. [chanpos, chanori, chanlab] = channelposition(sens, 'channel', 'all');
  97. sens.elecpos = chanpos; sens = rmfield(sens, 'pnt');
  98. sens.chanpos = chanpos;
  99. end
  100. end
  101. if ~isfield(sens, 'chanpos')
  102. if isgrad
  103. % sensor description is a MEG sensor-array, containing oriented coils
  104. [chanpos, chanori, lab] = channelposition(sens, 'channel', 'all');
  105. sens.chanpos = chanpos;
  106. sens.chanori = chanori;
  107. else
  108. % sensor description is something else, EEG/ECoG etc
  109. [chanpos, lab] = channelposition(sens, 'channel', 'all');
  110. sens.chanpos = chanpos;
  111. end
  112. end
  113. if ~isfield(sens, 'chantype')
  114. if isgrad
  115. sens.chantype = ft_chantype(sens);
  116. else
  117. % FIXME for EEG we have not yet figured out how to deal with this
  118. end
  119. end
  120. if ~isfield(sens, 'chanunit') && ~ft_senstype(sens, 'unknown')
  121. if ft_senstype(sens, 'ctf')
  122. sens.chanunit = repmat({'T'}, size(sens.label));
  123. elseif ft_senstype(sens, 'bti')
  124. % FIXME
  125. sens.chanunit = repmat({'unknown'}, size(sens.label));
  126. elseif ft_senstype(sens, 'neuromag')
  127. % FIXME
  128. sens.chanunit = repmat({'unknown'}, size(sens.label));
  129. elseif ft_senstype(sens, 'itab')
  130. % FIXME
  131. sens.chanunit = repmat({'unknown'}, size(sens.label));
  132. elseif ft_senstype(sens, 'yokogawa')
  133. % FIXME
  134. sens.chanunit = repmat({'unknown'}, size(sens.label));
  135. else
  136. % FIXME for EEG or other MEG systems we have not yet figured out how to deal with this
  137. end
  138. end
  139. % if ~isfield(sens, 'unit')
  140. % sens = ft_convert_units(sens);
  141. % end
  142. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  143. otherwise
  144. error('converting to version %s is not supported', version);
  145. end % switch
  146. % this makes the display with the "disp" command look better
  147. sens = sortfieldnames(sens);
  148. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  149. % SUBFUNCTION
  150. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  151. function b = sortfieldnames(a)
  152. fn = sort(fieldnames(a));
  153. for i=1:numel(fn)
  154. b.(fn{i}) = a.(fn{i});
  155. end