1- % function mirror_runMTLocalizer
2- clear all ;
3- clc
4-
5- % 8 trials = 370 sec (without trigger) =6.17 minutes
6- % if TR =2 Sec. 370 sec / 2 (TR) = 185 TRs (without trigger) + 4 = 189 TRs
7- % if TR =2.5 Sec. 370 sec / 2 (TR) = 148 TRs (without trigger) + 4 = 152 TRs
8-
9- %% To correct for the y-axis problem inside the scanner
10- % where the lower 1/3 of the screen is not appearing because of coil indicate which device the script is running on, on PC, the middle of the
11- % y axis will be the middle of the screen, on the Scanner, the middle of y-axis will be the middle of the upper 2/3 of the screen, because the
12- % lower 1/3 is not visible due to the coil in the scanner.
13- device = ' Scanner' ;
14- % device = 'PC';
15-
16- fprintf(' Connected Device is %s \n\n ' ,device );
17-
18- % Original Script Written by Sam Weiller to localize MT+/V5
19- % Adapted by M.Rezk to localize MT/MST (Huk,2002)
20- %% Start me up
21- % Get the subject Name
22- SubjName = input(' Subject Name: ' ,' s' );
23- if isempty(SubjName )
24- SubjName = ' trial' ;
25- end
26-
27- fprintf(' Auditory MT Localizer \n\n ' )
28-
291%% Experiment Parametes
30- % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31- initial_wait = 5 ; % seconds to have a blank screen at the beginning, the scans will be discarded until % the magnetic field is homogenous
32- finalWait = 5 ;
33- % blockDur = 16; % Block duration [should be a multiple of osc (below)]
34- ISI = 0.1 ; % Interstimulus Interval between events in the block.
35- ibi = 6 ; % Inter-block duration in seconds (time between blocks)
36- nrBlocks = 14 ; % Number of trials , where 1 block = 1 block of all conditions (static and motion)
37- numEventsPerBlock = 12 ;
38- range_targets = [0 2 ]; % range of number of targets in each block (from 2 to 5 targets in each block)
39-
40- mirror_width= 11.5 ; % Width (x-axis) of the mirror (in cm)
41- v_dist = 14 ; % viewing distance from the mirror (cm) "in this script we use mirror"
42- fix_r = 0.15 ; % radius of fixation point (deg)
43-
44- % Audiofile_duration = 16 ; % Length of the Audio file (in seconds)
45- % Stop_audiofile = blockDur ; % Let the audio file play for x Seconds
46- % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 1 Cycle = one inward and outward motion together
472%% Experimental Design
48- % function "experimental_design" while assign the blocks, conditions, and
3+ % function "experimental_design" while assign the blocks, conditions, and
494% the number of targets that will be used in the motion localizer
50- % [names,targets,condition] = experimental_design(nrBlocks,range_targets);
5+ % [names,targets,condition] = experimental_design(nrBlocks,range_targets);
516[names ,targets ,condition ,directions ,isTarget ] = experimental_design(nrBlocks ,numEventsPerBlock ,range_targets ) ;
527
538numBlocks = length(names ); % Create a variable with the number of blocks in the whole experiment
549
5510
56- %% InitializePsychAudio;
57- InitializePsychSound(1 );
58-
59- [soundData , freq ] = loadAudioFiles(SubjName );
60- phandle = PsychPortAudio(' Open' ,[],[],1 ,freq ,2 );
61- % PsychPortAudio('FillBuffer',phandle,soundData_static);
62- % fprintf('\nstatic wav file loaded. \n')
63-
64- %% PTB Setup
65- screenNumber = max(Screen(' Screens' ));
66- % screenNumber = 0;
67- % Screen('Preference', 'SkipSyncTests', 2);
68- [w , winRect , xMid , yMid ] = startPTB(screenNumber , 1 , [128 128 128 ]);
69- HideCursor ;
70-
71- %% Color indeces, and Screen parameters and inter-flip interval.
72- % Color indices
73- white = WhiteIndex(screenNumber );
74- black = BlackIndex(screenNumber );
75- grey = ceil((white + black )/2 );
76-
77- % Flip interval and screen size
78- ifi = Screen(' GetFlipInterval' , w ); % Get the flip interval
79- [tw , th ] = Screen(' WindowSize' , w );
80-
81- % nframes = floor(blockDur/ifi);
82- % while mod(nframes,2)~=0 % make sure the nframes are even number
83- % nframes = nframes-1; % to be able to re-assign dots in the static condition (to perform divison calculation)
84- % end
85-
86- %% Welcome screen
87- Screen(' TextFont' ,w , ' Courier New' );
88- Screen(' TextSize' ,w , 20 );
89- Screen(' TextStyle' , w , 1 );
90- DrawFormattedText(w ,' Press for FASTER sound \n\n\n (static or motion)' ,...
91- ' center' , ' center' , black );
92- Screen(' Flip' , w );
93- [~ , ~ , ~ ]=KbCheck ;
94- KbWait ;
95- Screen(' Flip' , w );
96-
97- WaitSecs(0.25 );
98-
99- % DrawFormattedText(w,'The experiment is about to begin','center', 'center', black);
100- % Screen('Flip', w);
101- % [KeyIsDown, pend, KeyCode]=KbCheck;
102- %
103- % KbWait;
104- % Screen('Flip', w);
105-
10611%% FUNCTION
10712if strcmp(device ,' PC' )
10813 DrawFormattedText(w ,' Waiting For Trigger' ,...
10914 ' center' , ' center' , black );
11015 Screen(' Flip' , w );
111-
16+
11217 % press key
11318 KbWait();
11419 KeyIsDown= 1 ;
11520 while KeyIsDown > 0
11621 [KeyIsDown , ~ , ~ ]=KbCheck ;
11722 end
118-
23+
11924% open Serial Port "SerPor" - COM1 (BAUD RATE: 11520)
12025elseif strcmp(device ,' Scanner' )
12126 DrawFormattedText(w ,' Waiting For Trigger' ,' center' , ' center' , black );
15964playTime = zeros(numBlocks ,1 );
16065
16166for blocks = 1 : numBlocks
162-
67+
16368 timeLogger .block(blocks ).startTime = GetSecs - experimentStartTime ; % Get the start time of the block
16469 timeLogger .block(blocks ).condition = condition(blocks ); % Get the condition of the block (motion or static)
165- timeLogger .block(blocks ).names = names(blocks ); % Get the name of the block
166-
70+ timeLogger .block(blocks ).names = names(blocks ); % Get the name of the block
71+
16772 responseCount= 0 ;
168-
73+
16974 for iEvent = 1 : numEventsPerBlock
170-
75+
17176 Sound= [];
172-
77+
17378 if isTarget(blocks ,iEvent )==0
174-
79+
17580 if strcmp(directions(blocks ,iEvent ),' S' )
17681 Sound= soundData .S ;
17782 elseif strcmp(directions(blocks ,iEvent ),' U' )
18388 elseif strcmp(directions(blocks ,iEvent ),' L' )
18489 Sound= soundData .L ;
18590 end
186-
91+
18792 elseif isTarget(blocks ,iEvent )==1
188-
93+
18994 if strcmp(directions(blocks ,iEvent ),' S' )
19095 Sound= soundData .S_T ;
19196 elseif strcmp(directions(blocks ,iEvent ),' U' )
197102 elseif strcmp(directions(blocks ,iEvent ),' L' )
198103 Sound= soundData .L_T ;
199104 end
200-
105+
201106 end
202-
107+
203108 eventOnsets(blocks ,iEvent )=GetSecs - experimentStartTime ;
204-
109+
205110 PsychPortAudio(' FillBuffer' ,phandle ,Sound );
206111 playTime(blocks ,1 ) = PsychPortAudio(' Start' ,phandle );
207-
112+
208113 % length(playedAudio)/freq
209-
114+
210115 while GetSecs() <= eventOnsets(blocks ,iEvent )+ experimentStartTime + (length(Sound )/freq )
211-
116+
212117 if strcmp(device ,' Scanner' )
213118 [sbutton ,secs ] = TakeSerialButton(SerPor );
214119 % [sbutton,secs] = MT_TakeSerialButtonPerFrame(SerPor);
215120 % responseKey(end+1)= sbutton;
216121 if sbutton ~= 0
217122 responseTime(end + 1 )= secs - experimentStartTime ;
218-
123+
219124 % %%%%%%%%%%%%%%%%%%%%
220125 % while you are pressing, wait till it is
221126 % released
222127 while sbutton ~= 0
223128 [sbutton ,secs ]= TakeSerialButton(Cfg .SerPor );
224129 end
225130 % %%%%%%%%%%%%%%%%%%%%
226-
131+
227132 responseCount = responseCount + 1 ;
228133 end
229-
230-
231-
134+
135+
136+
232137 elseif strcmp(device ,' PC' )
233-
138+
234139 [keyIsDown , secs , ~ ] = KbCheck();
235-
140+
236141 if keyIsDown
237142 responseTime(end + 1 )= secs - experimentStartTime ;
238143 while keyIsDown == 1
239144 [keyIsDown , ~ ] = KbCheck();
240145 end
241-
146+
242147 responseCount = responseCount + 1 ;
243148 end
244149 end
245-
150+
246151 end
247-
152+
248153 eventEnds(blocks ,iEvent )=GetSecs - experimentStartTime ;
249154 eventDurations(blocks ,iEvent )=eventEnds(blocks ,iEvent )-eventOnsets(blocks ,iEvent );
250-
155+
251156 WaitSecs(ISI );
252-
157+
253158 end
254-
159+
255160 responsesPerBlock (blocks ,1 ) = responseCount ;
256-
161+
257162 %% Get Block end and duration
258163 timeLogger .block(blocks ).endTime = GetSecs - experimentStartTime ; % Get the time for the block end
259164 timeLogger .block(blocks ).length = timeLogger .block(blocks ).endTime - timeLogger .block(blocks ).startTime; % Get the block duration
260-
165+
261166 %% Fixation cross and inter-block interval
262167 Screen(' FillOval' , w , uint8(white ), fix_cord ); % draw fixation dot (flip erases it)
263168 blank_onset= Screen(' Flip' , w );
264169 WaitSecs(' UntilTime' , blank_onset + ibi ); % wait for the inter-block interval
265-
170+
266171end ;
267172
268173% At the end of the blocks wait ... secs before ending the experiment.
291196% responseTime(i)=0; % this way, we remove the additional 1s for the same button response
292197% end % - The same concept for the responseTime
293198% end
294- %
199+ %
295200% for i=length(targetTime):-1:2 % The same concept as responseKey adn responseTime.
296201% if targetTime(i-1)~=0 % Our Targets lasts 3 frames, to remove the TargetTime for the 2nd and 3rd frame
297202% targetTime(i)=0; % we remove targets that are preceeded by a non-zero value
298203% end % that way, we have the time of the first frame only of the target
299204% end
300- %
205+ %
301206% responseKey = responseKey(responseKey > 0); % Remove zero elements from responseKey, responseTime, & targetTime
302207% responseTime = responseTime(responseTime > 0);
303208% targetTime = targetTime(targetTime > 0);
327232 if strcmp(Cfg .device ,' Scanner' )
328233 CloseSerialPort(Cfg .SerPor );
329234 end
330-
331- end
235+
236+ end
0 commit comments