DD_Processing.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. %% define some variables
  2. % remove recordings
  3. remI = 0; % remove certain recordings from analysis? (0: no, 1: yes)
  4. remRec = [1,2,3,4,5,6,13]; % define recordings to be removed from analysis (if remI==1)
  5. % select processing options
  6. detrendI = 0; % detrend data? (1: yes, 0: no)
  7. zsNormI = 0; % z-normalise data data? (1: yes, 0: no)
  8. demeanI = 0; % demean data? (this is independent from baseline correction!)
  9. subsampleI = 1; % calculate averages from all responses (= 0) or only from dev after std and std before dev (= 1)?
  10. % filter settings
  11. type = 1; % 1: Butterworth, 2: IFFT
  12. order = 4;
  13. lowc = [0.1,40,150,300]; % low cut frequency in Hz
  14. hic = 2500; % high cut frequency in Hz
  15. nFilt = size(lowc,2)+1; % number of filters used (+1 because of unfiltered data)
  16. % rejection criterion
  17. artRejI = 0; % turn artefact rejection on (1) or off (0)
  18. rejThr = 150; % uV threshold (every trial with min/max value exceeding this will be rejected before averaging)
  19. % speaker distance
  20. spDis = 0.15; % distance from ear to speaker in m (to correct for sound-travel delay)
  21. % baseline correction settings
  22. blcWin = [-0.001,0]; % window used for baseline correction in s; postive values: time after stim onset, negative values: time before stim onset
  23. %% data processing
  24. for runType = 1:3 % run once for Oddball (1), once for 50 % (2) and once for MR dataset (3)
  25. combName = ["20000,60000";"DisAM,DisNoAM";"DisAM,DisMimic";"DisAM,Eloc";"DisAM,ElocMimic";...
  26. "DisNoAM,DisMimic";"DisNoAM,Eloc";"DisNoAM,ElocMimic";...
  27. "DisMimic,Eloc";"DisMimic,ElocMimic";...
  28. "Eloc,ElocMimic"];
  29. % load data
  30. switch runType
  31. case 1
  32. load('DD_Data_Oddball.mat')
  33. fileName = "DD_avData_Oddball";
  34. case 2
  35. load('DD_Data_50Per.mat')
  36. fileName = "DD_avData_50Per";
  37. case 3
  38. load('DD_Data_MR.mat')
  39. fileName = "DD_avData_MR";
  40. end
  41. nComb = size(combName,1); % number of different stimulus combination to be processed
  42. dataAv_cell = cell(1,nComb); % preallocate
  43. dataGrAv_cell = cell(1,nComb); % preallocate
  44. dataDifAv_cell = cell(1,nComb); % preallocate
  45. dataDifGrAv_cell = cell(1,nComb); % preallocate
  46. dataSe_cell = cell(1,nComb); % preallocate
  47. dataTt_cell = cell(1,nComb); % preallocate
  48. filenames_cell = cell(1,nComb); % preallocate
  49. recID_cell = cell(1,nComb); % preallocate
  50. fileI_Oddb_cell = cell(1,nComb); % preallocate
  51. fileI_Ctrl_cell = cell(1,nComb); % preallocate
  52. timetr_cell = cell(1,nComb); % preallocate
  53. pts2begin_cell = cell(1,nComb); % preallocate
  54. nBlcks_cell = cell(1,nComb); % preallocate
  55. nFiles_cell = cell(1,nComb); % preallocate
  56. nFilt_cell = cell(1,nComb); % preallocate
  57. nDevUsed_cell = cell(1,nComb); % preallocate
  58. nStdUsed_cell = cell(1,nComb); % preallocate
  59. stimDur_cell = cell(1,nComb); % preallocate
  60. stimDelay_cell = cell(1,nComb); % preallocate
  61. fsDwn_cell = cell(1,nComb); % preallocate
  62. for c = 1:nComb % run analysis once for each stimulation-condition
  63. % for c = 7:7 % run analysis once for each stimulation-condition
  64. switch runType
  65. case 1
  66. switch c % switch dataset depending on loop iteration
  67. case 1
  68. data = Data_Oddball_20_60;
  69. case 2
  70. data = Data_Oddball_DisAM_DisNoAM;
  71. case 3
  72. data = Data_Oddball_DisAM_DisMimic;
  73. case 4
  74. data = Data_Oddball_DisAM_Eloc;
  75. case 5
  76. data = Data_Oddball_DisAM_ElocMimic;
  77. case 6
  78. data = Data_Oddball_DisNoAM_DisMimic;
  79. case 7
  80. data = Data_Oddball_DisNoAM_Eloc;
  81. case 8
  82. data = Data_Oddball_DisNoAM_ElocMimic;
  83. case 9
  84. data = Data_Oddball_DisMimic_Eloc;
  85. case 10
  86. data = Data_Oddball_DisMimic_ElocMimic;
  87. case 11
  88. data = Data_Oddball_Eloc_ElocMimic;
  89. end
  90. case 2
  91. switch c % switch dataset depending on loop iteration
  92. case 1
  93. data = Data_50Per_20_60;
  94. case 2
  95. data = Data_50Per_DisAM_DisNoAM;
  96. case 3
  97. data = Data_50Per_DisAM_DisMimic;
  98. case 4
  99. data = Data_50Per_DisAM_Eloc;
  100. case 5
  101. data = Data_50Per_DisAM_ElocMimic;
  102. case 6
  103. data = Data_50Per_DisNoAM_DisMimic;
  104. case 7
  105. data = Data_50Per_DisNoAM_Eloc;
  106. case 8
  107. data = Data_50Per_DisNoAM_ElocMimic;
  108. case 9
  109. data = Data_50Per_DisMimic_Eloc;
  110. case 10
  111. data = Data_50Per_DisMimic_ElocMimic;
  112. case 11
  113. data = Data_50Per_Eloc_ElocMimic;
  114. end
  115. case 3
  116. switch c
  117. case 1 % 20000,60000
  118. data = Data_MR_PureTones;
  119. AfrqI = 1; % frequency index of A in MR control
  120. BfrqI = 7; % frequency index of B in MR control
  121. case 2 % DisAM,DisNoAM
  122. data = Data_MR_Vocs;
  123. AfrqI = 2; % frequency index of DisAM-Response in MR control
  124. BfrqI = 3; % frequency index of DisNoAM-Response in MR control
  125. case 3 % DisAM,DisMimic
  126. data = Data_MR_Vocs;
  127. AfrqI = 2; % frequency index of DisAM-Response in MR control
  128. BfrqI = 10; % frequency index of DisMimic-Response in MR control
  129. case 4 % DisAM,Eloc
  130. data = Data_MR_Vocs;
  131. AfrqI = 2; % frequency index of DisAM-Response in MR control
  132. BfrqI = 1; % frequency index of Eloc-Response in MR control
  133. case 5 % DisAM,ElocMimic
  134. data = Data_MR_Vocs;
  135. AfrqI = 2; % frequency index of DisAM-Response in MR control
  136. BfrqI = 9; % frequency index of ElocMimic-Response in MR control
  137. case 6 % DisNoAM,DisMimic
  138. data = Data_MR_Vocs;
  139. AfrqI = 3; % frequency index of DisNoAM-Response in MR control
  140. BfrqI = 10; % frequency index of DisMimic-Response in MR control
  141. case 7 % DisNoAM,Eloc
  142. data = Data_MR_Vocs;
  143. AfrqI = 3; % frequency index of DisNoAM-Response in MR control
  144. BfrqI = 1; % frequency index of Eloc-Response in MR control
  145. case 8 % DisNoAM,ElocMimic
  146. data = Data_MR_Vocs;
  147. AfrqI = 3; % frequency index of DisNoAM-Response in MR control
  148. BfrqI = 9; % frequency index of ElocMimic-Response in MR control
  149. case 9 % DisMimic,Eloc
  150. data = Data_MR_Vocs;
  151. AfrqI = 10; % frequency index of DisMimic-Response in MR control
  152. BfrqI = 1; % frequency index of Eloc-Response in MR control
  153. case 10 % DisMimic,ElocMimic
  154. data = Data_MR_Vocs;
  155. AfrqI = 10; % frequency index of DisMimic-Response in MR control
  156. BfrqI = 9; % frequency index of ElocMimic-Response in MR control
  157. case 11 % Eloc,ElocMimic
  158. data = Data_MR_Vocs;
  159. AfrqI = 1; % frequency index of Eloc-Response in MR control
  160. BfrqI = 9; % frequency index of ElocMimic-Response in MR control
  161. end
  162. end
  163. % Organise dataset in multiple variables (in separate script)
  164. DD_OrgData
  165. % cut out buffers from raw data and split data into step-blocks
  166. recRawCut = zeros(blockLen,nBlcks,nFiles); % preallocate
  167. for f = 1:nFiles
  168. for b = 1:nBlcks
  169. recRawCut(:,b,f) = rec_raw{f}(1+(b-1)*blockLenBuff(f):blockLen+(b-1)*blockLenBuff(f));
  170. recRawCut(:,b,f) =recRawCut(:,b,f)*96; % convert values from points to µV
  171. end
  172. end
  173. % artefact rejection
  174. recRawCut = reshape(recRawCut,pSmpl,nTrials,nBlcks,nFiles); % reshape to have one trial in each column
  175. nTrialsAcc = zeros(nBlcks,nFiles); % preallocate
  176. seqAcc = zeros(nTrials,nBlcks,nFiles); % preallocate
  177. switch artRejI
  178. case 0 % if artefact rejection is turned off
  179. nTrialsAcc(:) = nTrials;
  180. for f = 1:nFiles
  181. for b = 1:nBlcks
  182. seqAcc(:,b,f) = seq(f,:);
  183. end
  184. end
  185. case 1 % run if artefact rejection is turned on
  186. % preallocate
  187. maxV = zeros(1,nTrials,nBlcks,nFiles);
  188. rejIdx = zeros(1,nTrials,nBlcks,nFiles);
  189. for f = 1:nFiles
  190. for b = 1:nBlcks
  191. for t = 1:nTrials
  192. maxV(1,t,b,f) = max(abs(recRawCut(:,t,b,f))); % find (absolute) max value in each trial for unfiltered data (hence "1" in 5th dimension)
  193. rejIdx(1,t,b,f) = maxV(:,t,b,f)<rejThr; % compare max value of trial with rejection threshold, "1" if max is smaller than threshold -> trial will be accepted later
  194. end % repeat for every trial in current file and (level-)step
  195. nTrialsAcc(b,f) = sum(rejIdx(:,:,b,f)); % count number of accepted trials for current file and step
  196. recRawCut(:,1:nTrialsAcc(b,f),b,f) = recRawCut(:,logical(rejIdx(:,:,b,f)),b,f); % apply previously created rejection index-array as logical array on 2nd dimension (trials) of filtered data. Indexing is applied on all filters (5th dim) simultaneously; array is filled only until number of accepted responses is reached (3rd dim), the rest is still filled with zeros
  197. seqAcc(1:nTrialsAcc(b,f),b,f) = seq(f,logical(rejIdx(:,:,b,f)));
  198. end
  199. end
  200. end
  201. % process data
  202. recPro = recRawCut; % rename
  203. recFilt = zeros(pSmpl*nTrials,nBlcks,nFiles,nFilt-1); % preallocate
  204. for f = 1:nFiles
  205. for b = 1:nBlcks
  206. % detrending
  207. if detrendI==1
  208. recPro(:,1:nTrialsAcc(b,f),b,f) = detrend(recPro(:,1:nTrialsAcc(b,f),b,f));
  209. end
  210. % z score normalisation
  211. if zsNormI==1
  212. recPro(:,1:nTrialsAcc(b,f),b,f) = zscoreJo(recPro(:,1:nTrialsAcc(b,f),b,f),pSmpl);
  213. end
  214. % demeaning
  215. if demeanI==1
  216. recPro(:,1:nTrialsAcc(b,f),b,f) = demean(recPro(:,1:nTrialsAcc(b,f),b,f));
  217. end
  218. % filtering
  219. recProRS = reshape(recPro,nTrials*pSmpl,nBlcks,nFiles);
  220. for ft = 1:nFilt-1 % "-1" because "nFilt" includes raw-array which must be excluded here
  221. recFilt(1:nTrialsAcc(b,f)*pSmpl,b,f,ft) = Filter_Butter(recProRS(1:nTrialsAcc(b,f)*pSmpl,b,f),order,lowc(ft),hic,"bandpass",fsDwn);
  222. end
  223. end
  224. end
  225. recProFilt = cat(4,recProRS,recFilt); % concatenate unfiltered and filtered data in 4th dimension
  226. recProFilt = reshape(recProFilt,pSmpl,nTrials,nBlcks,nFiles,nFilt); % reshape to split raw-data into separate trials (2nd dimension)
  227. % baseline correction
  228. blcStartPts = round(pts2begin(1)+blcWin(1)*fsDwn); % transform time window for baseline correction into points
  229. blcEndPts = round(pts2begin(1)+blcWin(2)*fsDwn);
  230. for f = 1:nFiles
  231. for b = 1:nBlcks
  232. for ft = 1:nFilt
  233. recProFilt(:,1:nTrialsAcc(b,f),b,f,ft) = blCorr(recProFilt(:,1:nTrialsAcc(b,f),b,f,ft),blcStartPts,blcEndPts);
  234. end
  235. end
  236. end
  237. % split blocks into deviant and standard responses
  238. [devR,stdR,nDevAcc,nStdAcc] = sortBlck(recProFilt,seqAcc,nTrialsAcc,AfrqI,BfrqI,runType);
  239. nDevUsed = nDevAcc; % define number of accepted deviants as number of used deviants --> changes later again if subsampling is on!
  240. nStdUsed = nStdAcc; % define number of accepted standards as number of used standards --> changes later again if subsampling is on!
  241. % prepare data for time trace analysis (different script)
  242. devAll = devR; % rename all accepted dev and std responses
  243. stdAll = stdR;
  244. devTt = zeros(pSmpl,100,nBlcks,nFiles,nFilt); % preallocate
  245. stdTt = zeros(pSmpl,100,nBlcks,nFiles,nFilt); % preallocate
  246. stdTtRs = zeros(pSmpl,9,100,nBlcks,nFiles,nFilt); % preallocate
  247. % stdTtMean = zeros(pSmpl,1,100,nBlcks,nFiles,nFilt); % preallocate
  248. stdTt2 = zeros(pSmpl,100,nBlcks,nFiles,nFilt); % preallocate
  249. switch runType % change depending on Oddball/Ctrl
  250. case 1 % oddball
  251. for f = 1:nFiles
  252. for b = 1:nBlcks
  253. devTt(:,:,b,f,:) = devAll(:,1:100,b,f,:); % use all dev responses
  254. stdTt(:,:,b,f,:) = stdAll(:,1:9:900,b,f,:); % use only every 9th std response (to have the same number as dev responses)
  255. stdTtRs(:,:,:,b,f,:) = reshape(stdAll(:,1:900,b,f,:),pSmpl,9,100,1,1,nFilt); % reshape to have 9 consecutive std responses in one dimension
  256. stdTt2(:,:,b,f,:) = mean(stdTtRs(:,:,:,b,f,:),2); % average 9 consecutive std responses and save as stdTt2
  257. end
  258. end
  259. case 2 % 50Per
  260. for f = 1:nFiles
  261. for b = 1:nBlcks
  262. devTt(:,:,b,f,:) = devAll(:,1:5:500,b,f,:); % use only every 5th 50Per response (to have the same number als dev responses)
  263. stdTt(:,:,b,f,:) = stdAll(:,1:5:500,b,f,:);
  264. end
  265. end
  266. case 3 % MR
  267. for f = 1:nFiles
  268. for b = 1:nBlcks
  269. devTt(:,:,b,f,:) = devAll(:,1:100,b,f,:); % use 100 MR responses; ATTENTION: Number of MR responses varies between 95 and 105 -> use only 90 responses in final analysis
  270. stdTt(:,:,b,f,:) = stdAll(:,1:100,b,f,:);
  271. end
  272. end
  273. end
  274. devTtAv = reshape(mean(devTt,4),pSmpl,100,nBlcks,nFilt); % average responses across individuals to be saved and further processed in another script
  275. stdTtAv = reshape(mean(stdTt,4),pSmpl,100,nBlcks,nFilt);
  276. stdTt2Av = reshape(mean(stdTt2,4),pSmpl,100,nBlcks,nFilt);
  277. % subsample oddball responses (extract dev after std & std before
  278. % dev) and reassign variables "nDevUsed" & "nStdUsed"
  279. % ATTENTION: this section only works correctly if the same files
  280. % are available for Oddball and Control conditions!
  281. switch runType
  282. case 1 % if oddball run is processed
  283. switch subsampleI
  284. case 1
  285. [devR,stdR,nTrialsSub] = subsample(devR,stdR,seqAcc,nTrialsAcc); % subsample oddball responses --> number of trials will be much less afterwards (= nTrialsSub)
  286. nDevUsed = nTrialsSub; % define number of subsampled deviants as number of used deviants
  287. nStdUsed = nTrialsSub; % define number of subsampled standards as number of used standards
  288. nDevUsed_oddb{c} = nDevUsed; % assign number of used deviants to separate variable. (std not necessary bc ctrls will only need number of deviants. Additionally, nStdAcc and nDevAcc should be equal anyway if subsampling is on)
  289. end
  290. case {2,3} % if control run is processed
  291. switch subsampleI
  292. case 1
  293. switch runType
  294. case 2 % 50Per
  295. nDevUsed = nDevUsed_oddb{c}; % use respective number of used oddball deviants as number of used control deviants
  296. nStdUsed = nDevUsed_oddb{c}; % ATTENTION: use respective number of used oddball deviants as number of used control standards
  297. end
  298. % in case of MR, use all accepted dev and std
  299. % responses
  300. end
  301. % run random perutation to shuffle responses --> important for 50Per
  302. % control: to make sure not only the earliest responses are used
  303. % for averaging
  304. for f = 1:nFiles
  305. for b = 1:nBlcks
  306. rDev = randperm(nDevAcc(b,f)); % create random vector containing all ACCEPTED dev responses (they cover the whole sequence)
  307. devR(:,1:nDevAcc(b,f),b,f,:) = devR(:,rDev,b,f,:); % shuffle those vectors that contain an actual response and no zeros --> timing within sequence is now irrelevant
  308. rStd = randperm(nStdAcc(b,f)); % repeat the same for std responses
  309. stdR(:,1:nStdAcc(b,f),b,f,:) = stdR(:,rStd,b,f,:);
  310. end
  311. end
  312. end
  313. % calculate average, grand-average & standard error of sorted responses
  314. devAv = zeros(pSmpl,nBlcks,nFiles,nFilt);
  315. stdAv = zeros(pSmpl,nBlcks,nFiles,nFilt);
  316. for f = 1:nFiles
  317. for b = 1:nBlcks
  318. devAv(:,b,f,:) = mean(devR(:,1:nDevUsed(b,f),b,f,:),2); % averaging is performed only on those vectors that contain an actual response and not only zeros (2nd dim) --> only those (meaningful) vectors have been mixed before
  319. stdAv(:,b,f,:) = mean(stdR(:,1:nStdUsed(b,f),b,f,:),2);
  320. end
  321. end
  322. % calculate grand average
  323. devGrAv = reshape(mean(devAv,3),pSmpl,nBlcks,nFilt);
  324. stdGrAv = reshape(mean(stdAv,3),pSmpl,nBlcks,nFilt);
  325. % calculate standard deviation
  326. devStdD = reshape(std(devAv,0,3),pSmpl,nBlcks,nFilt);
  327. stdStdD = reshape(std(stdAv,0,3),pSmpl,nBlcks,nFilt);
  328. % calculate standard error
  329. devSe = devStdD/sqrt(nFiles);
  330. stdSe = stdStdD/sqrt(nFiles);
  331. % split dataset into several sub-variables for simplisity
  332. switch runType
  333. case 1
  334. % sorted responses
  335. ADev{c} = devAv(:,1,:,:); % A is deviant in block 1 (AB)
  336. ADev{c} = reshape(ADev{c},pSmpl,nFiles,nFilt); % reshape av data into 3D array
  337. AStd{c} = stdAv(:,2,:,:); % A is standard in block 2 (BA)
  338. AStd{c} = reshape(AStd{c},pSmpl,nFiles,nFilt); % reshape av data into 3D array
  339. BDev{c} = devAv(:,2,:,:); % B is deviant in block 2 (BA)
  340. BDev{c} = reshape(BDev{c},pSmpl,nFiles,nFilt); % reshape av data into 3D array
  341. BStd{c} = stdAv(:,1,:,:); % B is standard in block 1 (AB)
  342. BStd{c} = reshape(BStd{c},pSmpl,nFiles,nFilt); % reshape av data into 3D array
  343. ADevGrAv{c} = devGrAv(:,1,:);
  344. ADevGrAv{c} = reshape(ADevGrAv{c},pSmpl,nFilt); % reshape grav into 2D array
  345. AStdGrAv{c} = stdGrAv(:,2,:);
  346. AStdGrAv{c} = reshape(AStdGrAv{c},pSmpl,nFilt); % reshape grav data into 2D array
  347. BDevGrAv{c} = devGrAv(:,2,:);
  348. BDevGrAv{c} = reshape(BDevGrAv{c},pSmpl,nFilt); % reshape grav data into 2D array
  349. BStdGrAv{c} = stdGrAv(:,1,:);
  350. BStdGrAv{c} = reshape(BStdGrAv{c},pSmpl,nFilt); % reshape grav data into 2D array
  351. ADevSe{c} = devSe(:,1,:);
  352. ADevSe{c} = reshape(ADevSe{c},pSmpl,nFilt); % reshape standard error into 2D array
  353. AStdSe{c} = stdSe(:,2,:);
  354. AStdSe{c} = reshape(AStdSe{c},pSmpl,nFilt); % reshape standard error into 2D array
  355. BDevSe{c} = devSe(:,2,:);
  356. BDevSe{c} = reshape(BDevSe{c},pSmpl,nFilt); % reshape standard error into 2D array
  357. BStdSe{c} = stdSe(:,1,:);
  358. BStdSe{c} = reshape(BStdSe{c},pSmpl,nFilt); % reshape standard error into 2D array
  359. ADevTt{c} = devTtAv(:,:,1,:); % A is deviant in block 1 (AB)
  360. ADevTt{c} = reshape(ADevTt{c},pSmpl,100,nFilt); % reshape av data into 3D array
  361. AStdTt{c} = stdTtAv(:,:,2,:); % A is standard in block 2 (BA)
  362. AStdTt{c} = reshape(AStdTt{c},pSmpl,100,nFilt); % reshape av data into 3D array
  363. BDevTt{c} = devTtAv(:,:,2,:); % B is deviant in block 2 (BA)
  364. BDevTt{c} = reshape(BDevTt{c},pSmpl,100,nFilt); % reshape av data into 3D array
  365. BStdTt{c} = stdTtAv(:,:,1,:); % B is standard in block 1 (AB)
  366. BStdTt{c} = reshape(BStdTt{c},pSmpl,100,nFilt); % reshape av data into 3D array
  367. AStdTt2{c} = stdTt2Av(:,:,2,:); % A is standard in block 2 (BA)
  368. AStdTt2{c} = reshape(AStdTt2{c},pSmpl,100,nFilt); % reshape av data into 3D array
  369. BStdTt2{c} = stdTt2Av(:,:,1,:); % B is standard in block 1 (AB)
  370. BStdTt2{c} = reshape(BStdTt2{c},pSmpl,100,nFilt); % reshape av data into 3D array
  371. case {2,3}
  372. switch runType
  373. case 2
  374. % sorted responses
  375. ACtrl{c} = devAv(:,1,:,:); % A is deviant in block 1 (AB) --> in this case (50Per), it does not matter which condition is used, as long as it is the right stimulus
  376. ACtrl{c} = reshape(ACtrl{c},pSmpl,nFiles,nFilt); % reshape av data into 3D array
  377. BCtrl{c} = devAv(:,2,:,:); % B is deviant in block 2 (BA) --> in this case (50Per), it does not matter which condition is used, as long as it is the right stimulus
  378. BCtrl{c} = reshape(BCtrl{c},pSmpl,nFiles,nFilt); % reshape av data into 3D array
  379. ACtrlGrAv{c} = devGrAv(:,1,:);
  380. ACtrlGrAv{c} = reshape(ACtrlGrAv{c},pSmpl,nFilt); % reshape grav into 2D array
  381. BCtrlGrAv{c} = devGrAv(:,2,:);
  382. BCtrlGrAv{c} = reshape(BCtrlGrAv{c},pSmpl,nFilt); % reshape grav data into 2D array
  383. ACtrlSe{c} = devSe(:,1,:);
  384. ACtrlSe{c} = reshape(ACtrlSe{c},pSmpl,nFilt); % reshape standard error into 2D array
  385. BCtrlSe{c} = devSe(:,2,:);
  386. BCtrlSe{c} = reshape(BCtrlSe{c},pSmpl,nFilt); % reshape standard error into 2D array
  387. ACtrlTt{c} = devTtAv(:,:,1,:); % A is deviant in block 1 (AB) --> in this case (50Per), it does not matter which condition is used, as long as it is the right stimulus
  388. ACtrlTt{c} = reshape(ACtrlTt{c},pSmpl,100,nFilt); % reshape av data into 3D array
  389. BCtrlTt{c} = devTtAv(:,:,2,:); % B is deviant in block 2 (BA) --> in this case (50Per), it does not matter which condition is used, as long as it is the right stimulus
  390. BCtrlTt{c} = reshape(BCtrlTt{c},pSmpl,100,nFilt); % reshape av data into 3D array
  391. case 3
  392. % sorted responses
  393. ACtrl{c} = devAv; % A was treated as deviant for calculations
  394. ACtrl{c} = reshape(ACtrl{c},pSmpl,nFiles,nFilt); % reshape av data into 3D array
  395. BCtrl{c} = stdAv; % B was treated as standard for calculations
  396. BCtrl{c} = reshape(BCtrl{c},pSmpl,nFiles,nFilt); % reshape av data into 3D array
  397. ACtrlGrAv{c} = devGrAv;
  398. ACtrlGrAv{c} = reshape(ACtrlGrAv{c},pSmpl,nFilt); % reshape grav into 2D array
  399. BCtrlGrAv{c} = stdGrAv;
  400. BCtrlGrAv{c} = reshape(BCtrlGrAv{c},pSmpl,nFilt); % reshape grav into 2D array
  401. ACtrlSe{c} = devSe;
  402. ACtrlSe{c} = reshape(ACtrlSe{c},pSmpl,nFilt); % reshape standard error into 2D array
  403. BCtrlSe{c} = stdSe;
  404. BCtrlSe{c} = reshape(BCtrlSe{c},pSmpl,nFilt); % reshape standard error into 2D array
  405. ACtrlTt{c} = devTtAv; % A was treated as deviant for calculations
  406. ACtrlTt{c} = reshape(ACtrlTt{c},pSmpl,100,nFilt); % reshape av data into 3D array
  407. BCtrlTt{c} = stdTtAv; % B was treated as standard for calculations
  408. BCtrlTt{c} = reshape(BCtrlTt{c},pSmpl,100,nFilt); % reshape av data into 3D array
  409. end
  410. % calculate difference curves
  411. ADifDev{c} = ADev{c}-ACtrl{c};
  412. ADifStd{c} = AStd{c}-ACtrl{c};
  413. BDifDev{c} = BDev{c}-BCtrl{c};
  414. BDifStd{c} = BStd{c}-BCtrl{c};
  415. ADifDevGrAv{c} = ADevGrAv{c}-ACtrlGrAv{c};
  416. ADifStdGrAv{c} = AStdGrAv{c}-ACtrlGrAv{c};
  417. BDifDevGrAv{c} = BDevGrAv{c}-BCtrlGrAv{c};
  418. BDifStdGrAv{c} = BStdGrAv{c}-BCtrlGrAv{c};
  419. end
  420. % organise processed dev and std responses in cell array
  421. switch runType
  422. case 1
  423. dataAv= {ADev{c},AStd{c},BDev{c},BStd{c}};
  424. dataGrAv = {ADevGrAv{c},AStdGrAv{c},BDevGrAv{c},BStdGrAv{c}};
  425. dataDifAv = [];
  426. dataDifGrAv = [];
  427. dataSe = {ADevSe{c},AStdSe{c},BDevSe{c},BStdSe{c}};
  428. dataTt = {ADevTt{c},AStdTt{c},BDevTt{c},BStdTt{c},AStdTt2{c},BStdTt2{c}};
  429. case {2,3}
  430. dataAv = {ACtrl{c},BCtrl{c}};
  431. dataGrAv = {ACtrlGrAv{c},BCtrlGrAv{c}};
  432. dataDifAv = {ADifDev{c},ADifStd{c},BDifDev{c},BDifStd{c}};
  433. dataDifGrAv = {ADifDevGrAv{c},ADifStdGrAv{c},BDifDevGrAv{c},BDifStdGrAv{c}};
  434. dataSe = {ACtrlSe{c},BCtrlSe{c}};
  435. dataTt = {ACtrlTt{c},BCtrlTt{c}};
  436. end
  437. % concatenate important data in another cell array with one cell
  438. % for each stimulation-condition
  439. dataAv_cell{c} = dataAv;
  440. dataGrAv_cell{c} = dataGrAv;
  441. dataDifAv_cell{c} = dataDifAv;
  442. dataDifGrAv_cell{c} = dataDifGrAv;
  443. dataSe_cell{c} = dataSe;
  444. dataTt_cell{c} = dataTt;
  445. filenames_cell{c} = filenames;
  446. recID_cell{c} = recID;
  447. fileI_Oddb_cell{c} = fileI_Oddb;
  448. fileI_Ctrl_cell{c} = fileI_Ctrl;
  449. timetr_cell{c} = timetr;
  450. pts2begin_cell{c} = pts2begin;
  451. nBlcks_cell{c} = nBlcks;
  452. nFiles_cell{c} = nFiles;
  453. nFilt_cell{c} = nFilt;
  454. stimDur_cell{c} = stimDur;
  455. stimDelay_cell{c} = stimDelay;
  456. fsDwn_cell{c} = fsDwn;
  457. nDevUsed_cell{c} = nDevUsed;
  458. nStdUsed_cell{c} = nStdUsed;
  459. end
  460. save(fileName,'dataAv_cell','dataGrAv_cell','dataDifAv_cell',...
  461. 'dataDifGrAv_cell','dataSe_cell','dataTt_cell','filenames_cell','recID_cell',...
  462. 'fileI_Oddb_cell','fileI_Ctrl_cell','timetr_cell','pts2begin_cell','combName',...
  463. 'nComb','nBlcks_cell','nFiles_cell','nFilt_cell','nDevUsed_cell','nStdUsed_cell',...
  464. 'stimDur_cell','stimDelay_cell','fsDwn_cell','subsampleI',...
  465. 'artRejI','zsNormI','detrendI','demeanI')
  466. end