Skip to content
This repository was archived by the owner on Apr 13, 2021. It is now read-only.

Commit 1b9d064

Browse files
author
Pasi Miettinen
committed
Fix 20 ms integration
1 parent 7713608 commit 1b9d064

File tree

1 file changed

+54
-18
lines changed

1 file changed

+54
-18
lines changed

peregrine/tracking.py

+54-18
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,19 @@ def is_pickleable(self):
344344
"""
345345
return True
346346

347+
def store_track_state(self):
348+
self.stored_track_state = {}
349+
self.stored_track_state['carr_phase'] = self.carr_phase
350+
self.stored_track_state['code_phase'] = self.code_phase
351+
self.stored_track_state['carr_phase_acc'] = self.carr_phase_acc
352+
self.stored_track_state['code_phase_acc'] = self.code_phase_acc
353+
354+
def restore_track_state(self):
355+
self.carr_phase = self.stored_track_state['carr_phase']
356+
self.code_phase = self.stored_track_state['code_phase']
357+
self.carr_phase_acc = self.stored_track_state['carr_phase_acc']
358+
self.code_phase_acc = self.stored_track_state['code_phase_acc']
359+
347360
def run(self, samples):
348361
"""
349362
Run tracking channel for the given batch of data.
@@ -372,22 +385,32 @@ def run(self, samples):
372385
samples_processed = 0
373386
samples_total = len(samples[self.signal]['samples'])
374387

375-
estimated_blksize = self.coherent_ms * self.sampling_freq / 1e3
388+
estimated_blksize = 2 * self.coherent_ms * self.sampling_freq / 1e3
376389

377-
self.track_result.status = 'T'
390+
if estimated_blksize > self.samples_to_track:
391+
raise ValueError("Sample file too short")
392+
393+
# check if there is a problem with batch size unless we are at the last
394+
# batch
395+
if ((sample_index + estimated_blksize) > samples_total and
396+
self.samples_to_track - self.samples_tracked > estimated_blksize):
397+
logging.error("Sample batch too small")
398+
raise ValueError("Sample batch too small")
378399

379-
while self.samples_tracked < self.samples_to_track and \
380-
(sample_index + 2 * estimated_blksize) < samples_total:
400+
self.track_result.status = 'T'
381401

402+
while (self.samples_tracked < self.samples_to_track and
403+
(sample_index + estimated_blksize) < samples_total):
382404
self._run_preprocess()
383405

406+
lf_dict = self.loop_filter.to_dict()
384407
if self.pipelining:
385408
# Pipelining and prediction
386409
corr_code_freq = self.next_code_freq
387410
corr_carr_freq = self.next_carr_freq
388411

389-
self.next_code_freq = self.loop_filter.to_dict()['code_freq']
390-
self.next_carr_freq = self.loop_filter.to_dict()['carr_freq']
412+
self.next_code_freq = lf_dict['code_freq']
413+
self.next_carr_freq = lf_dict['carr_freq']
391414

392415
if self.short_n_long and not self.stage1 and not self.short_step:
393416
# In case of short/long cycles, the correction applicable for the
@@ -406,43 +429,56 @@ def run(self, samples):
406429

407430
else:
408431
# Immediate correction simulation
409-
self.next_code_freq = self.loop_filter.to_dict()['code_freq']
410-
self.next_carr_freq = self.loop_filter.to_dict()['carr_freq']
432+
self.next_code_freq = lf_dict['code_freq']
433+
self.next_carr_freq = lf_dict['carr_freq']
411434

412435
corr_code_freq = self.next_code_freq
413436
corr_carr_freq = self.next_carr_freq
414437

415438
coherent_iter, code_chips_to_integrate = self._short_n_long_preprocess()
416439

440+
coherent_idx = 0
441+
# Store state in case of insufficient sample count left
442+
self.store_track_state()
443+
code_freq = corr_code_freq + self.chipping_rate
444+
code_step = code_freq / self.sampling_freq
445+
417446
for _ in range(self.coherent_iter):
418447

419-
if (sample_index + 2 * estimated_blksize) >= samples_total:
420-
break
448+
if (sample_index + coherent_idx + code_step * code_chips_to_integrate >=
449+
samples_total):
450+
# Restore state because loop cannot be finished
451+
self.restore_track_state()
452+
self.sample_index += samples_processed
453+
return self._get_result()
421454

422-
samples_ = samples[self.signal]['samples'][sample_index:]
455+
samples_ =\
456+
samples[self.signal]['samples'][(sample_index + coherent_idx):]
423457

424-
E_, P_, L_, blksize, self.code_phase, self.carr_phase = self.correlator(
458+
E_, P_, L_, blksize, self.code_phase, self.carr_phase = \
459+
self.correlator(
425460
samples_,
426461
code_chips_to_integrate,
427-
corr_code_freq + self.chipping_rate, self.code_phase,
462+
code_freq, self.code_phase,
428463
corr_carr_freq + self.IF, self.carr_phase,
429464
self.prn_code,
430465
self.sampling_freq,
431-
self.signal
432-
)
466+
self.signal)
433467

434468
if blksize > estimated_blksize:
435-
estimated_blksize = blksize
469+
estimated_blksize = 2 * blksize
436470

437-
sample_index += blksize
438-
samples_processed += blksize
471+
coherent_idx += blksize
439472
self.carr_phase_acc += corr_carr_freq * blksize / self.sampling_freq
440473
self.code_phase_acc += corr_code_freq * blksize / self.sampling_freq
441474

442475
self.E += E_
443476
self.P += P_
444477
self.L += L_
445478

479+
sample_index += coherent_idx
480+
samples_processed += coherent_idx
481+
446482
more_integration_needed = self._short_n_long_postprocess()
447483
if more_integration_needed:
448484
continue

0 commit comments

Comments
 (0)