meeg.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. function D = meeg(varargin)
  2. % Function for creating meeg objects.
  3. % FORMAT
  4. % D = meeg;
  5. % returns an empty object
  6. % D = meeg(D);
  7. % converts a D struct to object or does nothing if already
  8. % object
  9. % D = meeg(nchannels, nsamples, ntrials)
  10. % return a time dataset with default settings
  11. % D = meeg(nchannels, nfrequencies, nsamples, ntrials)
  12. % return TF time dataset with default settings
  13. %
  14. % SPM MEEG format consists of a header object optionally linked to
  15. % binary data file. The object is usually saved in the header mat file
  16. %
  17. % The header file will contain a struct called D. All
  18. % information other than data is contained in this struct and access to the
  19. % data is via methods of the object. Also, arbitrary data can be stored
  20. % inside the object if their field names do not conflict with existing
  21. % methods' names.
  22. %
  23. % The following is a description of the internal implementation of meeg.
  24. %
  25. % Fields of meeg:
  26. % .type - type of data in the file: 'continuous', 'single', 'evoked'
  27. % .Fsample - sampling rate
  28. %
  29. % .data - file_array object linking to the data or empty if unlinked
  30. %
  31. %
  32. % .Nsamples - length of the trial (whole data if the file is continuous).
  33. % .timeOnset - the peri-stimulus time of the first sample in the trial (in sec)
  34. %
  35. % .fname, .path - strings added by spm_eeg_load to keep track of where a
  36. % header struct was loaded from.
  37. %
  38. % .trials - this describes the segments of the epoched file and is also a
  39. % structure array.
  40. %
  41. % Subfields of .trials
  42. %
  43. % .label - user-specified string for the condition
  44. % .onset - time of the first sample in seconds in terms of the
  45. % original file
  46. % .bad - 0 or 1 flag to allow rejection of trials.
  47. % .repl - for epochs that are averages - number of replications used
  48. % for the average.
  49. % .tag - the user can put any data here that will be attached to
  50. % the respective trial. This is useful e.g. to make sure the
  51. % relation between regressors and data is not broken when
  52. % removing bad trials or merging files.
  53. % .events - this is a structure array describing events related to
  54. % each trial.
  55. %
  56. % Subfields of .events
  57. %
  58. % .type - string (e.g. 'front panel trigger')
  59. % .value - number or string, can be empty (e.g. 'Trig 1').
  60. % .time - in seconds in terms of the original file
  61. % .duration - in seconds
  62. %
  63. % .channels - This is a structure array which is a field of meeg.
  64. % length(channels) should equal size(.data.y, 1) and the order
  65. % must correspond to the order of channels in the data.
  66. %
  67. % Subfields of .channels
  68. %
  69. % .label - channel label which is always a string
  70. % .type - a string, possible values - 'MEG', 'EEG', 'VEOG', 'HEOG',
  71. % 'EMG' ,'LFP' etc.
  72. % .units - units of the data in the channel.
  73. % .bad - 0 or 1 flag to mark channels as bad.
  74. % .X_plot2D, .Y_plot2D - positions on 2D plane (formerly in ctf). NaN
  75. % for channels that should not be plotted.
  76. %
  77. % .sensors
  78. %
  79. %
  80. % Subfields of .sensors (optional)
  81. % .meg - struct with sensor positions for MEG (subfields: .pnt .ori .tra .label)
  82. % .eeg - struct with sensor positions for MEG (subfields: .pnt .tra .label)
  83. %
  84. % .fiducials - headshape and fiducials for coregistration with sMRI
  85. %
  86. % Subfiels of .fiducials (optional)
  87. % .pnt - headshape points
  88. % .fid.pnt - fiducial points
  89. % .fid.label - fiducial labels
  90. %
  91. % .transform - additional information for transfomed (most commonly time-frequency) data
  92. % Subfields of .transform
  93. % .ID - 'time', 'TF', or 'TFphase'
  94. % .frequencies (optional)
  95. %
  96. % .history - structure array describing commands that modified the file.
  97. %
  98. % Subfields of .history:
  99. %
  100. % .function - string, the function name
  101. % .arguments - cell array, the function arguments
  102. % .time - when function call was made
  103. %
  104. % .other - structure used to store other information bits, not fitting the
  105. % object structure at the moment,
  106. % for example:
  107. % .inv - structure array corresponding to the forw/inv problem in MEEG.
  108. % .val - index of the 'inv' solution currently used.
  109. %
  110. % .condlist - cell array of unique condition labels defining the proper
  111. % condition order
  112. %
  113. % .montage - structure used to store info on on-line montage used
  114. % .M contains transformation matrix of the montage and names of
  115. % original and new channels (+ new channels definition)
  116. % .Mind indicates which montage to use
  117. %__________________________________________________________________________
  118. % Copyright (C) 2005-2011 Wellcome Trust Centre for Neuroimaging
  119. % Vladimir Litvak
  120. % $Id: meeg.m 6525 2015-08-20 10:03:16Z vladimir $
  121. switch nargin
  122. case 0
  123. D = struct('Nsamples', 0);
  124. case 1
  125. D = varargin{1};
  126. case 2
  127. error('Illegal number of arguments');
  128. case 3
  129. D = struct('Nsamples', varargin{2}, ...
  130. 'channels', struct('bad', num2cell(zeros(1, varargin{1}))), ...
  131. 'trials', struct('bad', num2cell(zeros(1, varargin{3}))));
  132. case 4
  133. D = struct('Nsamples', varargin{3}, ...
  134. 'channels', struct('bad', num2cell(zeros(1, varargin{1}))), ...
  135. 'trials', struct('bad', num2cell(zeros(1, varargin{4}))));
  136. D.transform.ID = 'TF';
  137. D.transform.frequencies = 1:varargin{2};
  138. end
  139. if ~isa(D, 'meeg')
  140. D = class(checkmeeg(D), 'meeg');
  141. end