function y = whitenoise(T, Fs)
// White noise generator
//
// Usage:
//       y = whitenoise(T, Fs)
//
// where T:  duration in s
//       Fs: sampling rate in Hz
//       y:  white noise output row vector 
//
// This function generates random noise of given duration
// and root mean square equal to 1. DC component is 0.
// If Fs is not provided, its default value is 44100. If 
// Fs = 1 then the number of samples to generate is floor(T)+1.
// 
// Se also: pinknoise, browniannoise, bandnoise
//
// ------------------------------------
// Author: Federico Miyara
// Date:   2010-06-07
//         2010-10-23
//         2012-05-27
//         2019-05-24
//         2020-08-29  

// Provide default values for missing arguments
rhs = argn(2);
if rhs < 2
   Fs = 44100;
end

// White gaussian noise
y = grand(1, 1 + floor(Fs*T), "nor", 0, 1);

// DC removal
y = y - mean(y);

// Normalisation to ensure RMS value equal to 1
y = y / sqrt(mean(y.^2));

endfunction
