Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Adding Gaussian Noise to Signal In C++

Status
Not open for further replies.

guang4243

Newbie level 5
Newbie level 5
Joined
Sep 27, 2011
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Malaysia
Visit site
Activity points
1,338
Unlike in the Matlab, user can use randn or awgn to adding the white noise to signal.
Now I want to add white noise to signal by using C++.
I only know that in C++ only have the rand() function.
So, can I know how to use C++ to add white noise as how the Matlab are?
Any reference so that I can refer?

Hope can get reply soon.
Thank you.
 

'morning guang4243,

I've applied the technique described in the (brilliant!) book "Numerical Recipes in C" to create random numbers with arbitrary probability distributions with success in the past. The book is available freely on the web, and the section describing both the technique AND the generation of Gaussian deviates is here: **broken link removed**

Their function gasdev(...) calls their own random number generator (described earlier in the same chapter **broken link removed**), but you could probably graft in your own if you had a particular favourite :)
 

C++ supports plenty of statistical distributions, Gaussian definitely included: http://en.cppreference.com/w/cpp/numeric/random
Here's the relevant example for a standard normal (Gaussian) distribution: http://en.cppreference.com/w/cpp/numeric/random/normal_distribution
Here's a tutorial: http://isocpp.org/blog/2013/03/n3551-random-number-generation

Note that these were added in 2011 -- if your compiler still doesn't support it, upgrade ASAP, it's 2013.
Any of the modern compilers should do: http://isocpp.org/get-started

Alternatively, if you're forced to work with legacy compiler(s), you can also use Boost.Random: http://boost.org/libs/random/
Since the Standard C++ <random> facility is based on the Boost.Random library, it's very easy to reuse the code and translate the examples.
 

Thanks for the info.

Now i have another problem when i want to get noisy data.
To build noisy data, I aldy added Random Noise with uniform distribution into the E-field data (this is clean data).
But i have problem on how to calculate the SNR between the noisy data and the clean data.
Can i know where can i refer to?

Hope can get reply soon.
Thank You
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top