34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
import numpy as np
|
|
|
|
from galileo_rx.navigation.inav_fec import InavViterbiDecoder
|
|
from tests.navigation.test_deinterleaver import ENCODED
|
|
|
|
|
|
SOURCE = (
|
|
"1111111111110000110011001010101000000000000011110011001101010101"
|
|
"11100011111011001101111110001010000111000001001101000000"
|
|
)
|
|
|
|
|
|
def test_hard_and_soft_viterbi_against_independent_icd_vector() -> None:
|
|
coded = np.fromiter(map(int, ENCODED), dtype=np.int8)
|
|
decoder = InavViterbiDecoder(traceback_depth=35)
|
|
hard = decoder.decode(coded, mode="hard")
|
|
soft = decoder.decode(np.where(coded, 4.0, -4.0), mode="soft")
|
|
assert hard.valid and soft.valid
|
|
assert "".join(map(str, hard.decoded_bits)) == SOURCE
|
|
assert hard.decoded_bits == soft.decoded_bits
|
|
|
|
|
|
def test_soft_viterbi_corrects_individual_and_burst_errors() -> None:
|
|
coded = np.fromiter(map(int, ENCODED), dtype=np.int8)
|
|
soft = np.where(coded, 5.0, -5.0)
|
|
soft[[20, 81, 177]] *= -1.0
|
|
soft[120:124] *= -1.0
|
|
result = InavViterbiDecoder().decode(soft, mode="soft")
|
|
assert result.valid
|
|
assert "".join(map(str, result.decoded_bits)) == SOURCE
|
|
assert result.corrected_error_metric == 7.0
|