Project

General

Profile

Revision 1002

Added by Ben Poole about 15 years ago

gaussian noise now has a gauss_init to initialize with a seed and chaos scalar

View differences:

branches/simulator/projects/simulator/simulator/core/gauss.c
13 13
#include <math.h>
14 14
#include "gauss.h"
15 15

  
16
float chaos_scalar;
16
double chaos_scalar;
17 17

  
18
float gauss_noise(void)
18
void gauss_init(double chaos, unsigned int seed)
19 19
{
20
    float x1, x2, w, y1, y2;
20
    chaos_scalar = chaos;
21
    srand(seed);
22
}
21 23

  
22
    srand( SEED );
24
double gauss_noise(void)
25
{
26
    double x1, x2, w, y1, y2;
27

  
23 28
    do 
24 29
    {
25 30
	x1 = 2.0 * rand()/RAND_MAX - 1.0;
26 31
	x2 = 2.0 * rand()/RAND_MAX - 1.0;
27 32
	w = x1 * x1 + x2 * x2;
28 33
    } while ( w >= 1.0 );
29
    w = sqrt( (-2.0 * log( w ) ) / w );
30
    return (x1 * w);
34
    w = sqrtf( (-2.0 * logf( w ) ) / w );
35

  
36
    return chaos_scalar*x1*w;
31 37
}
32 38

  
33 39

  
branches/simulator/projects/simulator/simulator/core/gauss.h
10 10

  
11 11
#ifndef __GAUSS_H__
12 12
#define __GAUSS_H__
13
#define SEED 0
14 13

  
15
extern float chaos_scalar; 
16
float gauss_noise(void);
14
extern double chaos_scalar; 
15
void gauss_init(double chaos, unsigned int seed);
16
double gauss_noise(void);
17 17

  
18 18

  
19 19
#endif

Also available in: Unified diff