Files
imdd_silas/projects/HighSpeedExperiment_2024/auswertung/ber_vs_length.m
sioe e47a4dbbbe Many changes for 400G DSP
Minimal Example
...
2024-12-17 16:17:58 +01:00

192 lines
8.7 KiB
Matlab

basePath = 'C:\Users\Silas\Documents\MATLAB\Datensätze\sioe_labor\';
useGui = 0;
pamlvls = [6];
wlengths = [1293,1302,1310];%db.distinctValues.Configurations.wavelength
figoffset = 20;
figure(21)
tiledlayout(1, 3, 'TileSpacing', 'compact', 'Padding', 'compact');
for w = 1:numel(wlengths)
nexttile;
for p = 1:numel(pamlvls)
pamlvl = pamlvls(p);
wlength = wlengths(w);
db = DBHandler("pathToDB",[basePath,'silas_labor.db']);
if useGui
filterParams = db.promptFilterParameters();
selectedFields = db.promptSelectFields();
else
filterParams = db.tables;
filterParams.Configurations = struct( ...
'bitrate', 420e9, ...
'db_mode', [], ...
'fiber_length', [], ...
'interference_attenuation', [], ...
'interference_path_length', [], ...
'is_mpi', 0, ...
'pam_level', pamlvl, ...
'precomp_amp', [], ...
'rop_attenuation', 0, ...
'symbolrate', [], ...
'v_awg', [], ...
'v_bias', [], ...
'wavelength', wlength ...
);
% filterParams.Equalizer.eq_type = equalizer_structure.vnle;
selectedFields = {'Runs.run_id','BERs.ber_id','Equalizer.eq_id','Equalizer.eq_type','BERs.ber','BERs.occurrence',...
'Configurations.db_mode','Configurations.pam_level','Configurations.bitrate','Configurations.symbolrate','Configurations.fiber_length','Configurations.wavelength','Configurations.precomp_amp',...
'Measurements.power_rop','Measurements.power_laser','Measurements.power_pd_in'};
end
sgtitle(['Rate: ',num2str(filterParams.Configurations.bitrate),' Gbit/s'])
% Get data table from DB
[dataTable,~] = db.queryDB(filterParams, selectedFields);
% Extract unique rows from dataTable for each run_id with relevant configuration details
uniqueConfigFields = {'run_id', 'pam_level', 'bitrate','symbolrate', 'fiber_length', 'wavelength', 'precomp_amp', 'db_mode'};
[~, uniqueIdx] = unique(dataTable.run_id); % Get unique run_id indices
configDetails = dataTable(uniqueIdx, uniqueConfigFields); % Extract unique configurations for each run_id
% Calculate the mean BER for each combination of 'run_id' and 'eq_type'
groupedData = groupsummary(dataTable, {'run_id', 'eq_type'}, {'mean','min'}, {'ber', 'power_rop','power_pd_in'});
groupedData = groupsummary(dataTable, {'run_id', 'eq_type'}, {'mean', 'min', @(x) meanExcludingOutliers(x)}, {'ber', 'power_rop','power_pd_in'});
% Join groupedData with configDetails on the run_id field
joinedData = join(groupedData, configDetails, 'Keys', 'run_id');
% Define the fields that you want to use for filtering
filterFields = {'eq_type'};
% Create a cell array to store filtered data tables for each filter field
filteredDataByField = struct();
hold on
% Loop over each field you want to filter by
for f = 1:numel(filterFields)
currentField = filterFields{f};
% Determine unique values for the current field
uniqueValues = unique(joinedData.(currentField));
% Create a struct entry for the current field
filteredDataByField.(currentField) = cell(numel(uniqueValues), 1);
% Loop over each unique value for the current field
for i = 1:numel(uniqueValues)
currentValue = uniqueValues(i);
% Filter joinedData for the current value
if isnumeric(currentValue)
filteredData = joinedData(joinedData.(currentField) == currentValue, :);
else
filteredData = joinedData(strcmp(joinedData.(currentField), currentValue), :);
end
%%% workaround to average the BERs of several runs (ie in 1km case or trials)
%%% Workaround to average the BERs of several runs (e.g., in 1 km case or trials)
% Grouping variable(s)
groupVars = {'fiber_length'};
% Use groupsummary to calculate the mean and min of relevant fields
groupedDataWithMeans = groupsummary(filteredData, groupVars, {'mean', 'min'}, {'mean_ber', 'min_ber', 'fun1_ber', 'mean_power_rop', 'mean_power_pd_in'});
% Extract representative values for constant fields
[~, uniqueIdx] = unique(filteredData.(groupVars{1})); % Get the first occurrence of each bitrate value
constantFields = filteredData(uniqueIdx, {'bitrate', 'GroupCount', 'pam_level', 'symbolrate', 'fiber_length', 'wavelength', 'precomp_amp', 'db_mode'});
% Keep track of which run_id values were grouped
groupedRunIDs = varfun(@(x) {unique(x)}, filteredData, 'GroupingVariables', groupVars, 'InputVariables', 'run_id');
groupedRunIDs.Properties.VariableNames(end) = {'GroupedRunIDs'};
% Join the grouped data with the constant fields
groupedDataWithMeans = join(groupedDataWithMeans, constantFields, 'Keys', groupVars);
% Join the grouped data with the grouped run_id list
groupedDataWithMeans = join(groupedDataWithMeans, groupedRunIDs, 'Keys', groupVars);
% Update filteredData to include the grouped information
filteredData = groupedDataWithMeans;
%%% end of workaround
cols = linspecer(8);
% a=plot(filteredData.bitrate.*1e-9,filteredData.mean_mean_ber,...
% 'Color',cols(i,:),'MarkerSize',4,'LineWidth',1,'LineStyle',':',...
% 'Marker','o','MarkerFaceColor','auto','MarkerEdgeColor',cols(i,:),...
% 'DisplayName',currentValue);
lst = ["-",":","--"];
a=plot(filteredData.(groupVars{1}),filteredData.mean_fun1_ber,...
'Color',cols(i,:),'MarkerSize',4,'LineWidth',1,'LineStyle',lst(1),...
'Marker','o','MarkerFaceColor','auto','MarkerEdgeColor',cols(i,:),...
'DisplayName',[char(currentValue),'; ',num2str(wlength),' nm' ]);
%
% scatter(filteredData.symbolrate.*1e-9,filteredData.min_min_ber,5,'Marker','_',...
% 'Color',cols(i,:),'LineWidth',1,...
% 'MarkerFaceColor',cols(i,:),'MarkerEdgeColor','black',...
% 'DisplayName',currentValue);
a.DataTipTemplate.DataTipRows(1).Label = groupVars{1};
a.DataTipTemplate.DataTipRows(1).Format = ['%.1f',''];
a.DataTipTemplate.DataTipRows(2).Label = 'BER';
a.DataTipTemplate.DataTipRows(2).Format ='%.1e';
a.DataTipTemplate.DataTipRows(3).Label = 'P_{out}';
a.DataTipTemplate.DataTipRows(3).Value = filteredData.mean_mean_power_rop;
a.DataTipTemplate.DataTipRows(3).Format = ['%.2f',' dBm'];
a.DataTipTemplate.DataTipRows(4).Label = 'Baudr';
a.DataTipTemplate.DataTipRows(4).Value = filteredData.bitrate .*1e-9;
a.DataTipTemplate.DataTipRows(4).Format = ['%.1f',' GBd'];
a.DataTipTemplate.DataTipRows(5).Label = 'Run ID';
a.DataTipTemplate.DataTipRows(5).Value = filteredData.GroupedRunIDs;
a.DataTipTemplate.DataTipRows(5).Format = ['%f',' GBd'];
a.DataTipTemplate.FontSize = 9;
a.DataTipTemplate.FontName = 'arial';
end
end
% Continue with the rest of your plot settings
title(sprintf('Lambda: %f',wlength));
yline(2e-2, 'DisplayName', '20% O-FEC', 'LineStyle', '--', 'HandleVisibility', 'off');
yline(3.8e-3, 'DisplayName', 'HD-FEC', 'LineStyle', '--', 'HandleVisibility', 'off');
xlabel(groupVars{1},'Interpreter','none');
ylabel('Bit Error Rate (BER)');
%xlim([300, 480])
ylim([8e-4,0.5])
set(gca, 'yscale', 'log');
set(gca, 'Box', 'on');
grid on;
grid minor;
legend('Interpreter', 'none');
end
end
% Custom function using rmoutliers to calculate mean after removing outliers
function meanWithoutOutliers = meanExcludingOutliers(x)
% Remove outliers using rmoutliers with default method (based on median)
xWithoutOutliers = rmoutliers(x);
% Calculate the mean of the non-outliers
if isempty(xWithoutOutliers)
% Handle the case where all values are outliers
meanWithoutOutliers = NaN;
else
meanWithoutOutliers = mean(xWithoutOutliers);
end
end