123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- function runstim_RF_barsweep(T_Trl)
- global Par %global parameters
- % global LPStat %das status values
- %Size of fixation window
- FixWinSizex = 1.3;
- FixWinSizey = 1.3;
- %Plot marker at RF loc
- % RFon = 0;
- rand('state',sum(clock))
- %Global properties -assumes Tracker opened at 85Hz
- frame = 1/60;
- %Dot sizes (physical)
- FixDotSize = 0.1;%0.3
- FixPix = round(Par.PixPerDeg.*FixDotSize);
- TargSz = 0.5*FixDotSize;%0.3.*Par.PixPerDeg;
- %Fixation coordinates
- Px = 0;
- Py = 0;
- fixcol =[0.6,0,0];%[1 0 0]
- fixcol2 = [0,0,1];
- %Receptive field guesses in pixels, the bar sweep will be centred on this
- %point
- RFx = 30;
- RFy = -30;
- % RFxa = [-50 -70 -50 -80 -100]; % Darwin, guess based on flash map
- % RFya = [-50 -50 -100 -70 -60]; % Darwin
- %Tracker times
- FIXT = 200; %time to fix before stim onset
- STIMT = 1000; %duration of bar sweep, should be 1000ms
- PREFIXT = 2000; %Time ot enter fix window
- %Timing properties
- BarDur = STIMT./1000; %in seconds
- BarDurFrame = round(BarDur./frame);
- %This is speed in degrees per second
- BarSpeed = 4.*Par.PixPerDeg;
- %actual distance covered by bar in stimulus time
- BarDist = BarSpeed.*BarDur;
- %Bar properties
- BarCol = [1 1 1];
- BarThick = 1;%0.33.*Par.PixPerDeg; %in degrees
- BarLength = BarDist/2; %This is half the bar length (in pixels)
- %0 = left to right, 90 = down-to-up, 180 = right to left, 270 = up to down
- Ang = [0 90 180 270];
- Times = Par.Times; %copy timing structure
- BG = [0.5 0.5 0.5]; %background Color
- %Create log file
- LOG.fn = 'runstim_RF_barsweep';
- LOG.BG = BG;
- LOG.Par = Par;
- LOG.Ang = Ang;
- LOG.Times = Times;
- LOG.BarDur = BarDur;
- LOG.BarSpeed = BarSpeed;
- LOG.BarCol = BarCol;
- LOG.BarThick = BarThick;
- LOG.BarLength = BarLength;
- LOG.BarDist = BarDist;
- LOG.Frame = frame;
- LOG.FIXT = FIXT;
- LOG.STIMT = STIMT;
- LOG.RFx = RFx;
- LOG.RFy = RFy;
- LOG.ScreenX = 1024;
- LOG.Screeny = 768;
- currentDir=cd;
- mydir = [currentDir,'\RF_mapping_logs\'];
- fn = input('Enter LOG file name (e.g. 20110413_B1), blank = no file\n','s');
- if isempty(fn)
- logon = 0;
- else
- logon = 1;
- fn = [mydir,'RF_barsweep_',fn];
- save(fn,'LOG')
- end
- % for i = 1:10
- % uS(i)= cgflip(BG(1), BG(2), BG(3));
- % end
- %Copy the run stim, it will have the same name as the LOG and go in the
- %same directory
- fnrs = [fn,'_','runstim.m'];
- cfn = [mfilename('fullpath') '.m'];
- copyfile(cfn,fnrs)
- %Randomly permute the four directions
- RANDTAB = randperm(4);
- %////YOUR STIMULATION CONTROL LOOP /////////////////////////////////
- Hit = 2;
- TZ = 0;
- %Windows (fix only)
- WIN = [0 0 Par.PixPerDeg.*FixWinSizex Par.PixPerDeg.*FixWinSizey 0];
- Par.WIN = WIN';
- Par.ESC = false; %escape has not been pressed
- while ~Par.ESC
- %Pretrial
- %REad in the sweep direction fo rthis trial
- I = RANDTAB(1);
-
- %Word bit = direction
- % dasword(I);
- %Spatial properties - start and end of sweep
- BarStartx = RFx-(cosd(Ang(I)).*(BarDist./2));
- BarStarty = RFy-(sind(Ang(I)).*(BarDist./2));
- BarEndx = RFx+(cosd(Ang(I)).*(BarDist./2));
- BarEndy = RFy+(sind(Ang(I)).*(BarDist./2));
- %Speed
- BarSpeedx = (BarEndx-BarStartx)./BarDurFrame;
- BarSpeedy = (BarEndy-BarStarty)./BarDurFrame;
- %/////////////////////////////////////////////////////////////////////
- %START THE TRIAL
- %set control window positions and dimensions
- refreshtracker(1) %for your control display
- SetWindowDas %for the dascard
- Abort = false; %whether subject has aborted before end of trial
- %///////// EVENT 0 START FIXATING //////////////////////////////////////
- Par.Updatxy = 1;
- cgellipse(Px,Py,FixPix,FixPix,fixcol,'f') %the red fixation dot on the screen
- cgflip(BG(1), BG(2), BG(3))
- dasreset(0)
- %subject has to start fixating central dot
- Par.SetZero = false; %set key to false to remove previous presses
- Par.Updatxy = 1; %centering key is enabled
- Time = 1;
- Hit = 0;
- while Time < PREFIXT && Hit == 0
- dasrun(5)
- [Hit Time] = DasCheck; %retrieve position values and plot on Control display
- end
- %///////// EVENT 1 KEEP FIXATING or REDO ////////////////////////////////////
- Par.Updatxy = 1;
- if Hit ~= 0 %subjects eyes are in fixation window keep fixating for FIX time
- dasreset(1); %test for exiting fix window
- Time = 1;
- Hit = 0;
- while Time < FIXT && Hit == 0
- %Check for 5 ms
- dasrun(5)
- %or just pause for 5ms?
- [Hit Time] = DasCheck;
- end
- if Hit ~= 0 %eye has left fixation to early
- %possibly due to eye overshoot, give another chance
- dasreset(0);
- Time = 1;
- Hit = 0;
- while Time < PREFIXT && Hit == 0
- dasrun(5)
- [Hit Time] = DasCheck; %retrieve position values and plot on Control display
- end
- if Hit ~= 0 %subjects eyes are in fixation window keep fixating for FIX time
- dasreset(1); %test for exiting fix window
- Time = 1;
- Hit = 0;
- while Time < FIXT && Hit == 0
- %Check for 5 ms
- dasrun(5)
- % dasrun(5)
- [Hit Time] = DasCheck;
- end
- else
- Hit = -1; %the subject did not fixate
- end
- end
- else
- Hit = -1; %the subject did not fixate
- end
- %///////// EVENT 2 DISPLAY STIMULUS //////////////////////////////////////
- if Hit == 0 %subject kept fixation, display stimulus
- Par.Updatxy = 1;
- dasreset(1); %test for exiting fix window
- Time = 0;
- % StimFlg = true;
- stimbitdone = 0;
- cgpenwid(BarThick)
- fp=0;
- % clear uS
- while Time < STIMT && Hit == 0 %Keep fixating till target onset
- cgellipse(Px,Py,FixPix,FixPix,fixcol,'f') %the red fixation dot on the screen
- %Centre of Bar, update x and y position
- if ~stimbitdone
- Barx = BarStartx;
- Bary = BarStarty;
- else
- Barx = Barx+BarSpeedx;
- Bary = Bary+BarSpeedy;
- end
- %Bar begin and end
- BarAng = Ang(I)+90;
- x1 = round(Barx-(cosd(BarAng).*(BarLength)));
- x2 = round(Barx+(cosd(BarAng).*(BarLength)));
- y1 = round(Bary-(sind(BarAng).*(BarLength)));
- y2 = round(Bary+(sind(BarAng).*(BarLength)));
- cgdraw(x1,y1,x2,y2,BarCol)
- % if RFon
- % for r = 1:length(RFxa)
- % cgellipse(RFxa(r),RFya(r),20,20,[1,0,1],'f')
- % end
- % end
- % cgflip('V')
- fp = fp+1;
- uS(fp) = cgflip(BG(1), BG(2), BG(3));
- % pause
- if ~stimbitdone
- % dasbit(Par.StimB, 1);
- dasbit(1, 1);%first input arg- 1: stim on
- stimbitdone = 1;
- end
- %..............................................................
- % if Time > STIMT && StimFlg %present stim no longer than stim time
- % StimFlg = false;
- % end
-
- % %Check for 1 ms
- dasrun(1)%check whether fixation is maintained
- Hit = LPStat(1); %LPStat reads out results from dasrun (buffer)
- Time = LPStat(0); %time
- %[Hit,Time] = DasCheck;
- end
- % dasreset( 0 ) %test enter fix window
- % 0 enter fix window
- % 1 leave fix window
- % 2 enter target window
- %LPStat(0) = time (ms) passed since last reset
- %LPStat(1) = control window hit (1 : in or out (depending on input arg to dasreset), 2 : in correct
- % target window
- %LPStat.(2) = hit position x
- %LPStat(3) = hit postion y
- %LPStat(4) = reaction time(saccade onset)
- %LPStat(5) = time saccade length (exiting fix win and entering target
- %win)
- %///////// EVENT 3 TARGET ONSET, REACTION TIME //////////////////////////////////////
- Par.Updatxy = 1;
- if Hit == 0 %subject kept fixation
- cgellipse(0,0,TargSz,TargSz,fixcol2,'f') %the red fixation dot on the screen
- cgflip(BG(1), BG(2), BG(3))
- % dasbit(Par.TargetB, 1);
- %EXTRACT USING THE TARGETB as we only want completed trials
- %Update counter
- TZ = TZ+1;
- MAT(TZ,:) = [I,Ang(I),1];
- Hit = 2;
- else
- Abort = true;
- end
- %END EVENT 3
- else
- Abort = true;
- end
- %END EVENT 2
- %///////// POSTTRIAL AND REWARD //////////////////////////////////////
- if Hit ~= 0 && ~Abort %has entered a target window (false or correct)
- % if Par.Mouserun
- % HP = line('XData', Par.ZOOM * (LPStat(3) + Par.MOff(1)), 'YData', Par.ZOOM * (LPStat(4) + Par.MOff(2)), 'EraseMode','none');
- % else
- % HP = line('XData', Par.ZOOM * LPStat(3), 'YData', Par.ZOOM * LPStat(4), 'EraseMode','none');
- % end
- % set(HP, 'Marker', '+', 'MarkerSize', 20, 'MarkerEdgeColor', 'm')
-
- if Hit == 2
- % dasbit(Par.MicroB, 1);
- % dasbit(Par.CorrectB, 1);
- dasbit(2, 1);%first input arg- 2: correct trial
- pause(0.1);%add a time buffer between sending of dasbits
- dasbit(2+I, 1);%first input arg- 3 to 6: stimulus condition
- % dasbit(Par.RewardB, 1);
- dasjuice(5.1);
- Par.Corrcount = Par.Corrcount + 1;
- pause(Par.RewardTime) %RewardTime is in seconds
- dasjuice(0.0);
- % dasbit(Par.RewardB, 0);
- %Remove trial
- RANDTAB(1) = [];
- if ~length(RANDTAB)
- RANDTAB = randperm(4);
- end
-
- else
- Hit = 0;
- end
- %keep following eye motion
- dasrun(5)
- DasCheck; %keep following eye motion
- end
- %///////////////////////INTERTRIAL AND CLEANUP
- % display([ num2str(Hit) ' ' num2str(LPStat(6)) ' ' num2str(LPStat(7)) ' ' num2str(Time - LPStat(7)) ]);
- %reset all bits to null
- for i = [0 1 2 3 4 5 6 7] %Error, Stim, Saccade, Trial, Correct,
- dasbit(i, 0);
- end
- dasclearword
- %Par.Trlcount = Par.Trlcount + 1; %counts total number of trials for this session
- %tracker('update_trials', gcbo, [], guidata(gcbo)) %displays number of trials, corrects and errors
- Par.Trlcount = Par.Trlcount + 1; %counts total number of trials for this session
- SCNT = {'TRIALS'};
- SCNT(2) = { ['N: ' num2str(Par.Trlcount) ]};
- SCNT(3) = { ['C: ' num2str(Par.Corrcount) ] };
- SCNT(4) = { ['E: ' num2str(Par.Errcount) ] };
- set(T_Trl, 'String', SCNT ) %display updated numbers in GUI
- [Hit T] = DasCheck;
- % cgrect(465,-370,50,50,[1,1,1])
- cgflip(BG(1), BG(2), BG(3))
- % pause( Times.InterTrial/1000 ) %pause is called with seconds
- %Times.InterTrial is in ms
-
- if TZ > 0
- save(fn,'LOG','MAT')
- end
- end %WHILE_NOT_ESCAPED%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|