|
1 | 1 | import numpy as np |
2 | 2 | from numpy.typing import NDArray |
3 | 3 |
|
4 | | - |
5 | | -def _standard_normal( |
6 | | - n: int, seed: int | np.random.Generator | None = None |
7 | | -) -> NDArray[np.float64]: |
8 | | - """ |
9 | | - Draw i.i.d. samples from a standard Normal distribution (mean=0, stdev=1). |
10 | | -
|
11 | | - Parameters |
12 | | - ---------- |
13 | | - n : int |
14 | | - Number of samples to generate. |
15 | | - seed : int, np.random.Generator or None, optional |
16 | | - A seed used to initialize a random number generator. If passed a Generator, |
17 | | - it will be used unaltered. |
18 | | -
|
19 | | - Returns |
20 | | - ------- |
21 | | - numpy.ndarray, shape (n,) |
22 | | - Sequence of i.i.d. samples. |
23 | | - """ |
24 | | - return np.random.default_rng(seed).standard_normal(n) |
| 4 | +# def _standard_normal( |
| 5 | +# n: int, seed: int | np.random.Generator | None = None |
| 6 | +# ) -> NDArray[np.float64]: |
| 7 | +# """ |
| 8 | +# Draw i.i.d. samples from a standard Normal distribution (mean=0, stdev=1). |
| 9 | + |
| 10 | +# Parameters |
| 11 | +# ---------- |
| 12 | +# n : int |
| 13 | +# Number of samples to generate. |
| 14 | +# seed : int, np.random.Generator or None, optional |
| 15 | +# A seed used to initialize a random number generator. If passed a Generator, |
| 16 | +# it will be used unaltered. |
| 17 | + |
| 18 | +# Returns |
| 19 | +# ------- |
| 20 | +# numpy.ndarray, shape (n,) |
| 21 | +# Sequence of i.i.d. samples. |
| 22 | +# """ |
| 23 | +# return np.random.default_rng(seed).standard_normal(n) |
25 | 24 |
|
26 | 25 |
|
27 | 26 | def white_noise( |
@@ -66,8 +65,10 @@ def white_noise( |
66 | 65 | -------- |
67 | 66 | smsfusion.gauss_markov, smsfusion.random_walk |
68 | 67 | """ |
| 68 | + rng = np.random.default_rng(seed) |
69 | 69 | sigma_wn = N * np.sqrt(fs) |
70 | | - return sigma_wn * _standard_normal(n, seed=seed) # type: ignore[no-any-return] |
| 70 | + wn = sigma_wn * rng.standard_normal(n) # type: ignore[no-any-return] |
| 71 | + return wn |
71 | 72 |
|
72 | 73 |
|
73 | 74 | def random_walk( |
@@ -116,10 +117,12 @@ def random_walk( |
116 | 117 | -------- |
117 | 118 | smsfusion.gauss_markov, smsfusion.white_noise |
118 | 119 | """ |
| 120 | + rng = np.random.default_rng(seed) |
| 121 | + |
119 | 122 | sigma_wn = K / np.sqrt(fs) |
120 | 123 |
|
121 | 124 | x = np.zeros(n) |
122 | | - epsilon = _standard_normal(n - 1, seed=seed) |
| 125 | + epsilon = rng.standard_normal(n - 1) |
123 | 126 | for i in range(1, n): |
124 | 127 | x[i] = x[i - 1] + sigma_wn * epsilon[i - 1] |
125 | 128 |
|
@@ -184,14 +187,16 @@ def gauss_markov( |
184 | 187 | -------- |
185 | 188 | smsfusion.random_walk, smsfusion.white_noise |
186 | 189 | """ |
| 190 | + rng = np.random.default_rng(seed) |
| 191 | + |
187 | 192 | dt = 1.0 / fs |
188 | 193 | beta = 1.0 / tau_c |
189 | 194 |
|
190 | 195 | phi = np.exp(-beta * dt) |
191 | 196 | sigma_wn = sigma * np.sqrt(1.0 - np.exp(-2 * beta * dt)) |
192 | 197 |
|
193 | 198 | x = np.zeros(n) |
194 | | - epsilon = _standard_normal(n - 1, seed=seed) |
| 199 | + epsilon = rng.standard_normal(n - 1) |
195 | 200 | for i in range(1, n): |
196 | 201 | x[i] = phi * x[i - 1] + sigma_wn * epsilon[i - 1] |
197 | 202 |
|
|
0 commit comments