Created
July 18, 2017 20:08
-
-
Save daniestevez/ff4b61376828352a9320ecc81580a34b to your computer and use it in GitHub Desktop.
Test for Decode CCSDS 27 degradation bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
import math | |
import numpy | |
from gnuradio import gr, digital | |
from gnuradio import blocks | |
from gnuradio import fec | |
# Best to choose powers of 10 | |
N_BITS = 1e8 | |
SKIP = 1000 | |
class BitErrors(gr.hier_block2): | |
def __init__(self): | |
gr.hier_block2.__init__(self, "BitErrors", | |
gr.io_signature(1, 1, gr.sizeof_char), | |
gr.io_signature(1, 1, gr.sizeof_int)) | |
# Bit comparison | |
intdump_decim = 100000 | |
self.connect(self, | |
# skip first samples | |
blocks.skiphead(gr.sizeof_char, SKIP), | |
# exchange 0 <-> 1 | |
blocks.not_bb(), | |
blocks.and_const_bb(1), | |
# average over blocks of intdump_decim samples | |
blocks.uchar_to_float(), | |
blocks.integrate_ff(intdump_decim), | |
blocks.multiply_const_ff(1.0/intdump_decim), | |
self) | |
class BERAWGNSimu(gr.top_block): | |
" This contains the simulation flow graph " | |
def __init__(self, use_decode_ccsds_27): | |
gr.top_block.__init__(self) | |
self.sink = blocks.vector_sink_f() | |
descrambler = digital.descrambler_bb(0x21, 0x00, 16) | |
add_const = blocks.add_const_ff(-0.5) | |
# generate stream of 1's, G3RUH scramble and CC-encode | |
self.connect(blocks.vector_source_b([1]*int(N_BITS), False), | |
digital.scrambler_bb(0x21, 0x00, 16), | |
blocks.pack_k_bits_bb(8), | |
fec.encode_ccsds_27_bb(), | |
blocks.uchar_to_float(), | |
add_const) | |
if use_decode_ccsds_27: | |
# CC-decode with decode_ccsds_27_fb | |
self.connect(add_const, | |
fec.decode_ccsds_27_fb(), | |
blocks.unpack_k_bits_bb(8), | |
descrambler) | |
else: | |
# CC-decode with fec.cc_decoder | |
self.connect(add_const, | |
fec.extended_decoder(fec.cc_decoder.make(800, 7, 2, [109, 79]), None), | |
descrambler) | |
# G3RUH descrambler and count bit errors | |
self.connect(descrambler, | |
digital.descrambler_bb(0x21, 0x00, 16), | |
BitErrors(), | |
self.sink) | |
if __name__ == "__main__": | |
print 'BER with decode_ccsds_27_fb' | |
fg = BERAWGNSimu(True) | |
fg.run() | |
print fg.sink.data() | |
print 'BER with fec.cc_decoder' | |
fg = BERAWGNSimu(False) | |
fg.run() | |
print fg.sink.data() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment