pb_vGenExp.m 5.21 KB
Newer Older
Jesse Heckman's avatar
Jesse Heckman committed
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
function pb_vGenExp(varargin)
% PB_VGENEXP()
%
% PB_VGENEXP() will generate an EXP-file for a default localization experiment. 
% EXP-files are used for the psychophysical experiments at the
% Biophysics Department of the Donders Institute for Brain, Cognition and
% Behavior of the Radboud University Nijmegen, the Netherlands.
%
% See also ... See also WRITESND, WRITELED, WRITETRG, GENWAV_DEFAULT, etc

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

   %% Initialization
   %  Clear, empty, default imputs 

   clc;
   close all;
   clear hidden;
   disp('>> GENERATING VC EXPERIMENT <<');
   
   cfn = 0;
   
   showexp     = pb_keyval('showexp',varargin,true);
   expfile     = pb_keyval('fname',varargin,'default_vc.exp'); 
   datdir      = pb_keyval('datdir',varargin,'DEFAULT');
                                               
   %% Desired azimuth and elevation
   dAz         = -45:5:45;
   dEl         = 0;

   [dAz,dEl]   = meshgrid(dAz,dEl);
   dAz         = dAz(:);
   dEl         = dEl(:);

   sel			= (abs(dAz)+abs(dEl))<=60 & dEl>-45; 
   dAz         = dAz(sel);
   dEl         = dEl(sel);
   nloc        = numel(dAz);

   %% Actual azimuth and elevation
   % The actual speaker positions are not perfectly aligned with 5 deg

   cfg			= spherelookup; % sphere positions
   channel		= cfg.interpolant(dAz',dEl');
   X           = cfg.lookup(channel+1,5);
   Y           = cfg.lookup(channel+1,6);

   %% Graphics

   if showexp
      cfn = pb_newfig(cfn);
      hold on;
      plot(dAz,dEl,'o')
      hold on
      plot(X,Y,'x')

      axis([-50 50 -50 50]);
      axis square
      set(gca,'TickDir','out');
      xlabel('Azimuth (deg)');
      ylabel('Elevation (deg)');
      pb_nicegraph;
   end

   %% Stimulus Condition
   
   modality       = [2]; % [1 2 3]; w/ [A, V, AV]
   int				= 65; % approx. dB
   freq           = 1; % BB, HP, LP
   [X,~,~]			= ndgrid(X,0,freq);
   [Y,minled2off,freq]	= ndgrid(Y,0,freq);
   X              = X(:);
   Y              = Y(:);
   int				= int(:);
   freq           = freq(:);

   %% Number and size
   Sz				= size(X);
   N				= Sz(1);% number of trials

   %% Randomize sound samples (to simulate fresh noise
   snd				= freq;
   sel				= snd==1; % BB
   p				= transpose(randperm(100,sum(sel))-1);
   snd(sel)		= snd(sel)*100 + p;

   sel				= snd==2; % HP
   p				= transpose(randperm(100,sum(sel))-1);
   snd(sel)		= snd(sel)*100 + p;

   sel				= snd==3; % LP
   p				= transpose(randperm(100,sum(sel))-1);
   snd(sel)		= snd(sel)*100 + p;

   %% Blocks

   block(1).Horizontal = struct('Amplitude',15,'Signal',1,'Duration',60,'Frequency',.1);
   block(1).Vertical = struct('Amplitude',25,'Signal',2,'Duration',60,'Frequency',.1);
   block(2).Horizontal = struct('Amplitude',50,'Signal',2,'Duration',30,'Frequency',.1);
   block(2).Vertical = struct('Amplitude',15,'Signal',1,'Duration',60,'Frequency',.5);

   %% Save data somewhere
   writeexp(expfile,datdir,X,Y,snd,int,modality,block); 
   % see below, these are helper functions to write an exp-file line by line / stimulus by stimulus

   %% Show the exp-file in Wordpad
   % for PCs
   if ispc && showexp
       dos(['"C:\Program Files\Windows NT\Accessories\wordpad.exe" ' expfile ' &']);
   end
end

function writeexp(expfile,datdir,theta,phi,snd,int,modality,block)
% Save known trial-configurations in exp-file
%
%WRITEEXP WRITEEXP(FNAME,DATDIR,THETA,PHI,ID,LEDON)
%
% WRITEEXP(FNAME,THETA,PHI,ID,LEDON)
%
% Write exp-file with file-name FNAME.
%
%
% See also manual at neural-code.com

   expfile		= fcheckext(expfile,'.exp'); % check whether the extension exp is included


   fid         = fopen(expfile,'w'); % this is the way to write date to a new file
   ntrials     = numel(theta); % only 135 trials

   %% Header of exp-file
   ITI			= [0 0];  % useless, but required in header
   Rep			= 1; % we have 0 repetitions, so insert 1...
   Rnd			= 0; % we randomized ourselves already
   Mtr			= 'n'; % the motor should be on
   writeheader(fid,datdir,ITI,ntrials*Rep,Rep,Rnd,Mtr,'Lab',2); % helper-function

   fprintf(fid,'\n%s%s\t%s\t%s\t%s\t%s','%','AX','SIG','AMP','DUR','FREQ');
   fprintf(fid,'\n%s\t\t\t%s\t%s\t%s\t%s\t%s\t%s\n','%','edg','bit','Event','Time','Event','Time');

   %% Body of exp-file
   % Create a trial
   
   for ii               = 1:ntrials		% each location
        
        AUD.SND = 'SND'; 
        AUD.X = theta; 
        AUD.Y = phi; 
        AUD.ID = snd(ii); 
        AUD.Int = int(ii); 
        AUD.EventOn = 1; 
%        AUD.Onset = ledon(ii)+sndon(ii);
        
        VIS.LED = 'LED'; 
        VIS.X = theta; 
        VIS.Y = phi; 
        VIS.Int = 5; 
        VIS.EventOn = 1; 
%        VIS.Onset = ledon(ii)+sndon(ii); 
        VIS.EventOff = 1; 
%        VIS.Offset = ledon(ii)+sndon(ii)+dur(ii);
        
        writetrl(fid,ii);
%        writeled(fid,'LED',0,0,5,0,0,1,ledon(ii)); % fixation LED
%        pb_writestim(modality(ii),fid,AUD,VIS);
    end
    fclose(fid);
end
 
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % 
%                                                           %
%       Part of Programmeer Beer Toolbox (PBToolbox)        %
%       Written by: Jesse J. Heckman (2018)                 %
%                                                           %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %