restructure and organize
This commit is contained in:
106
Functions/EQ_blocks/dsp_runid.m
Normal file
106
Functions/EQ_blocks/dsp_runid.m
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
function output = dsp_runid(run_id, options)
|
||||||
|
|
||||||
|
arguments
|
||||||
|
run_id
|
||||||
|
options.append_to_db = 0;
|
||||||
|
options.max_occurences = 4;
|
||||||
|
options.userParameters = struct();
|
||||||
|
options.database_type
|
||||||
|
options.dataBase
|
||||||
|
options.server = "134.245.243.254";
|
||||||
|
options.port = 3306;
|
||||||
|
options.user = "silas";
|
||||||
|
options.password = "silas";
|
||||||
|
options.load_file_path = struct();
|
||||||
|
options.storage_path
|
||||||
|
options.mode
|
||||||
|
options.recipe = @dsp_scope_signal;
|
||||||
|
options.debug_plots (1,1) logical = false;
|
||||||
|
end
|
||||||
|
|
||||||
|
try
|
||||||
|
output = initializeOutput();
|
||||||
|
database = [];
|
||||||
|
inputSource = normalizeDspInputSource(options.mode);
|
||||||
|
|
||||||
|
if inputSource == "run_id" || options.append_to_db
|
||||||
|
database = DBHandler("dataBase", [options.dataBase], "type", options.database_type, ...
|
||||||
|
"user", options.user, "password", options.password, ...
|
||||||
|
"server", options.server, "port", options.port);
|
||||||
|
end
|
||||||
|
|
||||||
|
switch inputSource
|
||||||
|
case "run_id"
|
||||||
|
dspInput = loadDspInputFromRunId(run_id, database, options);
|
||||||
|
case "file_paths"
|
||||||
|
dspInput = loadDspInputFromFilePaths(run_id, options);
|
||||||
|
end
|
||||||
|
|
||||||
|
options.max_occurences = min(options.max_occurences, length(dspInput.Scpe_cell));
|
||||||
|
for r = 1:options.max_occurences
|
||||||
|
|
||||||
|
%%%%%%%% CORE EQUALIZATION CALL (Scpe, Symbols, Bits, 'Options') %%%%%%%
|
||||||
|
|
||||||
|
dspOutput = options.recipe(dspInput.Scpe_cell{r}, dspInput.Symbols, dspInput.Tx_bits, ...
|
||||||
|
"fsym", dspInput.fsym, ...
|
||||||
|
"M", dspInput.M, ...
|
||||||
|
"duob_mode", dspInput.duob_mode, ...
|
||||||
|
"dataTable", dspInput.dataTable, ...
|
||||||
|
"userParameters", options.userParameters, ...
|
||||||
|
"debug_plots", options.debug_plots);
|
||||||
|
|
||||||
|
%%%%%%%% CORE EQUALIZATION CALL %%%%%%%
|
||||||
|
|
||||||
|
fieldNames = fieldnames(dspOutput);
|
||||||
|
for fieldIdx = 1:numel(fieldNames)
|
||||||
|
fieldName = fieldNames{fieldIdx};
|
||||||
|
output.(fieldName){r} = dspOutput.(fieldName);
|
||||||
|
end
|
||||||
|
if options.append_to_db
|
||||||
|
appendDspOutputToDatabase(database, run_id, dspOutput);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
catch ME
|
||||||
|
save('workerError.mat', 'ME');
|
||||||
|
rethrow(ME);
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function output = initializeOutput()
|
||||||
|
output.ffe_package = {};
|
||||||
|
output.dfe_package = {};
|
||||||
|
output.mlse_package = {};
|
||||||
|
output.vnle_package = {};
|
||||||
|
output.dbtgt_package = {};
|
||||||
|
output.dbenc_package = {};
|
||||||
|
output.mlmlse_package = {};
|
||||||
|
end
|
||||||
|
|
||||||
|
function inputSource = normalizeDspInputSource(mode)
|
||||||
|
mode = string(mode);
|
||||||
|
|
||||||
|
switch mode
|
||||||
|
case {"load_run_id", "run_id"}
|
||||||
|
inputSource = "run_id";
|
||||||
|
case {"load_files", "file_paths"}
|
||||||
|
inputSource = "file_paths";
|
||||||
|
otherwise
|
||||||
|
error('dsp_runid:UnsupportedMode', ...
|
||||||
|
'Mode "%s" is not supported. Use "run_id" or "file_paths".', mode);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function appendDspOutputToDatabase(database, run_id, dspOutput)
|
||||||
|
packageNames = fieldnames(dspOutput);
|
||||||
|
|
||||||
|
for i = 1:numel(packageNames)
|
||||||
|
package = dspOutput.(packageNames{i});
|
||||||
|
if isempty(package)
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
|
||||||
|
database.addProcessingResult(run_id, package.metrics, package.config);
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -8,7 +8,7 @@ function output = dsp_scope_signal(Scpe_sig_raw, Symbols, Tx_bits, options)
|
|||||||
options.fsym
|
options.fsym
|
||||||
options.M
|
options.M
|
||||||
options.duob_mode
|
options.duob_mode
|
||||||
options.parameters struct = struct()
|
options.userParameters struct = struct()
|
||||||
options.preprocess_mode string = "auto"
|
options.preprocess_mode string = "auto"
|
||||||
options.tx_pulseformer = []
|
options.tx_pulseformer = []
|
||||||
options.debug_plots (1,1) logical = false
|
options.debug_plots (1,1) logical = false
|
||||||
@@ -57,7 +57,7 @@ function output = dsp_scope_signal(Scpe_sig_raw, Symbols, Tx_bits, options)
|
|||||||
|
|
||||||
addProcessingResultToDatabase = 0; %#ok<NASGU>
|
addProcessingResultToDatabase = 0; %#ok<NASGU>
|
||||||
|
|
||||||
paramStruct = options.parameters;
|
paramStruct = options.userParameters;
|
||||||
if ~isempty(paramStruct)
|
if ~isempty(paramStruct)
|
||||||
paramNames = fieldnames(paramStruct);
|
paramNames = fieldnames(paramStruct);
|
||||||
for i = 1:numel(paramNames)
|
for i = 1:numel(paramNames)
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
function output = dsp_runid(run_id, options)
|
|
||||||
|
|
||||||
arguments
|
|
||||||
run_id
|
|
||||||
options.append_to_db = 0;
|
|
||||||
options.max_occurences = 4;
|
|
||||||
options.parameters = struct();
|
|
||||||
options.database_type
|
|
||||||
options.dataBase
|
|
||||||
options.server = "134.245.243.254";
|
|
||||||
options.port = 3306;
|
|
||||||
options.user = "silas";
|
|
||||||
options.password = "silas";
|
|
||||||
options.load_file_path = struct();
|
|
||||||
options.storage_path
|
|
||||||
options.mode
|
|
||||||
end
|
|
||||||
|
|
||||||
try
|
|
||||||
output = initializeOutput();
|
|
||||||
database = [];
|
|
||||||
|
|
||||||
if options.mode == "load_run_id" || options.append_to_db
|
|
||||||
database = DBHandler("dataBase", [options.dataBase], "type", options.database_type, ...
|
|
||||||
"user", options.user, "password", options.password, ...
|
|
||||||
"server", options.server, "port", options.port);
|
|
||||||
end
|
|
||||||
|
|
||||||
if options.mode == "load_run_id"
|
|
||||||
dspInput = preprocessRunId(run_id, database, options);
|
|
||||||
elseif options.mode == "load_files"
|
|
||||||
dspInput = loadDspInputFromFiles(run_id, options);
|
|
||||||
else
|
|
||||||
error('dsp_runid:UnsupportedMode', 'Mode "%s" is not supported by the refactored dsp_runid path.', options.mode);
|
|
||||||
end
|
|
||||||
|
|
||||||
options.max_occurences = min(options.max_occurences, length(dspInput.Scpe_cell));
|
|
||||||
for r = 1:options.max_occurences
|
|
||||||
scopeOutput = dsp_scope_signal(dspInput.Scpe_cell{r}, dspInput.Symbols, dspInput.Tx_bits, ...
|
|
||||||
"fsym", dspInput.fsym, ...
|
|
||||||
"M", dspInput.M, ...
|
|
||||||
"duob_mode", dspInput.duob_mode, ...
|
|
||||||
"parameters", options.parameters);
|
|
||||||
|
|
||||||
output.ffe_package{r} = scopeOutput.ffe_package;
|
|
||||||
output.dfe_package{r} = scopeOutput.dfe_package;
|
|
||||||
output.mlse_package{r} = scopeOutput.mlse_package;
|
|
||||||
output.vnle_package{r} = scopeOutput.vnle_package;
|
|
||||||
output.dbtgt_package{r} = scopeOutput.dbtgt_package;
|
|
||||||
output.dbenc_package{r} = scopeOutput.dbenc_package;
|
|
||||||
output.mlmlse_package{r} = scopeOutput.mlmlse_package;
|
|
||||||
|
|
||||||
if options.append_to_db
|
|
||||||
appendScopeOutputToDatabase(database, run_id, scopeOutput);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
catch ME
|
|
||||||
save('workerError.mat', 'ME');
|
|
||||||
rethrow(ME);
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function output = initializeOutput()
|
|
||||||
output.ffe_package = {};
|
|
||||||
output.dfe_package = {};
|
|
||||||
output.mlse_package = {};
|
|
||||||
output.vnle_package = {};
|
|
||||||
output.dbtgt_package = {};
|
|
||||||
output.dbenc_package = {};
|
|
||||||
output.mlmlse_package = {};
|
|
||||||
end
|
|
||||||
|
|
||||||
function dspInput = loadDspInputFromFiles(run_id, options)
|
|
||||||
Tx_bits = load(options.load_file_path.tx_bits_path);
|
|
||||||
Symbols = load(options.load_file_path.tx_symbols_path);
|
|
||||||
Scpe_sig_raw = load(options.load_file_path.rx_raw_path);
|
|
||||||
|
|
||||||
Tx_bits = Tx_bits.Bits;
|
|
||||||
Symbols = Symbols.Symbols;
|
|
||||||
Scpe_sig_raw = Scpe_sig_raw.Scpe_sig_raw;
|
|
||||||
|
|
||||||
fsym = Symbols.fs;
|
|
||||||
M = Symbols.logbook.ModifierCopy{1}.M;
|
|
||||||
duob_mode = Symbols.logbook.ModifierCopy{1}.duobinary_mode;
|
|
||||||
|
|
||||||
Scpe_sig_resampled = Scpe_sig_raw.resample("fs_in", Scpe_sig_raw.fs, "fs_out", 2*fsym);
|
|
||||||
[~, Scpe_cell, ~, found_sync] = Scpe_sig_resampled.tsynch("reference", Symbols, "fs_ref", fsym, "debug_plots", 1);
|
|
||||||
|
|
||||||
dspInput = struct();
|
|
||||||
dspInput.run_id = run_id;
|
|
||||||
dspInput.dataTable = table();
|
|
||||||
dspInput.Tx_bits = Tx_bits;
|
|
||||||
dspInput.Symbols = Symbols;
|
|
||||||
dspInput.Scpe_cell = Scpe_cell;
|
|
||||||
dspInput.found_sync = found_sync;
|
|
||||||
dspInput.fsym = fsym;
|
|
||||||
dspInput.M = M;
|
|
||||||
dspInput.duob_mode = duob_mode;
|
|
||||||
end
|
|
||||||
|
|
||||||
function appendScopeOutputToDatabase(database, run_id, scopeOutput)
|
|
||||||
packageNames = fieldnames(scopeOutput);
|
|
||||||
|
|
||||||
for i = 1:numel(packageNames)
|
|
||||||
package = scopeOutput.(packageNames{i});
|
|
||||||
if isempty(package)
|
|
||||||
continue
|
|
||||||
end
|
|
||||||
|
|
||||||
database.addProcessingResult(run_id, package.metrics, package.config);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Reference in New Issue
Block a user