pb_vRunExp.m 4.39 KB
Newer Older
Jesse Heckman's avatar
Jesse Heckman committed
1
function pb_vRunExp(expinfo,h)
Jesse Heckman's avatar
Jesse Heckman committed
2
3
4
5
6
7
8
9
10
11
12
13
% PB_VRUNEXP(varargin)
%
% PB_VRUNEXP() forms the core body of experimental paradigms in the VC, and 
% will loop over the trials.
%
% See also ...

% PBToolbox (2018): JJH: j.heckman@donders.ru.nl

   %% INITIALIZE
   %  load & read experiment
   
Jesse Heckman's avatar
Jesse Heckman committed
14
15
16
   [block, cfg]  	= pb_vReadExp(expinfo.expfile);     % struct
   nblocks       	= cfg.Blocks;
   nTotTrials    	= cfg.Trials;
Jesse Heckman's avatar
Jesse Heckman committed
17
   
Jesse Heckman's avatar
Jesse Heckman committed
18
19
20
   cnt               = 0;
   bDat(nblocks)     = struct;                        % pre-allocate data for speed
   tDat(nTotTrials)  = struct;
Jesse Heckman's avatar
Jesse Heckman committed
21
   
Jesse Heckman's avatar
Jesse Heckman committed
22
   set(h.buttonClose,   'Enable', 'off')                % avoid closing GUI during executing run function     
23
24
25
   set(h.buttonRun,     'Enable', 'off')
   set(h.buttonLoad,    'Enable', 'off')
   
Jesse Heckman's avatar
Jesse Heckman committed
26
27
28
29
30
   % Ready feedback plots
   axes(h.signals); cla;   
   axes(h.eTrace); cla; h.eTrace.YLim = [0 300]; h.eTrace.XLim = [0 2.5]; 
   axes(h.hTrace); cla; h.hTrace.YLim = [0 300]; h.hTrace.XLim = [0 2.5];
   
Jesse Heckman's avatar
Jesse Heckman committed
31
   %% BODY
Jesse Heckman's avatar
Jesse Heckman committed
32
   %  Iterate experiment
Jesse Heckman's avatar
Jesse Heckman committed
33
   
34
35
   pause(2);
   
Jesse Heckman's avatar
Jesse Heckman committed
36
   for iBlock = 1:nblocks
Jesse Heckman's avatar
Jesse Heckman committed
37
      % Runs blocks of trials with a vestibular condition
Jesse Heckman's avatar
Jesse Heckman committed
38
39
      nTrials  = length(block(iBlock).trial);
      
Jesse Heckman's avatar
Jesse Heckman committed
40
41
42
      %% RUN CHAIR
      %  read signals
      signal(1)   = block(iBlock).signal.ver;
Jesse Heckman's avatar
Jesse Heckman committed
43
      signal(2)   = block(iBlock).signal.hor;     
Jesse Heckman's avatar
Jesse Heckman committed
44
      signal      = pb_vSafety(signal); 
Jesse Heckman's avatar
Jesse Heckman committed
45
      
Jesse Heckman's avatar
Jesse Heckman committed
46
47
      % run chair
      bDat(iBlock).signal = pb_vRunVC(signal); 
Jesse Heckman's avatar
Jesse Heckman committed
48
      
Jesse Heckman's avatar
Jesse Heckman committed
49
50
51
      %% PLOT SIGNALS
      %  set axis and plot signals
      axes(h.signals); cla; hold on; 
52
53
      h.signals.YLim = [-50 50];
      
Jesse Heckman's avatar
Jesse Heckman committed
54
55
56
57
      plot(bDat(iBlock).signal.v.t,bDat(iBlock).signal.v.x,'k');
      plot(bDat(iBlock).signal.h.t,bDat(iBlock).signal.h.x,'b');
      
      updateBlock(h,iBlock,signal);
Jesse Heckman's avatar
Jesse Heckman committed
58
   
Jesse Heckman's avatar
Jesse Heckman committed
59
60
61
62
63
      for iTrial = 1:nTrials
         % Runs all trials within one block
         cnt = cnt+1; 
         updateTrial(h, iTrial, cnt, nTotTrials, tDat);
            
