Advertisement
Guest User

receiver.py

a guest
Oct 30th, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.93 KB | None | 0 0
  1. while epoch < len(sat_epoch_size) - 1:
  2.    
  3.     k = sat_epoch_size[epoch]
  4.     m = sat_epoch_size[epoch]
  5.    
  6.     norm_count = sat_epoch_size[epoch+1]
  7.     sum_count = norm_count - 1
  8.     if init == 0:
  9.       temp = b12(satellite_output.ts[init],pi,sidereal_day)
  10.       # print "b12: x,y,z  ",temp
  11.       x_veh_coords.append(temp[0])
  12.       y_veh_coords.append(temp[1])
  13.       z_veh_coords.append(temp[2])
  14.       print "x,y,z   ",x_veh_coords[epoch],y_veh_coords[epoch],z_veh_coords[epoch]
  15.     # if init > 1:
  16.       # N = []
  17.       # A = []
  18.       # X=[]
  19.       # Y=[]
  20.       # Z=[]
  21.  
  22.       # dXdx = []
  23.       # dXdy = []
  24.       # dXdz = []
  25.      
  26.       # dYdx = dXdy
  27.       # dYdy = []
  28.       # dYdz = []
  29.      
  30.       # dZdx = dXdz
  31.       # dZdy = dYdz
  32.       # dZdz = []
  33.      
  34.     if epoch != 0:
  35.       # This helps count through each while loop.
  36.       # this is necessary for the sum_count while loop to work correctly
  37.       j = epoch
  38.       sum_count = norm_count - 1 - epoch
  39.       m -= epoch
  40.    
  41.     print "----------------------------------------------------------"
  42.     print "Counters: epoch | i | j | k | m | norm_count | sum_count: "
  43.     print "           ",epoch,"   ", i," ", j," ", k," ", m,"     ", norm_count,"        ", sum_count
  44.     print "----------------------------------------------------------"
  45.    
  46.     # Calculate the norms of current epoch
  47.     # print "x_veh_coords[epoch]:  ",x_veh_coords[epoch]
  48.     while k < norm_count: #sat_epoch_size[epoch]:
  49.       # N.append( dec.sqrt( (dec(satellite_output.x[k]) - dec(x_veh_coords[epoch]))**2 + (dec(satellite_output.y[k]) - dec(y_veh_coords[epoch]))**2 + (dec(satellite_output.z[k]) - dec(z_veh_coords[epoch]))**2 ) )
  50.       # print "K: ",k, "Sat: ", satellite_output.i[k]
  51.       N.insert(k, ( dec.sqrt( (dec(satellite_output.x[k]) - dec(x_veh_coords[epoch]))**2 + (dec(satellite_output.y[k]) - dec(y_veh_coords[epoch]))**2 + (dec(satellite_output.z[k]) - dec(z_veh_coords[epoch]))**2 ) ) )
  52.       print "NORM k: ", k, N[k], "Sat: ", satellite_output.i[k]
  53.       # print "x_veh_coords[epoch]:  ",x_veh_coords[epoch]
  54.       # print "satellite_output.x[k]:  ", satellite_output.x[k]
  55.       k += 1
  56.     print "----------------------------------------------------------"
  57.    
  58.     # Calculate the sumation
  59.     while m < sum_count:
  60.       # print "m:  ",m, sum_count
  61.       A.insert(m, N[m+1+j] - N[m+j] - (speed_of_light)*( satellite_output.ts[m+j] - satellite_output.ts[m+1+j] ) )
  62.       X.insert(m, (dec(satellite_output.x[m+j]) - dec(x_veh_coords[epoch]))/( N[m+j] ) - (dec(satellite_output.x[m+1+j]) - dec(x_veh_coords[epoch]))/( N[m+1+j] ) )
  63.       Y.insert(m, (dec(satellite_output.y[m+j]) - dec(y_veh_coords[epoch]))/( N[m+j] ) - (dec(satellite_output.y[m+1+j]) - dec(y_veh_coords[epoch]))/( N[m+1+j] ) )
  64.       Z.insert(m, (dec(satellite_output.z[m+j]) - dec(z_veh_coords[epoch]))/( N[m+j] ) - (dec(satellite_output.z[m+1+j]) - dec(z_veh_coords[epoch]))/( N[m+1+j] ) )
  65.       # print " SUM m:  ", m, A[m], X[m], Y[m], Z[m], "Sat: ", satellite_output.i[m+j]
  66.       # print "NORM m: ", m, N[m+j], N[m+1+j]
  67.      
  68.       # Calculate all partial derivatives that are outside of the partial derivative sums.
  69.       dXdx.insert(m, ( N[m+1+j]**2 - (dec(satellite_output.x[m+j]) - dec(x_veh_coords[epoch]))**2 )/N[m+1+j]**3 - ( N[m+j]**2 - (dec(satellite_output.x[m+j]) - dec(x_veh_coords[epoch]))**2 )/N[m+j]**3 )
  70.       dXdy.insert(m, ( (dec(satellite_output.y[m+j]) - dec(y_veh_coords[epoch]))*(dec(satellite_output.x[m+j]) - dec(x_veh_coords[epoch])) )/N[m+j]**3 - ( (dec(satellite_output.y[m+1+j]) - dec(y_veh_coords[epoch]))*(dec(satellite_output.x[m+1+j]) - dec(x_veh_coords[epoch])) )/N[m+1+j]**3 )
  71.       dXdz.insert(m, ( (dec(satellite_output.z[m+j]) - dec(z_veh_coords[epoch]))*(dec(satellite_output.x[m+j]) - dec(x_veh_coords[epoch])) )/N[m+j]**3 - ( (dec(satellite_output.z[m+1+j]) - dec(z_veh_coords[epoch]))*(dec(satellite_output.x[m+1+j]) - dec(x_veh_coords[epoch])) )/N[m+1+j]**3 )
  72.       dYdx = dXdy
  73.       dYdy.insert(m, ( N[m+1+j]**2 - (dec(satellite_output.y[m+j]) - dec(y_veh_coords[epoch]))**2 )/N[m+1+j]**3 - ( N[m+j]**2 - (dec(satellite_output.y[m+j]) - dec(y_veh_coords[epoch]))**2 )/N[m+j]**3 )
  74.       dYdz.insert(m, ( (dec(satellite_output.y[m+j]) - dec(y_veh_coords[epoch]))*(dec(satellite_output.z[m+j]) - dec(z_veh_coords[epoch])) )/N[m+j]**3 - ( (dec(satellite_output.y[m+1+j]) - dec(y_veh_coords[epoch]))*(dec(satellite_output.z[m+1+j]) - dec(z_veh_coords[epoch])) )/N[m+1+j]**3 )
  75.       dZdx = dXdz
  76.       dZdy = dYdz
  77.       dZdz.insert(m, ( N[m+1+j]**2 - (dec(satellite_output.z[m+j]) - dec(z_veh_coords[epoch]))**2 )/N[m+1+j]**3 - ( N[m+j]**2 - (dec(satellite_output.z[m+j]) - dec(z_veh_coords[epoch]))**2 )/N[m+j]**3 )
  78.       # print " m: ",m, dXdx[m]
  79.       # print "Sat[m+j]: ",m+j, satellite_output.i[m+j], "Sat[m+1+j]: ",m+1+j, satellite_output.i[m+1+j]
  80.       # print "dXdx dXdy dXdz  ",m,dXdx[m], dXdy[m], dXdz[m]
  81.       # print "dYdx dYdy dYdz  ",m,dYdx[m], dYdy[m], dYdz[m]
  82.       # print "dZdx dZdy dZdz  ",m,dZdx[m], dZdy[m], dZdz[m]
  83.       m += 1
  84.     # print "----------------------------------------------------------"
  85.    
  86.     fx = 0
  87.    
  88.     dfdx = 0
  89.     dfdy = 0
  90.     dfdz = 0
  91.    
  92.     d2fdx2 = 0
  93.     d2fdxdy = 0
  94.     d2fdxdz = 0
  95.    
  96.     d2fdydx = d2fdxdy
  97.     d2fdy2 = 0
  98.     d2fdydz = 0
  99.    
  100.     d2fdzdx = d2fdxdz
  101.     d2fdzdy = d2fdydz
  102.     d2fdz2 = 0
  103.    
  104.     # Sum all of the 1st and 3nd order partials
  105.     # while i < sum_count:
  106.     for i in range(sum_count):
  107.       dfdx += 2*A[i]*X[i]
  108.       dfdy += 2*A[i]*Y[i]
  109.       dfdz += 2*A[i]*Z[i]
  110.       d2fdx2 += 2*( X[i]**2 + A[i]*dXdx[i] )
  111.       d2fdxdy += 2*( X[i]*Y[i]+A[i]*dXdy[i] )
  112.       d2fdxdz += 2*( X[i]*Z[i]+A[i]*dXdz[i] )
  113.       d2fdydx = d2fdxdy
  114.       d2fdy2 += 2*( Y[i]**2 + A[i]*dYdy[i] )
  115.       d2fdydz += 2*( Y[i]*Z[i]+A[i]*dYdz[i] )
  116.       d2fdzdx = d2fdxdz
  117.       d2fdzdy = d2fdydz
  118.       d2fdz2 += 2*( Z[i]**2 + A[i]*dZdz[i] )      
  119.      
  120.     # Solve J(x)*s = -F(x)
  121.     J = array([ [d2fdx2], [d2fdxdy], [d2fdxdz], [d2fdydx], [d2fdy2], [d2fdydz], [d2fdzdx], [d2fdzdy], [d2fdz2] ], dtype=numpy.dtype(decimal.Decimal))
  122.     J.shape = (3,3)
  123.     J = scipy.matrix(J.copy())
  124.     # print A
  125.     # b = array([X[i], Y[i], Z[i]])
  126.     b = array([ [dfdx], [dfdy], [dfdz] ], dtype=numpy.dtype(decimal.Decimal))
  127.     b.shape = (3,1)
  128.     b = scipy.matrix(b.copy())
  129.     s = linalg.solve(J,-b)
  130.     prev_x_veh_coords = x_veh_coords[epoch]
  131.     prev_y_veh_coords = y_veh_coords[epoch]
  132.     prev_z_veh_coords = z_veh_coords[epoch]
  133.     x_veh_coords[epoch] += dec(s[0,0])
  134.     y_veh_coords[epoch] += dec(s[1,0])
  135.     z_veh_coords[epoch] += dec(s[2,0])
  136.     # print "x, y, z  ", x_veh_coords[epoch], y_veh_coords[epoch], z_veh_coords[epoch]
  137.     prev_X = [prev_x_veh_coords, prev_y_veh_coords, prev_z_veh_coords]
  138.     curr_X = [x_veh_coords[epoch], y_veh_coords[epoch], z_veh_coords[epoch]]
  139.     distance_check = vec_norm(prev_X,curr_X)
  140.     # print "Distance check:  ", distance_check
  141.     if distance_check < 0.01:
  142.       epoch += 1
  143.       init = 1
  144.        
  145.     init += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement