RS_OrgData.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. %% Subscript: Organises data from datasets in multiple variables
  2. % subdivide dataset into its components
  3. if remI==1
  4. data(remRec{repDaSe},:) = []; % remove certain recordings from analysis
  5. end
  6. filenames_stim = cat(1,data{:,1});
  7. bsPos = cell2mat(strfind(filenames_stim,'\')); % find positions of back slashes in filename
  8. % bsPos = strfind(filenames_stim,'\'); % find positions of back slashes in filename
  9. startPos = bsPos(:,end); % use last back slash position as starting point
  10. ptPos = cell2mat(strfind(filenames_stim,'.')); % find positions of points in filename (here only one)
  11. % ptPos = strfind(filenames_stim,'.'); % find positions of points in filename (here only one)
  12. endPos = ptPos; % use point position as ending point
  13. recID = extractBetween(filenames_stim,startPos,endPos,'Boundaries','Exclusive'); % extract between Positions
  14. param_stim = cat(1,data{:,2});
  15. date = cat(1,data{:,7});
  16. artDateI = date<datetime(trArtDate,'Format','yyyyMMdd'); % logical array that identifies recordings with artefact
  17. filenames_rec = cat(1,data{:,3});
  18. param_rec = struct2cell(cat(1,(data{:,4}))); % concatenate struct arrays, then convert to cell arrays
  19. rec_raw = cat(1,data(:,6)./100); % "/100" because data from EP-Preamp are amplified by 100
  20. nFiles = size(data,1); % number of files within the variable
  21. %% define some additional parameters that are needed for calculations
  22. % stimulation-parameters; ATTENTION: always uses the parameters of first
  23. % file --> parameters must be consistent across all files!
  24. fs_stim = param_stim(1,4);
  25. fdown_stim = param_stim(1,17);
  26. fIndx = param_stim(1,2);
  27. Alvl = param_stim(1,9);
  28. Afrq = param_stim(1,10);
  29. Blvl = param_stim(1,26);
  30. Bfrq = param_stim(1,25);
  31. AfrqI = 999; % frequency index in MR control --> redundant but required in other runTypes
  32. BfrqI = 999;
  33. nResp = param_stim(1,47);
  34. SOA = param_stim(1,48);
  35. % define number of blocks dependent on whether all blocks or just a
  36. % sbubsample should be used
  37. switch subSConS
  38. case 0
  39. nBlcks = param_stim(1,49);
  40. case 1 % if subSConS is active
  41. nBlcks = conST; % use only as many blocks as trials were used in the oddball condition
  42. end
  43. IBI = param_stim(1,50);
  44. pts2begin_stim = param_stim(1,41);
  45. stimDur = round(param_stim(1,7),4);
  46. trDel = spDis/343.2; % travelling delay time of stimulus in s (343.2 is the speed of sound in air)
  47. stimDelay = round(param_stim(1,13)+trDel,4); % stimulus delay in s (corrected for sound travelling time)
  48. repper = round(param_stim(1,8),4);
  49. recdur = repper;
  50. recdur = recdur*recDurMult; % adjust rec dur based on multiplicator
  51. % recording-parameters
  52. fs = cat(2,param_rec{1,1})';
  53. chLbl = string(cat(2,param_rec{3,:}))';
  54. pts2begin = round(stimDelay.*fs); % samples before stimulus onset
  55. % additional parameters
  56. nCh = zeros(1,nFiles); % preallocate
  57. rawLen = zeros(1,nFiles); % preallocate
  58. for f = 1:nFiles
  59. nCh(f) = size(rec_raw{f},1); % number of channes in raw file
  60. rawLen(f) = size(rec_raw{f},2); % number of samples in each channel of raw file
  61. end
  62. pBlckRaw = round(SOA.*nResp.*fs); % length of one block WITHOUT additional stim delay added --> required for subsequent calculations
  63. pBlck = pBlckRaw+pts2begin; % length of one block in samples; PLUS stim delay at the end to make sure that all responses are included
  64. pIBI = round(IBI.*fs);
  65. pUnitRaw = pBlckRaw+pIBI;
  66. pUnit = pUnitRaw+pts2begin;
  67. pRecRaw = pUnitRaw*nBlcks;
  68. pRec = pRecRaw+pts2begin;
  69. pSiResp = pBlckRaw/nResp; % number of samples of each single response
  70. timetrUnit = (0:pUnit-1)/fs; % time trace of one trial
  71. timetrBlck = (0:pBlck-1)/fs; % time trace of one trial
  72. timetrSiResp = (0:pSiResp-1)/fs; % time trace of one trial
  73. if channels=="all"
  74. nameCh = chLbl;
  75. nCh_s = nCh;
  76. else
  77. nameCh = channels;
  78. nCh_s = size(channels,2);
  79. end
  80. timetr = (0:pBlck-1)/fs; % time trace of one trial
  81. % triggers
  82. trigs_all = zeros(nFiles,nBlcks); % preallocate
  83. for f = 1:nFiles % extract trigger events for each file individually
  84. eventsTemp = struct2cell(cat(1,data{f,5})); % extract all events from struct array "data" and convert it to cell array
  85. eventsTemp = eventsTemp(:,:,eventsTemp(1,1,:)=="Stimulus"); % find all triggers "Stimulus" within events array
  86. trigsIdx = eventsTemp(2,1,:)=="S 1"; % find all triggers "S 1" within events array
  87. trigsTemp = eventsTemp(3,1,trigsIdx(1,1,:)); % apply logical array on events array to extract triggers
  88. switch c
  89. case {1,2} % for multiple stimuli per block
  90. trigsTemp = trigsTemp(1,1,1:10:end); % use every 10th trigger only (first trigger of each block)
  91. end
  92. trigsTemp = cell2mat(trigsTemp); % convert trigger array to matrix
  93. trigs_all(f,:) = trigsTemp(:,:,1:nBlcks); % concatenate triggers of all files
  94. end