annotate aim-mat/tools/@signal/generaterampsinus.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=generaterampsinus(sig,carfre,modfre,amplitude,halflife)
tomwalters@0 3 % INPUT VALUES:
tomwalters@0 4 % sig: original @signal with length and samplerate
tomwalters@0 5 % carfre: carrier frequency (Hz) [1000]
tomwalters@0 6 % modfre: modulation frequency (Hz) [100]
tomwalters@0 7 % amplitude: [1]
tomwalters@0 8 % halflife: time for the envelope envelope to rise exponentially
tomwalters@0 9 % to 1/2
tomwalters@0 10 %
tomwalters@0 11 % RETURN VALUE:
tomwalters@0 12 % sig: @signal
tomwalters@0 13 %
bleeck@3 14 % This external file is included as part of the 'aim-mat' distribution package
bleeck@3 15 % (c) 2011, University of Southampton
bleeck@3 16 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 17 % download of current version is on the soundsoftware site:
bleeck@3 18 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 19 % documentation and everything is on http://www.acousticscale.org
tomwalters@0 20
tomwalters@0 21
tomwalters@0 22 function sig=generaterampsinus(sig,carfre,modfre,amplitude,halflife)
tomwalters@0 23
tomwalters@0 24 if nargin < 5
tomwalters@0 25 halflife=0.01;
tomwalters@0 26 end
tomwalters@0 27 if nargin < 4
tomwalters@0 28 amplitude=1;
tomwalters@0 29 end
tomwalters@0 30
tomwalters@0 31 if nargin < 3
tomwalters@0 32 modfre=100;
tomwalters@0 33 end
tomwalters@0 34 if nargin < 2
tomwalters@0 35 carfre=1000;
tomwalters@0 36 end
tomwalters@0 37
tomwalters@0 38
tomwalters@0 39 sinus=generatesinus(sig,carfre,amplitude,0);
tomwalters@0 40
tomwalters@0 41 % calculate envelope and mult both
tomwalters@0 42 envelope=sig;
tomwalters@0 43 time_const=halflife/0.69314718;
tomwalters@0 44
tomwalters@0 45 env_vals=getvalues(envelope);
tomwalters@0 46 time=0;
tomwalters@0 47 sr=getsr(envelope);
tomwalters@0 48 reprate=1/modfre;
tomwalters@0 49
tomwalters@0 50
tomwalters@0 51 for i=1:getnrpoints(envelope);
tomwalters@0 52 time=time+1/sr;
tomwalters@0 53
tomwalters@0 54 env_vals(i)= exp(-(reprate-time)/time_const);
tomwalters@0 55 time=mod(time,reprate);
tomwalters@0 56
tomwalters@0 57 end
tomwalters@0 58
tomwalters@0 59 envelope=setvalues(envelope,env_vals);
tomwalters@0 60
tomwalters@0 61 sig=sinus*envelope;
tomwalters@0 62 % sig=sig*amplitude;
tomwalters@0 63
tomwalters@0 64 sig=setname(sig,sprintf('Ramp Sinus %4.2f kHz, Modulation=%4.2f Hz, halflife=%4.2f ms',carfre/1000,modfre,halflife*1000));