restructure and organize
This commit is contained in:
97
Functions/Job_Processing/loadDspInputFromFilePaths.m
Normal file
97
Functions/Job_Processing/loadDspInputFromFilePaths.m
Normal file
@@ -0,0 +1,97 @@
|
||||
function dspInput = loadDspInputFromFilePaths(run_id, options)
|
||||
%LOADDSPINPUTFROMFILEPATHS Load explicit signal files and prepare DSP input.
|
||||
|
||||
arguments
|
||||
run_id
|
||||
options struct
|
||||
end
|
||||
|
||||
Tx_bits = load(textScalar(options.load_file_path.tx_bits_path));
|
||||
Symbols = load(textScalar(options.load_file_path.tx_symbols_path));
|
||||
Scpe_sig_raw = load(textScalar(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);
|
||||
|
||||
if found_sync
|
||||
Scpe_cell = selectSyncedOccurrences(Scpe_cell, options);
|
||||
else
|
||||
warning('Could not synchronize the received signal with the stored symbols!');
|
||||
end
|
||||
|
||||
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 value = textScalar(value)
|
||||
value = firstValue(value);
|
||||
value = char(string(value));
|
||||
end
|
||||
|
||||
function value = firstValue(value)
|
||||
if iscell(value)
|
||||
value = value{1};
|
||||
elseif ~ischar(value) && ~isscalar(value)
|
||||
value = value(1);
|
||||
end
|
||||
end
|
||||
|
||||
function Scpe_cell = selectSyncedOccurrences(Scpe_cell, options)
|
||||
available_occurences = length(Scpe_cell);
|
||||
start_occurence = floor(getOption(options, 'start_occurence', 1));
|
||||
max_occurences = floor(getOption(options, 'max_occurences', available_occurences));
|
||||
|
||||
if available_occurences < 1
|
||||
warning('loadDspInputFromFilePaths:NoSyncedOccurrences', ...
|
||||
'Synchronization reported success, but no synced occurrences are available.');
|
||||
return
|
||||
end
|
||||
|
||||
if start_occurence < 1
|
||||
error('loadDspInputFromFilePaths:InvalidStartOccurrence', ...
|
||||
'start_occurence must be >= 1.');
|
||||
end
|
||||
|
||||
if max_occurences < 1
|
||||
Scpe_cell = Scpe_cell(1:0);
|
||||
return
|
||||
end
|
||||
|
||||
if start_occurence > available_occurences
|
||||
warning('loadDspInputFromFilePaths:StartOccurrenceTooHigh', ...
|
||||
['Requested start_occurence %d, but only %d synced occurrences are available. ', ...
|
||||
'Processing the last occurrence only.'], ...
|
||||
start_occurence, available_occurences);
|
||||
Scpe_cell = Scpe_cell(available_occurences);
|
||||
return
|
||||
end
|
||||
|
||||
stop_occurence = min(available_occurences, start_occurence + max_occurences - 1);
|
||||
Scpe_cell = Scpe_cell(start_occurence:stop_occurence);
|
||||
end
|
||||
|
||||
function value = getOption(options, name, defaultValue)
|
||||
if isfield(options, name)
|
||||
value = options.(name);
|
||||
else
|
||||
value = defaultValue;
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user