Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
Project: test
Views: 91871# -*- coding: utf-8 -*-123import numpy as np4from numpy.linalg import norm, inv5from numpy.random import randn6from numpy import dot789numpy.random.seed(1234)10user_pos = np.array([1000, 100]) # d5, D61112pred_user_pos = np.array([100, 0]) #d7, d8131415t_pos = np.asarray([[0, 1000],16[0, -1000],17[500, 500]], dtype=float)181920def transmitter_range(pos, transmitter_pos):21""" Compute distance between position 'pos' and the list of positions22in transmitter_pos"""2324N = len(transmitter_pos)25rng = np.zeros(N)2627diff = np.asarray(pos) - transmitter_pos2829for i in range(N):30rng[i] = norm(diff[i])3132return norm(diff, axis=1)3334353637# compute measurement of where you are with respect to seach sensor383940rz= transmitter_range(user_pos, t_pos) # $B21,224142# add some noise43for i in range(len(rz)):44rz[i] += randn()454647# now iterate on the predicted position48pos = pred_user_pos495051def hx_range(pos, t_pos, r_est):52N = len(t_pos)53H = np.zeros((N, 2))54for j in range(N):55H[j,0] = -(t_pos[j,0] - pos[0]) / r_est[j]56H[j,1] = -(t_pos[j,1] - pos[1]) / r_est[j]57return H585960def lop_ils(zs, t_pos, pos_est, hx, eps=1.e-6):61""" iteratively estimates the solution to a set of measurement, given62known transmitter locations"""63pos = np.array(pos_est)6465converged = False66for i in range(20):67r_est = transmitter_range(pos, t_pos) #B32-B3368print('iteration:', i)69#print ('ra1, ra2', ra1, ra2)70print()7172H=hx(pos, t_pos, r_est)7374Hinv = inv(dot(H.T, H)).dot(H.T)7576#update position estimate77y = zs - r_est78print('residual', y)7980Hy = np.dot(Hinv, y)81print('Hy', Hy)8283pos = pos + Hy84print('pos', pos)8586print()87print()8889if max(abs(Hy)) < eps:90converged = True91break9293return pos, converged94959697print(lop_ils(rz, t_pos, (900,90), hx=hx_range))9899100101#####################102"""103# compute measurement (simulation)104rza1, rza2 = transmitter_range(user_pos) # $B21,22105106rza1 += randn()107rza2 += randn()108109# now iterate on the predicted position110pos = pred_user_pos111112113for i in range(10):114ra1, ra2 = transmitter_range(pos) #B32-B33115print('iteration:', i)116print ('ra1, ra2', ra1, ra2)117print()118119H = np.array([[-(t1_pos[0] - pos[0]) / ra1, -(t1_pos[1] - pos[1]) / ra1],120[-(t2_pos[0] - pos[0]) / ra2, -(t2_pos[1] - pos[1]) / ra2]])121Hinv = inv(H)122123#update position estimate124residual_t1 = rza1 - ra1125residual_t2 = rza2 - ra2126y = np.array([[residual_t1], [residual_t2]])127print('residual', y.T)128129130Hy = np.dot(Hinv, y)131132pos = pos + Hy[:,0]133print('pos', pos)134135print()136print()137138if (max(abs(y)) < 1.e-6):139break140"""141142143