import numpy as np from galileo_rx.tracking.symbol_sync import ( compare_symbol_streams, recover_bpsk_symbols, synchronize_secondary_code, ) def test_raw_symbol_recovery_and_bounded_sign_alignment() -> None: truth = np.asarray([1, -1, -1, 1, 1, -1], dtype=np.int8) prompts = np.repeat(-truth, 2).astype(np.complex128) * (10 + 1j) recovered, values = recover_bpsk_symbols(prompts, 2) assert values.dtype == np.float64 result = compare_symbol_streams(recovered, truth, max_alignment_offset_symbols=1) assert result.sign_inverted assert result.symbol_errors == 0 def test_joint_secondary_phase_and_frequency_sync() -> None: secondary = np.asarray([1, 1, -1, 1, -1], dtype=np.int8) phase = 3 residual_hz = 17.0 dt = 0.004 epochs = np.arange(40) prompts = secondary[(phase + epochs) % secondary.size] * np.exp(1j * (0.7 + 2 * np.pi * residual_hz * dt * epochs)) result = synchronize_secondary_code(prompts, secondary, dt, residual_frequency_min_hz=-30, residual_frequency_max_hz=30) assert result.phase == phase assert result.residual_frequency_hz == residual_hz assert result.normalized_correlation > 0.999999 assert result.sign_errors == 0