annotate aim-mat/tools/@signal/generatesweep.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=generatesweep(sig,fre1,fre2,amplitude,phase)
tomwalters@0 3 % INPUT VALUES:
tomwalters@0 4 % sig: original @signal with length and samplerate
tomwalters@0 5 % fre1: start frequency (Hz)
tomwalters@0 6 % fre2: stop frequency (Hz)
tomwalters@0 7 % amplitude: [1]
tomwalters@0 8 % phase: startphase [0]
tomwalters@0 9 % phases must be in degrees!
tomwalters@0 10 % RETURN VALUE:
tomwalters@0 11 % sig: @signal
tomwalters@0 12 %
bleeck@3 13 % This external file is included as part of the 'aim-mat' distribution package
bleeck@3 14 % (c) 2011, University of Southampton
bleeck@3 15 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 16 % download of current version is on the soundsoftware site:
bleeck@3 17 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 18 % documentation and everything is on http://www.acousticscale.org
tomwalters@0 19
tomwalters@0 20
tomwalters@0 21 function sig=generatesweep(sig,fre1,fre2,amplitude,phase)
tomwalters@0 22
tomwalters@0 23 if nargin < 5
tomwalters@0 24 phase=0;
tomwalters@0 25 end
tomwalters@0 26 if nargin < 4
tomwalters@0 27 amplitude=1;
tomwalters@0 28 end
tomwalters@0 29
tomwalters@0 30 if nargin <3
tomwalters@0 31 disp('GenerateSweep: Error: usage: sig=generatesweep(sig,fre1,fre2[,amplitude,phase])')
tomwalters@0 32 end
tomwalters@0 33
tomwalters@0 34 nr_points=getnrpoints(sig);
tomwalters@0 35 sr=getsr(sig);
tomwalters@0 36 length=getlength(sig);
tomwalters@0 37
tomwalters@0 38 from=0+phase;
tomwalters@0 39
tomwalters@0 40 fre_space=linspace(fre1,fre2,nr_points); % the change of frequency
tomwalters@0 41 t_space=linspace(0,length,nr_points); % a linear function of time
tomwalters@0 42 val=2*pi*t_space.*fre_space;
tomwalters@0 43
tomwalters@0 44 val=val + phase;
tomwalters@0 45
tomwalters@0 46 data=sin(val);
tomwalters@0 47
tomwalters@0 48 data=data*amplitude;
tomwalters@0 49
tomwalters@0 50 sig=signal(data);
tomwalters@0 51 sig=setsr(sig,sr);
tomwalters@0 52 sig=setname(sig,sprintf('Sweep from %4.2f kHz to %4.2f kHz',fre1/1000,fre2/1000));