views:

834

answers:

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

+2  A: 

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.

>> GN(2,2,1,1,2)

prob =

    0.1000


pval =

    0.4738


prob =

    0.1000


pval =

    0.2674


prob =

    0.1000


pval =

    0.4885


prob =

    0.1000


pval =

    0.5473


ans =

    0.5821    0.1358
    0.6204    0.8254

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

MatlabDoug
thanks Doug, you pointed me into the right direction. The solution is to - before testing the probability - create random value that is more or less probable to be selected. Thanks!
Gacek

related questions