From c529495b47be33426d384368ed2cfd2d2b65723c Mon Sep 17 00:00:00 2001
From: Lewin Probst <info@emirror.de>
Date: Sun, 24 Nov 2019 12:56:17 +0100
Subject: [PATCH] Added function to calculate TOA data with a drift applied.

---
 lib/+artoa/+soundsources/calculateDrift.m     | 23 +++++++++++++++++++
 .../+soundsources/calculateToaAtTimestep.m    | 16 +++++++++++++
 2 files changed, 39 insertions(+)
 create mode 100644 lib/+artoa/+soundsources/calculateDrift.m
 create mode 100644 lib/+artoa/+soundsources/calculateToaAtTimestep.m

diff --git a/lib/+artoa/+soundsources/calculateDrift.m b/lib/+artoa/+soundsources/calculateDrift.m
new file mode 100644
index 0000000..bf2e806
--- /dev/null
+++ b/lib/+artoa/+soundsources/calculateDrift.m
@@ -0,0 +1,23 @@
+function [drift] = calculateDrift(pStartRafosDate, pEndRafosDate, pStartOffset, pEndOffset)
+%CALCULATEDRIFT Calculates the drift corresponding to 1 day.
+%   Calculates the drift of a soundsource in 1 day in seconds.
+%
+%   Parameters:
+%       pStartRafosDate (double):       The start rafos date that should be
+%                                       taken into account.
+%       pEndRafosDate (double):         The end rafos date.
+%       pStartOffset (double):          The starting offset [s].
+%       pEndOffset (double):            The end offset [s].
+%
+%   Returns:
+%       drift (double):     The calculated drift [s/day].
+
+%% Calculate drift
+duration = pEndRafosDate - pStartRafosDate;
+totalOffset = pEndOffset - pStartOffset;
+
+drift = totalOffset / duration;
+
+
+end
+
diff --git a/lib/+artoa/+soundsources/calculateToaAtTimestep.m b/lib/+artoa/+soundsources/calculateToaAtTimestep.m
new file mode 100644
index 0000000..ad87af4
--- /dev/null
+++ b/lib/+artoa/+soundsources/calculateToaAtTimestep.m
@@ -0,0 +1,16 @@
+function [toa] = calculateToaAtTimestep(pToa, pTimestep, pStartOffset, pDrift)
+%CALCULATETOAATTIMESTEP Calculates the TOA at the given timestep.
+%   Calculates the new TOA at the given timestep.
+%
+%   Parameters:
+%       pToa (double):          The start TOA.
+%       pTimestep (double):     The timestep from start of the soundsource
+%                               in rafos days.
+%       pStartOffset (double):  The start offset of the soundsource.
+%       pDrift (double):        The drift of the soundsource in seconds per day.
+
+%% Calculate new toa
+toa = pToa + pStartOffset + pDrift * pTimestep;
+
+end
+
-- 
GitLab