function dn_cn_figures(target) %DN_CN_FIGURES Calibration cases with d_n (v109) and with c_n replacing d_n. % Writes dn_cn_fixed.png and dn_cn_adaptive.png in this folder. if nargin < 1, target = 0.4; end here = fileparts(mfilename('fullpath')); base = struct('c_ref', true, 'c_gate', true, 'c_paper', true, 'up_gain', 0.32); evalc('A = run_paper_benchmark(target, base);'); evalc('B = run_paper_benchmark(target, setfield(base, ''d_mode'', ''c''));'); %#ok red = '#901500'; green = '#39BF5E'; gray = [0.55 0.55 0.55]; nm = {'With d_n (v109)', 'c_n replaces d_n'}; fig = newFig(7.5, 2.4); tl = tiledlayout(fig, 1, 4, 'TileSpacing', 'compact', 'Padding', 'compact'); for k = 1:4 a = A.cases(k); b = B.cases(k); ax = nexttile(tl); hold on h = [plot(a.tc, a.b_true, 'k-', 'LineWidth', 1.2), plot(a.tc, a.b_est, '-', 'Color', red, 'LineWidth', 1), ... plot(b.tc, b.b_est, '-', 'Color', green, 'LineWidth', 1)]; yline(target, '--', 'Color', gray); title(sprintf('Case %d: %s, %s\nerror %.3f vs %.3f', k, lower(a.history), lower(a.band), a.err, b.err), 'FontWeight', 'normal') xlim([0 120]); ylim([0.15 0.75]); xlabel('Time (s)'); grid on if k == 1, ylabel('NCF margin'); end end lg = legend(h, [{'True margin'}, nm], 'Orientation', 'horizontal', 'Box', 'off'); lg.Layout.Tile = 'north'; print(fig, fullfile(here, 'dn_cn_fixed.png'), '-dpng', '-r150'); close(fig) fig = newFig(7.5, 5.4); tl = tiledlayout(fig, 3, 4, 'TileSpacing', 'compact', 'Padding', 'compact'); R = {A, B}; col = {red, green}; for k = 5:8 for v = 1:2 c = R{v}.cases(k); ax = nexttile(tl, (v - 1)*4 + k - 4); hold on h(1) = plot(c.tc, c.b_true, 'k-', 'LineWidth', 1.2); h(v + 1) = plot(c.tc, c.b_est, '-', 'Color', col{v}, 'LineWidth', 1); yline(target, '--', 'Color', gray); xlim([0 120]); ylim([0.15 0.75]); set(ax, 'XTickLabel', []); grid on if v == 1, title(sprintf('Case %d: %s, %s', k, lower(c.history), lower(c.band)), 'FontWeight', 'normal'), end text(3, 0.2, sprintf('error %.3f, unsafe %.1f%%', c.err, c.unsafe), 'FontSize', 7) if k == 5, ylabel({nm{v}, 'NCF margin'}); end end ax = nexttile(tl, 8 + k - 4); hold on plot(A.cases(k).tc, A.cases(k).lambda, '-', 'Color', red, 'LineWidth', 1) plot(B.cases(k).tc, B.cases(k).lambda, '-', 'Color', green, 'LineWidth', 1) xlim([0 120]); ylim([0 1.1]); xlabel('Time (s)'); grid on if k == 5, ylabel('Adaptive factor \lambda'); end end lg = legend(h, [{'True margin'}, nm], 'Orientation', 'horizontal', 'Box', 'off'); lg.Layout.Tile = 'north'; print(fig, fullfile(here, 'dn_cn_adaptive.png'), '-dpng', '-r150'); close(fig) end function fig = newFig(w, h) fig = figure('Color', 'w', 'Units', 'inches', 'Position', [1 1 w h], 'Visible', 'off', ... 'PaperUnits', 'inches', 'PaperSize', [w h], 'PaperPosition', [0 0 w h], 'InvertHardcopy', 'off'); set(fig, 'DefaultAxesFontName', 'Times New Roman', 'DefaultTextFontName', 'Times New Roman', 'DefaultAxesFontSize', 8) end