Mercurial > hg > aimmat
annotate aim-mat/tools/@signal/bin.m @ 4:537f939baef0 tip
various bug fixes and changed copyright message
author | Stefan Bleeck <bleeck@gmail.com> |
---|---|
date | Tue, 16 Aug 2011 14:37:17 +0100 |
parents | 20ada0af3d7d |
children |
rev | line source |
---|---|
bleeck@3 | 1 % This external file is included as part of the 'aim-mat' distribution package |
bleeck@3 | 2 % (c) 2011, University of Southampton |
bleeck@3 | 3 % Maintained by Stefan Bleeck (bleeck@gmail.com) |
bleeck@3 | 4 % download of current version is on the soundsoftware site: |
bleeck@3 | 5 % http://code.soundsoftware.ac.uk/projects/aimmat |
bleeck@3 | 6 % documentation and everything is on http://www.acousticscale.org |
tomwalters@0 | 7 |
tomwalters@0 | 8 % calculate the binned version of the signal |
tomwalters@0 | 9 function retsig=bin(sig,binwidth) |
tomwalters@0 | 10 |
tomwalters@0 | 11 |
tomwalters@0 | 12 new_sr=1/binwidth; % the sr of the binned signal |
tomwalters@0 | 13 old_sr=getsr(sig); |
tomwalters@0 | 14 |
tomwalters@0 | 15 cvals=getvalues(sig); |
tomwalters@0 | 16 nrbinspro=old_sr/new_sr; |
tomwalters@0 | 17 nr_bins=round(getlength(sig)/binwidth); |
tomwalters@0 | 18 new_val=zeros(nr_bins,1); |
tomwalters@0 | 19 |
tomwalters@0 | 20 for k=1:nr_bins |
tomwalters@0 | 21 start_bin=round((k-1)*nrbinspro+1); |
tomwalters@0 | 22 stop_bin=round(k*nrbinspro); |
tomwalters@0 | 23 stop_bin=min(stop_bin,length(cvals)); |
tomwalters@0 | 24 new_val(k)=sum(cvals(start_bin:stop_bin)); |
tomwalters@0 | 25 end |
tomwalters@0 | 26 retsig=signal(new_val); |
tomwalters@0 | 27 retsig=setsr(retsig,new_sr); |
tomwalters@0 | 28 retsig=setname(retsig,sprintf('binned signal %s with binwidth %3.2fms',getname(sig),binwidth*1000)); |
tomwalters@0 | 29 |
tomwalters@0 | 30 |