PMD theory; S21 measures; NGMI theory

This commit is contained in:
Silas Oettinghaus
2026-03-25 10:26:50 +01:00
parent 5b90bc11a0
commit ed7c68d78b
34 changed files with 14156 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
% Parameters
symbols = [0, 1, 2, 3]; % PAM-4 symbols
P_X = [0.25, 0.25, 0.25, 0.25]; % Uniform probabilities
sigma2 = 0.1; % Noise variance
received_samples = [0.2, 1.1, 1.9, 2.8];% Received symbols (example)
gray_bits = [0 0; 0 1; 1 1; 1 0]; % Gray coding (bits per symbol)
m = size(gray_bits, 2); % Bits per symbol
N = length(received_samples); % Number of received samples
% Conditional probability function for AWGN
q_Y_given_X = @(y, x) (1 / sqrt(2 * pi * sigma2)) * exp(-(y - x).^2 / (2 * sigma2));
% Entropy term
H_X = -sum(P_X .* log2(P_X)); % Entropy of input distribution
% GMI computation
noise_impact_term = 0;
for k = 1:N
y_k = received_samples(k); % Current received sample
[~, closest_symbol_idx] = min(abs(symbols - y_k)); % Closest symbol index
closest_symbol = symbols(closest_symbol_idx); % Closest symbol
for i = 1:m
% Extract i-th bit for each symbol
bit_mask = gray_bits(:, i); % Binary column for i-th bit of all symbols
matching_symbols = symbols(bit_mask == gray_bits(closest_symbol_idx, i));
% Numerator: Sum over x in x_{b_{k, i}}
numerator = sum(q_Y_given_X(y_k, matching_symbols) .* P_X(ismember(symbols, matching_symbols)));
% Denominator: Sum over all x
denominator = sum(q_Y_given_X(y_k, symbols) .* P_X);
% Logarithmic contribution
noise_impact_term = noise_impact_term + log2(numerator / denominator);
end
end
% Normalize the noise impact term by N
noise_impact_term = noise_impact_term / N;
% GMI
GMI = H_X + noise_impact_term;
NGMI = GMI / m;
% Display the result
fprintf('GMI: %.4f bits\n', GMI);
fprintf('NGMI: %.4f bits\n', NGMI);

View File

@@ -0,0 +1,43 @@
% estimate_entropies.m
clear; rng(0);
%% 1) Parameters
M = 1e5; % number of Monte-Carlo samples
EbNo_dB = 0; % SNR per bit in dB
EbNo = 10^(EbNo_dB/10);
sigma2 = 1/(2*EbNo); % noise variance per real dimension
% 4-QAM constellation (row vector)
X = [1+1j, 1-1j, -1+1j, -1-1j];
N = numel(X);
PX = ones(1,N)/N; % uniform PMF
%% 2) Generate transmit symbols and AWGN
idx = randi(N,1,M); % 1×M random symbol indices
s = X(idx); % 1×M transmitted symbols
n = sqrt(sigma2)*(randn(1,M) + 1j*randn(1,M));
y = s + n; % 1×M received samples
%% 3) Compute p_{Y|X}(y|x) for each constellation point
% Create an N×M matrix where row n is |y - X(n)|^2
d2 = abs(bsxfun(@minus, X(:), y)).^2; % N×M
pYgX = (1/(pi*sigma2)) * exp(-d2 / sigma2); % N×M
%% 4) Estimate H(Y) = -E[ log2 p_Y(Y) ]
% Mixture density p_Y(y_m) = sum_n PX(n)*pYgX(n,m)
pY = PX * pYgX; % 1×M
HY = -mean(log2(pY)); % bits
%% 5) Estimate H(Y|X) = -E[ log2 p(Y|X) ]
% For each m, pick the row corresponding to the true idx(m)
linearIdx = sub2ind([N, M], idx, 1:M);
pYgX_true = pYgX(linearIdx); % 1×M
HYgX = -mean(log2(pYgX_true)); % bits
%% 6) Mutual information
I = HY - HYgX;
%% 7) Display
fprintf('Estimated H(Y) = %.4f bits\n', HY);
fprintf('Estimated H(Y|X) = %.4f bits\n', HYgX);
fprintf('Estimated I(X;Y) = %.4f bits\n', I);

View File

