Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

DD_Plotting.m 42 KB

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