annotate aim-mat/tools/@signal/generateirn.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=generateirn(sig,delay,g,niter)
tomwalters@0 3 % INPUT VALUES:
tomwalters@0 4 % sig: original @signal with length and samplerate
tomwalters@0 5 % delay: delay, after which the noise is added again
tomwalters@0 6 % g: gain
tomwalters@0 7 % niter: number of iterations that are added
tomwalters@0 8 %
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
bleeck@3 18
tomwalters@0 19
tomwalters@0 20 function sig=generateirn(sig,delay,g,niter)
tomwalters@0 21
tomwalters@0 22 srate=getsr(sig);
tomwalters@0 23 dur=getlength(sig);
tomwalters@0 24
tomwalters@0 25 dels=round(delay*srate);
tomwalters@0 26 npts=round(dur*srate);
tomwalters@0 27
tomwalters@0 28 nois=randn(size(1:npts));
tomwalters@0 29
tomwalters@0 30 for i=1:niter;
tomwalters@0 31 dnois=nois;
tomwalters@0 32 dnoist=dnois(1:dels);
tomwalters@0 33 dnois=[dnois dnoist];
tomwalters@0 34 dnois=dnois(dels+1:npts+dels);
tomwalters@0 35 dnois=dnois.*g;
tomwalters@0 36 nois=nois+dnois;
tomwalters@0 37 end;
tomwalters@0 38
tomwalters@0 39 rms=sqrt(mean(nois.*nois));
tomwalters@0 40 b=nois./rms;
tomwalters@0 41
tomwalters@0 42 sig=setvalues(sig,b);