0
votes

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
What do you mean by "it doesn't work"? Does the code run but give incorrect results (in which case give us expected and actual output and a small test case) or does it give an error and not finish (in which case gives us the error message and a small test case)?David
Your example can't be run. Please supply all needed values (especially x). I assume that your vectors S and W don't have the same size, otherwise SW = S+W; should definetly work. Just to be sure: try W = M+sqrt(V)*rand(size(S));hbaderts
you need to define V and x, and the dimentions of S and W need to be the same, i suggest you debug your code step by step and let us know what is the specific problem.shoham
Please define: x1, x, M and V. Then we can help you.Trojanian
OK, I've edited my question please check for me again.Marcus

2 Answers

1
votes

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.

1
votes

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.