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 eqParam_id (1,1) double {mustBeNumeric} = NaN date_of_processing (1,1) datetime = datetime('now') numBits (1,1) double = 0 BER (1,1) double = 0 numBitErr (1,1) double = 0 BER_precoded (1,1) double = 0 numBitErr_precoded (1,1) double = 0 SNR (1,1) double {mustBeNumeric} = NaN SNR_level (:,1) double {mustBeNumeric} = [] STD (1,1) double {mustBeNumeric} = NaN STD_level (:,1) double = [] STDrx (1,1) double {mustBeNumeric} = NaN STDrx_level (:,1) double = [] EVM (1,1) double {mustBeNumeric} = NaN EVM_level (:,1) double {mustBeNumeric} = [] GMI (1,1) double {mustBeNumeric} = NaN AIR (1,1) double {mustBeNumeric} = NaN 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 if isprop(obj, varargin{i}) obj.(varargin{i}) = varargin{i+1}; else error('Property %s does not exist in ResultData', varargin{i}); end end end end function s = toStruct(obj) % Convert the object to a struct s = struct(); props = properties(obj); for i = 1:length(props) s.(props{i}) = obj.(props{i}); end end function str = toString(obj) % Convert the object to a formatted string s = obj.toStruct(); str = sprintf('ResultData:\n'); fields = fieldnames(s); for i = 1:length(fields) val = s.(fields{i}); if isempty(val) str = sprintf('%s%s: []\n', str, fields{i}); elseif isnumeric(val) && length(val) > 1 str = sprintf('%s%s: [%s]\n', str, fields{i}, num2str(val')); else str = sprintf('%s%s: %s\n', str, fields{i}, string(val)); end end end function print(obj,options) % Print method to display key metrics in a formatted way arguments obj options.description = ''; end % 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([char(options.description),' 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(); fields = fieldnames(s); for i = 1:length(fields) if isprop(obj, fields{i}) obj.(fields{i}) = s.(fields{i}); end end end end end