12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- clear all;
- %% settings (transfer to exp settings file)
- npings=5; % total number of pings
- nodd=1; % number of odd pings
- delth=5000; % delay period length (ms)
- pilth=100; % ping duration (ms)
- minipi=400; % minimum inter-ping-interval
- maxsend=1000; %max pause (ms) before first/last ping
- minstart = 300 %minimum start time
- %% command for experiment script
- pausvec=pingT(npings,nodd,delth,pilth,minipi,maxsend,minstart)
- % pausvec(1): time *before* the first ping
- % pausvec(2:npings): time *after* each ping
- % pausvec(1) will be between 0 and minipi
- % pausvec(2) and pausvec(end) will be between 0 and minipi
- %% vector defining which ping is an oddball
- odvec=[zeros(1,npings-nodd) ones(1,nodd)];
- odvec=odvec(randperm(npings));
- %% subfunction doing the timing job for delay between encoding and test
- function pausvec=pingT(npings,nodd,delth,pilth,minipi,maxsend,minstart)
- pausvec=NaN(1,npings+1);
- pausvec(1)=randsample(minstart:maxsend,1); % pause before first ping (<minipi) % JLD edited
- pausvec(end)=randsample(minipi+pilth:maxsend,1);; % pause after last ping (>pilth, <minipi) % JLD edited
- for p=2:npings-1
- tleft=delth-nansum(pausvec); % time left
- pleft=npings-p; % #pings left
- maxipi=tleft-pleft*minipi; % max inter-ping-interval
- pausvec(p)=randsample(minipi:maxipi,1); % pseudo-random pause length
- end
- pausvec(end-1)=delth-nansum(pausvec);% allocate remaining time left
- % shorten post-ping time by ping lenghts (already done for last one)
- pausvec(2:end)=pausvec(2:end)-pilth;
- % do another permute to be sure:
- pausvec=pausvec([1 randperm(npings-1)+1 npings+1]);
- if sum(pausvec)~=delth-pilth*npings
- error('ping time assignment error')
- end
- end
- %%
|