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

Commit 5dd66dd

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

File tree

1 file changed

+58
-18
lines changed

1 file changed

+58
-18
lines changed

peregrine/tracking.py

+58-18
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,23 @@ 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+
if not self.stored_track_state:
356+
logger.error("No stored track state available")
357+
return
358+
359+
self.carr_phase = self.stored_track_state['carr_phase']
360+
self.code_phase = self.stored_track_state['code_phase']
361+
self.carr_phase_acc = self.stored_track_state['carr_phase_acc']
362+
self.code_phase_acc = self.stored_track_state['code_phase_acc']
363+
347364
def run(self, samples):
348365
"""
349366
Run tracking channel for the given batch of data.
@@ -372,22 +389,32 @@ def run(self, samples):
372389
samples_processed = 0
373390
samples_total = len(samples[self.signal]['samples'])
374391

375-
estimated_blksize = self.coherent_ms * self.sampling_freq / 1e3
392+
estimated_blksize = 2 * self.coherent_ms * self.sampling_freq / 1e3
376393

377-
self.track_result.status = 'T'
394+
if estimated_blksize > self.samples_to_track:
395+
raise ValueError("Sample file too short")
378396

379-
while self.samples_tracked < self.samples_to_track and \
380-
(sample_index + 2 * estimated_blksize) < samples_total:
397+
# check if there is a problem with batch size unless we are at the last
398+
# batch
399+
if ((sample_index + estimated_blksize) > samples_total and
400+
self.samples_to_track - self.samples_tracked > estimated_blksize):
401+
logging.error("Sample batch too small")
402+
raise ValueError("Sample batch too small")
381403

404+
self.track_result.status = 'T'
405+
406+
while (self.samples_tracked < self.samples_to_track and
407+
(sample_index + estimated_blksize) < samples_total):
382408
self._run_preprocess()
383409

410+
lf_dict = self.loop_filter.to_dict()
384411
if self.pipelining:
385412
# Pipelining and prediction
386413
corr_code_freq = self.next_code_freq
387414
corr_carr_freq = self.next_carr_freq
388415

389-
self.next_code_freq = self.loop_filter.to_dict()['code_freq']
390-
self.next_carr_freq = self.loop_filter.to_dict()['carr_freq']
416+
self.next_code_freq = lf_dict['code_freq']
417+
self.next_carr_freq = lf_dict['carr_freq']
391418

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

407434
else:
408435
# 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']
436+
self.next_code_freq = lf_dict['code_freq']
437+
self.next_carr_freq = lf_dict['carr_freq']
411438

412439
corr_code_freq = self.next_code_freq
413440
corr_carr_freq = self.next_carr_freq
414441

415442
coherent_iter, code_chips_to_integrate = self._short_n_long_preprocess()
416443

444+
coherent_idx = 0
445+
# Store state in case of insufficient sample count left
446+
self.store_track_state()
447+
code_freq = corr_code_freq + self.chipping_rate
448+
code_step = code_freq / self.sampling_freq
449+
417450
for _ in range(self.coherent_iter):
418451

419-
if (sample_index + 2 * estimated_blksize) >= samples_total:
420-
break
452+
if (sample_index + coherent_idx + code_step * code_chips_to_integrate >=
453+
samples_total):
454+
# Restore state because loop cannot be finished
455+
self.restore_track_state()
456+
self.sample_index += samples_processed
457+
return self._get_result()
421458

422-
samples_ = samples[self.signal]['samples'][sample_index:]
459+
samples_ =\
460+
samples[self.signal]['samples'][(sample_index + coherent_idx):]
423461

424-
E_, P_, L_, blksize, self.code_phase, self.carr_phase = self.correlator(
462+
E_, P_, L_, blksize, self.code_phase, self.carr_phase = \
463+
self.correlator(
425464
samples_,
426465
code_chips_to_integrate,
427-
corr_code_freq + self.chipping_rate, self.code_phase,
466+
code_freq, self.code_phase,
428467
corr_carr_freq + self.IF, self.carr_phase,
429468
self.prn_code,
430469
self.sampling_freq,
431-
self.signal
432-
)
470+
self.signal)
433471

434472
if blksize > estimated_blksize:
435-
estimated_blksize = blksize
473+
estimated_blksize = 2 * blksize
436474

437-
sample_index += blksize
438-
samples_processed += blksize
475+
coherent_idx += blksize
439476
self.carr_phase_acc += corr_carr_freq * blksize / self.sampling_freq
440477
self.code_phase_acc += corr_code_freq * blksize / self.sampling_freq
441478

442479
self.E += E_
443480
self.P += P_
444481
self.L += L_
445482

483+
sample_index += coherent_idx
484+
samples_processed += coherent_idx
485+
446486
more_integration_needed = self._short_n_long_postprocess()
447487
if more_integration_needed:
448488
continue

0 commit comments

Comments
 (0)