runstim_CheckSNR.m 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. function runstim_CheckSNR(T_Trl)
  2. global Par %global parameters
  3. % global LPStat %das status values
  4. FixWinSizex = 1.3;
  5. FixWinSizey = 1.3;
  6. %Plot marker at RF loc
  7. % RFon = 0;
  8. %
  9. % cgflip(0.5,0.5,0.5)
  10. % cgflip(0.5,0.5,0.5)
  11. % cgrect(45,-140,100,100,[1,1,1])
  12. % cgflip(0.5,0.5,0.5)
  13. % pause
  14. rand('state',sum(clock))
  15. %Global properties -assumes 85Hz
  16. frame = 1./85;
  17. %Dot sizes
  18. FixDotSize = 0.3;
  19. FixPix = Par.PixPerDeg.*FixDotSize;
  20. TargSz = 0.3.*Par.PixPerDeg;
  21. Px = 0;
  22. Py = 0;
  23. %Make a checkerboard sprite
  24. checksz = 1.*Par.PixPerDeg;
  25. Grid_x = -800:checksz:800;
  26. Grid_y = -650:checksz:650;
  27. drawon = 1;
  28. cgmakesprite(1,1600,1300,[0,0,0])
  29. cgsetsprite(1)
  30. for y = 1:length(Grid_y)
  31. drawon = 1-drawon;
  32. for x = 1:length(Grid_x)
  33. drawon = 1-drawon;
  34. if drawon
  35. cgrect(Grid_x(x),Grid_y(y),checksz,checksz,[1,1,1])
  36. end
  37. end
  38. end
  39. cgsetsprite(0)
  40. %Tracker times
  41. FIXT = 400; %time to fix before stim onset
  42. TARGT = 400; %800 %time to target
  43. STIMT = TARGT; %This is irrelevent for this stimulus, we keep in just for form's sake
  44. %TARGT is the exposure time of the RF mapping bar
  45. Times = Par.Times; %copy timing structure
  46. BG = [0.5 0.5 0.5]; %background Color
  47. %Create log file
  48. LOG.fn = 'runstim_RFauto';
  49. LOG.BG = BG;
  50. LOG.Par = Par;
  51. LOG.Times = Times;
  52. LOG.Frame = frame;
  53. LOG.FIXT = FIXT;
  54. LOG.TARGT = TARGT;
  55. LOG.STIMT = STIMT;
  56. LOG.ScreenX = 1024;
  57. LOG.Screeny = 768;
  58. mydir = 'C:\Users\Xing\L\RF_mapping_logs\';
  59. fn = input('Enter LOG file name (e.g. 20110413_B1), blank = no file\n','s');
  60. if isempty(fn)
  61. logon = 0;
  62. else
  63. logon = 1;
  64. fn = [mydir,'CheckSNR_',fn];
  65. save(fn,'LOG')
  66. end
  67. %Copy the run stime
  68. fnrs = [fn,'_','runstim.m'];
  69. cfn = [mfilename('fullpath') '.m'];
  70. copyfile(cfn,fnrs)
  71. %////YOUR STIMULATION CONTROL LOOP /////////////////////////////////
  72. Hit = 2;
  73. TZ = 0;
  74. %timing
  75. PREFIXT = Times.ToFix; %time to enter fixation window
  76. %Windows (fix and target)
  77. WIN = [0 0 Par.PixPerDeg.*FixWinSizex Par.PixPerDeg.*FixWinSizey 0];
  78. Par.WIN = WIN';
  79. Par.ESC = false; %escape has not been pressed
  80. while ~Par.ESC
  81. %Pretrial
  82. dasword(1);
  83. %/////////////////////////////////////////////////////////////////////
  84. %START THE TRIAL
  85. %set control window positions and dimensions
  86. refreshtracker(1) %for your control display
  87. SetWindowDas %for the dascard
  88. Abort = false; %whether subject has aborted before end of trial
  89. %///////// EVENT 0 START FIXATING //////////////////////////////////////
  90. Par.Updatxy = 1;
  91. cgellipse(Px,Py,FixPix,FixPix,[1,0,0],'f') %the red fixation dot on the screen
  92. cgflip(BG(1), BG(2), BG(3))
  93. dasreset(0)
  94. %subject has to start fixating central dot
  95. Par.SetZero = false; %set key to false to remove previous presses
  96. Par.Updatxy = 1; %centering key is enabled
  97. Time = 1;
  98. Hit = 0;
  99. while Time < PREFIXT && Hit == 0
  100. dasrun(5)
  101. [Hit Time] = DasCheck; %retrieve position values and plot on Control display
  102. end
  103. %///////// EVENT 1 KEEP FIXATING or REDO ////////////////////////////////////
  104. Par.Updatxy = 1;
  105. if Hit ~= 0 %subjects eyes are in fixation window keep fixating for FIX time
  106. dasreset(1); %test for exiting fix window
  107. Time = 1;
  108. Hit = 0;
  109. while Time < FIXT && Hit == 0
  110. %Check for 5 ms
  111. dasrun(5)
  112. %or just pause for 5ms?
  113. [Hit Time] = DasCheck;
  114. end
  115. if Hit ~= 0 %eye has left fixation to early
  116. %possibly due to eye overshoot, give another chance
  117. dasreset(0);
  118. Time = 1;
  119. Hit = 0;
  120. while Time < PREFIXT && Hit == 0
  121. dasrun(5)
  122. [Hit Time] = DasCheck; %retrieve position values and plot on Control display
  123. end
  124. if Hit ~= 0 %subjects eyes are in fixation window keep fixating for FIX time
  125. dasreset(1); %test for exiting fix window
  126. Time = 1;
  127. Hit = 0;
  128. while Time < FIXT && Hit == 0
  129. %Check for 5 ms
  130. dasrun(5)
  131. % dasrun(5)
  132. [Hit Time] = DasCheck;
  133. end
  134. else
  135. Hit = -1; %the subject did not fixate
  136. end
  137. end
  138. else
  139. Hit = -1; %the subject did not fixate
  140. end
  141. %///////// EVENT 2 DISPLAY STIMULUS //////////////////////////////////////
  142. if Hit == 0 %subject kept fixation, display stimulus
  143. Par.Updatxy = 1;
  144. dasreset(1); %test for exiting fix window
  145. Time = 0;
  146. cgdrawsprite(1,randi(round(2*Par.PixPerDeg)),randi(round(2*Par.PixPerDeg)))
  147. cgellipse(Px,Py,FixPix,FixPix,[1,0,0],'f') %the red fixation dot on the screen
  148. cgflip(BG(1), BG(2), BG(3));
  149. dasbit(Par.StimB, 1);
  150. while Time < TARGT && Hit == 0 %Keep fixating till target onset
  151. %Check for 5 ms
  152. dasrun(5)
  153. [Hit Time] = DasCheck;
  154. end
  155. %///////// EVENT 3 TARGET ONSET, REACTION TIME //////////////////////////////////////
  156. Par.Updatxy = 1;
  157. if Hit == 0 %subject kept fixation
  158. cgellipse(0,0,TargSz,TargSz,[0.6,0.2,0.6],'f') %the red fixation dot on the screen
  159. cgflip(BG(1), BG(2), BG(3))
  160. dasbit(Par.TargetB, 1);
  161. %EXTRACT USING THE TARGETB
  162. Hit = 2;
  163. else
  164. Abort = true;
  165. end
  166. %END EVENT 3
  167. else
  168. Abort = true;
  169. end
  170. %END EVENT 2
  171. %///////// POSTTRIAL AND REWARD //////////////////////////////////////
  172. if Hit ~= 0 && ~Abort %has entered a target window (false or correct)
  173. % if Par.Mouserun
  174. % HP = line('XData', Par.ZOOM * (LPStat(3) + Par.MOff(1)), 'YData', Par.ZOOM * (LPStat(4) + Par.MOff(2)), 'EraseMode','none');
  175. % else
  176. % HP = line('XData', Par.ZOOM * LPStat(3), 'YData', Par.ZOOM * LPStat(4), 'EraseMode','none');
  177. % end
  178. % set(HP, 'Marker', '+', 'MarkerSize', 20, 'MarkerEdgeColor', 'm')
  179. if Hit == 2
  180. % dasbit(Par.MicroB, 1);
  181. % dasbit(Par.CorrectB, 1);
  182. % dasbit(Par.RewardB, 1);
  183. dasjuice(5.1);
  184. Par.Corrcount = Par.Corrcount + 1;
  185. pause(Par.RewardTime) %RewardTime is in seconds
  186. dasjuice(0.0);
  187. % dasbit(Par.RewardB, 0);
  188. else
  189. Hit = 0;
  190. end
  191. %keep following eye motion
  192. dasrun(5)
  193. DasCheck; %keep following eye motion
  194. end
  195. %///////////////////////INTERTRIAL AND CLEANUP
  196. % display([ num2str(Hit) ' ' num2str(LPStat(6)) ' ' num2str(LPStat(7)) ' ' num2str(Time - LPStat(7)) ]);
  197. %reset all bits to null
  198. for i = [0 1 2 3 4 5 6 7] %Error, Stim, Saccade, Trial, Correct,
  199. dasbit(i, 0);
  200. end
  201. dasclearword
  202. %Par.Trlcount = Par.Trlcount + 1; %counts total number of trials for this session
  203. %tracker('update_trials', gcbo, [], guidata(gcbo)) %displays number of trials, corrects and errors
  204. Par.Trlcount = Par.Trlcount + 1; %counts total number of trials for this session
  205. SCNT = {'TRIALS'};
  206. SCNT(2) = { ['N: ' num2str(Par.Trlcount) ]};
  207. SCNT(3) = { ['C: ' num2str(Par.Corrcount) ] };
  208. SCNT(4) = { ['E: ' num2str(Par.Errcount) ] };
  209. set(T_Trl, 'String', SCNT ) %display updated numbers in GUI
  210. [Hit T] = DasCheck;
  211. % cgrect(465,-370,50,50,[1,1,1])
  212. cgflip(BG(1), BG(2), BG(3))
  213. % pause( Times.InterTrial/1000 ) %pause is called with seconds
  214. %Times.InterTrial is in ms
  215. if TZ > 0
  216. save(fn,'LOG')
  217. end
  218. end %WHILE_NOT_ESCAPED%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%