Skip to content

Commit 52576dd

Browse files
committed
refactor first part of the exp
1 parent 9645838 commit 52576dd

File tree

3 files changed

+118
-135
lines changed

3 files changed

+118
-135
lines changed

ALocalizer.m

Lines changed: 39 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,26 @@
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

538
numBlocks = 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
10712
if 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)
12025
elseif strcmp(device,'Scanner')
12126
DrawFormattedText(w,'Waiting For Trigger','center', 'center', black);
@@ -159,19 +64,19 @@
15964
playTime = zeros(numBlocks,1);
16065

16166
for 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')
@@ -183,9 +88,9 @@
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')
@@ -197,72 +102,72 @@
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+
266171
end;
267172

268173
% At the end of the blocks wait ... secs before ending the experiment.
@@ -291,13 +196,13 @@
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);
@@ -327,5 +232,5 @@
327232
if strcmp(Cfg.device,'Scanner')
328233
CloseSerialPort(Cfg.SerPor);
329234
end
330-
331-
end
235+
236+
end

audioLocTranslational.m

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
%% Auditory hMT localizer using translational motion in four directions
2+
% (up- down- left and right-ward)
3+
4+
% Original Script Written by Sam Weiller to localize MT+/V5
5+
% adapted by M.Rezk to localize MT/MST (Huk,2002)
6+
% re-adapted by MarcoB and RemiG 2020
7+
8+
%%
9+
10+
% Clear all the previous stuff
11+
% clc; clear;
12+
if ~ismac
13+
close all;
14+
clear Screen;
15+
end
16+
17+
% make sure we got access to all the required functions and inputs
18+
addpath(genpath(fullfile(pwd, 'subfun')))
19+
20+
[expParameters, cfg] = setParameters;
21+
22+
% set and load all the parameters to run the experiment
23+
expParameters = userInputs(cfg, expParameters);
24+
expParameters = createFilename(expParameters, cfg);
25+
26+
expParameters %#ok<NOPTS>
27+
28+
%% Experiment
29+
30+
% Safety loop: close the screen if code crashes
31+
try
32+
33+
%% Init the experiment
34+
[cfg] = initPTB(cfg);
35+
36+
% % Convert some values from degrees to pixels
37+
% cfg = deg2Pix('diameterAperture', cfg, cfg);
38+
% expParameters = deg2Pix('dotSize', expParameters, cfg);
39+
%
40+
%
41+
[el] = eyeTracker('Calibration', cfg, expParameters);
42+
43+
% % % REFACTOR THIS FUNCTION
44+
[expParameters] = expDesign(expParameters);
45+
% % %
46+
47+
% Prepare for the output logfiles with all
48+
logFile = saveEventsFile('open', expParameters, [], ...
49+
'direction', 'speed', 'target', 'event', 'block');
50+
51+
% % % REFACTOR THIS FUNCTION
52+
[soundData, freq] = loadAudioFiles(SubjName);
53+
phandle = PsychPortAudio('Open',[],[],1,freq,2);
54+
% % %
55+
56+
% Prepare for fixation Cross
57+
if expParameters.Task1
58+
59+
cfg.xCoords = [-expParameters.fixCrossDimPix expParameters.fixCrossDimPix 0 0] ...
60+
+ expParameters.xDisplacementFixCross;
61+
62+
cfg.yCoords = [0 0 -expParameters.fixCrossDimPix expParameters.fixCrossDimPix] ...
63+
+ expParameters.yDisplacementFixCross;
64+
65+
cfg.allCoords = [cfg.xCoords; cfg.yCoords];
66+
67+
end
68+
69+
70+
71+
catch
72+
73+
cleanUp()
74+
psychrethrow(psychlasterror);
75+
76+
end

setParameters.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
%% Engine parameters
3131

3232
% Monitor parameters
33-
cfg.monitorWidth = 42; % Monitor Width in cm
33+
cfg.monitorWidth = 42; % Monitor Width in cm (x-axis)
3434
cfg.screenDistance = 134; % Distance from the screen in cm
3535
cfg.diameterAperture = 8; % Diameter/length of side of aperture in Visual angles
3636

@@ -158,6 +158,8 @@
158158
expParameters.yDisplacementFixCross = 0; % Manual displacement of the fixation cross
159159
expParameters.fixationCrossColor = cfg.white;
160160
expParameters.fixationCrossColorTarget = cfg.red;
161+
expParameters.fixationRadius = 0.15; % Radius of fixation point (deg)
162+
161163
end
162164

163165
if cfg.debug

0 commit comments

Comments
 (0)