Files
imdd_silas/Functions/Job_Processing/findSignalPulseformer.m
2026-03-25 14:52:43 +01:00

87 lines
2.1 KiB
Matlab

function pulseformer = findSignalPulseformer(signalLike)
%FINDSIGNALPULSEFORMER Try to recover TX pulseformer metadata from a signal logbook.
pulseformer = [];
if isempty(signalLike) || ~isprop(signalLike, 'logbook') || isempty(signalLike.logbook)
return
end
if ~ismember('ModifierCopy', signalLike.logbook.Properties.VariableNames)
return
end
modifierCopies = signalLike.logbook.ModifierCopy;
for idx = numel(modifierCopies):-1:1
pulseformer = extractPulseformerCandidate(modifierCopies{idx});
if ~isempty(pulseformer)
return
end
end
end
function pulseformer = extractPulseformerCandidate(candidate)
pulseformer = [];
if isempty(candidate)
return
end
if isa(candidate, 'Pulseformer')
pulseformer = candidate;
return
end
if iscell(candidate)
for cellIdx = 1:numel(candidate)
pulseformer = extractPulseformerCandidate(candidate{cellIdx});
if ~isempty(pulseformer)
return
end
end
return
end
if isstruct(candidate)
if isfield(candidate, 'pulseformer')
pulseformer = extractPulseformerCandidate(candidate.pulseformer);
if ~isempty(pulseformer)
return
end
end
if hasPulseformerFields(candidate)
pulseformer = candidate;
end
return
end
try
if isprop(candidate, 'pulseformer')
pulseformer = extractPulseformerCandidate(candidate.pulseformer);
if ~isempty(pulseformer)
return
end
end
catch
end
try
if hasPulseformerFields(candidate)
pulseformer = candidate;
end
catch
end
end
function tf = hasPulseformerFields(candidate)
tf = false;
if isstruct(candidate)
tf = isfield(candidate, 'pulse') && isfield(candidate, 'pulselength');
return
end
tf = isobject(candidate) && isprop(candidate, 'pulse') && isprop(candidate, 'pulselength');
end