0

again my question is related to white noise ,but with different meaning.let us compare following two code.first

function [ x ] = generate(N,m,A3)
f1 = 100;
f2 = 200;
T = 1./f1;
t = (0:(N*T/m):(N*T))'; %'
wn = rand(length(t),1).*2 - 1;
x = 20.*sin(2.*pi.*f1.*t) + 30.*cos(2.*pi.*f2.*t) + A3.*wn;
%[pks,locs] = findpeaks(x);
 plot(x)
end

using generate(3,500,10)

graph of this code is following

enter image description here

but let us change our code so that it makes zero mean with white noise

function [ x ] = generate1(N,m,A3)
f1 = 100;
f2 = 200;
T = 1./f1;
t = (0:(N*T/m):(N*T))'; %'
wn = rand(length(t),1).*2 - 1;
mn=wn-mean(wn);
x = 20.*sin(2.*pi.*f1.*t) + 30.*cos(2.*pi.*f2.*t) + A3.*mn;
%[pks,locs] = findpeaks(x);
 plot(x)
end

and graph is following enter image description here

if we compare these two picture,we could say that it is almost same,just some changes,so does matter if we make zero mean or not?for real analysis,like for finding peaks and so on.thanks very much

UPDATED: there is updated code

function [ x ] = generate1(N,m,A3)
f1 = 100;
f2 = 200;
T = 1./f1;
t = (0:(N*T/m):(N*T))'; %'
wn = randn(length(t),1); %zero mean variance 1
x = 20.*sin(2.*pi.*f1.*t) + 30.*cos(2.*pi.*f2.*t) + A3.*wn;
%[pks,locs] = findpeaks(x);
 plot(x)
end

enter image description here

and it's picture

2 Answers2

1

What is the value of mean(wm)? If it is close to zero, then no, it does not matter.

Technically, white noise has zero mean by definition.

mpenkov
  • 21,621
  • 10
  • 84
  • 126
1

Your initial noise is uniformly distributed between -1 & +1

Your second noise is also uniformly disributed between -1 & +1, because mean is already zero, subtracting it is meaningless

in order to obtain white noise you can use randn() function:

wn = randn(length(t),1); %zero mean variance 1

You may not observe any much difference again if your noise coefficient A3 has a much lower value compared to 20 & 30 which are the coefficients of your signal.

In order to find peaks, adding noise may not serve any purpose because noise tends to decrease the information content of signals

fatihk
  • 7,789
  • 1
  • 26
  • 48
  • so what would be effective code for white noise?could you edit your answer related to my white noise code? –  Apr 09 '13 at 08:37
  • i will change it,and i will upload again picture –  Apr 09 '13 at 08:42
  • The OP is subtracting the *sample* mean, which has an expected value of 0, but will not actually be 0. This actually has the effect of reducing the variance... – Oliver Charlesworth Apr 09 '13 at 08:46
  • i have updated,right Amplitude is small,but for large value what is a chance that it may have some effect? –  Apr 09 '13 at 08:47
  • i have posted my effort what i have done and asked question,is it worth to downvote? –  Apr 09 '13 at 08:51
  • In order to find peaks, adding noise may not serve any purpose because noise tends to decrease the information content of signals – fatihk Apr 09 '13 at 08:51
  • i am sure,because it is not funy question,so please it is better some guys not to disturb others,yes for peaks it is not question with this.just for white noise –  Apr 09 '13 at 08:53
  • @dato: I downvoted because you don't appear to have given this much thought. The mean is a scalar value, i.e. a constant. What effect does adding a constant have on the resulting graph? – Oliver Charlesworth Apr 09 '13 at 08:57
  • ok thanks for your help @fatih_k i will accept it,i think there is nothing to add right to my question,about amplitude it is just experiment deal –  Apr 09 '13 at 08:57
  • now imagine that i did not know it,instead do some like this,just tell me –  Apr 09 '13 at 08:58