Add new functions

This commit is contained in:
Silas Oettinghaus
2025-02-17 21:31:12 +01:00
parent becaf3f6c9
commit d099efea03
21 changed files with 1502 additions and 272 deletions

View File

@@ -1,176 +0,0 @@
function [ber] = imdd_simulation_minimal(varargin)
% BASIC IMDD Model...
% varargin is either empty or a struct, i.e.:
% optionalvars = struct('bitrate',300e9,'M',6);
% then:
% imdd_simulation_minimal(optionalvars)
% replaces the respective variables -> nice for looping parameter sets
curFolder = pwd;
funcFolder=fileparts(mfilename('fullpath'));
if ~isempty(funcFolder)
cd(funcFolder);
end
% TX
M = 4;
fsym = 112e9;
bitrate = 224e9;
apply_pulsef = 1;
fdac = 256e9;
fadc = 256e9;
random_key = 1;
db_precode = 0;
db_encode = 0;
rcalpha = 0.05;
kover = 16;
vbias_rel = 0.5;
u_pi = 2.9;
vbias = -vbias_rel*u_pi;
laser_wavelength = 1310;
laser_linewidth = 0;
tx_bw_nyquist = 0.95;
% Channel
link_length = 1; %km
% RX
rop = -7;
rx_bw_nyquist = 0.9;
% EQ
vnle_order=[50,7,7];
dfe_order = [2 0 0];
len_tr = 4096*2;
mu_ffe = [0.0004 0.0004 0.0004];
mu_dfe = 0.0004;
mu_dc = 0.00;
% Replace optional input arguments if there are any
if ~isempty(varargin)
var_s = varargin{1};
if isstruct(var_s)
fields = fieldnames(var_s);
for i = 1:numel(fields)
eval([fields{i}, ' = ', num2str( var_s.(fields{i}) ), ';']);
fprintf("%s <-- %.2f \n", fields{i}, var_s.(fields{i}));
end
else
error('Optional variables should be passed as a struct.');
end
end
fsym_ = floor( bitrate*1e-9./log2(M) ).*1e9;
if fsym_ ~= fsym
fsym = fsym_;
fprintf('Adapted symbolrate to %d GBd, to match provided bitrate of %d GBit/s using PAM %d \n',fsym.*1e-9,bitrate.*1e-9, M);
end
f_nyquist = fsym/2;
%%%% TX Signal
Pform = Pulseformer("fsym",fsym,"fdac",4*fsym,"pulse","rrc","pulselength",16,"rrcalpha",rcalpha);
[Digi_sig,Tx_symbols,Tx_bits] = PAMsource(...
"fsym",fsym,"M",M,"order",18,"useprbs",1,...
"fs_out",fdac,...
"applyclipping",0,"clipfactor",1.5,...
"applypulseform",apply_pulsef,"pulseformer",Pform,...
"randkey",random_key,...
"db_precode",db_precode,"db_encode",db_encode,...
"mrds_code",0,"mrds_blocklength",512).process();
Digi_sig.spectrum("displayname",'Digital Spectrum at TX','fignum',10,'normalizeTo0dB',1);
%%%%% AWG
% El_sig = M8199A("kover",kover).process(Digi_sig);
El_sig = AWG("fdac",fdac,"f_cutoff",fsym,"lpf_active",1,"kover",kover,"bit_resolution",12).process(Digi_sig);
% El_sig.spectrum("displayname",'Digi Spectrum','fignum',100,'normalizeTo0dB',0);
El_sig = El_sig.setPower(0,"dBm");
El_sig.eye(fsym,M,"fignum",11,'displayname','Rx Eye');
%%%%% Low-pass el. components %%%%%%
El_sig = Filter('filtdegree',4,"f_cutoff",75e9,"fs",fdac*kover,"filterType",filtertypes.butterworth,"active",true).process(El_sig);
%%%%% Electrical Driver Amplifier %%%%%%
El_sig = Amplifier("amp_mode","ideal_no_noise","gain_mode","gain","amplification_db",3).process(El_sig);
%%%%% 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).process(El_sig);
%%%%%% Fiber %%%%%%
Opt_sig = Fiber("fsimu",Opt_sig.fs,"fiber_length",link_length/1000,"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);
Rx_sig.eye(fsym,M,"fignum",30,'displayname','Rx Eye');
%%%%%% Low-pass RX (PD, El. Connectors and Scope %%%%%%
Rx_sig = Filter('filtdegree',4,"f_cutoff",75e9,"fs",fdac*kover,"filterType",filtertypes.butterworth,"active",true).process(Rx_sig);
%%%%%% Low-pass inside 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);
Scpe_sig.spectrum("displayname",'Digital (256 GSa/s) Rx Spectrum','fignum',10,'normalizeTo0dB',1);
Scpe_sig.normalize("mode","rms").plot("displayname",'Digital (256 GSa/s) Rx Spectrum','fignum',21,'clear',1);
%%%%%% Sample to 2x fsym %%%%%%
Scpe_sig = Scpe_sig.resample("fs_in",fadc,"fs_out",2*fsym);
%%%%%% Sync Rx signal with reference %%%%%%
[Scpe_sig,S] = Scpe_sig.tsynch("reference",Tx_symbols,"fs_ref",fsym);
%%% EQUALIZING
%FFE or VNLE
[Eq_signal,Eq_noise] = EQ("Ne",vnle_order,"Nb",dfe_order,"training_length",len_tr,"training_loops",5,"dd_loops",5,"K",2,"DCmu",mu_dc,"DDmu",[mu_ffe mu_dfe],"DFEmu",0.005,"FFEmu",0,"plotfinal",0,"ideal_dfe",1).process(Scpe_sig,Tx_symbols);
Rx_bits = PAMmapper(M,0).demap(Eq_signal);
[~,numErrors,ber,~] = calc_ber(Rx_bits.signal,Tx_bits.signal,"skip_front",100,"skip_end",150,"returnErrorLocation",1);
Eq_signal.normalize("mode","rms").plot("displayname",'Digital (256 GSa/s) Rx Spectrum','fignum',21,'clear',0);
%%% Visualize EQ Stuff
figure(40);
clf
title(sprintf('PAM %d after EQ ; BER: %1.2e',M, ber ));
constellation = unique(Tx_symbols.signal);
received = NaN(numel(constellation),length(Tx_symbols));
for lvl = 1:numel(constellation)
%Separate the equalized signal into the
%respective levels based on the actually
%transmitted level!
received(lvl,Tx_symbols.signal==constellation(lvl)) = Eq_signal.signal(Tx_symbols.signal==constellation(lvl));
intermediate = received(lvl,:);
cnt(lvl) = numel(intermediate(~isnan(intermediate)));
hold on
histogram(received(lvl,:),1000,"EdgeAlpha",0,'DisplayName',['Lvl ',num2str(lvl),' | ',num2str(cnt(lvl)),' entries']);
end
legend
fprintf('BER: %.2e \n',ber);
autoArrangeFigures;
if ~isempty(curFolder)
cd(curFolder);
end
end

View File

@@ -1,23 +0,0 @@
uloops = struct;
uloops.bitrate = [300,330,360,390,420,450,480].*1e9;
uloops.M = [4,6,8];
wh = DataStorage(uloops);
wh.addStorage("ber");
fprintf("Let's simulate %d configuratiuons! \n",wh.getLastLinIndice);
wh = submit_simulations(wh,"parallel",1);
for m_ = uloops.M
ber_row = wh.getStoValue('ber', uloops.bitrate,m_);
figure(2024)
hold on
plot(uloops.bitrate.*1e-9,ber_row,'DisplayName',sprintf('PAM %d',m_));
end
yline(3.8e-3,'LineWidth',2,'DisplayName','3.8e-3');
yline(2e-2,'LineWidth',2,'LineStyle','--','DisplayName','2e-2');
beautifyBERplot()
legend

View File

@@ -1,72 +0,0 @@
function wh = submit_simulations(wh,options)
arguments
wh
options.parallel = 1;
end
%%% 2) SUBMIT SIMULATION
% Initialize job results
if options.parallel
if isempty(gcp('nocreate'))
parpool;
end
results = parallel.FevalFuture.empty();
else
results = [];
end
lin_idx = 1;
for lin_idx = 1:wh.getLastLinIndice
optionalVars = struct();
if ~isempty(wh.getDimension)
% Build the optionalVars struct
[parametervalues,parameternames]=wh.getPhysIndicesByLinIndex(lin_idx);
for pidx = 1:numel(parameternames)
optionalVars.(parameternames{pidx}) = parametervalues{pidx};
end
end
%%% SIMULATION HERE
if options.parallel
numOutputs = 1;
results(lin_idx) = parfeval(@imdd_simulation_minimal, numOutputs, optionalVars);
else
finalresults{lin_idx} = imdd_simulation_minimal(optionalVars);
wh.addValueToStorageByLinIdx(finalresults{lin_idx}, 'ber', lin_idx);
end
end
if options.parallel
%%% 4) Setup waitbar
h = waitbar(0, 'Processing Simulations...');
% Helper function to compute progress
updateWaitbar = @(~) waitbar(mean(arrayfun(@(f) strcmp(f.State, 'finished'), results)), h);
fprintf('Fetching results... \n');
% Update the waitbar after each simulation
updateWaitbarFutures = afterEach(results, updateWaitbar, 0);
% Close the waitbar after all simulations complete
afterAll(updateWaitbarFutures, @(~) delete(h), 0);
%%% 7) Fetch final results after all computations
fetchOutputs(results);
for ridx = 1:length(results)
wh.addValueToStorageByLinIdx(results(ridx).OutputArguments{1}, 'ber', ridx);
end
end
end

