DD_Plotting.m 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. %% define some variables
  2. filt = 4; % 1: non, 2: 10 Hz, 3: 45 Hz, 4: 50 Hz, 5: 55 Hz
  3. cutTime = 2; % plot only certain time window? (0: no, 1: short, 2: long)
  4. avType = 1; % plot grand average (1) or individual averages (2)
  5. fixedY = 1; % use dynamic (0) or fixed (1) y-axis?
  6. inclCtrl = 0; % plot control data? (0: no, 1: 50 %, 2: MR, 3: DevOnly)
  7. statsType = 1; % decide which statistics to use if control is included; 1: t-test, 2: ANOVA
  8. plotStatsI = 1; % plot stats-windows?
  9. varType = 1; % plot stats of amplitude or timing variable? (1: amplitude, 2: timimg)
  10. uWin = (1); % used windows for stats (1:4) (it's always 4 if varType is 2)
  11. repRateI = 1; % decide which rep rate to plot (1: 25 ms, 2: 30 ms, 3: 50 ms)
  12. subStdI = 2; % decide which dataset to plot; 1: Std after Dev, 2: Std before Dev (does not affect omission responses)
  13. anaType = 1; % 1: window-based analysis; 2: point-based analysis
  14. plotRespI = 1; % plot responses?
  15. plotDifI = 0; % plot difference curves?
  16. plotOmI = 0; % plot omission responses?
  17. plotBpI = 1; % plot boxplots?
  18. plotCsResI = 0; % plot consecutive standard responses?
  19. plotCsValI = 0; % plot response strengths of consecutive standard responses
  20. clMark = 0; % plot significant clusters as bars? (no: 0, bar: 1)
  21. cStart = 1; % stimulus combination to start with
  22. oLowHigh = 0; % plot only Low and High chirp?
  23. saveI = 0; % save figure?
  24. chirpPeak = [0.00648,0.00842];
  25. % decide which set of rms-windows to plot
  26. % boxpFigWi = 800; % width of boxplot figure
  27. switch size(uWin,2)
  28. case 1
  29. boxpFigWi = 300; % width of boxplot figure
  30. case 2
  31. boxpFigWi = 500; % width of boxplot figure
  32. end
  33. % switch plotOmI
  34. % case 1
  35. % uWin = 1;
  36. % end
  37. switch filt
  38. case 1
  39. switch plotOmI
  40. case 0
  41. filtName = 'noF';
  42. y_lim = [-0.8,1];
  43. case 1
  44. filtName = 'noF';
  45. y_lim = [-0.8,1];
  46. end
  47. case 2
  48. switch plotOmI
  49. case 0
  50. filtName = '10F';
  51. y_lim = [-0.8,1];
  52. case 1
  53. filtName = '10F';
  54. y_lim = [-0.8,1];
  55. end
  56. case 3
  57. switch plotOmI
  58. case 0
  59. filtName = '45F';
  60. y_lim = [-0.8,1];
  61. case 1
  62. filtName = '45F';
  63. y_lim = [-0.8,1];
  64. end
  65. case 4
  66. switch plotOmI
  67. case 0
  68. filtName = '50F';
  69. y_lim = [-0.35,0.55];
  70. case 1
  71. filtName = '50F';
  72. y_lim = [-0.35,0.55];
  73. end
  74. case 5
  75. switch plotOmI
  76. case 0
  77. filtName = '55F';
  78. y_lim = [-0.3,0.55];
  79. case 1
  80. filtName = '55F';
  81. y_lim = [-0.3,0.55];
  82. end
  83. end
  84. % define colors and names
  85. colDev = [1,0,0]; % dev: red
  86. colStd = [0,0,1]; % std: blue
  87. col50Per = [1,0,1]; % 50Per: magenta
  88. colMR = [0,0,0]; % MR: black
  89. colDevO = [0,0,0]; % Dev only: black
  90. switch plotOmI
  91. case 0
  92. nameDev = 'Deviant';
  93. nameStd = 'Standard';
  94. case 1
  95. nameDev = 'Omitted deviant';
  96. nameStd = 'Omitted standard';
  97. end
  98. name50Per = '50 % Control';
  99. nameMR = 'MS Control';
  100. nameDevO = 'Dev Only';
  101. %% load processed data
  102. switch repRateI
  103. case 1
  104. repRate = '25ms';
  105. case 2
  106. repRate = '30ms';
  107. case 3
  108. repRate = '50ms';
  109. end
  110. switch subStdI
  111. case 1
  112. subStd = 'SaD';
  113. case 2
  114. subStd = 'SbD';
  115. end
  116. switch inclCtrl
  117. case 0
  118. load(['DD_CbpData_noCtrl_',repRate,'_',subStd,'.mat']) % load stats data
  119. load(['DD_statsData_noCtrl_',repRate,'_',subStd,'.mat']) % load stats data
  120. case 1 % load 50Per data and rename important variables
  121. load(['DD_avData_50Per_',repRate,'_',subStd,'.mat'])
  122. load('DD_CbpData_50Per_',repRate,'_',subStd,'.mat') % load stats data
  123. load('DD_statsData_50Per_',repRate,'_',subStd,'.mat') % load stats data
  124. dataAv_cell_Ctrl = dataAv_cell; % rename
  125. dataGrAv_cell_Ctrl = dataGrAv_cell;
  126. dataDifAv_cell_Ctrl = dataDifAv_cell; % rename
  127. dataDifGrAv_cell_Ctrl = dataDifGrAv_cell;
  128. dataSe_cell_Ctrl = dataSe_cell;
  129. filenames_stim_cell_Ctrl = filenames_stim_cell;
  130. nameCtrl = name50Per;
  131. colCtrl = col50Per; % set control color to 50 % color
  132. case 2 % load MR data and rename important variables
  133. load(['DD_avData_MR_',repRate,'_',subStd,'.mat'])
  134. load('DD_CbpData_MR_',repRate,'_',subStd,'.mat') % load stats data
  135. load('DD_statsData_MR_',repRate,'_',subStd,'.mat') % load stats data
  136. dataAv_cell_Ctrl = dataAv_cell; % rename
  137. dataGrAv_cell_Ctrl = dataGrAv_cell;
  138. dataDifAv_cell_Ctrl = dataDifAv_cell; % rename
  139. dataDifGrAv_cell_Ctrl = dataDifGrAv_cell;
  140. dataSe_cell_Ctrl = dataSe_cell;
  141. filenames_stim_cell_Ctrl = filenames_stim_cell;
  142. nameCtrl = nameMR;
  143. colCtrl = colMR; % set control color to MR color
  144. case 3
  145. load(['DD_avData_LowOnly_',repRate,'_',subStd,'.mat'])
  146. load('DD_CbpData_DevO_',repRate,'_',subStd,'.mat') % load stats data
  147. load('DD_statsData_DevO_',repRate,'_',subStd,'.mat') % load stats data
  148. dataAv_cell_CoLow = dataAv_cell; % rename
  149. dataGrAv_cell_CoLow = dataGrAv_cell;
  150. dataSe_cell_CoLow = dataSe_cell;
  151. filenames_cell_CoLow = filenames_stim_cell;
  152. load(['DD_avData_HighOnly_',repRate,'_',subStd,'.mat'])
  153. dataAv_cell_CoHigh = dataAv_cell; % rename
  154. dataGrAv_cell_CoHigh = dataGrAv_cell;
  155. dataSe_cell_CoHigh = dataSe_cell;
  156. filenames_cell_CoHigh = filenames_stim_cell;
  157. nameCtrl = nameDevO;
  158. colCtrl = colDevO; % set control color to MR color
  159. end
  160. switch plotOmI
  161. case 0
  162. % load Oddball data (will overwrite Ctrl variables that were not renamed)
  163. load(['DD_avData_Oddball_',repRate,'_',subStd,'.mat'])
  164. case 1
  165. load(['DD_avData_HighOm_',repRate,'.mat'])
  166. % load Om data
  167. dataAv_cell_HighOm = dataAv_cell; % rename
  168. dataGrAv_cell_HighOm = dataGrAv_cell;
  169. dataSe_cell_HighOm = dataSe_cell;
  170. filenames_cell_HighOm = filenames_stim_cell;
  171. load(['DD_avData_LowOm_',repRate,'.mat'])
  172. dataAv_cell_LowOm = dataAv_cell; % rename
  173. dataGrAv_cell_LowOm = dataGrAv_cell;
  174. dataSe_cell_LowOm = dataSe_cell;
  175. filenames_cell_LowOm = filenames_stim_cell;
  176. load(['DD_CbpData_Om_',repRate,'.mat']) % load stats data
  177. load(['DD_statsData_Om_',repRate,'.mat']) % load stats data
  178. end
  179. %% do some additional calculations
  180. switch zsNormI
  181. case 0
  182. yLabelName = 'Voltage [µV]';
  183. case 1
  184. yLabelName = 'z-norm. voltage [a.u.]';
  185. end
  186. % change stats variables if timing is selected
  187. if varType==2
  188. varS = timS;
  189. pV = pTV;
  190. cohensD_V = cohensDT_V;
  191. statsV = statsTV;
  192. uWin = 2;
  193. end
  194. switch cutTime
  195. case 1
  196. switch filt
  197. case {1,2,3}
  198. timeStart = -2; % starting time of the plot (relative to stim onset)
  199. timeEnd = 20; % ending time of the plot (relative to stim onset)
  200. case {4,5}
  201. timeStart = -2; % starting time of the plot (relative to stim onset)
  202. timeEnd = 20; % ending time of the plot (relative to stim onset)
  203. end
  204. case 2
  205. switch repRateI
  206. case 1
  207. timeStart = -2; % starting time of the plot (relative to stim onset)
  208. timeEnd = 10.5; % ending time of the plot (relative to stim onset)
  209. case 2
  210. timeStart = -2; % starting time of the plot (relative to stim onset)
  211. timeEnd = 10.5; % ending time of the plot (relative to stim onset)
  212. case 3
  213. timeStart = -2; % starting time of the plot (relative to stim onset)
  214. timeEnd = 10.5; % ending time of the plot (relative to stim onset)
  215. end
  216. end
  217. if oLowHigh==1 % plot only stim combination 7 (DisNoAM/Eloc) if oDisEloc is 1
  218. cStart = 1;
  219. nComb = 1;
  220. end
  221. combNameS = split(combName(cStart:end),","); % split comb names at comma
  222. %% plotting: responses
  223. if plotRespI==1
  224. for c = cStart:nComb % run once for each stimulus combination
  225. % extract data corresponding to current stimulation-condition from
  226. % cell-arrays
  227. switch plotDifI
  228. case 0
  229. switch plotOmI
  230. case 0
  231. dataAv = dataAv_cell{c};
  232. dataGrAv = dataGrAv_cell{c};
  233. dataSe = dataSe_cell{c};
  234. case 1
  235. dataAvHighOm = dataAv_cell_HighOm{c};
  236. dataGrAvHighOm = dataGrAv_cell_HighOm{c};
  237. dataSeHighOm = dataSe_cell_HighOm{c};
  238. dataAvLowOm = dataAv_cell_LowOm{c};
  239. dataGrAvLowOm = dataGrAv_cell_LowOm{c};
  240. dataSeLowOm = dataSe_cell_LowOm{c};
  241. combName = append("OR_",combName);
  242. end
  243. switch inclCtrl
  244. case {1,2}
  245. dataAvCtrl = dataAv_cell_Ctrl{c};
  246. dataGrAvCtrl = dataGrAv_cell_Ctrl{c};
  247. dataSeCtrl = dataSe_cell_Ctrl{c};
  248. filenames_Ctrl = filenames_stim_cell_Ctrl{c};
  249. bsPos = cell2mat(strfind(filenames_Ctrl,'\')); % find positions of back slashes in filename
  250. % bsPos = strfind(filenames_Ctrl,'\'); % find positions of back slashes in filename
  251. startPos = bsPos(:,end); % use last back slash position as starting point
  252. filenames_Ctrl = extractAfter(filenames_Ctrl,startPos);
  253. case 3
  254. dataAvCoLow = dataAv_cell_CoLow{c};
  255. dataGrAvCoLow = dataGrAv_cell_CoLow{c};
  256. dataSeCoLow = dataSe_cell_CoLow{c};
  257. filenames_CoLow = filenames_cell_CoLow{c};
  258. bsPos = cell2mat(strfind(filenames_CoLow,'\')); % find positions of back slashes in filename
  259. startPos = bsPos(:,end); % use last back slash position as starting point
  260. filenames_CoLow = extractAfter(filenames_CoLow,startPos);
  261. dataAvCoHigh = dataAv_cell_CoHigh{c};
  262. dataGrAvCoHigh = dataGrAv_cell_CoHigh{c};
  263. dataSeCoHigh = dataSe_cell_CoHigh{c};
  264. filenames_CoHigh = filenames_cell_CoHigh{c};
  265. bsPos = cell2mat(strfind(filenames_CoHigh,'\')); % find positions of back slashes in filename
  266. startPos = bsPos(:,end); % use last back slash position as starting point
  267. filenames_CoHigh = extractAfter(filenames_CoHigh,startPos);
  268. end
  269. case 1
  270. dataAv = dataDifAv_cell_Ctrl{c};
  271. dataGrAv = dataDifGrAv_cell_Ctrl{c};
  272. plotStatsI = 0; % plot no significance windows when plotting diference curves
  273. switch inclCtrl
  274. case 0
  275. error('To plot difference curves, activate inclCtrl')
  276. case {1,2}
  277. dataAvCtrl = dataAv_cell_Ctrl{c}; % won't be plotted, only processed to keep the code simpler
  278. dataGrAvCtrl = dataGrAv_cell_Ctrl{c};
  279. filenames_Ctrl = filenames_cell_Ctrl{c};
  280. bsPos = cell2mat(strfind(filenames_Ctrl,'\')); % find positions of back slashes in filename
  281. startPos = bsPos(:,end); % use last back slash position as starting point
  282. filenames_Ctrl = extractAfter(filenames_Ctrl,startPos);
  283. case 3
  284. dataAvCoLow = dataAv_cell_CoLow{c}; % won't be plotted, only processed to keep the code simpler
  285. dataGrAvCoLow = dataGrAv_cell_CoLow{c};
  286. filenames_CoLow = filenames_cell_CoLow{c};
  287. bsPos = cell2mat(strfind(filenames_CoLow,'\')); % find positions of back slashes in filename
  288. startPos = bsPos(:,end); % use last back slash position as starting point
  289. filenames_CoLow = extractAfter(filenames_CoLow,startPos);
  290. dataAvCoHigh = dataAv_cell_CoHigh{c}; % won't be plotted, only processed to keep the code simpler
  291. dataGrAvCoHigh = dataGrAv_cell_CoHigh{c};
  292. filenames_CoHigh = filenames_cell_CoHigh{c};
  293. bsPos = cell2mat(strfind(filenames_CoHigh,'\')); % find positions of back slashes in filename
  294. startPos = bsPos(:,end); % use last back slash position as starting point
  295. filenames_CoHigh = extractAfter(filenames_CoHigh,startPos);
  296. end
  297. end
  298. filenames = filenames_stim_cell{c};
  299. recID = recID_cell{c};
  300. bsPos = cell2mat(strfind(filenames,'\')); % find positions of back slashes in filename
  301. % bsPos = strfind(filenames,'\'); % find positions of back slashes in filename
  302. startPos = bsPos(:,end); % use last back slash position as starting point
  303. filenames = extractAfter(filenames,startPos);
  304. timetr = round(timetr_cell{c}*1000,4);
  305. stimDur = stimDur_cell{c}(1)*1000;
  306. stimDelay = stimDelay_cell{c}(1)*1000;
  307. stimWin = [stimDelay,stimDelay+stimDur];
  308. nFiles = nFiles_cell{c};
  309. fs = fs_cell{c};
  310. % subdivide responses for simplicity
  311. switch plotOmI
  312. case 0
  313. ADevAv = dataAv{1};
  314. AStdAv = dataAv{2};
  315. BDevAv = dataAv{3};
  316. BStdAv = dataAv{4};
  317. ADevGrAv = dataGrAv{1};
  318. AStdGrAv = dataGrAv{2};
  319. BDevGrAv = dataGrAv{3};
  320. BStdGrAv = dataGrAv{4};
  321. ADevSe = dataSe{1};
  322. AStdSe = dataSe{2};
  323. BDevSe = dataSe{3};
  324. BStdSe = dataSe{4};
  325. case 1
  326. ADevAv = dataAvHighOm{3};
  327. AStdAv = dataAvHighOm{4};
  328. BDevAv = dataAvLowOm{1};
  329. BStdAv = dataAvLowOm{2};
  330. ADevGrAv = dataGrAvHighOm{3};
  331. AStdGrAv = dataGrAvHighOm{4};
  332. BDevGrAv = dataGrAvLowOm{1};
  333. BStdGrAv = dataGrAvLowOm{2};
  334. ADevSe = dataSeHighOm{3};
  335. AStdSe = dataSeHighOm{4};
  336. BDevSe = dataSeLowOm{1};
  337. BStdSe = dataSeLowOm{2};
  338. end
  339. switch inclCtrl
  340. case {1,2}
  341. AAvCtrl = dataAvCtrl{1};
  342. BAvCtrl = dataAvCtrl{2};
  343. AGrAvCtrl = dataGrAvCtrl{1};
  344. BGrAvCtrl = dataGrAvCtrl{2};
  345. ASeCtrl = dataSeCtrl{1};
  346. BSeCtrl = dataSeCtrl{2};
  347. case 3
  348. AAvCtrl = dataAvCoLow{1};
  349. BAvCtrl = dataAvCoHigh{3};
  350. AGrAvCtrl = dataGrAvCoLow{1};
  351. BGrAvCtrl = dataGrAvCoHigh{3};
  352. % TEST (plots std only when activated)
  353. % AGrAvCtrl = dataGrAvCoLow{2};
  354. % BGrAvCtrl = dataGrAvCoHigh{4};
  355. ASeCtrl = dataSeCoLow{1};
  356. BSeCtrl = dataSeCoHigh{3};
  357. end
  358. % plot single channel
  359. for s = 1:2 % once for A, once for B
  360. % process timetrace
  361. switch cutTime
  362. case 0
  363. timeWin = floor([timetr(1),timetr(end)]); % data in this window will be plotted (relative to recording onset)
  364. timeStart = timeWin(1)-(stimDelay);
  365. timeEnd = timeWin(2)-(stimDelay);
  366. timeCut = (1:size(timetr,2));
  367. case {1,2}
  368. timeWin = [round((stimDelay)+timeStart+chirpPeak(s)*1000,4),...
  369. round((stimDelay)+timeEnd+chirpPeak(s)*1000,4)]; % data in this window will be plotted (relative to recording onset)
  370. timeCut = round(timeWin(1)/1000*fs:timeWin(2)/1000*fs+1); % "+1" to reach the proper length, otherwise the index will be 1 point too short since timetr starts at 0 ms
  371. end
  372. switch s
  373. case 1
  374. grAvStd = AStdGrAv;
  375. grAvDev = ADevGrAv;
  376. avStd = AStdAv;
  377. avDev = ADevAv;
  378. seStd = AStdSe;
  379. seDev = ADevSe;
  380. stimName = 'A';
  381. switch inclCtrl
  382. case {1,2,3}
  383. grAvCtrl = AGrAvCtrl;
  384. avCtrl = AAvCtrl;
  385. seCtrl = ASeCtrl;
  386. end
  387. case 2
  388. grAvStd = BStdGrAv;
  389. grAvDev = BDevGrAv;
  390. avStd = BStdAv;
  391. avDev = BDevAv;
  392. seStd = BStdSe;
  393. seDev = BDevSe;
  394. stimName = 'B';
  395. switch inclCtrl
  396. case {1,2,3}
  397. grAvCtrl = BGrAvCtrl;
  398. avCtrl = BAvCtrl;
  399. seCtrl = BSeCtrl;
  400. end
  401. end
  402. figure('NumberTitle','off','Name',[combName{c},'_',stimName],'Position',[0,0,1000,600])
  403. title([convertStringsToChars(combNameS(s,c)),'-Freq. Chirp'])
  404. switch avType
  405. case 1 % grand averages
  406. hold on
  407. switch inclCtrl
  408. case {1,2,3}
  409. switch plotDifI
  410. case 0 % plot control response only when difference curve is deactivated
  411. % plot standard error
  412. seHiCtrl = grAvCtrl(timeCut,filt)+seCtrl(timeCut,filt);
  413. seLoCtrl = grAvCtrl(timeCut,filt)-seCtrl(timeCut,filt);
  414. seX = [timetr(timeCut),fliplr(timetr(timeCut))];
  415. seY = [seHiCtrl',fliplr(seLoCtrl')];
  416. patch(seX,seY,colCtrl,'FaceAlpha',0.2,'EdgeColor','none')
  417. % plot data
  418. plotCtrl = plot(timetr(timeCut),grAvCtrl(timeCut,filt),'color',colCtrl,'Linewidth',2);
  419. end
  420. end
  421. % plot standard error
  422. seHiDev = grAvDev(timeCut,filt)+seDev(timeCut,filt);
  423. seLoDev = grAvDev(timeCut,filt)-seDev(timeCut,filt);
  424. seX = [timetr(timeCut),fliplr(timetr(timeCut))];
  425. seY = [seHiDev',fliplr(seLoDev')];
  426. patch(seX,seY,colDev,'FaceAlpha',0.2,'EdgeColor','none')
  427. % plot data
  428. plotDev = plot(timetr(timeCut),grAvDev(timeCut,filt),'color',colDev,'Linewidth',2);
  429. % plot standard error
  430. seHiStd = grAvStd(timeCut,filt)+seStd(timeCut,filt);
  431. seLoStd = grAvStd(timeCut,filt)-seStd(timeCut,filt);
  432. seX = [timetr(timeCut),fliplr(timetr(timeCut))];
  433. seY = [seHiStd',fliplr(seLoStd')];
  434. patch(seX,seY,colStd,'FaceAlpha',0.2,'EdgeColor','none')
  435. % plot data
  436. plotStd = plot(timetr(timeCut),grAvStd(timeCut,filt),'color',colStd,'Linewidth',2);
  437. xticks(timeWin(1):2:timeWin(2))
  438. set(gca,'XTickLabel',timeStart:2:timeEnd)
  439. switch clMark
  440. case 1 % plot bars respresenting clusters
  441. yDist = y_lim(2)-y_lim(1);
  442. yMin = y_lim(1)+yDist*0.05;
  443. yCl = [yMin+yDist*0.05;yMin+yDist*0.05;yMin+yDist*0.07;yMin+yDist*0.07];
  444. % count number of significant clusters in vector
  445. pSmpl = length(grAvStd);
  446. vecSigClIs = [0,reshape(vecSigClI(c,s,filt,:),1,pSmpl)]; % add 0 at start to make sure possible cluster starting at point 1 is considered
  447. vecSigClIe = [reshape(vecSigClI(c,s,filt,:),1,pSmpl),0]; % add 0 at the end to make sure possible cluster lasting until the end is considered
  448. startSigCl = find(diff(vecSigClIs)==1); % find all points where difference vector is 1 (starting points of clusters in original vector)
  449. endSigCl = find(diff(vecSigClIe)==-1); % find all points where difference vector is -1 (ending points of clusters in original vector)
  450. nCl = numel(startSigCl); % return number of cluster starting points = number of clusters
  451. xCl = zeros(4,nCl);
  452. for cl = 1:nCl
  453. xCl(:,cl) = ([startSigCl(cl);endSigCl(cl);endSigCl(cl);startSigCl(cl)])./fs*1000;
  454. patch('XData',xCl(:,cl),'YData',yCl,'EdgeColor','Black','EdgeAlpha',1,'FaceColor','Black','FaceAlpha',1)
  455. end
  456. end
  457. xlabel('Time [ms]','FontWeight','bold','FontSize',20)
  458. ylabel(yLabelName,'FontWeight','bold','FontSize',20)
  459. switch inclCtrl
  460. case 0
  461. legend([plotDev,plotStd],nameDev,nameStd,'Location','northwest','AutoUpdate','off')
  462. case {1,2,3}
  463. switch plotDifI
  464. case 0
  465. legend([plotDev,plotStd,plotCtrl],nameDev,nameStd,nameCtrl,'Location','northwest','AutoUpdate','off')
  466. case 1
  467. legend([plotDev,plotStd],nameDev,nameStd,'Location','northwest','AutoUpdate','off')
  468. end
  469. end
  470. set(gca,'FontSize',20,'Linewidth',2,'FontName','Arial')
  471. switch plotStatsI
  472. case 1
  473. x_min = timetr(winAll{s}(:,1));
  474. x_max = timetr(winAll{s}(:,2));
  475. x = [x_min;x_max;x_max;x_min];
  476. switch fixedY
  477. case 0
  478. y_limAuto = ylim;
  479. yMin = y_limAuto(1);
  480. y_max = y_limAuto(2);
  481. case 1
  482. yMin = y_lim(1);
  483. y_max = y_lim(2);
  484. end
  485. y_temp = [yMin;yMin;y_max;y_max];
  486. y = repmat(y_temp,1,uWin(end));
  487. for w = uWin
  488. switch inclCtrl
  489. case 0
  490. pVTemp = pV(c,s,filt,w);
  491. % pVTemp
  492. % statsV{c,s,filt,w}
  493. % cohensD_V(c,s,filt,w,1)
  494. case {1,2,3}
  495. switch statsType
  496. case 1 % use t-test statistics
  497. pVTemp = pV(c,s,filt,w);
  498. case 2 % use ANOVA statistics
  499. pVTemp = multcompV{c,s,filt,w}.pValue(1); % extract pValue for comparison between dev and std condition
  500. % pVTemp
  501. % statsV{c,s,filt,w}
  502. % cohensD_V(c,s,filt,w,1)
  503. end
  504. end
  505. if pVTemp<0.05
  506. sigWin = patch('XData',x(:,w),'YData',y(:,w),'EdgeColor','black','EdgeAlpha',1,'FaceColor','black','FaceAlpha',.2,'Linewidth',2);
  507. else
  508. sigWin = patch('XData',x(:,w),'YData',y(:,w),'EdgeColor','black','EdgeAlpha',1,'FaceColor','none','Linewidth',2);
  509. end
  510. uistack(sigWin,'bottom')
  511. end
  512. end
  513. xlim([timeWin(1),timeWin(2)])
  514. if fixedY==1
  515. ylim(y_lim)
  516. end
  517. case 2 % individual averages
  518. for f = 1:nFiles
  519. figure ('NumberTitle','off','Name',[combName{c},'_',stimName,'_',convertStringsToChars(recID(f))],'Position',[0,0,1000,500])
  520. hold on
  521. switch inclCtrl
  522. case {1,2,3}
  523. switch plotDifI
  524. case 0 % plot control response only when difference curve is deactivated
  525. plotCtrl = plot(timetr(timeCut),avCtrl(timeCut,f,filt),'color',colCtrl,'Linewidth',2);
  526. end
  527. end
  528. plotStd = plot(timetr(timeCut),avStd(timeCut,f,filt),'color',colStd,'Linewidth',2);
  529. plotDev = plot(timetr(timeCut),avDev(timeCut,f,filt),'color',colDev,'Linewidth',2);
  530. xticks(timeWin(1):5:timeWin(2))
  531. set(gca,'XTickLabel',timeStart:5:timeEnd)
  532. switch clMark
  533. case 1 % plot bar
  534. yDist = y_lim(2)-y_lim(1);
  535. yMin = y_lim(1)+yDist*0.05;
  536. x_stim = [stimWin(1);stimWin(2);stimWin(2);stimWin(1)];
  537. yCl = [yMin+yDist*0.05;yMin+yDist*0.05;yMin+yDist*0.07;yMin+yDist*0.07];
  538. patch('XData',x_stim,'YData',yCl,'EdgeColor','Black','EdgeAlpha',1,'FaceColor','Black','FaceAlpha',1)
  539. end
  540. xlabel('Time [ms]','FontWeight','bold','FontSize',20)
  541. ylabel(yLabelName,'FontWeight','bold','FontSize',20)
  542. set(gca,'FontSize',20,'Linewidth',2,'FontName','Arial')
  543. xlim([timeWin(1),timeWin(2)])
  544. if fixedY==1
  545. ylim(y_lim)
  546. end
  547. switch plotStatsI
  548. case 1
  549. x_min = timetr(winAll{s}(:,1)+blcEnd(s)*fs(1));
  550. x_max = timetr(winAll{s}(:,2)+blcEnd(s)*fs(1));
  551. x = [x_min;x_max;x_max;x_min];
  552. switch fixedY
  553. case 0
  554. y_limAuto = ylim;
  555. yMin = y_limAuto(1);
  556. y_max = y_limAuto(2);
  557. case 1
  558. yMin = y_lim(1);
  559. y_max = y_lim(2);
  560. end
  561. y_temp = [yMin;yMin;y_max;y_max];
  562. y = repmat(y_temp,1,uWin(end));
  563. for w = uWin
  564. sigWin = patch('XData',x(:,w),'YData',y(:,w),'EdgeColor','black','EdgeAlpha',1,'FaceColor','none','Linewidth',2);
  565. uistack(sigWin,'bottom')
  566. txt = {['Dev: ',num2str(varS{c}(f,s,1,filt,w))],['Std: ',num2str(varS{c}(f,s,2,filt,w))]};
  567. text(x(1,w)-x(1,w)*0.2,y(3,w)-y(3,w)*0.2,txt,'FontSize',20,'Linewidth',2,'FontName','Arial')
  568. end
  569. end
  570. end
  571. end
  572. % xline(((pts2begin_cell{1}(1)/fs(1)))*1000,'Linewidth',2)
  573. % xline((chirpPeak(s)+(pts2begin_cell{1}(1)/fs(1)))*1000,'Linewidth',2) % mark blc end
  574. if saveI==1
  575. saveas(gcf,[combName{c},'_',stimName,'_',filtName,'_cutTime',num2str(cutTime),'_ctrl',num2str(inclCtrl),'_uWin',num2str(uWin),'_varType',num2str(varType),'_repRate',['_',repRate],'_subStd',['_',subStd],'.jpg'])
  576. saveas(gcf,[combName{c},'_',stimName,'_',filtName,'_cutTime',num2str(cutTime),'_ctrl',num2str(inclCtrl),'_uWin',num2str(uWin),'_varType',num2str(varType),'_repRate',['_',repRate],'_subStd',['_',subStd],'.svg'])
  577. saveas(gcf,[combName{c},'_',stimName,'_',filtName,'_cutTime',num2str(cutTime),'_ctrl',num2str(inclCtrl),'_uWin',num2str(uWin),'_varType',num2str(varType),'_repRate',['_',repRate],'_subStd',['_',subStd],'.fig'])
  578. end
  579. end
  580. end
  581. end
  582. %% plotting: boxplots
  583. switch varType
  584. case 1
  585. titleBp = 'ABR Amplitude';
  586. yLabelNameBp = 'ABR p-p Amp. [µV]';
  587. % yLabelNameBp = yLabelName;
  588. case 2
  589. titleBp = 'Peak V Latency';
  590. yLabelNameBp = 'Peak V Latency [ms]';
  591. end
  592. if plotBpI==1
  593. switch inclCtrl
  594. case 0
  595. xDev = [1,4,7,10,13];
  596. xStd = [2,5,8,11,14];
  597. sig_groups = {[1,2],[4,5],[7,8],[10,11],[13,14]};
  598. case {1,2,3}
  599. xDev = [1,5,9,13,17];
  600. xStd = [2,6,10,14,18];
  601. xCtrl = [3,7,11,15,19];
  602. sig_groups1 = {[1,2],[5,6],[9,10],[13,14],[17,18]}; % dev vs. std
  603. sig_groups2 = {[1,3],[5,7],[9,11],[13,15],[17,19]}; % dev vs. ctrl
  604. sig_groups3 = {[2,3],[6,7],[10,11],[14,15],[18,19]}; % std vs. ctrl
  605. end
  606. for c = cStart:nComb % run once for each stimulus combination
  607. for s = 1:2 % once for A, once for B
  608. switch s
  609. case 1
  610. stimName = 'A';
  611. case 2
  612. stimName = 'B';
  613. end
  614. rmsMin = floor(min(varS{c}(:,s,:,filt,:),[],'all')); % identify minimum RMS value for y-limit
  615. rmsMax = ceil(max(varS{c}(:,s,:,filt,:),[],'all')); % identify maximum RMS value for y-limit
  616. figure('NumberTitle','off','Name',['Boxpl_',combName{c},'_',stimName],'Position',[0,0,boxpFigWi,400])
  617. % title(titleBp)
  618. ylim([rmsMin-0.5,rmsMax+1]) % doesn't set the actual y-lim, is just required to get an equal distance between lines and asterisks of sigstar. Sigstar sets the actual y-lim itself
  619. for w = uWin
  620. hold on
  621. boxDev = boxchart(xDev(w)*ones(size(varS{c}(:,s,1,filt,w))),varS{c}(:,s,1,filt,w),'BoxFaceColor',colDev,'MarkerColor',colDev,'Linewidth',2);
  622. boxStd = boxchart(xStd(w)*ones(size(varS{c}(:,s,2,filt,w))),varS{c}(:,s,2,filt,w),'BoxFaceColor',colStd,'MarkerColor',colStd,'Linewidth',2);
  623. varSdif = mean(varS{c}(:,s,2,filt,w)-varS{c}(:,s,1,filt,w))
  624. varSdifStdd = std(varS{c}(:,s,2,filt,w)-varS{c}(:,s,1,filt,w))
  625. switch inclCtrl
  626. case 0
  627. H = sigstar(sig_groups{w},pV(c,s,filt,w),cohensD_V(c,s,filt,w,1));
  628. case {1,2,3}
  629. boxCtrl = boxchart(xCtrl(w)*ones(size(varS{c}(:,s,3,filt,w))),varS{c}(:,s,3,filt,w),'BoxFaceColor',colCtrl,'MarkerColor',colCtrl,'Linewidth',2);
  630. switch statsType
  631. case 1
  632. H = sigstar(sig_groups1{w},pV(c,s,filt,w),cohensD_V(c,s,filt,w,1));
  633. case 2
  634. pVTemp = multcompV{c,s,filt,w}.pValue([1,2,4]);
  635. eS = zeros(3,1);
  636. for cmp = 1:3
  637. eS(cmp) = cohensD_V(c,s,filt,w,cmp);
  638. end
  639. H = sigstar({sig_groups1{w},sig_groups2{w},sig_groups3{w}},pVTemp,eS);
  640. end
  641. end
  642. set(H(:,2),'FontSize',25,'FontName','Arial')
  643. end
  644. switch inclCtrl
  645. case 0
  646. xlim([xDev(uWin(1))-1,xStd(uWin(end))+1])
  647. xticks((xDev(uWin)+xStd(uWin))/2)
  648. % legend([boxDev,boxStd],nameDev,nameStd,'Location','northwest','AutoUpdate','off')
  649. case {1,2,3}
  650. xlim([xDev(uWin(1))-1,xCtrl(uWin(end))+1])
  651. xticks(xStd(uWin))
  652. % legend([boxDev,boxStd,boxCtrl],nameDev,nameStd,nameCtrl,'Location','northwest','AutoUpdate','off')
  653. end
  654. ylabel(yLabelNameBp,'FontWeight','bold','FontSize',20)
  655. % xticklabels(winTxt(uWin))
  656. xticks([])
  657. set(gca,'FontSize',25,'Linewidth',2,'FontName','Arial')
  658. if saveI==1
  659. saveas(gcf,['Boxp_',combName{c},'_',stimName,'_',filtName,'_cutTime',num2str(cutTime),'_ctrl',num2str(inclCtrl),'_uWin','_varType',num2str(varType),'_uWin',num2str(uWin),'_repRate',['_',repRate],'_subStd',['_',subStd],'.jpg'])
  660. saveas(gcf,['Boxp_',combName{c},'_',stimName,'_',filtName,'_cutTime',num2str(cutTime),'_ctrl',num2str(inclCtrl),'_uWin','_varType',num2str(varType),'_uWin',num2str(uWin),'_repRate',['_',repRate],'_subStd',['_',subStd],'.svg'])
  661. saveas(gcf,['Boxp_',combName{c},'_',stimName,'_',filtName,'_cutTime',num2str(cutTime),'_ctrl',num2str(inclCtrl),'_uWin','_varType',num2str(varType),'_uWin',num2str(uWin),'_repRate',['_',repRate],'_subStd',['_',subStd],'.fig'])
  662. end
  663. end
  664. end
  665. end
  666. %% consecutive stds
  667. if plotCsValI==1
  668. for c = 1:nComb % once for each stimulus combination
  669. for s = 1:2 % once for A, once for B
  670. switch s
  671. case 1
  672. stimName = 'A'; % ConS starts with B (High), since B is std in oddball block 1
  673. case 2
  674. stimName = 'B';
  675. end
  676. switch varType
  677. case 1
  678. varMax = max(abs(varAvCsS{c}(s,filt,uWin,:)));
  679. varPlot = reshape(varAvCsS{c}(s,filt,uWin,:),1,nConS)/varMax; % plot amplitude variable
  680. sePlot = reshape(varSeCsS{c}(s,filt,uWin,:),1,nConS);
  681. case 2
  682. varMax = max(abs(timAvCsS{c}(s,filt,uWin,:)));
  683. varPlot = reshape(timAvCsS{c}(s,filt,uWin,:),1,nConS)/varMax; % plot timing variable
  684. sePlot = reshape(timSeCsS{c}(s,filt,uWin,:),1,nConS);
  685. end
  686. figure('NumberTitle','off','Name',[combName{c},'_',stimName],'Position',[0,0,1000,600])
  687. hold on
  688. title([convertStringsToChars(combNameS(s,c)),'-Freq. Chirp'])
  689. errConSV = errorbar(varPlot,sePlot,'k','LineStyle','none','Marker','.','MarkerSize',30,'Linewidth',2);
  690. % plotConSV = plot(varPlot,'k','LineStyle','none','Marker','.','MarkerSize',30,'Linewidth',2);
  691. end
  692. end
  693. end
  694. if plotCsResI==1
  695. for c = 1:nComb % once for each stimulus combination
  696. pSmpl = size(conSGrAv{c},1);
  697. fs = fs_cell{c};
  698. timetrConS = (0:nConS*pSmpl-1)/fs(1); % time trace of one trial
  699. filenames = filenames_stim_cell{c};
  700. recID = recID_cell{c};
  701. bsPos = cell2mat(strfind(filenames,'\')); % find positions of back slashes in filename
  702. % bsPos = strfind(filenames,'\'); % find positions of back slashes in filename
  703. startPos = bsPos(:,end); % use last back slash position as starting point
  704. filenames = extractAfter(filenames,startPos);
  705. nFiles = nFiles_cell{c};
  706. for s = 1:2 % once for A, once for B
  707. switch s
  708. case 1
  709. stimName = 'A'; % ConS starts with B (High), since B is std in oddball block 1
  710. case 2
  711. stimName = 'B';
  712. end
  713. conSPlot = zeros(pSmpl*nConS,1);
  714. switch avType
  715. case 1 % grand average
  716. for cs = 1:nConS
  717. conSPlot(1+pSmpl*(cs-1):pSmpl*cs) = conSGrAv{c}(:,s,cs,filt);
  718. % figure
  719. % plot(conSGrAv{c}(:,s,cs,filt),'k','Linewidth',2)
  720. end
  721. figure('NumberTitle','off','Name',[combName{c},'_',stimName],'Position',[0,0,1000,600])
  722. title([convertStringsToChars(combNameS(s,c)),'-Freq. Chirp'])
  723. hold on
  724. plotConS = plot(timetrConS,conSPlot,'k','Linewidth',2);
  725. switch plotStatsI
  726. case {1,2}
  727. for cn = 1:nConS
  728. x_min = timetrConS(winAll{s}(:,1)+round(blcEnd(s)*fs(1)+pSmpl*(cn-1)+1));
  729. x_max = timetrConS(winAll{s}(:,2)+round(blcEnd(s)*fs(1)+pSmpl*(cn-1)+1));
  730. x = [x_min;x_max;x_max;x_min];
  731. switch fixedY
  732. case 0
  733. y_limAuto = ylim;
  734. y_min = y_limAuto(1);
  735. y_max = y_limAuto(2);
  736. case 1
  737. y_min = y_lim(1);
  738. y_max = y_lim(2);
  739. end
  740. y_temp = [y_min;y_min;y_max;y_max];
  741. y = repmat(y_temp,1,uWin(end));
  742. for w = uWin
  743. sigWin = patch('XData',x(:,w),'YData',y(:,w),'EdgeColor','red','EdgeAlpha',1,'FaceColor','none','Linewidth',2,'LineStyle','--');
  744. uistack(sigWin,'bottom')
  745. end
  746. end
  747. end
  748. case 2 % individual average
  749. for f = 1:nFiles
  750. for cs = 1:nConS
  751. conSPlot(1+pSmpl*(cs-1):pSmpl*cs) = conSAv{c}(:,s,f,cs,filt);
  752. end
  753. figure('NumberTitle','off','Name',[combName{c},'_',stimName,'_',convertStringsToChars(filenames(f))],'Position',[0,0,1000,600])
  754. title([convertStringsToChars(combNameS(s,c)),'-Freq. Chirp'])
  755. hold on
  756. plotConS = plot(timetrConS,conSPlot,'k','Linewidth',2);
  757. switch plotStatsI
  758. case {1,2}
  759. for cn = 1:nConS
  760. x_min = timetrConS(winAll{s}(:,1)+round(blcEnd(s)*fs(1)+pSmpl*(cn-1)+1));
  761. x_max = timetrConS(winAll{s}(:,2)+round(blcEnd(s)*fs(1)+pSmpl*(cn-1)+1));
  762. x = [x_min;x_max;x_max;x_min];
  763. switch fixedY
  764. case 0
  765. y_limAuto = ylim;
  766. y_min = y_limAuto(1);
  767. y_max = y_limAuto(2);
  768. case 1
  769. y_min = y_lim(1);
  770. y_max = y_lim(2);
  771. end
  772. y_temp = [y_min;y_min;y_max;y_max];
  773. y = repmat(y_temp,1,uWin(end));
  774. for w = uWin
  775. sigWin = patch('XData',x(:,w),'YData',y(:,w),'EdgeColor','red','EdgeAlpha',1,'FaceColor','none','Linewidth',2,'LineStyle','--');
  776. uistack(sigWin,'bottom')
  777. end
  778. end
  779. end
  780. end
  781. end
  782. end
  783. end
  784. end