annotate aim-mat/tools/@signal/getpart.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 @signal
tomwalters@0 2 % function sig=getpart(sig,from,[to])
tomwalters@0 3 %
tomwalters@0 4 % INPUT VALUES:
tomwalters@0 5 % @sig: original signal
tomwalters@0 6 % from: from this time in seconds
tomwalters@0 7 % to: to this time in seconds (default: end of signal)
tomwalters@0 8 % RETURN VALUE:
tomwalters@0 9 % returns a signal-object that is a copy of the original signal in the
tomwalters@0 10 % range from-to
tomwalters@0 11 %
bleeck@3 12 % This external file is included as part of the 'aim-mat' distribution package
bleeck@3 13 % (c) 2011, University of Southampton
bleeck@3 14 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 15 % download of current version is on the soundsoftware site:
bleeck@3 16 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 17 % documentation and everything is on http://www.acousticscale.org
tomwalters@0 18
tomwalters@0 19 function sig=getpart(a,from,to)
tomwalters@0 20
tomwalters@0 21 sr=getsr(a);
tomwalters@0 22
tomwalters@0 23 if nargin<3
tomwalters@0 24 to=getlength(a);
tomwalters@0 25 end
tomwalters@0 26
tomwalters@0 27 if from < getminimumtime(a)
tomwalters@0 28 error('error: negative beginning in getpart');
tomwalters@0 29 end
tomwalters@0 30
tomwalters@0 31 if to > getmaximumtime(a)+sr
tomwalters@0 32 error('error: getpart wants part behind signal');
tomwalters@0 33 end
tomwalters@0 34
tomwalters@0 35 duration=to-from;
tomwalters@0 36 sig=signal(duration,sr);
tomwalters@0 37
tomwalters@0 38 target_nr_point=getnrpoints(sig);
tomwalters@0 39
tomwalters@0 40 start=time2bin(a,from)+1;
tomwalters@0 41 stop=time2bin(a,to);
tomwalters@0 42
tomwalters@0 43 % realtarget=stop-start+1;
tomwalters@0 44 % if realtarget~=target_nr_point
tomwalters@0 45 % % seems to happen when sr=44100
tomwalters@0 46 % target_nr_point=realtarget;
tomwalters@0 47 % end
tomwalters@0 48
tomwalters@0 49 len=length(a.werte);
tomwalters@0 50 if start+target_nr_point-1 > len
tomwalters@0 51 target_nr_point=len-start+1;
tomwalters@0 52 % seems to happen when sr=44100
tomwalters@0 53 sig.werte(1:target_nr_point)=a.werte(start:start+target_nr_point-1);
tomwalters@0 54 else
tomwalters@0 55 sig.werte(1:end)=a.werte(start:start+target_nr_point-1);
tomwalters@0 56 end
tomwalters@0 57 % sig.werte(1:end)=a.werte(start:stop);
tomwalters@0 58
tomwalters@0 59 sig=setstarttime(sig,from);
tomwalters@0 60 sig=setname(sig,sprintf('Part of Signal: %s',getname(a)));
tomwalters@0 61
tomwalters@0 62
tomwalters@0 63