9 changed files with 1175 additions and 42 deletions
Binary file not shown.
@ -0,0 +1,614 @@
@@ -0,0 +1,614 @@
|
||||
function AfIm_pupil_Exp_Rivalry(subName,meanLum,Bckg_Chro,axis_chck,AdaptTime,nRep,OneHemi_chck,Simu_chck) |
||||
Clock = 0; |
||||
%%%%%%%%%%%%%%%% |
||||
% ARDUINO and CAMERA settings |
||||
|
||||
Cam_freq = 240 ; % square waves freq |
||||
Cam_RECduration = 30; %in seconds. (30secs is the maximal time allowed by Matlab to play tone in arduino board) |
||||
ard = arduino; % open arduino |
||||
%%%%%%%%%%%%%%% |
||||
|
||||
|
||||
try |
||||
assignin('base','Stop_Press',0)% this works for the STOP experiment button |
||||
|
||||
% Check that Psychtoolbox is properly installed, switch to unified KbName's |
||||
% across operating systems, and switch color range to normalized 0 - 1 range: |
||||
PsychDefaultSetup(2); |
||||
|
||||
locOutDir = ['/Users/mike/Documents/AfterimageOutputs/']; |
||||
saveFile = sprintf('%s%s_Pupil_AfIm', locOutDir, subName); |
||||
|
||||
fp = fopen(saveFile, 'at'); |
||||
|
||||
%% Color information, load hfp data and color calibration |
||||
|
||||
hfpFile = sprintf('%s%sHFP', locOutDir, subName); |
||||
load([hfpFile,'.mat']); |
||||
hfpRG = rg_avg; |
||||
hfpBG = bg_avg; |
||||
|
||||
|
||||
|
||||
% cd(a); % return to program folder. |
||||
load('colorCalFile1.mat'); |
||||
fprintf('\nLast calibration was %s\n', describe.date) |
||||
pix = pix/1001; |
||||
|
||||
|
||||
% cd(aa) ;% output folder |
||||
% aa = cd('/Users/clemente/Desktop/AfterImage Programs/A Outputs'); |
||||
% aa = cd('D:\Dropbox\Luminotecnia\2017\Chicago Lab files\2 Experiments\Color AfterImage_Exp_Room_150\2nd\1 Programs\A Outputs') |
||||
% maxLum = 20; %cd/m^2 |
||||
|
||||
contFile = sprintf('%s%s_ContMatch.mat', locOutDir, subName); |
||||
load(contFile, '-mat') |
||||
|
||||
lCont = Final_lCont_avg; |
||||
lumMod = Final_lumMod_avg; |
||||
sCont = Final_sCont_ref; |
||||
|
||||
nCont = size(sCont,2); |
||||
nBckg_Chro = size(Bckg_Chro,1); |
||||
|
||||
% white = [.665 1]; |
||||
blackLut = [0 0 0]; |
||||
redLut = [.8 0 0]; |
||||
|
||||
% Bckg_Chro = Final_lCont_avg(:,1:2) |
||||
|
||||
%% Save Session Information |
||||
|
||||
theDate = datestr(now(),'mm/dd/yyyy HH:MM:SS'); |
||||
% a = '/Users/clemente/Dropbox/Luminotecnia/2018/Experiments/Color Background Afterimage/1 Programs/4 ColBackg AI' ;% folder where the program is. |
||||
infoFile = sprintf('%s%s_SessionsInfo', locOutDir, subName); |
||||
|
||||
checkfile = exist(infoFile, 'file'); |
||||
fo = fopen(infoFile, 'at'); |
||||
if checkfile == 0 % if file doesn't exist, then print the following header: |
||||
fprintf(fo,'Subject\t Date\t Time\t Lum\t nBckg_Chro\t nCont\t nRep\t l_\t s_\t lum_\t ls45\t ls135\t luml45\t luml135\t lums45\t luml135\n') |
||||
end |
||||
|
||||
% fo = fopen(infoFile, 'at') |
||||
fprintf(fo, '%s\t%i/%i/%i %i:%i:%i\t %1.2f\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\tPupil\n',... |
||||
subName, theDate(2), theDate(3), theDate(1), theDate(4), theDate(5), round(theDate(6)),... |
||||
meanLum, nBckg_Chro, nCont, nRep,axis_chck(1),axis_chck(2),... |
||||
axis_chck(3),axis_chck(4) ,axis_chck(5),axis_chck(6),... |
||||
axis_chck(7),axis_chck(8),axis_chck(9)); |
||||
% % % % fprintf(fo, '%s\t%i/%i/%i %i:%i:%i\t %1.2f\t%1.3f\t%1.3f\t%i\n',... |
||||
% % % % subName, theDate(2), theDate(3), theDate(1), theDate(4), theDate(5), round(theDate(6)),... |
||||
% % % % maxLum, white(1),white(2), nRep)%,curr_cond(1),curr_cond(2),... |
||||
% % % % % % curr_cond(3),curr_cond(4) ,curr_cond(5),curr_cond(6),... |
||||
% % % % % % curr_cond(7),curr_cond(8),curr_cond(9)); |
||||
|
||||
fclose(fo); |
||||
|
||||
%% set up psych toolbox |
||||
%set up 10 bit color |
||||
PsychImaging('PrepareConfiguration'); |
||||
%PsychImaging('AddTask', 'General', 'EnableNative10BitFrameBuffer',1); %the 0 is turn off dithering? |
||||
expScreen = 1; |
||||
%create white LUT |
||||
|
||||
% cd(a); |
||||
|
||||
% % % wLMS(1,1) = white(1,1)*maxLum; |
||||
% % % wLMS(1,2) = (1-white(1,1))*maxLum; |
||||
% % % wLMS(1,3) = white(1,2)*maxLum; |
||||
% % % wXYZ(1,:) = LMS_to_XYZ(wLMS(1,:)); |
||||
% % % wRGB(1,:) = XYZ_to_RGB(wXYZ(1,:), maxPhosXYZ); |
||||
% % % wRGB(1,1) = pix(dsearchn(redProp(:), wRGB(1,1)))*hfpRG; |
||||
% % % wRGB(1,2) = pix(dsearchn(grnProp(:), wRGB(1,2))); |
||||
% % % wRGB(1,3) = pix(dsearchn(blueProp(:), wRGB(1,3)))*hfpBG; |
||||
|
||||
[window, windowRect] = PsychImaging('OpenWindow', expScreen, [0 0 0], [], [], []); % Set a black screen before starting |
||||
%Screen('OpenWindow',0, [0 0 0]); %makes main screen dark |
||||
%PsychImaging('OpenWindow', expScreen, wRGB); |
||||
[xcent,ycent] = RectCenter(windowRect); |
||||
center = [xcent ycent]; |
||||
[xWinSize,~] = Screen('WindowSize',window); |
||||
|
||||
%% TIMING |
||||
%find frames per second |
||||
ifi = Screen('GetFlipInterval', window);% Measure the vertical refresh rate of the monitor |
||||
topPriorityLevel = MaxPriority(window);% Retreive the maximum priority number |
||||
numSecs = 8; %in seconds, total presentation time |
||||
framesPerSec = round(1/ifi); |
||||
nFrames = numSecs * framesPerSec; |
||||
waitframes = 1; %number of frames to wait between refresh |
||||
% color changed .03 of full cycle per second - finished 1/2 cycle in 16 seconds, 1/32 |
||||
%in Zaidi, clock face appears at 10.15 seconds, will approximate this |
||||
%number |
||||
zaidiClock = 2%10.15; %is when Zaidi started in his example. |
||||
clFrmStart = floor(1/ifi*zaidiClock); |
||||
clTotTime = 6%2.9*2; %how long is clock in the screen |
||||
handInt = 12*2; %how many places to stop around the clock |
||||
clFrames = floor(clTotTime/handInt/ifi); %this will move the hand 15 degrees at a time, and decides how many frames to sit at each angle |
||||
|
||||
|
||||
if Clock |
||||
ISI = 8; |
||||
else |
||||
ISI = 20; |
||||
end |
||||
%% Stimulus Size Parameters |
||||
circleDeg = 7.2; |
||||
clockPt = 0.1; |
||||
|
||||
% code assumes 1 pixel = 1 arc min |
||||
pixPerDeg = 35; %at a distance of 57 cm |
||||
circlePix = circleDeg*pixPerDeg; |
||||
clockPix = clockPt*pixPerDeg; |
||||
|
||||
tstcircle = [xcent - circlePix/2 ycent - circlePix/2 xcent + circlePix/2 ycent + circlePix/2]; |
||||
|
||||
%create circular grid for clock face and the numbers |
||||
% % % circleDegGrid = 2 ; |
||||
% % % rad = circleDegGrid/2*pixPerDeg; %circlePix/2-pixPerDeg/2; |
||||
rad = circleDeg/2*pixPerDeg; %circlePix/2-pixPerDeg/2; |
||||
radNum = (circleDeg/2) * pixPerDeg; |
||||
clockDegs = [1:15:360]; |
||||
for iC = 1:length(clockDegs) |
||||
[xcFace(iC), ycFace(iC)] = pol2cart(clockDegs(iC)*pi/180, rad); |
||||
[xcNumber(iC), ycNumber(iC)] = pol2cart(clockDegs(iC)*pi/180, 1*radNum); |
||||
end |
||||
|
||||
rhtXCircleCenter = xWinSize/4; |
||||
lftXCircleCenter = xWinSize-xWinSize/4; |
||||
tstCircleLeft = [lftXCircleCenter - circlePix/2 ycent - circlePix/2 lftXCircleCenter + circlePix/2 ycent + circlePix/2]; |
||||
tstCircleRight = [rhtXCircleCenter - circlePix/2 ycent - circlePix/2 rhtXCircleCenter + circlePix/2 ycent + circlePix/2]; |
||||
|
||||
|
||||
%create matrix of dot locations |
||||
clockPosMat = [reshape(xcFace,1, length(clockDegs)); reshape(ycFace,1, length(clockDegs))]; |
||||
clockNumMat = [reshape(xcNumber,1, length(clockDegs)); reshape(ycNumber,1, length(clockDegs))]; |
||||
|
||||
Screen('TextSize', window, 14); |
||||
textOne = [6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 1 2 3 4 5]; |
||||
yPositionIsBaseline=1; |
||||
%create array of second hand positions to index |
||||
count = 1; |
||||
secHandCord(1:handInt) = (1:15:360)*(pi/180); |
||||
for iMove = 1:length(secHandCord) |
||||
secHandMove(count:count+clFrames-1) = secHandCord(iMove); |
||||
count = count+clFrames; |
||||
end |
||||
secHandMove(length(secHandMove)+1:length(secHandMove)*2) = secHandMove(1:length(secHandMove)); |
||||
|
||||
% Specs for the border frame |
||||
frameSize = 60; |
||||
frameWidth = 5; |
||||
frameCircleLeft = [tstCircleLeft(1)-frameSize tstCircleLeft(2)-frameSize tstCircleLeft(3)+frameSize tstCircleLeft(4)+frameSize]; |
||||
frameCircleRight = [tstCircleRight(1)-frameSize tstCircleRight(2)-frameSize tstCircleRight(3)+frameSize tstCircleRight(4)+frameSize]; |
||||
|
||||
WaitSecs(1); |
||||
|
||||
|
||||
%%///////////////////////////////////////////////////////////////////////// |
||||
%%///////////////////////// EXPERIMENT TRIALS ///////////////////////////// |
||||
%%///////////////////////////////////////////////////////////////////////// |
||||
clear iCond |
||||
|
||||
curr_axis = find(axis_chck) |
||||
%run experiment |
||||
|
||||
TrialCount = 1; |
||||
|
||||
Card_Dir = 0; |
||||
|
||||
for iChro = 1:size(Bckg_Chro,1) |
||||
|
||||
|
||||
|
||||
wLMS(1,1) = Bckg_Chro(iChro,1)*meanLum; |
||||
wLMS(1,2) = (1-Bckg_Chro(iChro,1))*meanLum; |
||||
wLMS(1,3) = Bckg_Chro(iChro,2)*meanLum; |
||||
wXYZ(1,:) = LMS_to_XYZ(wLMS(1,:)); |
||||
wRGB(1,:) = XYZ_to_RGB(wXYZ(1,:), maxPhosXYZ); |
||||
wRGB(1,1) = pix(dsearchn(redProp(:), wRGB(1,1)))*hfpRG; |
||||
wRGB(1,2) = pix(dsearchn(grnProp(:), wRGB(1,2))); |
||||
wRGB(1,3) = pix(dsearchn(blueProp(:), wRGB(1,3)))*hfpBG; |
||||
|
||||
commandwindow; |
||||
Speak(' Press any key when you are ready'); |
||||
KbStrokeWait; |
||||
|
||||
% Adaptation screen |
||||
Screen('FillRect', window, wRGB); |
||||
Screen('DrawDots', window, [0 0],clockPix, 0, [lftXCircleCenter,center(2)], 2); % black dot for fixation |
||||
Screen('DrawDots', window, [0 0],clockPix, 0, [rhtXCircleCenter,center(2)], 2); % black dot for fixation |
||||
Screen('Flip',window) |
||||
|
||||
WaitSecs(AdaptTime) |
||||
|
||||
|
||||
|
||||
cont = randperm(nCont); %randomize contrast conditions |
||||
for iCont = 1:nCont |
||||
for iRep = 1:nRep |
||||
FlushEvents('mouseDown','keyDown'); |
||||
|
||||
%create colors with depending on contrast |
||||
l = [Bckg_Chro(iChro,1)+(Bckg_Chro(iChro,1)*lCont(iChro,cont(iCont))) Bckg_Chro(iChro,2) meanLum |
||||
Bckg_Chro(iChro,1)-(Bckg_Chro(iChro,1)*lCont(iChro,cont(iCont))) Bckg_Chro(iChro,2) meanLum]; %+l, -l |
||||
|
||||
s = [Bckg_Chro(iChro,1) Bckg_Chro(iChro,2)+(Bckg_Chro(iChro,2)*sCont(iChro,cont(iCont))) meanLum |
||||
Bckg_Chro(iChro,1) Bckg_Chro(iChro,2)-(Bckg_Chro(iChro,2)*sCont(iChro,cont(iCont))) meanLum];%+s, -s |
||||
|
||||
lum = [Bckg_Chro(iChro,1) Bckg_Chro(iChro,2) meanLum-lumMod(iChro,cont(iCont)) |
||||
Bckg_Chro(iChro,1) Bckg_Chro(iChro,2) meanLum+lumMod(iChro,cont(iCont))]; % -lum , +lum |
||||
|
||||
l_s_45 = [Bckg_Chro(iChro,1)+(Bckg_Chro(iChro,1)*lCont(iChro,cont(iCont))) Bckg_Chro(iChro,2)+(Bckg_Chro(iChro,2)*sCont(iChro,cont(iCont))) meanLum |
||||
Bckg_Chro(iChro,1)-(Bckg_Chro(iChro,1)*lCont(iChro,cont(iCont))) Bckg_Chro(iChro,2)-(Bckg_Chro(iChro,2)*sCont(iChro,cont(iCont))) meanLum]; |
||||
|
||||
l_s_135 = [Bckg_Chro(iChro,1)-(Bckg_Chro(iChro,1)*lCont(iChro,cont(iCont))) Bckg_Chro(iChro,2)+(Bckg_Chro(iChro,2)*sCont(iChro,cont(iCont))) meanLum |
||||
Bckg_Chro(iChro,1)+(Bckg_Chro(iChro,1)*lCont(iChro,cont(iCont))) Bckg_Chro(iChro,2)-(Bckg_Chro(iChro,2)*sCont(iChro,cont(iCont))) meanLum]; |
||||
|
||||
|
||||
lum_l_45 = [Bckg_Chro(iChro,1)+(Bckg_Chro(iChro,1)*lCont(iChro,cont(iCont))) Bckg_Chro(iChro,2) meanLum+lumMod(iChro,cont(iCont)) |
||||
Bckg_Chro(iChro,1)-(Bckg_Chro(iChro,1)*lCont(iChro,cont(iCont))) Bckg_Chro(iChro,2) meanLum-lumMod(iChro,cont(iCont))]; |
||||
|
||||
lum_l_135 = [Bckg_Chro(iChro,1)+(Bckg_Chro(iChro,1)*lCont(iChro,cont(iCont))) Bckg_Chro(iChro,2) meanLum-lumMod(iChro,cont(iCont)) |
||||
Bckg_Chro(iChro,1)-(Bckg_Chro(iChro,1)*lCont(iChro,cont(iCont))) Bckg_Chro(iChro,2) meanLum+lumMod(iChro,cont(iCont))]; |
||||
|
||||
lum_s_45 = [Bckg_Chro(iChro,1) Bckg_Chro(iChro,2)+(Bckg_Chro(iChro,2)*sCont(iChro,cont(iCont))) meanLum+lumMod(iChro,cont(iCont)) |
||||
Bckg_Chro(iChro,1) Bckg_Chro(iChro,2)-(Bckg_Chro(iChro,2)*sCont(iChro,cont(iCont))) meanLum-lumMod(iChro,cont(iCont))]; |
||||
|
||||
lum_s_135 = [Bckg_Chro(iChro,1) Bckg_Chro(iChro,2)+(Bckg_Chro(iChro,2)*sCont(iChro,cont(iCont))) meanLum-lumMod(iChro,cont(iCont)) |
||||
Bckg_Chro(iChro,1) Bckg_Chro(iChro,2)-(Bckg_Chro(iChro,2)*sCont(iChro,cont(iCont))) meanLum+lumMod(iChro,cont(iCont))]; |
||||
|
||||
|
||||
rnd_idx = randperm(length(curr_axis)); |
||||
curr_axis = curr_axis(rnd_idx) |
||||
% cond = randperm(9); |
||||
for iCond = 1:length(curr_axis) |
||||
%create table of color changes |
||||
switch curr_axis(iCond) |
||||
case 1 |
||||
colLut = l; |
||||
case 2 |
||||
colLut = s; |
||||
case 3 %%%% ATENCION que ahora LUM es la condicion 3 |
||||
colLut = lum; |
||||
case 4 |
||||
colLut = l_s_45; |
||||
case 5 |
||||
colLut = l_s_135; |
||||
case 6 |
||||
colLut = lum_l_45; |
||||
case 7 |
||||
colLut = lum_l_135; |
||||
case 8 |
||||
colLut = lum_s_45; |
||||
case 9 |
||||
colLut = lum_s_135; |
||||
end |
||||
|
||||
|
||||
%LMS values of each color, ls to LMS |
||||
for iLMS = 1:2 |
||||
cLMS(iLMS,1) = colLut(iLMS,1)*colLut(iLMS, 3); |
||||
cLMS(iLMS,2) = (1-colLut(iLMS,1))*colLut(iLMS, 3); |
||||
cLMS(iLMS,3) = colLut(iLMS,2)*colLut(iLMS, 3); |
||||
end |
||||
|
||||
%XYZ values for each oaca |
||||
for iXYZ = 1:length(cLMS(:,1)) |
||||
cXYZ(iXYZ,:) = LMS_to_XYZ(cLMS(iXYZ,:)); |
||||
end |
||||
|
||||
%use lut to find corrected monitor RGB values for each rgb color |
||||
for iRGB = 1:length(cXYZ(:,1)) |
||||
cRGB(iRGB,:) = XYZ_to_RGB(cXYZ(iRGB,:), maxPhosXYZ); |
||||
cRGB(iRGB,1) = pix(dsearchn(redProp(:), cRGB(iRGB,1)))*hfpRG; |
||||
cRGB(iRGB,2) = pix(dsearchn(grnProp(:), cRGB(iRGB,2))); |
||||
cRGB(iRGB,3) = pix(dsearchn(blueProp(:), cRGB(iRGB,3)))*hfpBG; |
||||
end |
||||
|
||||
rampLeft = zeros(nFrames,3); |
||||
rampRight = zeros(nFrames,3); |
||||
for iRamp = 1:3 %for 3 phosophors |
||||
rampLeft(:,iRamp) = sinspace(wRGB(1,iRamp), cRGB(1,iRamp), nFrames); |
||||
rampRight(:,iRamp) = sinspace(wRGB(1,iRamp), cRGB(2,iRamp), nFrames); |
||||
end |
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
||||
% loadCombined =1; |
||||
% if loadCombined |
||||
% rampLeft = importdata('rampLeft_Combined.mat'); |
||||
% rampRight = importdata('rampRight_Combined.mat'); |
||||
% end |
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
||||
|
||||
|
||||
%create random start point for clock hand |
||||
randStrt = randi(handInt-1); %won't pick midnight as start point due to second hand array not being long enough |
||||
%clock set to go around 1 full circle |
||||
for ihand = 1:handInt*clFrames+clFrames |
||||
th(ihand) = (secHandMove(randStrt*clFrames-clFrames+ihand)); |
||||
[handx(ihand), handy(ihand)] = pol2cart(th(ihand),1*rad); |
||||
end |
||||
|
||||
handx = handx + xcent; |
||||
handy = handy + ycent; |
||||
|
||||
%///////////// |
||||
switch OneHemi_chck |
||||
case 0 %if FullCircle |
||||
Dir = [-1]; |
||||
case 1 |
||||
Dir = [2 -2]; %just one hemifield modulated |
||||
end |
||||
|
||||
Dir_rnd = randperm(1); |
||||
for iDir = 1:1 |
||||
Card_Dir = Dir(Dir_rnd(iDir)); |
||||
|
||||
switch Card_Dir |
||||
case {1,2} |
||||
ramp = rampLeft; % Increment |
||||
HF_posit = 0; % to place the hemifield in the LEFT position |
||||
case {-1,-2} |
||||
ramp = rampRight; % Decrement |
||||
HF_posit = 180; % to place the hemifield in the RIGHT position |
||||
end |
||||
%--------------------------- |
||||
|
||||
if ~Clock |
||||
flatSound; % so the subject prepare for the stimulus |
||||
WaitSecs(4); % a few seconds before start recording |
||||
%%%%%%%%%%%%%%%%%%%%%%%%% |
||||
% START CAMERA RECORDING |
||||
playTone(ard,'D3',240,Cam_RECduration); % |
||||
%%%%%%%%%%%%%%%%%%%% |
||||
|
||||
WaitSecs(4); % |
||||
end |
||||
|
||||
keypress = 0; |
||||
count = 0; %for clock hand |
||||
TrialCountStr = num2str(TrialCount); |
||||
Priority(topPriorityLevel); |
||||
FlushEvents('mouseDown','keyDown'); |
||||
%ListenChar(2) |
||||
secs0 = Screen('Flip', window); |
||||
for iFrames = 1:nFrames |
||||
|
||||
Screen('FillOval', window, ramp(iFrames,:), tstCircleLeft ); |
||||
Screen('FillOval', window, ramp(iFrames,:), tstCircleRight ); |
||||
|
||||
Screen('DrawDots', window, [0 0],clockPix, 0, [lftXCircleCenter,center(2)], 2); % black dot for fixation |
||||
Screen('DrawDots', window, [0 0],clockPix, 0, [rhtXCircleCenter,center(2)], 2); % black dot for fixation |
||||
|
||||
Screen('FrameOval', window, 0 ,frameCircleLeft, frameWidth, frameWidth); |
||||
Screen('FrameOval', window, 0 ,frameCircleRight, frameWidth, frameWidth); |
||||
Screen('DrawLine', window, 0, lftXCircleCenter+circlePix/2+frameSize, center(2),... |
||||
lftXCircleCenter+circlePix/2+frameSize-20, center(2), frameWidth); |
||||
Screen('DrawLine', window, 0, lftXCircleCenter, center(2)+circlePix/2+frameSize,... |
||||
lftXCircleCenter, center(2)+circlePix/2+frameSize-20, frameWidth); |
||||
Screen('DrawLine', window, 0, rhtXCircleCenter-circlePix/2-frameSize, center(2),... |
||||
rhtXCircleCenter-circlePix/2-frameSize+20, center(2), frameWidth); |
||||
Screen('DrawLine', window, 0, rhtXCircleCenter, center(2)-circlePix/2-frameSize,... |
||||
rhtXCircleCenter, center(2)-circlePix/2-frameSize+20, frameWidth); |
||||
|
||||
if Clock %--------------------- |
||||
Screen('DrawDots', window, clockPosMat,clockPix, blackLut, [lftXCircleCenter,center(2)], 2); |
||||
Screen('DrawDots', window, clockPosMat,clockPix, blackLut, [rhtXCircleCenter,center(2)], 2); |
||||
Screen('DrawText', window, TrialCountStr, 20, 20, redLut, wRGB); |
||||
|
||||
|
||||
for itxt = 1:24 |
||||
textNum = sprintf('%i', textOne(itxt)); |
||||
Screen('DrawText', window, textNum, 1.18*clockNumMat(1,itxt)+center(1,1)-7, 1.18*clockNumMat(2,itxt)+center(1,2)-7, blackLut, wRGB); |
||||
end |
||||
|
||||
if iFrames == clFrmStart |
||||
beep; |
||||
end |
||||
|
||||
if iFrames > clFrmStart-1 && iFrames < clFrmStart + handInt*clFrames+5 |
||||
count = count+1; |
||||
Screen('DrawLine', window, redLut, xcent, ycent, handx(count), handy(count), 2.5); |
||||
end |
||||
|
||||
end % Clock --------------------- |
||||
|
||||
% % %----------------- |
||||
% % % PrintScreen of the monitor (for the paper) |
||||
% % % GetImage call. Alter the rect argument to change the location of the screen shot |
||||
% % imageArray = Screen('GetImage', window, [0 0 300 300]); |
||||
% % % imwrite is a Matlab function, not a PTB-3 function |
||||
% % imwrite(imageArray, 'test.jpg') |
||||
% % %------------------ |
||||
|
||||
vbl = Screen('Flip', window, secs0 + (waitframes - 0.5) * ifi); |
||||
|
||||
Screen('DrawingFinished', window); % tell psychtoolbox drawing is finished, should help timing |
||||
|
||||
end |
||||
Priority(0); |
||||
|
||||
if ~Clock |
||||
WaitSecs(18); % to tell the subject to blink normally |
||||
flatSound; |
||||
end |
||||
|
||||
% Speak('Report Time') |
||||
|
||||
|
||||
% WaitSecs(5)% This is sumed to the ISI except for the last trial |
||||
% % % % while ~keypress |
||||
% % % % if CharAvail |
||||
% % % % userRes = input(' '); |
||||
% % % % keypress = 1; |
||||
% % % % end |
||||
% % % % end |
||||
% % % % FlushEvents('mouseDown','keyDown'); |
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
||||
% RESPONSES % |
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
||||
|
||||
if Clock |
||||
|
||||
% if Simu_chck |
||||
% userRes = 'simu'; |
||||
% |
||||
% else |
||||
|
||||
keyIsDown=0; |
||||
kbName=[]; |
||||
Digit = []; |
||||
|
||||
Nums = {'0','1','2','3','4','5','6','7','8','9'}; |
||||
Screen('TextSize', window, 30); |
||||
commandwindow; |
||||
while keyIsDown==0 | (strcmp('ENTER',kbName)==0)% & strcmp('2',kbName)==0) |
||||
|
||||
keyIsDown=0; |
||||
[keyIsDown, secs, keyCode] = KbCheck; |
||||
|
||||
|
||||
if keyIsDown==1 % |
||||
kbName = KbName(keyCode); |
||||
end |
||||
|
||||
if Digit & any(strcmp(Nums(:),kbName)); |
||||
idx=find(strcmp(Nums(:),kbName)); |
||||
NumPressed = Nums{idx}; |
||||
|
||||
kbName = strcat(firstDigit,NumPressed); |
||||
userRes = kbName; |
||||
% DrawFormattedText(window, kbName, 'center', 'center', color); |
||||
DrawFormattedText(window, kbName, 400, 512, redLut); |
||||
Screen('Flip', window); |
||||
kbName = []; |
||||
Digit = 0; |
||||
WaitSecs(.4); |
||||
elseif any(strcmp(Nums(:),kbName)) |
||||
idx=find(strcmp(Nums(:),kbName)); |
||||
NumPressed = Nums{idx}; |
||||
userRes = kbName; |
||||
%-si es numero -- llevarlo a la pantalla |
||||
DrawFormattedText(window, kbName, 400, 512, redLut); |
||||
% Flip to the screen |
||||
Screen('Flip', window); |
||||
|
||||
Digit = 1 ;% flag to mean that |
||||
firstDigit = kbName; |
||||
WaitSecs(.4); |
||||
kbName = []; |
||||
|
||||
end |
||||
|
||||
if strcmp('DELETE',kbName)==1 %-si es el backspace --limpiar numero |
||||
kbName = []% ; |
||||
userRes = kbName |
||||
firstDigit = []; |
||||
Digit = 0; |
||||
DrawFormattedText(window, kbName, 400, 512, redLut); |
||||
% Flip to the screen |
||||
Screen('Flip', window); |
||||
%else % -si no es numero -- ignorar |
||||
WaitSecs(.4); |
||||
end |
||||
|
||||
|
||||
end %end while |
||||
|
||||
% end % end simu_chck |
||||
|
||||
else |
||||
randStrt = 94;% it will be saved as 99 |
||||
userRes = '99'; |
||||
|
||||
end % Clock |
||||
|
||||
% userRes = num2str(2); |
||||
% |
||||
% AfterResp = 'OK' |
||||
|
||||
|
||||
|
||||
Screen('TextSize', window, 14); |
||||
FlushEvents('mouseDown','keyDown'); |
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
||||
% SAVE % |
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
||||
|
||||
%aa = cd('/Users/clemente/Desktop/AfterImage Programs/A Outputs'); |
||||
% aa = cd('D:\Dropbox\Luminotecnia\2017\Chicago Lab files\2 Experiments\Color AfterImage_Exp_Room_150\2nd\1 Programs\A Outputs') |
||||
%cd |
||||
WaitSecs(.2) |
||||
|
||||
time = clock; |
||||
% % fprintf(fp, '%s\t%i/%i/%i %i:%i:%i\t%1.3f\t%1.3f\t%1.3f\t%1.3f\t%i\t%i\t%i\t%i\tExperiment\n',... |
||||
% % subName, time(2), time(3), time(1), time(4), time(5), round(time(6)), hfpRG, hfpBG, Bckg_Chro(iChro,1), Bckg_Chro(iChro,2), cont(iCont), curr_axis(iCond), Card_Dir, userRes); |
||||
|
||||
fprintf(fp, '%s\t%i/%i/%i %i:%i:%i\t%1.3f\t%1.3f\t%1.3f\t%1.3f\t%i\t%i\t%i\t%i\t%s\tPupilExp\n',... |
||||
subName, time(2), time(3), time(1), time(4), time(5), round(time(6)), hfpRG, hfpBG, Bckg_Chro(iChro,1), Bckg_Chro(iChro,2), cont(iCont), curr_axis(iCond), Card_Dir, randStrt+5, userRes); |
||||
|
||||
% a = cd('/Users/clemente/Dropbox/Luminotecnia/2018/Experiments/Color Background Afterimage/1 Programs/4 ColBackg AI'); % |
||||
% a = cd('D:\Dropbox\Luminotecnia\2017\Chicago Lab files\2 Experiments\Color AfterImage_Exp_Room_150\2nd\1 Programs\4 AfterImage'); % |
||||
|
||||
cd |
||||
|
||||
WaitSecs(.2) |
||||
|
||||
|
||||
%ListenChar(0) |
||||
Screen('FillRect', window, wRGB, windowRect); |
||||
%Screen('DrawDots', window, [0 0],clockPix, 0, center, 2); % black dot for fixation |
||||
Screen('DrawDots', window, [0 0],clockPix, 0, [lftXCircleCenter,center(2)], 2); % black dot for fixation |
||||
Screen('DrawDots', window, [0 0],clockPix, 0, [rhtXCircleCenter,center(2)], 2); % black dot for fixation |
||||
Screen('Flip', window); |
||||
clear secHandCord colLut |
||||
|
||||
|
||||
TrialCount = TrialCount+1 |
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
||||
% WANT TO STOP? % |
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
||||
% pause(3) |
||||
yesno=evalin('base','Stop_Press') |
||||
|
||||
|
||||
if yesno==1 |
||||
return |
||||
end |
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
||||
WaitSecs(ISI); % |
||||
|
||||
|
||||
|
||||
end % iDir |
||||
end %ICond |
||||
end %iCont |
||||
end %iRep |
||||
end %iChro |
||||
|
||||
%%%%%%%%%%%%%%%%%% |
||||
% STOP CAMERA |
||||
Speak('Stop camera software'); |
||||
WaitSecs(10); |
||||
writeDigitalPin(ard,'D3',1); |
||||
writeDigitalPin(ard,'D3',0); |
||||
%%%%%%%%%%%%%%%%% |
||||
|
||||
fclose(fp); |
||||
sca |
||||
%create a matrix of seconds compared to pi values for each frame - just |
||||
%used in data analysis |
||||
% % % % piVSsecs(:,1) = [0:1/(nFrames-1):1]; |
||||
% % % % piVSsecs(:,2) = [0:numSecs/(nFrames-1):numSecs]; |
||||
catch ME |
||||
warndlg('The program failed to run. Try again.') |
||||
disp(ME); |
||||
return |
||||
|
||||
end |
||||
|
||||
end |
@ -0,0 +1,515 @@
@@ -0,0 +1,515 @@
|
||||
function ContMatch_session_Rivalry(subName,meanLum,Bckg_Chro,AdaptTime,curr_cond) |
||||
|
||||
try |
||||
assignin('base','Stop_Press',0)% this works for the STOP experiment button |
||||
|
||||
commandwindow; % open this, and the cursor will appear there |
||||
% Check that Psychtoolbox is properly installed, switch to unified KbName's |
||||
% across operating systems, and switch color range to normalized 0 - 1 range: |
||||
PsychDefaultSetup(2); |
||||
|
||||
%% Start Experiment |
||||
|
||||
%a = cd; |
||||
theDate = fix(clock); |
||||
mainDir = '/Users/mike/Documents/AfterImage/002 After Image GUI Project'; |
||||
locOutDir = ['/Users/mike/Documents/AfterimageOutputs/']; |
||||
saveFile = sprintf('%s%s_ContMatch.mat', locOutDir, subName); |
||||
|
||||
%% Color information, load hfp data and color calibration |
||||
|
||||
hfpFile = sprintf('%s%sHFP', locOutDir, subName); |
||||
load([hfpFile,'.mat']); |
||||
hfpRG = rg_avg |
||||
hfpBG = bg_avg |
||||
|
||||
% hfpRG = .89; |
||||
% hfpBG = 1 ; |
||||
|
||||
%% Load previous matched contrast |
||||
|
||||
name = sprintf('%s%s_ContMatch.mat', locOutDir, subName); |
||||
if exist(name, 'file') == 2 |
||||
|
||||
load(name) |
||||
|
||||
% Prev_l_cont_match = l_cont_match; |
||||
l_cont_match = []; |
||||
% Prev_lum_cont_match = lum_cont_match; |
||||
lum_cont_match = []; |
||||
% Prev_lumMod_match = lumMod_match; |
||||
lumMod_match = []; |
||||
|
||||
|
||||
|
||||
else |
||||
|
||||
Prev_l_cont_match = []; |
||||
Prev_lum_cont_match = []; |
||||
Prev_lumMod_match = []; |
||||
|
||||
end |
||||
|
||||
|
||||
|
||||
|
||||
%% |
||||
%cd(a); % return to folder where the program is |
||||
% Calib_Dire = cd('/Users/clemente/Dropbox/Luminotecnia/2017/Chicago Lab files/2 Experiments/Color AfterImage_Exp_Room_150/2nd/1 Programs/001 After Image GUI Project'); |
||||
load([mainDir,'/colorCalFile1.mat']); |
||||
fprintf('\nLast calibration was %s\n', describe.date); |
||||
pix = pix/1001; |
||||
maxLum = 20; %cd/m^2 |
||||
|
||||
lumMod_initial = [.6 .7 .8 1 ]; |
||||
|
||||
lCont_initial = [0.02 0.026 0.034 .04]; |
||||
|
||||
|
||||
sCont = [.35 .5 .65 .8]; |
||||
% sCont = [.5 .5 .5 .5]; |
||||
|
||||
nCont = length(sCont); |
||||
|
||||
% white = [.665 1]; |
||||
blackLut = [0 0 0]; |
||||
redLut = [.8 0 0]; |
||||
|
||||
% % Bckg_Chro = [.665 1.353 |
||||
% % .665 .647 |
||||
% % .647 1 |
||||
% % .683 1]; % 4 rows X 2 columns |
||||
|
||||
|
||||
%% set up psych toolbox |
||||
%set up 10 bit color |
||||
PsychImaging('PrepareConfiguration'); |
||||
%PsychImaging('AddTask', 'General', 'EnableNative10BitFrameBuffer',1); %the 0 is turn off dithering? |
||||
expScreen = 1; |
||||
%create white LUT |
||||
% % % wLMS(1,1) = white(1,1)*maxLum; |
||||
% % % wLMS(1,2) = (1-white(1,1))*maxLum; |
||||
% % % wLMS(1,3) = white(1,2)*maxLum; |
||||
% % % wXYZ(1,:) = LMS_to_XYZ(wLMS(1,:)); |
||||
% % % wRGB(1,:) = XYZ_to_RGB(wXYZ(1,:), maxPhosXYZ); |
||||
% % % wRGB(1,1) = pix(dsearchn(redProp(:), wRGB(1,1)))*hfpRG; |
||||
% % % wRGB(1,2) = pix(dsearchn(grnProp(:), wRGB(1,2))); |
||||
% % % wRGB(1,3) = pix(dsearchn(blueProp(:), wRGB(1,3)))*hfpBG; |
||||
|
||||
[window, windowRect] = PsychImaging('OpenWindow', expScreen, [0 0 0], [], [], []); % |
||||
%Screen('OpenWindow',0, [0 0 0]); %makes main screen dark |
||||
%PsychImaging('OpenWindow', expScreen, wRGB); |
||||
[xcent,ycent] = RectCenter(windowRect); |
||||
center = [xcent ycent]; |
||||
[xWinSize,~] = Screen('WindowSize',window); |
||||
|
||||
%% TIMING |
||||
%find frames per second |
||||
ifi = Screen('GetFlipInterval', window);% Measure the vertical refresh rate of the monitor |
||||
topPriorityLevel = MaxPriority(window);% Retreive the maximum priority number |
||||
% % % % numSecs = 16; %in seconds, total presentation time |
||||
hfpFreq = 4.6; hfpPeriod = 1/hfpFreq; |
||||
numSecs = hfpPeriod; %in seconds, total presentation time |
||||
framesPerSec = round(1/ifi); |
||||
nFrames = numSecs * framesPerSec; |
||||
|
||||
% waitframes = floor(framesPerSec/hfpFreq); %number of frames to wait between refresh |
||||
nFrames = round(hfpPeriod /ifi) ; |
||||
% % % % waitframes = 1; %number of frames to wait between refresh |
||||
waitframes = 1; %number of frames to wait between refresh |
||||
|
||||
%% Stimulus Size Parameters |
||||
circleDeg = 3.6; |
||||
clockPt = 0.1; |
||||
|
||||
% code assumes 1 pixel = 1 arc min |
||||
pixPerDeg = 35; %at a distance of 57 cm |
||||
circlePix = circleDeg*pixPerDeg; |
||||
clockPix = clockPt*pixPerDeg; |
||||
|
||||
tstcircle = [xcent - circlePix/2 ycent - circlePix/2 xcent + circlePix/2 ycent + circlePix/2]; |
||||
rhtXCircleCenter = xWinSize/4; |
||||
lftXCircleCenter = xWinSize-xWinSize/4; |
||||
tstCircleLeft = [lftXCircleCenter - circlePix/2 ycent - circlePix/2 lftXCircleCenter + circlePix/2 ycent + circlePix/2]; |
||||
tstCircleRight = [rhtXCircleCenter - circlePix/2 ycent - circlePix/2 rhtXCircleCenter + circlePix/2 ycent + circlePix/2]; |
||||
|
||||
% Specs for the border frame |
||||
frameSize = 60; |
||||
frameWidth = 5; |
||||
frameCircleLeft = [tstCircleLeft(1)-frameSize tstCircleLeft(2)-frameSize tstCircleLeft(3)+frameSize tstCircleLeft(4)+frameSize]; |
||||
frameCircleRight = [tstCircleRight(1)-frameSize tstCircleRight(2)-frameSize tstCircleRight(3)+frameSize tstCircleRight(4)+frameSize]; |
||||
|
||||
WaitSecs(1); |
||||
|
||||
%run experiment |
||||
Priority(topPriorityLevel); |
||||
|
||||
vbl = Screen('Flip', window); |
||||
|
||||
|
||||
|
||||
|
||||
%%///////////////////////////////////////////////////////////////////////// |
||||
%%/ TRIALS |
||||
%%///////////////////////////////////////////////////////////////////////// |
||||
|
||||
stepSize_l = 0.0005; |
||||
stepSize_lum = 0.01; |
||||
order = randi(1); |
||||
count = 0; |
||||
|
||||
nRep = 3; % in this case is always three |
||||
|
||||
for iChro = 1:size(Bckg_Chro,1) |
||||
|
||||
wLMS(1,1) = Bckg_Chro(iChro,1)*maxLum; |
||||
wLMS(1,2) = (1-Bckg_Chro(iChro,1))*maxLum; |
||||
wLMS(1,3) = Bckg_Chro(iChro,2)*maxLum; |
||||
wXYZ(1,:) = LMS_to_XYZ(wLMS(1,:)); |
||||
wRGB(1,:) = XYZ_to_RGB(wXYZ(1,:), maxPhosXYZ); |
||||
wRGB(1,1) = pix(dsearchn(redProp(:), wRGB(1,1)))*hfpRG; |
||||
wRGB(1,2) = pix(dsearchn(grnProp(:), wRGB(1,2))); |
||||
wRGB(1,3) = pix(dsearchn(blueProp(:), wRGB(1,3)))*hfpBG; |
||||
|
||||
Screen('FillRect', window, wRGB); |
||||
Screen('Flip',window) |
||||
WaitSecs(AdaptTime) |
||||
|
||||
for iaxis = curr_cond(1):curr_cond(end); % 1 means lCont and 2 means lumCont |
||||
for icont = 1:nCont % number of contrast to match |
||||
for irep = 1:nRep % |
||||
|
||||
FlushEvents('mouseDown','keyDown'); |
||||
|
||||
order = de2bi(count) |
||||
order = order(1); %use the last digit of the binary number (that is the first to matlab) so it switch between 0 and 1 |
||||
|
||||
if iaxis == 1 |
||||
cont_values = linspace(lCont_initial(icont),lCont_initial(icont)-0.02,21); |
||||
initial_idx = randi(length(cont_values)) |
||||
lCont = cont_values(initial_idx) |
||||
elseif iaxis == 2 |
||||
cont_values = linspace(lumMod_initial(icont),lumMod_initial(icont)-.5,21); |
||||
initial_idx = randi(length(cont_values)) |
||||
lumMod = cont_values(initial_idx) |
||||
end |
||||
|
||||
%%///////////////////////////////////////////////////////////////////////// |
||||
%%/ SUBJECT INPUTS (RESPONSES) |
||||
%%///////////////////////////////////////////////////////////////////////// |
||||
|
||||
DoneMatch = 0; |
||||
|
||||
while ~DoneMatch %look for key presses and put up stimulus |
||||
[ keyIsDown, timeSecs, keyCode ] = KbCheck; |
||||
if(CharAvail) % check for keypress, record if key=1 or 2 or 3 |
||||
[char] = GetChar; |
||||
switch char |
||||
case '8' |
||||
DoneMatch = 1; |
||||
clc |
||||
|
||||
switch iaxis |
||||
case 1 |
||||
l_cont_match (irep, icont) = lCont |
||||
case 2 |
||||
lumMod_match (irep, icont) = lumMod |
||||
lum_cont_match (irep, icont) = (lumMod) / maxLum |
||||
end |
||||
|
||||
case '6' |
||||
|
||||
switch iaxis |
||||
case 1 |
||||
lCont = lCont + stepSize_l |
||||
case 2 |
||||
lumMod = lumMod + stepSize_lum |
||||
end |
||||
|
||||
case '4' |
||||
|
||||
switch iaxis |
||||
case 1 |
||||
lCont = lCont - stepSize_l |
||||
if lt(lCont,0) |
||||
lCont=0 |
||||
end |
||||
case 2 |
||||
lumMod = lumMod - stepSize_lum |
||||
if lt(lumMod,0) |
||||
lumMod=0 |
||||
end |
||||
end |
||||
|
||||
case '9' |
||||
|
||||
switch iaxis |
||||
case 1 |
||||
lCont = lCont + stepSize_l/5; |
||||
case 2 |
||||
lumMod = lumMod + stepSize_lum/10; |
||||
end |
||||
|
||||
case '7' |
||||
|
||||
switch iaxis |
||||
case 1 |
||||
lCont = lCont - stepSize_l/5; |
||||
if lt(lCont,0) |
||||
lCont=0 |
||||
end |
||||
case 2 |
||||
lumMod = lumMod - stepSize_lum/10; |
||||
if lt(lumMod,0) |
||||
lumMod=0 |
||||
end |
||||
end |
||||
|
||||
end |
||||
FlushEvents('keyDown'); |
||||
end |
||||
|
||||
%%///////////////////////////////////////////////////////////////////////// |
||||
%%/ SET STIMULUS |
||||
%%///////////////////////////////////////////////////////////////////////// |
||||
%create colors depending on contrast |
||||
switch iaxis |
||||
case 1 |
||||
l = [Bckg_Chro(iChro,1)+(Bckg_Chro(iChro,1)*lCont) Bckg_Chro(iChro,2) maxLum |
||||
Bckg_Chro(iChro,1)-(Bckg_Chro(iChro,1)*lCont) Bckg_Chro(iChro,2) maxLum]; %+l, -l |
||||
|
||||
colLut = l; |
||||
|
||||
case 2 |
||||
lum = [Bckg_Chro(iChro,1) Bckg_Chro(iChro,2) maxLum-lumMod |
||||
Bckg_Chro(iChro,1) Bckg_Chro(iChro,2) maxLum+lumMod]; |
||||
|
||||
colLut = lum; |
||||
end |
||||
|
||||
s = [Bckg_Chro(iChro,1) Bckg_Chro(iChro,2)+(Bckg_Chro(iChro,2)*sCont(icont)) maxLum |
||||
Bckg_Chro(iChro,1) Bckg_Chro(iChro,2)-(Bckg_Chro(iChro,2)*sCont(icont)) maxLum];%+s, -s |
||||
|
||||
colLut_R = s; |
||||
|
||||
|
||||
|
||||
%LMS values of each color, ls to LMS |
||||
for iLMS = 1:2 |
||||
cLMS(iLMS,1) = colLut(iLMS,1)*colLut(iLMS, 3); |
||||
cLMS(iLMS,2) = (1-colLut(iLMS,1))*colLut(iLMS, 3); |
||||
cLMS(iLMS,3) = colLut(iLMS,2)*colLut(iLMS, 3); |
||||
|
||||
cLMS_R(iLMS,1) = colLut_R(iLMS,1)*colLut_R(iLMS, 3); |
||||
cLMS_R(iLMS,2) = (1-colLut_R(iLMS,1))*colLut_R(iLMS, 3); |
||||
cLMS_R(iLMS,3) = colLut_R(iLMS,2)*colLut_R(iLMS, 3); |
||||
|
||||
|
||||
|
||||
end |
||||
|
||||
%XYZ values for each |
||||
for iXYZ = 1:length(cLMS(:,1)) |
||||
cXYZ(iXYZ,:) = LMS_to_XYZ(cLMS(iXYZ,:)); |
||||
|
||||
cXYZ_R(iXYZ,:) = LMS_to_XYZ(cLMS_R(iXYZ,:)); |
||||
end |
||||
|
||||
%use lut to find corrected monitor RGB values for each rgb color |
||||
|
||||
|
||||
for iRGB = 1:length(cXYZ(:,1)) |
||||
cRGB(iRGB,:) = XYZ_to_RGB(cXYZ(iRGB,:), maxPhosXYZ); |
||||
cRGB(iRGB,1) = pix(dsearchn(redProp(:), cRGB(iRGB,1)))*hfpRG; |
||||
cRGB(iRGB,2) = pix(dsearchn(grnProp(:), cRGB(iRGB,2))); |
||||
cRGB(iRGB,3) = pix(dsearchn(blueProp(:), cRGB(iRGB,3)))*hfpBG; |
||||
|
||||
cRGB_R(iRGB,:) = XYZ_to_RGB(cXYZ_R(iRGB,:), maxPhosXYZ); |
||||
cRGB_R(iRGB,1) = pix(dsearchn(redProp(:), cRGB_R(iRGB,1)))*hfpRG; |
||||
cRGB_R(iRGB,2) = pix(dsearchn(grnProp(:), cRGB_R(iRGB,2))); |
||||
cRGB_R(iRGB,3) = pix(dsearchn(blueProp(:), cRGB_R(iRGB,3)))*hfpBG; |
||||
end |
||||
|
||||
|
||||
Left = zeros(nFrames,3); |
||||
Right = zeros(nFrames,3); |
||||
for iRamp = 1:3 %for 3 phosophors |
||||
Left(:,iRamp) = sinspaceOneCycle(wRGB(1,iRamp), cRGB(1,iRamp), nFrames); |
||||
Right(:,iRamp) = sinspaceOneCycle(wRGB(1,iRamp), cRGB_R(1,iRamp), nFrames); |
||||
end |
||||
|
||||
|
||||
%%///////////////////////////////////////////////////////////////////////// |
||||
%%/ DISPLAY STIMULUS |
||||
%%///////////////////////////////////////////////////////////////////////// |
||||
|
||||
startT=GetSecs(); |
||||
elapsedT=0; |
||||
for iFrames = 1:nFrames |
||||
|
||||
|
||||
Screen('FrameOval', window, 0 ,frameCircleLeft, frameWidth, frameWidth); |
||||
Screen('FrameOval', window, 0 ,frameCircleRight, frameWidth, frameWidth); |
||||
Screen('DrawLine', window, 0, lftXCircleCenter+circlePix/2+frameSize, center(2),... |
||||
lftXCircleCenter+circlePix/2+frameSize-20, center(2), frameWidth); |
||||
Screen('DrawLine', window, 0, lftXCircleCenter, center(2)+circlePix/2+frameSize,... |
||||
lftXCircleCenter, center(2)+circlePix/2+frameSize-20, frameWidth); |
||||
Screen('DrawLine', window, 0, rhtXCircleCenter-circlePix/2-frameSize, center(2),... |
||||
rhtXCircleCenter-circlePix/2-frameSize+20, center(2), frameWidth); |
||||
Screen('DrawLine', window, 0, rhtXCircleCenter, center(2)-circlePix/2-frameSize,... |
||||
rhtXCircleCenter, center(2)-circlePix/2-frameSize+20, frameWidth); |
||||
|
||||
switch order |
||||
case 0 |
||||
%LEFT SEMICIRCLE |
||||
Screen('FillArc', window, Left(iFrames,:), tstCircleRight, 180, 180); |
||||
%Screen('FillArc', window, Left(iFrames,:), tstCircleRight, 180, 180); |
||||
%Screen('FillArc', window, Right(iFrames,:), tstCircleLeft, 0, 180); |
||||
Screen('FillArc', window, Right(iFrames,:), tstCircleLeft, 0, 180); |
||||
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi); |
||||
|
||||
case 1 |
||||
%LEFT SEMICIRCLE |
||||
Screen('FillArc', window, Right(iFrames,:), tstCircleRight, 180, 180); |
||||
%Screen('FillArc', window, Left(iFrames,:), tstCircleRight, 180, 180); |
||||
%Screen('FillArc', window, Right(iFrames,:), tstCircleLeft, 0, 180); |
||||
Screen('FillArc', window, Left(iFrames,:), tstCircleLeft, 0, 180); |
||||
|
||||
%Screen('FillArc', window, Right(iFrames,:), tstcircle, 180, 180); |
||||
%Screen('FillArc', window, Left(iFrames,:), tstcircle, 0, 180); |
||||
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi); |
||||
|
||||
end |
||||
|
||||
end |
||||
|
||||
end %while done |
||||
|
||||
|
||||
|
||||
count = count+1; |
||||
elapsedT=GetSecs()-startT; |
||||
FreqCheck = 1/elapsedT; |
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
||||
% CHECK STOP BUTTON PUSHING? % |
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
||||
|
||||
yesno=evalin('base','Stop_Press') |
||||
|
||||
|
||||
if yesno==1 |
||||
return |
||||
end |
||||
|
||||
% - - - - - - - - - - - - - - - - - - - - - - - - - - |
||||
|
||||
end % irep |
||||
end %icont |
||||
end % iaxis |
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
||||
% FINAL VARIABLES % |
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
||||
|
||||
lCont_avg = median(l_cont_match,1); lCont_sd = std(l_cont_match,1); |
||||
lumCont_avg = median(lum_cont_match,1); lumCont_sd = std(lum_cont_match,1); |
||||
lumMod_avg = median(lumMod_match); |
||||
Avg_MatchCont = [lCont_avg ; |
||||
lumCont_avg]; |
||||
|
||||
|
||||
TodayDate = datevec(date); |
||||
for ii=1:nRep |
||||
CoMatch_Date(ii,1:3) = TodayDate(1:3) ; |
||||
end |
||||
|
||||
|
||||
Dated_l_cont_match = [CoMatch_Date repelem(Bckg_Chro(iChro,:),nRep,1) l_cont_match]; |
||||
Dated_lum_cont_match = [CoMatch_Date repelem(Bckg_Chro(iChro,:),nRep,1) lum_cont_match]; |
||||
Dated_lumMod_match = [CoMatch_Date repelem(Bckg_Chro(iChro,:),nRep,1) lumMod_match]; |
||||
|
||||
|
||||
if ~isempty(l_cont_match) |
||||
Prev_l_cont_match = [Prev_l_cont_match ; |
||||
Dated_l_cont_match]; |
||||
end |
||||
|
||||
if ~isempty(lum_cont_match) |
||||
Prev_lum_cont_match = [Prev_lum_cont_match ; |
||||
Dated_lum_cont_match]; |
||||
|
||||
Prev_lumMod_match = [Prev_lumMod_match ; |
||||
Dated_lumMod_match]; |
||||
end |
||||
|
||||
|
||||
if gt(size(Prev_l_cont_match,1),4)% Final values of contrast for the afterimage program |
||||
idx_l = find(and(Prev_l_cont_match(:,4) == Bckg_Chro(iChro,1), Prev_l_cont_match(:,5) == Bckg_Chro(iChro,2) )) |
||||
idx_lum = find(and(Prev_lum_cont_match(:,4) == Bckg_Chro(iChro,1), Prev_lum_cont_match(:,5) == Bckg_Chro(iChro,2) )) |
||||
idx_lumMod = find(and(Prev_lumMod_match(:,4) == Bckg_Chro(iChro,1), Prev_lumMod_match(:,5) == Bckg_Chro(iChro,2) )) |
||||
|
||||
|
||||
Final_lCont_avg(iChro,:) = [Bckg_Chro(iChro,:) median(Prev_l_cont_match(idx_l,end-3:end))]; |
||||
Final_lumCont_avg(iChro,:) = [Bckg_Chro(iChro,:) median(Prev_lum_cont_match(idx_lum,end-3:end))]; |
||||
Final_lumMod_avg(iChro,:) = [Bckg_Chro(iChro,:) median(Prev_lumMod_match(idx_lumMod,end-3:end))]; |
||||
else |
||||
Msg = 'MORE MEASUREMENTS ARE NEEDEED' |
||||
Final_lCont_avg = []; |
||||
Final_lumCont_avg = []; |
||||
Final_lumMod_avg = []; |
||||
|
||||
end |
||||
Final_sCont_ref = sCont; |
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
||||
% PLOT AND SAVE % |
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
||||
|
||||
f(iChro) = figure |
||||
|
||||
if ~isempty(l_cont_match) |
||||
errorbar(sCont,lCont_avg,lCont_sd,'r*--','MarkerSize',15); hold on |
||||
end |
||||
|
||||
if ~isempty(lum_cont_match) |
||||
errorbar(sCont,lumCont_avg,lumCont_sd,'k*--','MarkerSize',15); |
||||
end |
||||
|
||||
switch iChro |
||||
case 1 |
||||
set(f(iChro), 'Position', [1100 770 500 500]); |
||||
title('North (blueish)') |
||||
case 2 |
||||
set(f(iChro), 'Position', [1100 170 500 500]); |
||||
title('South (yellowish)') |
||||
case 3 |
||||
set(f(iChro), 'Position', [400 470 500 500]); |
||||
title('West (greenish)') |
||||
case 4 |
||||
set(f(iChro), 'Position', [1700 470 500 500]); |
||||
title('East (redish)') |
||||
end |
||||
|
||||
|
||||
end% iChro |
||||
|
||||
Screen('CloseAll') |
||||
|
||||
%aa = cd('/Users/clemente/Desktop/AfterImage Programs/A Outputs'); |
||||
save(saveFile,'Final_lCont_avg','Final_lumCont_avg','Final_lumMod_avg','Final_sCont_ref',... |
||||
'Prev_l_cont_match','Prev_lum_cont_match','Prev_lumMod_match') |
||||
|
||||
sca |
||||
|
||||
figure(1);figure(2);figure(3);figure(4); %bring figures to front |
||||
|
||||
catch ME |
||||
disp(ME); |
||||
warndlg('The program failed to run. Try again.') |
||||
return |
||||
|
||||
end |
||||
|
||||
|
||||
end |
Binary file not shown.
Loading…
Reference in new issue