----- MakeWNB: This script generates a Gaussian-modulated burst of noise which is white over a specified frequency band. -- Patrick Sutton & Sam Finn 2004.08.28
0001 function x = makebwhite(fc, df, dt, fs, T) 0002 0003 %----- MakeWNB: This script generates a Gaussian-modulated 0004 % burst of noise which is white over a specified frequency 0005 % band. 0006 % 0007 % -- Patrick Sutton & Sam Finn 2004.08.28 0008 0009 % $Id: makebwhite.m,v 1.1 2005/05/11 19:39:16 stuver Exp $ 0010 0011 0012 %----------------------------------------------- 0013 % User-specified quantities. 0014 %----------------------------------------------- 0015 0016 %----- Set desired time-frequency properties: 0017 % fc = 1000; % central frequency 0018 % df = 100; % bandwidth 0019 % dt = 0.001; % duration 0020 % fs = 16384; % sampling rate 0021 % T = 1; % duration of data sample 0022 0023 0024 %----------------------------------------------- 0025 % Do not edit below this line. 0026 %----------------------------------------------- 0027 0028 %----- Generate noise with the desired frequency content: 0029 0030 %----- Generate white noise burst with duration dt at sample rate df 0031 % (white over entire band [-df/2,df/2]). 0032 nSamp = ceil(T*df); 0033 x = randn([1,nSamp]); 0034 0035 %----- Resample to sample rate fSamp 0036 [p,q] = rat(fs/df); 0037 x = resample(x,p,q); 0038 0039 %----- Truncate (if necessary) to duration dt 0040 nSamp = floor(T*fs); 0041 x = x(1:nSamp); 0042 0043 %----- Heterodyne up by f+df/2 (moves zero frequency to center of desired 0044 % band) 0045 fup = fc+df/2; 0046 x = x.*exp(-2*pi*i*fup/fs*(1:numel(x))); 0047 0048 %----- Take real part and adjust amplitude 0049 x = real(x)/sqrt(2); 0050 0051 %----- window in the time domain 0052 t = [0:1/fs:T-1/fs]'; 0053 env = exp(-(t-T/2).^2/2/dt.^2); 0054 x = env.*x';