343 lines
13 KiB
Matlab
343 lines
13 KiB
Matlab
% minimal example IM/DD
|
|
|
|
M = 4;
|
|
fsym = 180e9;
|
|
|
|
apply_pulsef = 1;
|
|
fdac = 256e9;
|
|
fadc = 256e9;
|
|
random_key = 1;
|
|
|
|
rcalpha = 0.05;
|
|
kover = 16;
|
|
|
|
duob_mode = db_mode.no_db;
|
|
|
|
vbias_rel = 0.5;
|
|
u_pi = 3;
|
|
vbias = -vbias_rel*u_pi;
|
|
|
|
laser_wavelength = 1293;
|
|
laser_linewidth = 0;
|
|
tx_bw_nyquist = 0.8;
|
|
|
|
% Channel
|
|
link_length = 1;
|
|
|
|
% RX
|
|
rop = -7;
|
|
rx_bw_nyquist = 0.8;
|
|
|
|
vnle_order1 = 50;
|
|
vnle_order2 = 7;
|
|
vnle_order3 = 7;
|
|
|
|
vnle_order=[vnle_order1,vnle_order2,vnle_order3];
|
|
dfe_order = [0 0 0];
|
|
|
|
pf_ncoeffs = 1;
|
|
|
|
alpha = 0;
|
|
|
|
len_tr = 4096*2;
|
|
|
|
mu_ffe1 = 0.0001;
|
|
mu_ffe2 = 0.0008;
|
|
mu_ffe3 = 0.001;
|
|
mu_dc = 0.005;
|
|
% mu_dc = 0;
|
|
|
|
mu_ffe = [mu_ffe1 mu_ffe3 mu_ffe3];
|
|
mu_dfe = 0.0004;
|
|
|
|
n_stat_runs = 1;
|
|
base_random_key = random_key;
|
|
output.eq_stats = struct();
|
|
|
|
for stat_run = 1:n_stat_runs
|
|
random_key = base_random_key + stat_run - 1;
|
|
Pform = Pulseformer("fsym",fsym,"fdac",4*fsym,"pulse","rrc","pulselength",16,"alpha",rcalpha);
|
|
|
|
[Digi_sig,Symbols,Tx_bits] = PAMsource(...
|
|
"fsym",fsym,"M",M,"order",16,"useprbs",0,...
|
|
"fs_out",fdac,...
|
|
"applyclipping",0,"clipfactor",1.5,...
|
|
"applypulseform",apply_pulsef,"pulseformer",Pform,...
|
|
"randkey",random_key,...
|
|
'duobinary_mode',duob_mode,...
|
|
"mrds_code",0,"mrds_blocklength",512).process();
|
|
|
|
%%%%% AWG
|
|
El_sig = M8199A("kover",kover).process(Digi_sig);
|
|
% El_sig = AWG("fdac",fdac,"f_cutoff",fsym,"lpf_active",0,"kover",kover,"bit_resolution",12,"upsampling_method","samplehold","precomp_sinc_rolloff",1).process(Digi_sig);
|
|
El_sig.spectrum("displayname",'Digi Spectrum','fignum',1,'normalizeTo0dB',1);
|
|
xlim([0,130]);
|
|
ylim([-30,5]);
|
|
% El_sig = El_sig.setPower(0,"dBm");
|
|
|
|
%%%%% Electrical Driver Amplifier %%%%%%
|
|
% El_sig = Amplifier("amp_mode","ideal_no_noise","gain_mode","gain","amplification_db",3).process(El_sig);
|
|
El_sig = El_sig.normalize("mode","oneone");
|
|
scaling = 0.6*(u_pi/2-abs(vbias-u_pi/2));
|
|
El_sig = El_sig .* scaling;
|
|
|
|
%%%%% MODULATE E/O CONVERSION %%%%%%
|
|
[Opt_sig] = EML("mode",eml_mode.im_cosinus,"power",3,"fsimu",El_sig.fs,"lambda",laser_wavelength,"bias",vbias,"u_pi",u_pi,"linewidth",laser_linewidth,"randomkey",random_key+1,"alpha",alpha).process(El_sig);
|
|
|
|
Opt_sig.spectrum("displayname",'Opt Spectrum','fignum',10,'normalizeTo0dB',1);
|
|
|
|
% Opt_sig.eye(fsym,M,"displayname",'eye adter modulator','fignum',2026);
|
|
|
|
Opt_sig = Fiber("fsimu",Opt_sig.fs,"fiber_length",link_length,"alpha",0.3,"D",0,"lambda0",1310,"gamma",0,"Dslope",0.07).process(Opt_sig);
|
|
|
|
%%%%%% ROP %%%%%%
|
|
Rx_sig = Amplifier("amp_mode","ideal_no_noise","gain_mode","output_power","amplification_db",rop).process(Opt_sig);
|
|
|
|
%%%%%% PD Square Law %%%%%%
|
|
Rx_sig = Photodiode("fsimu",fdac*kover,"dark_current",2e-08,"responsivity",1,"temperature",20,"nep",1.8e-11).process(Rx_sig);
|
|
|
|
%%%%%% Low-pass RX (PD, El. Connectors and Scope %%%%%%
|
|
rx_bwl = 80e9;
|
|
Rx_sig = Filter('filtdegree',4,"f_cutoff",rx_bwl,"fs",fdac*kover,"filterType",filtertypes.butterworth,"active",true).process(Rx_sig);
|
|
|
|
% %%%%%% Low-pass Scope %%%%%%
|
|
Lp_scpe = Filter('filtdegree',4,"f_cutoff",110e9,"fs",fadc,"filterType",filtertypes.butterworth,"active",true);
|
|
|
|
%%%%%% Scope %%%%%%
|
|
Scpe_sig = Scope("fsimu",fdac*kover,"fadc",fadc,...
|
|
"delay",0,"fixed_delay",0,"filtertype",filtertypes.butterworth,...
|
|
"samplingdelay",0,"rand_samplingdelay",0,"freq_offset",0,"samp_jitter",0,...
|
|
"adcresolution",8,"quantbuffer",0.1,'block_dc',1,'lpf_active',1,'H_lpf',Lp_scpe).process(Rx_sig);
|
|
%%
|
|
|
|
% 1) matched filter
|
|
% pulse is symmetric, hence we can use pulsef firectly as matched filter.
|
|
% It feels off (bit I think correct) that the fsym is now the output freq.!!
|
|
% -> output 2 sps to omit timing recovery!?
|
|
Pform = Pulseformer("fsym",fsym,"fdac",2*fsym,"pulse","rrc","pulselength",16,"alpha",rcalpha,"matched",1);
|
|
Scpe_sig = Pform.process(Scpe_sig);
|
|
Scpe_sig.spectrum("displayname",'Signal after matched filter','fignum',1,'normalizeTo0dB',1);
|
|
%
|
|
|
|
% %%
|
|
% %%%%%% Sample to 2x fsym %%%%%%
|
|
% Scpe_sig = Scpe_sig.resample("fs_out",2*fsym);
|
|
% Scpe_sig.signal = Scpe_sig.signal(1:2*length(Symbols));
|
|
|
|
%%
|
|
%%%%%% Sync Rx signal with reference %%%%%%
|
|
[Scpe_sig,~] = Scpe_sig.tsynch("reference",Symbols,"fs_ref",fsym,"debug_plots",0);
|
|
Scpe_sig.spectrum("displayname",'Opt Spectrum','fignum',11,'normalizeTo0dB',1);
|
|
|
|
% Scpe_sig = Filter('filtdegree',4,"f_cutoff",Symbols.fs.*0.5,"fs",Scpe_sig.fs,"filterType",filtertypes.gaussian,"active",true).process(Scpe_sig);
|
|
|
|
Scpe_sig = Scpe_sig - mean(Scpe_sig.signal);
|
|
Scpe_sig.signal = Scpe_sig.signal(1:2*length(Symbols));
|
|
|
|
%% -------------------- FFE --------------------
|
|
ffe_options = struct( ...
|
|
"epochs_tr", 3, ...
|
|
"epochs_dd", 3, ...
|
|
"len_tr", 4096, ...
|
|
"order", 40, ...
|
|
"sps", 2, ...
|
|
"decide", 0, ...
|
|
"adaption", adaption_method.rls, ...
|
|
"dd_mode", 1);
|
|
|
|
eq_nlms = FFE("epochs_tr",ffe_options.epochs_tr,"epochs_dd",ffe_options.epochs_dd, ...
|
|
"len_tr",ffe_options.len_tr,"mu_dd",0.001,"mu_tr",0.001, ...
|
|
"order",ffe_options.order,"sps",ffe_options.sps,"decide",ffe_options.decide, ...
|
|
"adaption",ffe_options.adaption,"dd_mode",ffe_options.dd_mode,"save_debug",1,"optmize_mus",1);
|
|
|
|
output.ffe_results = ffe(eq_nlms,M,Scpe_sig,Symbols,Tx_bits, ...
|
|
"precode_mode",duob_mode,'showAnalysis',0,"postFFE",[], ...
|
|
"eth_style_symbol_mapping",0);
|
|
|
|
output.ffe_results.metrics.print("description","FFE");
|
|
|
|
%%
|
|
|
|
% -------------------- FFE --------------------
|
|
%%
|
|
|
|
for i = 3:-1:1
|
|
|
|
mu_adaptation = adaption_method(i);
|
|
|
|
switch mu_adaptation
|
|
case adaption_method.lms
|
|
mu_search_range = [1e-5, 1e-2];
|
|
|
|
case adaption_method.nlms
|
|
mu_search_range = [1e-3, 5e-1];
|
|
|
|
case adaption_method.rls
|
|
mu_search_range = [0.98, 0.99999]; % here mu is lambda
|
|
end
|
|
mu_max_evaluations = 10;
|
|
|
|
ffe_options = struct( ...
|
|
"epochs_tr", 3, ...
|
|
"epochs_dd", 2, ...
|
|
"len_tr", 4096*2, ...
|
|
"order", 20, ...
|
|
"sps", 2, ...
|
|
"decide", 0, ...
|
|
"adaption", mu_adaptation, ...
|
|
"dd_mode", 1);
|
|
|
|
method_name = char(mu_adaptation);
|
|
rng(random_key, "twister");
|
|
mu_dd_var = optimizableVariable("mu_dd", mu_search_range, "Transform", "log");
|
|
mu_tr_var = optimizableVariable("mu_tr", mu_search_range, "Transform", "log");
|
|
global ffe_mu_trace
|
|
ffe_mu_trace = table('Size',[0 5], ...
|
|
'VariableTypes',{'double','double','double','double','double'}, ...
|
|
'VariableNames',{'mu_dd','mu_tr','BER','SNR','mse_last_epoch'});
|
|
objective_fn = @(params) ffe_mu_objective(params, ffe_options, M, Scpe_sig, Symbols, Tx_bits, duob_mode);
|
|
|
|
output.eq_stats.(method_name).mu_optimization{stat_run} = bayesopt(objective_fn, [mu_dd_var, mu_tr_var], ...
|
|
"MaxObjectiveEvaluations", mu_max_evaluations, ...
|
|
"AcquisitionFunctionName", "expected-improvement-plus", ...
|
|
"IsObjectiveDeterministic", false, ...
|
|
"Verbose", 1, ...
|
|
"PlotFcn", []);
|
|
|
|
output.eq_stats.(method_name).mu_observed(stat_run,:) = output.eq_stats.(method_name).mu_optimization{stat_run}.XAtMinObjective;
|
|
output.eq_stats.(method_name).mu_estimated(stat_run,:) = output.eq_stats.(method_name).mu_optimization{stat_run}.XAtMinEstimatedObjective;
|
|
output.eq_stats.(method_name).optimization_trace{stat_run} = ffe_mu_trace;
|
|
|
|
best_mu_dd = output.eq_stats.(method_name).mu_observed.mu_dd(stat_run);
|
|
best_mu_tr = output.eq_stats.(method_name).mu_observed.mu_tr(stat_run);
|
|
output.eq_stats.(method_name).mu_used(stat_run,:) = table(best_mu_dd,best_mu_tr, ...
|
|
'VariableNames',{'mu_dd','mu_tr'});
|
|
|
|
eq_nlms = FFE("epochs_tr",ffe_options.epochs_tr,"epochs_dd",ffe_options.epochs_dd, ...
|
|
"len_tr",ffe_options.len_tr,"mu_dd",best_mu_dd,"mu_tr",best_mu_tr, ...
|
|
"order",ffe_options.order,"sps",ffe_options.sps,"decide",ffe_options.decide, ...
|
|
"adaption",ffe_options.adaption,"dd_mode",ffe_options.dd_mode,"save_debug",1);
|
|
|
|
output.ffe_results = ffe(eq_nlms,M,Scpe_sig,Symbols,Tx_bits, ...
|
|
"precode_mode",duob_mode,'showAnalysis',0,"postFFE",[], ...
|
|
"eth_style_symbol_mapping",0);
|
|
|
|
output.ffe_results.metrics.print("description",sprintf('%s',mu_adaptation));
|
|
|
|
output.eq_stats.(method_name).error_tr_first_epoch(stat_run,:) = eq_nlms.debug_struct.error_tr(1,:);
|
|
|
|
% figure(6)
|
|
% hold on
|
|
% for epoch = 1:ffe_options.epochs_tr
|
|
% plot(1:size(eq_nlms.debug_struct.error_tr,2),movmean(eq_nlms.debug_struct.error_tr(epoch,:),10));
|
|
% end
|
|
|
|
end
|
|
|
|
end
|
|
%%
|
|
|
|
figure(5);
|
|
clf;
|
|
hold on;
|
|
method_names = fieldnames(output.eq_stats);
|
|
cols = cbrewer2('Paired',6);
|
|
cols = cols(2:2:end,:);
|
|
for i = 1:numel(method_names)
|
|
method_name = method_names{i};
|
|
first_epoch = output.eq_stats.(method_name).error_tr_first_epoch;
|
|
|
|
|
|
for j = 1:size(first_epoch,1)
|
|
plot(movmean(output.eq_stats.(method_name).error_tr_first_epoch(j,:),10), ...
|
|
"DisplayName",method_name,"Color",[0.7,0.7,0.7],"LineWidth",0.1,'HandleVisibility','off');
|
|
end
|
|
|
|
end
|
|
|
|
for i = 1:numel(method_names)
|
|
method_name = method_names{i};
|
|
first_epoch = output.eq_stats.(method_name).error_tr_first_epoch;
|
|
|
|
output.eq_stats.(method_name).error_tr_first_epoch_mean = mean(first_epoch,1,"omitnan");
|
|
output.eq_stats.(method_name).error_tr_first_epoch_std = std(first_epoch,0,1,"omitnan");
|
|
plot(movmean(output.eq_stats.(method_name).error_tr_first_epoch_mean,50), ...
|
|
"DisplayName",method_name,"Color",cols(i,:));
|
|
end
|
|
|
|
|
|
grid on;
|
|
xlabel("Training symbol index","Interpreter","tex");
|
|
ylabel("Mean squared error, first epoch","Interpreter","tex");
|
|
legend("Location","best","Interpreter","tex");
|
|
|
|
figure(6);
|
|
clf;
|
|
tiledlayout(numel(method_names),3,"TileSpacing","compact","Padding","compact");
|
|
metric_names = {'BER','SNR','mse_last_epoch'};
|
|
metric_labels = {'BER','SNR','mean abs(error)^2, last epoch'};
|
|
for i = 1:numel(method_names)
|
|
method_name = method_names{i};
|
|
trace = vertcat(output.eq_stats.(method_name).optimization_trace{:});
|
|
observed_mu = output.eq_stats.(method_name).mu_observed;
|
|
estimated_mu = output.eq_stats.(method_name).mu_estimated;
|
|
for metric_idx = 1:numel(metric_names)
|
|
nexttile;
|
|
metric = trace.(metric_names{metric_idx});
|
|
if metric_idx ~= 2
|
|
metric = log10(max(metric,realmin));
|
|
end
|
|
scatter(trace.mu_tr,trace.mu_dd,25,metric,"filled");
|
|
hold on;
|
|
plot(observed_mu.mu_tr,observed_mu.mu_dd,"kp","MarkerSize",11, ...
|
|
"MarkerFaceColor","y","LineWidth",1.2,"DisplayName","Observed best");
|
|
plot(estimated_mu.mu_tr,estimated_mu.mu_dd,"kx","MarkerSize",10, ...
|
|
"LineWidth",1.6,"DisplayName","Estimated best");
|
|
set(gca,"XScale","log","YScale","log");
|
|
grid on;
|
|
xlabel('\mu_{tr}',"Interpreter","tex");
|
|
ylabel('\mu_{dd}',"Interpreter","tex");
|
|
title(sprintf("%s: %s",method_name,metric_labels{metric_idx}),"Interpreter","tex");
|
|
cb = colorbar;
|
|
if metric_idx ~= 2
|
|
cb.Label.String = sprintf("log10(%s)",metric_labels{metric_idx});
|
|
else
|
|
cb.Label.String = metric_labels{metric_idx};
|
|
end
|
|
cb.Label.Interpreter = "tex";
|
|
legend("Location","best","Interpreter","tex");
|
|
end
|
|
end
|
|
|
|
function objective = ffe_mu_objective(params, ffe_options, M, rx_signal, tx_symbols, tx_bits, duob_mode)
|
|
global ffe_mu_trace
|
|
try
|
|
eq_candidate = FFE("epochs_tr",ffe_options.epochs_tr,"epochs_dd",ffe_options.epochs_dd, ...
|
|
"len_tr",ffe_options.len_tr,"mu_dd",params.mu_dd,"mu_tr",params.mu_tr, ...
|
|
"order",ffe_options.order,"sps",ffe_options.sps,"decide",ffe_options.decide, ...
|
|
"adaption",ffe_options.adaption,"dd_mode",ffe_options.dd_mode,"save_debug",1);
|
|
|
|
candidate_results = ffe(eq_candidate, M, rx_signal, tx_symbols, tx_bits, ...
|
|
"precode_mode",duob_mode,'showAnalysis',0,"postFFE",[], ...
|
|
"eth_style_symbol_mapping",0);
|
|
|
|
objective = candidate_results.metrics.BER;
|
|
if ~isfinite(objective)
|
|
objective = 0.5;
|
|
end
|
|
mse_last_epoch = mean(eq_candidate.debug_struct.error_tr(end,:),"omitnan");
|
|
ffe_mu_trace = [ffe_mu_trace; table(params.mu_dd,params.mu_tr,objective, ...
|
|
candidate_results.metrics.SNR,mse_last_epoch, ...
|
|
'VariableNames',{'mu_dd','mu_tr','BER','SNR','mse_last_epoch'})];
|
|
|
|
fprintf("mu_dd=%9.3e, mu_tr=%9.3e -> BER=%9.3e, SNR=%6.2f dB, MSE=%9.3e\n", ...
|
|
params.mu_dd, params.mu_tr, objective, candidate_results.metrics.SNR, mse_last_epoch);
|
|
catch ME
|
|
objective = 0.5;
|
|
ffe_mu_trace = [ffe_mu_trace; table(params.mu_dd,params.mu_tr,objective,NaN,NaN, ...
|
|
'VariableNames',{'mu_dd','mu_tr','BER','SNR','mse_last_epoch'})];
|
|
fprintf("mu_dd=%9.3e, mu_tr=%9.3e -> failed: %s\n", ...
|
|
params.mu_dd, params.mu_tr, ME.message);
|
|
end
|
|
end
|