Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have an array of vaules in A [ ], i need to add gaussian noise to it .
I am using this function for gaussian noise generation .

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 ;

}


When i am plotting a graph of my array A[], i am getting a sine wave shape . But i am not able to understand how to add noise to my signal.
Thanks in advance.
Posted
Comments
CPallini 26-Sep-14 9:07am    
Your function doesn't look correct to me. What algorithm are you implementing?
mrinal bisht 26-Sep-14 9:33am    
I have taken this function from
http://www.embeddedrelated.com/showcode/311.php
CPallini 26-Sep-14 9:43am    
OK. If you trust it (no reference provided) then scale it down and add the scaled value to your wave.
mrinal bisht 26-Sep-14 9:49am    
Actualy i am just adding the noise to my signal but i am not getting the expected result.
I also tried box muller transform implementation from (http://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform#Implementation)
But while adding the noise to my signal array i am not getting desired result.
If i am using rand() function instead of gaussian noise then i am getting proper result.
CPallini 26-Sep-14 10:42am    
WHAT is the expected result?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900