zeechimp's picture
Create examples/from_wav.py
f121370 verified
Raw History Blame Contribute Delete
939 Bytes
#!/usr/bin/env python3
"""
Localize from four WAV files. Fill in the paths and receiver
positions, then run.
Run: python examples/from_wav.py
"""
import numpy as np
from ir_source_localizer import localize, load_wav
# Edit these:
WAV_PATHS = ["r0.wav", "r1.wav", "r2.wav", "r3.wav"]
RECEIVERS = [
(4.5, 3.5, 1.0),
(0.5, 3.5, 1.0),
(4.5, 0.5, 1.0),
(0.5, 0.5, 1.0),
]
SOURCE_HEIGHT = 1.0
SIGMA_GUESS = 4e-4 # adjust to your pulse
X_RANGE = (0.2, 4.8)
Y_RANGE = (0.2, 3.8)
# Load
irs = []
sample_rate = None
for path in WAV_PATHS:
data, sr = load_wav(path)
if sample_rate is None:
sample_rate = sr
if sr != sample_rate:
raise SystemExit(f"sample rate mismatch in {path}")
irs.append(data)
# Localize
result = localize(
irs=irs, sample_rate=sample_rate, receivers=RECEIVERS,
sz=SOURCE_HEIGHT,
x_range=X_RANGE, y_range=Y_RANGE,
sigma_guess=SIGMA_GUESS,
)
print(result)