Skip to content

Commit

Permalink
Revamped the whole project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
perrysou committed Sep 7, 2018
1 parent 0e49b5d commit 6448681
Show file tree
Hide file tree
Showing 28 changed files with 2,966 additions and 3,163 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is a GNSS Software Defined Radio (SDR) implemented in python, based on Soft

# System requirements

* python 2.7/3
* python 2.7
* matplotlib
* scipy
* numpy
Expand All @@ -15,10 +15,11 @@ Coming soon!

# Running the GNSS SDR

1. Run init.py
5. Run postProcessing.py
6. Now the signal processing will start
7. Continue from step 1 to repeat the process with a different data file.
1. Examine "main.py"
2. Tweak parameters for the "settings" class if necessary
3. Specify the binary file to be processed and run "main.py"
4. Wait until it is finished


# Resources
* The official homepage of the textbook
Expand Down
513 changes: 273 additions & 240 deletions acquisition.py

Large diffs are not rendered by default.

46 changes: 20 additions & 26 deletions ephemeris.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
def bin2dec(binaryStr=None):
if not isinstance(binaryStr, str):
raise IOError('Input must be a string.')
def bin2dec(binaryStr):
assert isinstance(binaryStr, str)
return int(binaryStr, 2)


# twosComp2dec.m


def twosComp2dec(binaryNumber=None, *args, **kwargs):
def twosComp2dec(binaryStr):
# TWOSCOMP2DEC(binaryNumber) Converts a two's-complement binary number
# BINNUMBER (in Matlab it is a string type), represented as a row vector of
# zeros and ones, to an integer.

# intNumber = twosComp2dec(binaryNumber)

# --- Check if the input is string -----------------------------------------
if not isinstance(binaryNumber, str):
if not isinstance(binaryStr, str):
raise IOError('Input must be a string.')

# --- Convert from binary form to a decimal number -------------------------
intNumber = int(binaryNumber, 2)
intNumber = int(binaryStr, 2)

# --- If the number was negative, then correct the result ------------------
if binaryNumber[0] == '1':
intNumber -= 2 ** len(binaryNumber)
if binaryStr[0] == '1':
intNumber -= 2 ** len(binaryStr)
return intNumber


# checkPhase.m


def checkPhase(word=None, D30Star=None, *args, **kwargs):
def checkPhase(word, d30star):
# Checks the parity of the supplied 30bit word.
# The last parity bit of the previous word is used for the calculation.
# A note on the procedure is supplied by the GPS standard positioning
Expand All @@ -49,7 +46,7 @@ def checkPhase(word=None, D30Star=None, *args, **kwargs):
# (character array).

word_new = []
if D30Star == '1':
if d30star == '1':
# Data bits must be inverted
for i in range(0, 24):
if word[i] == '1':
Expand All @@ -60,9 +57,7 @@ def checkPhase(word=None, D30Star=None, *args, **kwargs):


# ephemeris.m


def ephemeris(bits=None, D30Star=None, *args, **kwargs):
def ephemeris(bits, d30star):
# Function decodes ephemerides and TOW from the given bit stream. The stream
# (array) in the parameter BITS must contain 1500 bits. The first element in
# the array must be the first bit of a subframe. The subframe ID of the
Expand All @@ -85,29 +80,29 @@ def ephemeris(bits=None, D30Star=None, *args, **kwargs):
# stream (in seconds)
# eph - SV ephemeris

## Check if there is enough data ==========================================
# Check if there is enough data ==========================================
if len(bits) < 1500:
raise TypeError('The parameter BITS must contain 1500 bits!')

## Check if the parameters are strings ====================================
# Check if the parameters are strings ====================================
if any([not isinstance(x, str) for x in bits]):
raise TypeError('The parameter BITS must be a character array!')

if not isinstance(D30Star, str):
if not isinstance(d30star, str):
raise TypeError('The parameter D30Star must be a char!')

# Pi used in the GPS coordinate system
gpsPi = 3.1415926535898

## Decode all 5 sub-frames ================================================
# Decode all 5 sub-frames ================================================
for i in range(5):
# --- "Cut" one sub-frame's bits ---------------------------------------
subframe = bits[300 * i:300 * (i + 1)]

for j in range(10):
subframe[30 * j: 30 * (j + 1)] = checkPhase(subframe[30 * j: 30 * (j + 1)], D30Star)
subframe[30 * j: 30 * (j + 1)] = checkPhase(subframe[30 * j: 30 * (j + 1)], d30star)

D30Star = subframe[30 * (j + 1) - 1]
d30star = subframe[30 * (j + 1) - 1]

# --- Decode the sub-frame id ------------------------------------------
# For more details on sub-frame contents please refer to GPS IS.
Expand Down Expand Up @@ -188,14 +183,13 @@ def ephemeris(bits=None, D30Star=None, *args, **kwargs):
# Not decoded at the moment.
pass

## Compute the time of week (TOW) of the first sub-frames in the array ====
# Compute the time of week (TOW) of the first sub-frames in the array ====
# Also correct the TOW. The transmitted TOW is actual TOW of the next
# subframe and we need the TOW of the first subframe in this data block
# (the variable subframe at this point contains bits of the last subframe).
TOW = bin2dec(subframe[30:47]) * 6 - 30
# Initialize fields for ephemeris
eph = (
weekNumber, accuracy, health, T_GD, IODC, t_oc, a_f2, a_f1, a_f0, IODE_sf2, C_rs, deltan, M_0, C_uc, e, C_us,
sqrtA,
t_oe, C_ic, omega_0, C_is, i_0, C_rc, omega, omegaDot, IODE_sf3, iDot)
eph = (weekNumber, accuracy, health, T_GD, IODC, t_oc, a_f2, a_f1, a_f0,
IODE_sf2, C_rs, deltan, M_0, C_uc, e, C_us, sqrtA, t_oe,
C_ic, omega_0, C_is, i_0, C_rc, omega, omegaDot, IODE_sf3, iDot)
return eph, TOW
198 changes: 0 additions & 198 deletions findPreambles.py

This file was deleted.

Loading

0 comments on commit 6448681

Please sign in to comment.