pingtim_jld.m 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. clear all;
  2. %% settings (transfer to exp settings file)
  3. npings=5; % total number of pings
  4. nodd=1; % number of odd pings
  5. delth=5000; % delay period length (ms)
  6. pilth=100; % ping duration (ms)
  7. minipi=400; % minimum inter-ping-interval
  8. maxsend=1000; %max pause (ms) before first/last ping
  9. minstart = 300 %minimum start time
  10. %% command for experiment script
  11. pausvec=pingT(npings,nodd,delth,pilth,minipi,maxsend,minstart)
  12. % pausvec(1): time *before* the first ping
  13. % pausvec(2:npings): time *after* each ping
  14. % pausvec(1) will be between 0 and minipi
  15. % pausvec(2) and pausvec(end) will be between 0 and minipi
  16. %% vector defining which ping is an oddball
  17. odvec=[zeros(1,npings-nodd) ones(1,nodd)];
  18. odvec=odvec(randperm(npings));
  19. %% subfunction doing the timing job for delay between encoding and test
  20. function pausvec=pingT(npings,nodd,delth,pilth,minipi,maxsend,minstart)
  21. pausvec=NaN(1,npings+1);
  22. pausvec(1)=randsample(minstart:maxsend,1); % pause before first ping (<minipi) % JLD edited
  23. pausvec(end)=randsample(minipi+pilth:maxsend,1);; % pause after last ping (>pilth, <minipi) % JLD edited
  24. for p=2:npings-1
  25. tleft=delth-nansum(pausvec); % time left
  26. pleft=npings-p; % #pings left
  27. maxipi=tleft-pleft*minipi; % max inter-ping-interval
  28. pausvec(p)=randsample(minipi:maxipi,1); % pseudo-random pause length
  29. end
  30. pausvec(end-1)=delth-nansum(pausvec);% allocate remaining time left
  31. % shorten post-ping time by ping lenghts (already done for last one)
  32. pausvec(2:end)=pausvec(2:end)-pilth;
  33. % do another permute to be sure:
  34. pausvec=pausvec([1 randperm(npings-1)+1 npings+1]);
  35. if sum(pausvec)~=delth-pilth*npings
  36. error('ping time assignment error')
  37. end
  38. end
  39. %%