Search code examples
c#.netsignal-processingnoise

How to generate white noise without using SignalGenerator() or another built-in function in C#?


I am trying to analyze frequency outputs of different signals, when it came to white noise, i'm lost. I need to create an array of numbers to stream it to the sound card. Is there any algorithm that i can follow to generate a white noise. Any hint will be appreciated.


Solution

  • White noise is -basically- random frequencies composed together. Therefore, something like this method works fine(normalization process is also included):

    Random rand = new Random();
    void generateWhiteNoise(float[] output, int numberOfSamples)
            {
                for (int i = 0; i < numberOfSamples; i++)
                {
                    output[i] = 2.0f * (Convert.ToSingle(rand.NextDouble()) - 0.5f);
                }           
            }