tomwalters@0: % method of class @signal tomwalters@0: % function sig=genbandpassnoise(sig,varargin) tomwalters@0: % INPUT VALUES: tomwalters@0: % sig: @signal with length and samplerate 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: function sig=genbandpassnoise(sig,lowfrequency,highfrequency) tomwalters@0: % steepness is given in dB per octave (to make it compatible with Fastl) tomwalters@0: tomwalters@0: len=getlength(sig); tomwalters@0: sr=getsr(sig); tomwalters@0: tomwalters@0: % generate white noise: tomwalters@0: vals=getvalues(sig); tomwalters@0: tomwalters@0: nyquist_frequenz=sr/2; tomwalters@0: N=getnrpoints(sig); tomwalters@0: tomwalters@0: n1=round(lowfrequency/nyquist_frequenz*N/2); tomwalters@0: n2=round(highfrequency/nyquist_frequenz*N/2); tomwalters@0: tomwalters@0: if n1<=0 tomwalters@0: n1=1; tomwalters@0: end tomwalters@0: if n2>N tomwalters@0: n2=N; tomwalters@0: end tomwalters@0: tomwalters@0: noise1=zeros(size(vals)); tomwalters@0: noise2=zeros(size(vals)); tomwalters@0: for i=n1:n2 tomwalters@0: noise1(i)=rand(1); tomwalters@0: end tomwalters@0: for i=N-n2:N-n1 tomwalters@0: noise2(i)=rand(1); tomwalters@0: end tomwalters@0: ftband=noise1+ i*noise2; tomwalters@0: vals=ifft(ftband); tomwalters@0: vals=real(vals); tomwalters@0: tomwalters@0: sig=setvalues(sig,vals); tomwalters@0: sig=setname(sig,sprintf('Bandpass filtered noise from %4.1f Hz to %4.1f Hz',lowfrequency,highfrequency)); tomwalters@0: tomwalters@0: return