%ITA_3DA_CTCFILTER_REGULARIZED Generates a set of CTC Filter for a
%loudspeaker system with an arbitrary number of loudspeaker.
% The first input has to be a set of HRTF for each loudspeaker as
% multi-instance of itaAudio: [LS1_HRTF LS2_HRTF ... LSN_HRTF]
% or as one itaAudio containing:
% ch(1) = LS1 Left Ear
% ch(2) = LS1 Right Ear
% ch(3) = LS2 Left Ear
% ch(4) = LS2 Right Ear
% ch(5) = LS3 Left Ear
% ...
%
% The calculation algorithm is a simple inversion. Pre- and
% Postprocessing options can be found below
%
% For smoothing of HRTF or CTC filters use the functions provided by
% ita_3da_smoothing
%% Options
% Calculation
opts.beta=0.001;% regularization parameter
opts.thresholdStartIR=-1;% threshold for ita_start_IR() to cut out the start delay, -1 will disable the feature
opts.filterLength=-1;% resulting filter lengt if set to -1: maximum of 4096 and nSamples*2
opts.winLim=[.785];% limits for windowing (suppress artifacts at the end of HRIR caused by time shifting)
opts.postProcessing=true;% Indicates if a time shift and windowing operation is performed on the calculated filter. WARNING: May lead to non-causal filters (echo effect)
%% Init
hrtf=varargin{1};
H=ita_merge(hrtf(:));
if~isa(hrtf,'itaAudio')
error('First input (HRTF) has to be itaAudio')
end
if(H.nChannels<4)
error('At least two loudspeaker with two channels to each ear are needed!');
end
if~strcmpi(H.signalType,'energy')
warning('HRTFs are not energy signals! Changing them to energy');