Forums

matlab's raylrnd function

Started by KK October 30, 2004
Greetings,
  Consider the scalar complex random variable w ~ CN(0; 1) (CN is
complex normal distribution) has i.i.d. real and imaginary components
each distributed as N(0; 1/2). The magnitude of w is Rayleigh
distributed as follows
                     f(r)=r*exp(-r^2/2) r>=0
  I am trying to generate sequence of numbers which follow above
distribution using two approaches, viz, using envelope of CN & using
raylrnd function.
My question is why are the following sequences DO NOT have the same
statistics?

1. raylrnd(1,1,N)) 
2. abs(sqrt(0.5)*(randn(1,N)+j*randn(1,N)))

where N is a big number (say 100000).
I checked that the mean values of the above sequences do not match.
There is some obvious mistake I am doing ... I dont know what?
Any help is appreciated and critisms are well received.
Thanks.
-KK
KK wrote:
> 1. raylrnd(1,1,N)) > 2. abs(sqrt(0.5)*(randn(1,N)+j*randn(1,N))) > > where N is a big number (say 100000). > I checked that the mean values of the above sequences do not match. > There is some obvious mistake I am doing ... I dont know what? > Any help is appreciated and critisms are well received.
If you want to know how a Matlab function is implemented you can always try "type raylrnd", this shows the raylrnd.m file. Compare this with your implementation. Lars
"KK" <kewlkarun@yahoo.com> wrote in message
news:c8fd5039.0410301757.20fbd03d@posting.google.com...
> Greetings, > Consider the scalar complex random variable w ~ CN(0; 1) (CN is > complex normal distribution) has i.i.d. real and imaginary components > each distributed as N(0; 1/2). The magnitude of w is Rayleigh > distributed as follows > f(r)=r*exp(-r^2/2) r>=0 > I am trying to generate sequence of numbers which follow above > distribution using two approaches, viz, using envelope of CN & using > raylrnd function. > My question is why are the following sequences DO NOT have the same > statistics? > > 1. raylrnd(1,1,N)) > 2. abs(sqrt(0.5)*(randn(1,N)+j*randn(1,N))) > > where N is a big number (say 100000). > I checked that the mean values of the above sequences do not match. > There is some obvious mistake I am doing ... I dont know what? > Any help is appreciated and critisms are well received. > Thanks. > -KK
You might want to take the square root of the power of your complex noise rather than the abs value - also check that you haven't inadvertently defined j to be something other than square root of -1 before you generate the noise. I haven't got raylrnd() but env=sqrt(abs(randn(1,N)+i*randn(1,N)).^2/2) should do the job I hope. Best of luck - Mike
Lars Ljung <larslj@kthkth.se> wrote in message news:<F81hd.3027$up1.1668@text.news.blueyonder.co.uk>...
> KK wrote: > > 1. raylrnd(1,1,N)) > > 2. abs(sqrt(0.5)*(randn(1,N)+j*randn(1,N))) > > > > where N is a big number (say 100000). > > I checked that the mean values of the above sequences do not match. > > There is some obvious mistake I am doing ... I dont know what? > > Any help is appreciated and critisms are well received. > > If you want to know how a Matlab function is implemented you can always > try "type raylrnd", this shows the raylrnd.m file. Compare this with > your implementation. > > Lars
Greetings, I should have checked their implementation before. Raylrnd function implements "abs(randn(1,N)+j*randn(1,N))" for sigma =1 instead of abs(sqrt(0.5)*(randn(1,N)+j*randn(1,N))). I am not theoritically strong at this point, but I would suspect that it could be a bug. Wireless communications gurus - could you please comment who is correct? Regards, Karunakar
"Mike Yarwood" <mpyarwood@btopenworld.com> wrote in message news:<cm2va7$34f$1@sparta.btinternet.com>...
> "KK" <kewlkarun@yahoo.com> wrote in message > news:c8fd5039.0410301757.20fbd03d@posting.google.com... > > Greetings, > > Consider the scalar complex random variable w ~ CN(0; 1) (CN is > > complex normal distribution) has i.i.d. real and imaginary components > > each distributed as N(0; 1/2). The magnitude of w is Rayleigh > > distributed as follows > > f(r)=r*exp(-r^2/2) r>=0 > > I am trying to generate sequence of numbers which follow above > > distribution using two approaches, viz, using envelope of CN & using > > raylrnd function. > > My question is why are the following sequences DO NOT have the same > > statistics? > > > > 1. raylrnd(1,1,N)) > > 2. abs(sqrt(0.5)*(randn(1,N)+j*randn(1,N))) > > > > where N is a big number (say 100000). > > I checked that the mean values of the above sequences do not match. > > There is some obvious mistake I am doing ... I dont know what? > > Any help is appreciated and critisms are well received. > > Thanks. > > -KK > > You might want to take the square root of the power of your complex noise > rather than the abs value - also check that you haven't inadvertently > defined j to be something other than square root of -1 before you generate > the noise. I haven't got raylrnd() but > env=sqrt(abs(randn(1,N)+i*randn(1,N)).^2/2) should do the job I hope. > Best of luck - Mike
Hi, Square root of the power of the complex noise is its absolute value. I dont know why Mike introduced the factor 1/2 in the calculation of envelope. The matter is still unresolved for raylrnd function calculates b*sqrt(Xreal^2+Xim^2) where 'b' is the parameter as defined in raylrnd function and X is a sample of a complex normal distribution. Should not the factor be "b/sqrt(2)" instead of "b" in the above calculation? Thanks for your time, KK
"KK" <kewlkarun@yahoo.com> wrote in message
news:c8fd5039.0410311354.5327152e@posting.google.com...
> "Mike Yarwood" <mpyarwood@btopenworld.com> wrote in message
news:<cm2va7$34f$1@sparta.btinternet.com>...
> > "KK" <kewlkarun@yahoo.com> wrote in message > > news:c8fd5039.0410301757.20fbd03d@posting.google.com... > > > Greetings, > > > Consider the scalar complex random variable w ~ CN(0; 1) (CN is > > > complex normal distribution) has i.i.d. real and imaginary components > > > each distributed as N(0; 1/2). The magnitude of w is Rayleigh > > > distributed as follows > > > f(r)=r*exp(-r^2/2) r>=0 > > > I am trying to generate sequence of numbers which follow above > > > distribution using two approaches, viz, using envelope of CN & using > > > raylrnd function. > > > My question is why are the following sequences DO NOT have the same > > > statistics? > > > > > > 1. raylrnd(1,1,N)) > > > 2. abs(sqrt(0.5)*(randn(1,N)+j*randn(1,N))) > > > > > > where N is a big number (say 100000). > > > I checked that the mean values of the above sequences do not match. > > > There is some obvious mistake I am doing ... I dont know what? > > > Any help is appreciated and critisms are well received. > > > Thanks. > > > -KK > > > > You might want to take the square root of the power of your complex
noise
> > rather than the abs value - also check that you haven't inadvertently > > defined j to be something other than square root of -1 before you
generate
> > the noise. I haven't got raylrnd() but > > env=sqrt(abs(randn(1,N)+i*randn(1,N)).^2/2) should do the job I hope. > > Best of luck - Mike > > Hi, > Square root of the power of the complex noise is its absolute > value. I dont know why Mike introduced the factor 1/2 in the > calculation of envelope. The matter is still unresolved for raylrnd > function calculates > b*sqrt(Xreal^2+Xim^2) > where 'b' is the parameter as defined in raylrnd function and X is a > sample of a complex normal distribution. > Should not the factor be "b/sqrt(2)" instead of "b" in the above > calculation? > Thanks for your time, > KK
Hi KK - I see what you mean , I introduced the factor 1/2 into the envelope calculation because when you put two orthogonal normally distributed sets of values to gether , each having zero mean and standard deviation = 1 then the power of the complex noise that you get is =2. Assuming that you wanted it normalised w.r.t. a signal power of one so that you can later scale it conveniently you need to divide by two. This certainly seems to be equivalent to you taking the absolute value and dividing by square root of two, I've just never done it that way. It looks as though your 'b' is a convenient scaling factor and I have no idea why mathworks chose not to use b/sqrt(2) as , at least in my opinion, this would be an even more convenient scaling factor. Have you tried posting in comp.soft-sys.matlab? Best of luck - Mike