DSPRelated.com
Forums

Generation of Pink Noise using 3dB/octave filters on digital white noise

Started by bademiya July 10, 2006
>The most simple way is to just call the function random() from libc: > >#include <stdlib.h> >void createWhiteNoise(double amplitude, double* data, unsigned int num) >{ > for (unsigned int i = 0; i < num; ++i) > data[i] = amplitude * 2 * (((double)random() / (double)RAND_MAX)
- 0.5);
>} >
Thanks a lot Andreas. Just a question though, is there any limit to the amplitude used? For instance, can i say plug in a number like 10? Amit.
Ok. I have generated 2 different programs using the 2 algorithms provided
by Andreas and the other by Randy. I have noticed some differences between
the two and i'm not too sure which is better. The one by Andreas is much
louder and i have used an amplitude of 10. The one by Randy's whereby i
used Steve Park's rngs file has a much softer volume but eitherwise they
both sound the same. Which one in your opinion should i be using?
bademiya wrote:

>>The most simple way is to just call the function random() from libc: >> >>#include <stdlib.h> >>void createWhiteNoise(double amplitude, double* data, unsigned int num) >>{ >> for (unsigned int i = 0; i < num; ++i) >> data[i] = amplitude * 2 * (((double)random() / (double)RAND_MAX) > - 0.5); >>} >> > > Thanks a lot Andreas. Just a question though, is there any limit to the > amplitude used? For instance, can i say plug in a number like 10?
For best results the amplitude should be as high as the soundcard can handle. This depends on the number of bits. For CD quality you use 16 Bits, for recording purposes 24 bits. The highest amplitude is calculated according to this formula: max_ampl = 2 ^ (Bits - 1) If you create a WAV file then you have to specify the number of bits anyway, so it's all under your control. If you use 16 bits, then you can use 'int32_t' (usually 'short') as type for 'data' in createWhiteNoise(), for more bits you must use 'int32_t' (usually 'int'). bye Andreas -- Andreas H&#4294967295;nnebeck | email: acmh@gmx.de ----- privat ---- | www : http://www.huennebeck-online.de Fax/Anrufbeantworter: 0721/151-284301 GPG-Key: http://www.huennebeck-online.de/public_keys/andreas.asc PGP-Key: http://www.huennebeck-online.de/public_keys/pgp_andreas.asc
bademiya wrote:

> I intend to use the noise signal to measure the room impulse response and > to calibrate the speakers accordingly after detection.
For this purpose an MLS based signal is better suited. You can find source code on my homepage: http://www.huennebeck-online.de/software/download/src/index.html 'gensig' generates MLS signals (and also white and pink noise), while 'corr/mlscorr' processes the correlation and generates the room impulse response.
> However at the moment, i am having cable problems. As you all know, the > BF-561 board outputs audio signal through the RCA jacks. However, the PC > speakers i am using uses the standard 3.5mm stereo jack as input.
Well, if you are using ultracheap PC speakers then the impulse response you are measuring will be limited by the poor performance of this type of speakers.
> I have another query though. At the moment when i generate the white > noise, it plays for an infinite amount of time. Does anyone know how i can > limit the playback period to a much shorter time?
Read the manual of the program you use for playback. Tschau Andreas -- Andreas H&#4294967295;nnebeck | email: acmh@gmx.de ----- privat ---- | www : http://www.huennebeck-online.de Fax/Anrufbeantworter: 0721/151-284301 GPG-Key: http://www.huennebeck-online.de/public_keys/andreas.asc PGP-Key: http://www.huennebeck-online.de/public_keys/pgp_andreas.asc
bademiya wrote:

> Ok. I have generated 2 different programs using the 2 algorithms provided > by Andreas and the other by Randy. I have noticed some differences between > the two and i'm not too sure which is better. The one by Andreas is much > louder and i have used an amplitude of 10. The one by Randy's whereby i > used Steve Park's rngs file has a much softer volume but eitherwise they > both sound the same. Which one in your opinion should i be using?
Calculate the amplitude so that the output of the soundcard is at maximum level. See my other posting. Tschau Andreas -- Andreas H&#4294967295;nnebeck | email: acmh@gmx.de ----- privat ---- | www : http://www.huennebeck-online.de Fax/Anrufbeantworter: 0721/151-284301 GPG-Key: http://www.huennebeck-online.de/public_keys/andreas.asc PGP-Key: http://www.huennebeck-online.de/public_keys/pgp_andreas.asc
Hi.

