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_PlottingConSCurve.m 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. %% define some variables
  2. % general parameters
  3. plotRespI = 0; % plot responses?
  4. plotVarI = 1; % plot variables?
  5. saveI = 0; % should the figures be saved? (0: no, 1: yes)
  6. fixedY = 0; % should the y-axis be fixed?
  7. y_lim = [-0.25,0.35]; % limits for fixed y-axis
  8. % analysis parameters
  9. modelTy = 1; % model type to be plotted (1: linear regression model, 2: flexible model)
  10. filt = 2; % filter (1: none, 2: 60 Hz, 3: 70 Hz)
  11. stPaPlot = [1,4]; % statistical parameters to be considered for plotting
  12. % cosmetics
  13. figWid = 1000; % width of figure window
  14. figHei = 600; % height of figure window
  15. winCol = [0.9290,0.6940,0.1250;0.4940,0.1840,0.5560]; % colors for analysis windows
  16. %% load and concatenate data
  17. % load and rename av data
  18. load("DD_avData_Oddball_25ms_SbD.mat")
  19. dataAv_25 = conSAv;
  20. dataGrAv_25 = conSGrAv;
  21. dataSe_25 = conSSe;
  22. load("DD_avData_Oddball_30ms_SbD.mat")
  23. dataAv_30 = conSAv;
  24. dataGrAv_30 = conSGrAv;
  25. dataSe_30 = conSSe;
  26. load("DD_avData_Oddball_50ms_SbD.mat")
  27. dataAv_50 = conSAv;
  28. dataGrAv_50 = conSGrAv;
  29. dataSe_50 = conSSe;
  30. % concatenate data
  31. dataAv = cat(1,dataAv_25,dataAv_30,dataAv_50);
  32. dataGrAv = cat(1,dataGrAv_25,dataGrAv_30,dataGrAv_50);
  33. dataSe = cat(1,dataSe_25,dataSe_30,dataSe_50);
  34. % load model data
  35. load('DD_ConSData.mat')
  36. %% do some additional calculations
  37. combNameS = split(combName,","); % split comb names at comma
  38. nStPa = numel(stPaPlot);
  39. nStims = 1; % 1: plots only low-freq. responses (remove line if both responses should be plotted)
  40. nStPa = 1; % 1: plots only P2P responses (remove line if both responses should be plotted)
  41. %% plot responses
  42. if plotRespI==1
  43. for r = 1:nRepRate % for each rep rate
  44. pSmpl = size(dataGrAv{r},1); % number of points per standard
  45. timeTr = (0:nConS*pSmpl-1)/fs(r); % time trace for the whole standard cluster
  46. for s = 1:nStims % for each stimulus (A and B)
  47. switch s
  48. case 1
  49. stimName = 'A';
  50. case 2
  51. stimName = 'B';
  52. end
  53. % concatenate standard responses
  54. dataPlot = zeros(pSmpl*nConS,1);
  55. for cs = 1:nConS
  56. dataPlot(1+pSmpl*(cs-1):pSmpl*cs) = dataGrAv{r}(:,s,cs,filt);
  57. end
  58. figure('NumberTitle','off','Name',['conSResp_',stimName,'_RepRate',num2str(r),'_Filt',num2str(filt)],'Position',[0,0,figWid,figHei])
  59. title([convertStringsToChars(combNameS(s)),'-Freq. Chirp'])
  60. hold on
  61. plotConS = plot(timeTr,dataPlot,'k','Linewidth',2);
  62. for cn = 1:nConS
  63. x_min = timeTr(winAll{r,s}(:,1)+round(pSmpl*(cn-1)+1));
  64. x_max = timeTr(winAll{r,s}(:,2)+round(pSmpl*(cn-1)+1));
  65. x = [x_min;x_max;x_max;x_min];
  66. switch fixedY
  67. case 0
  68. y_limAuto = ylim;
  69. y_min = y_limAuto(1);
  70. y_max = y_limAuto(2);
  71. case 1
  72. y_min = y_lim(1);
  73. y_max = y_lim(2);
  74. end
  75. y_temp = [y_min;y_min;y_max;y_max];
  76. y = repmat(y_temp,1,nWin);
  77. for w = 1:nWin
  78. sigWin = patch('XData',x(:,w),'YData',y(:,w),'EdgeColor',winCol(w,:),'EdgeAlpha',1,'FaceColor','none','Linewidth',2,'LineStyle','--');
  79. uistack(sigWin,'bottom')
  80. end
  81. end
  82. if fixedY==1
  83. ylim(y_lim)
  84. end
  85. set(gca,'FontSize',30,'Linewidth',2,'FontName','Arial')
  86. if saveI==1
  87. saveas(gcf,['conSResp_',stimName,'_RepRate',num2str(r),'_Filt',num2str(filt),'.jpg'])
  88. saveas(gcf,['conSResp_',stimName,'_RepRate',num2str(r),'_Filt',num2str(filt),'.svg'])
  89. end
  90. end
  91. end
  92. end
  93. %% plot response variables (with fitted curve)
  94. if plotVarI==1
  95. for r = 1:nRepRate % for each rep rate
  96. pSmpl = size(dataGrAv{r},1); % number of points per standard
  97. x = (0:nConS*pSmpl-1)/fs(r); % time trace for the whole standard cluster
  98. for s = 1:nStims % for each stimulus (A and B)
  99. switch s
  100. case 1
  101. stimName = 'A';
  102. case 2
  103. stimName = 'B';
  104. end
  105. for pa = 1:nStPa % for each stat param
  106. switch pa
  107. case 1 % P2P
  108. yLabelNameL = 'ABR p-p Amp. [µV]';
  109. yLabelNameR = 'Rel. ABR p-p Amp.';
  110. win = 1; % analysis window
  111. case 2 % latency
  112. yLabelNameL = 'Peak V Latency [ms]';
  113. yLabelNameR = 'Rel. Peak V Latency';
  114. win = 2; % analysis window
  115. end
  116. stPaAv = reshape(mean(stPa(:,r,s,:,filt,win,stPaPlot(pa)),1),nConS,1);
  117. varMax = max(stPaAv);
  118. figure('NumberTitle','off','Name',['conSVar_',stimName,'_RepRate',num2str(r),'_Filt',num2str(filt),'_Param',num2str(pa)],'Position',[0,0,figWid,figHei])
  119. hold on
  120. box on
  121. title([convertStringsToChars(combNameS(s)),'-Freq. Chirp'])
  122. % plot data points and create absolute and relative y axis
  123. yyaxis left % absolute
  124. set(gca,'YColor','k')
  125. plotVar = plot(stPaAv,'k','LineStyle','none','Marker','.','MarkerSize',30,'Linewidth',2); % plot datapoints
  126. % plot model
  127. switch modelTy
  128. case 1 % linear regression model
  129. plotMdl = plot(linFit{r,s,filt,win,stPaPlot(pa)}); % plot linear regression model
  130. % model adjustments
  131. plotMdl(1).Color = [0,0,0];
  132. plotMdl(2).Color = [0,0,0];
  133. plotMdl(3).Color = [0,0,0];
  134. plotMdl(4).Color = [0,0,0];
  135. % linFit{r,s,filt,win,stPaPlot(pa)} % print model variables
  136. case 2 % flexible model
  137. plotMdl = plot(flexFit{r,s,filt,win,stPaPlot(pa)},'k'); % plot flexible model
  138. % model adjustments
  139. plotMdl(1).Color = [0,0,0];
  140. plotMdl.LineStyle = "-";
  141. % flexFit{r,s,filt,win,stPaPlot(pa)}
  142. % flexGof{r,s,filt,win,stPaPlot(pa)}
  143. end
  144. % adjust ylim
  145. yLimL = ylim;
  146. yMinL = yLimL(1)-diff(yLimL)*0.1;
  147. yMaxL = yLimL(2)+diff(yLimL)*0.1;
  148. ylim([yMinL,yMaxL]);
  149. yLimL = ylim;
  150. ylabel(yLabelNameL,'FontWeight','bold','FontSize',30)
  151. yyaxis right % relative
  152. set(gca,'YColor','k')
  153. ylim(yLimL/stPaAv(1)) % relative to first standard of cluster
  154. yLimR = ylim;
  155. ylabel(yLabelNameR,'FontWeight','bold','FontSize',30)
  156. % cosmetics
  157. set(plotMdl,'Linewidth',2);
  158. xticks(1:1:nConS)
  159. xticklabels(1:1:nConS)
  160. xlim([0,nConS+1])
  161. xLim = xlim;
  162. % create text
  163. switch modelTy
  164. case 1
  165. p = round(linFit{r,s,filt,win,stPaPlot(pa)}.Coefficients.pValue(2),3);
  166. if p<0.001
  167. ast = '***';
  168. elseif p<0.01
  169. ast = '**';
  170. elseif p<0.05
  171. ast = '*';
  172. else
  173. ast = '';
  174. end
  175. Rs = round(linFit{r,s,filt,win,stPaPlot(pa)}.Rsquared.Ordinary,3);
  176. txt = ['\itp',ast,'\rm = ',num2str(p),', \itR^2\rm = ',num2str(Rs)];
  177. text((xLim(2)*0.4),yLimR(2)-diff(yLimR)*0.1,txt,'FontSize',30)
  178. legend([plotVar,plotMdl(2),plotMdl(3)],'Data','Lin. Reg. Model','95 % Conf. Int.','Location','northeast')
  179. case 2
  180. end
  181. xlabel("Number of Consecutive Std. after Dev.",'FontWeight','bold','FontSize',30)
  182. title([convertStringsToChars(combNameS(s)),'-Freq. Chirp'])
  183. set(gca,'FontSize',30,'Linewidth',2,'FontName','Arial')
  184. if saveI==1
  185. saveas(gcf,['conSVar_',stimName,'_RepRate',num2str(r),'_Filt',num2str(filt),'.jpg'])
  186. saveas(gcf,['conSVar_',stimName,'_RepRate',num2str(r),'_Filt',num2str(filt),'.svg'])
  187. end
  188. end
  189. end
  190. end
  191. end
  192. bla = 1;