Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to generate normally distributed R.V in matlab?

Status
Not open for further replies.

rameshrai

Full Member level 3
Joined
Aug 16, 2010
Messages
158
Helped
7
Reputation
14
Reaction score
7
Trophy points
1,298
Activity points
2,272
hi,

how do i generated normally distributed r.v between 0 and 1 in matlab?

i know R = normrnd(mu,sigma) but what is value of mu and sigma? I guess mu=0.5 but what is sigma?

thanks
 

Unfortunately, it is not possible to give you a direct answer, since your requirements are inconsistent. You asked that the variable be (1) normally distributed, and (2) bounded by 0 and 1.
In a rigorous sense, any normally distributed variable is bounded by -inf and +inf. You can see that by inspecting the graphs and equations at https://en.wikipedia.org/wiki/Normal_distribution. Thus it is impossible to generate an exact solution.

However, you could instead say "I want X% of the datapoints to fall within 0 and 1. For example, you could pick 99.7%, which is the 3-sigma value. Since your mu is 0.5, that makes the distance to each bound 0.5, and for a 3 sigma value of 0.5, you just get sigma = 0.5/3 = 0.1667.

This STILL doesn't guarantee that your data points lie within 0 and 1. 3 out of every thousand draws will fall outside. You could either (a) throw them away or (b) make them equal to whatever the closest bound it. Just note that if you do either (a) or (b), your distribution is "technically" not a Gaussian anymore, although it will look very much like one. If you run the code below, you see that the ends of the tails have been chopped off.

If I had to answer the question, this is what I would do:


%define your lower and upper bound
bound = [0 1];
%calculate mu
mu = mean(bound);
%
sigmabound = 3; %how many sigmas to contain

sigma = diff(bound/(2*sigmabound));

%generate the random variable
a = normrnd(mu,sigma, 10000,1);

%remove the points that lie outside the bound
a(a>bound(2)|a<bound(1)) = [];

%plot result
hist(a,100)
 
For normally distributed noise, use the randn() function.

For uniformly distributed noise on the open interval (0,1), use the rand() function.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top