double AWGN_generator() { /* Generates additive white Gaussian Noise samples with zero mean and a standard deviation of 1. */ double temp1_d; double temp2_d; double result_d; int p_ui; p_ui = 1; while( p_ui > 0 ) { temp2_d = ( rand() / ((double) RAND_MAX ) ); /* rand() function generates an integer between 0 and RAND_MAX, which is defined in stdlib.h. */ if ( temp2_d == 0 ) {// temp2 is >= (RAND_MAX / 2) p_ui = 1; } // end if else {// temp2 is < (RAND_MAX / 2) p_ui = -1; }// end else }// end while() temp1_d = cos( ( 2.0 * (double)PI ) * rand() / (double) ( RAND_MAX ) ); result_d = sqrt( -2.0 * log( temp2_d ) ) * temp1_d; return result_d ; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)