SingleSource.m 2.17 KiB
function [positions, clockError] = SingleSource(pData, pSoundsourcePositions, pCombinationDetails)
%SINGLESOURCE Implements the single source tracking algorithm
%
% Parameters:
% pData (struct):
% Data structured by soundsource. The toa is already corrected
% (e.g. doppler correction etc.)
% pSoundsourcePositions (struct):
% The soundsource positions [deg].
% pCombinationDetails (table):
% Contains all information of the current soundsource
% combination.
%
%
% Returns:
% positions (double):
% The calculated list of segment positions as a X x 2 column vector.
% clockError (double):
% The estimated clock error.
%% Get reference position and all soundsource names that are involved
referencePosition = cellfun(@str2double, strsplit(pCombinationDetails.referencePosition{1}));
soundsourceNames = strsplit(pCombinationDetails.soundsources{1});
%% Check if only one sound source is selected
if length(soundsourceNames) ~= 1 || isempty(soundsourceNames)
error('Only one or at least one soundsource requires to be specified for SingleSource tracking!');
end
%% Get required data for single source tracking
pData.(soundsourceNames{1}).horizontalVelocity = ...
[ ...
NaN; ...
calculateHorizontalVelocity( ...
[pData.(soundsourceNames{1}).date{:}]', ...
[pData.(soundsourceNames{1}).distance{:}]' ...
) ...
];
averageHorizontalVelocity = mean( ...
pData.(soundsourceNames{1}).horizontalVelocity( ...
~isnan(pData.(soundsourceNames{1}).horizontalVelocity) ...
) ...
);
%% Return NaN because this is a sample
positions = NaN(size(pData.(soundsourceNames{1}).date, 1), 2);
clockError = [];
error('Tracking method implementation not finished yet!');
%% Helper functions
function [hvel] = calculateHorizontalVelocity(dates, distances)
% calculate the average speed in m/s
% distances are stored in km
% dates as rafos dates
diffDistances = diff(distances) / 1000; % now in [m]
diffDates = diff(dates) * 24 * 3600; % now in [s]
hvel = abs(diffDistances ./ diffDates);
end
end