Thread Subject: Question about SNR and noise

Subject: Question about SNR and noise

From: Giovanna

Date: 3 Sep, 2007 11:01:51

Message: 1 of 25

Hi everybody
I need to add a noise signal to my output signal. The noise
characteristic are 10dB. I dont have the Communication
Toolbox and therefore, I cant use wgn, o awgn function.
How I could generate the Gaussian White noise with this
characteristics.
If someone have an idea, please let me know.
Cheers

Subject: Question about SNR and noise

From: Krishna

Date: 4 Sep, 2007 08:31:04

Message: 2 of 25

On Sep 3, 4:01 pm, "Giovanna " <giovanna.casti...@jku.at> wrote:
> Hi everybody
> I need to add a noise signal to my output signal. The noise
> characteristic are 10dB. I dont have the Communication
> Toolbox and therefore, I cant use wgn, o awgn function.
> How I could generate the Gaussian White noise with this
> characteristics.
> If someone have an idea, please let me know.
> Cheers

help randn

and maybe the following code snippet helps.

snrdB = 10;
sig = sqrt(2)*sin(2*pi*[0:1/64:100]);
noise = 10^(-snrdB/20)*randn(size(sig));
sig_plus_noise = sig + noise;
sigPowerdB = 10*log10(sig*sig'/length(sig));
noisePowerdB = 10*log10(noise*noise'/length(noise));

HTH,
Krishna
http://dsplog.blogspot.com

Subject: Question about SNR and noise

From: Hugo Human

Date: 8 Sep, 2007 21:26:39

Message: 3 of 25

 Krishna <krishna.pillai@gmail.com> wrote in message
<1188894664.473504.267470@50g2000hsm.googlegroups.com>...
> On Sep 3, 4:01 pm, "Giovanna "
<giovanna.casti...@jku.at> wrote:
> > Hi everybody
> > I need to add a noise signal to my output signal. The
noise
> > characteristic are 10dB. I dont have the Communication
> > Toolbox and therefore, I cant use wgn, o awgn function.
> > How I could generate the Gaussian White noise with this
> > characteristics.
> > If someone have an idea, please let me know.
> > Cheers
>
> help randn
>
> and maybe the following code snippet helps.
>
> snrdB = 10;
> sig = sqrt(2)*sin(2*pi*[0:1/64:100]);
> noise = 10^(-snrdB/20)*randn(size(sig));
> sig_plus_noise = sig + noise;
> sigPowerdB = 10*log10(sig*sig'/length(sig));
> noisePowerdB = 10*log10(noise*noise'/length(noise));
>
> HTH,
> Krishna
> http://dsplog.blogspot.com
>

I have never seen this :

> noise = 10^(-snrdB/20)*randn(size(sig));


As far as I know it's
noise = 10^(-snrdB/10)*randn(size(sig));
because
SNR = 10*log(1/var);

But what I want to know is, because your signal's power is
0.5, how does this influence your equation....
Is this why you use
SNR = 20*log(1/var);
????

Subject: Question about SNR and noise

From: Krishna

Date: 9 Sep, 2007 14:56:33

Message: 4 of 25

On Sep 9, 2:26 am, "Hugo Human" <s24093...@hotmail.com> wrote:

> I have never seen this :
> > noise = 10^(-snrdB/20)*randn(size(sig));
>
> As far as I know it's
> noise = 10^(-snrdB/10)*randn(size(sig));
> because
> SNR = 10*log(1/var);

I do not disagree to the SNR = 10*log(1/var);. However, note that am
scaling a noise voltage signal (and not the
power signal). Hence the 10^(-snrdB/20) for scaling.

> But what I want to know is, because your signal's power is
> 0.5, how does this influence your equation....

No. Note that I have used a scaling factor of sqrt(2). Hence the
signal power approx=1 (0dB).

> Is this why you use
> SNR = 20*log(1/var);
> ????
No. I have never said SNR = 20*log(1/var).

Does that clarify?

Krishna
http://dsplog.blogspot.com


Subject: Question about SNR and noise

From: Hugo Human

Date: 9 Sep, 2007 20:06:10

Message: 5 of 25

 Krishna <krishna.pillai@gmail.com> wrote in message
<1189349793.885183.96240@57g2000hsv.googlegroups.com>...
> On Sep 9, 2:26 am, "Hugo Human" <s24093...@hotmail.com>
wrote:
>
> > I have never seen this :
> > > noise = 10^(-snrdB/20)*randn(size(sig));
> >
> > As far as I know it's
> > noise = 10^(-snrdB/10)*randn(size(sig));
> > because
> > SNR = 10*log(1/var);
>
> I do not disagree to the SNR = 10*log(1/var);. However,
note that am
> scaling a noise voltage signal (and not the
> power signal). Hence the 10^(-snrdB/20) for scaling.
>
> > But what I want to know is, because your signal's
power is
> > 0.5, how does this influence your equation....
>
> No. Note that I have used a scaling factor of sqrt(2).
Hence the
> signal power approx=1 (0dB).
>
> > Is this why you use
> > SNR = 20*log(1/var);
> > ????
> No. I have never said SNR = 20*log(1/var).
>
> Does that clarify?
>
> Krishna
> http://dsplog.blogspot.com
>
>

Not really ...
Let's use an example... plz.
If I have a signal:
x = 1*exp(i*2*pi*freq1*t + phase1); % in volts

Now, how do I add noise to this signal ???
The power of a sinusoid like this is 0.5, right ???
Should SNR = 10*log(1/var) OR
SNR = 10*log(0.5/var)
or how ?
Basically, how do I now scale the randn values for
different SNRs for a sinusoid with a 1 volt amplitude
(power = 0.5, I think ?)?

Subject: Question about SNR and noise

From: Greg Heath

Date: 9 Sep, 2007 22:50:37

Message: 6 of 25

On Sep 3, 7:01 am, "Giovanna " <giovanna.casti...@jku.at> wrote:
> Hi everybody
> I need to add a noise signal to my output signal. The noise
> characteristic are 10dB.

Does that mean the signal-to-noise ratio is 10dB?

> I dont have the Communication
> Toolbox and therefore, I cant use wgn, o awgn function.
> How I could generate the Gaussian White noise with this
> characteristics.
> If someone have an idea, please let me know.
> Cheers

%%%%%%%%%%%%%% Analysis

m = s + n; % Measured signal
<n> = 0;
<n.*n> = Pn % Noise power
<n.*s> = 0;

s = s0 + s1;
<s> = s0; % Signal mean
<s1> = 0;
<s0.*s1> = 0; % Assumption (Ergodicity?)

<s0.*s0> = Ps0; % DC signal power
<s1.*s1> = Ps1 % = var(s); Signal variance
Ps = <s.*s> = Ps0 + Ps1 % Signal Power

SNR = (Ps/Pn); % Signal-to-noise ratio
SNRdB = 10*log10(SNR)

%%%%%%%%%%%%%% Synthesis

SNR = 10^(SNRdB/10)
Pn = Ps/SNR

m = s + sqrt(Ps/SNR)*randn(size(s))

Hope this helps.

Greg

Subject: Question about SNR and noise

From: Krishna

Date: 10 Sep, 2007 02:36:02

Message: 7 of 25

On Sep 10, 1:06 am, "Hugo Human" <s24093...@hotmail.com> wrote:
> Not really ...
> Let's use an example... plz.
> If I have a signal:
> x = 1*exp(i*2*pi*freq1*t + phase1); % in volts
>
> Now, how do I add noise to this signal ???
> The power of a sinusoid like this is 0.5, right ???

No. The power of the complex sinusoidal which you stated above is 1
(and not 0.5). A quick check
trying to plug in some numbers:
x = 1*exp(i*2*pi*2*[0:1/100:1]+0);
xPower = x*x'/length(x);
xPower =

     1

> Should SNR = 10*log(1/var) OR
> SNR = 10*log(0.5/var)
> or how ?

Based on your signal power, you can scale your noise power. For the
complex exponential, I think the former
SNR = 10*log(1/var) is pertinent.

HTH,
Krishna
http://dsplog.blogspot.com

Subject: Question about SNR and noise

From: Hugo Human

Date: 10 Sep, 2007 12:39:47

Message: 8 of 25

 Krishna <krishna.pillai@gmail.com> wrote in message
<1189391762.667749.208030@50g2000hsm.googlegroups.com>...
> On Sep 10, 1:06 am, "Hugo Human" <s24093...@hotmail.com>
wrote:
> > Not really ...
> > Let's use an example... plz.
> > If I have a signal:
> > x = 1*exp(i*2*pi*freq1*t + phase1); % in volts
> >
> > Now, how do I add noise to this signal ???
> > The power of a sinusoid like this is 0.5, right ???
>
> No. The power of the complex sinusoidal which you stated
above is 1
> (and not 0.5). A quick check
> trying to plug in some numbers:
> x = 1*exp(i*2*pi*2*[0:1/100:1]+0);
> xPower = x*x'/length(x);
> xPower =
>
> 1
>
> > Should SNR = 10*log(1/var) OR
> > SNR = 10*log(0.5/var)
> > or how ?
>
> Based on your signal power, you can scale your noise
power. For the
> complex exponential, I think the former
> SNR = 10*log(1/var) is pertinent.
>
> HTH,
> Krishna
> http://dsplog.blogspot.com
>

First of ... Thanks for all your help this far ^_^

Second: This "scaling" factor (noise std, sqrt(var)), how
do I scale this with the signal power of 1, and then add
this to the signal for different SNRs... what I mean is

SNR = 10; % dB
x = 1*exp(i*2*pi*f*[0:1/100:1]+0); % Signal with power 1
noise_var = 10^(-SNR/10);
noise_std = sqrt(noise_var)
awgn = randn(1,N)*noise_std;

Do I now go :
x = x + awgn;
OR
x = x + (awgn/sqrt(2));
???
I see some people add the sqrt(2), I don't know what
that's for ???

Subject: Question about SNR and noise

From: Randy Poe

Date: 10 Sep, 2007 13:28:31

Message: 9 of 25

On Sep 10, 8:39 am, "Hugo Human" <s24093...@hotmail.com> wrote:
> Krishna <krishna.pil...@gmail.com> wrote in message
>
> <1189391762.667749.208...@50g2000hsm.googlegroups.com>...
>
>
>
> > On Sep 10, 1:06 am, "Hugo Human" <s24093...@hotmail.com>
> wrote:
> > > Not really ...
> > > Let's use an example... plz.
> > > If I have a signal:
> > > x = 1*exp(i*2*pi*freq1*t + phase1); % in volts
>
> > > Now, how do I add noise to this signal ???
> > > The power of a sinusoid like this is 0.5, right ???
>
> > No. The power of the complex sinusoidal which you stated
> above is 1
> > (and not 0.5). A quick check
> > trying to plug in some numbers:
> > x = 1*exp(i*2*pi*2*[0:1/100:1]+0);
> > xPower = x*x'/length(x);
> > xPower =
>
> > 1
>
> > > Should SNR = 10*log(1/var) OR
> > > SNR = 10*log(0.5/var)
> > > or how ?
>
> > Based on your signal power, you can scale your noise
> power. For the
> > complex exponential, I think the former
> > SNR = 10*log(1/var) is pertinent.
>
> > HTH,
> > Krishna
> >http://dsplog.blogspot.com
>
> First of ... Thanks for all your help this far ^_^
>
> Second: This "scaling" factor (noise std, sqrt(var)), how
> do I scale this with the signal power of 1, and then add
> this to the signal for different SNRs... what I mean is

I may have missed it, but I don't see anyone using complex
AWGN to add to your signal.

  N = n0 * complex( randn(m,1), randn(m,1) );

will give you m samples of complex white gaussian noise
of power 2*n0^2.

> SNR = 10; % dB
> x = 1*exp(i*2*pi*f*[0:1/100:1]+0); % Signal with power 1
> noise_var = 10^(-SNR/10);
> noise_std = sqrt(noise_var)
> awgn = randn(1,N)*noise_std;

So I would use

awgn = complex( randn(1, N), randn(1, N) ) * noise_std/sqrt(2);

> Do I now go :
> x = x + awgn;

Yes.

But the awgn above is pure real, and the imaginary
component of your signal will be noise-free.

> OR
> x = x + (awgn/sqrt(2));
> ???
> I see some people add the sqrt(2), I don't know what
> that's for ???

If you saw it, it is because some people (unlike what I said)
were indeed using complex noise, which is a sum of two
independent noise processes, one real and one imaginary,
each of which has power noise_var. So the total noise
power is 2*noise_var. The sqrt(2) divides the power of
each of these two noise channels in half, so that their
total is the desired noise power.

                - Randy

Subject: Question about SNR and noise

From: Hugo Human

Date: 10 Sep, 2007 14:05:35

Message: 10 of 25

 Randy Poe <poespam-trap@yahoo.com> wrote in message
<1189430911.786415.145550@g4g2000hsf.googlegroups.com>...
> On Sep 10, 8:39 am, "Hugo Human" <s24093...@hotmail.com>
wrote:
> > Krishna <krishna.pil...@gmail.com> wrote in message
> >
> >
<1189391762.667749.208...@50g2000hsm.googlegroups.com>...
> >
> >
> >
> > > On Sep 10, 1:06 am, "Hugo Human"
<s24093...@hotmail.com>
> > wrote:
> > > > Not really ...
> > > > Let's use an example... plz.
> > > > If I have a signal:
> > > > x = 1*exp(i*2*pi*freq1*t + phase1); % in volts
> >
> > > > Now, how do I add noise to this signal ???
> > > > The power of a sinusoid like this is 0.5, right ???
> >
> > > No. The power of the complex sinusoidal which you
stated
> > above is 1
> > > (and not 0.5). A quick check
> > > trying to plug in some numbers:
> > > x = 1*exp(i*2*pi*2*[0:1/100:1]+0);
> > > xPower = x*x'/length(x);
> > > xPower =
> >
> > > 1
> >
> > > > Should SNR = 10*log(1/var) OR
> > > > SNR = 10*log(0.5/var)
> > > > or how ?
> >
> > > Based on your signal power, you can scale your noise
> > power. For the
> > > complex exponential, I think the former
> > > SNR = 10*log(1/var) is pertinent.
> >
> > > HTH,
> > > Krishna
> > >http://dsplog.blogspot.com
> >
> > First of ... Thanks for all your help this far ^_^
> >
> > Second: This "scaling" factor (noise std, sqrt(var)),
how
> > do I scale this with the signal power of 1, and then
add
> > this to the signal for different SNRs... what I mean is
>
> I may have missed it, but I don't see anyone using
complex
> AWGN to add to your signal.
>
> N = n0 * complex( randn(m,1), randn(m,1) );
>
> will give you m samples of complex white gaussian noise
> of power 2*n0^2.
>
> > SNR = 10; % dB
> > x = 1*exp(i*2*pi*f*[0:1/100:1]+0); % Signal with power
1
> > noise_var = 10^(-SNR/10);
> > noise_std = sqrt(noise_var)
> > awgn = randn(1,N)*noise_std;
>
> So I would use
>
> awgn = complex( randn(1, N), randn(1, N) ) *
noise_std/sqrt(2);
>
> > Do I now go :
> > x = x + awgn;
>
> Yes.
>
> But the awgn above is pure real, and the imaginary
> component of your signal will be noise-free.
>
> > OR
> > x = x + (awgn/sqrt(2));
> > ???
> > I see some people add the sqrt(2), I don't know what
> > that's for ???
>
> If you saw it, it is because some people (unlike what I
said)
> were indeed using complex noise, which is a sum of two
> independent noise processes, one real and one imaginary,
> each of which has power noise_var. So the total noise
> power is 2*noise_var. The sqrt(2) divides the power of
> each of these two noise channels in half, so that their
> total is the desired noise power.
>
> - Randy
>


Omg, what a stupid mistake !!! Sorry, I didn't even think
of the imaginary parts ! I kninda forgot. Sorry, i'm still
new with this.

Thanks for your help ^_^

Subject: Question about SNR and noise

From: Hugo Human

Date: 10 Sep, 2007 15:32:45

Message: 11 of 25

Just a quick question...

If I now use a sine wave instead of an exp one, would the
following be true ?

x = 1*sin(2*pi*2*[1:0.1:1000] + 0);

Power of sine wave = 0.5
Thus,

var = 10^(-Es_over_N0/20); % NOTE :It's over 20 now...
std_noise = sqrt(var);

awgn = randn(1,N)*std_noise; % NOTE :Not devided by sqrt(2)

signal = x + awgn;

????
Is my assumptions now correct ?

Subject: Question about SNR and noise

From: Krishna

Date: 11 Sep, 2007 02:39:09

Message: 12 of 25

On Sep 10, 8:32 pm, "Hugo Human" <s24093...@hotmail.com> wrote:
> Just a quick question...
>
> If I now use a sine wave instead of an exp one, would the
> following be true ?
>
> x = 1*sin(2*pi*2*[1:0.1:1000] + 0);
>
> Power of sine wave = 0.5
> Thus,

OK. power of signal in dB = 10*log10(0.5) = -3dB

> var = 10^(-Es_over_N0/20); % NOTE :It's over 20 now...

No. Keep var = 10^(-Es_over_N0/10);

> std_noise = sqrt(var);

Ok

> awgn = randn(1,N)*std_noise; % NOTE :Not devided by sqrt(2)

No. awgn = (1/sqrt(2))*randn(1,N)*std_noise;
this 1/sqrt(2) factor is scale noise power further by -3dB (as the
signal power is -3dB).
The noise power = -Es_over_N0 + -3dB. For example, if Es_over_N0 =
10dB, the signal power is -3dB
and noise power = -10+-3 = -13dB.

noise power in dB = 10*log10(awgn*awgn'/length(awgn))

> signal = x + awgn;
>
> ????
> Is my assumptions now correct ?

HTH,
Krishna
http://dsplog.blogspot.com

Subject: Question about SNR and noise

From: Hugo Human

Date: 11 Sep, 2007 10:29:08

Message: 13 of 25

 Krishna <krishna.pillai@gmail.com> wrote in message
<1189478349.973402.286010@k79g2000hse.googlegroups.com>...
> On Sep 10, 8:32 pm, "Hugo Human" <s24093...@hotmail.com>
wrote:
> > Just a quick question...
> >
> > If I now use a sine wave instead of an exp one, would
the
> > following be true ?
> >
> > x = 1*sin(2*pi*2*[1:0.1:1000] + 0);
> >
> > Power of sine wave = 0.5
> > Thus,
>
> OK. power of signal in dB = 10*log10(0.5) = -3dB

OK...

>
> > var = 10^(-Es_over_N0/20); % NOTE :It's over 20 now...
>
> No. Keep var = 10^(-Es_over_N0/10);


OK...

>
> > std_noise = sqrt(var);
>
> Ok
>
> > awgn = randn(1,N)*std_noise; % NOTE :Not devided by
sqrt(2)
>
> No. awgn = (1/sqrt(2))*randn(1,N)*std_noise;
> this 1/sqrt(2) factor is scale noise power further by -
3dB (as the
> signal power is -3dB).


I don't get this part. Why scale the noise by a further -3
dB. And what has this got to do with the -3dB of the
signal? What if the signal power was not -3dB, due to a
different amplitude? is this 1/sqrt(2) (isn't this like -
3.5dB ???) the power of the signal ?


> The noise power = -Es_over_N0 + -3dB. For example, if
Es_over_N0 =
> 10dB, the signal power is -3dB
> and noise power = -10+-3 = -13dB.
>
> noise power in dB = 10*log10(awgn*awgn'/length(awgn))
>
> > signal = x + awgn;
>
> HTH,
> Krishna
> http://dsplog.blogspot.com
>

How can I now test if the noise I created is actualy with
i.e. a SNR = -20

I tried
xPower = x*x'/length(x);
aPower = awgn*awgn'/length(awgn);
SNR or Es_over_N0 = 10*log10(xPower/aPower);
Correct ?

Subject: Question about SNR and noise

From: Hugo Human

Date: 11 Sep, 2007 10:50:53

Message: 14 of 25

I'm currently using this to "test" the SNR... Is this
O.K ? Do you see any errors ?


N = 131;
SNR = -29;
noise_var = 10^(-SNR/10);
noise_std = sqrt(noise_var);
awgn1 = noise_std/sqrt(2)*randn(1,N+1);
t = 0:100*(10^-9)/N:100*(10^-9); % set the amount of
samples in 100ns
x = 1*sin(2*pi*(0.42*10^9)*t + 0);
xPower = x*x'/length(x)
aPower = awgn1*awgn1'/length(awgn1)
SNR = 10*log10(xPower/aPower)

It seems to be giving the correct answers...

Subject: Question about SNR and noise

From: Hugo Human

Date: 11 Sep, 2007 11:12:49

Message: 15 of 25

N = 131;
SNR = -29;
t = 0:100*(10^-9)/N:100*(10^-9); % set the amount of
samples in 100ns
x = 1*sin(2*pi*(0.42*10^9)*t + 0) + 0.4*sin(2*pi*
(0.22*10^9)*t + 0);

xPower = x*x'/length(x)
% What the power should be for given SNR and meaused
signal;
aPower = xPower/(10^(SNR/10))

% Variance, given power of signal, and calculated noise
power
noise_var = 10^(-10*log10(xPower/aPower)/10);
noise_std = sqrt(noise_var);
awgn1 = noise_std/sqrt(2)*randn(1,N+1);

% Measured values
measured_aPower = awgn1*awgn1'/length(awgn1)
SNR = 10*log10(xPower/measured_aPower)



Also correct????

Subject: Question about SNR and noise

From: Hugo Human

Date: 11 Sep, 2007 14:18:38

Message: 16 of 25

> > awgn = randn(1,N)*std_noise; % NOTE :Not devided by
sqrt(2)
>
> No. awgn = (1/sqrt(2))*randn(1,N)*std_noise;
> this 1/sqrt(2) factor is scale noise power further by -
3dB (as the
> signal power is -3dB).
> The noise power = -Es_over_N0 + -3dB. For example, if
Es_over_N0 =
> 10dB, the signal power is -3dB
> and noise power = -10+-3 = -13dB.
>
> noise power in dB = 10*log10(awgn*awgn'/length(awgn))

> HTH,
> Krishna
> http://dsplog.blogspot.com
>

What I can understand from this is that you can do the
following :
    SNR = -10;
    N = 131;
    t = 0:100*(10^-9)/N:100*(10^-9); % set the amount of
samples in 100ns
    x = 1*sin(2*pi*(0.42*10^9)*t + 0) + 0.4*sin(2*pi*
(0.22*10^9)*t + 0);
    xPower = x*x'/length(x); % Signal power
    aPower = - SNR + 10*log10(xPower); % ????????????????
    aPower = aPower/(10^(SNR/10)); % ???????????????
    noise_var = 10^(-10*log10(xPower/aPower)/10);
    noise_std = sqrt(noise_var);
    awgn1 = noise_std/sqrt(2)*randn(1,N+1);
    measured_aPower = awgn1*awgn1'/length(awgn1);
    SNR = 10*log10(xPower/measured_aPower);

Which I think is wrong.... I think it should be something
like this:

    SNR = -10;
    N = 131;
    t = 0:100*(10^-9)/N:100*(10^-9); % set the amount of
samples in 100ns
    x = 1*sin(2*pi*(0.42*10^9)*t + 0) + 0.4*sin(2*pi*
(0.22*10^9)*t + 0);
    xPower = x*x'/length(x); % Signal power
    aPower = xPower/(10^(SNR/10)); % !!!!!!!!!!!!!
    noise_var = 10^(-10*log10(xPower/aPower)/10);
    noise_std = sqrt(noise_var);
    awgn1 = noise_std/sqrt(2)*randn(1,N+1);
    measured_aPower = awgn1*awgn1'/length(awgn1);
    SNR = 10*log10(xPower/measured_aPower);

NOTE: Note that I am using 2 simulanios signals... Will
this change the 1/sqrt(2)???

If I do this for about 10000 times, and plot a histogram,
it centers around -9.5dB, and not 10dB...

For some reason it's always 0.5 dB out... Why ?
It's corrects itself when you just simply say SNR = SNR -
0.5; But I don't wanna do this
The standard deviation is 0.5
    aPower = aPower/(10^(SNR/10));

Help would be appreciated...

Subject: Question about SNR and noise

From: Hugo Human

Date: 11 Sep, 2007 14:37:06

Message: 17 of 25

I think I finally figure it out ... OR NOT ???? Can
someone tell me if this code is correct ???

Ignore the other posts !!!!!!
Note the different amplitudes...

SNR_tot = [];
ampl1 = 8;
ampl2 = 3;
ampl_tot = sqrt(ampl1^2+ ampl2^2);
for a = 1:1:10000
    N = 131;
    SNR = -10;
    t = 0:100*(10^-9)/N:100*(10^-9); % set the amount of
samples in 100ns
    x = ampl1*sin(2*pi*(0.45*10^9)*t + 0) + ampl2*sin(2*pi*
(0.12*10^9)*t + 0);
    
    xPower = x*x'/length(x);
    % What the power should be for given SNR and meaused
signal;
    aPower = xPower/(10^(SNR/10)); What the noise power
should be for the given SNR
    % Variance, given power of signal, and calculated
noise power
    noise_var = 10^(-(10*log10(xPower/aPower))/10);
    noise_std = sqrt(noise_var);
    awgn1 = noise_std*ampl_tot/sqrt(2)*randn(1,N+1); %
Note the use of ampl_tot
    
    % Measured values
    measured_aPower = awgn1*awgn1'/length(awgn1);
    SNR = 10*log10(xPower/measured_aPower);
    SNR_tot = [SNR_tot SNR];
end

std(SNR_tot)
hist(SNR_tot);

Subject: Question about SNR and noise

From: Greg Heath

Date: 12 Sep, 2007 13:48:03

Message: 18 of 25

On Sep 11, 10:37 am, "Hugo Human" <s24093...@hotmail.com> wrote:
> I think I finally figure it out ... OR NOT ???? Can
> someone tell me if this code is correct ???

See comments and error corrections below.

> SNR_tot = [];
> ampl1 = 8;
> ampl2 = 3;
> ampl_tot = sqrt(ampl1^2+ ampl2^2);

INCORRECT. The two sine terms are not orthogonal.
Obtain max(x) and min(x) below.

> for a = 1:1:10000

Use i,j,k,m, or n for integer loop indices

> N = 131;
> SNR = -10;

SNR = +10 ?

Better to use the notation

SNRdB = 10
SNR = 10^(SNRdB/10)

> t = 0:100*(10^-9)/N:100*(10^-9); % set the amount of
> samples in 100ns

N, dt, and max(t) not compatible

t = dt*(0:N-1);
max(t) = (N-1)*dt

> x = ampl1*sin(2*pi*(0.45*10^9)*t + 0) + ampl2*sin(2*pi*
> (0.12*10^9)*t + 0);

Better to assign values to parameters. Then use parameters in
command expressions.

Could add random phases 2*pi*rand to both terms.

> xPower = x*x'/length(x);
> % What the power should be for given SNR and meaused
> signal;
> aPower = xPower/(10^(SNR/10)); What the noise power
> should be for the given SNR
> % Variance, given power of signal, and calculated
> noise power
> noise_var = 10^(-(10*log10(xPower/aPower))/10);

Doesn't look correct.

> noise_std = sqrt(noise_var);
> awgn1 = noise_std*ampl_tot/sqrt(2)*randn(1,N+1); %
> Note the use of ampl_tot

INCORRECT

> % Measured values
> measured_aPower = awgn1*awgn1'/length(awgn1);
> SNR = 10*log10(xPower/measured_aPower);
> SNR_tot = [SNR_tot SNR];
> end
>
> std(SNR_tot)
> hist(SNR_tot);

See my two posts.

Hope this helps.

Greg

Subject: Question about SNR and noise

From: Greg Heath

Date: 12 Sep, 2007 13:55:57

Message: 19 of 25

On Sep 9, 6:50 pm, Greg Heath <he...@alumni.brown.edu> wrote:
> On Sep 3, 7:01 am, "Giovanna " <giovanna.casti...@jku.at> wrote:
>
> > Hi everybody
> > I need to add a noise signal to my output signal. The noise
> > characteristic are 10dB.
>
> Does that mean the signal-to-noise ratio is 10dB?
>
> > I dont have the Communication
> > Toolbox and therefore, I cant use wgn, o awgn function.
> > How I could generate the Gaussian White noise with this
> > characteristics.
> > If someone have an idea, please let me know.
> > Cheers
>
> %%%%%%%%%%%%%% Analysis
>
> m = s + n; % Measured signal
> <n> = 0;
> <n.*n> = Pn % Noise power
> <n.*s> = 0;
>
> s = s0 + s1;
> <s> = s0; % Signal mean
> <s1> = 0;
> <s0.*s1> = 0; % Assumption (Ergodicity?)
>
> <s0.*s0> = Ps0; % DC signal power
> <s1.*s1> = Ps1 % = var(s); Signal variance
> Ps = <s.*s> = Ps0 + Ps1 % Signal Power
>
> SNR = (Ps/Pn); % Signal-to-noise ratio
> SNRdB = 10*log10(SNR)
>
> %%%%%%%%%%%%%% Synthesis
>
> SNR = 10^(SNRdB/10)
> Pn = Ps/SNR
>
> m = s + sqrt(Ps/SNR)*randn(size(s))

Example:

%2345678901234567890123456789012345678901234567890123456789012

% Google only allows line lengths of 62. Use shorter lines to
% mitigate wrapping of replies.

close all, clear, clc, k = 0
state0 = 0
randn('state',state0)
rand('state',state0) % For random phase option

tmax = 1e-7 % 100 ns
N = 132 %
dt = tmax/(N-1) % 7.6336e-010
t = dt*(0:N-1);

a1 = 8, f1 = 45e7 % tmax = 45 periods
a2 = 3, f2 = 12e7 % tmax = 12 periods

x = a1*sin(2*pi*f1*t) + a2*sin(2*pi*f2*t);

k=k+1, figure(k)
hold on
plot(t,x)
plot(t,zeros(size(t)), 'k')
hold off
legend('Signal')
xlabel('Time')
ylabel('Magnitude')

meanx = mean(x) % -4.6374e-015
varx = var(x) % 36.5
stdx = std(x) % 6.0415
maxx = max(x) % 10.9820 <== NOTE!
minx = min(x) % -10.9820

xpower = meanx^2 + ((N-1)/N)*varx % 36.2235
xpower = x*x'/N % 36.2235

SNRdB0 = 10
SNR0 = 10^(SNRdB0/10) % 10
npower0 = xpower/SNR0 % 3.6223
an0 = sqrt(npower0) % 1.9032

ntrials = 1e4
SNRdB = zeros(1,ntrials);

for i = 1:ntrials
    noise = an0*randn(1,N);
    npower = noise*noise'/N
    SNR = xpower/npower
    SNRdB(i) = 10*log10(SNR);
end

minSNRdB = min(SNRdB) % 8.1835
medianSNRdB = median(SNRdB) % 10.0211
meanSNRdB = mean(SNRdB) % 10.0356
stdSNRdB = std(SNRdB) % 0.5336
maxSNRdB = max(SNRdB) % 12.1494

k=k+1, figure(k)
hold on
plot(t,x)
plot(t,x+noise,'r')
plot(t,zeros(size(t)), 'k')
hold off
xlabel('Time')
ylabel('Magnitude')
legend('Signal','Signal+Noise')

k=k+1, figure(k)
bar(hist(SNRdB,20)/ntrials)
legend('SNRdB0 = ',num2str(SNRdB0))
xlabel('SNRdB')
ylabel('Probability')

for j=k:-1:1
   figure(j)
end

Hope this helps.

Greg


Subject: Question about SNR and noise

From: Hugo Human

Date: 14 Sep, 2007 21:37:25

Message: 20 of 25

 Greg Heath <heath@alumni.brown.edu> wrote in message
<1189605357.644931.297130@r29g2000hsg.googlegroups.com>...
> On Sep 9, 6:50 pm, Greg Heath <he...@alumni.brown.edu>
wrote:
> > On Sep 3, 7:01 am, "Giovanna "
<giovanna.casti...@jku.at> wrote:
> >
> > > Hi everybody
> > > I need to add a noise signal to my output signal.
The noise
> > > characteristic are 10dB.
> >
> > Does that mean the signal-to-noise ratio is 10dB?
> >
> > > I dont have the Communication
> > > Toolbox and therefore, I cant use wgn, o awgn
function.
> > > How I could generate the Gaussian White noise with
this
> > > characteristics.
> > > If someone have an idea, please let me know.
> > > Cheers
> >
> > %%%%%%%%%%%%%% Analysis
> >
> > m = s + n; % Measured signal
> > <n> = 0;
> > <n.*n> = Pn % Noise power
> > <n.*s> = 0;
> >
> > s = s0 + s1;
> > <s> = s0; % Signal mean
> > <s1> = 0;
> > <s0.*s1> = 0; % Assumption
(Ergodicity?)
> >
> > <s0.*s0> = Ps0; % DC signal power
> > <s1.*s1> = Ps1 % = var(s); Signal
variance
> > Ps = <s.*s> = Ps0 + Ps1 % Signal Power
> >
> > SNR = (Ps/Pn); % Signal-to-noise
ratio
> > SNRdB = 10*log10(SNR)
> >
> > %%%%%%%%%%%%%% Synthesis
> >
> > SNR = 10^(SNRdB/10)
> > Pn = Ps/SNR
> >
> > m = s + sqrt(Ps/SNR)*randn(size(s))
>
> Example:
>
> %
23456789012345678901234567890123456789012345678901234567890
12
>
> % Google only allows line lengths of 62. Use shorter
lines to
> % mitigate wrapping of replies.
>
> close all, clear, clc, k = 0
> state0 = 0
> randn('state',state0)
> rand('state',state0) % For random phase
option
>
> tmax = 1e-7 % 100 ns
> N = 132 %
> dt = tmax/(N-1) % 7.6336e-010
> t = dt*(0:N-1);
>
> a1 = 8, f1 = 45e7 % tmax = 45 periods
> a2 = 3, f2 = 12e7 % tmax = 12 periods
>
> x = a1*sin(2*pi*f1*t) + a2*sin(2*pi*f2*t);
>
> k=k+1, figure(k)
> hold on
> plot(t,x)
> plot(t,zeros(size(t)), 'k')
> hold off
> legend('Signal')
> xlabel('Time')
> ylabel('Magnitude')
>
> meanx = mean(x) % -4.6374e-015
> varx = var(x) % 36.5
> stdx = std(x) % 6.0415
> maxx = max(x) % 10.9820 <== NOTE!
> minx = min(x) % -10.9820
>
> xpower = meanx^2 + ((N-1)/N)*varx % 36.2235
> xpower = x*x'/N %
36.2235
>
> SNRdB0 = 10
> SNR0 = 10^(SNRdB0/10) % 10
> npower0 = xpower/SNR0 % 3.6223
> an0 = sqrt(npower0) % 1.9032
>
> ntrials = 1e4
> SNRdB = zeros(1,ntrials);
>
> for i = 1:ntrials
> noise = an0*randn(1,N);
> npower = noise*noise'/N
> SNR = xpower/npower
> SNRdB(i) = 10*log10(SNR);
> end
>
> minSNRdB = min(SNRdB) % 8.1835
> medianSNRdB = median(SNRdB) % 10.0211
> meanSNRdB = mean(SNRdB) % 10.0356
> stdSNRdB = std(SNRdB) % 0.5336
> maxSNRdB = max(SNRdB) % 12.1494
>
> k=k+1, figure(k)
> hold on
> plot(t,x)
> plot(t,x+noise,'r')
> plot(t,zeros(size(t)), 'k')
> hold off
> xlabel('Time')
> ylabel('Magnitude')
> legend('Signal','Signal+Noise')
>
> k=k+1, figure(k)
> bar(hist(SNRdB,20)/ntrials)
> legend('SNRdB0 = ',num2str(SNRdB0))
> xlabel('SNRdB')
> ylabel('Probability')
>
> for j=k:-1:1
> figure(j)
> end
>
> Hope this helps.
>
> Greg
>
>


Ahhh.... ok, I c. But why do I get fairly acrate results
then? My mean of my SNR is also acurate, as well as the
std and the median ?

Subject: Question about SNR and noise

From: Hugo Human

Date: 14 Sep, 2007 21:45:13

Message: 21 of 25

Sorry for double posting...

Can you please just explaine why this step ?

an0 = sqrt(npower0) % 1.9032

Subject: Question about SNR and noise

From: Luis campos

Date: 23 Nov, 2007 02:52:46

Message: 22 of 25

Hi folks, just a simple question that is doing my
heading...

Assuming amplitude is 1, hence signal power = 0.5


a)generate and plot 100 points of a 5Hz sinusoid sampled
at 50Hz contaminated with zero-mean UNIFORM noise with SNR
of 5

b)generate and plot 100 points of a 5Hz sinusoid sampled
at 50Hz contaminated with zero-mean GAUSSIAN noise with
SNR of 1

THANKS A LOT FOR YOUR HELP

Subject: Question about SNR and noise

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 23 Nov, 2007 04:18:10

Message: 23 of 25

In article <fi5f9u$p0b$1@fred.mathworks.com>,
Luis campos <lfaeac@hotmail.com> wrote:

>Assuming amplitude is 1, hence signal power = 0.5

>a)generate and plot 100 points of a 5Hz sinusoid sampled
>at 50Hz contaminated with zero-mean UNIFORM noise with SNR
>of 5

The hard part of this is figuring out how to generate the sine
properly. 5 Hz sampled at 50 Hz, so every 10th point will be
the same. If T is the pure sinewave, is it T(99) that is the
final return to 0, or T(100), or T(101) ?

Hint: linspace().


zero-mean Uniform noise of maximum amplitude S is S*(rand() * 2 - 1)

The '* 2 - 1' portion converts the random range of 0 to 1 into -1 to 1
--
   "Any sufficiently advanced bug is indistinguishable from a feature."
   -- Rich Kulawiec

Subject: Question about SNR and noise

From: Luis campos

Date: 25 Nov, 2007 21:19:13

Message: 24 of 25

Hi lads

Can someone help with this question please ??
Thank you very much for your help

Central Limit Theorem

One of the reasons the Gaussian pdf is so pervasive in
modelling noise in digital communication systems is
because of the Central Limit Theorem. Investigate this
theorem and provide a concise definition in no more than
30 words. Explain how this may be useful when analysing
digital communication systems. Using the statistical and
random functions available in MATLAB design an experiment
that approximates the central limit theorem.

Subject: Question about SNR and noise

From: Mathuranathan Viswanathan

Date: 2 Feb, 2010 10:00:22

Message: 25 of 25

"Luis campos" <lfaeac@hotmail.com> wrote in message <ficosg$qa5$1@fred.mathworks.com>...
> Hi lads
>
> Can someone help with this question please ??
> Thank you very much for your help
>
> Central Limit Theorem
>
> One of the reasons the Gaussian pdf is so pervasive in
> modelling noise in digital communication systems is
> because of the Central Limit Theorem. Investigate this
> theorem and provide a concise definition in no more than
> 30 words. Explain how this may be useful when analysing
> digital communication systems. Using the statistical and
> random functions available in MATLAB design an experiment
> that approximates the central limit theorem.
>
Hi
You can refer http://gaussianwaves.blogspot.com for simulating Central limit theorem in MATLAB.

Regards
Mathuranathan
http://gaussianwaves.blogspot.com

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com