Faster DP_fiber with GPU processing... Run test\gpu_cpu_comparison.m to see difference on your setup

This commit is contained in:
silas (home)
2026-02-01 13:53:20 +01:00
parent 67689bb70f
commit fba7cbdba2
15 changed files with 1281 additions and 217 deletions

View File

@@ -1,16 +1,4 @@
% Minimal MZM transfer-function demo (sinusoidal drive) aligned with your notation
%
% Implements exactly:
% E_out(t) = E0 * exp(j*w0*t) * exp(-j*w0*L*n_eff/c0) * 1/2 * [ exp(-j*phi1(t)) + rho*exp(-j*phi2(t)) ]
% with phi_{1,2}(t) = pi * v_{1,2}(t)/Vpi
%
% Push-pull:
% v1(t) = +v_drive(t)/2 , v2(t) = -v_drive(t)/2 => phi1 = +pi/2 * v_drive/Vpi, phi2 = -pi/2 * v_drive/Vpi
%
% And the ideal TF (rho=1):
% E_out/E_in = exp(-j*w0*L*n_eff/c0) * cos( (pi/2) * v_drive/Vpi )
%
% Note: E_in(t) = E0 * exp(j*w0*t) in this script.
% Parameters
c0 = physconst('lightspeed'); % [m/s]
@@ -25,27 +13,60 @@ Vpi = 3.2; % [V] half-wave voltage (your V_pi)
% Drive
f0 = 1e9; % [Hz]
fs = 100e9; % [Hz]
Nper = 1; % number of periods
Vpp = 0.5*Vpi; % [V] peak-to-peak of v_drive(t)
fs = 200e9; % [Hz]
Nper = 2; % number of periods
Vpp = 0.6*Vpi; % [V] peak-to-peak of v_drive(t)
biasV = 2; % [V] differential bias added to v_drive
% Analytic
v_ = linspace(-1,2, 2001);
% Field transfer function (amplitude)
Field_mzm_analytic = cos((pi/2)*v_);
% Power transfer function (intensity)
P_mzm_analytic = Field_mzm_analytic.^2;
% Imbalance factor in YOUR notation:
rho = 1; % rho=1 -> ideal balanced MZM (collapses to ideal TF)
biasV = 1.1; % [V] differential bias added to v_drive
% Time axis + differential drive voltage v_drive(t)
T = Nper/f0;
t = (0:1/fs:T-1/fs).';
v_drive = biasV + (Vpp/2)*sin(2*pi*f0*t); % v_drive(t) (peak = Vpp/2)
if 1
% SINE
v_drive = biasV + (Vpp/2)*sin(2*pi*f0*t); % v_drive(t) (peak = Vpp/2)
else
% --- Generate PAM-4 Sequence ---
symbols = linspace(-0.5, 0.5, 4);
num_symbols = 12; % Increased slightly for better visual
rng(44);
random_data = symbols(randi(4, 1, num_symbols));
% Create time axis (Note: T is your period from the sine code)
sps = round(T * fs);
t = (0:1/fs:(num_symbols*T)-1/fs).';
% Upsample to rectangular waveform
v_pam = repelem(random_data, sps).';
% Apply swing and bias: Resulting range is [biasV-Vpp/2, biasV+Vpp/2]
v_drive_rect = biasV + (v_pam * Vpp);
% --- Round the edges ---
filter_span = round(sps/1.5); % Increased span for smoother "rounding"
window = gausswin(filter_span);
window = window / sum(window);
% Apply filter (using 'same' to keep vector length, but be aware of edge transients)
v_drive = conv(v_drive_rect, window, 'same');
end
% Analytic
v_ = linspace(-1,2, 2001);
% Field transfer function (amplitude)
Field_mzm_analytic = cos((pi/2)*v_);
% Power transfer function (intensity)
P_mzm_analytic = Field_mzm_analytic.^2;
% Imbalance factor in YOUR notation:
rho = 1;
% Push-pull branch voltages (consistent with v_drive = v1 - v2)
v1 = +0.5*v_drive; % arm 1
@@ -69,8 +90,6 @@ H_num = E_out ./ E_in;
% Power (normalized)
Pnorm_num = abs(H_num).^2; % since |E_out/E_in|^2
% Ideal TF (analytic) for comparison (rho=1, push-pull)
H_ideal = common_phase .* cos( (pi/2) * (v_drive./Vpi) );
@@ -78,9 +97,6 @@ Pnorm_ideal = abs(H_ideal).^2;
Pnorm_math = cos( (pi/2) * (v_drive./Vpi) ).^2;
set(groot, 'defaultLegendInterpreter', 'tex');
set(groot, 'defaultAxesTickLabelInterpreter', 'tex');
set(groot, 'defaultTextInterpreter', 'tex');
@@ -100,8 +116,11 @@ plot(v_norm,t*1e9, 'LineWidth', 1.0,'Color',colvdrive); grid on;
ylabel('t [ns]'); xlabel('v_{drive}(t)/V_\pi');
title('Drive voltage (normalized)');
xlim([min(v_) max(v_)]);
% mat2tikz_improved('C:\Users\Silas\Documents\6971e0b65b380ca6d71c837f\02_IMDD_System\tikz\linear_casee\mzm_input_signal.tex');
%% IN/OUT (static transfer) normalized x-axis + analytic curve
if 0
figure(2); clf
plot(v_, Field_mzm_analytic, 'LineWidth', 1.2,'LineStyle','--','Color',colfield); hold on;% analytic power TF
plot(v_, P_mzm_analytic, 'LineWidth', 1.2, 'Color',colpow); hold on;% analytic power TF
@@ -123,18 +142,78 @@ xlim([min(v_) max(v_)+1]);
ylim([-1 1]);
% mat2tikz_improved('C:\Users\Silas\Documents\6971e0b65b380ca6d71c837f\02_IMDD_System\tikz\mzm.tex');
end
%%
% % FIELD TF (only field here; do not mix power into this figure)
figure(3); clf
plot(v_, Field_mzm_analytic, 'LineWidth', 1.2,'LineStyle','--','Color',colfield); hold on;% analytic power TF
plot(v_, P_mzm_analytic, 'LineWidth', 1.2, 'Color',colpow); hold on;% analytic power TF
scatter(v_norm, Pnorm_num, 12, '.', 'LineWidth', 1,'MarkerEdgeColor',colvdrive);
scatter(biasV./Vpi,(cos((pi/2)*biasV./Vpi)^2),10,'Marker','o');
line([min(v_drive), min(v_drive)]./Vpi,[(cos((pi/2)*min(v_drive)./Vpi)^2), -2],'linewidth',0.5,'color','black','linestyle','--');
line([max(v_drive) max(v_drive)]./Vpi,[(cos((pi/2)*max(v_drive)./Vpi)^2), -2],'linewidth',0.5,'color','black','linestyle','--');
xline([min(v_norm) max(v_norm)])
grid on;
xlabel('v_{drive}(t)/V_\pi'); ylabel('|E_{out}/E_{in}|^2');
% legend
xlim([min(v_) max(v_)]);
ylim([-1 1]);
% mat2tikz_improved('C:\Users\Silas\Documents\6971e0b65b380ca6d71c837f\02_IMDD_System\tikz\mzm_tramsfer_function_matlab.tex');
%%
figure(4); clf
% plot(v_, Field_mzm_analytic, 'LineWidth', 1.2,'LineStyle','--','Color',colfield); hold on;% analytic power TF
plot(v_, P_mzm_analytic, 'LineWidth', 1.2, 'Color','black'); hold on;% analytic power TF
input_dots = linspace(min(v_drive),max(v_drive),4)./Vpi;
% input_dots = unique(v_drive_rect)./Vpi;
output_dots = (cos((pi/2)*input_dots).^2);
scatter(input_dots,output_dots,'Marker','x','LineWidth',1,'MarkerEdgeColor','black');
scatter(input_dots,zeros(size(input_dots)),'Marker','^','LineWidth',2,'MarkerEdgeColor','black');
% scatter(ones(size(input_dots)),output_dots,'Marker','<','LineWidth',2,'MarkerEdgeColor','black');
for i = 1:numel(input_dots)
% Draw the dashed projection lines
line([input_dots(i), input_dots(i)], [output_dots(i), 0], 'linewidth', 0.5, 'color', 'black', 'linestyle', '--', 'handlevisibility', 'off');
line([input_dots(i), 1], [output_dots(i), output_dots(i)], 'linewidth', 0.5, 'color', 'black', 'linestyle', '--', 'handlevisibility', 'off');
% Add the level annotation boxes near the output (y-axis)
% Adjust the '1.05' to move the box further right or 'output_dots(i)' for height
j = 3-(i-1)*2;
text(1, output_dots(i), sprintf('Level %d', j), ...
'FontSize', 8, ...
'EdgeColor', 'black', ...
'BackgroundColor', 'white', ...
'Margin', 2);
end
xlim([0,1.5]);
ylim([0,1])
% line([min(v_drive), min(v_drive)]./Vpi,[(cos((pi/2)*min(v_drive)./Vpi)^2), 0],'linewidth',0.5,'color','black','linestyle','--');
% line([max(v_drive), max(v_drive)]./Vpi,[(cos((pi/2)*max(v_drive)./Vpi)^2), 0],'linewidth',0.5,'color','black','linestyle','--');
% mat2tikz_improved('C:\Users\Silas\Documents\6971e0b65b380ca6d71c837f\02_IMDD_System\tikz\linear_casee\mzm_tf.tex');
% xticks(sort(input_dots));
% yticks(sort(output_dots));
grid off
%%
% % FIELD TF (only field here; do not mix power into this figure)
figure(5); clf
% plot(t*1e9, real(H_num), 'LineWidth', 1.0); hold on;
% plot(t*1e9, real(H_ideal), '--', 'LineWidth', 1.0,'DisplayName','Field','Color',colfield); hold on;
plot(t*1e9, Pnorm_num, 'LineWidth', 1.0,'DisplayName','Intensity', 'Color',colpow); hold on;
grid on;
xlabel('t [ns]'); ylabel('Re\{E_{out}/E_{in}\}');
legend
mat2tikz_improved('C:\Users\Silas\Documents\6971e0b65b380ca6d71c837f\02_IMDD_System\tikz\mzm_out.tex');
yticks(sort(output_dots));
% mat2tikz_improved('C:\Users\Silas\Documents\6971e0b65b380ca6d71c837f\02_IMDD_System\tikz\linear_casee\mzm_output_signal.tex');