0
$\begingroup$

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
$\endgroup$
1

4 Answers 4

1
$\begingroup$

Looking at your various comments with other answers, let me see if I can restate your question, and you can tell me if that's correct. You have a sensor and are modelling the output to include noise with mean=zero and unknown variance (your wording makes it sound as though variance is also zero). You asked if zero mean noise implies that signal variance describes the magnitude of the signal.

Just to be clear: you are talking about the variance of the noise, correct, not the variance of the signal? I will assume you meant noise variance, and also that variance of the noise is non-zero.

If the noise has mean=0, that means that the noise is a random signal centered on the true value. If you think about noise as a signal that wiggles randomly through time across some limited range, we can say that the center of this range is equal to the true value of the sensor. The variance of the noise, then, describes how far from the true value this wiggling signal goes - how far away from the true value these random perturbations go. If you look at the true (noise-free) value and the noise separately, the noise would wiggle randomly around the zero line while the true value is whatever its values are. The values that the true value can take on (how much true value moves around, a.k.a. its variance) is entirely independent of the noise's variance (how much noise moves around).

In contrast, if noise had a non-zero mean, it would create a bias or an offset to your true value (so, if noise had mean=1 in your example, then your recorded values would be 3.19, 2.97, 3.04...).

When you say error of +/- 0.2, do you mean that 0.2 is the variance, the standard deviation, or the maximum amount from the true value by which the readout value can deviate? If it's the maximum error, then simulating it as you do with "0.2*noise" will give about 35% of the values outside of the range [-0.2, 0.2], because that doesn't set a hard limit on what the values can be. Taking your "noise" vector and multiplying it by 0.2 makes it into a vector with mean=0 and standard-deviation=0.2 (before multiplying by 0.2, it was mean=0 and stddev=1). If std=0.2, then 65% of your values will be in the range [-0.2, 0.2]. If you want all values to be within [-0.2, 0.2], use 0.2/4 or 0.2/5 as your multiplier - there will still be a few outliers, but it will be 1 out of 1,000 values instead of 1 out of 3.

$\endgroup$
1
  • $\begingroup$ thank you so much for this answer. Yes, I realized later what does 0.2 represent. $\endgroup$
    – CroCo
    Feb 28, 2014 at 20:48
2
$\begingroup$

You need to know what a probability distribution is, along with the definitions of mean and variance. The mean is average value of observations from that distribution (as the number of observations is large). The variance measures the average squared deviations from the mean. So, you can think of it as the average(amplitude^2)(which is not the same as (average(amplitude))^2). This measures the spread of values of the distribution. We worry about it precisely since the signal is random - if it were constant, this would not matter, but knowing the variance tells us something about where the distribution takes its values (in the case of the Gaussian, for example, you have the 68-95-99.7 rule, for example).

Before adding noise, you should know a bit about probability (and even if Gaussian noise is the right noise to add).

As for C++ implementation, Boost has a normal distribution as one of its rng options as does c++11 compilers (see this thread).

$\endgroup$
3
  • $\begingroup$ I know what does mean and variance imply and also I know the probability for some extend but the problem why the noise must be zero mean and variance? and how can I specify the variance for any sensor? $\endgroup$
    – CroCo
    Feb 21, 2014 at 21:13
  • $\begingroup$ Zero variance means that there is no noise. If you know the mean of the noise and it is non-zero, you can just remove some of the noise by just subtracting out the mean of the noise. $\endgroup$
    – Batman
    Feb 22, 2014 at 5:57
  • $\begingroup$ (It is trivial to prove that if X is a real valued r.v. then E[X^2] = 0 implies X = 0 a.s. (i.e. up to a set of measure zero)) $\endgroup$
    – Batman
    Feb 22, 2014 at 6:24
2
$\begingroup$

The Box–Muller method uses two independent random numbers distributed uniformly on $(0,1)$, then uses such two uniformly distributed numbers to produce values with normal distribution.

Zero-mean indicates the average value of the detected signal at each time point is zero. In digital signal processing, zero often refers to $2^{n-1}$ where $n$ is the bit number of digitizer. For example, if you have a 16-bit signal ($65536$), then $32768$ represent the zero in double, and those numbers that less than $32768$ are negative.

$\endgroup$
3
  • $\begingroup$ Nitpick: the average magnitude wouldn't be zero. Instead, the average value is zero. $\endgroup$
    – Jason R
    Feb 21, 2014 at 4:58
  • $\begingroup$ @lennon310, probably I'll go with random generator of C++11. I've updated my post, would you please see it? $\endgroup$
    – CroCo
    Feb 21, 2014 at 21:08
  • $\begingroup$ @CroCo Thank you CroCo. Your code looks good to me. The error has its confidence interval. The mean value of your error is 0.2, but there are at times got the error out of the range. Check this page for details about the confidence level: onlinestatbook.com/2/estimation/mean.html $\endgroup$
    – lennon310
    Feb 21, 2014 at 21:26
0
$\begingroup$

i think you are little bit confused.Actually the variance is the thing which gives a range from the mean to vary randomly. suposing your mean is one, then your noise signal varies from a range (add plus or minus one to the variance factor to randomize your data).

regards, phani tej

$\endgroup$
5
  • $\begingroup$ does the noise in all sensors must be zero mean and variance? $\endgroup$
    – CroCo
    Feb 21, 2014 at 21:09
  • $\begingroup$ the thermal noise in the sensors is modelled as a awgn noise, with zero mean. the variance cannot be zero. if the variance is zero , it means that the noise is not deviating from the mean(i.e there is no noise contribution from the sensors). so depending on your application mean might be zero or non zero. but making variance zero removes the randomness nature of the noise(no deviation). $\endgroup$
    – phanitej
    Feb 24, 2014 at 4:17
  • $\begingroup$ I did not say zero variance. I want to know if I want to simulate a sensor how can I choose the variance that reflects the reality of sensors? $\endgroup$
    – CroCo
    Feb 24, 2014 at 4:53
  • $\begingroup$ but you mentioned in the comment like "zero mean and variance". the variance you have to chose depends on the signal to noise ratio. keep on increasing the snr from 1 to 10 (in db) (i.e reduction in noise variance). and then perform simulation. $\endgroup$
    – phanitej
    Feb 24, 2014 at 5:25
  • $\begingroup$ use the formula..variance=power(10,(-0.1*SNR(db))) $\endgroup$
    – phanitej
    Feb 24, 2014 at 6:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.