function x = makebwhite(fc, df, dt, fs, T)

%----- 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

% $Id: makebwhite.m,v 1.1 2005/05/11 19:39:16 stuver Exp $


%-----------------------------------------------
% User-specified quantities.
%-----------------------------------------------

%----- Set desired time-frequency properties:
% fc = 1000;  % central frequency
% df = 100;   % bandwidth
% dt = 0.001; % duration
% fs = 16384; % sampling rate
% T = 1;      % duration of data sample


%-----------------------------------------------
% Do not edit below this line.
%-----------------------------------------------

%----- Generate noise with the desired frequency content:

%----- Generate white noise burst with duration dt at sample rate df
%      (white over entire band [-df/2,df/2]).
nSamp = ceil(T*df);
x = randn([1,nSamp]);

%----- Resample to sample rate fSamp
[p,q] = rat(fs/df);
x = resample(x,p,q);

%----- Truncate (if necessary) to duration dt
nSamp = floor(T*fs);
x = x(1:nSamp);

%----- Heterodyne up by f+df/2 (moves zero frequency to center of desired
%      band)
fup = fc+df/2;
x = x.*exp(-2*pi*i*fup/fs*(1:numel(x)));

%----- Take real part and adjust amplitude
x = real(x)/sqrt(2);

%----- window in the time domain
t = [0:1/fs:T-1/fs]';
env = exp(-(t-T/2).^2/2/dt.^2);
x = env.*x';
