tomwalters@0: % method of class @signal tomwalters@0: % tomwalters@0: % INPUT VALUES: tomwalters@0: % tomwalters@0: % RETURN VALUE: tomwalters@0: % tomwalters@0: % bleeck@3: % This external file is included as part of the 'aim-mat' distribution package bleeck@3: % (c) 2011, University of Southampton bleeck@3: % Maintained by Stefan Bleeck (bleeck@gmail.com) bleeck@3: % download of current version is on the soundsoftware site: bleeck@3: % http://code.soundsoftware.ac.uk/projects/aimmat bleeck@3: % documentation and everything is on http://www.acousticscale.org bleeck@3: tomwalters@0: tomwalters@0: function sources=getsourceestimate(sig,sigma) tomwalters@0: % usage: sources=getsourceestimate(sig,sigma)) tomwalters@0: % returns a struct of sources.position and sources.height tomwalters@0: % for each maximum in the signal sig. tomwalters@0: % it is assumed, that each maximum contributes to the signal with tomwalters@0: % a gaussian kernel of the width "sigma" tomwalters@0: tomwalters@0: tomwalters@0: grafix=0; % debug tomwalters@0: tomwalters@0: % nrchannels=getnrchannels(cframe); tomwalters@0: % smoothwidth=nrchannels/64; tomwalters@0: % fresumme=smooth(fresumme,smoothwidth); tomwalters@0: tomwalters@0: finished=0; % it can be finished by: tomwalters@0: % a) after 5 Maxima tomwalters@0: % b) the signal is below 30 % of original tomwalters@0: how_many_max_maximal=5; tomwalters@0: threshold_criterion=0.3; tomwalters@0: tomwalters@0: if nargin < 2 tomwalters@0: % wie breit jedes Maximum angenommen wird tomwalters@0: sigma=3; % this is in the sr of the singal tomwalters@0: end tomwalters@0: tomwalters@0: current_max=1; tomwalters@0: start_max_hight=max(sig); % so hoch im Moment tomwalters@0: tomwalters@0: if grafix tomwalters@0: plot(sig); tomwalters@0: hold on; tomwalters@0: a=axis; tomwalters@0: a(3)=-start_max_hight*1.1; tomwalters@0: a(4)=start_max_hight*1.1; tomwalters@0: axis(a); tomwalters@0: end tomwalters@0: tomwalters@0: cols=['b';'g';'k';'y';'b';'g';'k']; % verschiedene Farben für die unterschiedlichen Dominanzregionen tomwalters@0: while ~finished tomwalters@0: [maxpos,minpos,maxs,mins]=getminmax(sig); tomwalters@0: [maxmaxhight,maxmaxpos]=max(sig); tomwalters@0: tomwalters@0: gauss=signal(sig); tomwalters@0: gauss=generategauss(gauss,maxmaxpos,maxmaxhight,sigma); tomwalters@0: sig=sig-gauss; tomwalters@0: tomwalters@0: sources{current_max}.position=maxmaxpos; tomwalters@0: sources{current_max}.height=maxmaxhight; tomwalters@0: sources{current_max}.sigma=sigma; tomwalters@0: tomwalters@0: tomwalters@0: if grafix tomwalters@0: cur_col=cols(mod(current_max,7)+1,:); tomwalters@0: plot(sig,cur_col); tomwalters@0: axis(a); tomwalters@0: plot(maxmaxpos,maxmaxhight,'r.','MarkerSize',20); tomwalters@0: end tomwalters@0: current_max_hight=max(sig); % so hoch im Moment tomwalters@0: if current_max_hight <= start_max_hight*threshold_criterion tomwalters@0: finished=1; tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: current_max=current_max+1; tomwalters@0: if current_max>how_many_max_maximal tomwalters@0: finished=1; tomwalters@0: end tomwalters@0: tomwalters@0: end tomwalters@0: if grafix tomwalters@0: plot(sig,'r'); tomwalters@0: axis(a); tomwalters@0: end tomwalters@0: tomwalters@0: return tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: