ita_loudness_compare_rir.m 3.34 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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
function varargout = ita_loudness_compare_rir(varargin)
%ITA_LOUDNESS_COMPARE_RIR - compares two RIRs' timevariant loudness
%  This function compares two Room Impulse Responses' timevariant loudness
%
%  Syntax:
%   audioObjOut = ita_loudness_compare_rir(audioObjIn1,audioObjIn2,options)
%
%   Options (default):
%           'blocksize' (defaultopt1)   : description
%           'overlap' (defaultopt1)     : description
%
%  Example:
%   audioObjOut = ita_loudness_compare_rir(audioObjIn)
%
%  See also:
%   ita_toolbox_gui, ita_read, ita_write, ita_generate
%
%   Reference page in Help browser 
%        <a href="matlab:doc ita_loudness_compare_rir">doc ita_loudness_compare_rir</a>

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


% Author: Martin Guski -- Email: mgu@akustik.rwth-aachen.de
% Created:  09-Dec-2010 


% TODO:
% input direkt spezifische Lautheit


%% Get Function String
thisFuncStr  = [upper(mfilename) ':'];     %Use to show warnings or infos in this functions

%% Initialization and Input Parsing
% all fixed inputs get fieldnames with posX_* and dataTyp
% optonal inputs get a default value ('comment','test', 'opt1', true)
% please see the documentation for more details
sArgs        = struct('pos1_data','itaAudio', 'pos2_data','itaAudio', 'blocksize', 0.1, 'overlap', 0);
[ia1, ia2,sArgs] = ita_parse_arguments(sArgs,varargin); %#ok<NASGU>

%% +++Body - Your Code here+++ 'input' is an audioObj and is given back 

[LoudnessVsTime1 LoudnessVsTimeVsFreq1]        = ita_loudness_timevariant(ia1, 'blocksize', sArgs.blocksize, 'overlap', sArgs.overlap);
[LoudnessVsTime2 LoudnessVsTimeVsFreq2]        = ita_loudness_timevariant(ia2, 'blocksize', sArgs.blocksize, 'overlap', sArgs.overlap);



% da es noch kein 2D itaResult gibt ...
% anaBlockSize    = round(sArgs.blocksize/1000 * ia1.samplingRate);
% nOverlap        = round(sArgs.overlap * anaBlockSize);
% analysisDeltaT  = (anaBlockSize-nOverlap) / ia1.samplingRate ;
% timeVec = (0:size(LoudnessVsTimeVsFreq1,2)-1 )* analysisDeltaT;





ratio.data  = abs(LoudnessVsTimeVsFreq2.data ./ LoudnessVsTimeVsFreq1.data);

% idx2Invert= ratio >=1;  % alle werte zwischen 0 und 1
idx2Invert= ratio.data <=1;    % alle werte > 1
ratio.data(idx2Invert) = 1./ratio.data(idx2Invert);

idxNan = isnan(ratio.data);
ratio.data(idxNan) = 1; % TODO: sinnvoll? besser 0??


ratio.timeVector = LoudnessVsTimeVsFreq1.timeVector;
ratio.freqVector = LoudnessVsTimeVsFreq1.freqVector;










% sample use of the ita warning/ informing function
% ita_verbose_info([thisFuncStr 'Testwarning'],0);







%% Add history line
% input = ita_metainfo_add_historyline(input,mfilename,varargin);

%% Set Output
if nargout == 0
    figure
    
    % nicht zu viel plotten, da sonst java nicht hinterher kommt
    timePlotLimits = [0 0.2]; % in sekunden
       
    barkVec = .1:.1:24;
    timePlotIdx = round(timePlotLimits/analysisDeltaT)+1;
    
    
    contourf(ratio.timeVector(timePlotIdx(1):timePlotIdx(2)) ,ratio.freqVector,  ratio.data(:,timePlotIdx(1):timePlotIdx(2)));
    
    
    shading flat;  xlabel('time [s]'); ylabel('[Bark]')
    colorbar
    caxis([1 50])
    title(strrep([ia1.comment ' vs. ' ia2.comment ], '_', ' '))
    
else
    
    
    varargout(1) = {ratio};
end
%end function
end