matlabmeasurementnoise-generator

How to add x % noise in a signal in MATLAB?


I am trying to add 5 % noise to a measured signal as follows (in MATLAB), but when I calculate percent of noise after addition, it is beyond +/- 5 % . Can you please tell me why this is the case ? Shouldnt it be within a +/- 5 % bound ?

 noiseSigma = 0.05 * signal;                % signal is my original signal

signal

noise = noiseSigma .* randn(1, length(signal));

noisySignal = signal + noise;

Noise in signal

percent_noise = 100*(noisySignal-signal)./signal;

percent of noise in signal


Solution

  • randn draws from a normal distribution so it can be larger than 1.

    If you want to limit your noise to 5 percent you can try the following:

    noise_limit = 0.05 * signal;
    addative_noise = noise_limit .* (2*rand(1, length(signal))-1);
    result = signal+addative_noise;
    

    This works because rand chooses values between zero and one. multiply it by two and subtract one, and it chooses values between -1 and 1.