File size: 6,763 Bytes
e7dce60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
%*****TESTING STIM SETUP****

% the number of trials of each stim pairing
Btrials_perType = 4;  % 4*12= 48

% build the trial list
AB_trials = repmat([ A,B ], Btrials_perType, 1);
BA_trials = repmat([ B,A ], Btrials_perType, 1);
AC_trials = repmat([ A,C ], Btrials_perType, 1);
CA_trials = repmat([ C,A ], Btrials_perType, 1);
AD_trials = repmat([ A,D ], Btrials_perType, 1);
DA_trials = repmat([ D,A ], Btrials_perType, 1);
BC_trials = repmat([ B,C ], Btrials_perType, 1);
CB_trials = repmat([ C,B ], Btrials_perType, 1);
BD_trials = repmat([ B,D ], Btrials_perType, 1);
DB_trials = repmat([ D,B ], Btrials_perType, 1);
CD_trials = repmat([ C,D ], Btrials_perType, 1);
DC_trials = repmat([ D,C ], Btrials_perType, 1);

% bind all the trial types to define the block's trials
B_trialList_test = [AB_trials; BA_trials; AC_trials; CA_trials; AD_trials; DA_trials; BC_trials; CB_trials;...
    BD_trials; DB_trials; CD_trials; DC_trials;];

% load the textures into an array mapping onto corresponding choice ids
textures = [];
textures(A) = B_textures{1}{6}; % {A,B,C,D}
textures(B) = B_textures{2}{6};
textures(C) = B_textures{3}{6};
textures(D) = B_textures{4}{6};

%****BEGIN TEST*****

BComplete = false;
numBBlocks = 1; %*******Determines # of Blocks*******
Bblock_index = 0;
no_response = false;

% loop through the Test phase
while ~BComplete
    
    % track trial ids
    trial_ids = [];
    % track trial type
    trial_stimuli = [];
    %track response
    trial_response = [];
    % track which stim was choosen
    trial_selectedStim = [];
    % track the rt
    trial_RT = [];
    % track the accuracy
    trial_accuracy = [];
    
    % increment the block index
    Bblock_index = Bblock_index + 1;
    
    random_index = randperm(size(B_trialList_test, 1));
    randomized_trialList_test = B_trialList_test(random_index,:);
    
    trial_index = 1;
    while trial_index <= size(randomized_trialList_test, 1)
        
        % Fixation
        fixation_text = '+';
        Screen('TextFont',wPtr,'Times');
        Screen('TextStyle',wPtr,0);
        Screen('TextColor',wPtr,[255 255 255]);
        Screen('TextSize',wPtr,80);
        DrawFormattedText(wPtr,fixation_text,'center','center');
        Screen(wPtr, 'Flip');
        % show the fixation for 1 sec
        WaitSecs(1);
        
        % get the current trial's info
        L = randomized_trialList_test(trial_index, 1);
        R = randomized_trialList_test(trial_index, 2);
        TRIALCODE=strcat(num2str(L),num2str(R));
        TRIALTRIGGER=str2num(TRIALCODE);
        
        % define overall accuracy
        if  L<R
            correct_choice = left_button;
        elseif R<L
            correct_choice = right_button;
        end

        % now draw the stim
        Screen('DrawTexture', wPtr, textures(L), [], left_rect_test);
        Screen('DrawTexture', wPtr, textures(R), [], right_rect_test);
        %io64(ioObject,LTP1address,TRIALTRIGGER); WaitSecs(.05); io64(ioObject,LTP1address,0);
        err=DaqDOut(DAQindx, 0, TRIALTRIGGER); WaitSecs(0.05);
        Screen(wPtr, 'Flip');
        
        % start the trial timer;
        startTime = GetSecs();
        
        wait_stamp=GetSecs;
        % display "tmp"
        while 1
            [ keyIsDown, seconds, keyCode ] = KbCheck(GPindx);
            if keyIsDown
                if keyCode(left_button) &&  left_button==correct_choice
                    subject_choice = left_button;
                    no_response = false;
                    trlResponse = 1;
                    trlAccuracy = 1;
                    RESPTRIGGER = 1;
                    break;
                elseif keyCode(right_button) &&  right_button==correct_choice
                    subject_choice = right_button;
                    no_response = false;
                    trlResponse = 1;
                    trlAccuracy = 1;
                    RESPTRIGGER = 2;
                    break;
                elseif keyCode(left_button) &&  left_button~=correct_choice % suboptimal
                    subject_choice = left_button;
                    no_response = false;
                    trlResponse = 1;
                    trlAccuracy = 0;
                    RESPTRIGGER = 3;
                    break;
                elseif keyCode(right_button) &&  right_button~=correct_choice % suboptimal
                    subject_choice = right_button;
                    no_response = false;
                    trlResponse = 1;
                    trlAccuracy = 0;
                    RESPTRIGGER = 4;
                    break;
                end
            elseif(GetSecs-wait_stamp) > TSTDEADLINE,
                subject_choice = no_response;
                no_response = true;
                trlResponse = -1;
                trlAccuracy = -1;
                RESPTRIGGER = 5;
                break;
            end
        end
        %io64(ioObject,LTP1address,RESPTRIGGER); WaitSecs(.05); io64(ioObject,LTP1address,0);
        err=DaqDOut(DAQindx, 0, RESPTRIGGER); WaitSecs(0.05);
        clear TRIALCODE RESPTRIGGER;
        % stop the trial timer
        RT = GetSecs() - startTime;
        
        % determine which button they pressed
        trlselectedStim = subject_choice;
        
        % determine the reward feedback
        Screen('TextSize',wPtr,60);
        Screen('TextFont',wPtr,'Times');
        Screen('TextStyle',wPtr,1);
        
        % Store the trial data
        %
        % update the trial number list
        trial_ids = [trial_ids; trial_index];
        % store the trial stimuli
        trial_stimuli = [trial_stimuli; TRIALTRIGGER];
        %store response
        trial_response = [trial_response; trlResponse];
        % store the RT
        trial_RT = [trial_RT; RT];
        % store the subject's choice
        trial_selectedStim = [trial_selectedStim; trlselectedStim];
        % store accuracy independent of feedback
        trial_accuracy = [trial_accuracy; trlAccuracy];
        
        % increment the trial index
        trial_index = trial_index + 1;
        
    end
    
    % mark each trial with the block number
    data_test = zeros(size(trial_ids, 1), 1) + Bblock_index;
    % collate all the data from the block
    data_test = [data_test, trial_ids, trial_stimuli, trial_response, trial_selectedStim, trial_RT, trial_accuracy];
    
    % check to see if B is done
    if Bblock_index >= numBBlocks
        BComplete = true;
    end
end

% Save data
save([datadir 'M' num2str(subject_number),'_B',num2str(Block),'_CC_test.mat'], 'data_test');

% *****END OF B1_test*****