Skip to content

Instantly share code, notes, and snippets.

@noc0lour
Created June 26, 2024 13:25
Show Gist options
  • Save noc0lour/36998f9a527aace884c23f9dd8b0ffd4 to your computer and use it in GitHub Desktop.
Save noc0lour/36998f9a527aace884c23f9dd8b0ffd4 to your computer and use it in GitHub Desktop.
import aff3ct
import numpy as np
def test_turbo(info_len=64):
codeword_len = (2 * info_len) + 12
punc_pattern = [[1, ], [1, ], [1, ]]
punc_pattern = [[1, 1], [1, 0], [0, 1, ]]
print('Turbo encoder')
tenc = aff3ct.TurboEncoderLTE(info_len, codeword_len, punc_pattern)
print('Turbo decoder')
tdec = aff3ct.TurboDecoderLTE(info_len, codeword_len, 2, punc_pattern)
print('asserts')
assert tenc.blockLength() == tdec.blockLength()
assert tenc.infoLength() == tdec.infoLength()
print(tenc.blockLength(), tenc.infoLength())
for i in range(100):
d = np.random.randint(0, 2, size=info_len, dtype=np.int32)
tc = tenc.encode(d)
llrs = 1. - 2. * tc
llrs += np.random.uniform(-.1, .1, size=llrs.size)
llrs *= 8.
llrs = llrs.astype(np.float32)
assert tenc.blockLength() == llrs.size
hatd = tdec.decode(llrs)
# print(d == hatd)
# print(np.all(d == hatd))
assert np.all(d == hatd)
if __name__ == "__main__":
test_turbo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment