function plotCurve(wh,plotJob) %PLOTCURVE Summary of this function goes here % Detailed explanation goes here fig = findall(groot, 'Type', 'figure', 'Name', plotJob.figName); if isvalid(fig) figure(fig) fig = get(fig); AxesMain = fig.CurrentAxes; hold on else fig = figure('name',char(plotJob.figName)); AxesMain = gca; hold on end col = plotJob.color; % we want to fetch all realizations if plotJob.pmd == 0 realization = 499; % realization = 0:7; else realization = wh.parameter.realization.values(1:end); end realization = wh.parameter.realization.values(1:end); % get all xAxis values xAxis = wh.parameter.p_out.values; % Fetch Data from Warehouse for xl = 1:numel(xAxis) p_out = xAxis(xl); if string(plotJob.dataStatArg) == "Worst" temp = wh.getStoValue('ber',plotJob.l,plotJob.d,plotJob.sgm,string(plotJob.pol),plotJob.p_in,p_out,plotJob.pmd,plotJob.gamma,realization,plotJob.ch,1310,plotJob.channelspacing,plotJob.randzdw); temp = removeZeros(temp); ber(xl) = max(temp,[],'all'); linew = 1.0; markersz = 3; linestyle = '-'; elseif string(plotJob.dataStatArg) == "AVG" temp = wh.getStoValue('ber',plotJob.l,plotJob.d,plotJob.sgm,string(plotJob.pol),plotJob.p_in,p_out,plotJob.pmd,plotJob.gamma,realization,plotJob.ch,1310,plotJob.channelspacing,plotJob.randzdw); temp = removeZeros(temp); ber(xl) = mean(temp,'all'); linew = 1.0; markersz = 3; linestyle = '--'; elseif string(plotJob.dataStatArg) == "Best" temp = wh.getStoValue('ber',plotJob.l,plotJob.d,plotJob.sgm,string(plotJob.pol),plotJob.p_in,p_out,plotJob.pmd,plotJob.gamma,realization,plotJob.ch,1310,plotJob.channelspacing,plotJob.randzdw); temp = removeZeros(temp); ber(xl) = min(temp,[],'all'); linew = 1.0; markersz = 3; linestyle = '-'; elseif string(plotJob.dataStatArg) == "All Channels; mean(PMD Realizations)" temp = wh.getStoValue('ber',plotJob.l,plotJob.d,plotJob.sgm,string(plotJob.pol),plotJob.p_in,p_out,plotJob.pmd,plotJob.gamma,realization,plotJob.ch,1310,plotJob.channelspacing,plotJob.randzdw); temp = removeZeros(temp); ber(:,xl) = mean(temp,1,"omitnan").'; linew = 1; markersz = 1; linestyle = '-'; elseif string(plotJob.dataStatArg) == "Lineplot with quartiles" temp = wh.getStoValue('ber',plotJob.l,plotJob.d,plotJob.sgm,string(plotJob.pol),plotJob.p_in,p_out,plotJob.pmd,plotJob.gamma,realization,plotJob.ch,1310,plotJob.channelspacing,plotJob.randzdw); temp = removeZeros(temp); ber(xl) = mean(temp,"all","omitnan").'; upperq(xl) = quantile(temp,0.99,"all"); lowerq(xl) = quantile(temp,0.04,"all"); if lowerq(xl) == 0 lowerq(xl) = lowerq(xl-1); end % upperq(xl) = 0.5*std(tmp,1,'all','omitnan'); % lowerq(xl) = 0.5*std(tmp,1,'all','omitnan'); % upperq(xl) = max(dataNoNans); % lowerq(xl) = min(dataNoNans); % upperq(xl) = mean(tmp,"all","omitnan") + 1.96 * (std(tmp,1,'all','omitnan')/sqrt(numel(tmp))); % lowerq(xl) = mean(tmp,"all","omitnan") - 1.96 * (std(tmp,1,'all','omitnan')/sqrt(numel(tmp))); linew = 1; markersz = 1; linestyle = '-'; elseif string(plotJob.dataStatArg) == "All Channels ;All PMD Realizations" raw_fetch = wh.getStoValue('ber',plotJob.l,plotJob.d,plotJob.sgm,string(plotJob.pol),plotJob.p_in,p_out,plotJob.pmd,plotJob.gamma,realization,plotJob.ch,1310,plotJob.channelspacing,plotJob.randzdw).'; tmp = reshape(raw_fetch,[],1); ber(1:size(tmp,1),xl) = tmp; ber_per_chann(:,:,xl) = raw_fetch; linew = 0.3; markersz = 2; linestyle = ':'; end end %routine to remove total outliers (here those wehere the rop curve has a mean BER greater than 0.1) % ber_per_chann_clean = NaN(size(ber_per_chann)); % for ch = 1:size(ber_per_chann,1) % bla = squeeze(ber_per_chann(ch,:,:)); % ber_per_chann(ch,find(mean(bla,2)>0.25),:) = NaN; % cleaned = rmoutliers(bla,"mean",'ThresholdFactor',2); % % ber_per_chann_clean(ch,1:size(cleaned,1),1:size(cleaned,2)) = cleaned; % % end % % ber = []; % for rop = 1:size(ber_per_chann,3) % temp = squeeze(ber_per_chann_clean(:,:,rop)); % ber(rop) = mean(temp,"all","omitnan").'; % upperq(rop) = quantile(temp,0.9,"all"); % lowerq(rop) = quantile(temp,0.1,"all"); % end xAxis = xAxis; % Plot Data if string(plotJob.plotTypeArg) == "Scatter" for rlz = 1:size(ber,1) if rlz < size(ber,1) scatter(xAxis,ber(rlz,:),markersz,'MarkerEdgeColor',col,'MarkerFaceColor',col,'Parent', AxesMain(1),'HandleVisibility','off'); else scatter(xAxis,ber(rlz,:),markersz,'MarkerEdgeColor',col,'MarkerFaceColor',col,'Parent', AxesMain(1),'DisplayName',[plotJob.dataStatArg,' Ch.: ', plotJob.displayname]); end end elseif string(plotJob.plotTypeArg) == "Lines" % if ~anynan(ber) % [xAxis,ber] = interpCurve(xAxis, ber); % end for rlz = 1:size(ber,1) % if (string(plotJob.dataStatArg) == "All Channels ;All PMD Realizations")||(string(plotJob.dataStatArg) == "All Channels; mean(PMD Realizations)") ch = mod(rlz,plotJob.ch); if ch == 0; ch = plotJob.ch; end else ch = plotJob.dataStatArg; end if rlz < size(ber,1) s = plot(xAxis,ber(rlz,:),linestyle,'Marker',"none",'MarkerSize',markersz,'LineWidth',linew,'Color',col,'Parent', AxesMain,'HandleVisibility','off'); s.DataTipTemplate.Interpreter = "latex"; s.DataTipTemplate.DataTipRows(1).Label = "Ch: "; s.DataTipTemplate.DataTipRows(1).Value = repmat(ch,size(ber)); s.DataTipTemplate.DataTipRows(1); s.DataTipTemplate.DataTipRows(2) = []; else if string(plotJob.dataStatArg) == "Lineplot with quartiles" [hl,hp] = boundedline(xAxis,ber(rlz,:),([(ber(rlz,:)-lowerq(rlz,:));upperq(rlz,:)-ber(rlz,:)]'),'-o','alpha','Color',col,'transparency', 0.1,'linewidth',0.7); hl.MarkerFaceColor = col; hl.MarkerSize = 3; set(hp,'HandleVisibility','off'); %hp.LineWidth = 1.2; ho = outlinebounds(hl,hp); set(ho, 'linestyle', ':', 'color', col,'Linewidth',0.5); set(ho,'HandleVisibility','off'); else s = plot(xAxis,ber(rlz,:),linestyle,'Marker',"o",'MarkerFaceColor',col,'MarkerSize',markersz,'LineWidth',linew,'Color',col,'Parent', AxesMain,'DisplayName',[plotJob.displayname]); s.DataTipTemplate.Interpreter = "latex"; s.DataTipTemplate.DataTipRows(1).Label = "Ch: "; s.DataTipTemplate.DataTipRows(1).Value = repmat(string(ch),size(ber)); s.DataTipTemplate.DataTipRows(1) s.DataTipTemplate.DataTipRows(2) = []; end end end end % Draw FEC Threshold Line %get x data of first children: %get all linear Values if 0 linear = wh.getStoValue('ber',plotJob.l,plotJob.d,plotJob.sgm,string(plotJob.pol),plotJob.p_in,wh.parameter.p_out.values,0,0,499,"symmetric"); linear = mean(linear,2); lincurve = findall(AxesMain, 'Type', 'line','DisplayName','Linear Baseline'); % if isempty(lincurve) xdata = AxesMain.Children(1).XData; hdfec = 3.8e-3.*ones(size(xdata)); plot(xdata,linear,'-','Marker',"o",'MarkerSize',3,'LineWidth',4,'Color',[0.6400 0.6400 0.6400],'MarkerFaceColor',[0.6400 0.6400 0.6400],'Parent', AxesMain,'DisplayName','Linear Baseline'); %h = get(gca,'Children'); %set(gca,'Children',[h(2) h(1)]) end end feccurve = findall(AxesMain, 'Type', 'line','DisplayName','FEC $3.8*10^{-3}$'); % if isempty(feccurve) xdata = AxesMain.Children(1).XData; hdfec = 3.8e-3.*ones(size(xdata)); plot(xdata,hdfec,'--','MarkerSize',4,'Color','black','MarkerFaceColor','black','LineWidth',1,'Parent', AxesMain,'DisplayName','FEC $3.8*10^{-3}$','HandleVisibility','off'); %h = get(gca,'Children'); %set(gca,'Children',[h(2) h(1)]) end % Figure Settings %title(AxesMain,plotJob.title,"Interpreter","none"); xlabel(AxesMain,plotJob.xAxisLabel,"Interpreter","latex"); ylabel(AxesMain,plotJob.yAxisLabel,"Interpreter","latex"); set(AxesMain,'yscale','log'); grid(AxesMain,'on'); grid(AxesMain,'minor'); grid minor %legend(AxesMain); fontsize(AxesMain,8,"points") % fontname(AxesMain,"Arial") fig.Position = plotJob.Position; fig.Units = "centimeters"; fig.Position = [2 2 8.5 7]; set(AxesMain,'TickLabelInterpreter','latex') set(AxesMain.Legend,'Interpreter','latex') % set(gcf,'Units','centimeters') % set(gcf,'Position',[2 2 9 4.5]) ylim([1e-5,0.3]); xlim([min(xAxis),-3]); % annotation('textbox', [0.125, 0.32, 0.1, 0.1], 'String', "FEC 3.8e-3","LineStyle","none","FontSize",8,"FontUnits","points") hold off end function vec = removeZeros(vec) % Find rows that contain only zeros rows_to_remove = all(vec == 0, 2); % Remove rows with only zeros vec(rows_to_remove, :) = []; end