Files
imdd_silas/projects/HighSpeedExperiment_2024/db_auswertung/rate_vs_ber.m
Silas Oettinghaus 9ce23c4a10 Many changes in DBHandler
new general processing structure
just before splitting off the projects folder from this repo
2025-05-13 10:24:09 +02:00

187 lines
6.7 KiB
Matlab

basePath = 'C:\Users\Silas\Documents\MATLAB\Datensätze\sioe_labor\';
database = DBHandler("pathToDB",[basePath,'silas_labor.db'],"type",'sqlite');
filterParams = database.tables;
filterParams.Configurations = struct( ...
'bitrate', [], ... %[224,336,360,390,420,448]
'db_mode', [], ...
'fiber_length', 1, ...
'interference_attenuation', [], ...
'interference_path_length', [], ...
'is_mpi', 0, ...
'pam_level', 4, ...
'rop_attenuation', 0, ...
'wavelength', 1310 ...
);
% filterParams.EqualizerParameters.diff_precode = int32(db_mode.db_encoded);
% filterParams.EqualizerParameters.equalizer_structure = int32(equalizer_structure.vnle);
% filterParams.EqualizerParameters.DCmu = 0.00;
selectedFields = {'Configurations.run_id' 'Runs.rx_raw_path' 'Configurations.bitrate' 'Configurations.symbolrate' 'Configurations.pam_level'...
'Configurations.db_mode' 'Configurations.rop_attenuation' 'Configurations.is_mpi' 'Configurations.interference_attenuation' ...
'EqualizerParameters.equalizer_structure' 'EqualizerParameters.diff_precode' 'EqualizerParameters.eq_id' 'EqualizerParameters.DCmu' 'Measurements.power_pd_in' ...
'Measurements.power_mpi_interference' 'Measurements.power_mpi_signal' 'Results.BER' 'Results.BER_precoded' 'Results.SNR' 'Results.GMI' 'Results.Alpha' 'Results.date_of_processing'};
[dataTable,sql_query] = database.queryDB(filterParams, selectedFields);
fixedVars = {'eq_id','bitrate'};
dataTableGrpd = groupIt(fixedVars,dataTable);
plotRealizations = 0;
% Create a new figure
figure();
hold on
unique_eq = unique(dataTable.eq_id);
cols = linspecer(8);
for i = 1:numel(unique_eq)
idx = find(dataTableGrpd.eq_id == unique_eq(i), 1, 'first');
equalizer_ = equalizer_structure(dataTableGrpd.equalizer_structure(idx));
loop_filt = dataTableGrpd.eq_id==unique_eq(i);
% Plot LINE: BER vs. interference_attenuation
switch equalizer_
case equalizer_structure.vnle
bers = dataTableGrpd.BER(loop_filt,:);
case equalizer_structure.vnle_pf_mlse
bers = dataTableGrpd.BER(loop_filt,:);
case equalizer_structure.vnle_db_mlse
bers = dataTableGrpd.BER_precoded(loop_filt,:);
case equalizer_structure.db_encoded
bers = dataTableGrpd.BER(loop_filt,:);
end
name = sprintf('%s',equalizer_);
p = plot(dataTableGrpd.bitrate(loop_filt,:).*1e-9, bers, '-', 'LineWidth', 0.5,'Color',cols(i,:),'DisplayName',name);
pair_one = {'Run ID', dataTableGrpd.run_id(loop_filt,:)};
pair_two = {'Rate', dataTableGrpd.bitrate(loop_filt,:)};
addDatatips(p, pair_one, pair_two);
xticks(unique(dataTableGrpd.bitrate(loop_filt,:).*1e-9));
% Plot SCATTERS: BER vs. interference_attenuation
loop_filt = dataTable.eq_id==unique_eq(i);
if plotRealizations
switch equalizer_
case equalizer_structure.vnle
bers = dataTable.BER(loop_filt,:);
case equalizer_structure.vnle_pf_mlse
bers = dataTable.BER(loop_filt,:);
case equalizer_structure.vnle_db_mlse
bers = dataTable.BER_precoded(loop_filt,:);
case equalizer_structure.db_encoded
bers = dataTable.BER(loop_filt,:);
end
sc = scatter(dataTable.bitrate(loop_filt,:).*1e-9, bers, 'LineWidth', 0.5,'Marker','*','MarkerEdgeColor',cols(i,:),'HandleVisibility','off');
pair_one = {'Run ID', dataTable.run_id(loop_filt,:)};
pair_two = {'Rate', dataTable.bitrate(loop_filt,:)};
addDatatips(sc, pair_one, pair_two);
xticks(unique(dataTable.bitrate(loop_filt,:).*1e-9));
end
end
% Label the axes and add a title
xlabel('Bitrate in Gbps');
ylabel('BER');
title('Line Rate vs. BER');
yline(3.8e-3,'LineWidth',1,'LineStyle','--','HandleVisibility','off');
% Enable grid for better readability
grid on;
beautifyBERplot;
ylim([1e-4 0.5]);
function resultTable = groupIt(fixedVars,dataTable)
% Group by run_id and eq_id (adjust grouping keys as needed)
[G, groupKeys] = findgroups(dataTable(:, fixedVars));
% Preallocate a cell array for aggregated data.
varNames = dataTable.Properties.VariableNames;
nVars = numel(varNames);
aggData = cell(height(groupKeys), nVars);
groupCount = zeros(height(groupKeys), 1); % To store the size of each group
% Loop over each group.
for i = 1:height(groupKeys)
idx = (G == i); % Logical index for group i
groupCount(i) = sum(idx); % Count number of rows in this group
% For each variable in the table:
for j = 1:nVars
colData = dataTable.(varNames{j});
if isnumeric(colData)
% For numeric data, compute the mean.
aggData{i, j} = min(colData(idx));
else
% For non-numeric data, take the first entry.
if iscell(colData)
aggData{i, j} = colData{find(idx, 1)};
else
aggData{i, j} = colData(find(idx, 1));
end
end
end
end
% Convert the aggregated cell array into a table.
resultTable = cell2table(aggData, 'VariableNames', varNames);
% Append the group count as a new column.
resultTable.nRows = groupCount;
end
function addDatatips(sc, varargin)
% addDatatips Adds custom data tip rows to a scatter plot.
%
% addDatatips(sc, pair1, pair2, ...) adds one or more custom rows to the
% data tip display of the scatter plot identified by sc.
%
% Each pair should be provided as a 1x2 cell array: {label, value}.
% The value can be a scalar or a vector. If a vector is provided, its length
% must match the number of scatter plot points.
%
% Example:
% sc = scatter(x, y, 'LineWidth', 1.5, 'Marker', 'o');
% pair_one = {'Attenuation', attenuationVector};
% addDatatips(sc, pair_one);
numPoints = numel(sc.XData);
for k = 1:length(varargin)
pair = varargin{k};
if ~iscell(pair) || numel(pair) ~= 2
error('Each pair must be a 1x2 cell array: {label, value}.');
end
label = pair{1};
value = pair{2};
% If value is a vector, ensure its length is either 1 or equal to the number of scatter points.
if isvector(value) && numel(value) ~= 1 && numel(value) ~= numPoints
error('The vector for "%s" must be a scalar or have %d elements matching the scatter data points.', label, numPoints);
end
% Create a new data tip row using the provided label and vector.
newRow = dataTipTextRow(label, value);
sc.DataTipTemplate.DataTipRows(end+1) = newRow;
end
end