Re: Add Noise

beliavsky_at_aol.com
Date: 03/18/04


Date: 18 Mar 2004 14:33:24 -0800


"Filippos Louis" <flouis@geol.uoa.gr> wrote in message news:<c3c3cm$33i$1@nic.grnet.gr>...
> Hi all
> Does anyone know of a Fortran routine to add noise to data on a vector?
> (Gaussian or Random)!
> Thank you in advance
>
> FLouis

Here is a Fortran 90/95 function with driver to simulate Gaussian
variates using the Box-Muller algoritm.

module box_muller
implicit none
public :: normal_bm
contains
function normal_bm() result(zz)
! generate a random normal deviate using the Box-Muller method
real :: zz
real :: dist,xx(2)
real, parameter :: two = 2.0, minus_two = -2.0
do
   call random_number(xx)
   xx = two*xx - 1.0
   dist = xx(1)**2 + xx(2)**2
   if (dist < 1.0) exit
end do
zz = xx(1)*sqrt(minus_two*log(dist)/dist)
end function normal_bm
end module box_muller

program xnormal_bm
use box_muller, only: normal_bm
implicit none
integer :: i
integer, parameter :: n = 1000000
real :: xx(n)
call random_seed()
do i=1,n
   xx(i) = normal_bm()
end do
write (*,"(' moments:',100f8.4)") &
       (/sum(xx),sum(xx**2),sum(xx**3),sum(xx**4)/) / n
end program xnormal_bm

With Compaq Visual Fortran 6.6 it produce the result

moments: 0.0010 0.9970 0.0037 2.9859

which looks good. Can anyone recommend a Fortran code to test the
quality of a vector of variates that are supposed to be IID normal?

Some sources for Fortran codes for random number generation are listed
at http://www.dmoz.org/Computers/Programming/Languages/Fortran/Source_Code/Statistics_and_Econometrics/
.



Relevant Pages

  • Re: Is it time to legitimise REAL*8 etc?
    ... why the Fortran 90 Standard introduced the kind selection functions, ... to programmers who still use this notation that they really ought to use ... machines as we can. ... but Gaussian cost something like US$2000. ...
    (comp.lang.fortran)
  • Re: Is it time to legitimise REAL*8 etc?
    ... why the Fortran 90 Standard introduced the kind selection functions, ... to programmers who still use this notation that they really ought to use ... All current compilers seem to accept REAL*8 and similar without ... but Gaussian cost something like US$2000. ...
    (comp.lang.fortran)
  • Re: fft newbie
    ... i am quite as new to programming in general and to fortran in particular ... as to programming ffts. ... gaussian as output data. ... array, or vice-versa. ...
    (comp.dsp)
  • Re: Recycled scientists
    ... CPMD is written in Fortran. ... Gaussian (a big-time quantuum chemistry package) is written in Fortran. ... Unfortunately Be Nice School graduates learn that never is heard a discouraging word, which often puts a tight constraint upon how people deal with each other: no disagreements, no differing opinions, nothing but compromise and blandness. ...
    (sci.research.careers)
  • Re: Windows to Linux Fortran code
    ... I am to "convert" a program written in fortran under windows, ... are called from DOS script files that act upon menus written in some ... Local "environment variables" have been set ... If you do decide to use OS system calls from within your Fortran code ...
    (comp.lang.fortran)