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?
var(Y-X)
work? I think that would give you the variance of whatawgn()
applied. – chessofnerd