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 tomwalters@0: tomwalters@0: % calculate the binned version of the signal tomwalters@0: function retsig=bin(sig,binwidth) tomwalters@0: tomwalters@0: tomwalters@0: new_sr=1/binwidth; % the sr of the binned signal tomwalters@0: old_sr=getsr(sig); tomwalters@0: tomwalters@0: cvals=getvalues(sig); tomwalters@0: nrbinspro=old_sr/new_sr; tomwalters@0: nr_bins=round(getlength(sig)/binwidth); tomwalters@0: new_val=zeros(nr_bins,1); tomwalters@0: tomwalters@0: for k=1:nr_bins tomwalters@0: start_bin=round((k-1)*nrbinspro+1); tomwalters@0: stop_bin=round(k*nrbinspro); tomwalters@0: stop_bin=min(stop_bin,length(cvals)); tomwalters@0: new_val(k)=sum(cvals(start_bin:stop_bin)); tomwalters@0: end tomwalters@0: retsig=signal(new_val); tomwalters@0: retsig=setsr(retsig,new_sr); tomwalters@0: retsig=setname(retsig,sprintf('binned signal %s with binwidth %3.2fms',getname(sig),binwidth*1000)); tomwalters@0: tomwalters@0: