Skip to content
Snippets Groups Projects
Commit 1dee4880 authored by leprob001's avatar leprob001
Browse files

Added selection and calculation for drift and offsets in offset window.

parent 23e3eacc
No related branches found
No related tags found
No related merge requests found
function [] = selectOffsetsAndDrift()
%SELECTOFFSETSANDDRIFT Summary of this function goes here
% Detailed explanation goes here
global artoaWorkspace;
%% Initialize required variables
selectedOffsets = table();
%% Get required variables
offsetsTable = artoaWorkspace.editOffsets.soundsourceOffsets;
%% Select float offset and drift;
selectedOffsets('Float', :) = selectFromRow(offsetsTable('Float', :));
%% Run through all soundsources
variableNames = offsetsTable.Properties.RowNames;
for i = 1:length(variableNames)
if strcmp('Float', variableNames{i})
continue;
end
selectedOffsets(variableNames{i}, :) = selectFromRow(offsetsTable(variableNames{i}, :));
end
%% Store selected values
artoaWorkspace.editOffsets.selectedOffsets = selectedOffsets;
function [selected] = selectFromRow(pTableRow)
% offset
offset = 0;
if ~isnan(pTableRow.EmpiricalOffset)
offset = pTableRow.EmpiricalOffset;
elseif ~isnan(pTableRow.OffsetStart)
offset = pTableRow.OffsetStart;
elseif ~isnan(pTableRow.OptimumTotalOffset)
offset = pTableRow.OptimumTotalOffset;
end
% drift
drift = 0;
if ~isnan(pTableRow.EmpiricalDrift)
drift = pTableRow.EmpiricalDrift;
elseif ~isnan(pTableRow.Drift)
drift = pTableRow.Drift;
elseif ~isnan(pTableRow.OptimumTotalDrift)
drift = pTableRow.OptimumTotalDrift;
end
selected = table();
selected.offset = offset;
selected.drift = drift;
end
end
...@@ -14,10 +14,15 @@ artoaWorkspace.editOffsets.soundsourceOffsets(:, :) = artoaGui.editOffsets.table ...@@ -14,10 +14,15 @@ artoaWorkspace.editOffsets.soundsourceOffsets(:, :) = artoaGui.editOffsets.table
toaData = artoaWorkspace.toaData; toaData = artoaWorkspace.toaData;
toaData.toa = artoaDataInput.toaData.toa; toaData.toa = artoaDataInput.toaData.toa;
%% Select offset and drift from the table
artoa.controller.edit.offsets.selectOffsetsAndDrift();
artoaWorkspace.toaData = artoa.toa.recalculate( ... artoaWorkspace.toaData = artoa.toa.recalculate( ...
artoaWorkspace.float, ...
toaData, ... toaData, ...
artoa.controller.getSoundsourcesWithAppliedToa(), ... artoa.controller.getSoundsourcesWithAppliedToa(), ...
artoaWorkspace.editOffsets.soundsourceOffsets ... artoaWorkspace.editOffsets.selectedOffsets ...
); );
artoa.controller.edit.timeOfArrival.plot(); artoa.controller.edit.timeOfArrival.plot();
......
...@@ -26,9 +26,13 @@ end ...@@ -26,9 +26,13 @@ end
artoaGui.figures.editOffsets = figure( ... artoaGui.figures.editOffsets = figure( ...
'Name', windowTitle, ... 'Name', windowTitle, ...
'NumberTitle', 'off', ... 'NumberTitle', 'off', ...
'MenuBar','none' ... 'MenuBar','none', ...
'Units', 'characters' ...
); );
% adjust width
artoaGui.figures.editOffsets.Position(3) = 120;
artoaGui.editOffsets = struct(); artoaGui.editOffsets = struct();
set( ... set( ...
......
function [adjustedToa] = addDrift(pToa, pOffsetBegin, pDrift, pStartTimestep)
%ADDFLOATDRIFT Summary of this function goes here
% Detailed explanation goes here
%% Prepare return variable
adjustedToa = pToa;
%% Parameter check
if isnan(pOffsetBegin)
pOffsetBegin = 0;
end
if isnan(pDrift)
pDrift = 0;
end
if pOffsetBegin == 0 && pDrift == 0
return;
end
if nargin < 4
pStartTimestep = 0;
end
if length(pStartTimestep) > 1
adjustedToa = artoa.toa.atGivenTimesteps(pToa, pStartTimestep, pOffsetBegin, pDrift);
return;
end
%
% %% Get required data
% maxToaDate = max(pToaData.toaDate);
% minToaDate = min(pToaData.toaDate);
%% Calculate offset for every toa
adjustedToa = artoa.toa.atTimestep(pToa, pStartTimestep, pOffsetBegin, pDrift);
return;
offset = [];
for i = 1:length(adjustedToa)
offset = [ ...
offset; ...
artoa.toa.atTimestep( ...
adjustedToa.toa(i), ...
pStartTimestep + i, ...
pOffsetBegin, ...
pDrift ...
) ...
];
end
% offset = ((pOffsetEnd - pOffsetBegin) / (maxToaDate - minToaDate)) ...
% * (pToaData.toaDate - minToaDate) + pOffsetBegin;
%% Add calculated offset to toa data
adjustedToa.toa = pToa.toa + offset;
end
function [toa] = atGivenTimesteps(pToa, pTimesteps, pStartOffset, pDrift)
%CALCULATETOAATTIMESTEP Calculates the TOA at the given timestep.
% Calculates the new TOA at the given timestep.
%
% Parameters:
% pToa (double): The start TOA.
% pStartTimestep (double): The starting timestep.
% pStartOffset (double): The start offset of the soundsource.
% pDrift (double): The drift of the soundsource in seconds per day.
%% Prepare variables
offsetAtTimesteps = pDrift * pTimesteps;
%% Calculate new toa
toa = pToa + pStartOffset + offsetAtTimesteps;
end
function [toa] = atTimestep(pToa, pTimestep, pStartOffset, pDrift) function [toa] = atTimestep(pToa, pStartTimestep, pStartOffset, pDrift)
%CALCULATETOAATTIMESTEP Calculates the TOA at the given timestep. %CALCULATETOAATTIMESTEP Calculates the TOA at the given timestep.
% Calculates the new TOA at the given timestep. % Calculates the new TOA at the given timestep.
% %
% Parameters: % Parameters:
% pToa (double): The start TOA. % pToa (double): The start TOA.
% pTimestep (double): The timestep from start of the soundsource % pStartTimestep (double): The starting timestep.
% in rafos days. % pStartOffset (double): The start offset of the soundsource.
% pStartOffset (double): The start offset of the soundsource. % pDrift (double): The drift of the soundsource in seconds per day.
% pDrift (double): The drift of the soundsource in seconds per day.
%% Prepare variables
timesteps = [1:length(pToa)] + pStartTimestep;
if iscolumn(pToa)
timesteps = timesteps';
end
offsetAtTimesteps = pDrift * timesteps;
%% Calculate new toa %% Calculate new toa
toa = pToa + pStartOffset + pDrift * pTimestep; toa = pToa + pStartOffset + offsetAtTimesteps;
end end
function [toaData] = recalculate(pToaData, pAppliedSoundsources, pOffsetsTable) function [toaData] = recalculate(pFloat, pToaData, pAppliedSoundsources, pOffsetsTable)
%RECALCULATETOADATA Summary of this function goes here %RECALCULATETOADATA Summary of this function goes here
% Detailed explanation goes here % Detailed explanation goes here
...@@ -6,32 +6,63 @@ function [toaData] = recalculate(pToaData, pAppliedSoundsources, pOffsetsTable) ...@@ -6,32 +6,63 @@ function [toaData] = recalculate(pToaData, pAppliedSoundsources, pOffsetsTable)
toaData = pToaData; toaData = pToaData;
%% Add float offset %% Add float offset
toaData = artoa.toa.addDriftByStartEndOffset( ... floatLaunchRafosTime = artoa.convert.dmy2rd( ...
toaData, ... pFloat.launchtime(3), ...
pOffsetsTable{'Float', 'DateStart'}, ... pFloat.launchtime(2), ...
pOffsetsTable{'Float', 'DateEnd'} ... pFloat.launchtime(1) ...
) ...
+ artoa.convert.hms2rd( ...
pFloat.launchtime(4), ...
pFloat.launchtime(5), ...
0 ...
); );
%% Add drift for every phase
stepSize = length(toaData.toa) / pFloat.toaperphase;
for i = 1:stepSize:length(toaData.toa)
startIndex = i;
endIndex = i + stepSize - 1;
toaData.toa(startIndex:endIndex) = artoa.toa.addDrift( ...
toaData.toa(startIndex:endIndex), ...
pOffsetsTable{'Float', 'offset'}, ...
pOffsetsTable{'Float', 'drift'}, ...
floor(min(toaData.toaDate) - floatLaunchRafosTime) ...
);
end
%% Calculate soundsources %% Calculate soundsources
fnames = fieldnames(pAppliedSoundsources); fnames = fieldnames(pAppliedSoundsources);
for i = 1:length(fnames) for i = 1:length(fnames)
% get rafos start date
rafosBeginEmission = artoa.convert.dmy2rd( ...
pAppliedSoundsources.(fnames{i}).begemis(3), ...
pAppliedSoundsources.(fnames{i}).begemis(2), ...
pAppliedSoundsources.(fnames{i}).begemis(1) ...
) ...
+ artoa.convert.hms2rd( ...
pAppliedSoundsources.(fnames{i}).begemis(4), ...
pAppliedSoundsources.(fnames{i}).begemis(5), ...
0 ...
);
toaLogical = strcmp(fnames{i}, toaData.soundSource); toaLogical = strcmp(fnames{i}, toaData.soundSource);
toaDate = toaData.toaDate(toaLogical); toaDate = toaData.toaDate(toaLogical);
toa = toaData.toa(toaLogical); toa = toaData.toa(toaLogical);
[toaDate, sortedDates] = sort(toaDate);
toa = toa(sortedDates);
% calculate drift of soundsource % calculate drift of soundsource
drift = artoa.drift.byStartEndOffset( ... toa = artoa.toa.addDrift( ...
max(toaDate) - min(toaDate), ... toa, ...
pOffsetsTable{fnames{i}, 'Begin'}, ... pOffsetsTable{fnames{i}, 'offset'}, ...
pOffsetsTable{fnames{i}, 'End'} ... pOffsetsTable{fnames{i}, 'drift'}, ...
floor(toaDate - rafosBeginEmission) ...
); );
for o = 1:length(toa)
toa(o) = artoa.toa.atTimestep( ... % undo sorting
toa(o), ... toa(sortedDates) = toa;
toaDate(o) - min(toaDate), ...
pOffsetsTable{fnames{i}, 'Begin'}, ...
drift ...
);
end
toaData.toa(toaLogical) = toa; toaData.toa(toaLogical) = toa;
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment