Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
  • 6 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
10 peregrine/acquisition.py
@@ -15,7 +15,7 @@
import numpy as np
import pyfftw
-import pickle
+import cPickle
from include.generateCAcode import caCodes
@@ -507,13 +507,13 @@ def progress_callback(freq_num, num_freqs):
def load_wisdom(self, wisdom_file=DEFAULT_WISDOM_FILE):
"""Load saved FFTW wisdom from file."""
with open(wisdom_file, 'rb') as f:
- wisdom = pickle.load(f)
+ wisdom = cPickle.load(f)
pyfftw.import_wisdom(wisdom)
def save_wisdom(self, wisdom_file=DEFAULT_WISDOM_FILE):
"""Save FFTW wisdom to file."""
with open(wisdom_file, 'wb') as f:
- pickle.dump(pyfftw.export_wisdom(), f)
+ cPickle.dump(pyfftw.export_wisdom(), f, protocol=cPickle.HIGHEST_PROTOCOL)
class AcquisitionResult:
@@ -573,7 +573,7 @@ def save_acq_results(filename, acq_results):
"""
with open(filename, 'wb') as f:
- pickle.dump(acq_results, f)
+ cPickle.dump(acq_results, f, protocol=cPickle.HIGHEST_PROTOCOL)
def load_acq_results(filename):
"""
@@ -591,5 +591,5 @@ def load_acq_results(filename):
"""
with open(filename, 'rb') as f:
- return pickle.load(f)
+ return cPickle.load(f)
View
4 peregrine/include/generateCAcode.py
@@ -67,7 +67,7 @@ def generateCAcode(PRN):
return CAcode
-caCodes = np.empty((32, 1023), dtype=np.int8)
-for PRN in range(32):
+caCodes = np.empty((51, 1023), dtype=np.int8)
+for PRN in range(51):
caCodes[PRN][:] = generateCAcode(PRN)
View
18 peregrine/run.py
@@ -11,7 +11,7 @@
import sys
import argparse
-import pickle
+import cPickle
import logging
from operator import attrgetter
@@ -87,26 +87,34 @@ def main():
logging.info("Skipping tracking, loading saved tracking results.")
try:
with open(track_results_file, 'rb') as f:
- track_results = pickle.load(f)
+ track_results = cPickle.load(f)
except IOError:
logging.critical("Couldn't open tracking results file '%s'.",
track_results_file)
sys.exit(1)
else:
signal = load_samples(args.file,
- int(settings.samplingFreq*1e-3*37100))
+ int(settings.samplingFreq*1e-3*settings.msToProcess))
track_results = track(signal, acq_results, settings)
try:
with open(track_results_file, 'wb') as f:
- pickle.dump(track_results, f)
+ cPickle.dump(track_results, f, protocol=cPickle.HIGHEST_PROTOCOL)
logging.debug("Saving tracking results as '%s'" % track_results_file)
except IOError:
logging.error("Couldn't save tracking results file '%s'.",
track_results_file)
# Do navigation
+ nav_results_file = args.file + ".nav_results"
if not args.skip_navigation:
- navSolutions = navigation(track_results, settings)
+ nav_solns = navigation(track_results, settings)
+ nav_results = []
+ for s, t in nav_solns:
+ nav_results += [(t, s.pos_llh, s.vel_ned)]
+ with open(nav_results_file, 'wb') as f:
+ cPickle.dump(nav_results, f, protocol=cPickle.HIGHEST_PROTOCOL)
+ logging.debug("Saving navigation results as '%s'" % nav_results_file)
if __name__ == '__main__':
main()
+
View
17 peregrine/samples.py
@@ -76,14 +76,19 @@ def load_samples(filename, num_samples=-1, num_skip=0, file_format='int8'):
num_skip_bytes = 0
num_skip_samples = 0
num_bytes = -1
- with open(filename, 'rb') as f:
- f.seek(num_skip_bytes)
- packed = np.fromfile(f, dtype=np.uint8, count=num_bytes)
- sign_mag_mapping = np.array([1, 3, 5, 7, -1, -3, -5, -7], dtype=np.int8)
+
+ packed = np.memmap(filename, offset=num_skip_bytes, dtype=np.uint8, mode='r')
+ if num_bytes > 0:
+ packed = packed[:num_bytes]
+
samples = np.empty(len(packed) * 2, dtype=np.int8)
- samples[::2] = (packed >> 5) & 7
+
+ # Unpack 2 samples from each byte
+ samples[::2] = (packed >> 5)
samples[1::2] = (packed >> 2) & 7
- samples = sign_mag_mapping[samples]
+ # Sign-magnitude to two's complement mapping
+ samples = (1-2*(samples>>2)) * (2*(samples&3)+1)
+
samples = samples[num_skip_samples:]
if num_samples > 0:
samples = samples[:num_samples]
View
79 peregrine/tracking.py
@@ -27,32 +27,25 @@
_progressbar_available = False
-def calc_loop_coef(lbw, zeta, k):
- omega_n = lbw*8.0*zeta / (4.0*zeta**2 + 1.0)
- tau1 = k / (omega_n**2)
- tau2 = 2.0 * zeta / omega_n
- return (tau1, tau2)
-
-class LoopFilter:
- def __init__(self, freq, lbw, zeta, k, loop_freq):
- self.freq = freq
-
- tau1, tau2 = calc_loop_coef(lbw, zeta, k)
- self.igain = 1.0 / (tau1 * loop_freq)
- self.pgain = tau2 / tau1
-
- self.prev_error = 0
-
- def update(self, error):
- self.freq += self.pgain * (error - self.prev_error) + \
- self.igain * error
- self.prev_error = error
-
- return self.freq
-
-
-def track(signal, channel, settings, show_progress=True, trk=swiftnav.correlate.track_correlate):
+default_loop_filter = swiftnav.track.SimpleTrackingLoop(
+ (2, 0.7, 1), # Code loop parameters
+ (25, 0.7, 0.25), # Carrier loop parameters
+ 1e3 # Loop frequency
+)
+
+comp_loop_filter = swiftnav.track.CompTrackingLoop(
+ (2, 0.7, 1), # Code loop parameters
+ (25, 0.7, 0.25), # Carrier loop parameters
+ 1e3, # Loop frequency
+ 0.005, # Tau
+ 1000 # Gain schedule after 1000 iterations (1s)
+)
+
+def track(signal, channel, settings,
+ show_progress=True,
+ trk=swiftnav.correlate.track_correlate,
+ loop_filter=default_loop_filter):
logger.info("Tracking starting")
logger.debug("Tracking %d channels, PRNs %s" % (len(channel), [chan.prn+1 for chan in channel]))
@@ -85,11 +78,13 @@ def track(signal, channel, settings, show_progress=True, trk=swiftnav.correlate.
track_result = TrackResults(settings.msToProcess)
track_result.PRN = channel[channelNr].prn
- codeFreq = settings.codeFreqBasis
- codeLoop = LoopFilter(codeFreq, 2, 0.7, 1, 1e3)
+ # Convert acquisition SNR to C/N0
+ cn0_0 = 10*np.log10(channel[channelNr].snr)
+ cn0_0 += 10*np.log10(1000) # Channel bandwidth
+ cn0_est = swiftnav.track.CN0Estimator(1e3, cn0_0, 10, 1e3)
+
+ loop_filter.start(settings.codeFreqBasis, channel[channelNr].carr_freq)
remCodePhase = 0.0
- carrFreq = channel[channelNr].carr_freq
- carrLoop = LoopFilter(carrFreq, 25, 0.7, 0.25, 1e3)
remCarrPhase = 0.0
# Get a vector with the C/A code sampled 1x/chip
@@ -108,27 +103,22 @@ def track(signal, channel, settings, show_progress=True, trk=swiftnav.correlate.
if pbar:
pbar.update(loopCnt + channelNr*settings.msToProcess, attr={'chan': channelNr+1})
- codePhaseStep = codeFreq/settings.samplingFreq
+ codePhaseStep = loop_filter.code_freq/settings.samplingFreq
rawSignal = signal[numSamplesToSkip:]#[:blksize_]
- I_E, Q_E, I_P, Q_P, I_L, Q_L, blksize, remCodePhase, remCarrPhase = trk(rawSignal, codeFreq, remCodePhase, carrFreq, remCarrPhase, caCode, settings)
+ I_E, Q_E, I_P, Q_P, I_L, Q_L, blksize, remCodePhase, remCarrPhase = trk(rawSignal, loop_filter.code_freq, remCodePhase, loop_filter.carr_freq, remCarrPhase, caCode, settings)
numSamplesToSkip += blksize
- carrError = math.atan(Q_P/(I_P+1e-10)) / (2.0 * math.pi)
- carrFreq = carrLoop.update(carrError)
+ E = I_E + Q_E*1.j
+ P = I_P + Q_P*1.j
+ L = I_L + Q_L*1.j
+ loop_filter.update(E, P, L)
- track_result.carrFreq[loopCnt] = carrFreq
track_result.carrPhase[loopCnt] = remCarrPhase
- track_result.pllDiscr[loopCnt] = carrError
-
- #Find DLL error and update code NCO
- codeError = -(math.sqrt(I_E*I_E + Q_E*Q_E) - math.sqrt(I_L*I_L + Q_L*Q_L)) / \
- (math.sqrt(I_E*I_E + Q_E*Q_E) + math.sqrt(I_L*I_L + Q_L*Q_L) + 1e-10)
- codeFreq = codeLoop.update(codeError)
+ track_result.carrFreq[loopCnt] = loop_filter.carr_freq
track_result.codePhase[loopCnt] = remCodePhase
- track_result.codeFreq[loopCnt] = codeFreq
- track_result.dllDiscr[loopCnt] = codeError
+ track_result.codeFreq[loopCnt] = loop_filter.code_freq
#Record stuff for postprocessing
track_result.absoluteSample[loopCnt] = numSamplesToSkip
@@ -140,6 +130,8 @@ def track(signal, channel, settings, show_progress=True, trk=swiftnav.correlate.
track_result.Q_P[loopCnt] = Q_P
track_result.Q_L[loopCnt] = Q_L
+ track_result.cn0[loopCnt] = cn0_est.update(I_P)
+
#Possibility for lock-detection later
track_result.status = 'T'
track_results += [track_result]
@@ -167,6 +159,5 @@ def __init__(self, n_points):
self.Q_E = np.empty(n_points)
self.Q_P = np.empty(n_points)
self.Q_L = np.empty(n_points)
- self.dllDiscr = np.empty(n_points);
- self.pllDiscr = np.empty(n_points);
+ self.cn0 = np.empty(n_points)

No commit comments for this range

Something went wrong with that request. Please try again.