tomwalters@0: % method of class @signal tomwalters@0: % function sig=generatesweep(sig,fre1,fre2,amplitude,phase) tomwalters@0: % INPUT VALUES: tomwalters@0: % sig: original @signal with length and samplerate tomwalters@0: % fre1: start frequency (Hz) tomwalters@0: % fre2: stop frequency (Hz) tomwalters@0: % amplitude: [1] tomwalters@0: % phase: startphase [0] tomwalters@0: % phases must be in degrees! tomwalters@0: % RETURN VALUE: tomwalters@0: % sig: @signal tomwalters@0: % 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: tomwalters@0: function sig=generatesweep(sig,fre1,fre2,amplitude,phase) tomwalters@0: tomwalters@0: if nargin < 5 tomwalters@0: phase=0; tomwalters@0: end tomwalters@0: if nargin < 4 tomwalters@0: amplitude=1; tomwalters@0: end tomwalters@0: tomwalters@0: if nargin <3 tomwalters@0: disp('GenerateSweep: Error: usage: sig=generatesweep(sig,fre1,fre2[,amplitude,phase])') tomwalters@0: end tomwalters@0: tomwalters@0: nr_points=getnrpoints(sig); tomwalters@0: sr=getsr(sig); tomwalters@0: length=getlength(sig); tomwalters@0: tomwalters@0: from=0+phase; tomwalters@0: tomwalters@0: fre_space=linspace(fre1,fre2,nr_points); % the change of frequency tomwalters@0: t_space=linspace(0,length,nr_points); % a linear function of time tomwalters@0: val=2*pi*t_space.*fre_space; tomwalters@0: tomwalters@0: val=val + phase; tomwalters@0: tomwalters@0: data=sin(val); tomwalters@0: tomwalters@0: data=data*amplitude; tomwalters@0: tomwalters@0: sig=signal(data); tomwalters@0: sig=setsr(sig,sr); tomwalters@0: sig=setname(sig,sprintf('Sweep from %4.2f kHz to %4.2f kHz',fre1/1000,fre2/1000));