Hi guys,

I start saying that this is not properly a "technical" question, but it requires a little bit knowledge about communications concepts like gaussian noise and SNR.

I'm coding a scientific software, and obviously it has some problem. It's not giving the result I'm expecting, so I triple checked everything and the one I'm proposing seems me to be the weakest part of the software.

Ok, I created an array of complex elementes, but img part is always 0.

I need to create a gaussian noise vector to add to this array to simulate noise conditions.

I've not found source files to generate gaussian noise, so I decided to try by myself: I tought i could generate 1000 arrays of pseudorandom elements between -1 and 1 and sum them time by time. At the end I divide each element by 1000, so I have a "random" array of values in the range [-1,1].

This is the code.

Main part:

Code:

for (j = 0; j < NVARS; j++) { init_genrand(rand());
for (i = 0; i < LENGTH; i++) {
uniformVar[i].real = (genrand_real1()*2 - 1);
uniformVar[i].img = 0.0;
}
cpxvecsum(noisevector, uniformVar, LENGTH);
}

Now that I have a random array of noise, I need to make it gaussian noise, obviously depending on my SNR value.

First of all I find the power of this array, so I can divide each element for a certain number to make its power=1.

Snippet:

Code:

float DigitalSignalPower(complex* vettore, int size) { int i;
float absol;
float temp = 0.0;
for (i = 0; i < size; i++) {
absol = fabs(vettore[i].real);
temp += pow(absol, 2);
}
return temp / size;
}

what I did is:

and at the end divide by size to normalize the result on the length of the array.

And in the main I divide each element by the square of this number. Now the power of the vector is 1, but I don't know if the "algorithm" is right.

By the way, I know that:

so I need to find new N_{power }but I need to get it in a linear scale, so:

I have a fixed SNRdB, and I compute Signal power as I computed noise power at the start of the topic:

Code:

float DigitalSignalPower(complex* vettore, int size) { int i;
float absol;
float temp = 0.0;
for (i = 0; i < size; i++) {
absol = fabs(vettore[i].real);
temp += pow(absol, 2);
}
return temp / size;
}

and at the end I multiply my noise vector element by element with the square of this number.

Seems you right?

Maybe you know a faster way to implement gaussian noise?