Files
imdd_silas/Functions/Theory/Dissertation/dispersion_around_zdw.m
2026-03-12 17:26:13 +01:00

214 lines
7.2 KiB
Matlab

% plot_dispersion_models
% ------------------------------------------------------------
% Visualizes exact and linearized chromatic dispersion D(λ)
% around the zero-dispersion wavelength (ZDW).
%
% Inputs:
% lambda0_nm - ZDW in nm
% S0 - dispersion slope at ZDW [ps/(nm^2·km)]
% ------------------------------------------------------------
%% ZDW 1
lambda0_nm = [1310];
S0 = [0.075,0.095]';
% wavelength axis around ZDW
lambda_nm = linspace(1240, 1360, 400);
% exact dispersion model
D_exact_1 = (S0./4) .* ( ...
lambda_nm - (lambda0_nm^4)./(lambda_nm.^3) );
%% ZDW 2
lambda0_nm = [1320];
% exact dispersion model
D_exact_2 = (S0./4) .* ( ...
lambda_nm - (lambda0_nm^4)./(lambda_nm.^3) );
%% plot
figure('Color','w'); hold on;
cols = [0.6510 0.8078 0.8902;...
0.1216 0.4706 0.7059;...
0.6980 0.8745 0.5412;...
0.2000 0.6275 0.1725];
plot(lambda_nm, D_exact_1(1,:), 'LineWidth',2, 'DisplayName',sprintf('$S_0=\SI{0.09}{\Dslope}$'),'Color',[0,0,0]);
plot(lambda_nm, D_exact_1(2,:), 'LineWidth',2, 'DisplayName',sprintf('$S_0=\SI{0.09}{\Dslope}$'),'Color',[0,0,0]);
% plot(lambda_nm, D_exact_2(1,:), 'LineWidth',2, 'HandleVisibility','on', 'DisplayName',sprintf('$S_0=\SI{0.09}{\Dslope}$'),'Color',[0,0,0]);
% plot(lambda_nm, D_exact_2(2,:), 'LineWidth',2, 'HandleVisibility','on', 'DisplayName',sprintf('$S_0=\SI{0.09}{\Dslope}$'),'Color',[0,0,0]);
xlabel('Wavelength $\lambda$ [nm]','Interpreter','latex');
ylabel('D($\lambda$) [ps/(nm km)]','Interpreter','latex');
title('Chromatic Dispersion Around the ZDW');
legend('Location','best');
grid on; box on;
xlim([min(lambda_nm) max(lambda_nm)])
ylim([-5 5]);
% mat2tikz_improved('C:\Users\Silas\Documents\6971e0b65b380ca6d71c837f\02_IMDD_System\tikz\dispersion\dispersion')
%%
%% plot_dispersion_dual_ZDW
% Visualizes two ZDW fiber types, each with an S0 tolerance range.
%% plot_dispersion_minimal_for_tikz
% Minimal setup for clean TikZ tuning
% 1. Parameters
lambda_nm = linspace(1240, 1360, 400);
S0_range = [0.075, 0.095];
ZDW_range = [1300, 1325];
% 2. Calculate Envelope and Nominal
[S_mesh, Z_mesh] = meshgrid(S0_range, ZDW_range);
D_all = zeros(length(lambda_nm), 4);
for i = 1:4
D_all(:,i) = (S_mesh(i)/4) .* (lambda_nm - (Z_mesh(i)^4)./(lambda_nm.^3));
end
D_env_min = min(D_all, [], 2);
D_env_max = max(D_all, [], 2);
D_nominal = (mean(S0_range)/4) .* (lambda_nm - (mean(ZDW_range)^4)./(lambda_nm.^3));
% 3. Plotting
figure('Color','w'); hold on;
env_col = [0.1216, 0.4706, 0.7059];
% Shaded area
[hl, hp] = boundedline(lambda_nm, (D_env_min+D_env_max)/2, ...
(D_env_max-D_env_min)/2, 'alpha', 'cmap', env_col);
set(hl, 'YData', D_nominal, 'Color', 'k', 'LineWidth', 1.5);
% Generate the outline and capture the handle
ho = outlinebounds(hl, hp);
% Change properties
set(ho, 'Color', 'k', ... % Make it black
'LineStyle', '--', ... % Make it dashed
'LineWidth', 0.5, ... % Make it thin
'HandleVisibility', 'off'); % Hide from legend
% 4. "Minimal" Measurement Lines (Tweak these in TikZ later)
% Vertical measurement at 1290nm
lambda_v = 1290;
[~, idx] = min(abs(lambda_nm - lambda_v));
y_bot = D_env_min(idx);
y_top = D_env_max(idx);
% Simple line - in TikZ this will be a single \draw command
line([lambda_v, lambda_v], [y_bot, y_top], 'Color', 'r', 'LineWidth', 1.2, 'Tag', 'VertArrow');
text(lambda_v + 2, (y_top+y_bot)/2, '$\Delta D$', 'Color', 'r', 'Interpreter', 'latex');
% Horizontal measurement at D=0
z1 = ZDW_range(1);
z2 = ZDW_range(2);
line([z1, z2], [0, 0], 'Color', [0.1 0.5 0.1], 'LineWidth', 1.2, 'Tag', 'HorizArrow');
text(mean(ZDW_range), 0.5, '$\Delta \lambda_0$', 'Color', [0.1 0.5 0.1], ...
'Interpreter', 'latex', 'HorizontalAlignment', 'center');
% 5. Aesthetics
xlabel('Wavelength $\lambda$ [nm]', 'Interpreter', 'latex');
ylabel('$D(\lambda)$ [ps/(nm km)]', 'Interpreter', 'latex');
grid on; box on;
xlim([1240 1360]); ylim([-5 5]);
line(xlim, [0 0], 'Color', [0.4 0.4 0.4], 'LineStyle', '--', 'HandleVisibility', 'off');
% Legend using the handles we have
legend([hp, hl], {'Worst-case Envelope', 'Nominal Realization'}, ...
'Location', 'northwest', 'Interpreter', 'latex');
% To export, run:
% matlab2tikz('dispersion.tex', 'standalone', true);
%% plot_dispersion_for_tikz
% Optimized for matlab2tikz compatibility with manual arrows
%% plot_dispersion_statistical_envelopes
% Visualizes hard spec limits vs. 98% statistical distribution
%% plot_dispersion_final_for_tikz
lambda_nm = linspace(1240, 1360, 400);
% 1. Statistical & Specification Parameters
p01_L = norminv(0.01, 1317, 2);
p99_L = norminv(0.99, 1317, 2);
p01_S = norminv(0.01, 0.0872, 0.0012);
p99_S = norminv(0.99, 0.0872, 0.0012);
% Scenarios: [ZDW_min, ZDW_max], [S0_min, S0_max], [Color RGB]
scenarios = { ...
[1303, 1325], [0.075, 0.0925], [0.6510, 0.8078, 0.8902]; ... % 1. Wide Spec (Gray)
[p01_L, p99_L], [p01_S, p99_S], [0.6, 0.6, 0.6] ... % 2. 98% Stats (Blue)
};
figure('Color','w'); hold on;
hp_handles = [];
% 2. Calculate and Plot Envelopes
for k = 1:size(scenarios, 1)
Zr = scenarios{k,1};
Sr = scenarios{k,2};
col = scenarios{k,3};
[S_mesh, Z_mesh] = meshgrid(Sr, Zr);
D_all = zeros(length(lambda_nm), 4);
for i = 1:4
D_all(:,i) = (S_mesh(i)/4) .* (lambda_nm - (Z_mesh(i)^4)./(lambda_nm.^3));
end
D_min_env = min(D_all, [], 2);
D_max_env = max(D_all, [], 2);
[hl, hp] = boundedline(lambda_nm, (D_min_env+D_max_env)/2, (D_max_env-D_min_env)/2, ...
'cmap','alpha', col);
hp_handles(k) = hp;
set(hl, 'Visible', 'off');
if k == 1
D_wide_min = D_min_env;
D_wide_max = D_max_env;
% ho = outlinebounds(hl, hp);
% % Change properties
% set(ho, 'Color', 'k', ... % Make it black
% 'LineStyle', '--', ... % Make it dashed
% 'LineWidth', 1, ... % Make it thin
% 'HandleVisibility', 'off'); % Hide from legend
% Capture Wide Spec (k=1) bounds for the TikZ measurement lines
hp.FaceAlpha = 0.5;
else
hp.FaceAlpha = 0.8;
end
end
% 3. Nominal Line
D_nom = (0.0872/4) .* (lambda_nm - (1317^4)./(lambda_nm.^3));
h_nom = plot(lambda_nm, D_nom, 'k', 'LineWidth', 1,'LineStyle','-');
% 4. Minimal Lines for TikZ (Measuring Wide Spec)
lambda_v = 1290;
[~, idx_v] = min(abs(lambda_nm - lambda_v));
% Vertical line showing full Wide Spec dispersion range at 1290nm
line([lambda_v, lambda_v], [D_wide_min(idx_v), D_wide_max(idx_v)], 'Color', 'k', 'Tag', 'VertArrow','LineWidth', 1);
% Horizontal line showing Wide Spec ZDW range at D=0
% line([1303, 1325], [0, 0], 'Color', 'k', 'Tag', 'HorizArrow','LineWidth', 1);
% 5. Aesthetics & Legend
xlabel('Wavelength $\lambda$ [nm]', 'Interpreter', 'latex');
ylabel('$D(\lambda)$ [ps/(nm km)]', 'Interpreter', 'latex');
grid on; box on;
xlim([1240 1360]); ylim([-5 5]);
leg_labels = { ...
'$\lambda_0 \in [1303, 1325], S_0 \in [0.075, 0.0925]$', ...
'$\lambda_0 \in [1312, 1322], S_0 \in [0.084, 0.090]$', ...
'$\lambda_0 = 1317, S_0 = 0.0872$'};
legend([hp_handles, h_nom], leg_labels, 'Location', 'northwest', 'Interpreter', 'latex', 'FontSize', 8);
% Export command (uncomment to use)
% mat2tikz_improved('C:\Users\Silas\Documents\6971e0b65b380ca6d71c837f\02_IMDD_System\tikz\dispersion\dispersion_slope.tikz')