正确增加信号噪声的方法 [英] Proper way to add noise to signal

查看:944
本文介绍了正确增加信号噪声的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在许多领域,我发现在添加噪声的同时,我们提到了一些规格,例如零均值和方差.我需要添加AWGN,彩色噪声,Db中变化的SNR的均匀噪声.以下代码显示了如何生成和添加噪声的方式.我知道函数awgn(),但这是一种黑匣子,不知道如何添加噪音.因此,可以请有人解释产生和增加噪声的正确方法.谢谢

In many areas I have found that while adding noise, we mention some specification like zero mean and variance. I need to add AWGN, colored noise, uniform noise of varying SNR in Db. The following code shows the way how I generated and added noise. I am aware of the function awgn() but it is a kind of black box thing without knowing how the noise is getting added. So, can somebody please explain the correct way to generate and add noise. Thank you

SNR = [-10:5:30]; %in Db
snr = 10 .^ (0.1 .* SNR);

for I = 1:length(snr)
    noise = 1 / sqrt(2) * (randn(1, N) + 1i * randn(1, N));
    u = y + noise .* snr(I);
end

推荐答案

我添加了另一个答案,因为这让我感到惊讶,史蒂文(Steven's)不太正确,霍奇勒(Horchler)建议查看函数awgn是一个好方法.

I'm adding another answer since it strikes me that Steven's is not quite correct and Horchler's suggestion to look inside function awgn is a good one.

MATLAB或Octave(在通信工具箱中)具有函数awgn,该函数添加(高斯白噪声)噪声以获得所需的信噪比功率水平;以下是代码的相关部分(来自Octave函数):

Either MATLAB or Octave (in the communications toolbox) have a function awgn that adds (white Gaussian) noise to attain a desired signal-to-noise power level; the following is the relevant portion of the code (from the Octave function):

  if (meas == 1)  % <-- if using signal power to determine appropriate noise power
    p = sum( abs( x(:)) .^ 2) / length(x(:));
    if (strcmp(type,"dB"))
      p = 10 * log10(p);
    endif
  endif

  if (strcmp(type,"linear"))
    np = p / snr;
  else   % <-- in dB
    np = p - snr;
  endif

  y = x + wgn (m, n, np, 1, seed, type, out);

正如您通过计算p(输入数据的功效)所看到的那样,史蒂文的答案似乎不太正确.

As you can see by the way p (the power of the input data) is computed, the answer from Steven does not appear to be quite right.

您可以要求该函数计算数据阵列的总功率,并将其与您提供的所需s/n值相结合,以计算增加的​​噪声的适当功率水平.为此,您可以在可选输入之间传递字符串"measured"(例如,请参见此处).八度文档或此处(对于MATLAB文档):

You can ask the function to compute the total power of your data array and combine that with the desired s/n value you provide to compute the appropriate power level of the added noise. You do this by passing the string "measured" among the optional inputs, like this (see here for the Octave documentation or here for the MATLAB documentation):

     y = awgn (x, snr, 'measured')

这最终导致meas=1,因此meas==1在上面的代码中为true.然后,函数awgn使用传递给它的信号来计算信号功率,然后根据此信号和所需的信噪比(s/n)计算所添加噪声的适当功率电平.

This leads ultimately to meas=1 and so meas==1 being true in the code above. The function awgn then uses the signal passed to it to compute the signal power, and from this and the desired s/n it then computes the appropriate power level for the added noise.

文档进一步解释了

默认情况下,snr和pwr假定为dB和dBW 分别.可以选择默认行为,其类型设置为 D b".在将type设置为"linear"的情况下,假定pwr为 以瓦特和snr为单位的比率.

By default the snr and pwr are assumed to be in dB and dBW respectively. This default behavior can be chosen with type set to "dB". In the case where type is set to "linear", pwr is assumed to be in Watts and snr is a ratio.

这意味着您可以传递负或0 dB的snr值.然后,结果还将取决于您传递的其他选项,例如字符串"measured".

This means you can pass a negative or 0 dB snr value. The result will also depend then on other options you pass, such as the string "measured".

对于MATLAB情况,我建议阅读文档,其中介绍了如何使用该功能awgn在不同的情况下.请注意,Octave和MATLAB中的实现并不完全相同,噪声功率的计算应相同,但可能会有不同的选择.

For the MATLAB case I suggest reading the documentation, it explains how to use the function awgn in different scenarios. Note that implementations in Octave and MATLAB are not identical, the computation of noise power should be the same but there may be different options.

这是wgn的相关部分(在上面被awgn称为):

And here is the relevant part from wgn (called above by awgn):

  if (strcmp(type,"dBW"))
    np = 10 ^ (p/10);
  elseif (strcmp(type,"dBm"))
    np = 10 ^((p - 30)/10);
  elseif (strcmp(type,"linear"))
    np = p;
  endif

  if(!isempty(seed))
    randn("state",seed);
  endif

  if (strcmp(out,"complex"))
    y = (sqrt(imp*np/2))*(randn(m,n)+1i*randn(m,n)); % imp=1 assuming impedance is 1 Ohm
  else
    y = (sqrt(imp*np))*randn(m,n);
  endif

如果要检查噪声(np)的功率,则awgnawg函数假定以下关系成立:

If you want to check the power of your noise (np), the awgn and awg functions assume the following relationships hold:

  np = var(y,1);        % linear scale
  np = 10*log10(np);    % in dB 

其中,var(...,1)是噪声y人口方差.

这篇关于正确增加信号噪声的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