annotate aim-mat/tools/@signal/expand.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=expand(sig,newlength,[value])
tomwalters@0 3 %
tomwalters@0 4 % makes the signal longer (or shorter) by appending values with the value value
tomwalters@0 5 % if time is negative, then expand it to the front by filling the first time with value
tomwalters@0 6 %
tomwalters@0 7 % INPUT VALUES:
tomwalters@0 8 % sig: original @signal
tomwalters@0 9 % newlength: the new length of the signal
tomwalters@0 10 % value: value, with wich the new part is filled [0]
tomwalters@0 11 %
tomwalters@0 12 % RETURN VALUE:
tomwalters@0 13 % time: time, when signal is bigger 0 for first time
tomwalters@0 14 %
bleeck@3 15 % This external file is included as part of the 'aim-mat' distribution package
bleeck@3 16 % (c) 2011, University of Southampton
bleeck@3 17 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 18 % download of current version is on the soundsoftware site:
bleeck@3 19 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 20 % documentation and everything is on http://www.acousticscale.org
tomwalters@0 21
tomwalters@0 22 function sig=expand(a,newlength,value)
tomwalters@0 23
tomwalters@0 24 lenalt=getlength(a);
tomwalters@0 25 sig=a; % erst mal eine Kopie des Signals
tomwalters@0 26 sr=getsr(a);
tomwalters@0 27 if newlength < 0 % aha, länger machen mit vorne auffüllen
tomwalters@0 28 lenneu=lenalt-newlength; % denn die newlength ist ja negativ
tomwalters@0 29 temp=a.werte;
tomwalters@0 30
tomwalters@0 31 start=time2bin(a,-newlength);
tomwalters@0 32 stop=time2bin(a,lenneu);
tomwalters@0 33
tomwalters@0 34 neuevals=ones(1,stop)*value;% erst alle mit den gewünschten Werten belegen
tomwalters@0 35 bla=time2bin(a,lenalt);
tomwalters@0 36 neuevals(start+1:stop)=temp(1:bla); % dann mit dem alten Signal überschreiben
tomwalters@0 37
tomwalters@0 38 sig.werte(1:stop)=neuevals(1:stop);
tomwalters@0 39
tomwalters@0 40 else % positive neue Länge
tomwalters@0 41 if lenalt>=newlength %nothing to do
tomwalters@0 42 return;
tomwalters@0 43 end
tomwalters@0 44 start=time2bin(a,lenalt);
tomwalters@0 45 stop=time2bin(a,newlength);
tomwalters@0 46 sig.werte(start:stop)=value;
tomwalters@0 47 end
tomwalters@0 48
tomwalters@0 49