Commit 51dbaf36 authored by Jesse Heckman's avatar Jesse Heckman
Browse files

added vc generate expp

parent 1351627b
function VIS = pb_vFixLed(VIS,fixled,varargin)
% PB_VFIXLED(VIS,fixled,varargin)
%
% PB_VFIXLED(VIS,fixled,varargin) adds a fixation led at start of VS prior
% to the stimulus
%
% See also PB_VGENVISEXP, PB_VWRITESTIM
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
if ~fixled.bool || ~isstruct(VIS); return; end
x = pb_keyval('x',varargin,0);
y = pb_keyval('y',varargin,0);
dur = pb_keyval('dur',varargin,500);
VIS(end+1) = VIS;
VIS(1).X = x;
VIS(1).Y = y;
VIS(1).Int = 50;
VIS(1).EventOn = 0;
VIS(1).Onset = 0;
VIS(1).EventOff = 0;
VIS(1).Offset = dur;
c = 1;
for i = length(VIS)-1
if VIS(c).EventOn == VIS(c+1).EventOn
VIS(c+1).Onset = VIS(c).Onset + dur;
%VIS(c+1).Offset = VIS(c).Offset + dur;
end
if VIS(c).EventOff == VIS(c+1).EventOff
%VIS(c+1).Offset = VIS(c+1).Offset + dur;
end
c=c+1;
end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......@@ -13,11 +13,9 @@ function pb_vGenVisExp(varargin)
%% Initialization
% Clear, empty, default imputs
clc;
close all;
clear hidden;
pb_clean;
disp('>> GENERATING VC EXPERIMENT <<');
disp(' ...')
cfn = 0;
......@@ -29,14 +27,19 @@ function pb_vGenVisExp(varargin)
cd(cdir);
%% Desired azimuth and elevation
% Select target ranges
maxAbsAz = 5;
maxAbsEl = 0;
% Possible targets
dAz = -45:5:45;
dEl = 0;
[dAz,dEl] = meshgrid(dAz,dEl);
dAz = dAz(:);
dEl = dEl(:);
sel = (abs(dAz)+abs(dEl))<=60 & dEl>-45;
sel = (abs(dAz)+abs(dEl)) <= maxAbsAz & abs(dEl) <= maxAbsEl;
dAz = dAz(sel);
dEl = dEl(sel);
nloc = numel(dAz);
......@@ -44,10 +47,10 @@ function pb_vGenVisExp(varargin)
%% Actual azimuth and elevation
% The actual speaker positions are not perfectly aligned with 5 deg
cfg = spherelookup; % sphere positions
cfg = pb_vLookup; % sphere positions
channel = cfg.interpolant(dAz',dEl');
X = cfg.lookup(channel+1,5);
Y = cfg.lookup(channel+1,6);
X = cfg.lookup(channel+1,4);
Y = cfg.lookup(channel+1,5);
%% Graphics
......@@ -67,36 +70,32 @@ function pb_vGenVisExp(varargin)
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);
% FIXATION LED
fixled.bool = true; % do you want a fixation light?
fixled.x = 0;
fixled.y = 0;
fixled.dur = 2000;
modality = 2; % 2=VISUAL
int = [50]; % w/ [i1, i2, i3...]
dur = [500]; % stim duration in ms
col = [1]; % w/ [R,G]
[X,~,~] = ndgrid(X,0,col,int,dur);
[Y,~,col,int,dur] = ndgrid(Y,0,col,int,dur);
X = X(:);
Y = Y(:);
int = int(:);
freq = freq(:);
int = int(:);
col = col(:);
dur = dur(:);
%% 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;
N = Sz(1); % number of trials
%% Blocks
%% Block Information
block(1).Horizontal = struct('Amplitude',15,'Signal',1,'Duration',60,'Frequency',.1);
block(1).Vertical = struct('Amplitude',25,'Signal',2,'Duration',60,'Frequency',.1);
......@@ -104,7 +103,7 @@ function pb_vGenVisExp(varargin)
block(2).Vertical = struct('Amplitude',15,'Signal',1,'Duration',60,'Frequency',.5);
%% Save data somewhere
writeexp(expfile,datdir,X,Y,int,block);
writeexp(expfile,datdir,X,Y,int,dur,block,fixled);
% see below, these are helper functions to write an exp-file line by line / stimulus by stimulus
%% Show the exp-file in Wordpad
......@@ -114,48 +113,57 @@ function pb_vGenVisExp(varargin)
end
end
function writeexp(expfile,datdir,theta,phi,int,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.
expfile = fcheckext(expfile,'.exp'); % check whether the extension exp is included
function writeexp(expfile,datdir,theta,phi,int,dur,block,fixled)
% 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.
fid = fopen(expfile,'w'); % this is the way to write date to a new file
trialsz = numel(theta); % only 135 trials
blocksz = length(block);
%% 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
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
trlIdx = 1;
trialsz = numel(theta); % number of trials
blocksz = length(block); % xnumber of blocks
trlIdx = 1; % trial count
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
pb_vWriteHeader(fid,datdir,ITI,blocksz,blocksz*trialsz*Rep,Rep,Rnd,Mtr,'Lab',5); % helper-function
for iBlock = 1:blocksz
%pb_vWriteBlock(block);
for ii = 1:trialsz % each location
% Write blocks
pb_vWriteBlock(fid,iBlock);
pb_vWriteSignal(fid,block(iBlock));
pl = randperm(trialsz); % randomize trialorder in blocks
for iTrial = 1:trialsz
% Write trials
pb_vWriteTrial(fid,trlIdx);
VIS = [];
VIS.LED = 'LED';
VIS.X = theta;
VIS.Y = phi;
VIS.Int = int;
VIS.EventOn = 1;
%VIS.Onset = ledon(ii);
VIS.EventOff = 1;
%VIS.Offset = ledon(ii)+dur(ii);
VIS.X = theta(pl(iTrial));
VIS.Y = phi(pl(iTrial));
VIS.Int = int(pl(iTrial));
VIS.EventOn = 0;
VIS.Onset = 500;
VIS.EventOff = 0;
VIS.Offset = VIS.Onset + dur(pl(iTrial));
VIS = pb_vFixLed(VIS,fixled,'x',fixled.x,'y',fixled.y,'dur',fixled.dur);
pb_vWriteTrial(fid,trlIdx);
pb_writestim(2,fid,[],VIS);
pb_vWriteStim(fid,2,[],VIS);
trlIdx = trlIdx +1;
trlIdx = trlIdx+1;
end
end
fclose(fid);
......
function pb_vWriteBlock()
% PB_VWRITEBLOCK()
function pb_vWriteBlock(fid, blckIdx)
% PB_VWRITEBLOCK(fid, blckIdx)
%
% PB_VWRITEBLOCK() ...
% PB_VWRITEBLOCK(fid, blckIdx) writes block announcement in expfile.
%
% See also ...
% See also PB_VGENVISEXP, PB_VWRITETRIAL
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
if nargin < 2; trlIdx = 0; end
if nargin < 2; blckIdx = 0; end
fprintf(fid,'\n');
fprintf(fid,'%s\n',['% Trial: ' num2str(trlIdx)]);
fprintf(fid,'~~~\n');
fprintf(fid,'%s\n',['% Block: ' num2str(blckIdx)]);
fprintf(fid,'%s\n','==>');
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......
......@@ -15,6 +15,9 @@ function pb_vWriteHeader(fid,datdir,ITI,Nblcks,Ntrls,Rep,Rnd,Mtr,varargin)
fprintf(fid,'%s\n','%');
fprintf(fid,'%s\n',['%% Experiment: C:\DATA\' datdir]);
fprintf(fid,'%s\n','%');
fprintf(fid,'\n');
fprintf(fid,'%s %s\n','%%','HEADER');
fprintf(fid,'%s\t\t%d\t%d\n','ITI',ITI(1),ITI(2));
fprintf(fid,'%s\t%d\n','Blocks',Nblcks);
fprintf(fid,'%s\t%d\n','Trials',Ntrls);
......@@ -32,7 +35,7 @@ function pb_vWriteHeader(fid,datdir,ITI,Nblcks,Ntrls,Rep,Rnd,Mtr,varargin)
fprintf(fid,'%s %s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n','%','MOD','X','Y','ID','INT','On','On','Off','Off','Event');
fprintf(fid,'%s\t\t\t%s\t%s\t%s\t%s\t%s\t%s\n','%','edg','bit','Event','Time','Event','Time');
fprintf(fid,'\n');
fprintf(fid,'%% BODY');
fprintf(fid,'%s %s','%%','BODY');
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......
function pb_vWriteSignal(fid,block)
% PB_VWRITESIGNAL(fid,block)
%
% PB_VWRITESIGNAL(fid,block) ...
%
% See also ...
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
h = block.Horizontal;
v = block.Vertical;
fprintf(fid,'%s\t\t%d\t%d\t%d\t%0.1f\n','HOR',h.Signal,h.Amplitude,h.Duration,h.Frequency);
fprintf(fid,'%s\t\t%d\t%d\t%d\t%0.1f\n','VER',v.Signal,v.Amplitude,v.Duration,v.Frequency);
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function pb_vWriteStim(fid,Modality,AUD,VIS)
% PB_VWRITESTIM(fid,Modality,AUD,VIS)
%
% PB_VWRITESTIM(fid,Modality,AUD,VIS) ...
%
% See also ...
% PBToolbox (2018): JJH: j.heckman@donders.ru.nl
stimsz = max([length(AUD) length(VIS)]);
for i = 1:stimsz
switch Modality
case 1 % A
fprintf(fid,'%s\t%d\t%d\t%d\t%f\t%d\t%d\n',AUD(i).SND,AUD(i).X,AUD(i).Y,AUD(i).ID,AUD(i).Int,AUD(i).EventOn,AUD(i).Onset);
case 2 % V
fprintf(fid,'%s\t%.0f\t%.0f\t \t%d\t%d\t%d\t%d\t%d\n',VIS(i).LED,VIS(i).X,VIS(i).Y,VIS(i).Int,VIS(i).EventOn,VIS(i).Onset,VIS(i).EventOff,VIS(i).Offset);
case 3 % AV
fprintf(fid,'%s\t%d\t%d\t%d\t%.1f\t%d\t%d\n',AUD(i).SND,AUD(i).X,AUD(i).Y,AUD(i).ID,AUD(i).Int,AUD(i).EventOn,AUD(i).Onset);
fprintf(fid,'%s\t%.0f\t%.0f\t \t%d\t%d\t%d\t%d\t%d\n',VIS.LED,VIS.X,VIS(i).Y,VIS(i).Int,VIS(i).EventOn,VIS(i).Onset,VIS(i).EventOff,VIS(i).Offset);
end
end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2018) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function pb_vWriteTrial(fid,trlIdx)
% PB_VWRITETRIAL(fid, trlIdx)
%
% PB_VWRITETRIAL(fid, trlIdx) writes trial announcement in expfile.
% PB_VWRITETRIAL(fid, trlIdx) writes trial announcement in expfile.
%
% See also PB_VGENVISEXP, PB_VWRITEBLOCK
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment