@@ -344,6 +344,25 @@ def is_pickleable(self):
344
344
"""
345
345
return True
346
346
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
+
364
+ self .stored_track_state = None
365
+
347
366
def run (self , samples ):
348
367
"""
349
368
Run tracking channel for the given batch of data.
@@ -372,22 +391,32 @@ def run(self, samples):
372
391
samples_processed = 0
373
392
samples_total = len (samples [self .signal ]['samples' ])
374
393
375
- estimated_blksize = self .coherent_ms * self .sampling_freq / 1e3
394
+ estimated_blksize = 2 * self .coherent_ms * self .sampling_freq / 1e3
376
395
377
- self .track_result .status = 'T'
396
+ if estimated_blksize > self .samples_to_track :
397
+ raise ValueError ("Sample file too short" )
378
398
379
- while self .samples_tracked < self .samples_to_track and \
380
- (sample_index + 2 * estimated_blksize ) < samples_total :
399
+ # check if there is a problem with batch size unless we are at the last
400
+ # batch
401
+ if ((sample_index + estimated_blksize ) > samples_total and
402
+ self .samples_to_track - self .samples_tracked > estimated_blksize ):
403
+ logging .error ("Sample batch too small" )
404
+ raise ValueError ("Sample batch too small" )
381
405
406
+ self .track_result .status = 'T'
407
+
408
+ while (self .samples_tracked < self .samples_to_track and
409
+ (sample_index + estimated_blksize ) < samples_total ):
382
410
self ._run_preprocess ()
383
411
412
+ lf_dict = self .loop_filter .to_dict ()
384
413
if self .pipelining :
385
414
# Pipelining and prediction
386
415
corr_code_freq = self .next_code_freq
387
416
corr_carr_freq = self .next_carr_freq
388
417
389
- self .next_code_freq = self . loop_filter . to_dict () ['code_freq' ]
390
- self .next_carr_freq = self . loop_filter . to_dict () ['carr_freq' ]
418
+ self .next_code_freq = lf_dict ['code_freq' ]
419
+ self .next_carr_freq = lf_dict ['carr_freq' ]
391
420
392
421
if self .short_n_long and not self .stage1 and not self .short_step :
393
422
# In case of short/long cycles, the correction applicable for the
@@ -406,43 +435,56 @@ def run(self, samples):
406
435
407
436
else :
408
437
# 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' ]
438
+ self .next_code_freq = lf_dict ['code_freq' ]
439
+ self .next_carr_freq = lf_dict ['carr_freq' ]
411
440
412
441
corr_code_freq = self .next_code_freq
413
442
corr_carr_freq = self .next_carr_freq
414
443
415
444
coherent_iter , code_chips_to_integrate = self ._short_n_long_preprocess ()
416
445
446
+ coherent_idx = 0
447
+ # Store state in case of insufficient sample count left
448
+ self .store_track_state ()
449
+ code_freq = corr_code_freq + self .chipping_rate
450
+ code_step = code_freq / self .sampling_freq
451
+
417
452
for _ in range (self .coherent_iter ):
418
453
419
- if (sample_index + 2 * estimated_blksize ) >= samples_total :
420
- break
454
+ if (sample_index + coherent_idx + code_step * code_chips_to_integrate >=
455
+ samples_total ):
456
+ # Restore state because loop cannot be finished
457
+ self .restore_track_state ()
458
+ self .sample_index += samples_processed
459
+ return self ._get_result ()
421
460
422
- samples_ = samples [self .signal ]['samples' ][sample_index :]
461
+ samples_ = \
462
+ samples [self .signal ]['samples' ][(sample_index + coherent_idx ):]
423
463
424
- E_ , P_ , L_ , blksize , self .code_phase , self .carr_phase = self .correlator (
464
+ E_ , P_ , L_ , blksize , self .code_phase , self .carr_phase = \
465
+ self .correlator (
425
466
samples_ ,
426
467
code_chips_to_integrate ,
427
- corr_code_freq + self . chipping_rate , self .code_phase ,
468
+ code_freq , self .code_phase ,
428
469
corr_carr_freq + self .IF , self .carr_phase ,
429
470
self .prn_code ,
430
471
self .sampling_freq ,
431
- self .signal
432
- )
472
+ self .signal )
433
473
434
474
if blksize > estimated_blksize :
435
- estimated_blksize = blksize
475
+ estimated_blksize = 2 * blksize
436
476
437
- sample_index += blksize
438
- samples_processed += blksize
477
+ coherent_idx += blksize
439
478
self .carr_phase_acc += corr_carr_freq * blksize / self .sampling_freq
440
479
self .code_phase_acc += corr_code_freq * blksize / self .sampling_freq
441
480
442
481
self .E += E_
443
482
self .P += P_
444
483
self .L += L_
445
484
485
+ sample_index += coherent_idx
486
+ samples_processed += coherent_idx
487
+
446
488
more_integration_needed = self ._short_n_long_postprocess ()
447
489
if more_integration_needed :
448
490
continue
0 commit comments