Need Matlab code for box muller

Status
Not open for further replies.

mvenkat3272

Newbie level 5
Joined
Aug 11, 2006
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,331
Could anybody give me the codes for box muller or any other noise generation algorithm or at least give me the links from where to download them?
 

Re: Matlab code

i have tried that and i did not get any specific hits during searches
 

code 1:

r = rand(1000,2); % 2 cols of uniform rand
% Do the Box-Muller transformation
n = sqrt(-2*log(r,1)))*[1,1].*[cos(2*pi*r,2)), sin(2*pi*r,2))];
hist % plot two histograms

code 2:
function x=boxmuller(n,sd);

x=zeros(n,1);

len=ceil(n/2);
rand('seed',sd);

for i=1:len
u1=rand(1,1);
u2=rand(1,1);
x(i)=sqrt(-2*log(u1))*cos(2*pi*u2);
if (i+len<=n)
x(i+len)=sqrt(-2*log(u1))*sin(2*pi*u2);
end;
end;
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…