@@ -0,0 +1,116 @@
if 0
pmd = 0.2 * ( 1e-12 / sqrt(1e3) ) ; % 0.1 ps/sqrt(km) -> 1e-9 -> s/sqrt(m)
L = 1000; % m
corr_len = 100;
num_wave_plates = 100;
wp_len = L / num_wave_plates; %waveplate length
dgd = pmd * sqrt(L);
fdac = 120e9; % GHz
fsim = fdac * 512 ; %oversampled simulation frequency
dt = 1/fsim; % sample time
nt = 4; % sampled signal length
omega = 2*pi*[(0:nt/2-1),(-nt/2:-1)]/(dt*nt) ; %angular frequency vector for optical signal of length nt
omega = 2*pi*fsim ; %angular frequency vector for optical signal of length nt
for rlz = 1:20000
db0 = [];
db1 = [];
delta_beta = [];
db0 = (rand(num_wave_plates,1)*2*pi - pi); % normal distr. between -pi <-> +pi
db1 = sqrt(3*pi/8)*(dgd/fsim)/ num_wave_plates .* omega; % linear increasing delta beta 1
%loop over waveplates
for n_wp = 1:length(db0)
delta_beta(n_wp,:) = (db1+db0(n_wp))./corr_len;
end
dphi = delta_beta*wp_len; %phase shift due to propagation constant = beta * L
if rlz == 1
figure()
plot(cumsum( delta_beta ));
end
dphi_end(rlz) = sum( dphi );
end
figure;
histogram((dphi_end),100);
deltaT = mean(abs(dphi_end));
%H = exp(-1j*dphi); % Filter to apply phase shift in freq. domain
end
PMD = 0.1 * ( 1e-12 / sqrt(1e3) ); %PMD s/sqrt(m)
L = 10e3; %m
sigma_dgd = PMD * sqrt(L); % in sec.
disp(['variance of DGD in pico seconds: ',num2str(sigma_dgd*1e12)]);
disp(['variance of DGD in pico seconds: ',num2str(sigma_dgd*1e12)]);
dgd = [];
for i = 1:4
dgd(i,:) = DGD(sigma_dgd,10000);
end
rms = PMD * sqrt(40e3) * 1e12 ; % in sec.
t = [0:0.01:100];
z2 = sqrt(2/pi).*(t.^2)/(rms.^3).*exp(-t.^2/(2*rms^2)) ;
figure;
histogram(dgd*1e12,1000,"Normalization","pdf");
hold on
plot(t(1:200),z2(1:200),'r');
hold off
function z = DGD(sigma_dgd,N)
%PMD = sqrt( (PMD*1e12)^2/3 );
% PMD = PMD * 1/( 1e-12 / sqrt(1e3) );
sigma_dgd = sigma_dgd*1e12;
x = [0:N];
almaga = randn(3,N)*sigma_dgd;
y = almaga.^2;
z0 = sqrt(sum(y,1));
disp(mean(z0));
disp(std(z0));
% disp(var(z0));
z1 = [];
for l = 0:0.1:N
z1 = [z1 sum(z0(1,:)>l & z0(1,:)<l+0.1) / N ];
end
z = z0 *1e-12;
rms = sigma_dgd;
t = [0:0.01:N];
z2 = sqrt(2/pi).*(t.^2)/(rms.^3).*exp(-t.^2/(2*rms^2)) ;
figure;
histogram(z0,1000,"Normalization","pdf");
hold on
plot(t(1:200),z2(1:200),'r');
return
end

View File

@@ -0,0 +1,59 @@
PMDcoeff = 0.1 * ( 1e-12 / sqrt(1e3) ); %PMD s/sqrt(m)
L_40 = 40e3; %m
mean_dgd = PMDcoeff * sqrt(L_40); % in sec. E(tau) == PMD value
disp(['defined mean of DGD in pico seconds: ',num2str(mean_dgd*1e12)]);
dgd_40km = [];
for i = 1:4000
dgd_40km(i,:) = getDGDrealization(mean_dgd,1);
end
disp(['simulated mean of DGD in pico seconds: ',num2str(mean(dgd_40km)*1e12)]);
%%% 2 test for segmented link %%%%
L_10 = 10e3; %m
mean_dgd = PMDcoeff * sqrt(L_10); % in sec. E(tau) == PMD value
dgd_10km = [];
for j = 1:4
for i = 1:1000
dgd_10km(i,j) = getDGDrealization(mean_dgd,1);
end
end
a = sum(dgd_10km,2) ;
%%% calc maxwell curve
mean_dgd = PMDcoeff * sqrt(L_40) * 1e12 ; % in sec.
q = sqrt(pi/8) * mean_dgd;
t = [0:0.01:100];
maxwell = sqrt(2/pi).* (t.^2)/(q.^3) .* exp(-t.^2/(2*q^2)) ;
%%% plot everything
figure;
histogram(dgd_40km*1e12,1000,"Normalization","pdf",'EdgeColor','none','FaceColor','b','FaceAlpha',0.6);
hold on
histogram(a*1e12,1000,"Normalization","pdf",'EdgeColor','none','FaceColor','g','FaceAlpha',0.6);
plot(t(1:200),maxwell(1:200),'r','LineWidth',3);
xline(mean_dgd,'LineWidth',3,'Color','magenta')
hold off
function z = getDGDrealization(mean_dgd,N)
mean_dgd = mean_dgd; %to pico seconds
q = sqrt(pi/8) * mean_dgd;
threenormaldists = randn(3,N)*q; %3x normal dist around [-1,1] with a deviation of mean_dgd
y = threenormaldists.^2;
z = sqrt(sum(y,1));
end