Commit 46edd773 authored by Philipp Schäfer's avatar Philipp Schäfer

itaHRTF - ITD calculation

-fixed a hard coded indicing. Now properly filters out f=0Hz
-Renamed a few variables for better understanding
parent 738a7bf0
...@@ -943,22 +943,31 @@ classdef itaHRTF < itaAudio ...@@ -943,22 +943,31 @@ classdef itaHRTF < itaAudio
thisC = ita_time_shift(this,tau(idxMin)-this.trackLength/3,'time'); thisC = ita_time_shift(this,tau(idxMin)-this.trackLength/3,'time');
if ischar(sArgs.filter) % frequency dependent if ischar(sArgs.filter) % frequency dependent
p1 = thisC.freqData(:,1:2:thisC.dimensions); pLeft = thisC.freqData(:,thisC.EarSide == 'L');
p2 = thisC.freqData(:,2:2:thisC.dimensions); pRight = thisC.freqData(:,thisC.EarSide == 'R');
phase1 = unwrap(angle(p1)); phaseLeft = unwrap(angle(pLeft));
phase2 = unwrap(angle(p2)); phaseRight = unwrap(angle(pRight));
phasenDiff = phase1 - phase2; phasenDiff = phaseLeft - phaseRight;
ITD = phasenDiff./(2*pi*repmat(thisC.freqVector,1,size(phase1,2))); ITD = phasenDiff./(2*pi*repmat(thisC.freqVector,1,size(phaseLeft,2)));
else % averaged else % averaged
usedBins = thisC.freq2index(sArgs.filter(1)):thisC.freq2index(sArgs.filter(2)); usedBins = ( thisC.freq2index(sArgs.filter(1)):thisC.freq2index(sArgs.filter(2)) )';
phase = unwrap(angle(thisC.freqData(3:end,:)));
freqVector = thisC.freqVector; %Remove invalid indices including the one for f=0Hz
t0_freq = bsxfun(@rdivide, phase,2*pi*freqVector(3:end)); if any( usedBins == 1 )
t0_freq = t0_freq(~isnan(t0_freq(:,1)),:); ita_verbose_info('itaHRTF: Excluding invalid bin (f=0Hz) for ITD calculation (phase_delay method)', 2)
t0_mean = mean(t0_freq(usedBins-2,:)); %mean is smoother than max; lower freq smooths also the result end
ITD = t0_mean(thisC.EarSide == 'L') - t0_mean(thisC.EarSide == 'R'); usedBins( usedBins <= 1 ) = [];
phase = unwrap(angle(thisC.freqData(usedBins,:)));
freqVector = thisC.freqVector(usedBins);
phaseDelay = bsxfun(@rdivide, phase,2*pi*freqVector);
phaseDelay = phaseDelay(~isnan(phaseDelay(:,1)),:);
phaseDelayMean = mean(phaseDelay); %mean is smoother than max; lower freq smooths also the result
ITD = phaseDelayMean(thisC.EarSide == 'L') - phaseDelayMean(thisC.EarSide == 'R');
end end
case 'xcorr' case 'xcorr'
% ..................................................... % .....................................................
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment