localizer_preproc.m 2.21 KB
Newer Older
1 2
% revision 1.00.1 beta, 07/01/04

3
function DOA = localizer_preproc(in)
4 5 6 7 8 9
% in contains one of the 3 intervals presented in the experiment

global def
global work
global simwork

10 11 12
sig=in';
fs=def.samplerate;

13
DOAazimuth = simwork.LocModel.az;
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
time = 0:1./simwork.LocModel.fs.*simwork.LocModel.wndlen./2: size(sig,2)./simwork.LocModel.fs -1./simwork.LocModel.fs.*simwork.LocModel.wndlen;

% STFT from Multi-Channel BSS Locate toolbox R. Lebarbenchon and E. Camberlein)
% http://bass-db.gforge.inria.fr/bss_locate/

% Resample to model fs 
if fs ~= simwork.LocModel.fs
    sig = resample(sig.',simwork.LocModel.fs,fs).';
end
X = MBSS_stft_multi(sig,simwork.LocModel.wndlen);

% Feature extraction
mFeature = [];
for IDXpair = 1:size(simwork.LocModel.vPairs,2)
    
    G_length = simwork.LocModel.wndlen./2+1;
    ifftwin = hanning_(2.*G_length);
    ifftwin = ifftwin(G_length+1:end);
    
    G = squeeze(conj(X(:,:,simwork.LocModel.vPairs(1,IDXpair))) .* X(:,:,simwork.LocModel.vPairs(2,IDXpair)));
    % PHAT weighting
    G = G./max(abs(G),eps);
    
    % Apply ifft window
    G = G .* ifftwin(:,ones(1,size(G,2))) .*simwork.LocModel.nUpsample;
    
    % zero-padding according to upsampling factor
    G = [G;zeros(floor((simwork.LocModel.nUpsample-1).*simwork.LocModel.wndlen./2),size(G,2))];
    
    % reconstruct mirror frequencies, assumes even wndlen
    G = [G;  conj(G(end-1:-1:2,:))];
    
    % ifft and swap halves of csd to compensate for fftshift
    vGCC = ifftshift(ifft(G,[], 1,'symmetric'),1);
    
    % Use only relevant part of GCC-PHAT function
    vDelaybins = size(vGCC,1)./2-simwork.LocModel.maxLag(IDXpair)+1:size(vGCC,1)./2+simwork.LocModel.maxLag(IDXpair)+1;
    mFeature = [mFeature; vGCC(vDelaybins,:)];
end

% Compute DOA probability map
for IDXt = 1 : size(mFeature,2)
    %     Apply linear SVM model (one for each direction) to feature vector
    c = (simwork.LocModel.w * mFeature(:,IDXt)) + simwork.LocModel.b.';
    
    %     map to probability using a sigmoid transformation
    probability(:,IDXt) = 1 ./ (1 + exp(-(simwork.LocModel.x.' + c .* simwork.LocModel.y.')));
61 62 63 64 65 66 67 68 69 70 71
end 



[val indxdoa]=max(probability,[],1);
DOA=mode(DOAazimuth(indxdoa));