function AfIm_Exp_copy(subName,numRep,maxLum,white,curr_cond) theDate = fix(clock); % % infoFile = sprintf('%s_SessionsInfo', subName); % % fo = fopen(infoFile, 'at'); % % fprintf(fo, '%s\t%i/%i/%i %i:%i:%i\t %1.2f\t%1.3f\t%1.3f\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\t%i\n',... % % subName, time(2), time(3), time(1), time(4), time(5), round(time(6)),... % % maxLum, white(1),white(2), numRep,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); % % saveFile = sprintf('%s_afterimage', subName) a = '/Users/clemente/Dropbox/Luminotecnia/2017/Chicago Lab files/2 Experiments/Color AfterImage_Exp_Room_150/2nd/1 Programs/4 AfterImage' ;% folder where the program is. fp = fopen(saveFile, 'at'); %% Color information, load hfp data and color calibration aa = cd('/Users/clemente/Dropbox/Luminotecnia/2017/Chicago Lab files/2 Experiments/Color AfterImage_Exp_Room_150/2nd/1 Programs/A Outputs'); hfpFile = sprintf('%sHFP', 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/Dropbox/Luminotecnia/2017/Chicago Lab files/2 Experiments/Color AfterImage_Exp_Room_150/2nd/1 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_ContMatch', subName); cd load(contFile, '-mat') lCont = fliplr(Final_lCont_avg);% sort the matrix in descendent order lumMod = fliplr(Final_lumMod_avg); sCont = [.8 .65 .5 .35]; numCont = 4; % white = [.665 1]; blackLut = [0 0 0]; redLut = [.8 0 0]; %% 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, wRGB, [], [], []); % %Screen('OpenWindow',0, [0 0 0]); %makes main screen dark %PsychImaging('OpenWindow', expScreen, wRGB); [xcent,ycent] = RectCenter(windowRect); center = [xcent ycent]; %% 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 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 = 10.15; %is when Zaidi started in his example. clFrmStart = floor(1/ifi*zaidiClock); clTotTime = 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 %% 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]; %create circular grid for clock face and the numbers 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, radNum); end %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)); % numRep = 3; %number of times to repeat the experiment WaitSecs(5); %practice for iprac = 1 FlushEvents('mouseDown','keyDown'); %create colors depending on contrast l = [white(1)+(white(1)*lCont(1)) 1 maxLum white(1)-(white(1)*lCont(1)) 1 maxLum]; %+l, -l s = [white(1) white(2)+(white(2)*sCont(1)) maxLum white(1) white(2)-(white(2)*sCont(1)) maxLum];%+s, -s forFive = [white(1)+(white(1)*lCont(1)) white(2)+(white(2)*sCont(1)) maxLum white(1)-(white(1)*lCont(1)) white(2)-(white(2)*sCont(1)) maxLum]; oneThrFive = [white(1)-(white(1)*lCont(1)) white(2)+(white(2)*sCont(1)) maxLum white(1)+(white(1)*lCont(1)) white(2)-(white(2)*sCont(1)) maxLum]; lum = [white(1) white(2) maxLum-lumMod(1) white(1) white(2) maxLum+lumMod(1)]; lum_l_45 = [white(1)+(white(1)*lCont(1)) white(2) maxLum+lumMod(1) white(1)-(white(1)*lCont(1)) white(2) maxLum-lumMod(1)]; lum_l_135 = [white(1)+(white(1)*lCont(1)) white(2) maxLum-lumMod(1) white(1)-(white(1)*lCont(1)) white(2) maxLum+lumMod(1)]; lum_s_45 = [white(1) white(2)+(white(2)*sCont(1)) maxLum+lumMod(1) white(1) white(2)-(white(2)*sCont(1)) maxLum-lumMod(1)]; lum_s_135 = [white(1) white(2)+(white(2)*sCont(1)) maxLum-lumMod(1) white(1) white(2)-(white(2)*sCont(1)) maxLum+lumMod(1)]; % cond = randperm(1); cond = 1:9 rnd_idx = randperm(length(curr_cond)); curr_cond = curr_cond(rnd_idx) % Cond = Cond(curr_cond_rnd) ; for iCond = 1:length(curr_cond) %create table of color changes switch curr_cond(iCond) case 1 colLut = l; case 2 colLut = s; case 3 colLut = forFive; case 4 colLut = oneThrFive; case 5 colLut = lum; case 6 colLut = lum_l_45; case 7 colLut = lum_l_135; case 8 colLut = lum_s_45; case 9 colLut = lum_s_135; % % % % % % % % case 2 % % % % % % % % colLut = TEST_lum_l; 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 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 %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),rad); end handx = handx + xcent; handy = handy + ycent; WaitSecs(3); %a short adaptation before the next trial keypress = 0; count = 0; %for clock hand Priority(topPriorityLevel); FlushEvents('mouseDown','keyDown'); %ListenChar(2) secs0 = Screen('Flip', window); for iFrames = 1:nFrames Screen('FillArc', window, rampLeft(iFrames,:), tstcircle, 0, 180); Screen('FillArc', window, rampRight(iFrames,:), tstcircle, 180, 180); Screen('DrawDots', window, clockPosMat,clockPix, redLut, center, 2); Screen('DrawDots', window, [0 0],clockPix, 0, center, 2); % black dot for fixation Screen('DrawText', window, 'Pr', 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, redLut, 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 vbl = Screen('Flip', window, secs0 + (waitframes - 0.5) * ifi); Screen('DrawingFinished', window); % tell psychtoolbox drawing is finished, should help timing end Priority(0); 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); WaitSecs(.4); %else % -si no es numero -- ignorar end end %end while userRes Screen('TextSize', window, 14); FlushEvents('mouseDown','keyDown'); aa = cd('/Users/clemente/Dropbox/Luminotecnia/2017/Chicago Lab files/2 Experiments/Color AfterImage_Exp_Room_150/2nd/1 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%i\t%i\t%s\t%i\tPractice\n',... % subName, time(2), time(3), time(1), time(4), time(5), round(time(6)), hfpRG, hfpBG, 1, cond(iCond), randStrt+5, userRes); time = clock; fprintf(fp, '%s\t%i/%i/%i %i:%i:%i\t%1.3f\t%1.3f\t%i\t%i\t%i\t%s\tPractice\n',... subName, time(2), time(3), time(1), time(4), time(5), round(time(6)), hfpRG, hfpBG, 1,curr_cond(iCond), randStrt, userRes); a = cd('/Users/clemente/Dropbox/Luminotecnia/2017/Chicago Lab files/2 Experiments/Color AfterImage_Exp_Room_150/2nd/1 Programs/4 AfterImage'); % % 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('Flip', window); clear secHandCord colLut end end clear iCond TrialCount = 1; %run experiment for iRep = 1:numRep cont = randperm(numCont); %randomize contrast conditions for iCont = 1:numCont FlushEvents('mouseDown','keyDown'); %create colors with depending on contrast l = [white(1)+(white(1)*lCont(cont(iCont))) white(2) maxLum white(1)-(white(1)*lCont(cont(iCont))) white(2) maxLum]; %+l, -l s = [white(1) white(2)+(white(2)*sCont(cont(iCont))) maxLum white(1) white(2)-(white(2)*sCont(cont(iCont))) maxLum];%+s, -s forFive = [white(1)+(white(1)*lCont(cont(iCont))) white(2)+(white(2)*sCont(cont(iCont))) maxLum white(1)-(white(1)*lCont(cont(iCont))) white(2)-(white(2)*sCont(cont(iCont))) maxLum]; oneThrFive = [white(1)-(white(1)*lCont(cont(iCont))) white(2)+(white(2)*sCont(cont(iCont))) maxLum white(1)+(white(1)*lCont(cont(iCont))) white(2)-(white(2)*sCont(cont(iCont))) maxLum]; lum = [white(1) white(2) maxLum-lumMod(cont(iCont)) white(1) white(2) maxLum+lumMod(cont(iCont))]; lum_l_45 = [white(1)+(white(1)*lCont(iCont)) white(2) maxLum+lumMod(iCont) white(1)-(white(1)*lCont(iCont)) white(2) maxLum-lumMod(iCont)]; lum_l_135 = [white(1)+(white(1)*lCont(iCont)) white(2) maxLum-lumMod(iCont) white(1)-(white(1)*lCont(iCont)) white(2) maxLum+lumMod(iCont)]; lum_s_45 = [white(1) white(2)+(white(2)*sCont(iCont)) maxLum+lumMod(iCont) white(1) white(2)-(white(2)*sCont(iCont)) maxLum-lumMod(iCont)]; lum_s_135 = [white(1) white(2)+(white(2)*sCont(iCont)) maxLum-lumMod(iCont) white(1) white(2)-(white(2)*sCont(iCont)) maxLum+lumMod(iCont)]; % cond = 1:9 rnd_idx = randperm(length(curr_cond)); curr_cond = curr_cond(rnd_idx) % Cond = Cond(curr_cond_rnd) ; for iCond = 1:length(curr_cond) %create table of color changes switch curr_cond(iCond) % cond = randperm(9); % for iCond = 1:9 %create table of color changes % switch cond(iCond) case 1 colLut = l; case 2 colLut = s; case 3 colLut = forFive; case 4 colLut = oneThrFive; case 5 colLut = lum; 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 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 %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),rad); end handx = handx + xcent; handy = handy + ycent; WaitSecs(5); %a short adaptation before the next trial 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('FillArc', window, rampLeft(iFrames,:), tstcircle, 0, 180); Screen('FillArc', window, rampRight(iFrames,:), tstcircle, 180, 180); Screen('DrawDots', window, clockPosMat,clockPix, redLut, center, 2); Screen('DrawDots', window, [0 0],clockPix, 0, center, 2); % black dot for fixation 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, redLut, 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 vbl = Screen('Flip', window, secs0 + (waitframes - 0.5) * ifi); Screen('DrawingFinished', window); % tell psychtoolbox drawing is finished, should help timing end Priority(0); % % % % while ~keypress % % % % if CharAvail % % % % userRes = input(' '); % % % % keypress = 1; % % % % end % % % % end % % % % FlushEvents('mouseDown','keyDown'); 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 % userRes = num2str(2); AfterResp = 'OK' Screen('TextSize', window, 14); FlushEvents('mouseDown','keyDown'); aa = cd('/Users/clemente/Dropbox/Luminotecnia/2017/Chicago Lab files/2 Experiments/Color AfterImage_Exp_Room_150/2nd/1 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) % fprintf(fp, '%s\t%i/%i/%i %i:%i:%i\t%1.3f\t%1.3f\t%i\t%i\t%i\t%s\n',... subName, time(2), time(3), time(1), time(4), time(5), round(time(6)), hfpRG, hfpBG, cont(iCont), curr_cond(iCond), randStrt+5, userRes); a = cd('/Users/clemente/Dropbox/Luminotecnia/2017/Chicago Lab files/2 Experiments/Color AfterImage_Exp_Room_150/2nd/1 Programs/4 AfterImage'); % % 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('Flip', window); clear secHandCord colLut TrialCount = TrialCount+1 end %ICond end %iCont end %iRep fclose(fp); sca end