example1.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. %% Example 1: Run analyzePRF on an example dataset
  2. %% Download dataset (if necessary) and add analyzePRF to the MATLAB path
  3. setup;
  4. %% Load in the data
  5. % Load in the data
  6. load('exampledataset.mat');
  7. % Check the workspace
  8. whos
  9. %%
  10. %% Inspect the data
  11. % Check dimensionality of the data
  12. data
  13. %%
  14. % There are four runs of data; each run consists of 150 time points (TR = 2 s).
  15. % The data have already been pre-processed for slice timing correction, motion
  16. % correction, and spatial undistortion. For simplicity, we have selected
  17. % 10 example voxels from the left hemisphere. Let's visualize the time-series
  18. % data for the second voxel.
  19. temp = cellfun(@(x) x(2,:),data,'UniformOutput',0);
  20. figure; hold on;
  21. set(gcf,'Units','points','Position',[100 100 600 150]);
  22. plot(cat(2,temp{:}),'r-');
  23. straightline(150*(1:4)+.5,'v','g-');
  24. xlabel('TR');
  25. ylabel('BOLD signal');
  26. ax = axis;
  27. axis([.5 600+.5 ax(3:4)]);
  28. title('Time-series data');
  29. %%
  30. %% Inspect the stimuli
  31. % Check dimensionality of the stimuli
  32. stimulus
  33. %%
  34. % The stimulus images have been prepared at a resolution of 100 pixels x 100 pixels.
  35. % There are 300 images per run because we have prepared the images at a time resolution
  36. % of 1 second. (Note that this is faster than the data sampling rate. When analyzing
  37. % the data, we will resample the data to match the stimulus rate.) Let's inspect a
  38. % few of the stimulus images in the first run.
  39. figure;
  40. set(gcf,'Units','points','Position',[100 100 700 300]);
  41. for p=1:3
  42. subplot(1,3,p); hold on;
  43. num = 239+2*p;
  44. imagesc(stimulus{1}(:,:,num),[0 1]);
  45. axis image tight;
  46. set(gca,'YDir','reverse');
  47. colormap(gray);
  48. title(sprintf('Image number %d',num));
  49. end
  50. %%
  51. % Notice that the range of values is 0 to 1 (0 indicates that the gray background was
  52. % present; 1 indicates that the stimulus was present). For these stimulus images,
  53. % the stimulus is a bar that moves downward and to the left.
  54. %% Analyze the data
  55. % Start parallel MATLAB to speed up execution.
  56. %if matlabpool('size')==0
  57. % matlabpool open;
  58. %end
  59. % new parallel processing method [CK]
  60. if ~exist('mypool','var')
  61. mypool=parpool();
  62. end
  63. % We need to resample the data to match the temporal rate of the stimulus. Here we use
  64. % cubic interpolation to increase the rate of the data from 2 seconds to 1 second (note
  65. % that the first time point is preserved and the total data duration stays the same).
  66. data = tseriesinterp(data,2,1,2);
  67. % Finally, we analyze the data using analyzePRF. The third argument is the TR, which
  68. % is now 1 second. The default analysis strategy involves two generic initial seeds
  69. % and an initial seed that is computed by performing a grid search. This last seed is
  70. % a little costly to compute, so to save time, we set 'seedmode' to [0 1] which means
  71. % to just use the two generic initial seeds. We suppress command-window output by
  72. % setting 'display' to 'off'.
  73. results = analyzePRF(stimulus,data,1,struct('seedmode',[0 1],'display','off'));
  74. %%
  75. % Note that because of the use of parfor, the command-window output for different
  76. % voxels will come in at different times (and so the text above is not really
  77. % readable).
  78. %% Inspect the results
  79. % The stimulus is 100 pixels (in both height and weight), and this corresponds to
  80. % 10 degrees of visual angle. To convert from pixels to degreees, we multiply
  81. % by 10/100.
  82. cfactor = 10/100;
  83. % Visualize the location of each voxel's pRF
  84. figure; hold on;
  85. set(gcf,'Units','points','Position',[100 100 400 400]);
  86. cmap = jet(size(results.ang,1));
  87. for p=1:size(results.ang,1)
  88. xpos = results.ecc(p) * cos(results.ang(p)/180*pi) * cfactor;
  89. ypos = results.ecc(p) * sin(results.ang(p)/180*pi) * cfactor;
  90. ang = results.ang(p)/180*pi;
  91. sd = results.rfsize(p) * cfactor;
  92. h = drawellipse(xpos,ypos,ang,2*sd,2*sd); % circle at +/- 2 pRF sizes
  93. set(h,'Color',cmap(p,:),'LineWidth',2);
  94. set(scatter(xpos,ypos,'r.'),'CData',cmap(p,:));
  95. end
  96. drawrectangle(0,0,10,10,'k-'); % square indicating stimulus extent
  97. axis([-10 10 -10 10]);
  98. straightline(0,'h','k-'); % line indicating horizontal meridian
  99. straightline(0,'v','k-'); % line indicating vertical meridian
  100. axis square;
  101. set(gca,'XTick',-10:2:10,'YTick',-10:2:10);
  102. xlabel('X-position (deg)');
  103. ylabel('Y-position (deg)');
  104. %%
  105. % Please see the example2.m script for an example of how to inspect the model fit
  106. % and compare it to the data.