How to add white Gaussian noise to signal

9.1k views Asked by At

How can i add white Gaussian noise to signal.
Now, i'm using awgn function but it doesn't work.
Am i give an incorrect parameter?

EDITED

x = -2:.002:2;

% Initail variables
M = 0;
V = 500*10^(-6);

% Creating a singal
T = -pi + (pi+pi)*rand(1,1);
S = (13.5)*cos(2*pi*x+T);

% Creating Noise singal
W = M+sqrt(V)*rand(1,2500);

% Adding Noise to signal // This doesn't work
SW = awgn(S,W,'measured');
% or this doesn't work too
SW = S + W;

Thanks in advance.

enter image description hereenter image description here

2

There are 2 answers

0
hbaderts On BEST ANSWER

Your vectors don't have the same size. S is 1x2001 and W is 1x2500. Try

W = M + sqrt(V)*rand(size(S));

Then you can just add the signals by

SW = S + W;

As Kostya already wrote, awgn can be used if you know the desired SNR.

0
Kostya On

From Matlab manual

y = awgn(x,snr) adds white Gaussian noise to the vector signal x. The scalar snr specifies the signal-to-noise ratio per sample, in dB.