start with 400G analysis work
This commit is contained in:
@@ -0,0 +1,343 @@
|
||||
%% 400G BER over bitrate: best normal algorithms plus duobinary signaling
|
||||
% Normal algorithms are reduced to the best BER per gross rate across
|
||||
% db_mode 0/1, pre-emphasis on/off, and BER/BER_precoded result variants.
|
||||
% Duobinary signaling uses db_mode = 2 and only the sequence-detection BER
|
||||
% stored in the BER field.
|
||||
|
||||
clear; clc;
|
||||
|
||||
%% 1) Query data
|
||||
|
||||
selectedPamLevel = 8;
|
||||
selectedFiberLengthKm = 10;
|
||||
selectedWavelengthNm = 1310;
|
||||
selectedRopAttenuation = 0; % set [] to use all ROP attenuation values
|
||||
selectedIsMpi = 0; % set [] to use all entries
|
||||
|
||||
normalDbModes = [double(db_mode.no_db), double(db_mode.db_precoded)];
|
||||
duobinaryDbMode = double(db_mode.db_encoded);
|
||||
|
||||
maxBerForPlot = 0.5;
|
||||
showRawEntries = false;
|
||||
showBestLine = true;
|
||||
|
||||
algoStyles = defaultAlgorithmStyles();
|
||||
|
||||
db = DBHandler( ...
|
||||
"dataBase", "labor_highspeed", ...
|
||||
"type", "mysql", ...
|
||||
"server", "192.168.178.192", ...
|
||||
"user", "silas", ...
|
||||
"password", "silas");
|
||||
db.refresh();
|
||||
|
||||
fp = QueryFilter();
|
||||
fp.where('Runs', 'fiber_length', 'EQUALS', selectedFiberLengthKm);
|
||||
fp.where('Runs', 'pam_level', 'EQUALS', selectedPamLevel);
|
||||
fp.where('Runs', 'wavelength', 'EQUALS', selectedWavelengthNm);
|
||||
if ~isempty(selectedRopAttenuation)
|
||||
fp.where('Runs', 'rop_attenuation', 'EQUALS', selectedRopAttenuation);
|
||||
end
|
||||
if ~isempty(selectedIsMpi)
|
||||
fp.where('Runs', 'is_mpi', 'EQUALS', selectedIsMpi);
|
||||
end
|
||||
|
||||
selectedFields = db.getTableFieldNames('dashboard_ungrouped_alltime');
|
||||
selectedFields = appendMissingFields(selectedFields, ...
|
||||
{'Runs.precomp_amp'; 'Runs.is_mpi'});
|
||||
selectedFields = selectedFields(:);
|
||||
|
||||
[rawData, query] = db.queryDB(fp, selectedFields);
|
||||
disp(query);
|
||||
fprintf("Fetched %d 400G result rows.\n", height(rawData));
|
||||
|
||||
%% 2) Clean data and build the five plotted curves
|
||||
|
||||
data = rawData;
|
||||
numericFields = ["result_id", "run_id", "eq_id", "bitrate", "grossrate", ...
|
||||
"symbolrate", "pam_level", "wavelength", "fiber_length", "db_mode", ...
|
||||
"rop_attenuation", "precomp_amp", "is_mpi", "numBits", "numBitErr", ...
|
||||
"BER", "numBitErr_precoded", "BER_precoded", "STD", "STDrx", ...
|
||||
"GMI", "AIR", "NGMI", "EVM", "Alpha"];
|
||||
for fieldIdx = 1:numel(numericFields)
|
||||
fieldName = numericFields(fieldIdx);
|
||||
if ismember(fieldName, string(data.Properties.VariableNames))
|
||||
data.(char(fieldName)) = numericColumn(data.(char(fieldName)));
|
||||
end
|
||||
end
|
||||
|
||||
if ~ismember("precomp_amp", string(data.Properties.VariableNames))
|
||||
warning("plot_best_algos:NoPrecompAmp", ...
|
||||
"Runs.precomp_amp was not returned. Falling back to pre_emphasis = (db_mode == 0).");
|
||||
data.pre_emphasis = data.db_mode == double(db_mode.no_db);
|
||||
else
|
||||
data.pre_emphasis = derivePreEmphasis(data.precomp_amp, data.db_mode);
|
||||
end
|
||||
|
||||
normalRows = data(ismember(data.db_mode, normalDbModes), :);
|
||||
normalPlotData = buildNormalMetricRows(normalRows);
|
||||
normalPlotData = normalPlotData(isfinite(normalPlotData.BER_plot) & ...
|
||||
normalPlotData.BER_plot > 0 & normalPlotData.BER_plot < maxBerForPlot, :);
|
||||
|
||||
duobinaryRows = data(data.db_mode == duobinaryDbMode, :);
|
||||
if ismember("equalizer_structure", string(duobinaryRows.Properties.VariableNames))
|
||||
duobinaryRows = duobinaryRows( ...
|
||||
equalizerMask(duobinaryRows.equalizer_structure, ...
|
||||
equalizer_structure.db_encoded), :);
|
||||
end
|
||||
duobinaryPlotData = buildDuobinarySignalingRows(duobinaryRows);
|
||||
duobinaryPlotData = duobinaryPlotData(isfinite(duobinaryPlotData.BER_plot) & ...
|
||||
duobinaryPlotData.BER_plot > 0 & ...
|
||||
duobinaryPlotData.BER_plot < maxBerForPlot, :);
|
||||
|
||||
plotData = [normalPlotData; duobinaryPlotData];
|
||||
if isempty(plotData)
|
||||
warning("plot_best_algos:NoRows", ...
|
||||
"No rows remain after length/PAM/wavelength/BER filtering.");
|
||||
return
|
||||
end
|
||||
|
||||
plotData.bitrate_Gbps = plotData.bitrate .* 1e-9;
|
||||
plotData.grossrate_Gbps = plotData.grossrate .* 1e-9;
|
||||
|
||||
fprintf("Remaining candidate BER rows: %d\n", height(plotData));
|
||||
disp(groupcounts(plotData, ["algorithm_key", "db_mode", "pre_emphasis", "precode"]));
|
||||
|
||||
bestPlotData = bestBerByAlgorithmAndGrossRate(plotData);
|
||||
fprintf("Keeping %d best-BER rows across algorithm/gross-rate groups.\n", ...
|
||||
height(bestPlotData));
|
||||
disp(groupcounts(bestPlotData, "algorithm_key"));
|
||||
|
||||
%% 3) Plot one figure with five lines
|
||||
|
||||
availableStyles = algoStyles(hasAlgorithmRows(bestPlotData, algoStyles), :);
|
||||
if isempty(availableStyles)
|
||||
warning("plot_best_algos:NoSelectedAlgorithms", ...
|
||||
"None of the configured algorithm styles match the queried rows.");
|
||||
return
|
||||
end
|
||||
|
||||
fig = figure(); clf;
|
||||
ax = axes(fig); hold(ax, "on");
|
||||
|
||||
for styleIdx = 1:height(availableStyles)
|
||||
style = availableStyles(styleIdx, :);
|
||||
rowMask = bestPlotData.algorithm_key == style.algorithm_key;
|
||||
if ~any(rowMask)
|
||||
continue
|
||||
end
|
||||
|
||||
algoData = sortrows(bestPlotData(rowMask, :), "grossrate_Gbps");
|
||||
|
||||
if showRawEntries
|
||||
scatter(ax, algoData.grossrate_Gbps, algoData.BER_plot, ...
|
||||
9, ...
|
||||
"Marker", ".", ...
|
||||
"MarkerEdgeColor", style.color, ...
|
||||
"MarkerFaceColor", style.color, ...
|
||||
"MarkerEdgeAlpha", 0.25, ...
|
||||
"MarkerFaceAlpha", 0.25, ...
|
||||
"HandleVisibility", "off");
|
||||
end
|
||||
|
||||
if showBestLine
|
||||
plot(ax, algoData.grossrate_Gbps, algoData.BER_plot, ...
|
||||
"LineStyle", style.lineStyle, ...
|
||||
"Marker", style.marker, ...
|
||||
"MarkerSize", 5, ...
|
||||
"LineWidth", 1.5, ...
|
||||
"Color", style.color, ...
|
||||
"MarkerFaceColor", style.markerFaceColor, ...
|
||||
"MarkerEdgeColor", style.color, ...
|
||||
"DisplayName", style.name);
|
||||
end
|
||||
end
|
||||
|
||||
yline(ax, [2.2e-4, 4.85e-3, 2e-2], ...
|
||||
"LineWidth", 1, ...
|
||||
"LineStyle", "--", ...
|
||||
"Color", [0.25 0.25 0.25], ...
|
||||
"HandleVisibility", "off");
|
||||
|
||||
title(ax, sprintf("PAM-%d, %.0f km, %.0f nm", ...
|
||||
selectedPamLevel, selectedFiberLengthKm, selectedWavelengthNm));
|
||||
xlabel(ax, "Gross rate [Gb/s]");
|
||||
ylabel(ax, "BER");
|
||||
set(ax, "YScale", "log");
|
||||
ylim(ax, [1e-5, maxBerForPlot]);
|
||||
grid(ax, "on");
|
||||
box(ax, "on");
|
||||
|
||||
xTicks = unique(bestPlotData.grossrate_Gbps(isfinite(bestPlotData.grossrate_Gbps)));
|
||||
if ~isempty(xTicks)
|
||||
xticks(ax, xTicks);
|
||||
xlim(ax, [min(xTicks), max(xTicks)]);
|
||||
end
|
||||
|
||||
legend(ax, "Location", "best", "Interpreter", "none");
|
||||
if exist("beautifyBERplot", "file")
|
||||
beautifyBERplot("logscale", true, "setcolors", false, ...
|
||||
"setmarkers", false, "changemarkers", false);
|
||||
end
|
||||
|
||||
set(fig, "Position", 1e3 .* [0.1000 0.5500 0.7200 0.4200]);
|
||||
|
||||
%% Local helpers
|
||||
|
||||
function fields = appendMissingFields(fields, extraFields)
|
||||
fields = cellstr(fields);
|
||||
extraFields = cellstr(extraFields);
|
||||
for idx = 1:numel(extraFields)
|
||||
if ~any(strcmp(fields, extraFields{idx}))
|
||||
fields{end+1, 1} = extraFields{idx}; %#ok<AGROW>
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function values = numericColumn(values)
|
||||
if iscell(values)
|
||||
values = string(values);
|
||||
end
|
||||
if isstring(values) || ischar(values)
|
||||
values = str2double(values);
|
||||
end
|
||||
values = double(values);
|
||||
end
|
||||
|
||||
function styles = defaultAlgorithmStyles()
|
||||
styles = table( ...
|
||||
["vnle"; ...
|
||||
"vnle_pf_mlse"; ...
|
||||
"vnle_db_mlse"; ...
|
||||
"ml_mlse"; ...
|
||||
"db_encoded"], ...
|
||||
[equalizer_structure.vnle; ...
|
||||
equalizer_structure.vnle_pf_mlse; ...
|
||||
equalizer_structure.vnle_db_mlse; ...
|
||||
equalizer_structure.ml_mlse; ...
|
||||
equalizer_structure.db_encoded], ...
|
||||
["VNLE"; ...
|
||||
"VNLE + PF + MLSE"; ...
|
||||
"VNLE DBt. + MLSE"; ...
|
||||
"ML pre-EQ + Viterbi"; ...
|
||||
"Duobinary signaling"], ...
|
||||
["o"; "square"; "diamond"; "^"; "v"], ...
|
||||
["-"; "-"; "-"; "-"; "-"], ...
|
||||
["w"; "w"; "w"; "w"; "w"], ...
|
||||
[clr.Paired.red; ...
|
||||
clr.Paired.green; ...
|
||||
clr.Paired.blue; ...
|
||||
clr.Paired.purple; ...
|
||||
clr.Paired.orange], ...
|
||||
'VariableNames', ["algorithm_key", "eq", "name", "marker", ...
|
||||
"lineStyle", "markerFaceColor", "color"]);
|
||||
end
|
||||
|
||||
function preEmphasis = derivePreEmphasis(precompAmp, dbMode)
|
||||
preEmphasis = false(size(dbMode));
|
||||
|
||||
validPrecomp = isfinite(precompAmp);
|
||||
preEmphasis(validPrecomp) = precompAmp(validPrecomp) > -45;
|
||||
|
||||
missingPrecomp = ~validPrecomp;
|
||||
preEmphasis(missingPrecomp) = dbMode(missingPrecomp) == double(db_mode.no_db);
|
||||
end
|
||||
|
||||
function plotData = buildNormalMetricRows(data)
|
||||
baseRows = data(isfinite(data.BER), :);
|
||||
baseRows.precode = false(height(baseRows), 1);
|
||||
baseRows.BER_plot = baseRows.BER;
|
||||
baseRows.algorithm_key = algorithmKeyFromEqualizer(baseRows.equalizer_structure);
|
||||
baseRows = baseRows(baseRows.algorithm_key ~= "", :);
|
||||
|
||||
if ismember("BER_precoded", string(data.Properties.VariableNames))
|
||||
precodedRows = data(isfinite(data.BER_precoded), :);
|
||||
precodedRows.precode = true(height(precodedRows), 1);
|
||||
precodedRows.BER_plot = precodedRows.BER_precoded;
|
||||
precodedRows.algorithm_key = algorithmKeyFromEqualizer( ...
|
||||
precodedRows.equalizer_structure);
|
||||
precodedRows = precodedRows(precodedRows.algorithm_key ~= "", :);
|
||||
plotData = [baseRows; precodedRows];
|
||||
else
|
||||
warning("plot_best_algos:NoPrecodedBer", ...
|
||||
"BER_precoded was not returned. Plotting only BER rows for normal algorithms.");
|
||||
plotData = baseRows;
|
||||
end
|
||||
end
|
||||
|
||||
function plotData = buildDuobinarySignalingRows(data)
|
||||
plotData = data(isfinite(data.BER), :);
|
||||
plotData.precode = false(height(plotData), 1);
|
||||
plotData.BER_plot = plotData.BER;
|
||||
plotData.algorithm_key = repmat("db_encoded", height(plotData), 1);
|
||||
end
|
||||
|
||||
function algorithmKey = algorithmKeyFromEqualizer(equalizerColumn)
|
||||
eqNumeric = equalizerNumeric(equalizerColumn);
|
||||
algorithmKey = strings(size(eqNumeric));
|
||||
|
||||
algorithmKey(eqNumeric == enumValue(equalizer_structure.vnle)) = "vnle";
|
||||
algorithmKey(eqNumeric == enumValue(equalizer_structure.vnle_pf_mlse)) = ...
|
||||
"vnle_pf_mlse";
|
||||
algorithmKey(eqNumeric == enumValue(equalizer_structure.vnle_db_mlse)) = ...
|
||||
"vnle_db_mlse";
|
||||
algorithmKey(eqNumeric == enumValue(equalizer_structure.ml_mlse)) = "ml_mlse";
|
||||
end
|
||||
|
||||
function mask = equalizerMask(equalizerColumn, eqValue)
|
||||
eqNumeric = equalizerNumeric(equalizerColumn);
|
||||
mask = eqNumeric == enumValue(eqValue);
|
||||
end
|
||||
|
||||
function eqNumeric = equalizerNumeric(equalizerColumn)
|
||||
if isa(equalizerColumn, "equalizer_structure")
|
||||
eqNumeric = double(equalizerColumn);
|
||||
elseif isnumeric(equalizerColumn)
|
||||
eqNumeric = double(equalizerColumn);
|
||||
else
|
||||
equalizerString = string(equalizerColumn);
|
||||
eqNumeric = str2double(equalizerString);
|
||||
|
||||
enumNames = ["vnle", "ffe", "dfe", "vnle_pf_mlse", ...
|
||||
"vnle_db_mlse", "db_encoded", "ml_mlse"];
|
||||
enumValues = [ ...
|
||||
enumValue(equalizer_structure.vnle), ...
|
||||
enumValue(equalizer_structure.ffe), ...
|
||||
enumValue(equalizer_structure.dfe), ...
|
||||
enumValue(equalizer_structure.vnle_pf_mlse), ...
|
||||
enumValue(equalizer_structure.vnle_db_mlse), ...
|
||||
enumValue(equalizer_structure.db_encoded), ...
|
||||
enumValue(equalizer_structure.ml_mlse)];
|
||||
|
||||
for idx = 1:numel(enumNames)
|
||||
missingNumeric = isnan(eqNumeric);
|
||||
eqNumeric(missingNumeric & equalizerString == enumNames(idx)) = ...
|
||||
enumValues(idx);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function value = enumValue(enumEntry)
|
||||
value = double(enumEntry);
|
||||
end
|
||||
|
||||
function bestData = bestBerByAlgorithmAndGrossRate(data)
|
||||
groupVars = ["algorithm_key", "grossrate_Gbps"];
|
||||
groupId = findgroups(data(:, groupVars));
|
||||
keepIdx = NaN(max(groupId), 1);
|
||||
|
||||
for curGroup = 1:max(groupId)
|
||||
rowIdx = find(groupId == curGroup);
|
||||
[~, localBestIdx] = min(data.BER_plot(rowIdx));
|
||||
keepIdx(curGroup) = rowIdx(localBestIdx);
|
||||
end
|
||||
|
||||
bestData = sortrows(data(keepIdx, :), groupVars);
|
||||
end
|
||||
|
||||
function keep = hasAlgorithmRows(data, algoStyles)
|
||||
keep = false(height(algoStyles), 1);
|
||||
for idx = 1:height(algoStyles)
|
||||
keep(idx) = any(data.algorithm_key == algoStyles.algorithm_key(idx));
|
||||
end
|
||||
end
|
||||
294
projects/Diss/400G_revisit/PLOT_BER_VS_ALGO.m
Normal file
294
projects/Diss/400G_revisit/PLOT_BER_VS_ALGO.m
Normal file
@@ -0,0 +1,294 @@
|
||||
%% 400G BER over bitrate from labor_highspeed.dashboard_ungrouped_alltime
|
||||
% 1) gather all BER entries for one PAM format and fiber length
|
||||
% 2) derive pre-emphasis and precoding groups
|
||||
% 3) plot one bitrate-vs-BER tile per equalizer structure
|
||||
|
||||
clear; clc;
|
||||
|
||||
%% 1) Gather data
|
||||
|
||||
selectedPamLevel = 4;
|
||||
selectedFiberLengthKm = 10;
|
||||
selectedWavelength =1310; % set [] to use all wavelengths
|
||||
selectedRopAttenuation = []; % set [] to use all ROP attenuation values
|
||||
selectedIsMpi = []; % set [] to use all entries
|
||||
|
||||
maxBerForPlot = 0.5;
|
||||
showRawEntries = true;
|
||||
showMedianLine = true;
|
||||
|
||||
eqStyles = defaultEqualizerStyles();
|
||||
comboStyles = defaultCombinationStyles();
|
||||
|
||||
db = DBHandler( ...
|
||||
"dataBase", "labor_highspeed", ...
|
||||
"type", "mysql");
|
||||
db.refresh();
|
||||
|
||||
fp = QueryFilter();
|
||||
fp.where('Runs', 'fiber_length', 'EQUALS', selectedFiberLengthKm);
|
||||
fp.where('Runs', 'pam_level', 'EQUALS', selectedPamLevel);
|
||||
if ~isempty(selectedWavelength)
|
||||
fp.where('Runs', 'wavelength', 'EQUALS', selectedWavelength);
|
||||
end
|
||||
if ~isempty(selectedRopAttenuation)
|
||||
fp.where('Runs', 'rop_attenuation', 'EQUALS', selectedRopAttenuation);
|
||||
end
|
||||
if ~isempty(selectedIsMpi)
|
||||
fp.where('Runs', 'is_mpi', 'EQUALS', selectedIsMpi);
|
||||
end
|
||||
|
||||
selectedFields = db.getTableFieldNames('dashboard_ungrouped_alltime');
|
||||
selectedFields = [selectedFields; {'Runs.precomp_amp'; 'Runs.is_mpi'}];
|
||||
selectedFields = selectedFields(:);
|
||||
|
||||
[rawData, query] = db.queryDB(fp, selectedFields);
|
||||
disp(query);
|
||||
fprintf("Fetched %d 400G result rows.\n", height(rawData));
|
||||
|
||||
%% 2) Clean data and derive analysis groups
|
||||
|
||||
data = rawData;
|
||||
numericFields = ["result_id", "run_id", "eq_id", "bitrate", "grossrate", ...
|
||||
"symbolrate", "pam_level", "wavelength", "fiber_length", "db_mode", ...
|
||||
"rop_attenuation", "precomp_amp", "is_mpi", "numBits", "numBitErr", ...
|
||||
"BER", "numBitErr_precoded", "BER_precoded", "STD", "STDrx", ...
|
||||
"GMI", "AIR", "NGMI", "EVM", "Alpha"];
|
||||
for fieldIdx = 1:numel(numericFields)
|
||||
fieldName = numericFields(fieldIdx);
|
||||
if ismember(fieldName, string(data.Properties.VariableNames))
|
||||
data.(char(fieldName)) = numericColumn(data.(char(fieldName)));
|
||||
end
|
||||
end
|
||||
|
||||
if ~ismember("precomp_amp", string(data.Properties.VariableNames))
|
||||
warning("analyze_db:NoPrecompAmp", ...
|
||||
"Runs.precomp_amp was not returned. Falling back to pre_emphasis = (db_mode == 0).");
|
||||
data.pre_emphasis = data.db_mode == 0;
|
||||
else
|
||||
data.pre_emphasis = derivePreEmphasis(data.precomp_amp, data.db_mode);
|
||||
end
|
||||
|
||||
plotData = buildBerMetricRows(data);
|
||||
plotData = plotData(isfinite(plotData.BER_plot) & ...
|
||||
plotData.BER_plot > 0 & plotData.BER_plot < maxBerForPlot, :);
|
||||
|
||||
if isempty(plotData)
|
||||
warning("analyze_db:NoRows", ...
|
||||
"No rows remain after fiber/PAM/BER filtering.");
|
||||
return
|
||||
end
|
||||
|
||||
plotData.bitrate_Gbps = plotData.bitrate .* 1e-9;
|
||||
plotData.grossrate_Gbps = plotData.grossrate .* 1e-9;
|
||||
|
||||
fprintf("Remaining plotted BER rows: %d\n", height(plotData));
|
||||
disp(groupcounts(plotData, ["equalizer_structure", "pre_emphasis", "precode"]));
|
||||
|
||||
bestPlotData = bestBerByBitrateAndGroup(plotData);
|
||||
fprintf("Keeping %d best-BER rows across bitrate/EQ/pre-emphasis/precode groups.\n", ...
|
||||
height(bestPlotData));
|
||||
|
||||
%% 3) Plot bitrate versus BER
|
||||
|
||||
availableEqStyles = eqStyles(hasEqualizerRows(bestPlotData, eqStyles), :);
|
||||
if isempty(availableEqStyles)
|
||||
warning("analyze_db:NoSelectedEqualizers", ...
|
||||
"None of the configured equalizer styles match the queried rows.");
|
||||
return
|
||||
end
|
||||
|
||||
fig = figure(401); clf;
|
||||
tiledlayout(1, height(availableEqStyles), ...
|
||||
"TileSpacing", "compact", ...
|
||||
"Padding", "compact");
|
||||
|
||||
for eqIdx = 1:height(availableEqStyles)
|
||||
eqStyle = availableEqStyles(eqIdx, :);
|
||||
ax = nexttile; hold(ax, "on");
|
||||
eqMask = equalizerMask(bestPlotData.equalizer_structure, eqStyle.eq);
|
||||
|
||||
for comboIdx = 1:height(comboStyles)
|
||||
comboStyle = comboStyles(comboIdx, :);
|
||||
rowMask = eqMask & ...
|
||||
bestPlotData.pre_emphasis == comboStyle.pre_emphasis & ...
|
||||
bestPlotData.precode == comboStyle.precode;
|
||||
|
||||
if ~any(rowMask)
|
||||
continue
|
||||
end
|
||||
|
||||
comboData = sortrows(bestPlotData(rowMask, :), "bitrate_Gbps");
|
||||
comboColor = emphasisColor(eqStyle.color, comboStyle.pre_emphasis);
|
||||
label = sprintf("%s, %s", eqStyle.name, comboStyle.name);
|
||||
|
||||
if showRawEntries
|
||||
scatter(ax, comboData.bitrate_Gbps, comboData.BER_plot, ...
|
||||
5, ...
|
||||
"Marker", '.', ...
|
||||
"MarkerEdgeColor", comboColor, ...
|
||||
"MarkerFaceColor", comboColor, ...
|
||||
"MarkerEdgeAlpha", 0.25, ...
|
||||
"MarkerFaceAlpha", 0.25, ...
|
||||
"HandleVisibility", "off");
|
||||
end
|
||||
|
||||
if showMedianLine
|
||||
summaryTable = summarizeBerByBitrate(comboData);
|
||||
plot(ax, summaryTable.bitrate_Gbps, summaryTable.median_BER_plot, ...
|
||||
"LineStyle", comboStyle.lineStyle, ...
|
||||
"Marker", eqStyle.marker, ...
|
||||
"MarkerSize", 4, ...
|
||||
"LineWidth", 1.4, ...
|
||||
"Color", comboColor, ...
|
||||
"MarkerFaceColor", comboStyle.markerFaceColor, ...
|
||||
"MarkerEdgeColor", comboColor, ...
|
||||
"DisplayName", label);
|
||||
end
|
||||
end
|
||||
|
||||
yline(ax, [2.2e-4, 4.85e-3, 2e-2], ...
|
||||
"LineWidth", 1, ...
|
||||
"LineStyle", "--", ...
|
||||
"Color", [0.25 0.25 0.25], ...
|
||||
"HandleVisibility", "off");
|
||||
|
||||
title(ax, sprintf("PAM-%d, %s", selectedPamLevel, eqStyle.name));
|
||||
xlabel(ax, "Gross rate [Gb/s]");
|
||||
ylabel(ax, "BER");
|
||||
set(ax, "YScale", "log");
|
||||
ylim(ax, [1e-5, maxBerForPlot]);
|
||||
grid(ax, "on");
|
||||
box(ax, "on");
|
||||
|
||||
xTicks = unique(bestPlotData.bitrate_Gbps(isfinite(bestPlotData.bitrate_Gbps)));
|
||||
if ~isempty(xTicks)
|
||||
xticks(ax, xTicks);
|
||||
xlim(ax, [min(xTicks), max(xTicks)]);
|
||||
end
|
||||
|
||||
legend(ax, "Location", "best", "Interpreter", "none");
|
||||
if exist("beautifyBERplot", "file")
|
||||
beautifyBERplot("logscale", true, "setcolors", false, ...
|
||||
"setmarkers", false, "changemarkers", false);
|
||||
end
|
||||
end
|
||||
|
||||
set(fig, "Position", 1e3 .* [0.1000 0.5500 1.4113 0.3200]);
|
||||
|
||||
%% Local helpers
|
||||
|
||||
function values = numericColumn(values)
|
||||
if iscell(values)
|
||||
values = string(values);
|
||||
end
|
||||
if isstring(values) || ischar(values)
|
||||
values = str2double(values);
|
||||
end
|
||||
values = double(values);
|
||||
end
|
||||
|
||||
function styles = defaultEqualizerStyles()
|
||||
styles = table( ...
|
||||
[equalizer_structure.vnle; ...
|
||||
equalizer_structure.vnle_pf_mlse; ...
|
||||
equalizer_structure.vnle_db_mlse; ...
|
||||
equalizer_structure.ml_mlse], ...
|
||||
["VNLE"; ...
|
||||
"VNLE + PF + MLSE"; ...
|
||||
"VNLE DBt. + MLSE"; ...
|
||||
"ML pre-EQ + Viterbi"], ...
|
||||
["o"; "square"; "diamond"; "^"], ...
|
||||
[clr.Paired.red; ...
|
||||
clr.Paired.green; ...
|
||||
clr.Paired.blue; ...
|
||||
clr.Paired.purple], ...
|
||||
'VariableNames', ["eq", "name", "marker", "color"]);
|
||||
end
|
||||
|
||||
function styles = defaultCombinationStyles()
|
||||
styles = table( ...
|
||||
[true; true; false; false], ...
|
||||
[true; false; true; false], ...
|
||||
["w/ pre-emph., w/ precode"; ...
|
||||
"w/ pre-emph., w/o precode"; ...
|
||||
"w/o pre-emph., w/ precode"; ...
|
||||
"w/o pre-emph., w/o precode"], ...
|
||||
["--"; "-"; "--"; "-"], ...
|
||||
["w"; "w"; "none"; "none"], ...
|
||||
'VariableNames', ["pre_emphasis", "precode", "name", ...
|
||||
"lineStyle", "markerFaceColor"]);
|
||||
end
|
||||
|
||||
function preEmphasis = derivePreEmphasis(precompAmp, dbMode)
|
||||
preEmphasis = false(size(dbMode));
|
||||
|
||||
validPrecomp = isfinite(precompAmp);
|
||||
% In the 400G measurement scripts, -50 dB is the low/no-pre-emphasis
|
||||
% setting, while -38/-37/-34 dB are the active pre-emphasis settings.
|
||||
preEmphasis(validPrecomp) = precompAmp(validPrecomp) > -45;
|
||||
|
||||
missingPrecomp = ~validPrecomp;
|
||||
preEmphasis(missingPrecomp) = dbMode(missingPrecomp) == 0;
|
||||
end
|
||||
|
||||
function plotData = buildBerMetricRows(data)
|
||||
baseRows = data(isfinite(data.BER), :);
|
||||
baseRows.precode = false(height(baseRows), 1);
|
||||
baseRows.BER_plot = baseRows.BER;
|
||||
|
||||
if ismember("BER_precoded", string(data.Properties.VariableNames))
|
||||
precodedRows = data(isfinite(data.BER_precoded), :);
|
||||
precodedRows.precode = true(height(precodedRows), 1);
|
||||
precodedRows.BER_plot = precodedRows.BER_precoded;
|
||||
plotData = [baseRows; precodedRows];
|
||||
else
|
||||
warning("analyze_db:NoPrecodedBer", ...
|
||||
"BER_precoded was not returned. Plotting only precode = 0 rows.");
|
||||
plotData = baseRows;
|
||||
end
|
||||
end
|
||||
|
||||
function mask = equalizerMask(equalizerColumn, eqValue)
|
||||
if isa(equalizerColumn, "equalizer_structure")
|
||||
mask = equalizerColumn == eqValue;
|
||||
elseif isnumeric(equalizerColumn)
|
||||
mask = double(equalizerColumn) == double(int32(eqValue));
|
||||
else
|
||||
mask = string(equalizerColumn) == string(eqValue);
|
||||
end
|
||||
end
|
||||
|
||||
function keep = hasEqualizerRows(data, eqStyles)
|
||||
keep = false(height(eqStyles), 1);
|
||||
for idx = 1:height(eqStyles)
|
||||
keep(idx) = any(equalizerMask(data.equalizer_structure, eqStyles.eq(idx)));
|
||||
end
|
||||
end
|
||||
|
||||
function summaryTable = summarizeBerByBitrate(data)
|
||||
summaryTable = groupsummary(data, "bitrate_Gbps", "median", "BER_plot");
|
||||
summaryTable = sortrows(summaryTable, "bitrate_Gbps");
|
||||
end
|
||||
|
||||
function bestData = bestBerByBitrateAndGroup(data)
|
||||
groupVars = ["equalizer_structure", "pre_emphasis", "precode", "bitrate_Gbps"];
|
||||
groupId = findgroups(data(:, groupVars));
|
||||
keepIdx = NaN(max(groupId), 1);
|
||||
|
||||
for curGroup = 1:max(groupId)
|
||||
rowIdx = find(groupId == curGroup);
|
||||
[~, localBestIdx] = min(data.BER_plot(rowIdx));
|
||||
keepIdx(curGroup) = rowIdx(localBestIdx);
|
||||
end
|
||||
|
||||
bestData = sortrows(data(keepIdx, :), groupVars);
|
||||
end
|
||||
|
||||
function color = emphasisColor(baseColor, preEmphasis)
|
||||
if preEmphasis
|
||||
color = 0.65 .* baseColor + 0.35;
|
||||
else
|
||||
color = baseColor;
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,242 @@
|
||||
%% Duobinary transmission: BER over bitrate for detection algorithms
|
||||
% DB transmission means the sequence was precoded and encoded at the Tx
|
||||
% (Runs.db_mode = db_mode.db_encoded). In this stored-result convention:
|
||||
% BER -> VNLE + MLSE
|
||||
% BER_precoded -> VNLE + memoryless detection
|
||||
|
||||
clear; clc;
|
||||
|
||||
%% 1) Query data
|
||||
|
||||
selectedPamLevels = [4, 6, 8];
|
||||
selectedFiberLengthKm = 10;
|
||||
selectedWavelengthNm = 1310;
|
||||
selectedRopAttenuation = 0;
|
||||
selectedIsMpi = 0;
|
||||
selectedDbMode = db_mode.db_encoded;
|
||||
selectedEqualizerStructure = equalizer_structure.db_encoded;
|
||||
|
||||
maxBerForPlot = 0.5;
|
||||
showRawEntries = false;
|
||||
showBestLine = true;
|
||||
|
||||
db = DBHandler( ...
|
||||
"dataBase", "labor_highspeed", ...
|
||||
"type", "mysql", ...
|
||||
"server", "192.168.178.192", ...
|
||||
"user", "silas", ...
|
||||
"password", "silas");
|
||||
db.refresh();
|
||||
|
||||
fp = QueryFilter();
|
||||
fp.where('Runs', 'fiber_length', 'EQUALS', selectedFiberLengthKm);
|
||||
fp.where('Runs', 'wavelength', 'EQUALS', selectedWavelengthNm);
|
||||
fp.where('Runs', 'rop_attenuation', 'EQUALS', selectedRopAttenuation);
|
||||
fp.where('Runs', 'is_mpi', 'EQUALS', selectedIsMpi);
|
||||
fp.where('Runs', 'db_mode', 'EQUALS', double(selectedDbMode));
|
||||
|
||||
selectedFields = db.getTableFieldNames('dashboard_ungrouped_alltime');
|
||||
selectedFields = appendMissingFields(selectedFields, {'Runs.is_mpi'});
|
||||
selectedFields = selectedFields(:);
|
||||
|
||||
[rawData, query] = db.queryDB(fp, selectedFields);
|
||||
disp(query);
|
||||
fprintf("Fetched %d duobinary result rows.\n", height(rawData));
|
||||
|
||||
%% 2) Clean and reshape BER metrics
|
||||
|
||||
data = rawData;
|
||||
numericFields = ["result_id", "run_id", "eq_id", "bitrate", "grossrate", ...
|
||||
"symbolrate", "pam_level", "wavelength", "fiber_length", "db_mode", ...
|
||||
"rop_attenuation", "is_mpi", "numBits", "numBitErr", "BER", ...
|
||||
"numBitErr_precoded", "BER_precoded", "STD", "STDrx", ...
|
||||
"GMI", "AIR", "NGMI", "EVM", "Alpha"];
|
||||
for fieldIdx = 1:numel(numericFields)
|
||||
fieldName = numericFields(fieldIdx);
|
||||
if ismember(fieldName, string(data.Properties.VariableNames))
|
||||
data.(char(fieldName)) = numericColumn(data.(char(fieldName)));
|
||||
end
|
||||
end
|
||||
|
||||
data = data(ismember(data.pam_level, selectedPamLevels), :);
|
||||
if ismember("equalizer_structure", string(data.Properties.VariableNames)) && ...
|
||||
~isempty(selectedEqualizerStructure)
|
||||
data = data(equalizerMask(data.equalizer_structure, selectedEqualizerStructure), :);
|
||||
end
|
||||
|
||||
plotData = buildDetectionMetricRows(data);
|
||||
plotData = plotData(isfinite(plotData.BER_plot) & ...
|
||||
plotData.BER_plot > 0 & plotData.BER_plot < maxBerForPlot, :);
|
||||
|
||||
if isempty(plotData)
|
||||
warning("plot_duobinary_detection:NoRows", ...
|
||||
"No rows remain after duobinary/PAM/wavelength/BER filtering.");
|
||||
return
|
||||
end
|
||||
|
||||
plotData.bitrate_Gbps = plotData.bitrate .* 1e-9;
|
||||
plotData = sortrows(plotData, ...
|
||||
["pam_level", "wavelength", "detection_type", "bitrate_Gbps", "run_id"]);
|
||||
|
||||
fprintf("Remaining plotted BER rows: %d\n", height(plotData));
|
||||
disp(groupcounts(plotData, ["pam_level", "wavelength", "detection_type"]));
|
||||
|
||||
%% 3) Plot BER versus bitrate
|
||||
|
||||
detectionStyles = defaultDetectionStyles();
|
||||
availablePamLevels = selectedPamLevels(ismember(selectedPamLevels, unique(plotData.pam_level).'));
|
||||
|
||||
fig = figure(430); clf;
|
||||
tiledlayout(1, numel(availablePamLevels), ...
|
||||
"TileSpacing", "compact", ...
|
||||
"Padding", "compact");
|
||||
|
||||
for pamIdx = 1:numel(availablePamLevels)
|
||||
pamLevel = availablePamLevels(pamIdx);
|
||||
ax = nexttile; hold(ax, "on");
|
||||
pamMask = plotData.pam_level == pamLevel;
|
||||
|
||||
for styleIdx = 1:height(detectionStyles)
|
||||
style = detectionStyles(styleIdx, :);
|
||||
rowMask = pamMask & plotData.detection_type == style.detection_type;
|
||||
if ~any(rowMask)
|
||||
continue
|
||||
end
|
||||
|
||||
detectionData = sortrows(plotData(rowMask, :), "bitrate_Gbps");
|
||||
summaryTable = summarizeBerByBitrate(detectionData);
|
||||
|
||||
if showRawEntries
|
||||
scatter(ax, detectionData.bitrate_Gbps, detectionData.BER_plot, ...
|
||||
9, ...
|
||||
"Marker", ".", ...
|
||||
"MarkerEdgeColor", style.color, ...
|
||||
"MarkerFaceColor", style.color, ...
|
||||
"MarkerEdgeAlpha", 0.25, ...
|
||||
"MarkerFaceAlpha", 0.25, ...
|
||||
"HandleVisibility", "off");
|
||||
end
|
||||
|
||||
if showBestLine
|
||||
plot(ax, summaryTable.bitrate_Gbps, summaryTable.BER_plot, ...
|
||||
"LineStyle", style.lineStyle, ...
|
||||
"Marker", style.marker, ...
|
||||
"MarkerSize", 5, ...
|
||||
"LineWidth", 1.4, ...
|
||||
"Color", style.color, ...
|
||||
"MarkerFaceColor", style.markerFaceColor, ...
|
||||
"MarkerEdgeColor", style.color, ...
|
||||
"DisplayName", style.name);
|
||||
end
|
||||
end
|
||||
|
||||
yline(ax, [2.2e-4, 4.85e-3, 2e-2], ...
|
||||
"LineWidth", 1, ...
|
||||
"LineStyle", "--", ...
|
||||
"Color", [0.25 0.25 0.25], ...
|
||||
"HandleVisibility", "off");
|
||||
|
||||
title(ax, sprintf("PAM-%d, %.0f nm", pamLevel, selectedWavelengthNm));
|
||||
xlabel(ax, "Bitrate [Gb/s]");
|
||||
ylabel(ax, "BER");
|
||||
set(ax, "YScale", "log");
|
||||
ylim(ax, [1e-5, maxBerForPlot]);
|
||||
grid(ax, "on");
|
||||
box(ax, "on");
|
||||
|
||||
xTicks = unique(plotData.bitrate_Gbps(pamMask & isfinite(plotData.bitrate_Gbps)));
|
||||
if ~isempty(xTicks)
|
||||
xticks(ax, xTicks);
|
||||
xlim(ax, [min(xTicks), max(xTicks)]);
|
||||
end
|
||||
|
||||
legend(ax, "Location", "best", "Interpreter", "none");
|
||||
if exist("beautifyBERplot", "file")
|
||||
beautifyBERplot("logscale", true, "setcolors", false, ...
|
||||
"setmarkers", false, "changemarkers", false);
|
||||
end
|
||||
end
|
||||
|
||||
set(fig, "Position", 1e3 .* [0.1000 0.5500 1.4113 0.3200]);
|
||||
|
||||
%% Local helpers
|
||||
|
||||
function fields = appendMissingFields(fields, extraFields)
|
||||
fields = cellstr(fields);
|
||||
extraFields = cellstr(extraFields);
|
||||
for idx = 1:numel(extraFields)
|
||||
if ~any(strcmp(fields, extraFields{idx}))
|
||||
fields{end+1, 1} = extraFields{idx}; %#ok<AGROW>
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function values = numericColumn(values)
|
||||
if iscell(values)
|
||||
values = string(values);
|
||||
end
|
||||
if isstring(values) || ischar(values)
|
||||
values = str2double(values);
|
||||
end
|
||||
values = double(values);
|
||||
end
|
||||
|
||||
function plotData = buildDetectionMetricRows(data)
|
||||
baseRows = data(isfinite(data.BER), :);
|
||||
baseRows.detection_type = repmat("VNLE + MLSE", height(baseRows), 1);
|
||||
baseRows.BER_plot = baseRows.BER;
|
||||
|
||||
if ismember("BER_precoded", string(data.Properties.VariableNames))
|
||||
memorylessRows = data(isfinite(data.BER_precoded), :);
|
||||
memorylessRows.detection_type = repmat("VNLE + memoryless", ...
|
||||
height(memorylessRows), 1);
|
||||
memorylessRows.BER_plot = memorylessRows.BER_precoded;
|
||||
plotData = [baseRows; memorylessRows];
|
||||
else
|
||||
warning("plot_duobinary_detection:NoPrecodedBer", ...
|
||||
"BER_precoded was not returned. Plotting only VNLE + MLSE rows.");
|
||||
plotData = baseRows;
|
||||
end
|
||||
end
|
||||
|
||||
function styles = defaultDetectionStyles()
|
||||
styles = table( ...
|
||||
["VNLE + MLSE"; "VNLE + memoryless"], ...
|
||||
["VNLE + MLSE"; "VNLE + memoryless"], ...
|
||||
["o"; "square"], ...
|
||||
["-"; "--"], ...
|
||||
["w"; "none"], ...
|
||||
[clr.Paired.blue; clr.Paired.orange], ...
|
||||
'VariableNames', ["detection_type", "name", "marker", ...
|
||||
"lineStyle", "markerFaceColor", "color"]);
|
||||
end
|
||||
|
||||
function mask = equalizerMask(equalizerColumn, eqValue)
|
||||
if isa(equalizerColumn, "equalizer_structure")
|
||||
mask = equalizerColumn == eqValue;
|
||||
elseif isnumeric(equalizerColumn)
|
||||
mask = double(equalizerColumn) == enumValue(eqValue);
|
||||
else
|
||||
equalizerString = string(equalizerColumn);
|
||||
numericEqualizer = str2double(equalizerString);
|
||||
mask = equalizerString == string(eqValue) | numericEqualizer == enumValue(eqValue);
|
||||
end
|
||||
end
|
||||
|
||||
function value = enumValue(enumEntry)
|
||||
value = double(enumEntry);
|
||||
end
|
||||
|
||||
function summaryTable = summarizeBerByBitrate(data)
|
||||
groupId = findgroups(data.bitrate_Gbps);
|
||||
keepIdx = NaN(max(groupId), 1);
|
||||
|
||||
for curGroup = 1:max(groupId)
|
||||
rowIdx = find(groupId == curGroup);
|
||||
[~, localBestIdx] = min(data.BER_plot(rowIdx));
|
||||
keepIdx(curGroup) = rowIdx(localBestIdx);
|
||||
end
|
||||
|
||||
summaryTable = data(keepIdx, :);
|
||||
summaryTable = sortrows(summaryTable, "bitrate_Gbps");
|
||||
end
|
||||
BIN
projects/Diss/400G_revisit/duobinary_partly_failed.mat
Normal file
BIN
projects/Diss/400G_revisit/duobinary_partly_failed.mat
Normal file
Binary file not shown.
361
projects/Diss/400G_revisit/investigate_400g_algorithms.m
Normal file
361
projects/Diss/400G_revisit/investigate_400g_algorithms.m
Normal file
@@ -0,0 +1,361 @@
|
||||
% === 400G DSP settings ===
|
||||
dsp_options = struct();
|
||||
dsp_options.mode = "run_id";
|
||||
dsp_options.recipe = @dsp_400g_recipe;
|
||||
dsp_options.append_to_db = false;
|
||||
% dsp_options.append_mpi_reduction_db = false;
|
||||
dsp_options.start_occurence = 1;
|
||||
dsp_options.max_occurences = 1;
|
||||
dsp_options.debug_plots = false;
|
||||
|
||||
dsp_options.database_type = "mysql";
|
||||
dsp_options.dataBase = "labor_highspeed";
|
||||
|
||||
if ismac
|
||||
dsp_options.storage_path = "/Volumes/media/labdata/sioe_labor";
|
||||
else
|
||||
dsp_options.storage_path = "W:\labdata\sioe_labor";
|
||||
end
|
||||
dsp_options.server = "192.168.178.192";
|
||||
dsp_options.port = 3306;
|
||||
dsp_options.user = "silas";
|
||||
dsp_options.password = "silas";
|
||||
|
||||
db = DBHandler("dataBase", [dsp_options.dataBase], ...
|
||||
"type", dsp_options.database_type, ...
|
||||
"server", dsp_options.server, ...
|
||||
"user", dsp_options.user, ...
|
||||
"password", dsp_options.password);
|
||||
|
||||
%% Select runs
|
||||
|
||||
maxRunIds = 1; % keep small until the recipe settings are settled
|
||||
|
||||
fp = QueryFilter();
|
||||
fp.where('Runs','fiber_length','EQUALS', 10);
|
||||
fp.where('Runs','wavelength','EQUALS', 1310);
|
||||
fp.where('Runs','bitrate','EQUALS', 330e9);
|
||||
fp.where('Runs','pam_level','EQUALS', 4);
|
||||
fp.where('Runs','rop_attenuation','EQUALS', 0);
|
||||
fp.where('Runs','is_mpi','EQUALS', 0);
|
||||
fp.where('Runs', 'db_mode','EQUALS', 2);
|
||||
|
||||
fields = db.getTableFieldNames('Runs');
|
||||
[dataTable, query] = db.queryDB(fp, fields);
|
||||
disp(query);
|
||||
|
||||
dataTable = sortrows(dataTable, {'bitrate', 'run_id'});
|
||||
|
||||
% dataTable = dataTable(1:maxRunIds, :);
|
||||
|
||||
run_ids = dataTable.run_id(:).';
|
||||
|
||||
if isempty(run_ids)
|
||||
error("investigate_400g_algorithms:MissingRunIds", ...
|
||||
"No 400G runs match the current filters.");
|
||||
end
|
||||
|
||||
fprintf("Selected %d run_id(s): %s\n", numel(run_ids), mat2str(run_ids));
|
||||
|
||||
%% Parameter sweep
|
||||
|
||||
dsp_options.userParameters = struct();
|
||||
dsp_options.userParameters.run_ml_mlse_db = true;
|
||||
dsp_options.userParameters.run_mlse_db = true;
|
||||
|
||||
% Enable/disable equalizer branches.
|
||||
% dsp_options.userParameters.run_ffe = false;
|
||||
% dsp_options.userParameters.run_vnle = false;
|
||||
% dsp_options.userParameters.run_dfe = false;
|
||||
% dsp_options.userParameters.run_vnle_mlse = true;
|
||||
% dsp_options.userParameters.run_dbtgt = true;
|
||||
|
||||
% Examples for parameter loops. DataStorage expands every vector-valued field.
|
||||
% dsp_options.userParameters.len_tr = 4096*2;
|
||||
% dsp_options.userParameters.pf_ncoeffs = 1;
|
||||
|
||||
% dsp_options.userParameters.decoding_mode = [db_decoder.memoryless,db_decoder.sequencedetection];
|
||||
% dsp_options.userParameters.pf_ncoeffs = [1, 2, 3];
|
||||
% dsp_options.userParameters.mu_dc = [0, 1e-5, 1e-4];
|
||||
% dsp_options.userParameters.run_ml_mlse_db = [false, true];
|
||||
% dsp_options.userParameters.run_mlse_db = [false, true];
|
||||
|
||||
wh = DataStorage(dsp_options.userParameters);
|
||||
|
||||
n_realizations = (dsp_options.max_occurences - dsp_options.start_occurence + 1);
|
||||
n_userparams = prod(wh.dim);
|
||||
n_run_ids = numel(run_ids);
|
||||
parallel_jobs = n_userparams * n_run_ids;
|
||||
queried_jobs = n_realizations * n_userparams * n_run_ids;
|
||||
|
||||
fprintf("-> [ %d run_id(s) x %d userParam combination(s) = %d job(s) ] x %d realizations = %d total jobs \n", ...
|
||||
n_run_ids, n_userparams, parallel_jobs, n_realizations, queried_jobs);
|
||||
|
||||
%% Run
|
||||
|
||||
[results, wh] = submitJobs(run_ids, dsp_options, processingMode.serial, ...
|
||||
"wh", wh, ...
|
||||
"waitbar", true);
|
||||
|
||||
|
||||
%% Quick result overview
|
||||
|
||||
printBerSummary(wh);
|
||||
plotBerVsBitrateQuick(wh, dataTable);
|
||||
|
||||
function printBerSummary(wh)
|
||||
storageNames = fieldnames(wh.sto);
|
||||
if isempty(storageNames)
|
||||
fprintf("No non-empty recipe outputs were stored.\n");
|
||||
return
|
||||
end
|
||||
|
||||
fprintf("\nBER summary by stored package:\n");
|
||||
for storageIdx = 1:numel(storageNames)
|
||||
storageName = storageNames{storageIdx};
|
||||
values = wh.sto.(storageName)(:).';
|
||||
berValues = extractBerValues(values);
|
||||
|
||||
if isempty(berValues)
|
||||
fprintf(" %-18s no BER values\n", storageName);
|
||||
else
|
||||
fprintf(" %-18s min %.3e | median %.3e | n %d\n", ...
|
||||
storageName, min(berValues), median(berValues), numel(berValues));
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function berValues = extractBerValues(values)
|
||||
berValues = [];
|
||||
for valueIdx = 1:numel(values)
|
||||
packageCell = values{valueIdx};
|
||||
if isempty(packageCell)
|
||||
continue
|
||||
end
|
||||
if ~iscell(packageCell)
|
||||
packageCell = {packageCell};
|
||||
end
|
||||
|
||||
for packageIdx = 1:numel(packageCell)
|
||||
package = packageCell{packageIdx};
|
||||
if isstruct(package) && isfield(package, "metrics")
|
||||
metrics = package.metrics;
|
||||
if isprop(metrics, "BER")
|
||||
berValues(end+1) = metrics.BER; %#ok<AGROW>
|
||||
elseif isstruct(metrics) && isfield(metrics, "BER")
|
||||
berValues(end+1) = metrics.BER; %#ok<AGROW>
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
berValues = berValues(isfinite(berValues));
|
||||
end
|
||||
|
||||
function plotBerVsBitrateQuick(wh, dataTable)
|
||||
plotData = buildQuickBerTable(wh, dataTable);
|
||||
if isempty(plotData)
|
||||
fprintf("No BER values available for quick BER-vs-bitrate plot.\n");
|
||||
return
|
||||
end
|
||||
|
||||
storageNames = unique(plotData.storage_name, "stable");
|
||||
decodingModes = [db_decoder.memoryless, db_decoder.sequencedetection];
|
||||
berMetrics = ["BER", "BER_precoded"];
|
||||
lineStyles = ["-", ":"];
|
||||
rawMarkers = [".", "x"];
|
||||
markers = ["o", "square", "diamond", "^", "v", ">"];
|
||||
|
||||
fig = figure(402); clf;
|
||||
ax = axes(fig); hold(ax, "on");
|
||||
|
||||
for storageIdx = 1:numel(storageNames)
|
||||
storageName = storageNames(storageIdx);
|
||||
for modeIdx = 1:numel(decodingModes)
|
||||
decodingMode = decodingModes(modeIdx);
|
||||
for metricIdx = 1:numel(berMetrics)
|
||||
metricName = berMetrics(metricIdx);
|
||||
rowMask = plotData.storage_name == storageName & ...
|
||||
plotData.decoding_mode == decodingMode & ...
|
||||
plotData.metric_name == metricName;
|
||||
if ~any(rowMask)
|
||||
continue
|
||||
end
|
||||
|
||||
modeData = sortrows(plotData(rowMask, :), "bitrate_Gbps");
|
||||
summaryData = groupsummary(modeData, "bitrate_Gbps", "median", "BER");
|
||||
summaryData = sortrows(summaryData, "bitrate_Gbps");
|
||||
color = quickPlotColor(modeIdx);
|
||||
marker = markers(1 + mod(storageIdx - 1, numel(markers)));
|
||||
label = sprintf("%s, %s, %s", storageName, ...
|
||||
decodingModeLabel(decodingMode), metricName);
|
||||
|
||||
scatter(ax, modeData.bitrate_Gbps, modeData.BER, ...
|
||||
12, ...
|
||||
"Marker", rawMarkers(metricIdx), ...
|
||||
"MarkerEdgeColor", color, ...
|
||||
"MarkerEdgeAlpha", 0.25, ...
|
||||
"HandleVisibility", "off");
|
||||
|
||||
plot(ax, summaryData.bitrate_Gbps, summaryData.median_BER, ...
|
||||
"LineStyle", lineStyles(metricIdx), ...
|
||||
"Marker", marker, ...
|
||||
"MarkerSize", 5, ...
|
||||
"LineWidth", 1.4, ...
|
||||
"Color", color, ...
|
||||
"DisplayName", label);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
yline(ax, [2.2e-4, 4.85e-3, 2e-2], ...
|
||||
"LineWidth", 1, ...
|
||||
"LineStyle", "--", ...
|
||||
"Color", [0.25 0.25 0.25], ...
|
||||
"HandleVisibility", "off");
|
||||
|
||||
xlabel(ax, "Bitrate [Gb/s]");
|
||||
ylabel(ax, "BER");
|
||||
title(ax, "Quick BER vs bitrate");
|
||||
set(ax, "YScale", "log");
|
||||
grid(ax, "on");
|
||||
box(ax, "on");
|
||||
legend(ax, "Location", "best", "Interpreter", "none");
|
||||
|
||||
if exist("beautifyBERplot", "file")
|
||||
beautifyBERplot("logscale", true, "setcolors", false, ...
|
||||
"setmarkers", false, "changemarkers", false);
|
||||
end
|
||||
end
|
||||
|
||||
function plotData = buildQuickBerTable(wh, dataTable)
|
||||
storageNames = fieldnames(wh.sto);
|
||||
if isempty(storageNames)
|
||||
plotData = table();
|
||||
return
|
||||
end
|
||||
|
||||
runIds = dataTable.run_id(:);
|
||||
bitrates = dataTable.bitrate(:);
|
||||
|
||||
storageCol = strings(0, 1);
|
||||
runIdCol = zeros(0, 1);
|
||||
bitrateCol = zeros(0, 1);
|
||||
decodingCol = db_decoder.empty(0, 1);
|
||||
metricCol = strings(0, 1);
|
||||
berCol = zeros(0, 1);
|
||||
|
||||
for storageIdx = 1:numel(storageNames)
|
||||
storageName = storageNames{storageIdx};
|
||||
storageValues = wh.sto.(storageName);
|
||||
for linIdx = 1:numel(storageValues)
|
||||
[phys, storedValue] = wh.getPhysAndValueByLinIndex(storageName, linIdx);
|
||||
metricRows = extractBerMetricRows({storedValue});
|
||||
if isempty(metricRows) || ~isfield(phys, "decoding_mode")
|
||||
continue
|
||||
end
|
||||
|
||||
runId = resolveRunId(phys, runIds);
|
||||
bitrate = resolveBitrate(runId, runIds, bitrates);
|
||||
if ~isfinite(bitrate)
|
||||
continue
|
||||
end
|
||||
|
||||
nRows = height(metricRows);
|
||||
storageCol(end+1:end+nRows, 1) = string(storageName);
|
||||
runIdCol(end+1:end+nRows, 1) = double(runId);
|
||||
bitrateCol(end+1:end+nRows, 1) = double(bitrate);
|
||||
decodingCol(end+1:end+nRows, 1) = phys.decoding_mode;
|
||||
metricCol(end+1:end+nRows, 1) = metricRows.metric_name;
|
||||
berCol(end+1:end+nRows, 1) = metricRows.BER;
|
||||
end
|
||||
end
|
||||
|
||||
plotData = table(storageCol, runIdCol, bitrateCol, decodingCol, metricCol, berCol, ...
|
||||
'VariableNames', ["storage_name", "run_id", "bitrate", ...
|
||||
"decoding_mode", "metric_name", "BER"]);
|
||||
if ~isempty(plotData)
|
||||
plotData = plotData(isfinite(plotData.BER) & plotData.BER > 0, :);
|
||||
plotData.bitrate_Gbps = plotData.bitrate .* 1e-9;
|
||||
end
|
||||
end
|
||||
|
||||
function metricRows = extractBerMetricRows(values)
|
||||
metricNames = strings(0, 1);
|
||||
berValues = zeros(0, 1);
|
||||
requestedMetrics = ["BER", "BER_precoded"];
|
||||
|
||||
for valueIdx = 1:numel(values)
|
||||
packageCell = values{valueIdx};
|
||||
if isempty(packageCell)
|
||||
continue
|
||||
end
|
||||
if ~iscell(packageCell)
|
||||
packageCell = {packageCell};
|
||||
end
|
||||
|
||||
for packageIdx = 1:numel(packageCell)
|
||||
package = packageCell{packageIdx};
|
||||
if ~isstruct(package) || ~isfield(package, "metrics")
|
||||
continue
|
||||
end
|
||||
|
||||
metrics = package.metrics;
|
||||
for metricIdx = 1:numel(requestedMetrics)
|
||||
metricName = requestedMetrics(metricIdx);
|
||||
value = readMetricValue(metrics, metricName);
|
||||
if isfinite(value)
|
||||
metricNames(end+1, 1) = metricName; %#ok<AGROW>
|
||||
berValues(end+1, 1) = value; %#ok<AGROW>
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
metricRows = table(metricNames, berValues, ...
|
||||
'VariableNames', ["metric_name", "BER"]);
|
||||
end
|
||||
|
||||
function value = readMetricValue(metrics, metricName)
|
||||
value = NaN;
|
||||
fieldName = char(metricName);
|
||||
if isstruct(metrics) && isfield(metrics, fieldName)
|
||||
value = metrics.(fieldName);
|
||||
elseif isobject(metrics) && isprop(metrics, fieldName)
|
||||
value = metrics.(fieldName);
|
||||
end
|
||||
end
|
||||
|
||||
function runId = resolveRunId(phys, runIds)
|
||||
if isfield(phys, "run_id")
|
||||
runId = phys.run_id;
|
||||
else
|
||||
runId = runIds(1);
|
||||
end
|
||||
end
|
||||
|
||||
function bitrate = resolveBitrate(runId, runIds, bitrates)
|
||||
rowIdx = find(double(runIds) == double(runId), 1, "first");
|
||||
if isempty(rowIdx)
|
||||
bitrate = NaN;
|
||||
else
|
||||
bitrate = bitrates(rowIdx);
|
||||
end
|
||||
end
|
||||
|
||||
function color = quickPlotColor(modeIdx)
|
||||
colors = [ ...
|
||||
0.1059 0.6196 0.4667; ...
|
||||
0.8510 0.3725 0.0078];
|
||||
color = colors(1 + mod(modeIdx - 1, size(colors, 1)), :);
|
||||
end
|
||||
|
||||
function label = decodingModeLabel(decodingMode)
|
||||
switch decodingMode
|
||||
case db_decoder.memoryless
|
||||
label = "memoryless";
|
||||
case db_decoder.sequencedetection
|
||||
label = "sequence detection";
|
||||
otherwise
|
||||
label = string(decodingMode);
|
||||
end
|
||||
end
|
||||
@@ -9,7 +9,7 @@ clear; clc;
|
||||
|
||||
studyName = "block_update_sweep";
|
||||
selectedBlockUpdate = 1; % set [] to pool all block_update values
|
||||
selectedPamLevels = 6; % set [] to use all PAM levels in the query result
|
||||
selectedPamLevels = 4; % set [] to use all PAM levels in the query result
|
||||
|
||||
algorithmSelection = table( ...
|
||||
["plain_ffe"; ...
|
||||
@@ -17,7 +17,7 @@ algorithmSelection = table( ...
|
||||
"a2_residual"; ...
|
||||
"a1_moving_average"; ...
|
||||
"dc_tracking"], ...
|
||||
[true; true; true; true; true], ...
|
||||
[true; false; false; false; true], ...
|
||||
'VariableNames', ["algorithm", "enabled"]);
|
||||
selectedAlgorithms = algorithmSelection.algorithm(algorithmSelection.enabled);
|
||||
|
||||
@@ -286,6 +286,81 @@ for regimeIdx = 1:numel(regimeNames)
|
||||
% mat2tikz_improved("C:/Users/Silas/Documents/6971e0b65b380ca6d71c837f/04_Experimental_Evaluation/tikz/mpi/ber_vs_sir_" + regimeName + ".tikz","cleanfigure",1);
|
||||
end
|
||||
|
||||
%% 4) Plot BER spread over SIR by delay/coherence regime and algorithm
|
||||
|
||||
spreadTable = berSpreadSummary(cleanData, groupVars);
|
||||
fprintf("Calculated BER spread for %d regime/PAM/algorithm/SIR groups.\n", ...
|
||||
height(spreadTable));
|
||||
|
||||
figure(); clf; hold on;
|
||||
|
||||
for regimeIdx = 1:numel(regimeNames)
|
||||
regimeName = regimeNames(regimeIdx);
|
||||
lineStyle = pathRegimeLineStyle(regimeName);
|
||||
|
||||
for algIdx = 1:numel(selectedAlgorithms)
|
||||
algorithmName = selectedAlgorithms(algIdx);
|
||||
algColor = algorithmColor(algorithmName);
|
||||
marker = algorithmMarker(algorithmName, algorithmMarkers);
|
||||
displayName = algorithmDisplayName(algorithmName);
|
||||
|
||||
curveMask = spreadTable.path_regime == regimeName & ...
|
||||
spreadTable.algorithm == algorithmName;
|
||||
|
||||
if ~any(curveMask)
|
||||
continue
|
||||
end
|
||||
|
||||
curveTable = sortrows(spreadTable(curveMask, :), ...
|
||||
["pam_level", "sir_exact"]);
|
||||
|
||||
for pamIdx = 1:numel(selectedPamLevels)
|
||||
pamLevel = selectedPamLevels(pamIdx);
|
||||
pamMask = curveTable.pam_level == pamLevel;
|
||||
if ~any(pamMask)
|
||||
continue
|
||||
end
|
||||
|
||||
x = curveTable.sir_exact(pamMask).';
|
||||
y = curveTable.std_log10_BER(pamMask).';
|
||||
valid = isfinite(x) & isfinite(y);
|
||||
|
||||
if ~any(valid)
|
||||
continue
|
||||
end
|
||||
|
||||
if isscalar(selectedPamLevels)
|
||||
legendText = sprintf("%s, %s", displayName, regimeName);
|
||||
else
|
||||
legendText = sprintf("%s, %s, PAM %.0f", ...
|
||||
displayName, regimeName, pamLevel);
|
||||
end
|
||||
|
||||
plot(x(valid), y(valid), ...
|
||||
"LineStyle", lineStyle, ...
|
||||
"Marker", marker, ...
|
||||
"MarkerSize", 3.5, ...
|
||||
"LineWidth", 1, ...
|
||||
"Color", algColor, ...
|
||||
"MarkerFaceColor", "w", ...
|
||||
"MarkerEdgeColor", algColor, ...
|
||||
"DisplayName", legendText);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
xlabel("SIR (dB)");
|
||||
ylabel("Std. dev. of log_{10}(BER)");
|
||||
title("BER spread over SIR by delay regime and algorithm");
|
||||
xlim([15, 45]);
|
||||
grid on;
|
||||
box on;
|
||||
legend("Location", "northeast", "Interpreter", "none");
|
||||
|
||||
if exist("beautifyBERplot", "file")
|
||||
beautifyBERplot("logscale", false, "setcolors", false, "setmarkers", false);
|
||||
end
|
||||
|
||||
%% Local helpers
|
||||
|
||||
function values = numericColumn(values)
|
||||
@@ -487,6 +562,38 @@ function yFit = fitLogBer(x, y, xFit, fitOrder)
|
||||
yFit = 10 .^ polyval(coeff, xFit);
|
||||
end
|
||||
|
||||
function spreadTable = berSpreadSummary(cleanData, groupVars)
|
||||
summaryGroups = groupsummary(cleanData, groupVars);
|
||||
sirExactTable = groupsummary(cleanData, groupVars, "median", "sir_exact");
|
||||
summaryGroups = sortrows(summaryGroups, groupVars);
|
||||
sirExactTable = sortrows(sirExactTable, groupVars);
|
||||
summaryGroups.sir_exact = sirExactTable.median_sir_exact;
|
||||
|
||||
stdLogBer = NaN(height(summaryGroups), 1);
|
||||
stdBer = NaN(height(summaryGroups), 1);
|
||||
for groupIdx = 1:height(summaryGroups)
|
||||
rowMask = true(height(cleanData), 1);
|
||||
for varIdx = 1:numel(groupVars)
|
||||
varName = groupVars(varIdx);
|
||||
rowMask = rowMask & cleanData.(char(varName)) == ...
|
||||
summaryGroups.(char(varName))(groupIdx);
|
||||
end
|
||||
|
||||
berValues = cleanData.BER(rowMask);
|
||||
berValues = berValues(isfinite(berValues) & berValues > 0);
|
||||
if isempty(berValues)
|
||||
continue
|
||||
end
|
||||
|
||||
stdLogBer(groupIdx) = std(log10(berValues), 0, "omitnan");
|
||||
stdBer(groupIdx) = std(berValues, 0, "omitnan");
|
||||
end
|
||||
|
||||
spreadTable = summaryGroups;
|
||||
spreadTable.std_log10_BER = stdLogBer;
|
||||
spreadTable.std_BER = stdBer;
|
||||
end
|
||||
|
||||
function label = algorithmDisplayName(algorithmName)
|
||||
algorithmName = string(algorithmName);
|
||||
switch algorithmName
|
||||
@@ -532,3 +639,18 @@ function marker = algorithmMarker(algorithmName, algorithmMarkers)
|
||||
end
|
||||
marker = algorithmMarkers{mod(markerIdx - 1, numel(algorithmMarkers)) + 1};
|
||||
end
|
||||
|
||||
function lineStyle = pathRegimeLineStyle(regimeName)
|
||||
switch string(regimeName)
|
||||
case "0-1 m"
|
||||
lineStyle = "-";
|
||||
case "10-100 m"
|
||||
lineStyle = "--";
|
||||
case "300 m"
|
||||
lineStyle = ":";
|
||||
case "1000 m"
|
||||
lineStyle = "-.";
|
||||
otherwise
|
||||
lineStyle = "-";
|
||||
end
|
||||
end
|
||||
|
||||
@@ -132,7 +132,7 @@ summaryTable = addBerStdBounds(summaryTable, cleanData, groupVars);
|
||||
|
||||
blockUpdates = unique(cleanData.block_update(isfinite(cleanData.block_update))).';
|
||||
blockUpdates = sort(blockUpdates);
|
||||
helperBlockUpdates = unique(blockUpdates([1, end]), "stable");
|
||||
helperBlockUpdates = unique(blockUpdates([1, end-3]), "stable");
|
||||
|
||||
requiredSirRows = table();
|
||||
for pamIdx = 1:numel(selectedPamLevels)
|
||||
@@ -214,14 +214,14 @@ for pamIdx = 1:numel(selectedPamLevels)
|
||||
sirValues, boundCenterBer, boundLowerBer, boundUpperBer, ...
|
||||
boundMode, boundaryPolyfitOrderMax);
|
||||
|
||||
[hl, hp] = boundedline(xBand, centerBand, yBounds, ...
|
||||
'alpha', 'transparency', 0.1, ...
|
||||
'cmap', algColor, ...
|
||||
'nan', 'fill', ...
|
||||
'orientation', 'vert');
|
||||
set(hl, "LineStyle", "none", 'LineWidth', 1, "Marker", "none", ...
|
||||
"HandleVisibility", "off", "DisplayName", char(displayName));
|
||||
set(hp, "LineStyle", "-", "HandleVisibility", "off", "Marker", "none");
|
||||
% [hl, hp] = boundedline(xBand, centerBand, yBounds, ...
|
||||
% 'alpha', 'transparency', 0.1, ...
|
||||
% 'cmap', algColor, ...
|
||||
% 'nan', 'fill', ...
|
||||
% 'orientation', 'vert');
|
||||
% set(hl, "LineStyle", "none", 'LineWidth', 1, "Marker", "none", ...
|
||||
% "HandleVisibility", "off", "DisplayName", char(displayName));
|
||||
% set(hp, "LineStyle", "-", "HandleVisibility", "off", "Marker", "none");
|
||||
end
|
||||
|
||||
plot(sirValues(valid), meanBer(valid), ...
|
||||
@@ -242,11 +242,11 @@ for pamIdx = 1:numel(selectedPamLevels)
|
||||
xFit = linspace(min(sirValues(fitMask)), max(sirValues(fitMask)), 300);
|
||||
yFit = 10 .^ polyval(fitCoeff, xFit);
|
||||
|
||||
% plot(xFit, yFit, ...
|
||||
% "LineStyle", "--", ...
|
||||
% "LineWidth", 1.1, ...
|
||||
% "Color", algColor, ...
|
||||
% "HandleVisibility", "off");
|
||||
plot(xFit, yFit, ...
|
||||
"LineStyle", "--", ...
|
||||
"LineWidth", 1.1, ...
|
||||
"Color", algColor, ...
|
||||
"HandleVisibility", "off");
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,608 @@
|
||||
%% BER over SIR from saved MPI simulation warehouses grouped by linewidth
|
||||
% Loads a saved simulation warehouse and plots one BER-vs-SIR curve per
|
||||
% linewidth for each algorithm.
|
||||
|
||||
% clear;
|
||||
% clc;
|
||||
|
||||
%% Load data
|
||||
resultFile = "";
|
||||
if resultFile == ""
|
||||
resultDir = fullfile(fileparts(mfilename("fullpath")), "results");
|
||||
files = dir(fullfile(resultDir, "mpi_simulation_*.mat"));
|
||||
if isempty(files)
|
||||
error("PLOT_mpi_simulation_linewidth_vs_sir:NoResultFiles", ...
|
||||
"No mpi_simulation_*.mat files found in %s.", resultDir);
|
||||
end
|
||||
[~, newestIdx] = max([files.datenum]);
|
||||
resultFile = fullfile(files(newestIdx).folder, files(newestIdx).name);
|
||||
end
|
||||
|
||||
loaded = load(resultFile, "wh", "simulation_config");
|
||||
wh = loaded.wh;
|
||||
fprintf("Loaded MPI simulation warehouse:\n%s\n", resultFile);
|
||||
wh.showInfo;
|
||||
|
||||
%% Plot settings
|
||||
useBoundedLines = true;
|
||||
usePolyfit = true;
|
||||
polyfitOrderMax = 4;
|
||||
boundaryPolyfitOrderMax = 4;
|
||||
fecBerThreshold = 3.8e-3;
|
||||
maxBerForPlot = 0.1;
|
||||
crossingSirWindow = [15 40];
|
||||
boundMode = "fitStd";
|
||||
algorithmMarkers = {'o','square','diamond','^','v','>','<','pentagram'};
|
||||
|
||||
%% Collect and clean
|
||||
cleanData = collectMpiSimulationBerRows(wh);
|
||||
cleanData = normalizeBerColumnName(cleanData);
|
||||
cleanData = cleanData(isfinite(cleanData.BER) & cleanData.BER > 0 & ...
|
||||
cleanData.BER < maxBerForPlot, :);
|
||||
|
||||
if isempty(cleanData)
|
||||
warning("PLOT_mpi_simulation_linewidth_vs_sir:NoRows", ...
|
||||
"No valid BER rows remain for plotting.");
|
||||
return
|
||||
end
|
||||
|
||||
if all(~isfinite(cleanData.laser_linewidth))
|
||||
if isfield(loaded, "simulation_config") && isfield(loaded.simulation_config, "laser_linewidth")
|
||||
cleanData.laser_linewidth(:) = loaded.simulation_config.laser_linewidth;
|
||||
else
|
||||
cleanData.laser_linewidth(:) = 0;
|
||||
end
|
||||
end
|
||||
|
||||
cleanData.clean_keep = true(height(cleanData), 1);
|
||||
groupId = findgroups(cleanData.storage_name, cleanData.block_update, ...
|
||||
cleanData.laser_linewidth, cleanData.sir);
|
||||
for curGroup = unique(groupId(isfinite(groupId))).'
|
||||
rowMask = groupId == curGroup;
|
||||
berValues = cleanData.BER(rowMask);
|
||||
if nnz(rowMask) > 3
|
||||
cleanData.clean_keep(rowMask) = ~isoutlier(berValues);
|
||||
end
|
||||
end
|
||||
cleanData = cleanData(cleanData.clean_keep, :);
|
||||
|
||||
groupVars = ["storage_name", "algorithm", "block_update", "laser_linewidth", "sir"];
|
||||
summaryTable = groupsummary(cleanData, groupVars, {"mean", "min", "max"}, "BER");
|
||||
summaryTable = sortrows(summaryTable, groupVars);
|
||||
summaryTable.sir_exact = summaryTable.sir;
|
||||
summaryTable = addBerStdBounds(summaryTable, cleanData, groupVars);
|
||||
|
||||
selectedBlockUpdates = unique(cleanData.block_update(isfinite(cleanData.block_update))).';
|
||||
selectedAlgorithms = unique(cleanData.storage_name, "stable").';
|
||||
selectedLinewidths = unique(cleanData.laser_linewidth(isfinite(cleanData.laser_linewidth))).';
|
||||
selectedLinewidths = sort(selectedLinewidths);
|
||||
|
||||
requiredSirRows = table();
|
||||
for blockIdx = 1:numel(selectedBlockUpdates)
|
||||
blockUpdate = selectedBlockUpdates(blockIdx);
|
||||
for algIdx = 1:numel(selectedAlgorithms)
|
||||
storageName = selectedAlgorithms(algIdx);
|
||||
algorithmName = string(summaryTable.algorithm(find(summaryTable.storage_name == storageName, 1, "first")));
|
||||
for linewidthIdx = 1:numel(selectedLinewidths)
|
||||
laserLinewidth = selectedLinewidths(linewidthIdx);
|
||||
curveMask = summaryTable.storage_name == storageName & ...
|
||||
summaryTable.block_update == blockUpdate & ...
|
||||
summaryTable.laser_linewidth == laserLinewidth;
|
||||
|
||||
sirValues = summaryTable.sir_exact(curveMask).';
|
||||
meanBer = summaryTable.mean_BER(curveMask).';
|
||||
[~, ~, requiredSir, fitOrder] = fitBerAtFec( ...
|
||||
sirValues, meanBer, polyfitOrderMax, fecBerThreshold, crossingSirWindow);
|
||||
|
||||
newRow = table(storageName, algorithmName, blockUpdate, ...
|
||||
laserLinewidth, requiredSir, fitOrder, nnz(isfinite(sirValues) & isfinite(meanBer)), ...
|
||||
'VariableNames', {'storage_name', 'algorithm', 'block_update', ...
|
||||
'laser_linewidth', 'required_sir', 'fit_order', 'n_points'});
|
||||
requiredSirRows = [requiredSirRows; newRow]; %#ok<AGROW>
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
fprintf("Cleaned to %d simulation BER rows across %d storage/block/linewidth/SIR groups.\n", ...
|
||||
height(cleanData), height(summaryTable));
|
||||
disp(groupcounts(cleanData, ["storage_name", "block_update", "laser_linewidth"]));
|
||||
disp(requiredSirRows);
|
||||
|
||||
%% Plot BER vs SIR, linewidth as curve family
|
||||
for blockIdx = 1:numel(selectedBlockUpdates)
|
||||
blockUpdate = selectedBlockUpdates(blockIdx);
|
||||
|
||||
figure();
|
||||
clf;
|
||||
tiledlayout(numel(selectedAlgorithms), 1, "TileSpacing", "compact");
|
||||
|
||||
for algIdx = 1:numel(selectedAlgorithms)
|
||||
storageName = selectedAlgorithms(algIdx);
|
||||
nexttile;
|
||||
hold on;
|
||||
|
||||
for linewidthIdx = 1:numel(selectedLinewidths)
|
||||
laserLinewidth = selectedLinewidths(linewidthIdx);
|
||||
lineColor = linewidthColor(linewidthIdx, numel(selectedLinewidths));
|
||||
marker = algorithmMarker(storageName, algorithmMarkers);
|
||||
displayName = sprintf("%s, %s", ...
|
||||
algorithmDisplayName(storageName), linewidthLabel(laserLinewidth));
|
||||
|
||||
rawMask = cleanData.storage_name == storageName & ...
|
||||
cleanData.block_update == blockUpdate & ...
|
||||
cleanData.laser_linewidth == laserLinewidth;
|
||||
curveMask = summaryTable.storage_name == storageName & ...
|
||||
summaryTable.block_update == blockUpdate & ...
|
||||
summaryTable.laser_linewidth == laserLinewidth;
|
||||
|
||||
if ~any(curveMask)
|
||||
continue
|
||||
end
|
||||
|
||||
scatterRows = cleanData(rawMask, :);
|
||||
scatter(scatterRows.sir, scatterRows.BER, ...
|
||||
22, ...
|
||||
"Marker", ".", ...
|
||||
"MarkerEdgeColor", lineColor, ...
|
||||
"MarkerFaceColor", lineColor, ...
|
||||
"HandleVisibility", "off");
|
||||
|
||||
sirValues = summaryTable.sir_exact(curveMask).';
|
||||
meanBer = summaryTable.mean_BER(curveMask).';
|
||||
boundCenterBer = summaryTable.std_center_BER(curveMask).';
|
||||
boundLowerBer = summaryTable.std_lower_BER(curveMask).';
|
||||
boundUpperBer = summaryTable.std_upper_BER(curveMask).';
|
||||
valid = isfinite(sirValues) & isfinite(meanBer) & meanBer > 0;
|
||||
|
||||
if useBoundedLines && exist("boundedline", "file") && any(valid)
|
||||
[xBand, centerBand, yBounds] = berStdBounds( ...
|
||||
sirValues, boundCenterBer, boundLowerBer, boundUpperBer, ...
|
||||
boundMode, boundaryPolyfitOrderMax);
|
||||
|
||||
[hl, hp] = boundedline(xBand, centerBand, yBounds, ...
|
||||
'alpha', 'transparency', 0.08, ...
|
||||
'cmap', lineColor, ...
|
||||
'nan', 'fill', ...
|
||||
'orientation', 'vert');
|
||||
set(hl, "LineStyle", "none", "LineWidth", 1, "Marker", "none", ...
|
||||
"HandleVisibility", "off", "DisplayName", displayName);
|
||||
set(hp, "LineStyle", "-", "HandleVisibility", "off", "Marker", "none");
|
||||
end
|
||||
|
||||
plot(sirValues(valid), meanBer(valid), ...
|
||||
"LineStyle", "-", ...
|
||||
"Marker", marker, ...
|
||||
"MarkerSize", 3, ...
|
||||
"LineWidth", 1, ...
|
||||
"Color", lineColor, ...
|
||||
"MarkerFaceColor", "w", ...
|
||||
"MarkerEdgeColor", lineColor, ...
|
||||
"DisplayName", displayName, ...
|
||||
"HandleVisibility", "on");
|
||||
|
||||
if usePolyfit
|
||||
fitMask = valid & meanBer > 0;
|
||||
if nnz(fitMask) >= 2
|
||||
fitOrder = min(polyfitOrderMax, nnz(fitMask) - 1);
|
||||
fitCoeff = polyfit(sirValues(fitMask), log10(meanBer(fitMask)), fitOrder);
|
||||
xFit = linspace(min(sirValues(fitMask)), max(sirValues(fitMask)), 300);
|
||||
yFit = 10 .^ polyval(fitCoeff, xFit);
|
||||
plot(xFit, yFit, ...
|
||||
"LineStyle", "--", ...
|
||||
"LineWidth", 1.1, ...
|
||||
"Color", lineColor, ...
|
||||
"HandleVisibility", "off");
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
yline(2.2e-4, "LineWidth", 1, "LineStyle", "--", "HandleVisibility", "off");
|
||||
yline(fecBerThreshold, "LineWidth", 1, "LineStyle", "--", "HandleVisibility", "off");
|
||||
yline(2e-2, "LineWidth", 1, "LineStyle", "--", "HandleVisibility", "off");
|
||||
|
||||
title(sprintf("%s, block update %.0f", algorithmDisplayName(storageName), blockUpdate));
|
||||
xlabel("SIR (dB)");
|
||||
ylabel("BER");
|
||||
set(gca, "YScale", "log");
|
||||
ylim([9e-5, maxBerForPlot]);
|
||||
xlim(crossingSirWindow);
|
||||
grid on;
|
||||
box on;
|
||||
legend("Location", "northeast", "Interpreter", "none");
|
||||
|
||||
if exist("beautifyBERplot", "file")
|
||||
beautifyBERplot("logscale", true, "setcolors", false, ...
|
||||
"setmarkers", false, "changemarkers", false);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
%% Plot required SIR at FEC over linewidth
|
||||
for blockIdx = 1:numel(selectedBlockUpdates)
|
||||
blockUpdate = selectedBlockUpdates(blockIdx);
|
||||
|
||||
figure();
|
||||
clf;
|
||||
hold on;
|
||||
|
||||
for algIdx = 1:numel(selectedAlgorithms)
|
||||
storageName = selectedAlgorithms(algIdx);
|
||||
algColor = algorithmColor(storageName);
|
||||
marker = algorithmMarker(storageName, algorithmMarkers);
|
||||
displayName = algorithmDisplayName(storageName);
|
||||
rowMask = requiredSirRows.storage_name == storageName & ...
|
||||
requiredSirRows.block_update == blockUpdate;
|
||||
|
||||
x = requiredSirRows.laser_linewidth(rowMask).';
|
||||
y = requiredSirRows.required_sir(rowMask).';
|
||||
[x, sortIdx] = sort(x);
|
||||
y = y(sortIdx);
|
||||
valid = isfinite(x) & isfinite(y);
|
||||
|
||||
if ~any(valid)
|
||||
continue
|
||||
end
|
||||
|
||||
plot(x(valid), y(valid), ...
|
||||
"LineWidth", 1.4, ...
|
||||
"LineStyle", "-", ...
|
||||
"Marker", marker, ...
|
||||
"MarkerSize", 5, ...
|
||||
"Color", algColor, ...
|
||||
"MarkerFaceColor", "w", ...
|
||||
"MarkerEdgeColor", algColor, ...
|
||||
"DisplayName", char(displayName));
|
||||
end
|
||||
|
||||
set(gca, "XScale", "log");
|
||||
xticks(selectedLinewidths);
|
||||
xticklabels(arrayfun(@linewidthLabel, selectedLinewidths, "UniformOutput", false));
|
||||
ylim(crossingSirWindow);
|
||||
grid on;
|
||||
box on;
|
||||
xlabel("Laser linewidth");
|
||||
ylabel(sprintf("Required SIR at BER = %.1e (dB)", fecBerThreshold));
|
||||
title(sprintf("Required SIR over linewidth, block update %.0f", blockUpdate));
|
||||
legend("Location", "best", "Interpreter", "none");
|
||||
|
||||
if exist("beautifyBERplot", "file")
|
||||
beautifyBERplot("logscale", false, "setcolors", false, ...
|
||||
"setmarkers", false, "changemarkers", false);
|
||||
end
|
||||
end
|
||||
|
||||
%% Local helpers
|
||||
function data = collectMpiSimulationBerRows(wh)
|
||||
storageNames = string(fieldnames(wh.sto));
|
||||
data = table();
|
||||
|
||||
for storageIdx = 1:numel(storageNames)
|
||||
storageName = storageNames(storageIdx);
|
||||
storage = wh.sto.(char(storageName));
|
||||
|
||||
for linIdx = 1:numel(storage)
|
||||
package = storage{linIdx};
|
||||
ber = extractPackageBer(package);
|
||||
if ~isfinite(ber)
|
||||
continue
|
||||
end
|
||||
|
||||
[physValues, physNames] = wh.getPhysIndicesByLinIndex(linIdx);
|
||||
phys = struct();
|
||||
for physIdx = 1:numel(physNames)
|
||||
phys.(char(physNames{physIdx})) = physValues{physIdx};
|
||||
end
|
||||
|
||||
algorithm = extractPackageAlgorithm(package, storageName);
|
||||
newRow = table( ...
|
||||
storageName, ...
|
||||
algorithm, ...
|
||||
readPhysValue(phys, "sir", NaN), ...
|
||||
readPhysValue(phys, "block_update", NaN), ...
|
||||
readPhysValue(phys, "random_key", NaN), ...
|
||||
readPhysValue(phys, "laser_linewidth", NaN), ...
|
||||
ber, ...
|
||||
'VariableNames', {'storage_name', 'algorithm', 'sir', ...
|
||||
'block_update', 'random_key', 'laser_linewidth', 'BER'});
|
||||
data = [data; newRow]; %#ok<AGROW>
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function data = normalizeBerColumnName(data)
|
||||
variableNames = string(data.Properties.VariableNames);
|
||||
if ismember("BER", variableNames)
|
||||
return
|
||||
end
|
||||
|
||||
if ismember("ber", variableNames)
|
||||
data.Properties.VariableNames(variableNames == "ber") = {'BER'};
|
||||
return
|
||||
end
|
||||
|
||||
error("PLOT_mpi_simulation_linewidth_vs_sir:MissingBerColumn", ...
|
||||
"Could not find a BER or ber column in the simulation BER table.");
|
||||
end
|
||||
|
||||
function value = readPhysValue(phys, name, defaultValue)
|
||||
if isfield(phys, name)
|
||||
value = phys.(name);
|
||||
else
|
||||
value = defaultValue;
|
||||
end
|
||||
end
|
||||
|
||||
function ber = extractPackageBer(package)
|
||||
ber = NaN;
|
||||
if isempty(package)
|
||||
return
|
||||
end
|
||||
|
||||
if iscell(package)
|
||||
package = package{1};
|
||||
end
|
||||
|
||||
if isstruct(package) && isfield(package, "metrics")
|
||||
metrics = package.metrics;
|
||||
if isstruct(metrics) && isfield(metrics, "BER")
|
||||
ber = metrics.BER;
|
||||
elseif isobject(metrics) && isprop(metrics, "BER")
|
||||
ber = metrics.BER;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function algorithm = extractPackageAlgorithm(package, fallbackName)
|
||||
algorithm = fallbackName;
|
||||
if isempty(package)
|
||||
return
|
||||
end
|
||||
|
||||
if iscell(package)
|
||||
package = package{1};
|
||||
end
|
||||
|
||||
if isstruct(package) && isfield(package, "mpi_reduction_config") && ...
|
||||
isfield(package.mpi_reduction_config, "algorithm")
|
||||
algorithm = string(package.mpi_reduction_config.algorithm);
|
||||
end
|
||||
end
|
||||
|
||||
function summaryTable = addBerStdBounds(summaryTable, cleanData, groupVars)
|
||||
nGroups = height(summaryTable);
|
||||
stdCenter = NaN(nGroups, 1);
|
||||
stdLower = NaN(nGroups, 1);
|
||||
stdUpper = NaN(nGroups, 1);
|
||||
|
||||
for groupIdx = 1:nGroups
|
||||
rowMask = true(height(cleanData), 1);
|
||||
for varIdx = 1:numel(groupVars)
|
||||
varName = groupVars(varIdx);
|
||||
rowMask = rowMask & cleanData.(char(varName)) == summaryTable.(char(varName))(groupIdx);
|
||||
end
|
||||
|
||||
[stdCenter(groupIdx), stdLower(groupIdx), stdUpper(groupIdx)] = ...
|
||||
logBerMeanStdInterval(cleanData.BER(rowMask));
|
||||
end
|
||||
|
||||
summaryTable.std_center_BER = stdCenter;
|
||||
summaryTable.std_lower_BER = stdLower;
|
||||
summaryTable.std_upper_BER = stdUpper;
|
||||
end
|
||||
|
||||
function [centerBer, lowerBer, upperBer] = logBerMeanStdInterval(berValues)
|
||||
berValues = berValues(isfinite(berValues) & berValues > 0);
|
||||
if isempty(berValues)
|
||||
centerBer = NaN;
|
||||
lowerBer = NaN;
|
||||
upperBer = NaN;
|
||||
return
|
||||
end
|
||||
|
||||
logBer = log10(berValues(:));
|
||||
centerLog = mean(logBer, "omitnan");
|
||||
stdLog = std(logBer, 0, "omitnan");
|
||||
|
||||
centerBer = 10 .^ centerLog;
|
||||
lowerBer = 10 .^ (centerLog - stdLog);
|
||||
upperBer = 10 .^ (centerLog + stdLog);
|
||||
end
|
||||
|
||||
function [xBand, centerBand, yBounds] = berStdBounds(sirValues, centerBer, lowerBer, upperBer, boundMode, maxOrder)
|
||||
if boundMode == "directStd"
|
||||
[xBand, centerBand, yBounds] = directBerBounds(sirValues, centerBer, lowerBer, upperBer);
|
||||
return
|
||||
end
|
||||
|
||||
[xBand, centerBand, yBounds] = fittedBerBounds(sirValues, centerBer, lowerBer, upperBer, maxOrder);
|
||||
end
|
||||
|
||||
function [xBand, centerBand, yBounds] = directBerBounds(sirValues, centerBer, lowerBer, upperBer)
|
||||
valid = isfinite(sirValues) & isfinite(centerBer) & isfinite(lowerBer) & ...
|
||||
isfinite(upperBer) & centerBer > 0 & lowerBer > 0 & upperBer > 0;
|
||||
|
||||
xBand = sirValues(valid).';
|
||||
centerBand = centerBer(valid).';
|
||||
lowerBand = lowerBer(valid).';
|
||||
upperBand = upperBer(valid).';
|
||||
|
||||
[xBand, orderIdx] = sort(xBand(:));
|
||||
centerBand = centerBand(orderIdx);
|
||||
lowerBand = lowerBand(orderIdx);
|
||||
upperBand = upperBand(orderIdx);
|
||||
|
||||
lowerTmp = min(lowerBand, upperBand);
|
||||
upperBand = max(lowerBand, upperBand);
|
||||
lowerBand = lowerTmp;
|
||||
|
||||
centerBand = min(max(centerBand, lowerBand), upperBand);
|
||||
yBounds = [max(centerBand - lowerBand, 0), max(upperBand - centerBand, 0)];
|
||||
end
|
||||
|
||||
function [xBand, centerBand, yBounds] = fittedBerBounds(sirValues, meanBer, minBer, maxBer, maxOrder)
|
||||
valid = isfinite(sirValues) & isfinite(meanBer) & isfinite(minBer) & ...
|
||||
isfinite(maxBer) & meanBer > 0 & minBer > 0 & maxBer > 0;
|
||||
|
||||
x = sirValues(valid);
|
||||
yMean = meanBer(valid);
|
||||
yMin = minBer(valid);
|
||||
yMax = maxBer(valid);
|
||||
|
||||
if numel(x) < 2
|
||||
xBand = x(:);
|
||||
centerBand = yMean(:);
|
||||
yBounds = [max(yMean(:) - yMin(:), 0), max(yMax(:) - yMean(:), 0)];
|
||||
return
|
||||
end
|
||||
|
||||
[x, orderIdx] = sort(x(:));
|
||||
yMean = yMean(orderIdx);
|
||||
yMin = yMin(orderIdx);
|
||||
yMax = yMax(orderIdx);
|
||||
|
||||
xBand = linspace(min(x), max(x), 300).';
|
||||
fitOrder = min(maxOrder, numel(unique(x)) - 1);
|
||||
|
||||
if fitOrder < 1
|
||||
centerBand = interp1(x, yMean, xBand, "linear", "extrap");
|
||||
lowerBand = interp1(x, yMin, xBand, "linear", "extrap");
|
||||
upperBand = interp1(x, yMax, xBand, "linear", "extrap");
|
||||
else
|
||||
centerBand = fitLogBer(x, yMean, xBand, fitOrder);
|
||||
lowerBand = fitLogBer(x, yMin, xBand, fitOrder);
|
||||
upperBand = fitLogBer(x, yMax, xBand, fitOrder);
|
||||
end
|
||||
|
||||
lowerTmp = min(lowerBand, upperBand);
|
||||
upperBand = max(lowerBand, upperBand);
|
||||
lowerBand = lowerTmp;
|
||||
|
||||
centerBand = min(max(centerBand, lowerBand), upperBand);
|
||||
yBounds = [max(centerBand - lowerBand, 0), max(upperBand - centerBand, 0)];
|
||||
end
|
||||
|
||||
function yFit = fitLogBer(x, y, xFit, fitOrder)
|
||||
coeff = polyfit(x, log10(y), fitOrder);
|
||||
yFit = 10 .^ polyval(coeff, xFit);
|
||||
end
|
||||
|
||||
function [xFit, yFit, requiredSir, fitOrder] = fitBerAtFec( ...
|
||||
sirValues, meanBer, polyfitOrderMax, fecBerThreshold, crossingSirWindow)
|
||||
|
||||
xFit = NaN;
|
||||
yFit = NaN;
|
||||
requiredSir = NaN;
|
||||
fitOrder = NaN;
|
||||
|
||||
valid = isfinite(sirValues) & isfinite(meanBer) & meanBer > 0 & ...
|
||||
sirValues >= crossingSirWindow(1) & sirValues <= crossingSirWindow(2);
|
||||
if nnz(valid) < 2
|
||||
return
|
||||
end
|
||||
|
||||
sirValues = sirValues(valid);
|
||||
meanBer = meanBer(valid);
|
||||
[sirValues, sortIdx] = sort(sirValues);
|
||||
meanBer = meanBer(sortIdx);
|
||||
|
||||
fitOrder = min(polyfitOrderMax, nnz(valid) - 1);
|
||||
fitCoeff = polyfit(sirValues, log10(meanBer), fitOrder);
|
||||
xFit = linspace(max(min(sirValues), crossingSirWindow(1)), ...
|
||||
min(max(sirValues), crossingSirWindow(2)), 300);
|
||||
yFit = 10 .^ polyval(fitCoeff, xFit);
|
||||
|
||||
thresholdMask = isfinite(yFit) & yFit <= fecBerThreshold;
|
||||
if ~any(thresholdMask)
|
||||
return
|
||||
end
|
||||
|
||||
firstThresholdIdx = find(thresholdMask, 1, "first");
|
||||
if firstThresholdIdx == 1
|
||||
requiredSir = xFit(firstThresholdIdx);
|
||||
return
|
||||
end
|
||||
|
||||
xPair = xFit(firstThresholdIdx - 1:firstThresholdIdx);
|
||||
yPair = log10(yFit(firstThresholdIdx - 1:firstThresholdIdx));
|
||||
if all(isfinite(yPair)) && diff(yPair) ~= 0
|
||||
requiredSir = interp1(yPair, xPair, log10(fecBerThreshold), ...
|
||||
"linear", "extrap");
|
||||
else
|
||||
requiredSir = xFit(firstThresholdIdx);
|
||||
end
|
||||
|
||||
if requiredSir < crossingSirWindow(1) || requiredSir > crossingSirWindow(2)
|
||||
requiredSir = NaN;
|
||||
end
|
||||
end
|
||||
|
||||
function label = algorithmDisplayName(algorithmName)
|
||||
algorithmName = string(algorithmName);
|
||||
switch algorithmName
|
||||
case {"plain_ffe", "conventional_ffe"}
|
||||
label = "FFE only";
|
||||
case "a2_tracked_levels"
|
||||
label = "ACT";
|
||||
case "a2_residual"
|
||||
label = "L-DCA";
|
||||
case "a1_moving_average"
|
||||
label = "DCA";
|
||||
case "dc_tracking"
|
||||
label = "DCT";
|
||||
otherwise
|
||||
label = algorithmName;
|
||||
end
|
||||
end
|
||||
|
||||
function color = algorithmColor(algorithmName)
|
||||
algorithmName = string(algorithmName);
|
||||
switch algorithmName
|
||||
case {"plain_ffe", "conventional_ffe"}
|
||||
color = [0.3467 0.5360 0.6907];
|
||||
case "a2_tracked_levels"
|
||||
color = [0.9153 0.2816 0.2878];
|
||||
case "a2_residual"
|
||||
color = [0.4416 0.7490 0.4322];
|
||||
case "a1_moving_average"
|
||||
color = [1.0000 0.5984 0.2000];
|
||||
case "dc_tracking"
|
||||
color = [0.6769 0.4447 0.7114];
|
||||
otherwise
|
||||
color = [0 0 0];
|
||||
end
|
||||
end
|
||||
|
||||
function color = linewidthColor(linewidthIdx, nLinewidths)
|
||||
if nLinewidths <= 1
|
||||
color = [0.3467 0.5360 0.6907];
|
||||
return
|
||||
end
|
||||
|
||||
if exist("cbrewer2", "file")
|
||||
colors = cbrewer2("Set1", max(nLinewidths, 3));
|
||||
else
|
||||
colors = lines(nLinewidths);
|
||||
end
|
||||
|
||||
color = colors(linewidthIdx, :);
|
||||
end
|
||||
|
||||
function label = linewidthLabel(laserLinewidth)
|
||||
if abs(laserLinewidth) >= 1e6
|
||||
label = sprintf("%.3g MHz", laserLinewidth * 1e-6);
|
||||
elseif abs(laserLinewidth) >= 1e3
|
||||
label = sprintf("%.3g kHz", laserLinewidth * 1e-3);
|
||||
else
|
||||
label = sprintf("%.3g Hz", laserLinewidth);
|
||||
end
|
||||
end
|
||||
|
||||
function marker = algorithmMarker(algorithmName, algorithmMarkers)
|
||||
algorithmOrder = ["conventional_ffe", "dc_tracking", "a2_tracked_levels", ...
|
||||
"a2_residual", "a1_moving_average"];
|
||||
markerIdx = find(algorithmOrder == string(algorithmName), 1);
|
||||
if isempty(markerIdx)
|
||||
markerIdx = 1;
|
||||
end
|
||||
marker = algorithmMarkers{mod(markerIdx - 1, numel(algorithmMarkers)) + 1};
|
||||
end
|
||||
214
projects/Diss/MPI_revisit/simulation/mpi_simulation_worker.m
Normal file
214
projects/Diss/MPI_revisit/simulation/mpi_simulation_worker.m
Normal file
@@ -0,0 +1,214 @@
|
||||
function output = mpi_simulation_worker(userParameters, simulation_config)
|
||||
%MPI_SIMULATION_WORKER Build one decorrelated MPI point and run the DSP recipe.
|
||||
|
||||
arguments
|
||||
userParameters struct
|
||||
simulation_config struct
|
||||
end
|
||||
|
||||
config = applyDefaults(simulation_config);
|
||||
|
||||
[Scpe_sig_raw, Symbols, Tx_bits, dataTable] = buildMpiScopeSignal(userParameters, config);
|
||||
|
||||
output = config.recipe(Scpe_sig_raw, Symbols, Tx_bits, ...
|
||||
"fsym", config.fsym, ...
|
||||
"M", config.M, ...
|
||||
"duob_mode", config.duob_mode, ...
|
||||
"dataTable", dataTable, ...
|
||||
"userParameters", userParameters, ...
|
||||
"debug_plots", config.debug_plots);
|
||||
end
|
||||
|
||||
function config = applyDefaults(config)
|
||||
defaults = struct( ...
|
||||
"M", 4, ...
|
||||
"fsym", 112e9, ...
|
||||
"mpi_path_meter", 1000, ...
|
||||
"laser_linewidth", 150e3, ...
|
||||
"recipe", @mpi_recipe_dev, ...
|
||||
"debug_plots", false, ...
|
||||
"fdac", 256e9, ...
|
||||
"fadc", 256e9, ...
|
||||
"kover", 16, ...
|
||||
"random_key", 1, ...
|
||||
"rcalpha", 0.05, ...
|
||||
"duob_mode", db_mode.no_db, ...
|
||||
"vbias_rel", 0.5, ...
|
||||
"u_pi", 3, ...
|
||||
"laser_wavelength", 1293, ...
|
||||
"link_length_km", 1, ...
|
||||
"rop", -9, ...
|
||||
"rx_bwl", 80e9, ...
|
||||
"scope_bwl", 110e9, ...
|
||||
"alpha", 0);
|
||||
|
||||
names = fieldnames(defaults);
|
||||
for nameIdx = 1:numel(names)
|
||||
name = names{nameIdx};
|
||||
if ~isfield(config, name) || isempty(config.(name))
|
||||
config.(name) = defaults.(name);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function [Scpe_sig, Symbols, Tx_bits, dataTable] = buildMpiScopeSignal(userParameters, config)
|
||||
sir = readUserParameter(userParameters, "sir", 30);
|
||||
randomKey = readUserParameter(userParameters, "random_key", config.random_key);
|
||||
laserLinewidth = readUserParameter(userParameters, "laser_linewidth", config.laser_linewidth);
|
||||
config.laser_linewidth = laserLinewidth;
|
||||
|
||||
Pform = Pulseformer( ...
|
||||
"fsym", config.fsym, ...
|
||||
"fdac", 4 * config.fsym, ...
|
||||
"pulse", "rrc", ...
|
||||
"pulselength", 16, ...
|
||||
"alpha", config.rcalpha);
|
||||
|
||||
vbias = -config.vbias_rel * config.u_pi;
|
||||
mainSource = buildOpticalSource(Pform, config, randomKey, randomKey + 1, vbias);
|
||||
interferenceSource = buildOpticalSource(Pform, config, randomKey + 100000, ...
|
||||
randomKey + 100001, vbias);
|
||||
|
||||
Symbols = mainSource.Symbols;
|
||||
Tx_bits = mainSource.Tx_bits;
|
||||
Opt_sig = applyDecorrelatedMpi(mainSource.Opt_sig, interferenceSource.Opt_sig, ...
|
||||
sir, config.link_length_km);
|
||||
|
||||
Rx_sig = Amplifier( ...
|
||||
"amp_mode", "ideal_no_noise", ...
|
||||
"gain_mode", "output_power", ...
|
||||
"amplification_db", config.rop).process(Opt_sig);
|
||||
|
||||
Rx_sig = Photodiode( ...
|
||||
"fsimu", config.fdac * config.kover, ...
|
||||
"dark_current", 2e-08, ...
|
||||
"responsivity", 1, ...
|
||||
"temperature", 20, ...
|
||||
"nep", 1.8e-11).process(Rx_sig);
|
||||
Rx_sig.signal = real(Rx_sig.signal);
|
||||
|
||||
Rx_sig = Filter( ...
|
||||
"filtdegree", 4, ...
|
||||
"f_cutoff", config.rx_bwl, ...
|
||||
"fs", config.fdac * config.kover, ...
|
||||
"filterType", filtertypes.butterworth, ...
|
||||
"active", true).process(Rx_sig);
|
||||
Rx_sig.signal = real(Rx_sig.signal);
|
||||
|
||||
scopeFilter = Filter( ...
|
||||
"filtdegree", 4, ...
|
||||
"f_cutoff", config.scope_bwl, ...
|
||||
"fs", config.fadc, ...
|
||||
"filterType", filtertypes.butterworth, ...
|
||||
"active", true);
|
||||
|
||||
Scpe_sig = Scope( ...
|
||||
"fsimu", config.fdac * config.kover, ...
|
||||
"fadc", config.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", scopeFilter).process(Rx_sig);
|
||||
Scpe_sig.signal = real(Scpe_sig.signal);
|
||||
|
||||
HighpassFilter = Filter( ...
|
||||
"filtdegree", 6, ...
|
||||
"f_cutoff", 1e6, ...
|
||||
"fs", config.fadc, ...
|
||||
"filterType", filtertypes.butterworth, ...
|
||||
"active", true, "lowpass",0);
|
||||
|
||||
Scpe_sig = HighpassFilter.process(Scpe_sig);
|
||||
|
||||
dataTable = table( ...
|
||||
sir, ...
|
||||
config.fsym, ...
|
||||
config.M, ...
|
||||
config.mpi_path_meter, ...
|
||||
laserLinewidth, ...
|
||||
randomKey, ...
|
||||
'VariableNames', {'sir', 'symbolrate', 'pam_level', ...
|
||||
'interference_path_length', 'laser_linewidth', 'random_key'});
|
||||
end
|
||||
|
||||
function source = buildOpticalSource(Pform, config, sourceRandomKey, laserRandomKey, vbias)
|
||||
[Digi_sig, Symbols, Tx_bits] = PAMsource( ...
|
||||
"fsym", config.fsym, ...
|
||||
"M", config.M, ...
|
||||
"order", 18, ...
|
||||
"useprbs", 0, ...
|
||||
"fs_out", config.fdac, ...
|
||||
"applyclipping", 0, ...
|
||||
"clipfactor", 1.5, ...
|
||||
"applypulseform", 1, ...
|
||||
"pulseformer", Pform, ...
|
||||
"randkey", sourceRandomKey, ...
|
||||
"duobinary_mode", config.duob_mode, ...
|
||||
"mrds_code", 0, ...
|
||||
"mrds_blocklength", 512).process();
|
||||
|
||||
El_sig = M8199A("kover", config.kover).process(Digi_sig);
|
||||
|
||||
|
||||
El_sig = Filter("f_cutoff",65e9,"filterType","butterworth","filtdegree",4,"fs",El_sig.fs).process(El_sig);
|
||||
|
||||
El_sig = El_sig.normalize("mode", "oneone");
|
||||
|
||||
scaling = 0.6 * (config.u_pi / 2 - abs(vbias - config.u_pi / 2));
|
||||
El_sig = El_sig .* scaling;
|
||||
|
||||
Opt_sig = EML( ...
|
||||
"mode", eml_mode.im_cosinus, ...
|
||||
"power", 3, ...
|
||||
"fsimu", El_sig.fs, ...
|
||||
"lambda", config.laser_wavelength, ...
|
||||
"bias", vbias, ...
|
||||
"u_pi", config.u_pi, ...
|
||||
"linewidth", config.laser_linewidth, ...
|
||||
"randomkey", laserRandomKey, ...
|
||||
"alpha", config.alpha).process(El_sig);
|
||||
|
||||
source = struct( ...
|
||||
"Opt_sig", Opt_sig, ...
|
||||
"Symbols", Symbols, ...
|
||||
"Tx_bits", Tx_bits);
|
||||
end
|
||||
|
||||
function Opt_sig = applyDecorrelatedMpi(main_sig, interference_sig, sir, linkLengthKm)
|
||||
interference_sig = Amplifier( ...
|
||||
"amp_mode", "ideal_no_noise", ...
|
||||
"gain_mode", "output_power", ...
|
||||
"amplification_db", main_sig.power - sir).process(interference_sig);
|
||||
|
||||
if numel(main_sig.signal) ~= numel(interference_sig.signal)
|
||||
minLength = min(numel(main_sig.signal), numel(interference_sig.signal));
|
||||
main_sig.signal = main_sig.signal(1:minLength);
|
||||
interference_sig.signal = interference_sig.signal(1:minLength);
|
||||
end
|
||||
combined_sig = main_sig + interference_sig;
|
||||
|
||||
Opt_sig = Fiber( ...
|
||||
"fsimu", combined_sig.fs, ...
|
||||
"fiber_length", linkLengthKm, ...
|
||||
"alpha", 0.3, ...
|
||||
"D", 0, ...
|
||||
"lambda0", 1310, ...
|
||||
"gamma", 0, ...
|
||||
"Dslope", 0.07).process(combined_sig);
|
||||
end
|
||||
|
||||
function value = readUserParameter(userParameters, name, defaultValue)
|
||||
if isfield(userParameters, name)
|
||||
value = userParameters.(name);
|
||||
else
|
||||
value = defaultValue;
|
||||
end
|
||||
end
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
476
projects/Diss/MPI_revisit/simulation/run_mpi_simulation_recipe.m
Normal file
476
projects/Diss/MPI_revisit/simulation/run_mpi_simulation_recipe.m
Normal file
@@ -0,0 +1,476 @@
|
||||
%RUN_MPI_SIMULATION_RECIPE Queue MPI simulation points and store DSP packages.
|
||||
|
||||
clear;
|
||||
% clc;
|
||||
|
||||
%% Fixed experiment-like simulation setup
|
||||
simulation_config = struct();
|
||||
simulation_config.M = 4;
|
||||
simulation_config.fsym = 112e9;
|
||||
simulation_config.mpi_path_meter = 1000;
|
||||
simulation_config.laser_linewidth = 150e3;%[150e3 150e3 250e3 500e3 750e3 1e6 5e6 10e6 20e6 50e6];
|
||||
simulation_config.laser_linewidths = simulation_config.laser_linewidth;
|
||||
simulation_config.recipe = @mpi_recipe_dev;
|
||||
simulation_config.debug_plots = true;
|
||||
simulation_config.waitbar = true;
|
||||
simulation_config.processing_mode = processingMode.parallel;
|
||||
simulation_config.num_workers = 0;
|
||||
simulation_config.random_keys = 1:10;
|
||||
|
||||
simulation_config.fdac = 256e9;
|
||||
simulation_config.fadc = 256e9;
|
||||
simulation_config.kover = 16;
|
||||
simulation_config.random_key = 1;
|
||||
simulation_config.rcalpha = 0.05;
|
||||
simulation_config.duob_mode = db_mode.no_db;
|
||||
simulation_config.vbias_rel = 0.5;
|
||||
simulation_config.u_pi = 3;
|
||||
simulation_config.laser_wavelength = 1310;
|
||||
simulation_config.link_length_km = 0.5;
|
||||
simulation_config.rop = -7.5;
|
||||
simulation_config.rx_bwl = 70e9;
|
||||
simulation_config.scope_bwl = 70e9;
|
||||
simulation_config.alpha = 0;
|
||||
|
||||
%% Warehouse sweep setup
|
||||
sweep_params = struct();
|
||||
sweep_params.sir = 15:3:45;
|
||||
sweep_params.block_update = 1;
|
||||
sweep_params.random_key = simulation_config.random_keys;
|
||||
sweep_params.laser_linewidth = simulation_config.laser_linewidths;
|
||||
|
||||
wh = DataStorage(sweep_params);
|
||||
|
||||
fprintf("Requested %d MPI simulation job(s).\n", wh.getLastLinIndice());
|
||||
|
||||
%% Run queued simulations
|
||||
[results, wh] = submitMpiSimulationJobs(wh, simulation_config, ...
|
||||
"mode", simulation_config.processing_mode, ...
|
||||
"waitbar", simulation_config.waitbar, ...
|
||||
"numWorkers", simulation_config.num_workers);
|
||||
|
||||
%% Save result artifact
|
||||
result_dir = fullfile(fileparts(mfilename("fullpath")), "results");
|
||||
if ~exist(result_dir, "dir")
|
||||
mkdir(result_dir);
|
||||
end
|
||||
|
||||
timestamp = string(datetime("now", "Format", "yyyyMMdd_HHmmss"));
|
||||
result_file = fullfile(result_dir, "mpi_simulation_" + timestamp + ".mat");
|
||||
save(result_file, "wh", "simulation_config", "results");
|
||||
fprintf("Saved MPI simulation warehouse to:\n%s\n", result_file);
|
||||
|
||||
%% BER inspection
|
||||
plotMpiSimulationBer(wh);
|
||||
|
||||
function plotMpiSimulationBer(wh)
|
||||
storageNames = string(fieldnames(wh.sto));
|
||||
if isempty(storageNames)
|
||||
warning("run_mpi_simulation_recipe:NoStorage", ...
|
||||
"The warehouse does not contain any stored DSP packages.");
|
||||
return
|
||||
end
|
||||
|
||||
useBoundedLines = true;
|
||||
usePolyfit = true;
|
||||
polyfitOrderMax = 4;
|
||||
boundaryPolyfitOrderMax = 4;
|
||||
fecBerThreshold = 3.8e-3;
|
||||
maxBerForPlot = 0.1;
|
||||
boundMode = "fitStd";
|
||||
algorithmMarkers = {'o','square','diamond','^','v','>','<','pentagram'};
|
||||
|
||||
cleanData = collectMpiSimulationBerRows(wh);
|
||||
cleanData = normalizeBerColumnName(cleanData);
|
||||
cleanData = cleanData(isfinite(cleanData.BER) & cleanData.BER > 0 & ...
|
||||
cleanData.BER < maxBerForPlot, :);
|
||||
|
||||
if isempty(cleanData)
|
||||
warning("run_mpi_simulation_recipe:NoBerRows", ...
|
||||
"No valid BER rows remain for plotting.");
|
||||
return
|
||||
end
|
||||
|
||||
cleanData.clean_keep = true(height(cleanData), 1);
|
||||
groupId = findgroups(cleanData.storage_name, cleanData.block_update, cleanData.sir);
|
||||
for curGroup = unique(groupId(isfinite(groupId))).'
|
||||
rowMask = groupId == curGroup;
|
||||
berValues = cleanData.BER(rowMask);
|
||||
if nnz(rowMask) > 3
|
||||
cleanData.clean_keep(rowMask) = ~isoutlier(berValues);
|
||||
end
|
||||
end
|
||||
cleanData = cleanData(cleanData.clean_keep, :);
|
||||
|
||||
groupVars = ["storage_name", "algorithm", "block_update", "sir"];
|
||||
summaryTable = groupsummary(cleanData, groupVars, {"mean", "min", "max"}, "BER");
|
||||
summaryTable = sortrows(summaryTable, groupVars);
|
||||
summaryTable.sir_exact = summaryTable.sir;
|
||||
summaryTable = addBerStdBounds(summaryTable, cleanData, groupVars);
|
||||
|
||||
selectedBlockUpdates = unique(cleanData.block_update(isfinite(cleanData.block_update))).';
|
||||
selectedAlgorithms = unique(cleanData.storage_name, "stable").';
|
||||
|
||||
fprintf("Cleaned to %d simulation BER rows across %d storage/block/SIR groups.\n", ...
|
||||
height(cleanData), height(summaryTable));
|
||||
disp(groupcounts(cleanData, ["storage_name", "block_update"]));
|
||||
|
||||
figure();
|
||||
clf;
|
||||
tiledlayout(numel(selectedBlockUpdates), 1, "TileSpacing", "compact");
|
||||
|
||||
for blockIdx = 1:numel(selectedBlockUpdates)
|
||||
blockUpdate = selectedBlockUpdates(blockIdx);
|
||||
nexttile; hold on;
|
||||
|
||||
for algIdx = 1:numel(selectedAlgorithms)
|
||||
storageName = selectedAlgorithms(algIdx);
|
||||
algColor = algorithmColor(storageName);
|
||||
marker = algorithmMarker(storageName, algorithmMarkers);
|
||||
displayName = algorithmDisplayName(storageName);
|
||||
|
||||
rawMask = cleanData.storage_name == storageName & ...
|
||||
cleanData.block_update == blockUpdate;
|
||||
curveMask = summaryTable.storage_name == storageName & ...
|
||||
summaryTable.block_update == blockUpdate;
|
||||
|
||||
if ~any(curveMask)
|
||||
continue
|
||||
end
|
||||
|
||||
scatterRows = cleanData(rawMask, :);
|
||||
scatter(scatterRows.sir, scatterRows.BER, ...
|
||||
26, ...
|
||||
"Marker", ".", ...
|
||||
"MarkerEdgeColor", algColor, ...
|
||||
"MarkerFaceColor", algColor, ...
|
||||
"HandleVisibility", "off");
|
||||
|
||||
sirValues = summaryTable.sir_exact(curveMask).';
|
||||
meanBer = summaryTable.mean_BER(curveMask).';
|
||||
boundCenterBer = summaryTable.std_center_BER(curveMask).';
|
||||
boundLowerBer = summaryTable.std_lower_BER(curveMask).';
|
||||
boundUpperBer = summaryTable.std_upper_BER(curveMask).';
|
||||
valid = isfinite(sirValues) & isfinite(meanBer) & meanBer > 0;
|
||||
|
||||
if useBoundedLines && exist("boundedline", "file") && any(valid)
|
||||
[xBand, centerBand, yBounds] = berStdBounds( ...
|
||||
sirValues, boundCenterBer, boundLowerBer, boundUpperBer, ...
|
||||
boundMode, boundaryPolyfitOrderMax);
|
||||
|
||||
[hl, hp] = boundedline(xBand, centerBand, yBounds, ...
|
||||
'alpha', 'transparency', 0.1, ...
|
||||
'cmap', algColor, ...
|
||||
'nan', 'fill', ...
|
||||
'orientation', 'vert');
|
||||
set(hl, "LineStyle", "none", "LineWidth", 1, "Marker", "none", ...
|
||||
"HandleVisibility", "off", "DisplayName", char(displayName));
|
||||
set(hp, "LineStyle", "-", "HandleVisibility", "off", "Marker", "none");
|
||||
end
|
||||
|
||||
plot(sirValues(valid), meanBer(valid), ...
|
||||
"LineStyle", "-", ...
|
||||
"Marker", marker, ...
|
||||
"MarkerSize", 3, ...
|
||||
"LineWidth", 1, ...
|
||||
"Color", algColor, ...
|
||||
"MarkerFaceColor", "w", ...
|
||||
"MarkerEdgeColor", algColor, ...
|
||||
"DisplayName", char(displayName), ...
|
||||
"HandleVisibility", "on");
|
||||
|
||||
if usePolyfit
|
||||
fitMask = valid & meanBer > 0;
|
||||
if nnz(fitMask) >= 2
|
||||
fitOrder = min(polyfitOrderMax, nnz(fitMask) - 1);
|
||||
fitCoeff = polyfit(sirValues(fitMask), log10(meanBer(fitMask)), fitOrder);
|
||||
xFit = linspace(min(sirValues(fitMask)), max(sirValues(fitMask)), 300);
|
||||
yFit = 10 .^ polyval(fitCoeff, xFit);
|
||||
plot(xFit, yFit, ...
|
||||
"LineStyle", "--", ...
|
||||
"LineWidth", 1.1, ...
|
||||
"Color", algColor, ...
|
||||
"HandleVisibility", "off");
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
yline(2.2e-4, "LineWidth", 1, "LineStyle", "--", "HandleVisibility", "off");
|
||||
yline(fecBerThreshold, "LineWidth", 1, "LineStyle", "--", "HandleVisibility", "off");
|
||||
yline(2e-2, "LineWidth", 1, "LineStyle", "--", "HandleVisibility", "off");
|
||||
|
||||
title(sprintf("Simulated MPI, block update %.0f", blockUpdate));
|
||||
xlabel("SIR (dB)");
|
||||
ylabel("BER");
|
||||
set(gca, "YScale", "log");
|
||||
ylim([9e-5, maxBerForPlot]);
|
||||
xlim([min(cleanData.sir) - 1, max(cleanData.sir) + 1]);
|
||||
grid on;
|
||||
box on;
|
||||
legend("Location", "northeast", "Interpreter", "none");
|
||||
|
||||
if exist("beautifyBERplot", "file")
|
||||
beautifyBERplot("logscale", true, "setcolors", false, "setmarkers", false);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function data = collectMpiSimulationBerRows(wh)
|
||||
storageNames = string(fieldnames(wh.sto));
|
||||
data = table();
|
||||
|
||||
for storageIdx = 1:numel(storageNames)
|
||||
storageName = storageNames(storageIdx);
|
||||
storage = wh.sto.(char(storageName));
|
||||
|
||||
for linIdx = 1:numel(storage)
|
||||
package = storage{linIdx};
|
||||
ber = extractPackageBer(package);
|
||||
if ~isfinite(ber)
|
||||
continue
|
||||
end
|
||||
|
||||
[physValues, physNames] = wh.getPhysIndicesByLinIndex(linIdx);
|
||||
phys = struct();
|
||||
for physIdx = 1:numel(physNames)
|
||||
phys.(char(physNames{physIdx})) = physValues{physIdx};
|
||||
end
|
||||
|
||||
algorithm = extractPackageAlgorithm(package, storageName);
|
||||
newRow = table( ...
|
||||
storageName, ...
|
||||
algorithm, ...
|
||||
readPhysValue(phys, "sir", NaN), ...
|
||||
readPhysValue(phys, "block_update", NaN), ...
|
||||
readPhysValue(phys, "random_key", NaN), ...
|
||||
readPhysValue(phys, "laser_linewidth", NaN), ...
|
||||
ber, ...
|
||||
'VariableNames', {'storage_name', 'algorithm', 'sir', ...
|
||||
'block_update', 'random_key', 'laser_linewidth', 'BER'});
|
||||
data = [data; newRow]; %#ok<AGROW>
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function data = normalizeBerColumnName(data)
|
||||
variableNames = string(data.Properties.VariableNames);
|
||||
if ismember("BER", variableNames)
|
||||
return
|
||||
end
|
||||
|
||||
if ismember("ber", variableNames)
|
||||
data.Properties.VariableNames(variableNames == "ber") = {'BER'};
|
||||
return
|
||||
end
|
||||
|
||||
error("run_mpi_simulation_recipe:MissingBerColumn", ...
|
||||
"Could not find a BER or ber column in the simulation BER table.");
|
||||
end
|
||||
|
||||
function value = readPhysValue(phys, name, defaultValue)
|
||||
if isfield(phys, name)
|
||||
value = phys.(name);
|
||||
else
|
||||
value = defaultValue;
|
||||
end
|
||||
end
|
||||
|
||||
function ber = extractPackageBer(package)
|
||||
ber = NaN;
|
||||
if isempty(package)
|
||||
return
|
||||
end
|
||||
|
||||
if iscell(package)
|
||||
package = package{1};
|
||||
end
|
||||
|
||||
if isstruct(package) && isfield(package, "metrics")
|
||||
metrics = package.metrics;
|
||||
if isstruct(metrics) && isfield(metrics, "BER")
|
||||
ber = metrics.BER;
|
||||
elseif isobject(metrics) && isprop(metrics, "BER")
|
||||
ber = metrics.BER;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function algorithm = extractPackageAlgorithm(package, fallbackName)
|
||||
algorithm = fallbackName;
|
||||
if isempty(package)
|
||||
return
|
||||
end
|
||||
|
||||
if iscell(package)
|
||||
package = package{1};
|
||||
end
|
||||
|
||||
if isstruct(package) && isfield(package, "mpi_reduction_config") && ...
|
||||
isfield(package.mpi_reduction_config, "algorithm")
|
||||
algorithm = string(package.mpi_reduction_config.algorithm);
|
||||
end
|
||||
end
|
||||
|
||||
function summaryTable = addBerStdBounds(summaryTable, cleanData, groupVars)
|
||||
nGroups = height(summaryTable);
|
||||
stdCenter = NaN(nGroups, 1);
|
||||
stdLower = NaN(nGroups, 1);
|
||||
stdUpper = NaN(nGroups, 1);
|
||||
|
||||
for groupIdx = 1:nGroups
|
||||
rowMask = true(height(cleanData), 1);
|
||||
for varIdx = 1:numel(groupVars)
|
||||
varName = groupVars(varIdx);
|
||||
rowMask = rowMask & cleanData.(char(varName)) == summaryTable.(char(varName))(groupIdx);
|
||||
end
|
||||
|
||||
[stdCenter(groupIdx), stdLower(groupIdx), stdUpper(groupIdx)] = ...
|
||||
logBerMeanStdInterval(cleanData.BER(rowMask));
|
||||
end
|
||||
|
||||
summaryTable.std_center_BER = stdCenter;
|
||||
summaryTable.std_lower_BER = stdLower;
|
||||
summaryTable.std_upper_BER = stdUpper;
|
||||
end
|
||||
|
||||
function [centerBer, lowerBer, upperBer] = logBerMeanStdInterval(berValues)
|
||||
berValues = berValues(isfinite(berValues) & berValues > 0);
|
||||
if isempty(berValues)
|
||||
centerBer = NaN;
|
||||
lowerBer = NaN;
|
||||
upperBer = NaN;
|
||||
return
|
||||
end
|
||||
|
||||
logBer = log10(berValues(:));
|
||||
centerLog = mean(logBer, "omitnan");
|
||||
stdLog = std(logBer, 0, "omitnan");
|
||||
|
||||
centerBer = 10 .^ centerLog;
|
||||
lowerBer = 10 .^ (centerLog - stdLog);
|
||||
upperBer = 10 .^ (centerLog + stdLog);
|
||||
end
|
||||
|
||||
function [xBand, centerBand, yBounds] = berStdBounds(sirValues, centerBer, lowerBer, upperBer, boundMode, maxOrder)
|
||||
if boundMode == "directStd"
|
||||
[xBand, centerBand, yBounds] = directBerBounds(sirValues, centerBer, lowerBer, upperBer);
|
||||
return
|
||||
end
|
||||
|
||||
[xBand, centerBand, yBounds] = fittedBerBounds(sirValues, centerBer, lowerBer, upperBer, maxOrder);
|
||||
end
|
||||
|
||||
function [xBand, centerBand, yBounds] = directBerBounds(sirValues, centerBer, lowerBer, upperBer)
|
||||
valid = isfinite(sirValues) & isfinite(centerBer) & isfinite(lowerBer) & ...
|
||||
isfinite(upperBer) & centerBer > 0 & lowerBer > 0 & upperBer > 0;
|
||||
|
||||
xBand = sirValues(valid).';
|
||||
centerBand = centerBer(valid).';
|
||||
lowerBand = lowerBer(valid).';
|
||||
upperBand = upperBer(valid).';
|
||||
|
||||
[xBand, orderIdx] = sort(xBand(:));
|
||||
centerBand = centerBand(orderIdx);
|
||||
lowerBand = lowerBand(orderIdx);
|
||||
upperBand = upperBand(orderIdx);
|
||||
|
||||
lowerTmp = min(lowerBand, upperBand);
|
||||
upperBand = max(lowerBand, upperBand);
|
||||
lowerBand = lowerTmp;
|
||||
|
||||
centerBand = min(max(centerBand, lowerBand), upperBand);
|
||||
yBounds = [max(centerBand - lowerBand, 0), max(upperBand - centerBand, 0)];
|
||||
end
|
||||
|
||||
function [xBand, centerBand, yBounds] = fittedBerBounds(sirValues, meanBer, minBer, maxBer, maxOrder)
|
||||
valid = isfinite(sirValues) & isfinite(meanBer) & isfinite(minBer) & ...
|
||||
isfinite(maxBer) & meanBer > 0 & minBer > 0 & maxBer > 0;
|
||||
|
||||
x = sirValues(valid);
|
||||
yMean = meanBer(valid);
|
||||
yMin = minBer(valid);
|
||||
yMax = maxBer(valid);
|
||||
|
||||
if numel(x) < 2
|
||||
xBand = x(:);
|
||||
centerBand = yMean(:);
|
||||
yBounds = [max(yMean(:) - yMin(:), 0), max(yMax(:) - yMean(:), 0)];
|
||||
return
|
||||
end
|
||||
|
||||
[x, orderIdx] = sort(x(:));
|
||||
yMean = yMean(orderIdx);
|
||||
yMin = yMin(orderIdx);
|
||||
yMax = yMax(orderIdx);
|
||||
|
||||
xBand = linspace(min(x), max(x), 300).';
|
||||
fitOrder = min(maxOrder, numel(unique(x)) - 1);
|
||||
|
||||
if fitOrder < 1
|
||||
centerBand = interp1(x, yMean, xBand, "linear", "extrap");
|
||||
lowerBand = interp1(x, yMin, xBand, "linear", "extrap");
|
||||
upperBand = interp1(x, yMax, xBand, "linear", "extrap");
|
||||
else
|
||||
centerBand = fitLogBer(x, yMean, xBand, fitOrder);
|
||||
lowerBand = fitLogBer(x, yMin, xBand, fitOrder);
|
||||
upperBand = fitLogBer(x, yMax, xBand, fitOrder);
|
||||
end
|
||||
|
||||
lowerTmp = min(lowerBand, upperBand);
|
||||
upperBand = max(lowerBand, upperBand);
|
||||
lowerBand = lowerTmp;
|
||||
|
||||
centerBand = min(max(centerBand, lowerBand), upperBand);
|
||||
yBounds = [max(centerBand - lowerBand, 0), max(upperBand - centerBand, 0)];
|
||||
end
|
||||
|
||||
function yFit = fitLogBer(x, y, xFit, fitOrder)
|
||||
coeff = polyfit(x, log10(y), fitOrder);
|
||||
yFit = 10 .^ polyval(coeff, xFit);
|
||||
end
|
||||
|
||||
function label = algorithmDisplayName(algorithmName)
|
||||
algorithmName = string(algorithmName);
|
||||
switch algorithmName
|
||||
case {"plain_ffe", "conventional_ffe"}
|
||||
label = "FFE only";
|
||||
case "a2_tracked_levels"
|
||||
label = "ACT";
|
||||
case "a2_residual"
|
||||
label = "L-DCA";
|
||||
case "a1_moving_average"
|
||||
label = "DCA";
|
||||
case "dc_tracking"
|
||||
label = "DCT";
|
||||
otherwise
|
||||
label = algorithmName;
|
||||
end
|
||||
end
|
||||
|
||||
function color = algorithmColor(algorithmName)
|
||||
algorithmName = string(algorithmName);
|
||||
switch algorithmName
|
||||
case {"plain_ffe", "conventional_ffe"}
|
||||
color = [0.3467 0.5360 0.6907];
|
||||
case "a2_tracked_levels"
|
||||
color = [0.9153 0.2816 0.2878];
|
||||
case "a2_residual"
|
||||
color = [0.4416 0.7490 0.4322];
|
||||
case "a1_moving_average"
|
||||
color = [1.0000 0.5984 0.2000];
|
||||
case "dc_tracking"
|
||||
color = [0.6769 0.4447 0.7114];
|
||||
otherwise
|
||||
color = [0 0 0];
|
||||
end
|
||||
end
|
||||
|
||||
function marker = algorithmMarker(algorithmName, algorithmMarkers)
|
||||
algorithmOrder = ["conventional_ffe", "dc_tracking", "a2_tracked_levels", ...
|
||||
"a2_residual", "a1_moving_average"];
|
||||
markerIdx = find(algorithmOrder == string(algorithmName), 1);
|
||||
if isempty(markerIdx)
|
||||
markerIdx = 1;
|
||||
end
|
||||
marker = algorithmMarkers{mod(markerIdx - 1, numel(algorithmMarkers)) + 1};
|
||||
end
|
||||
@@ -0,0 +1,87 @@
|
||||
function [results, wh] = submitMpiSimulationJobs(wh, simulation_config, options)
|
||||
%SUBMITMPISIMULATIONJOBS Execute MPI simulation warehouse points via runBatch.
|
||||
|
||||
arguments
|
||||
wh DataStorage
|
||||
simulation_config struct
|
||||
options.mode = processingMode.serial
|
||||
options.waitbar (1,1) logical = true
|
||||
options.numWorkers (1,1) double {mustBeNonnegative, mustBeInteger} = 0
|
||||
options.idleTimeout (1,1) double {mustBePositive} = 300
|
||||
options.cancelExistingQueue (1,1) logical = true
|
||||
end
|
||||
|
||||
nJobs = wh.getLastLinIndice();
|
||||
jobs = repmat(struct("args", {{}}, "label", "", "meta", struct()), 1, nJobs);
|
||||
|
||||
for linIdx = 1:nJobs
|
||||
userParameters = buildUserParameters(wh, linIdx);
|
||||
jobs(linIdx).args = {userParameters, simulation_config};
|
||||
jobs(linIdx).label = buildJobLabel(userParameters, linIdx);
|
||||
jobs(linIdx).meta.lin_idx = linIdx;
|
||||
jobs(linIdx).meta.userParameters = userParameters;
|
||||
end
|
||||
|
||||
results = runBatch(@mpi_simulation_worker, jobs, ...
|
||||
"mode", options.mode, ...
|
||||
"waitbar", options.waitbar, ...
|
||||
"waitbarMessage", "Processing MPI simulations...", ...
|
||||
"numWorkers", options.numWorkers, ...
|
||||
"idleTimeout", options.idleTimeout, ...
|
||||
"cancelExistingQueue", options.cancelExistingQueue, ...
|
||||
"resultHandler", @storeResult, ...
|
||||
"errorHandler", @handleError);
|
||||
|
||||
function userParameters = buildUserParameters(storageWh, linIdx)
|
||||
userParameters = struct();
|
||||
if isempty(storageWh.getDimension())
|
||||
return
|
||||
end
|
||||
|
||||
[values, names] = storageWh.getPhysIndicesByLinIndex(linIdx);
|
||||
for paramIdx = 1:numel(names)
|
||||
userParameters.(char(names{paramIdx})) = values{paramIdx};
|
||||
end
|
||||
end
|
||||
|
||||
function label = buildJobLabel(userParameters, linIdx)
|
||||
label = sprintf("MPI sim job %d", linIdx);
|
||||
if isfield(userParameters, "sir")
|
||||
label = sprintf("%s, SIR %g dB", label, userParameters.sir);
|
||||
end
|
||||
if isfield(userParameters, "block_update")
|
||||
label = sprintf("%s, block %g", label, userParameters.block_update);
|
||||
end
|
||||
end
|
||||
|
||||
function storeResult(val, job, ~)
|
||||
if isempty(val) || ~isstruct(val)
|
||||
return
|
||||
end
|
||||
|
||||
storageNames = fieldnames(val);
|
||||
for storageIdx = 1:numel(storageNames)
|
||||
storageName = storageNames{storageIdx};
|
||||
if isempty(val.(storageName))
|
||||
continue
|
||||
end
|
||||
|
||||
ensureStorage(storageName);
|
||||
wh.addValueToStorageByLinIdx(val.(storageName), storageName, job.meta.lin_idx);
|
||||
end
|
||||
end
|
||||
|
||||
function ensureStorage(storageName)
|
||||
if ~isfield(wh.sto, storageName)
|
||||
wh.addStorage(storageName);
|
||||
end
|
||||
end
|
||||
|
||||
function handleError(ME, job, ~)
|
||||
fprintf("[%s] ERROR [%s]: %s\n", job.label, ME.identifier, ME.message);
|
||||
for st = ME.stack'
|
||||
fprintf(" %s:%d (%s)\n", st.file, st.line, st.name);
|
||||
end
|
||||
fprintf("Full report:\n%s\n", getReport(ME, "extended"));
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user