Aufgrund einer Wartung wird GitLab am 29.10. zwischen 9:00 und 10:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 29.10. between 9:00 and 10:00 am.

Aufgrund einer Konfigurationsänderung wird die GitLab Registry ab 10 Uhr nur Read Only zur Verfügung stehen. / Due to a configuration change, the GitLab Registry will be available for read-only access from 10am.

ita_sph_sampling_displacement.m 2.63 KB
Newer Older
1 2 3
function varargout = ita_sph_sampling_displacement(varargin)
%ITA_SPH_SAMPLING_DISPLACEMENT - displaced sampling positions
%  This function creates a sampling grid with an additive error in the sampling
4 5 6
%  positions taken from a given sampling grid. The default option for the displacement
%  is a relative displacement in percent/100. For a absolute displacement in meters
%  choose the option 'absolute'.
7 8
%  
%   Syntax:
9
%   samplingDisplaced = ita_sph_sampling_displacement(sampling, displacement, opts)
10 11
%
%   Options (default):
12 13 14 15
%			'absolute' (false)	: displacement is a absolute value
%			'weightPoles' (true): weigting for smaller errors towards the poles
%			'projectRad' (true)	: project displaced sampling back onto the original radius
%
16 17
%
%  Example:
18
%   samplingDisplaced = ita_sph_sampling_displacement(sampling, [5/10,5/10,5/10] * 1e-3, 'absolute')
19 20
%
%  See also:
21
%   ita_sph_sampling, ita_sph_mimo_error_simulation
22 23 24 25 26 27 28 29 30 31
%
%   Reference page in Help browser 
%        <a href="matlab:doc ita_sph_sampling_displacement">doc ita_sph_sampling_displacement</a>

% <ITA-Toolbox>
% This file is part of the ITA-Toolbox. Some rights reserved. 
% You can find the license for this m-file in the license.txt file in the ITA-Toolbox folder. 
% </ITA-Toolbox>


32
% Author: Marco Berzborn -- Email: marco.berzborn@akustik.rwth-aachen.de
33 34 35
% Created:  29-Mar-2016 

sArgs = struct('pos1_sampling','itaCoordinates',...
36 37 38 39 40
               'pos2_error','double',...
			   'absolute',false,...
			   'weightPoles',true,...
               'projectRad',true);
[sampling, displacement, sArgs] = ita_parse_arguments(sArgs,varargin);
41

42 43
if numel(displacement) == 1
	displacement = repmat(displacement,1,3);
44 45
end

46 47 48 49 50 51 52
if ~sArgs.absolute
	posError = randn(size(sampling.sph));
	posError = (bsxfun(@rdivide,posError,sqrt(sum(posError.^2,2))) .* repmat(sampling.sph(:,1),1,3)) * diag(displacement);
elseif sArgs.absolute
	posError = randn(size(sampling.sph));
	posError = bsxfun(@rdivide,posError,sqrt(sum(posError.^2,2))) * diag(displacement);
end
53 54

posError = itaCoordinates(posError,'cart');
55 56 57 58
if sArgs.weightPoles
	% consideration of the smaller deviations towards the poles
	% Ref: Rafaely - 2005 - Analysis and Design of Spherical Microphone Arrays
	posError.sph(:,2) = posError.sph(:,2)./sin(sampling.theta);
59 60


61 62 63 64 65
	% set all NaNs and Infs to zero as they are not wanted and lead to missing
	% sampling points.
	posError.cart(isnan(posError.cart)) = 0;
	posError.cart(isinf(posError.cart)) = 0;
end
66 67 68
% new sampling coordinates with erroneous positions
samplingError = itaCoordinates(sampling.cart + posError.cart,'cart');

69
if sArgs.projectRad
70 71 72 73
    samplingError.sph(:,1) = sampling.sph(:,1);
end

varargout{1} = samplingError;
74
end