File size: 1,268 Bytes
87f87a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/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}")