Once again, i have another query. I have written a program using Steve
Park's rngs file. By reading the rngs file, i understand that the output,
which is Random(), is any number between 0 and 1 in a double data type.
However, the one given Andreas has a possible range between -1 and 1 if i
set the amplitude as 1. 

The question is here is that what should be the output range of the white
noise? I understand that the BF561 is a fixed-point processor and the
format by default is normally the Q0.15 format which gives a very high
precision but has only a range between -1 and +1. Moreover, the ways to
generate white noise involves the use of the double data type in both the
ways that have been explained to me so far. My supervisor here has advised
me against using the double data type as it will involve a lot of computing
and may limit the scope of my programming. Therefore, i have changed
everything to float data type instead.

Using Steve Park's rngs, i have just written these lines to output the
white noise to the speakers:

               for(i = 0; i < 20000; i++){
                  iChannel0LeftOut = 2 * (Random() - 0.5);
  		  iTxBuffer1[INTERNAL_DAC_L0] = iChannel0LeftOut;
               }

Is this the appropriate way to generate white noise or am i making some
error here? As you can see, i have limited the output to be between -1 and
+1.

Amit.
>Calculate the amplitude so that the output of the soundcard is at maximum >level. See my other posting. > >Tschau >Andreas >-- >Andreas H&#4294967295;nnebeck | email: acmh@gmx.de >----- privat ---- | www : http://www.huennebeck-online.de >Fax/Anrufbeantworter: 0721/151-284301 >GPG-Key: http://www.huennebeck-online.de/public_keys/andreas.asc >PGP-Key: http://www.huennebeck-online.de/public_keys/pgp_andreas.asc > >
Thanks for your help. However, i am not using a soundcard to generate the noise. I'm using the Analog Devices BF561 board to generate the white noise.
Hi Amit,

As Andreas stated in another post, you really should be
using Maximal-Length Sequences (MLS) for this type of
application. Their autocorrelation properties are better-suited.

So this will "leap-frog" your question and make the whole
Park "rng" question moot. The MLS will also be easier
to generate using fixed-point arithmetic.

I won't even try to go into MLS - it's better if you
pick it up from a Google or, better, reading some
papers. I think the landmark paper on the subject
is "Transfer-Function Measurement with Maximum-Length
Sequences" by Rife and Vanderkooy, Journal of
the Audio Engineering Society.

--Randy


bademiya wrote:
> Hi. > > Once again, i have another query. I have written a program using Steve > Park's rngs file. By reading the rngs file, i understand that the output, > which is Random(), is any number between 0 and 1 in a double data type. > However, the one given Andreas has a possible range between -1 and 1 if i > set the amplitude as 1. > > The question is here is that what should be the output range of the white > noise? I understand that the BF561 is a fixed-point processor and the > format by default is normally the Q0.15 format which gives a very high > precision but has only a range between -1 and +1. Moreover, the ways to > generate white noise involves the use of the double data type in both the > ways that have been explained to me so far. My supervisor here has advised > me against using the double data type as it will involve a lot of computing > and may limit the scope of my programming. Therefore, i have changed > everything to float data type instead. > > Using Steve Park's rngs, i have just written these lines to output the > white noise to the speakers: > > for(i = 0; i < 20000; i++){ > iChannel0LeftOut = 2 * (Random() - 0.5); > iTxBuffer1[INTERNAL_DAC_L0] = iChannel0LeftOut; > } > > Is this the appropriate way to generate white noise or am i making some > error here? As you can see, i have limited the output to be between -1 and > +1. > > Amit.
Randy Yates wrote:
> Hi Amit, > > As Andreas stated in another post, you really should be > using Maximal-Length Sequences (MLS) for this type of > application.
Correction: "Maximum" Length Sequences. --RY
bademiya wrote:
>> Calculate the amplitude so that the output of the soundcard is at maximum >> level. See my other posting. >> >> Tschau >> Andreas >> -- >> Andreas H&#4294967295;nnebeck | email: acmh@gmx.de >> ----- privat ---- | www : http://www.huennebeck-online.de >> Fax/Anrufbeantworter: 0721/151-284301 >> GPG-Key: http://www.huennebeck-online.de/public_keys/andreas.asc >> PGP-Key: http://www.huennebeck-online.de/public_keys/pgp_andreas.asc >> >> > > Thanks for your help. However, i am not using a soundcard to generate the > noise. I'm using the Analog Devices BF561 board to generate the white > noise.
It doesn't matter where the DAC is. When it gets smaller numbers, it makes less sound. What is the maximum value with each method? What must you do to make them the same? Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;