attachment:present_pics_v3.m of SearchingBroadStimulusSets - CBU Base Wiki
location: attachment:present_pics_v3.m of SearchingBroadStimulusSets

Attachment 'present_pics_v3.m'

Download

   1 %FacesExperiment_DAI
   2 %Presents 92 images randomly
   3 %
   4 %abort the experiment by pressing any key
   5 %if experiment crashes for whatever reason press ctrl+c to get keyboard
   6 %function back
   7 %mv02 19/03 
   8 %Back to original timings, 2 secs pic, 4 sec rest and null events 
   9 
  10 clear all;
  11 KbName('UnifyKeyNames');
  12 
  13 %% SCANNERSYNC
  14 TR=1000; % TR in ms
  15 numdummies=20;
  16 
  17 % Create & initialise scanner sync object
  18 objSS=actxserver('MRISync.ScannerSync');  %Create a scanner object
  19 invoke(objSS,'Initialize','') %Initialise the Keithley board and object
  20 invoke(objSS,'SetMSPerSample',2); %Set “StartExperiment” routines’ sampling
  21 
  22 %Create subject files
  23 subjectNum = input('please enter the subject number:', 's');
  24 sessionNum = input('please enter the session number:', 's');
  25 fid=fopen('Results.txt','a');
  26 fprintf(fid,['***New session at ' datestr(now) '\n']);
  27 fprintf(fid, '%s\n', 'subjectNum sessionNum whichpicture');
  28 fclose('all');
  29 
  30 %ListenChar(2);   %prevents writing into the command window during the experiment
  31 
  32 %open screen
  33 try %embedded in try-catch in case something goes wrong
  34     whichScreen = 0;
  35     window = Screen(whichScreen, 'OpenWindow');
  36 
  37     white = WhiteIndex(window); % pixel value for white
  38     black = 128; % pixel value for grey
  39     Screen(window,'FillRect', black);
  40     HideCursor;
  41     WaitSecs(0.5);
  42 
  43     % onscreen instructions
  44     info =  ['You will be presented with a series of pictures' ...
  45         '\n\nPlease pay attention to the pictures' ...
  46         '\n\nThe experiment will begin after a countdown'];
  47 
  48     DrawFormattedText(window, info, 'center', 'center', white);
  49     Screen(window, 'Flip');
  50     %WaitSecs(10);  % now, wait below until first pulse
  51 
  52 
  53     % ScannerSync - waits for the first pulse, resets timer to 0, sets TR
  54     invoke(objSS,'StartExperiment', double(TR));
  55 
  56 
  57     %SCANNER PULSE IMPUT HERE%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  58     for countdown=(numdummies-1):-1:2 % two less as StartExperiment command above will already have heard a pulse and first trial waits for a pulse
  59         %cd_adjust=-2*countdown+6;
  60         %cd=countdown+cd_adjust;
  61         count_text=sprintf('%d', countdown);
  62         DrawFormattedText(window, count_text, 'center', 'center', white);
  63         Screen(window, 'Flip');
  64         WaitSecs(1.0);
  65     end;
  66 
  67     DrawFormattedText(window, '+', 'center', 'center', white);
  68     Screen(window, 'Flip');
  69     WaitSecs(1.5);  % a little less as will synchronise to next pulse below
  70 
  71     trialnum=1; % this includes the nulls
  72     while(1)
  73         while(1)
  74 
  75             %load picture
  76             parmfile=sprintf('c:\\temp\\parm%d.txt',trialnum);
  77             trialnum=trialnum+1;
  78             fprintf('Parameter file is %s\n',parmfile);
  79             dirfile=dir(parmfile);
  80             modtime=datestr(dirfile.date);
  81             accesstime=datestr(now);
  82             fid=fopen(parmfile,'r');
  83             whichpicture=str2num(fgetl(fid));
  84             fclose(fid);
  85 
  86             % -1 means end of session
  87             % -99 means end of experiment
  88             if (whichpicture==-1)
  89                 break;
  90             end;
  91             if (whichpicture==-99)
  92 
  93                 done = ['Thank you!'];
  94                 DrawFormattedText(window, done, 'center', 'center', white);
  95                 Screen(window, 'Flip');
  96                 WaitSecs(20);
  97 
  98                 Screen('CloseAll');
  99                 ShowCursor
 100                 return;
 101             end;
 102 
 103             % 0 means null trial
 104             if (whichpicture==0)
 105                 % SCANNERSYNC
 106                 invoke(objSS,'SynchroniseExperiment',1,0); %Set “StartExperiment” routines’ sampling
 107                 %null events (fixation screen)
 108                 WaitSecs(3.5); % A little less as will synchronise at start of next trial
 109             else
 110 
 111                 fprintf('File %s value of whichpicture %d\n',parmfile, whichpicture);
 112 
 113 
 114                 %    whichpicture=pics_shuffled(1,pics);
 115                 picture_name=sprintf('stimulus_big%d.TIF',whichpicture);
 116                 trialpicture=imread(picture_name, 'TIF');
 117                 % SCANNERSYNC
 118                 invoke(objSS,'SynchroniseExperiment',1,0); %Set “StartExperiment” routines’ sampling
 119 
 120                 %                 scaleby=2;
 121                 %
 122                 %                 trialpicture=double(trialpicture);
 123                 %                 for colourplane=1:3
 124                 %                     t(:,:,colourplane)=interp2(squeeze(trialpicture(:,:,colourplane)),scaleby);
 125                 %                 end;
 126 
 127                 %present picture for two seconds
 128                 tex=Screen('MakeTexture', window, trialpicture);
 129                 Screen('DrawTexture', window, tex); %needs to be adjusted depending on the size of the picture!
 130                 Screen(window, 'Flip');             %left, top, right, bottom; to make a square the difference between left-right and bottom-top must be the same!
 131 
 132                 % SCANNERSYNC
 133                 picstarttime=invoke(objSS,'SSGetTimer')
 134                 WaitSecs(2);
 135 
 136                 %present fixation cross for two seconds
 137                 DrawFormattedText(window, '+', 'center', 'center', white);
 138                 Screen(window, 'Flip');
 139 
 140                 % Unload the texture or it complains when there are lots
 141                 % loaded up
 142                 Screen('Close', tex);
 143 
 144                 WaitSecs(1.5); % A little less as will synchronise at start of next trial
 145 
 146                 %write to file
 147                 fid = fopen('Results.txt','a');
 148                 fprintf(fid, '%2s\t%1s\t%d\t%f\t%s\t%s\n', subjectNum, sessionNum, whichpicture, picstarttime,modtime,accesstime);
 149                 fclose(fid);
 150 
 151                 %terminate as per real-time instructions
 152 
 153 
 154                 %abort experiment
 155                 %abort=CharAvail;
 156                 %if abort==1
 157                 %      error('aborted by user');
 158                 %end;
 159             end;
 160         end;
 161 
 162         %end
 163 
 164         %KbWait;
 165         %while KbCheck; end;
 166         done = ['Brief pause,'...
 167             '\n\nplease remain fixated on the cross.'];
 168         DrawFormattedText(window, done, 'center', 'center', white);
 169         Screen(window, 'Flip');
 170         WaitSecs(3);
 171         % ...3 s here...
 172         %pause for real-time catch and wait for instructions
 173         DrawFormattedText(window, '+', 'center', 'center', white);
 174         Screen(window, 'Flip');
 175         % ...20.25 s here...
 176         WaitSecs(8.25);
 177         for waiti=1:36
 178             WaitSecs(1.0);
 179         end;
 180        % ...then the pulse, and we'll get a nice round 24 s                ...
 181         invoke(objSS,'SynchroniseExperiment',1,0); %Set “StartExperiment” routines’ sampling
 182 
 183     end
 184     %close
 185     Screen('CloseAll');
 186     ShowCursor
 187 
 188 catch
 189     % This "catch" section executes in case of an error in the "try" section
 190     % above.  Importantly, it closes the onscreen window if it's open.
 191     Screen('CloseAll');
 192     psychrethrow(psychlasterror);
 193     ShowCursor
 194     %ListenChar(0);
 195 end %end of try-catch
 196 
 197 %ListenChar(0);

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-05-11 15:03:39, 7.0 KB) [[attachment:SearchingBroadStimulusSets]]
  • [get | view] (2009-05-12 13:23:19, 162.5 KB) [[attachment:mvpa2.PNG]]
  • [get | view] (2009-05-11 15:05:29, 7.0 KB) [[attachment:present_pics_v3.m]]
  • [get | view] (2009-05-14 14:40:37, 49.3 KB) [[attachment:stimuli.png]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.