matlab 中的广义高斯噪声发生器
我需要在 Matlab 中创建广义高斯噪声发生器。
GGN 是具有以下分布的随机信号 v
:
v ~ GN(mi, alfa, beta) :
p(v; mi, alfa, beta) = (beta/(2*alfa*gamma(1/beta))) * exp(-(abs(v - mi)/alfa).^beta )
其中 p 是计算值 v 的概率。
请注意,gamma
是在 Matlab 函数中内置的,用于计算 伽玛函数。
我试图通过以下方式创建生成器:
function gn = GN(dim1, dim2, mi, alfa, beta)
gn = zeros(dim1, dim2);
for i=1:dim1
for j=1:dim2
v = mi + 10*(alfa^2)* rand(1) - 5*(alfa^2);
prob = rand(1);
while(p(v, mi, alfa, beta) < prob)
v = mi + 10*alfa* rand(1) - 5*alfa;
prob = rand(1);
end
gn(i,j) = v;
end
end
function pval = p(v, mi, alfa, beta)
pval = (beta/(2*alfa*gamma(1/beta))) * exp(-(abs(v - mi)/alfa).^beta );
但循环似乎是无限的,出了问题。
另请注意,对于:beta = 2
该生成器应返回等于正态高斯分布的值,平均值 mi
和标准差 alfa^2/2
编辑 好的,道格给我指明了正确的方向。我们需要创建或多或少有可能被选择的 v
值(我假设 10* std 相当不错),然后检查概率条件。
为每个概率检查(在 while 循环中)绘制一个新的 prob
值也很重要。
所以问题是已解决
请注意,该生成器允许您生成:
- beta = 2
的高斯噪声 - beta = 1
的拉普拉斯(脉冲)噪声
I need to create Generalized Gaussian Noise generator in Matlab.
GGN is a random signal v
of following distribution:
v ~ GN(mi, alfa, beta) :
p(v; mi, alfa, beta) = (beta/(2*alfa*gamma(1/beta))) * exp(-(abs(v - mi)/alfa).^beta )
Where p is the probablility counted for value v.
Note, that gamma
is built in Matlab function that computes the value of Gamma function.
I was trying to create the generator in following way:
function gn = GN(dim1, dim2, mi, alfa, beta)
gn = zeros(dim1, dim2);
for i=1:dim1
for j=1:dim2
v = mi + 10*(alfa^2)* rand(1) - 5*(alfa^2);
prob = rand(1);
while(p(v, mi, alfa, beta) < prob)
v = mi + 10*alfa* rand(1) - 5*alfa;
prob = rand(1);
end
gn(i,j) = v;
end
end
function pval = p(v, mi, alfa, beta)
pval = (beta/(2*alfa*gamma(1/beta))) * exp(-(abs(v - mi)/alfa).^beta );
But the loop seems to be infinite, somethings wrong.
Note also, that for:beta = 2
this generator should return values equal to normal gaussian distribution with mean value mi
and standard deviation alfa^2/2
Edit
OK, Doug pointed me in the right direction. We need to create the v
value that is more or less probable to be selected (I assumed, that 10* std is quite good) and then check the probability condition.
It is also important to draw a new prob
value for each probability check (in while loop).
So the problem is SOLVED
Note, that this generator allows you to generate:
- Gaussian noise for beta = 2
- Laplasian (impulse) noise for beta = 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尝试过这个并且效果很好。请注意,我将随机阈值设置为有史以来最随机的数字 0.1([0 1] 中的有效选择)。 pval 必须大于 prob 才能被接受。
在我看来,当随机阈值接近 1 时,这只是一场很难中奖的彩票。请注意 pval 可能出现的数字。
它不是无限循环,只是您要求 MATLAB 多次选择随机数,直到您中奖为止!看起来有点像 Bogosort
I tried this and it worked fine. Note that I set the random threshold to the most random number ever, 0.1 (a valid choice from [0 1]). pval must be great than prob to be accepted.
It looks to me like this is just a hard lottery to win when the random threshold is close to 1. Notice the possible numbers that come out for pval.
It is not infinite loop, just that you are asking MATLAB to choose random numbers until you win the lottery, several times! Seems like a bit of a Bogosort