annotate aim-mat/tools/@signal/genbandpassnoise.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=genbandpassnoise(sig,varargin)
tomwalters@0 3 % INPUT VALUES:
tomwalters@0 4 % sig: @signal with length and samplerate
tomwalters@0 5 % RETURN VALUE:
tomwalters@0 6 % sig: @signal
tomwalters@0 7 %
bleeck@3 8 % This external file is included as part of the 'aim-mat' distribution package
bleeck@3 9 % (c) 2011, University of Southampton
bleeck@3 10 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 11 % download of current version is on the soundsoftware site:
bleeck@3 12 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 13 % documentation and everything is on http://www.acousticscale.org
tomwalters@0 14
tomwalters@0 15 function sig=genbandpassnoise(sig,lowfrequency,highfrequency)
tomwalters@0 16 % steepness is given in dB per octave (to make it compatible with Fastl)
tomwalters@0 17
tomwalters@0 18 len=getlength(sig);
tomwalters@0 19 sr=getsr(sig);
tomwalters@0 20
tomwalters@0 21 % generate white noise:
tomwalters@0 22 vals=getvalues(sig);
tomwalters@0 23
tomwalters@0 24 nyquist_frequenz=sr/2;
tomwalters@0 25 N=getnrpoints(sig);
tomwalters@0 26
tomwalters@0 27 n1=round(lowfrequency/nyquist_frequenz*N/2);
tomwalters@0 28 n2=round(highfrequency/nyquist_frequenz*N/2);
tomwalters@0 29
tomwalters@0 30 if n1<=0
tomwalters@0 31 n1=1;
tomwalters@0 32 end
tomwalters@0 33 if n2>N
tomwalters@0 34 n2=N;
tomwalters@0 35 end
tomwalters@0 36
tomwalters@0 37 noise1=zeros(size(vals));
tomwalters@0 38 noise2=zeros(size(vals));
tomwalters@0 39 for i=n1:n2
tomwalters@0 40 noise1(i)=rand(1);
tomwalters@0 41 end
tomwalters@0 42 for i=N-n2:N-n1
tomwalters@0 43 noise2(i)=rand(1);
tomwalters@0 44 end
tomwalters@0 45 ftband=noise1+ i*noise2;
tomwalters@0 46 vals=ifft(ftband);
tomwalters@0 47 vals=real(vals);
tomwalters@0 48
tomwalters@0 49 sig=setvalues(sig,vals);
tomwalters@0 50 sig=setname(sig,sprintf('Bandpass filtered noise from %4.1f Hz to %4.1f Hz',lowfrequency,highfrequency));
tomwalters@0 51
tomwalters@0 52 return