root / branches / simulator / projects / simulator / Rangefinder_with_noise.c @ 991
History | View | Annotate | Download (454 Bytes)
1 |
float cm, IR, noise;
|
---|---|
2 |
|
3 |
cm = 5.5; // Enter value between 7 and 18 for accurate results |
4 |
noise = 5; // Enter scarlar of noise |
5 |
|
6 |
IR = 15.4005 * cm; // 15.4005 is an experimental value |
7 |
|
8 |
|
9 |
float x1, x2, w, y1, y2;
|
10 |
|
11 |
do
|
12 |
{ |
13 |
x1 = 2.0 * rand()/randmax() - 1.0; |
14 |
x2 = 2.0 * rand()/randmax() - 1.0; |
15 |
w = x1 * x1 + x2 * x2; |
16 |
} |
17 |
while ( w >= 1.0 ); |
18 |
|
19 |
w = sqrt( (-2.0 * ln( w ) ) / w ); |
20 |
y1 = x1 * w; |
21 |
y2 = x2 * w; |
22 |
|
23 |
IR = y1 * noise + IR; |