-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA01_fullProtocol_classicalCond.m
More file actions
473 lines (387 loc) · 14.8 KB
/
A01_fullProtocol_classicalCond.m
File metadata and controls
473 lines (387 loc) · 14.8 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
%%
% HT-LMD - High-Throughput Learning, Memory, and Drug-Testing Platform for Small Aquatic Models
% Copyright (C) 2025 Gokul Rajan
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <https://www.gnu.org/licenses/>.
%% L&M protocols
%protocol 1 (full protocol - train/ctrl/reverse): bias 2' + bias(flip) 2' + train x N + test 2' + test(flip) 2'
%protocol 2 (test): test1 2' + test2 2' (flip)
%protocol 3 (extinction): (test 1' + exposure 3") x N times
%% Clear the workspace and the screen
sca;
close all;
clearvars;
Screen('Preference', 'VisualDebugLevel', 1); % skip the initialization screen
Screen('Preference', 'SkipSyncTests', 1); % may lead to some synch timimng issue;
%% some initialization before we start
% Here we call some default settings for setting up Psychtoolbox
PsychDefaultSetup(2);
% Get the screen numbers
%screens = Screen('Screens');
% Draw to the external screen if avaliable
screenNumber = 2;
% to project stim
% Define black and white
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);
grey = white / 2;
inc = white - grey;
%% get BG
BGFullLocation = 'C:\Users\orger\Desktop\Gokul\stim\rev1.png';
BGFullImage = imread(BGFullLocation);
BGFullLocationRev = 'C:\Users\orger\Desktop\Gokul\stim\csfull.png';
BGFullImageRev = imread(BGFullLocationRev);
%%
% Open an on screen window
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, 0.7);
% Screen('DrawTexture', window, BGFullTexture, [], [], 0);
% Screen('Flip', window);
%% setup arduino
ard = arduino('COM3', 'Uno'); % Initializes Arduino
% D9 for CS1 LED
% D10 for CS2 LED
% D11 for CSfull LED
% D12 for US LED
% D07 for shock
%writeDigitalPin(ard, 'D09', 1); % CS1 LED ON
%writeDigitalPin(ard, 'D09', 0); % CS1 LED OFF
%writeDigitalPin(ard, 'D10', 1); % CS2 LED ON
%writeDigitalPin(ard, 'D10', 0); % CS2 LED OFF
%writeDigitalPin(ard, 'D11', 1); % CSfull LED ON
%writeDigitalPin(ard, 'D11', 0); % CSfull LED OFF
%writeDigitalPin(ard, 'D12', 1); % US LED ON
%writeDigitalPin(ard, 'D12', 0); % US LED OFF
%writeDigitalPin(ard, 'D07', 1); % Shock ON
%writeDigitalPin(ard, 'D07', 0); % Shock OFF
%% more initialization stuff
% Get the size of the on screen window
[screenXpixels, screenYpixels] = Screen('WindowSize', window);
% Query the frame duration
ifi = Screen('GetFlipInterval', window);
% Get the centre coordinate of the window
[xCenter, yCenter] = RectCenter(windowRect);
% Set up alpha-blending for smooth (anti-aliased) lines
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
%%
% Here we load in an image from file.
csHalfLocation = ['C:\Users\orger\Desktop\Gokul\stim\cs1.png'];
csHalfImage = imread(csHalfLocation);
csHalfLocationRev='C:\Users\orger\Desktop\Gokul\stim\cs1.png';
csHalfImageRev=imread(csHalfLocationRev);
csFullLocation = ['C:\Users\orger\Desktop\Gokul\stim\csfull.png'];
csFullImage = imread(csFullLocation);
csFullLocationRev = ['C:\Users\orger\Desktop\Gokul\stim\rev1.png'];
csFullImageRev = imread(csFullLocation);
BGFullTexture = Screen('MakeTexture', window, BGFullImage);
BGFullTextureRev = Screen('MakeTexture', window, BGFullImageRev);
% %% CS bias evaluation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% % Bias check phase 1
%
% if (strcmp(,'train') | strcmp(protocol,'ctrl')| strcmp(protocol,'reverse'))
%
% % biasTime var is the time the projection stays on (on 1 side)
% biasTime=120;
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% if (strcmp(protocol,'train')| strcmp(protocol,'ctrl'))
%
% % Get the size of the image
% [s1, s2, s3] = size(csHalfImage);
%
% % Here we check if the image is too big to fit on the screen and abort if
% % it is. See ImageRescaleDemo to see how to rescale an image.
% if s1 > screenYpixels || s2 > screenYpixels
% disp('ERROR! Image is too big to fit on the screen');
% sca;
% return;
% end
%
% % Make the image into a texture
% csHalfTexture = Screen('MakeTexture', window, csHalfImage);
%
% % Draw the image to the screen, unless otherwise specified PTB will draw
% % the texture full size in the center of the screen. We first draw the
% % image in its correct orientation.
% Screen('DrawTexture', window, csHalfTexture, [], [], 0);
%
% % Bias check phase 1
% writeDigitalPin(ard, 'D9', 1); % CS1 LED ON
% % Flip to the screen
% Screen('Flip', window);
% % Wait for few seconds
% WaitSecs(biasTime);
% writeDigitalPin(ard, 'D9', 0); % CS1 LED off
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % Bias phase 2 (flip)
% % Draw the image to the screen for a second time this time upside down and
% % drawn onto our updated blue background
% Screen('DrawTexture', window, csHalfTexture, [], [], 180);
% writeDigitalPin(ard, 'D10', 1); % CS2 LED ON
% % Flip to the screen
% Screen('Flip', window);
% WaitSecs(biasTime);
% writeDigitalPin(ard, 'D10', 0); % CS2 LED off
%
% elseif (strcmp(protocol,'reverse'))
%
% % Get the size of the image
% [s1, s2, s3] = size(csHalfImageRev);
%
% % Here we check if the image is too big to fit on the screen and abort if
% % it is. See ImageRescaleDemo to see how to rescale an image.
% if s1 > screenYpixels || s2 > screenYpixels
% disp('ERROR! Image is too big to fit on the screen');
% sca;
% return;
% end
%
% % Make the image into a texture
% csHalfTextureRev = Screen('MakeTexture', window, csHalfImageRev);
%
% % Draw the image to the screen, unless otherwise specified PTB will draw
% % the texture full size in the center of the screen. We first draw the
% % image in its correct orientation.
% Screen('DrawTexture', window, csHalfTextureRev, [], [], 0);
%
% % Bias check phase 1
% writeDigitalPin(ard, 'D9', 1); % CS1 LED ON
% % Flip to the screen
% Screen('Flip', window);
% % Wait for few seconds
% WaitSecs(biasTime);
% writeDigitalPin(ard, 'D9', 0); % CS1 LED Off
%
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % Bias phase 2 (flip)
% % Draw the image to the screen for a second time this time upside down and
% % drawn onto our updated blue background
% Screen('DrawTexture', window, csHalfTextureRev, [], [], 180);
% writeDigitalPin(ard, 'D10', 1); % CS2 LED ON
% % Flip to the screen
% Screen('Flip', window);
% WaitSecs(biasTime);
% writeDigitalPin(ard, 'D10', 0); % CS2 LED Off
%
%
% end
%
% end
%%
disp('press any key to start the experiment the stimulus');
pause('on');
pause()
pause('off');
%%
for ii=1:4
%% SELECT PROTOCOL SEQUENCE HERE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if ii==1 || ii==3
protocol='test';
elseif ii==2
protocol='train';
elseif ii==3
protocol='test';
elseif ii==4
protocol='exit';
end
%% TRAINING PHASE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
delay=2; % all in secs
isi=25; % rest between the reinforcement trials
shock=0.1; % duration of the actual shock in sec
trials=75; % # of trials
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for tr=1:trials
if (strcmp(protocol,'train')| strcmp(protocol,'ctrl'))
% Make the image into a texture
csFullTexture = Screen('MakeTexture', window, csFullImage);
if tr==1
WaitSecs(60); % wait few secs before starting training after bias evaluation; helps dispersion
end
% Get the size of the image
[u1, u2, u3] = size(csFullImage);
% Here we check if the image is too big to fit on the screen and abort if
% it is. See ImageRescaleDemo to see how to rescale an image.
if u1 > screenYpixels || u2 > screenYpixels
disp('ERROR! Image is too big to fit on the screen');
sca;
return;
end
% Draw the image to the screen, unless otherwise specified PTB will draw
% the texture full size in the center of the screen. We first draw the
% image in its correct orientation.
Screen('DrawTexture', window, csFullTexture, [], [], 0);
writeDigitalPin(ard, 'D11', 1); % CSfull LED ON
Screen('Flip', window); % Flip to the screen
% Wait for few secs for the US arrive
WaitSecs(delay);
writeDigitalPin(ard, 'D04', 1); % US LED ON
writeDigitalPin(ard, 'D07', 1); % Shock ON
WaitSecs(shock); % 70 msecs of shock
writeDigitalPin(ard, 'D04', 0); % US LED OFF
writeDigitalPin(ard, 'D07', 0); % Shock OFF
% Now fill the screen blank
Screen('DrawTexture', window, BGFullTexture, [], [], 0);
writeDigitalPin(ard, 'D11', 0); % CSfull LED OFF
% Flip to the screen
Screen('Flip', window);
WaitSecs(isi); %wait for isi before the next training trial
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
elseif (strcmp(protocol,'reverse'))
% Make the image into a texture
csFullTextureRev = Screen('MakeTexture', window, csFullImageRev);
% for tr=1:trials
%
% if tr==1
% WaitSecs(300); % wait few mins before starting training after bias evaluation
% end
% Get the size of the image
[u1, u2, u3] = size(csFullImageRev);
% Here we check if the image is too big to fit on the screen and abort if
% it is. See ImageRescaleDemo to see how to rescale an image.
if u1 > screenYpixels || u2 > screenYpixels
disp('ERROR! Image is too big to fit on the screen');
sca;
return;
end
% Draw the image to the screen, unless otherwise specified PTB will draw
% the texture full size in the center of the screen. We first draw the
% image in its correct orientation.
Screen('DrawTexture', window, BGFullTexture, [], [], 0);
writeDigitalPin(ard, 'D11', 1); % CSfull LED ON
Screen('Flip', window); % Flip to the screen
% Wait for few secs for the US arrive
WaitSecs(delay);
writeDigitalPin(ard, 'D12', 1); % US LED ON
writeDigitalPin(ard, 'D07', 1); % Shock ON
WaitSecs(shock); % 70 msecs of shock
writeDigitalPin(ard, 'D12', 0); % US LED OFF
writeDigitalPin(ard, 'D07', 0); % Shock OFF
% Now fill the screen blank
Screen('DrawTexture', window, BGFullTextureRev, [], [], 0);
writeDigitalPin(ard, 'D11', 0); % CSfull LED OFF
% Flip to the screen
Screen('Flip', window);
WaitSecs(isi); %wait for another minute before the next training trial
end
end
%% Testing phase %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if (strcmp(protocol,'test'))
testTime=300;
% test phase 1
% Get the size of the image
[s1, s2, s3] = size(csHalfImage);
% Here we check if the image is too big to fit on the screen and abort if
% it is. See ImageRescaleDemo to see how to rescale an image.
if s1 > screenYpixels || s2 > screenYpixels
disp('ERROR! Image is too big to fit on the screen');
sca;
return;
end
% Make the image into a texture
csHalfTexture = Screen('MakeTexture', window, csHalfImage);
% Draw the image to the screen, unless otherwise specified PTB will draw
% the texture full size in the center of the screen. We first draw the
% image in its correct orientation.
Screen('DrawTexture', window, csHalfTexture, [], [], 0);
writeDigitalPin(ard, 'D9', 1); % CS1 LED ON
Screen('Flip', window); % Flip to the screen
% Wait for few seconds
WaitSecs(testTime);
writeDigitalPin(ard, 'D9', 0); % CS1 LED Off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Test phase 2 (flip)
% Draw the image to the screen for a second time this time upside down and
% drawn onto our updated blue background
Screen('DrawTexture', window, csHalfTexture, [], [], 180);
writeDigitalPin(ard, 'D10', 1); % CS2 LED ON
% Flip to the screen
Screen('Flip', window);
WaitSecs(testTime);
if (strcmp(protocol,'reverse'))
% Now fill the screen blank
Screen('DrawTexture', window, BGFullTextureRev, [], [], 0);
writeDigitalPin(ard, 'D10', 0); % CS2 LED OFF
Screen('Flip', window);
else
% Now fill the screen blank
Screen('DrawTexture', window, BGFullTexture, [], [], 0);
writeDigitalPin(ard, 'D10', 0); % CS2 LED OFF
Screen('Flip', window);
end
end
%% Extinction %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if (strcmp(protocol,'extinction'))
exposure=3;
extinctionTest=60; % 20 trials/ 21 mins
extTrials=1;
while (extTrials<21)
% Make the image into a texture
csFullTexture = Screen('MakeTexture', window, csFullImage);
% Get the size of the image
[u1, u2, u3] = size(csFullImage);
% Here we check if the image is too big to fit on the screen and abort if
% it is. See ImageRescaleDemo to see how to rescale an image.
if u1 > screenYpixels || u2 > screenYpixels
disp('ERROR! Image is too big to fit on the screen');
sca;
return;
end
% Draw the image to the screen, unless otherwise specified PTB will draw
% the texture full size in the center of the screen. We first draw the
% image in its correct orientation.
Screen('DrawTexture', window, csFullTexture, [], [], 0);
writeDigitalPin(ard, 'D11', 1); % CSfull LED ON
Screen('Flip', window); % Flip to the screen
writeDigitalPin(ard, 'D12', 1); % US LED ON
WaitSecs(exposure);
writeDigitalPin(ard, 'D12', 0); % US LED OFF
% Get the size of the image
[s1, s2, s3] = size(csHalfImage);
% Here we check if the image is too big to fit on the screen and abort if
% it is. See ImageRescaleDemo to see how to rescale an image.
if s1 > screenYpixels || s2 > screenYpixels
disp('ERROR! Image is too big to fit on the screen');
sca;
return;
end
% Make the image into a texture
csHalfTexture = Screen('MakeTexture', window, csHalfImage);
% Draw the image to the screen, unless otherwise specified PTB will draw
% the texture full size in the center of the screen. We first draw the
% image in its correct orientation.
Screen('DrawTexture', window, csHalfTexture, [], [], 0);
writeDigitalPin(ard, 'D9', 1); % CS1 LED ON
Screen('Flip', window); % Flip to the screen
% Wait for few seconds
WaitSecs(extinctionTest);
extTrials=extTrials+1;
end
end
if (strcmp(protocol,'exit'))
% Wait for few second
disp('press any key to exit the stimulus');
pause('on');
pause()
pause('off');
% Clear the screen
sca;
end
end