Many changes towards simulation of JLT and once again the evaluation of the Highspeed data from Lab experiments 2024

This commit is contained in:
Silas Oettinghaus
2025-07-09 10:50:53 +02:00
parent 9ce23c4a10
commit 2cff29f239
35 changed files with 1874 additions and 549 deletions

View File

@@ -5,7 +5,7 @@ classdef DBHandler < handle
properties
conn % Database connection object
pathToDB % Path to the SQLite database
dataBase % Path to the SQLite database
tableNames % Cell array containing names of all tables in the database
tables = struct(); % Structure containing MATLAB tables for each database table
distinctValues
@@ -21,7 +21,7 @@ classdef DBHandler < handle
% obj = DBHandler('pathToDB', 'path/to/database.db');
arguments
options.pathToDB = ""; % Default value for pathToDB if not provided
options.dataBase = ""; % Default value for pathToDB if not provided
options.type = "mysql";
end
@@ -37,12 +37,17 @@ classdef DBHandler < handle
try
if options.type == "sqlite"
obj.conn = sqlite(obj.pathToDB);
obj.conn = sqlite(obj.dataBase);
elseif options.type == "mysql"
datasource = "jdbc:mysql://134.245.243.254:3306/labor";
% datasource = "jdbc:mysql://134.245.243.254:3306/labor";
obj.conn = database( ...
"labor", ... % Database name
string(obj.dataBase), ... % Database name
"silas", ... % Username
"silas", ... % Password (or getSecret)
"Vendor", "MySQL", ...
@@ -68,8 +73,10 @@ classdef DBHandler < handle
function obj = refresh(obj)
% Get table names and the first rows of each table to understand the structure
warning off
obj.getTableNames();
obj.getTables();
warning on
% obj.getDistinctValues();
end
@@ -201,20 +208,24 @@ classdef DBHandler < handle
if isstruct(newRow)
fields = fieldnames(newRow);
% Handle empty fields
emptyFields = structfun(@isempty, newRow);
if sum(emptyFields) > 0
emptyFieldNames = fields(emptyFields);
for idx = 1:numel(emptyFieldNames)
newRow.(emptyFieldNames{idx}) = NaN;
end
end
% % Handle empty fields
% emptyFields = structfun(@isempty, newRow);
% if sum(emptyFields) > 0
% emptyFieldNames = fields(emptyFields);
% for idx = 1:numel(emptyFieldNames)
% newRow.(emptyFieldNames{idx}) = NaN;
% end
% end
% Convert arrays to JSON strings
for i = 1:length(fields)
fieldValue = newRow.(fields{i});
if isnumeric(fieldValue) && length(fieldValue) > 1
newRow.(fields{i}) = jsonencode(fieldValue);
% Convert any non-scalar numeric (including [] and vectors) into JSON
for i = 1:numel(fields)
name = fields{i};
value = newRow.(name);
if isnumeric(value) && ~isscalar(value)
% jsonencode([]) -> "[]"
% jsonencode([a,b,c]) -> "[a,b,c]"
newRow.(name) = jsonencode(value);
end
end
@@ -238,6 +249,7 @@ classdef DBHandler < handle
elseif ischar(value)
newRow.(colName{1}) = string(value);
end
end
% Parameters for retry logic
@@ -251,7 +263,7 @@ classdef DBHandler < handle
if obj.type == "mysql"
newRow_ = obj.convertTableToCellStrings(newRow);
end
sqlwrite(obj.conn, tableName, newRow);
sqlwrite(obj.conn, tableName, newRow,"Catalog",obj.dataBase);
success = true;
catch e
if contains(e.message, 'database is locked') || contains(e.message, 'cannot rollback transaction')

View File

@@ -1,6 +1,6 @@
classdef Metricstruct
% ResultData - Class to store and manage metric data from signal processing results
properties
result_id (1,1) double {mustBeNumeric} = NaN
run_id (1,1) double {mustBeNumeric} = NaN
@@ -24,15 +24,15 @@ classdef Metricstruct
GMI (1,1) double {mustBeNumeric} = NaN
AIR (1,1) double {mustBeNumeric} = NaN
Alpha (:,1) double {mustBeNumeric} = []
Alpha (:,1) double {mustBeNumeric} = NaN
MLSE_dir (:,1) double {mustBeNumeric} = []
end
methods
function obj = Metricstruct(varargin)
% Constructor method for ResultData
% Can be called empty or with name-value pairs
% Process name-value pairs if provided
if nargin > 0
for i = 1:2:nargin
@@ -44,7 +44,7 @@ classdef Metricstruct
end
end
end
function s = toStruct(obj)
% Convert the object to a struct
s = struct();
@@ -53,7 +53,7 @@ classdef Metricstruct
s.(props{i}) = obj.(props{i});
end
end
function str = toString(obj)
% Convert the object to a formatted string
s = obj.toStruct();
@@ -70,9 +70,62 @@ classdef Metricstruct
end
end
end
function print(obj)
% Print method to display key metrics in a formatted way
% Define the width for formatting
nameWidth = 15; % Width for parameter names
valueWidth = 12; % Width for values
% Print header
fprintf('\n%s\n', repmat('=', 1, nameWidth + valueWidth));
fprintf(' Results \n');
fprintf('%s\n', repmat('=', 1, nameWidth + valueWidth));
% Function to format numbers with appropriate precision
function str = formatNumber(value)
if isnan(value)
str = 'N/A';
elseif abs(value) < 0.1 && value ~= 0
str = sprintf('%.2e', value);
else
str = sprintf('%.4f', value);
end
end
% Print each metric
% BER metrics
fprintf('%-*s: %*s\n', nameWidth, 'BER', valueWidth, formatNumber(obj.BER));
fprintf('%-*s: %*s\n', nameWidth, 'BER (precoded)', valueWidth, formatNumber(obj.BER_precoded));
% SNR
fprintf('%-*s: %*s\n', nameWidth, 'SNR', valueWidth, formatNumber(obj.SNR));
% Information rates
fprintf('%-*s: %*s\n', nameWidth, 'GMI', valueWidth, formatNumber(obj.GMI));
fprintf('%-*s: %*s GBd \n', nameWidth, 'AIR', valueWidth, formatNumber(obj.AIR.*1e-9));
% Alpha (if it's not empty, show first few values)
if ~isempty(obj.Alpha)
if length(obj.Alpha) <= 3
alphaStr = sprintf('%.4f ', obj.Alpha);
else
alphaStr = sprintf('%.4f %.4f %.4f...', obj.Alpha(1:3));
end
fprintf('%-*s: %s\n', nameWidth, 'Alpha', alphaStr);
else
fprintf('%-*s: %*s\n', nameWidth, 'Alpha', valueWidth, '[]');
end
% Print footer
fprintf('%s\n', repmat('=', 1, nameWidth + valueWidth));
end
end
methods (Static)
function obj = fromStruct(s)
% Create a ResultData object from a struct
obj = Metricstruct();
@@ -83,5 +136,6 @@ classdef Metricstruct
end
end
end
end
end