Question

For example if Ax = 0.0023, it should add some noise to it and produce newAx = 0.0027 If Hy = 94.54,then newHy = 93.42. Initially I started using rand in MATLAB in the following manner,

newAx = Ax + rand
newAx = 0.9453

This is very much far from the parameter Ax(0.0023) which I have.

If I have to use range then in this case we have to use min and max of Ax. That also introduces issues like it is far from the values. As I have a system where Ax is a gradually increasing parameter at every instant of time. Now at every instant depending on the value of Ax I have to generate some random noise to get newAx which is almost close to Ax. Example if Ax = 0.0023 generate newAx = 0.0027 and not newAx = 0.4590

I need to create a random noise which depends on the data itself.

Was it helpful?

Solution

What kind of "noise" are you trying to simulate?

rand(1) gives you a uniform random number in the range 0 < r < 1. "Uniform" means each value is equally likely, like rolling a single, perfect die.

In other words, the random value has a range of +/- 0.5, centered around 0.5. You want to center around your actual value, and you might want to scale the range depending on the actual value. e.g.

 2 * (rand(1) - 0.5) 

gives you a uniform random numbers in the range -1 < r < 1.


For example, if the noise should not exceed 1%, you would need to use:

newValue = oldValue * ( 1 +  2*(rand(1) - 0.5) * 0.01)

the 0.01 is the scale (1%) I used for the example, the 1 + ... centers around the original value.


Many processes don't have a uniform distribution. A common distribution for random noise (such as sensor noise) is a normal distribution, where values close to the center are more likely than values far from the center.

Matlab supports randn() for normal distribution.

Other distributions which model other systems can be derived from uniform random numbers.

OTHER TIPS

One way to do this is to use RANDN to generate normally distributed noise values, then scale the standard deviation of the noise to be a percentage of the data value:

noiseScale = 0.05;  %# Noise with a standard deviation of %5 of the data
newAx = Ax + noiseScale*Ax*randn;

And if Ax is a vector of values that you want to add noise to, you can do this:

newAx = Ax + noiseScale.*Ax.*randn(size(Ax));

If you want to make sure newAx stays within a particular range of values, you can use the functions MAX and MIN like so:

newAx = min(newAx,maxValue);  %# Clip newAx to a maximum of maxValue
newAx = max(newAx,minValue);  %# Clip newAx to a minimum of minValue
newDatum = oldDatum+2*(rand(1)-0.5)*oldDatum
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top