

files = ["imdd_simulation\projects\MPI_April\wh_pam4_dienstag.mat","imdd_simulation\projects\MPI_April\wh_pam6_dienstag.mat"];
linesstyles = ["-","--"];

vp = wh.parameter.vp.values;
vb = wh.parameter.vb.values;
sir = wh.parameter.sir.values(end); % 20    22    24    26    28    30    32    34    36
rop = wh.parameter.rop.values(end);
lw = wh.parameter.laser_linewidth.values(1);
pn_key = wh.parameter.pn_key.values;
bias = wh.parameter.vb.values(1:end-2);
figure()
tiledlayout(2,3)
cols = linspecer(4);

for d = 1:2
    load(files(d));
    for lw = wh.parameter.laser_linewidth.values
        nexttile

        curber = [];

        for v = 1:numel(wh.parameter.vp.values)
            vp_ = wh.parameter.vp.values(v);
            for b = 1:numel(bias)

                for k = pn_key
                    curber(k,b) = wh.getStoValue('ber',sir,lw,k,vp_,bias(b),rop);
                end

            end
            meanber =  mean(curber,1);
            hold on

            delta = meanber-curber;
            yneg = abs(max(delta));
            ypos = abs(min(delta));



            if d == 1
                curvename = ['PAM4, Vpp:',num2str((vp_/2*2)*100),' %'];
                [hl,hp] = boundedline(2-bias,meanber,([yneg;ypos]'),'-o','alpha','Color',cols(v,:),'transparency', 0.1,'linewidth',0.7);
                hl.MarkerFaceColor = cols(v,:);
                hl.MarkerSize = 3;
                hl.LineStyle = '-';
                hl.DisplayName = curvename;
                set(hp,'HandleVisibility','off');

                ho = outlinebounds(hl,hp);
                set(ho, 'linestyle', ':', 'color', cols(v,:),'Linewidth',0.5);
                set(ho,'HandleVisibility','off');
                %                 errorbar(2-bias,meanber,yneg,ypos,'LineStyle',linesstyles(d),'Marker','o','Color',cols(v,:),'MarkerSize',4,'MarkerFaceColor',cols(v,:),'MarkerEdgeColor',cols(v,:),'DisplayName',curvename);
            elseif d == 2
                 curvename = ['PAM6, Vpp:',num2str((vp_/2*2)*100),' %'];
                [hl,hp] = boundedline(2-bias,meanber,([yneg;ypos]'),'-o','alpha','Color',cols(v,:),'transparency', 0.1,'linewidth',0.7);
                hl.MarkerFaceColor = cols(v,:);
                hl.MarkerSize = 3;
                hl.LineStyle = '--';
                hl.DisplayName = curvename;
                set(hp,'HandleVisibility','off');

                ho = outlinebounds(hl,hp);
                set(ho, 'linestyle', ':', 'color', cols(v,:),'Linewidth',0.5);
                set(ho,'HandleVisibility','off');
               
                %                 errorbar(2-bias,meanber,yneg,ypos,'LineStyle',linesstyles(d),'Marker','square','Color',cols(v,:),'MarkerSize',4,'MarkerFaceColor',cols(v,:),'MarkerEdgeColor',cols(v,:),'DisplayName',curvename);
            end

            %
            %             plot(2-bias, meanber,'LineStyle',linesstyles(d),'LineWidth',0.5,'DisplayName',curvename,'Color',cols(v,:));
            %             scatter(2-bias,curber,4,'o','MarkerFaceColor',cols(v,:),'MarkerEdgeColor',cols(v,:),'HandleVisibility','off');
            hold on
            title(['SIR: ',num2str(sir),'; Lw: ',num2str(lw*1e-6),' MHz'])
            set(gca,'YScale','log');
            legend('Location','southwest')
            xlabel("Bias in V")
            ylabel("BER")

            xlim([0.4,1]);
            ylim([1e-4,3e-1]);

        end
        yline(3.8e-3,'DisplayName','FEC');
    end

end