View File

@@ -0,0 +1,89 @@
if 0
uloops = struct;
uloops.precomp = [0,1];
uloops.db_precode = [0,1];
uloops.bitrate = [300,330,360,390,420,450,480].*1e9; %[300,330,360,390,420,450,480]
uloops.laser_wavelength = [1293,1302,1310,1318,1327.4];
uloops.M = [4,6,8];
uloops.link_length = [2]; % 1,2,3,5,6,8,10
wh = DataStorage(uloops);
wh.addStorage("ber");
wh = submit_simulations(wh,"parallel",1,"simulation_mode",0);
save('wh_2km',"wh");
end
for wavelength = wh.parameter.laser_wavelength.values
cols = linspecer(6);%cbrewer2('Set2',10);
figcnt = 0;
figWidth = 21; % Full-width for IEEE double-column papers (~7 inches)
figHeight = 6; % Adjust height as needed (~3.5 inches)
figure('Units','centimeters','Position', [1 1 figWidth figHeight],'PaperUnits','centimeters','PaperPosition', [0 0 figWidth figHeight])
tiledlayout(1,3, 'Padding', 'compact', 'TileSpacing', 'compact');
for m = uloops.M
figcnt = figcnt+1;
% subplot(1,3,figcnt)
nexttile
hold on
title(sprintf('%d km | %d nm | PAM %d',uloops.link_length,wavelength,m));
precomp = 1;
db_precode = 0;
a = wh.getStoValue('ber',precomp, db_precode, uloops.bitrate , wavelength, m, uloops.link_length);
ber_vnle = cellfun(@(x) x.vnle_pf_package{1,1}.ber_vnle, a);
ber_vnle_cell = cellfun(@(s) cellfun(@(p) p.ber_vnle, s.vnle_pf_package, 'UniformOutput', true), a, 'UniformOutput', false);
ber_vnle_best = cellfun(@(c) min(c), ber_vnle_cell);
plot(uloops.bitrate.*1e-9,ber_vnle_best,'DisplayName',sprintf('Tx precomp + VNLE'),'Color',cols(3,:),'LineStyle','-','HandleVisibility','on');
xticks(uloops.bitrate.*1e-9);
xlim([min(uloops.bitrate.*1e-9) max(uloops.bitrate.*1e-9)]);
precomp = 0; %0
db_precode = 1;
a = wh.getStoValue('ber',precomp, db_precode, uloops.bitrate , wavelength, m, uloops.link_length);
% ber_db = cellfun(@(x) x.dbtgt_package{1,1}.ber, a);
ber_db_cell = cellfun(@(s) cellfun(@(p) p.ber, s.dbtgt_package, 'UniformOutput', true), a, 'UniformOutput', false);
ber_db_best = cellfun(@(c) min(c), ber_db_cell);
plot(uloops.bitrate.*1e-9,ber_db_best,'DisplayName',sprintf('DB tgt. + MLSE',uloops.link_length,uloops.M),'Color',cols(1,:),'LineStyle','-','HandleVisibility','on');
xticks(uloops.bitrate.*1e-9);
xlim([min(uloops.bitrate.*1e-9) max(uloops.bitrate.*1e-9)]);
precomp = 0; %0
db_precode = 0; %1
a = wh.getStoValue('ber',precomp, db_precode, uloops.bitrate , wavelength, m, uloops.link_length);
% ber_mlse = cellfun(@(x) x.vnle_pf_package{1,1}.ber_mlse, a);
ber_mlse_cell = cellfun(@(s) cellfun(@(p) p.ber_mlse, s.vnle_pf_package, 'UniformOutput', true), a, 'UniformOutput', false);
ber_mlse_best = cellfun(@(c) min(c), ber_mlse_cell);
plot(uloops.bitrate.*1e-9,ber_mlse_best,'DisplayName',sprintf('VNLE + 1 tap post-filter + MLSE',uloops.link_length,uloops.M),'Color',cols(4,:),'LineStyle','-','HandleVisibility','on');
xticks(uloops.bitrate.*1e-9);
xlim([min(uloops.bitrate.*1e-9) max(uloops.bitrate.*1e-9)]);
set(gca, 'YScale', 'log');
ylim([8e-5 0.3]);
yline([4.8e-3, 2e-2],'HandleVisibility','off','LineWidth',1,'LineStyle','--','Color',[0.1 0.1 0.1]);
% legend
beautifyBERplot()
xlabel('Bit Rate in Gbps');
ylabel('BER');
if m ==4
text(310,6.8e-3,"4.8e-3","FontSize",10,"Interpreter","latex")
text(310,3e-2,"2e-2","FontSize",10,"Interpreter","latex")
end
% text(0.5,1,sprintf('%d km %d nm PAM %d',uloops.link_length,wavelength,m),...
% 'Units', 'normalized',"FontSize",10,"Interpreter","latex","BackgroundColor",[1 1 1],"EdgeColor",[0 0 0],'HorizontalAlignment','center','VerticalAlignment','top')
end
lgd = legend;
% Place the legend underneath the tiled layout
lgd.NumColumns = 3;
lgd.Layout.Tile = 'south';
end

View File

@@ -14,7 +14,7 @@ if 1
wh = DataStorage(uloops);
wh.addStorage("ber");
wh = submit_simulations(wh,"parallel",1,"simulation_mode",0);
wh = submit_simulations(wh,"parallel",0,"simulation_mode",1);
end
wh_ana = wh;