如何使用特定方差产生噪声 [英] How to generate noise using specific variance

查看:206
本文介绍了如何使用特定方差产生噪声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在用于向信号添加噪声的matlab函数awgn()中,是否可以指定方差?

In the matlab function awgn() that is used to add noise to a signal, is there a way specify the variance?

通常,我会简单地完成noisevec = sqrt(2)*randn(length(X),1);创建方差为2的噪声矢量.那么嘈杂的观察结果就是

In general, I would have simply done noisevec = sqrt(2)*randn(length(X),1); creates a noise vector of variance 2. Then the noisy observations are

Y = X+noisevec

但是,我想应用awgn(),然后检查噪声的方差是否确实是用户指定的.该怎么做?

But, I would like to apply awgn() and then check if the variance of noise is indeed as specified by the user. How to do that?

         % add noise to produce
         % an SNR of 10dB, use:
         X = sin(0:pi/8:6*pi);
         Y = awgn(X,10,'measured');

更新:根据解决方案,使用提供的答案/解决方案中提供的awgn()生成具有特定方差的噪声时以及不使用awgn()时,输出应相同.我的理解有问题吗?这是我检查的方式.

UPDATE : Based on the solution, the output should be same when generating noise with specific variance using the awgn() given in the answer/ solution provided and when using without awgn(). Is something wrong in my understanding? Here is how I checked.

x =  rand(1,10); $generating source input
snr =10;
variance = 0.1;
%This procedure is  based on the answer
y1 = awgn(x, snr, 'measured');
y1 = x + (y1 - x) * sqrt(variance / var(y1 - x));

%This is the traditional way, without using awgn()

 y2 = x+sqrt(variance)*randn(1,10);

y1不等于y2.我想知道为什么吗?

y1 is not equal to y2. I wonder why?

推荐答案

awgn不会产生具有特定方差的噪声.但是,如果必须生成具有特定方差的噪声,则可以考虑定义自己的噪声生成器,该噪声生成器可以简单地将噪声按比例放大或缩小至所需水平:

awgn does not generate a noise with a specific variance. But if you have to generate a noise with a specific variance, you may consider defining your own noise generator which could be simply scaling the noise up or down to the desired level:

function y = AddMyNoise(x, variance)
    y = awgn(x, 10, 'measured');
    y = x + (y - x) * sqrt(variance / var(y - x));
end

更新:请注意,这种强制输出具有特定方差的方法可能很危险::如果x元素很少,它将给出奇怪的输出.在x为标量的极限中,此方法将向x添加固定值+ -sqrt(variance).不再有白噪声.但是,如果您有多个数据点,则将得到相当大的白噪声.

UPDATE: Note that this method of forcing the output to have a specific variance could be dangerous: It will give strange outputs if x has few elements. In the limit of x being a scalar, this approach will add a fixed value of +-sqrt(variance) to x. No white noise anymore. But if you have more than a few data points, you will get a reasonably white noise.

这篇关于如何使用特定方差产生噪声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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