Files
imdd_silas/Functions/Theory/Dissertation/power_fading_gif.m
2026-02-19 15:34:53 +01:00

69 lines
2.1 KiB
Matlab

%% ============================================================
% IM/DD Power Fading Evolution GIF (1 km -> 20 km)
% Uses the provided GifWriter (serial mode)
% ============================================================
clear; close all; clc;
%% Fiber and system parameters
lambda0 = 1310e-9; % zero-dispersion wavelength [m]
lambda = 1275e-9; % operating wavelength [m]
S0 = 0.09; % dispersion slope [ps/(nm^2·km)]
c = physconst('lightspeed');
%% Derived quantities (length-independent)
D_lambda = (S0/4) * (lambda*1e9 - (lambda0*1e9)^4/(lambda*1e9)^3); % ps/(nm·km)
D_si = D_lambda * 1e-6; % s/m^2
b2 = -D_si * lambda^2 / (2*pi*c); % s^2/m
%% Frequency grid
f_max = 150e9;
f = linspace(0, f_max, 4000); % [Hz]
%% Figure setup (keep it stable for nicer GIFs)
fig = figure('Color','w');
ax = axes(fig); %#ok<LAXES>
hold(ax,'on'); grid(ax,'on'); box(ax,'on');
xlabel(ax,'Frequency [GHz]');
ylabel(ax,'Magnitude [dB]');
ylim(ax,[-30 0]);
xlim(ax,[0 f_max/1e9]);
%% GIF writer (serial mode; simplest)
g = GifWriter('Name','power_fading_evolution', 'DelayTime',0.12, 'Parallel',false);
%% Loop: 1 km to 20 km
L = [1:20,19:-1:1];
for L_km = L
L_meter = L_km * 1e3; % [m]
% IM/DD transfer function (power fading)
phi = 2*pi^2 * b2 * f.^2 * L_meter;
H = abs(cos(phi));
HdB = 10*log10(max(H, 1e-12)); % avoid -Inf for deep notches
% Clear and redraw (stable axes)
cla(ax);
plot(ax, f/1e9, HdB, 'LineWidth', 1.8, 'Color','black');
% Analytic first-null frequency marker
f_null = sqrt(c*(0.5)/(abs(D_si)*lambda^2*L_meter));
xline(ax, f_null/1e9, 'r--', 'LineWidth', 1.2, ...
'Label', sprintf('f_{null}=%.1f GHz', f_null/1e9), ...
'LabelOrientation','horizontal', ...
'LabelVerticalAlignment','bottom');
title(ax, sprintf('Power Fading for: %.0f km @ 1275 nm', L_km));
drawnow;
% Add frame to GIF
g.addFrame(fig);
end
%% Done
g.compile(fig.Number);
disp(fullfile(g.OutputDir, sprintf('%s_fig_%d.gif', g.Name, fig.Number)));