How to generate noise using specific variance

谁说我不能喝 提交于 2019-12-20 07:48:33

问题


In the matlab function awgn() that is used to add noise to a signal, is there a way specify the variance?

In general, I would have simply done noisevec = sqrt(2)*randn(length(X),1); creates a noise vector of variance 2. Then the noisy observations are

Y = X+noisevec

But, I would like to apply awgn() and then check if the variance of noise is indeed as specified by the user. How to do that?

         % add noise to produce
         % an SNR of 10dB, use:
         X = sin(0:pi/8:6*pi);
         Y = awgn(X,10,'measured');

UPDATE : Based on the solution, the output should be same when generating noise with specific variance using the awgn() given in the answer/ solution provided and when using without awgn(). Is something wrong in my understanding? Here is how I checked.

x =  rand(1,10); $generating source input
snr =10;
variance = 0.1;
%This procedure is  based on the answer
y1 = awgn(x, snr, 'measured');
y1 = x + (y1 - x) * sqrt(variance / var(y1 - x));

%This is the traditional way, without using awgn()

 y2 = x+sqrt(variance)*randn(1,10);

y1 is not equal to y2. I wonder why?


回答1:


awgn does not generate a noise with a specific variance. But if you have to generate a noise with a specific variance, you may consider defining your own noise generator which could be simply scaling the noise up or down to the desired level:

function y = AddMyNoise(x, variance)
    y = awgn(x, 10, 'measured');
    y = x + (y - x) * sqrt(variance / var(y - x));
end

UPDATE: Note that this method of forcing the output to have a specific variance could be dangerous: It will give strange outputs if x has few elements. In the limit of x being a scalar, this approach will add a fixed value of +-sqrt(variance) to x. No white noise anymore. But if you have more than a few data points, you will get a reasonably white noise.



来源:https://stackoverflow.com/questions/39215427/how-to-generate-noise-using-specific-variance

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!