ita_sph_sampling_displacement.m 2.27 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
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
%  positions taken from a given sampling grid
%  
%   Syntax:
%   audioObjOut = ita_sph_sampling_displacement(audioObjIn, options)
%
%   Options (default):
%           'opt1' (defaultopt1) : description
%           'opt2' (defaultopt1) : description
%           'opt3' (defaultopt1) : description
%
%  Example:
%   audioObjOut = ita_sph_sampling_displacement(audioObjIn)
%
%  See also:
%   ita_toolbox_gui, ita_read, ita_write, ita_generate
%
%   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>


% Author: Marco Berzborn -- Email: marco.berzborn@rwth-aachen.de
% Created:  29-Mar-2016 


%% Initialization and Input Parsing

sArgs = struct('pos1_sampling','itaCoordinates',...
               'relativeError',[0.01 0.01 0.01]);
[sampling, sArgs] = ita_parse_arguments(sArgs,varargin);

if isempty(sArgs.relativeError)
    sArgs.relativeError = zeros(1,3);
elseif numel(sArgs.relativeError) == 1
    sArgs.relativeError = repmat(sArgs.relativeError,1,3);
end

posError = randn(size(sampling.sph));
posError = (bsxfun(@rdivide,posError,sqrt(sum(posError.^2,2))) .* repmat(sampling.sph(:,1),1,3)) * diag(sArgs.relativeError);

posError = itaCoordinates(posError,'cart');
posError = posError.makeSph;
% 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);

posError = posError.makeCart;

% 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;

% new sampling coordinates with erroneous positions
samplingError = itaCoordinates(sampling.cart + posError.cart,'cart');

if sArgs.relativeError(:,1) == 0
    samplingError.sph(:,1) = sampling.sph(:,1);
end

varargout{1} = samplingError;
end