Tuesday, October 18, 2011

Generating White Noise Sound on Octave / Matlab


The following white noise sound was generated with GNU Octave's random number generator rand(), which generates uniformly distributed random values in the interval [0,1). The wavwrite() function expects values in [-1.0, 1.0), so we multiply by 2 and shift down by 1. So to generate 10 seconds of noise sampled at 48 kHz:
white=rand(48000*10,1)*2-1;
I'm not sure about the inner workings of /dev/urandom, but I used the "reseed" command to feed it data from random.org, so this should be pretty random. To export this to a 16-bit, 48 kHz .wav file in our home directory, the command is:
wavwrite(white,48000,16,'white noise uniform.wav');
Then I converted the .wav file to a FLAC-encoded Ogg (.ogg) file:
flac --ogg "white noise uniform.wav"
(The "compressed" FLAC file is actually larger than the .wav file.)  :) Then I generated a lossily-compressed .ogg Vorbis file:
oggenc "white noise uniform.wav"
RMS value derived from:
sox "white noise uniform.wav" -e stat
and then in dB is 20 \log_{10}(\mathrm{RMS\ amplitude})
Histogram derived from
hist(white,100,1)

Update: 27 September 2016 
The very simple way to generate whitenoise in Octave (4.0.2+) is by implementing the following three lines,
y = randn (2, 44100) - 0.5;
player = audioplayer (y, 44100, 8);
play (player);
Then you can save it as wave file with
wavwrite (y(1,:), 44100, 'whitenoise.wav')
Or you can use audiowrite function to save it as .wav file.

Source:
- wikipedia.org
- https://www.gnu.org/software/octave/doc/v4.0.0/Audio-Player.html
Related Posts Plugin for WordPress, Blogger...