annotate aim-mat/tools/@signal/generatesinus.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=generatesinus(sig,[fre],[amplitude],[phase])
tomwalters@0 3 % INPUT VALUES:
tomwalters@0 4 % sig: original @signal with length and samplerate
tomwalters@0 5 % fre: frequency (Hz) [1000]
tomwalters@0 6 % amplitude: [1]
tomwalters@0 7 % phase: startphase [0]
tomwalters@0 8 % phases must be in degrees!
tomwalters@0 9 % RETURN VALUE:
tomwalters@0 10 % sig: @signal
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
tomwalters@0 20 function sig=generatesinus(sig,fre,amplitude,phase)
tomwalters@0 21
tomwalters@0 22 if nargin < 4
tomwalters@0 23 phase=0;
tomwalters@0 24 end
tomwalters@0 25 if nargin < 3
tomwalters@0 26 amplitude=1;
tomwalters@0 27 end
tomwalters@0 28 if nargin < 2
tomwalters@0 29 fre=1000;
tomwalters@0 30 end
tomwalters@0 31
tomwalters@0 32 nr_points=getnrpoints(sig);
tomwalters@0 33 sr=getsr(sig);
tomwalters@0 34 length=getlength(sig);
tomwalters@0 35
tomwalters@0 36 von=0+phase;
tomwalters@0 37 periode=1/fre;
tomwalters@0 38 bis=2*pi*length/periode + phase;
tomwalters@0 39
tomwalters@0 40
tomwalters@0 41 temp=linspace(von,bis,nr_points);
tomwalters@0 42 data=sin(temp);
tomwalters@0 43
tomwalters@0 44 data=data*amplitude;
tomwalters@0 45
tomwalters@0 46 sig=signal(data);
tomwalters@0 47 sig=setsr(sig,sr);
tomwalters@0 48 sig=setname(sig,sprintf('Sinus %4.2f kHz',fre/1000));