Create examples/batch_localize.py
Browse files- examples/batch_localize.py +48 -0
examples/batch_localize.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Localize N successive clicks in a single recording session and
|
| 4 |
+
report the trajectory.
|
| 5 |
+
|
| 6 |
+
Run: python examples/batch_localize.py
|
| 7 |
+
"""
|
| 8 |
+
import numpy as np
|
| 9 |
+
from ir_source_localizer import (
|
| 10 |
+
localize, simulate_all,
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
ROOM = (5.0, 4.0, 2.8)
|
| 14 |
+
RECEIVERS = np.array([
|
| 15 |
+
[4.5, 3.5, 1.0], [0.5, 3.5, 1.0],
|
| 16 |
+
[4.5, 0.5, 1.0], [0.5, 0.5, 1.0],
|
| 17 |
+
])
|
| 18 |
+
SAMPLE_RATE = 48000
|
| 19 |
+
SIGMA = 4e-4
|
| 20 |
+
|
| 21 |
+
# Simulate a walker moving across the room
|
| 22 |
+
positions = [
|
| 23 |
+
(1.0, 1.0, 1.0),
|
| 24 |
+
(1.5, 1.5, 1.0),
|
| 25 |
+
(2.0, 2.0, 1.0),
|
| 26 |
+
(2.5, 2.5, 1.0),
|
| 27 |
+
(3.0, 2.5, 1.0),
|
| 28 |
+
(3.5, 2.0, 1.0),
|
| 29 |
+
]
|
| 30 |
+
|
| 31 |
+
times = np.arange(2000) / SAMPLE_RATE
|
| 32 |
+
print(f" {'true (x, y)':>16} {'estimated':>16} {'err cm':>8}")
|
| 33 |
+
print(" " + "-" * 46)
|
| 34 |
+
for sx, sy, sz in positions:
|
| 35 |
+
irs = simulate_all(
|
| 36 |
+
RECEIVERS, (sx, sy, sz), ROOM, times,
|
| 37 |
+
alpha=0.72, sigma=SIGMA, n_reflect=2,
|
| 38 |
+
noise_frac=0.02, seed=int(sx * 100 + sy * 10),
|
| 39 |
+
)
|
| 40 |
+
res = localize(
|
| 41 |
+
irs=irs, sample_rate=SAMPLE_RATE, receivers=RECEIVERS,
|
| 42 |
+
sz=sz,
|
| 43 |
+
x_range=(0.2, 4.8), y_range=(0.2, 3.8),
|
| 44 |
+
sigma_guess=SIGMA, estimate_unc=False,
|
| 45 |
+
)
|
| 46 |
+
err = float(np.hypot(res.x - sx, res.y - sy)) * 100
|
| 47 |
+
print(f" ({sx:.2f}, {sy:.2f}) "
|
| 48 |
+
f"({res.x:.3f}, {res.y:.3f}) {err:>6.2f}")
|