64
65
         pb_vClearTrial(cnt,iBlock,iTrial);
         pb_vRecordData(expinfo,cnt);
Jesse Heckman's avatar
Jesse Heckman committed
66
67
         %pb_vRunTrial(experiment(iTrial));
         %pb_vFeedbackGUI();
68
         pause(1);
Jesse Heckman's avatar
Jesse Heckman committed
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
         
         %% PLOT TRACES
         %  head trace
         axes(h.hTrace); hold on;
         ws = 20; b  = (1/ws)*ones(1,ws); a  = 1;
         
         x  = 0:.05:2.5; 
         y  = randi(300,1,length(x)) .* tukeywin(length(x), 2)';
         y  = filter(b,a,y) .* tukeywin(length(x),1)';
         plot(x,y);
         
         %  eye trace
         axes(h.eTrace); hold on;    
         ws = 20; b  = (1/ws)*ones(1,ws); a  = 1;
         
         x  = 0:.05:2.5; 
         y  = randi(300,1,length(x)) .* tukeywin(length(x), 2)';
         y  = filter(b,a,y) .* tukeywin(length(x),1)';
         plot(x,y);
         
         %  highlight active traces
         te = pb_fobj(h.eTrace,'Type','Line'); 
         th = pb_fobj(h.hTrace,'Type','Line'); 
         col = pb_selectcolor(10,5);
         
         for iT = 1:length(th)
            switch iT 
               case length(th)
                  th(iT).Color = col(10,:);
                  te(iT).Color = col(10,:);
               otherwise 
                  th(iT).Color = col(1,:);
                  te(iT).Color = col(1,:);
            end
         end
Jesse Heckman's avatar
Jesse Heckman committed
104
      end
Jesse Heckman's avatar
Jesse Heckman committed
105
      pause(1)
Jesse Heckman's avatar
Jesse Heckman committed
106
   end 
Jesse Heckman's avatar
Jesse Heckman committed
107
   %% CHECK OUT
108
   disp([newline newline 'Experiment finished!'])
Jesse Heckman's avatar
Jesse Heckman committed
109

Jesse Heckman's avatar
Jesse Heckman committed
110
111
112
   set(h.buttonClose,   'Enable', 'on');
   set(h.buttonRun,     'Enable', 'on');
   set(h.buttonLoad,    'Enable', 'on');
Jesse Heckman's avatar
Jesse Heckman committed
113
114
115
116
end

function updateBlock(h, iBlock, signal)
   % Updates the block information to the GUI
Jesse Heckman's avatar
Jesse Heckman committed
117
   
Jesse Heckman's avatar
Jesse Heckman committed
118
119
   bn = pb_sentenceCase(num2str(iBlock,'%03d'));                           % count block
   set(h.Bn,'string',bn);
Jesse Heckman's avatar
Jesse Heckman committed
120
   
121
   vs = ['V = ' pb_sentenceCase(signal(1).type) ...                        % VC stim
Jesse Heckman's avatar
Jesse Heckman committed
122
      ', H = ' pb_sentenceCase(signal(2).type)];
Jesse Heckman's avatar
Jesse Heckman committed
123
124
125
   set(h.Vs,'string',vs);
end

Jesse Heckman's avatar
Jesse Heckman committed
126
function updateTrial(h, iTrial, cnt, nTotTrials, Dat)
Jesse Heckman's avatar
Jesse Heckman committed
127
128
   % Updates the trial information to the GUI
   
129
   h.figure1.Name = ['vPrime - ' num2str(cnt) '/' num2str(nTotTrials) ' Trials'];      % counting title
Jesse Heckman's avatar
Jesse Heckman committed
130
   
131
   tn = num2str(iTrial,'%03d');                                                        % blocktrial
Jesse Heckman's avatar
Jesse Heckman committed
132
133
134
135
   set(h.Tn,'string',tn)
end


Jesse Heckman's avatar
Jesse Heckman committed
136
137
138
139
140
141
142
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % 
%                                                           %
%       Part of Programmeer Beer Toolbox (PBToolbox)        %
%       Written by: Jesse J. Heckman (2018)                 %
%                                                           %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %