-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathGoldCode.py
More file actions
executable file
·74 lines (55 loc) · 2.03 KB
/
GoldCode.py
File metadata and controls
executable file
·74 lines (55 loc) · 2.03 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#Store the shift registers as a deque, so that deque.rotate() can be used.
from collections import deque
import numpy as np
'''
GPS Gold Code generator. Initialized with the feedback taps for one satellite.
'''
#Feedback taps as defined in GPS spec
g1tap = [2,9]
g2tap = [1,2,5,7,8,9]
sats = [(1, 5), (2, 6), (3, 7), (4, 8), (0, 8), (1, 9), (0, 7), (1, 8), (2, 9), (1, 2),
(2, 3), (4, 5), (5, 6), (6, 7), (7, 8), (8, 9), (0, 3), (1, 4), (2, 5), (3, 6),
(4, 7), (5, 8), (0, 2), (3, 5), (4, 6), (5, 7), (6, 8), (7, 9), (0, 5), (1, 6),
(2, 7), (3, 8), (4, 9), (3, 9), (0, 6), (1, 7), (3, 9)]
def getCode(num, zero = False, samplesPerChip = 1, prn = 0):
'''
Returns a list of bits that form the Gold Code PRN of the designated satellite
zero flag determines whether 0 or -1 is returned
'''
g1 = deque(1 for i in range(10))
g2 = deque(1 for i in range(10))
g = []
for i in range(num):
val = (g1[9] + g2[prn[0]] + g2[prn[1]]) % 2
g.append(val)
#Shift g1
g1[9] = sum([g1[i] for i in g1tap]) % 2
g1.rotate()
#Shift g2
g2[9] = sum([g2[i] for i in g2tap]) % 2
g2.rotate()
if(zero == False):
#format GC to have -1 in place of 0
for n,i in enumerate(g):
if i==0:
g[n]=-1
if (samplesPerChip > 1 ):
# Repeat each chip to match our ADC sample frequency
gsamp = np.repeat(g, samplesPerChip)
return gsamp
return g
def getTrackingCode(sat):
'''
Returns a code ready to be used by Tracking.py
'''
code = np.array(getCode(1023, prn = sats[sat - 1]))
# Need to add extra code chips to the ends so that it can 'slide'
# back and forth during tracking.
code = np.append(code,code[0])
code = np.insert(code,0, code[len(code) - 2])
return code
def getAcquisitionCode(sat, spc):
'''
Returns a code ready to be used by Acquisition.py
'''
return getCode(1023, samplesPerChip = spc, prn = sats[sat-1])