123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- %% define some variables
- filt = 6; % 1: non, 2: 0.1 Hz, 3: 10 Hz, 4: 40 Hz, 5: 45 Hz, 6: 50 Hz
- cutTime = 1; % plot only certain time window? (0: no, 1: short, 2: long)
- avType = 1; % plot grand average (1) or individual averages (2)
- repRateI = 2; % which rep rate to plot (1: 25 ms, 2: 50 ms)
- fixedY = 1; % use dynamic (0) or fixed (1) y-axis?
- plotSpecI = 0; % plot spectrogram of the stimulus?
- plotOsciI = 0; % plot oscillogram of the stimulus?
- plotRespI = 1; % plot responses?
- saveI = 1; % save figure?
- chirpPeak = [0.00648,0.00842];
- %% load processed data
- switch repRateI
- case 1
- load('RS_avData_25ms.mat') % load data
- case 2
- load('RS_avData_50ms.mat') % load data
- end
- col = 'k';
- %% do some additional calculations
- % define y-label name
- switch zsNormI
- case 0
- ylabelName = 'Voltage [µV]';
- case 1
- ylabelName = 'z-norm. voltage [a.u.]';
- end
- % define x-Axis
- switch cutTime
- case 0
- xtickSteps = 100; % ms-steps on x-axis that should be plotted
- case 1
- xtickSteps = 5; % ms-steps on x-axis that should be plotted
- switch filt
- case {1,2,3}
- timeStart = -3; % starting time of the plot (relative to stim onset)
- timeEnd = 10; % ending time of the plot (relative to stim onset)
- case {4,5,6}
- timeStart = -3; % starting time of the plot (relative to stim onset)
- timeEnd = 12; % ending time of the plot (relative to stim onset)
- end
- case 2
- xtickSteps = 50; % ms-steps on x-axis that should be plotted
- timeStart = 0; % starting time of the plot (relative to stim onset)
- timeEnd = 350; % ending time of the plot (relative to stim onset)
- end
- % define some names
- combNameS = split(combName,","); % split comb names at comma
- if filt==1
- filtName = 'noF';
- else
- filtName = num2str(lowc(filt-1));
- end
- % define y-axis depending on filter setting and plotted time frame
- switch filt
- case 1
- switch cutTime
- case 0
- y_lim = [-0.8,1];
- case 1
- y_lim = [-0.8,1];
- case 2
- y_lim = [-0.8,1];
- end
- case 2
- switch cutTime
- case 0
- y_lim = [-0.8,1];
- case 1
- y_lim = [-0.8,1];
- case 2
- y_lim = [-0.8,1];
- end
- case 3
- switch cutTime
- case 0
- y_lim = [-0.9,1];
- case 1
- y_lim = [-0.3,0.55];
- case 2
- y_lim = [-0.9,1];
- end
- case 4
- switch cutTime
- case 0
- y_lim = [-0.9,1];
- case 1
- y_lim = [-0.3,0.55];
- case 2
- y_lim = [-0.9,1];
- end
- case 5
- switch cutTime
- case 0
- y_lim = [-0.9,1];
- case 1
- y_lim = [-0.3,0.55];
- case 2
- y_lim = [-0.9,1];
- end
- case 6
- switch cutTime
- case 0
- y_lim = [-1,1];
- case 1
- y_lim = [-0.35,0.5];
- case 2
- y_lim = [-0.9,1];
- end
- end
- % do some prior calculations for colormap
- rgb1 = [ones(1,100),ones(1,100),(1:-0.01:0.01)]';
- rgb2 = [ones(1,100),(1:-0.01:0.01),zeros(1,100)]';
- rgb3 = [(1:-0.01:0.01),zeros(1,100),zeros(1,100)]';
- cMap = [rgb1,rgb2,rgb3];
- % do some prior calculations for tiled plots
- yMax = 11; % y-axis maximum in kHz for spectrogram
- % number of rows and colums of the tiled figure
- nCol = 2;
- nRow = 0; % depending on what is plotted, number of rows will change
- % add rows depending on what is plotted
- if plotOsciI==1
- nRow = nRow+1;
- end
- if plotSpecI==1
- nRow = nRow+1;
- end
- if plotRespI==1
- nRow = nRow+1;
- end
- %% plotting: stimuli and responses
- for f = 1:2 % once for each figure (block-stim and o1st-stim)
- % figure('NumberTitle','off','Name',[num2str(f),'_',SOAName,],'Position',[0,0,800,1300])
- figure('NumberTitle','off','Name',[num2str(f),'_',SOAName,],'Position',[0,0,1600,800])
- set(gca,'FontSize',20,'Linewidth',2,'FontName','Arial')
- t = tiledlayout(nRow,nCol);
- tileCount = 0; % counter of plotted tiles, important for later
- switch f
- case 1
- nComb = (1:2);
- case 2
- nComb = (3:4);
- end
- for s = 1:2 % run once for each stimulus combination
- c = (f-1)*2+s;
- % extract data corresponding to current stimulation-condition from
- % cell-arrays
- dataAv = dataAv_cell{c};
- dataGrAv = dataGrAv_cell{c};
- dataSe = dataSe_cell{c};
- filenames = filenames_stim_cell{c};
- recID = recID_cell{c};
- bsPos = cell2mat(strfind(filenames,'\')); % find positions of back slashes in filename
- startPos = bsPos(:,end); % use last back slash position as starting point
- filenames = extractAfter(filenames,startPos);
- timetr = round(timetrUnit_cell{c}*1000,4);
- stimDur = stimDur_cell{c}(1)*1000;
- stimDelay = stimDelay_cell{c}(1)*1000;
- stimWin = [stimDelay,stimDelay+stimDur];
- nFiles = nFiles_cell{c};
- fs_stim = fs_stim_cell{c};
- fs = fs_cell{c};
- stimCat = stimCat_cell{c};
- pts2begin = pts2begin_cell{c};
- % process timetrace
- switch cutTime
- case 0
- timeWin = floor([timetr(1),timetr(end)]); % data in this window will be plotted (relative to recording onset)
- timeStart = timeWin(1)-(stimDelay);
- timeEnd = timeWin(2)-(stimDelay);
- timeCut = (1:size(timetr,2));
- case {1,2}
- timeWin = [round((stimDelay)+timeStart+chirpPeak(s)*1000,4),...
- round((stimDelay)+timeEnd+chirpPeak(s)*1000,4)]; % data in this window will be plotted (relative to recording onset)
- 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
- end
- nexttile(s)
- % spectrogram
- if plotSpecI==1
- spectrogram(stimCat,56,52,[],fs_stim,'yaxis',"MinThreshold",-75)
- colormap(cMap)
- xLimAuto = xlim;
- xlim([xLimAuto(1),timeEnd])
- xticks(0:xtickSteps:timeEnd)
- ylim([0,yMax])
- colorbar('off')
- if s==1||s==3||s==6
- ylabel('Frequency [kHz]','FontWeight','bold')
- else
- ylabel([])
- end
- xlabel([])
- box on
- set(gca,'FontSize',20,'Linewidth',2,'FontName','Arial')
- tileCount = tileCount+1;
- end
- hold on
- title(combNameS(s))
- switch nRow
- case 2
- switch tileCount
- case {1,3}
- nexttile(s+nCol) % open new tile
- end
- case 3
- switch tileCount
- case {1,4}
- nexttile(s+nCol) % open new tile
- end
- end
- % oscillogram
- if plotOsciI==1
- box on
- xs = (0:length(stimCat)-1)/fs_stim*1000;
- plot(xs,stimCat,'k','Linewidth',2)
- xlim([0,timeEnd])
- xticks(0:xtickSteps:timeEnd)
- if s==1||s==3||s==nCol+1
- ylabel('SPL [a.u.]','FontWeight','bold')
- end
- set(gca,'FontSize',20,'Linewidth',2,'FontName','Arial')
- tileCount = tileCount+1;
- end
- switch nRow
- case 2
- switch tileCount
- case {1,3}
- nexttile(s+nCol) % open new tile
- end
- case 3
- switch tileCount
- case {1,4}
- nexttile(s+nCol) % open new tile
- case {2,5}
- nexttile(s+nCol+2) % open new tile
- end
- end
- % responses
- if plotRespI==1
- hold on
- box on
- % plot standard error
- seHiCtrl = dataGrAv(timeCut,filt)+dataSe(timeCut,filt);
- seLoCtrl = dataGrAv(timeCut,filt)-dataSe(timeCut,filt);
- seX = [timetr(timeCut),fliplr(timetr(timeCut))];
- seY = [seHiCtrl',fliplr(seLoCtrl')];
- patch(seX,seY,col,'FaceAlpha',0.2,'EdgeColor','none')
- % plot data
- plotGrAv = plot(timetr(timeCut),dataGrAv(timeCut,filt),col,'Linewidth',2);
- xticks(timeWin(1):xtickSteps:timeWin(2))
- set(gca,'XTickLabel',timeStart:xtickSteps:timeEnd)
- xlabel('Time [ms]','FontWeight','bold','FontSize',20)
- if s==1||s==3||s==nCol+1
- ylabel(ylabelName,'FontWeight','bold','FontSize',20)
- end
- set(gca,'FontSize',20,'Linewidth',2,'FontName','Arial')
- switch fixedY
- case 0
- y_limAuto = ylim;
- y_min = y_limAuto(1);
- y_max = y_limAuto(2);
- case 1
- y_min = y_lim(1);
- y_max = y_lim(2);
- ylim(y_lim)
- end
- xlim([timeWin(1),timeWin(2)])
- % if plotStatsI==1
- % y_temp = [y_min;y_min;y_max;y_max];
- % y = repmat(y_temp,1,uWin(end));
- % for r = startResp:nResp
- % for w = uWin
- % switch daSe
- % case {1,2,3}
- % switch plotDaSeI
- % case 1
- % statsV = pV(c,filt,r,w);
- % markWin = patch('XData',x(1,w,:),'YData',y(:,w),'EdgeColor','black','EdgeAlpha',1,'FaceColor','none','Linewidth',2,'LineStyle','--'); % window for first response, to indicate area all other responses were compared to
- % uistack(markWin,'bottom')
- % case 2
- % statsV = multcompV{c,filt,w}.pValue(2);
- % end
- % case 4 % comparison between 1st and second ABR (16 ms del)
- % statsV = pV(c,filt);
- % markWin = patch('XData',x(r,4,:),'YData',y(:,4),'EdgeColor','black','EdgeAlpha',1,'FaceColor','none','Linewidth',2,'LineStyle','--'); % window for first response, to indicate area 2nd responses was compared to
- % uistack(markWin,'bottom')
- % end
- % if statsV<0.05
- % sigWin = patch('XData',x(r,w,:),'YData',y(:,w),'EdgeColor','black','EdgeAlpha',1,'FaceColor','black','FaceAlpha',.2,'Linewidth',2);
- % else
- % sigWin = patch('XData',x(r,w,:),'YData',y(:,w),'EdgeColor','black','EdgeAlpha',1,'FaceColor','none','Linewidth',2);
- % end
- % uistack(sigWin,'bottom')
- % end
- % end
- % end
- tileCount = tileCount+1;
- end
- xticks(timeWin(1):3:timeWin(2))
- set(gca,'XTickLabel',timeStart:3:timeEnd)
- end
- if saveI==1
- saveas(gcf,[num2str(f),'_',filtName,'_',SOAName,'_cutTime',num2str(cutTime),'_to',num2str(timeEnd),'.jpg'])
- saveas(gcf,[num2str(f),'_',filtName,'_',SOAName,'_cutTime',num2str(cutTime),'_to',num2str(timeEnd),'.svg'])
- saveas(gcf,[num2str(f),'_',filtName,'_',SOAName,'_cutTime',num2str(cutTime),'_to',num2str(timeEnd),'.fig'])
- end
- end
- bla = 1;
|