%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Diese Funktion bestimmt die aufgrund der Korrektur mit der Leermessung % auftretende Verschiebung der HRIRs in negative Richtung und korri- % giert diese. Die Fensterlänge kann dabei beliebig gewählt werden. Der % Parameter "smooth" gibt an , ob die HRIRs geglättet werden sollen % (smooth = 1) oder nicht (smooth = 0). Das Programm orientiert sich an % dem paper von Keller, Hartung, Takahashi aus dem Jahr 1998. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [hrirshift_l, hrirshift_r, az_num, el_num] = offset(hrir_l, hrir_r, fensterzeit, smooth) % Fensterzeit in ms zwischen 0 und 500 fensterlaenge = fensterzeit * 100; L = size(hrir_l,3); zeilen = size(hrir_l,1); spalten = size(hrir_l,2); fenster = zeros(1,L); fenster(1) = 1; fenster(L-(fensterlaenge-2):L) = 1; hrirsmooth_l = zeros(zeilen,spalten,L); hrirsmooth_r = zeros(zeilen,spalten,L); offset_l = zeros(zeilen,spalten); offset_r = zeros(zeilen,spalten); for i = 1:zeilen for j = 1:spalten HRIR_l = squeeze(hrir_l(i,j,:)).'; HRIR_r = squeeze(hrir_r(i,j,:)).'; faltung_l = cconv(HRIR_l.^2, fenster,L); faltung_r = cconv(HRIR_r.^2, fenster,L); offset_l(i,j) = find(faltung_l == max(faltung_l),1); offset_r(i,j) = find(faltung_r == max(faltung_r),1); filter_l = zeros(1,L); filter_r = zeros(1,L); if offset_l(i,j)+fensterlaenge-1 <= L filter_l(1,offset_l(i,j):offset_l(i,j)+fensterlaenge-1) = 1; else filter_l(1,offset_l(i,j):L) = 1; filter_l(1,1:fensterlaenge-L+offset_l(i,j)-1) = 1; end if offset_r(i,j)+fensterlaenge-1 <= L filter_r(1,offset_r(i,j):offset_r(i,j)+fensterlaenge-1) = 1; else filter_r(1,offset_r(i,j):L) = 1; filter_r(1,1:fensterlaenge-L+offset_r(i,j)-1) = 1; end hrirsmooth_l(i,j,:) = HRIR_l .* filter_l; hrirsmooth_r(i,j,:) = HRIR_r .* filter_r; end end offset_l(offset_l < L/2) = nan; offset_r(offset_r < L/2) = nan; [off_l, I_l] = min(offset_l(:)); [off_r, I_r] = min(offset_r(:)); if off_l <= off_r offset = off_l; I = I_l; else offset = off_r; I = I_r; end if isnan(offset) == 1 az_num = 0; el_num = 0; if smooth == 0 hrirshift_l = hrir_l; hrirshift_r = hrir_r; else hrirshift_l = hrirsmooth_l; hrirshift_r = hrirsmooth_r; end else [az_num, el_num] = ind2sub(size(offset_l), I); if smooth == 0 hrirshift_l = circshift(hrir_l, [0,0,(L-offset)+1]); hrirshift_r = circshift(hrir_r, [0,0,(L-offset)+1]); else hrirshift_l = circshift(hrirsmooth_l, [0,0,(L-offset)+1]); hrirshift_r = circshift(hrirsmooth_r, [0,0,(L-offset)+1]); end end end