filterCTC.m 2.83 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
function result = filterCTC(binauralInput,CTCfilter,domain)
%filterCTC - Filter binaural signal with CTC filter network
%  This function receives a binaural singal as a two channel itaAudio
%  object and a CTC filter as a four channel itaAudio object (possibly
%  generated with the function generateCTC). It is possible to choose in
%  which domain calculation will be done, being time domain the standard.
%
%  The output is another binaural signal, saved as a two channel itaAudio
%  object.
%
%  Call: result = filterCTC(binauralInput,CTCfilter)
%
% Author: Bruno Masiero -- Email: bma@akustik.rwth-aachen.de
% Created:  29-Sep-2009 
%$ENDHELP$
%% Get ITA Toolbox preferences

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

verboseMode  = ita_preferences('verboseMode');  %#ok<NASGU>
thisFuncStr  = [upper(mfilename) ':'];     %#ok<NASGU>

%% Initialization
if nargin < 2
    error('CTC:InputArguments','This function requires two input arguments.')
end

if ~isa(binauralInput,'itaAudio') || ~isa(CTCfilter,'itaAudio')
    error('CTC:InputArguments','The input variable must be itaAudio objects.')
end

if nargin < 3
    domain = 'time';
end

% Frequency vectors for the binaural input
if binauralInput.nChannels ~= 2
    error('CTC:InputArguments','The binaural signal must contain two channels.')
else
    inL = binauralInput.ch(1);
    inR = binauralInput.ch(2);
end

% Frequency vectors for the CTC filters.
% e.g.: CTC_LR -> transfer function for the filter from the left signal to
% the right loudspeaker.
if size(CTCfilter,2) ~= 2
    error('CTC:InputArguments','The CTC filter must contain two rows.')
end

%% CTC filtering

[ca,cb] = size(CTCfilter);
  

if CTCfilter(1,1).nBins == 1
    for idx = 1:ca
        for jdx = 1:cb
            ctc(idx,jdx) = CTCfilter(idx,jdx).freq;
        end
    end
    CTC = ctc;
end

result = binauralInput;

if strcmp(domain,'time')
    for adx = 1:ca
        aux = 0;
        for bdx = 1:cb
            aux = aux + ita_convolve(CTCfilter(adx,bdx),binauralInput.ch(bdx));
        end
        result(adx) = aux;
    end
else
    % Do calculation in freq domain. First signals must be extended to be
    % the same size.
    for adx = 1:ca
        for bdx = 1:cb
            if CTCfilter(adx,bdx).nSamples < binauralInput.nSamples;
                CTCfilter(adx,bdx) = ita_extend_dat(CTCfilter(adx,bdx),binauralInput.nSamples,'forcesamples');
            end
        end
    end
        
    for adx = 1:ca
        aux = 0;
        for bdx = 1:cb
            aux = aux + CTCfilter(adx,bdx)*binauralInput.ch(bdx);
        end
        result(adx) = aux;
    end
end

result = merge(result);

%% Output
result = ita_metainfo_add_historyline(result,'filterCTC','ARGUMENTS');
result = result.';
end
%EOF generateCTC