Mercurial > hg > aimmat
annotate aim-mat/tools/@signal/squeeze.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 |
---|---|
tomwalters@0 | 1 % method of class @ |
tomwalters@0 | 2 % function newsig=squeeze(sig,factor) |
tomwalters@0 | 3 % INPUT VALUES: |
tomwalters@0 | 4 % sig: orginal @signal |
tomwalters@0 | 5 % factor: factor, by which the signal is squeezed |
tomwalters@0 | 6 % RETURN VALUE: |
tomwalters@0 | 7 % newsig: squeezed signal |
tomwalters@0 | 8 % |
tomwalters@0 | 9 % reduces the length of the signal by scaling it in time |
tomwalters@0 | 10 % |
bleeck@3 | 11 % This external file is included as part of the 'aim-mat' distribution package |
bleeck@3 | 12 % (c) 2011, University of Southampton |
bleeck@3 | 13 % Maintained by Stefan Bleeck (bleeck@gmail.com) |
bleeck@3 | 14 % download of current version is on the soundsoftware site: |
bleeck@3 | 15 % http://code.soundsoftware.ac.uk/projects/aimmat |
bleeck@3 | 16 % documentation and everything is on http://www.acousticscale.org |
tomwalters@0 | 17 |
tomwalters@0 | 18 function newsig=squeeze(sig,factor) |
tomwalters@0 | 19 |
tomwalters@0 | 20 |
tomwalters@0 | 21 %%%%%%%%%%%%%%% |
tomwalters@0 | 22 % if squeezed it becomes shorter |
tomwalters@0 | 23 if factor < 1 |
tomwalters@0 | 24 len=getlength(sig); |
tomwalters@0 | 25 newlen=len*factor; |
tomwalters@0 | 26 sr=sig.samplerate; |
tomwalters@0 | 27 newsr=sr; % dont change the sr |
tomwalters@0 | 28 if newlen < newsr |
tomwalters@0 | 29 newlen=newsr; |
tomwalters@0 | 30 end |
tomwalters@0 | 31 newsig=signal(newlen,newsr); |
tomwalters@0 | 32 nr_points=getnrpoints(newsig); |
tomwalters@0 | 33 new_vals=zeros(nr_points,1); |
tomwalters@0 | 34 for i=1:nr_points |
tomwalters@0 | 35 whichstart=(i-1)*newsr/factor; |
tomwalters@0 | 36 whichstop=i*newsr/factor; |
tomwalters@0 | 37 |
tomwalters@0 | 38 if whichstop>len |
tomwalters@0 | 39 whichstop=len; |
tomwalters@0 | 40 end |
tomwalters@0 | 41 new_vals(i)=average(sig,whichstart,whichstop); |
tomwalters@0 | 42 end |
tomwalters@0 | 43 newsig=setvalues(newsig,new_vals); |
tomwalters@0 | 44 return |
tomwalters@0 | 45 end |
tomwalters@0 | 46 |
tomwalters@0 | 47 newsig=sig; |
tomwalters@0 | 48 |
tomwalters@0 | 49 |