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