It might be a very silly question, however I'm facing problem with it. Now, the Gaussian noise is a signal with zero mean and variance. I understand what the mean and the variance mean however, I'm facing problem with zero mean. What does that mean? Does it mean that it is only a signal with variance which represents the magnitude of the signal? And if this is the case, why we bother ourself with variance since the magnitude of this signal is random? I want to understand that because I want build a sensor (a function in C/C++) and add some noise to the data. In MatLab, there is randn
to generate Gaussian noise, but I have no idea how to do same concept in C++.
Edit: Let's say I have a sensor with $\pm$ 0.2 as an error. What I understand that the noise should be a Gaussian noise with zero mean and variance. Now, I have a real data which represents the position in 1D. My sensor now should give the position with some uncertainty. This is my code in C++11
#include <iostream>
#include <chrono>
#include <random>
int main(int argc, const char * argv[])
{
double noise; // Gaussian noise with zero mean and variance 1
double data_sensor;
double position(2.0);
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::default_random_engine engine(seed);
std::normal_distribution<double> dist(0, 1);
for (int i(0); i < 10; ++i)
{
noise = dist(engine);
data_sensor = position + 0.2*noise;
std::cout << "Real Data: " << position << " Sensor Data: " << data_sensor << std::endl;
}
return 0;
}
The output
Real Data: 2 Sensor Data: 2.19025
Real Data: 2 Sensor Data: 1.96754
Real Data: 2 Sensor Data: 2.03551
Real Data: 2 Sensor Data: 1.58706 << Why this out of the range
Real Data: 2 Sensor Data: 2.11237
Real Data: 2 Sensor Data: 1.98482
Real Data: 2 Sensor Data: 1.94809
Real Data: 2 Sensor Data: 1.8264
Real Data: 2 Sensor Data: 1.9776
Real Data: 2 Sensor Data: 1.70071 << Why this out of the range