Skip to content
Snippets Groups Projects
Commit 07e56fc2 authored by Massimiliano Lincetto's avatar Massimiliano Lincetto
Browse files

test selfcalibration

parent 8cfdcba9
No related branches found
No related tags found
No related merge requests found
Source diff could not be displayed: it is too large. Options to address this: view the blob.
......@@ -3,8 +3,6 @@ import scipy.signal as ssg
from functools import partial
from tqdm import tqdm_notebook as tqdm
"""
Calculates distance(s) between a point 'p' and a(n array of) point(s) 'q'
as the norm of the difference vector(s) 'pq'
......@@ -34,10 +32,12 @@ def xcorr(u1, u2):
def chirp_template(f0, t1, f1):
return partial(wchirp, f0=f0, t1=t1, f1=f1)
class BeamStreamer():
O = (0,0,0) # origin of coordinates
c0 = 1500 # speed of sound [m/s]
class AcouEnv():
O = (0,0,0) # origin
c0 = 1500 # speed of sound [m/s]
h = 2500
class AcouStreamer(AcouEnv):
def __init__(self, f_s, footprint, beacon, noise_level = 0.0, t_margin = 0.0):
self.f_s = f_s
self.beacon = beacon
......@@ -45,7 +45,7 @@ class BeamStreamer():
self.calc_delays(footprint)
self.init_timebase(t_margin)
self.reset_noise(noise_level)
def calc_delays(self, footprint):
self.distances = dist(footprint, self.beacon) - dist(self.O, self.beacon)
......@@ -63,8 +63,32 @@ class BeamStreamer():
def sim_signals(self, template):
self.reference = template(self.timebase)
for stream, delay in zip(tqdm(self.streams), self.delays):
for stream, delay in zip(self.streams, self.delays):
stream[self.sect] += template(self.timebase[self.sect] - delay)
def calibrate_delays(self):
self.rec_shifts = np.empty_like(self.delays, dtype=int)
for i, stream in enumerate(self.streams):
cross_correlation = xcorr(stream[self.sect], self.reference[self.sect])
self.rec_shifts[i] = np.argmax(cross_correlation) - self.sect.start
@property
def t(self):
return self.timebase[self.sect]
@property
def s(self):
return self.streams[:, self.sect]
@property
def delays(self):
return self.distances / self.c0
@property
def calibrated_distances(self):
return dist(self.O, self.beacon) + (self.rec_shifts / self.f_s) * self.c0
class BeamFormer(AcouStreamer):
def beamform(self, nominal_footprint, probe):
W = np.zeros_like(self.timebase[self.sect])
......@@ -80,13 +104,7 @@ class BeamStreamer():
def delays(self):
return self.distances / self.c0
@property
def t(self):
return self.timebase[self.sect]
@property
def s(self):
return self.streams[:, self.sect]
''' meshgrid helper '''
......@@ -126,4 +144,13 @@ class BeamScanner:
self.W.append(W)
self.X.append(X)
Q = np.max(X)
self.Z[i, j] = Q
\ No newline at end of file
self.Z[i, j] = Q
def mse(P, locations, distances):
mse = 0.0
for location, distance in zip(locations, distances):
d = dist(P, location)
mse += (d - distance)**2
mse /= len(locations)
return mse
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment