randn函数加噪声_正确增加信号噪声的方法

本文探讨了如何在MATLAB或Octave中正确生成和添加AWGN噪声,强调了awgn函数的作用,并解释了如何利用'measured'选项根据输入信号的功率计算合适的噪声功率级别。此外,还解释了不同类型的SNR单位和其对结果的影响。
摘要由CSDN通过智能技术生成

bd96500e110b49cbb3cd949968f18be7.png

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

解决方案

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.

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) %

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 %

np = p - snr;

endif

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

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.

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')

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.

As the documentation further explains

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.

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".

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.

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

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

where var(...,1) is the population variance for the noise y.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值