ir-source-localizer / examples /batch_localize.py
zeechimp's picture
Create examples/batch_localize.py
87f87a1 verified
Raw History Blame Contribute Delete
1.27 kB
#!/usr/bin/env python3
"""
Localize N successive clicks in a single recording session and
report the trajectory.
Run: python examples/batch_localize.py
"""
import numpy as np
from ir_source_localizer import (
localize, simulate_all,
)
ROOM = (5.0, 4.0, 2.8)
RECEIVERS = np.array([
[4.5, 3.5, 1.0], [0.5, 3.5, 1.0],
[4.5, 0.5, 1.0], [0.5, 0.5, 1.0],
])
SAMPLE_RATE = 48000
SIGMA = 4e-4
# Simulate a walker moving across the room
positions = [
(1.0, 1.0, 1.0),
(1.5, 1.5, 1.0),
(2.0, 2.0, 1.0),
(2.5, 2.5, 1.0),
(3.0, 2.5, 1.0),
(3.5, 2.0, 1.0),
]
times = np.arange(2000) / SAMPLE_RATE
print(f" {'true (x, y)':>16} {'estimated':>16} {'err cm':>8}")
print(" " + "-" * 46)
for sx, sy, sz in positions:
irs = simulate_all(
RECEIVERS, (sx, sy, sz), ROOM, times,
alpha=0.72, sigma=SIGMA, n_reflect=2,
noise_frac=0.02, seed=int(sx * 100 + sy * 10),
)
res = localize(
irs=irs, sample_rate=SAMPLE_RATE, receivers=RECEIVERS,
sz=sz,
x_range=(0.2, 4.8), y_range=(0.2, 3.8),
sigma_guess=SIGMA, estimate_unc=False,
)
err = float(np.hypot(res.x - sx, res.y - sy)) * 100
print(f" ({sx:.2f}, {sy:.2f}) "
f"({res.x:.3f}, {res.y:.3f}) {err:>6.2f}")