/spm5/spm_eeg_inv_help.m

https://bitbucket.org/matthewbrett/spm-versions · Objective C · 142 lines · 117 code · 25 blank · 0 comment · 6 complexity · b24ca6fcb4d3ad805a7df5bcfd0518a4 MD5 · raw file

  1. % This script constitutes both a help script and a batch script that can be
  2. % modified for automatic source reconstruction or EEG-MEG model inversion.
  3. % It details how fields are specified and routines are called to generate a
  4. % processing stream from the trial-averaged data structure to a smoothed
  5. % contrast or window image for subsequent between subject analyses.
  6. % Load data and specify which the inversion number
  7. %==========================================================================
  8. % We start with loading the data structure D. Each inversion is stored in the
  9. % structure array D.inv. The current inversion is indexed by D.val; here we
  10. % will assume we want to specify and invert a second model. We will also
  11. % assume that EEG data is being analysed (this simplifies the registration
  12. % step below.
  13. %--------------------------------------------------------------------------
  14. D = spm_eeg_ldata( '??????????.mat');
  15. val = 1;
  16. D.val = val;
  17. D.modality = 'EEG';
  18. D.inv{val}.method = 'Imaging';
  19. % Compute a head model
  20. %==========================================================================
  21. % The next step is to define the head model in terms of s structural MRI (sMRI)
  22. % This is not necessary if you are happy using a standard head model supplied
  23. % with SPM. We will assume this analysis is going to use a standard model, so
  24. % the normalisation and mesh routines are commented out in this script
  25. %--------------------------------------------------------------------------
  26. % specify cortical mesh size (1 tp 4; 1 = 3004, 4 = 7204 dipoles)
  27. %--------------------------------------------------------------------------
  28. D.inv{val}.mesh.Msize = 2;
  29. % spatial normalization into a MNI template
  30. %--------------------------------------------------------------------------
  31. % D.inv{val}.mesh.sMRI = '??????????.img'
  32. % D = spm_eeg_inv_spatnorm(D);
  33. % and compute meshes
  34. %--------------------------------------------------------------------------
  35. % D = spm_eeg_inv_meshing(D);
  36. % or, use a template head model and associated meshes
  37. %--------------------------------------------------------------------------
  38. D = spm_eeg_inv_template(D);
  39. % Compute a head model
  40. %==========================================================================
  41. % Next, we need to register the sensor locations to the head model meshes.
  42. % This requires one to specify mat files describing the location of the sensors
  43. % and supplementary information about the cortical surface, which is in the
  44. % same frame of reference. The simplest way to do this is to use a Polhemus
  45. % file that contains both the locations of the fiducials and sensor locations.
  46. % To keep things simple, we will assume that we are analysing EEG. In this
  47. % case, the sensor locations also define the scalp surface and can be uses in
  48. % the registration to the head model.
  49. %--------------------------------------------------------------------------
  50. % get fiducials and head shape
  51. %--------------------------------------------------------------------------
  52. pol_file = 'C:\home\spm\Grandmean\standard_09_03_2004.pol';
  53. pol_skip = 2;
  54. [fid_eeg,headshape] = spm_eeg_inv_ReadPolhemus(pol_file,pol_skip);
  55. % get sensor locations
  56. %--------------------------------------------------------------------------
  57. if strcmp(D.modality,'EEG')
  58. sensors = headshape;
  59. else
  60. sensors = '?????????.mat';
  61. name = fieldnames(sensors);
  62. sensors = getfield(sensors,name{1});
  63. end
  64. D.inv{val}.datareg.sensors = sensors;
  65. D.inv{val}.datareg.fid_eeg = fid_eeg;
  66. D.inv{val}.datareg.headshape = headshape;
  67. D.inv{val}.datareg.megorient = sparse(0,3);
  68. % register data
  69. %--------------------------------------------------------------------------
  70. D = spm_eeg_inv_datareg(D);
  71. % Compute a forward model
  72. %==========================================================================
  73. % Next, using the geometry of the head model and the location of registered
  74. % sensors, we can now compute a forward model for each dipole and save it in a
  75. % lead-field or gain matrix. This is the basis of our likelihood model.
  76. %--------------------------------------------------------------------------
  77. D.inv{val}.forward.method = 'eeg_3sphereBerg';
  78. D = spm_eeg_inv_BSTfwdsol(D);
  79. % Invert the forward model
  80. %==========================================================================
  81. % Next, we invert the forward model using the trials or conditions of interest,
  82. % specified in the field 'trials'. The full model needs specifying in terms
  83. % of its priors, through the fields below.
  84. %--------------------------------------------------------------------------
  85. D.inv{val}.inverse.trials = [1 2]; % Trials
  86. D.inv{val}.inverse.type = 'MSP'; % Priors on sources MSP, LOR or IID
  87. D.inv{val}.inverse.smooth = 0.4; % Smoothness of source priors (mm)
  88. D.inv{val}.inverse.Np = 64; % Number of sparse priors (x 1/2)
  89. % We can also restrict solutions to bilateral spheres in source space
  90. %--------------------------------------------------------------------------
  91. D.inv{val}.inverse.xyz = [-48 0 0;
  92. 48 0 0]; % x,y,z and radius (mm)
  93. D.inv{val}.inverse.rad = [ 32 32];
  94. % and finally, invert
  95. %--------------------------------------------------------------------------
  96. D = spm_eeg_invert(D);
  97. % Compute conditional expectation of mean square (MS) response
  98. %==========================================================================
  99. % The penultimate step is to specify a time-frequency window and compute the
  100. % conditional expectation of the MS response. A simple windowed average
  101. % is a special case of this, where the frequency is zero. In this context,
  102. % the RMS is the same as the absolute value of the time-averaged repsone.
  103. % set time-frequency window
  104. %--------------------------------------------------------------------------
  105. D.inv{val}.contrast.woi = [100 200]; % peristimulus time (ms)
  106. D.inv{val}.contrast.fboi = [2 32]; % frequency window (Hz)
  107. % and evaluate contrast
  108. %--------------------------------------------------------------------------
  109. D = spm_eeg_inv_results(D);
  110. % Convert mesh data into an image for further analysis
  111. %==========================================================================
  112. % Finally, write the smoothed contrast to an image in voxel space. The file
  113. % name will correspond to the data name and current inversion (i.e., D.val)
  114. %--------------------------------------------------------------------------
  115. D.inv{D.val}.contrast.smooth = 8; % FWHM (mm)
  116. D.inv{D.val}.contrast.display = 0;
  117. D = spm_eeg_inv_Mesh2Voxels(D);