Esempio n. 1
0
    def __init__(self, samp_rate=512e3):
        gr.hier_block2.__init__(
            self,
            "RDS demodulator",
            gr.io_signaturev(
                2, 2, [gr.sizeof_gr_complex * 1, gr.sizeof_gr_complex * 1]),
            gr.io_signaturev(2, 2,
                             [gr.sizeof_char * 1, gr.sizeof_gr_complex * 1]),
        )

        ##################################################
        # Parameters
        ##################################################
        self.samp_rate = samp_rate

        ##################################################
        # Variables
        ##################################################
        self.bitrate = bitrate = 1187.5
        self.syms_rate = syms_rate = 2 * bitrate
        self.samp_per_sym = samp_per_sym = 4
        self.prefix = prefix = "radio/"

        self.variable_constellation_0 = variable_constellation_0 = digital.constellation_bpsk(
        ).base()

        self.fsm = fsm = trellis.fsm(prefix + "diff_manchester.fsm")
        self.decim = decim = int(samp_rate / (samp_per_sym * syms_rate))

        self.RRC_filtr_taps = RRC_filtr_taps = firdes.root_raised_cosine(
            10, samp_rate, syms_rate, 1, int(6 * samp_rate / syms_rate))

        ##################################################
        # Blocks
        ##################################################
        self.trellis_viterbi_x_0 = trellis.viterbi_b(trellis.fsm(fsm), 10000,
                                                     0, -1)
        self.trellis_metrics_x_0 = trellis.metrics_c(
            fsm.O(), 2, (-1, -1, -1, 1, 1, -1, 1, 1),
            digital.TRELLIS_EUCLIDEAN)
        self.fir_filter_xxx_0 = filter.fir_filter_ccf(decim, (RRC_filtr_taps))
        self.fir_filter_xxx_0.declare_sample_delay(0)
        self.digital_lms_dd_equalizer_cc_0_0 = digital.lms_dd_equalizer_cc(
            1, 0.1, 1, variable_constellation_0)
        self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_cc(
            samp_rate / decim / syms_rate, 0.25 * 0.175 * 0.175, 0.5, 0.175,
            0.005)
        self.blocks_multiply_xx_1 = blocks.multiply_vcc(1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_multiply_xx_1, 0),
                     (self.fir_filter_xxx_0, 0))
        self.connect((self.digital_clock_recovery_mm_xx_0, 0),
                     (self.digital_lms_dd_equalizer_cc_0_0, 0))
        self.connect((self.digital_lms_dd_equalizer_cc_0_0, 0), (self, 1))
        self.connect((self.digital_lms_dd_equalizer_cc_0_0, 0),
                     (self.trellis_metrics_x_0, 0))
        self.connect((self.fir_filter_xxx_0, 0),
                     (self.digital_clock_recovery_mm_xx_0, 0))
        self.connect((self, 0), (self.blocks_multiply_xx_1, 1))
        self.connect((self, 1), (self.blocks_multiply_xx_1, 0))
        self.connect((self.trellis_metrics_x_0, 0),
                     (self.trellis_viterbi_x_0, 0))
        self.connect((self.trellis_viterbi_x_0, 0), (self, 0))
def main():
    #pkt_len = 8192
    pkt_len = 32768
    nb_pkt = 100
    EbN0dB = numpy.linspace(0, 10, 11)
    bitrate_trellis_viterbi = numpy.zeros(len(EbN0dB))
    bitrate_viterbi = numpy.zeros(len(EbN0dB))
    bitrate_viterbi_vb = numpy.zeros(len(EbN0dB))
    bitrate_viterbi_vs = numpy.zeros(len(EbN0dB))
    bitrate_lazy = numpy.zeros(len(EbN0dB))
    bitrate_dynamic = numpy.zeros(len(EbN0dB))

    prefix = os.getcwd()
    #fsm = fsm = trellis.fsm(prefix + "/fsm/5_7.fsm")
    #fsm = fsm = trellis.fsm(prefix + "/fsm/229_159.fsm")
    #fsm = fsm = trellis.fsm(prefix + "/fsm/rsc_15_13.fsm")
    fsm = fsm = trellis.fsm(prefix + "/fsm/171_133.fsm")

    trellis_vit_dec = trellis.viterbi_b(trellis.fsm(fsm), pkt_len, 0, -1)
    vit_dec = lv.viterbi(trellis.fsm(fsm), pkt_len, 0, -1)
    vit_vb_dec = lv.viterbi_volk_branch(trellis.fsm(fsm), pkt_len, 0, -1)
    vit_vs_dec = lv.viterbi_volk_state(trellis.fsm(fsm), pkt_len, 0, -1)
    dyn_vit_dec = lv.dynamic_viterbi(trellis.fsm(fsm), pkt_len, 0, -1)
    lazy_dec = lv.lazy_viterbi(trellis.fsm(fsm), pkt_len, 0, -1)

    for i in range(0, len(EbN0dB)):
        print("Eb/N0=" + str(EbN0dB[i]))

        print("Simulating transmission")
        tb = transmitter_channel_metrics(pkt_len, nb_pkt, EbN0dB[i], fsm)
        tb.run()

        metrics = tb.dst.data()

        #Viterbi (gr-trellis)
        tb = ber_vs_ebn0_awgn(metrics, trellis_vit_dec)

        start_time = time.time()
        tb.run()
        elapsed_time = time.time() - start_time

        bitrate_trellis_viterbi[i] = pkt_len * nb_pkt / elapsed_time
        print("Bitrate Viterbi (gr-trellis):\t" +
              str(bitrate_trellis_viterbi[i]))

        #Viterbi (gr-lazyviterbi)
        tb = ber_vs_ebn0_awgn(metrics, vit_dec)

        start_time = time.time()
        tb.run()
        elapsed_time = time.time() - start_time

        bitrate_viterbi[i] = pkt_len * nb_pkt / elapsed_time
        print("Bitrate Viterbi (gr-lazyviterbi):\t" + str(bitrate_viterbi[i]))

        #Viterbi volk branch
        tb = ber_vs_ebn0_awgn(metrics, vit_vb_dec)

        start_time = time.time()
        tb.run()
        elapsed_time = time.time() - start_time

        bitrate_viterbi_vb[i] = pkt_len * nb_pkt / elapsed_time
        print("Bitrate Viterbi volk branch:\t" + str(bitrate_viterbi_vb[i]))

        #Viterbi volk state
        tb = ber_vs_ebn0_awgn(metrics, vit_vs_dec)

        start_time = time.time()
        tb.run()
        elapsed_time = time.time() - start_time

        bitrate_viterbi_vs[i] = pkt_len * nb_pkt / elapsed_time
        print("Bitrate Viterbi volk state:\t" + str(bitrate_viterbi_vs[i]))

        #Lazy Viterbi
        tb = ber_vs_ebn0_awgn(metrics, lazy_dec)

        start_time = time.time()
        tb.run()
        elapsed_time = time.time() - start_time

        bitrate_lazy[i] = pkt_len * nb_pkt / elapsed_time
        print("Bitrate Lazy:\t\t" + str(bitrate_lazy[i]))

        #Dynamic Viterbi
        tb = ber_vs_ebn0_awgn(metrics, dyn_vit_dec)

        start_time = time.time()
        tb.run()
        elapsed_time = time.time() - start_time

        bitrate_dynamic[i] = pkt_len * nb_pkt / elapsed_time
        print("Bitrate Dynamic:\t\t" + str(bitrate_dynamic[i]))

        print("")

    #Plot results
    plt.plot(EbN0dB,
             bitrate_trellis_viterbi,
             '-*',
             label="Viterbi (gr-trellis)")
    plt.plot(EbN0dB, bitrate_viterbi, '-+', label="Viterbi")
    plt.plot(EbN0dB, bitrate_viterbi_vb, '-+', label="Viterbi volk branch")
    plt.plot(EbN0dB, bitrate_viterbi_vs, '-d', label="Viterbi volk state")
    plt.plot(EbN0dB, bitrate_lazy, '-x', label="Lazy Viterbi")
    plt.plot(EbN0dB, bitrate_dynamic, '-o', label="Dynamique")

    plt.grid(which='both')
    plt.ylabel('Debit (bps)')
    plt.xlabel('Eb/N0 (dB)')
    plt.legend()
    plt.show()
Esempio n. 3
0
def main():
    pkt_len = 8192
    #pkt_len = 32768;
    nb_pkt = 100
    EbN0dB = numpy.linspace(0, 10, 11)
    bitrate_trellis_viterbi = numpy.zeros(len(EbN0dB))
    bitrate_viterbi = numpy.zeros(len(EbN0dB))
    bitrate_lazy = numpy.zeros(len(EbN0dB))
    bitrate_dynamic = numpy.zeros(len(EbN0dB))

    prefix = os.getcwd()
    #fsm = fsm = trellis.fsm(prefix + "/fsm/5_7.fsm");
    #fsm = fsm = trellis.fsm(prefix + "/fsm/229_159.fsm");
    fsm = fsm = trellis.fsm(prefix + "/fsm/rsc_15_13.fsm")
    #fsm = fsm = trellis.fsm(prefix + "/fsm/171_133.fsm");

    trellis_vit_dec = trellis.viterbi_b(trellis.fsm(fsm), pkt_len, 0, -1)
    vit_dec = lv.viterbi(trellis.fsm(fsm), pkt_len, 0, -1)
    dyn_vit_dec = lv.dynamic_viterbi(trellis.fsm(fsm), pkt_len, 0, -1)
    lazy_dec = lv.lazy_viterbi(trellis.fsm(fsm), pkt_len, 0, -1)

    for i in range(0, len(EbN0dB)):
        print "Eb/N0=",
        print EbN0dB[i]

        print "Simulating transmission"
        tb = transmitter_channel_metrics(pkt_len, nb_pkt, EbN0dB[i], fsm)
        tb.run()

        metrics = tb.dst.data()

        #Viterbi (gr-trellis)
        tb = ber_vs_ebn0_awgn(metrics, trellis_vit_dec)

        start_time = time.time()
        tb.run()
        elapsed_time = time.time() - start_time

        bitrate_trellis_viterbi[i] = pkt_len * nb_pkt / elapsed_time
        print "Bitrate Viterbi (gr-trellis):\t",
        print bitrate_trellis_viterbi[i]

        #Viterbi (gr-lazyviterbi)
        tb = ber_vs_ebn0_awgn(metrics, vit_dec)

        start_time = time.time()
        tb.run()
        elapsed_time = time.time() - start_time

        bitrate_viterbi[i] = pkt_len * nb_pkt / elapsed_time
        print "Bitrate Viterbi (gr-lazyviterbi):\t",
        print bitrate_viterbi[i]

        #Lazy Viterbi
        tb = ber_vs_ebn0_awgn(metrics, lazy_dec)

        start_time = time.time()
        tb.run()
        elapsed_time = time.time() - start_time

        bitrate_lazy[i] = pkt_len * nb_pkt / elapsed_time
        print "Bitrate Lazy:\t\t",
        print bitrate_lazy[i]

        #Dynamic Viterbi
        tb = ber_vs_ebn0_awgn(metrics, dyn_vit_dec)

        start_time = time.time()
        tb.run()
        elapsed_time = time.time() - start_time

        bitrate_dynamic[i] = pkt_len * nb_pkt / elapsed_time
        print "Bitrate Dynamic:\t\t",
        print bitrate_dynamic[i]

        print ""

    #Plot results
    trellis_viterbi_plot = plt.plot(EbN0dB,
                                    bitrate_trellis_viterbi,
                                    '-*',
                                    label="Viterbi (gr-trellis)")
    viterbi_plot = plt.plot(EbN0dB,
                            bitrate_viterbi,
                            '-+',
                            label="Viterbi (gr-lazyviterbi)")
    lazy_plot = plt.plot(EbN0dB, bitrate_lazy, '-x', label="Lazy")
    dynamic_viterbi_plot = plt.plot(EbN0dB,
                                    bitrate_dynamic,
                                    '-o',
                                    label="Dynamic")

    plt.grid(which='both')
    plt.ylabel('Bitrate (bps)')
    plt.xlabel('Eb/N0 (dB)')
    plt.legend()
    plt.show()
Esempio n. 4
0
    def __init__(self, pkt_len, nb_pkt, EbN0dB):
        gr.top_block.__init__(self, "BER vs Eb/N0 (7,5) AWGN")

        ##################################################
        # Variables
        ##################################################
        self.prefix = prefix = os.getcwd()
        self.pkt_len = pkt_len
        #self.fsm = fsm = trellis.fsm(prefix + "/fsm/229_159.fsm")
        #self.fsm = fsm = trellis.fsm(prefix + "/fsm/rsc_15_13.fsm")
        #self.fsm = fsm = trellis.fsm(prefix + "/fsm/171_133.fsm")
        self.fsm = fsm = trellis.fsm(prefix + "/fsm/5_7.fsm")
        Rc = 0.5
        self.const = const = digital.constellation_bpsk().base()

        var_c = 1
        Nb = 1
        Eb = var_c / (2.0 * Nb * Rc)
        N0 = Eb * 10**(-EbN0dB / 10.0)
        noisevar = 2 * N0

        ##################################################
        # Blocks
        ##################################################
        self.bits_src = blocks.vector_source_b(
            numpy.random.randint(0, 2, nb_pkt * pkt_len), False)
        self.trellis_encoder = trellis.encoder_bb(trellis.fsm(fsm), 0, pkt_len)
        self.unpack = blocks.unpack_k_bits_bb(2)
        self.pack_src = blocks.pack_k_bits_bb(8)
        self.to_symbols = digital.chunks_to_symbols_bc((const.points()), 1)

        self.noise_src = analog.noise_source_c(analog.GR_GAUSSIAN, noisevar, 0)
        self.noise_adder = blocks.add_vcc(1)

        self.metrics_computer = trellis.metrics_c(
            4, 2, ([-1, -1, -1, 1, 1, -1, 1, 1]), digital.TRELLIS_EUCLIDEAN)

        self.trellis_viterbi = trellis.viterbi_b(trellis.fsm(fsm), pkt_len, 0,
                                                 -1)
        self.viterbi = lv.viterbi(trellis.fsm(fsm), pkt_len, 0, -1)
        self.lazy = lv.lazy_viterbi(trellis.fsm(fsm), pkt_len, 0, -1)
        self.viterbi_vb = lv.viterbi_volk_branch(trellis.fsm(fsm), pkt_len, 0,
                                                 -1)
        self.viterbi_vs = lv.viterbi_volk_state(trellis.fsm(fsm), pkt_len, 0,
                                                -1)

        self.pack_trellis_viterbi = blocks.pack_k_bits_bb(8)
        self.pack_viterbi = blocks.pack_k_bits_bb(8)
        self.pack_lazy = blocks.pack_k_bits_bb(8)
        self.pack_viterbi_vb = blocks.pack_k_bits_bb(8)
        self.pack_viterbi_vs = blocks.pack_k_bits_bb(8)

        self.ber_computer_trellis_viterbi = fec.ber_bf(False)
        self.ber_computer_viterbi = fec.ber_bf(False)
        self.ber_computer_lazy = fec.ber_bf(False)
        self.ber_computer_viterbi_vb = fec.ber_bf(False)
        self.ber_computer_viterbi_vs = fec.ber_bf(False)

        self.vector_sink_trellis_viterbi = blocks.vector_sink_f()
        self.vector_sink_viterbi = blocks.vector_sink_f()
        self.vector_sink_lazy = blocks.vector_sink_f()
        self.vector_sink_viterbi_vb = blocks.vector_sink_f()
        self.vector_sink_viterbi_vs = blocks.vector_sink_f()

        ##################################################
        # Connections
        ##################################################

        self.connect((self.bits_src, 0), (self.trellis_encoder, 0))
        self.connect((self.trellis_encoder, 0), (self.unpack, 0))
        self.connect((self.unpack, 0), (self.to_symbols, 0))

        self.connect((self.to_symbols, 0), (self.noise_adder, 0))
        self.connect((self.noise_src, 0), (self.noise_adder, 1))
        self.connect((self.noise_adder, 0), (self.metrics_computer, 0))

        self.connect((self.metrics_computer, 0), (self.trellis_viterbi, 0))
        self.connect((self.metrics_computer, 0), (self.viterbi, 0))
        self.connect((self.metrics_computer, 0), (self.lazy, 0))
        self.connect((self.metrics_computer, 0), (self.viterbi_vb, 0))
        self.connect((self.metrics_computer, 0), (self.viterbi_vs, 0))

        self.connect((self.bits_src, 0), (self.pack_src, 0))
        self.connect((self.trellis_viterbi, 0), (self.pack_trellis_viterbi, 0))
        self.connect((self.viterbi, 0), (self.pack_viterbi, 0))
        self.connect((self.lazy, 0), (self.pack_lazy, 0))
        self.connect((self.viterbi_vb, 0), (self.pack_viterbi_vb, 0))
        self.connect((self.viterbi_vs, 0), (self.pack_viterbi_vs, 0))

        self.connect((self.pack_src, 0),
                     (self.ber_computer_trellis_viterbi, 0))
        self.connect((self.pack_src, 0), (self.ber_computer_viterbi, 0))
        self.connect((self.pack_src, 0), (self.ber_computer_lazy, 0))
        self.connect((self.pack_src, 0), (self.ber_computer_viterbi_vb, 0))
        self.connect((self.pack_src, 0), (self.ber_computer_viterbi_vs, 0))

        self.connect((self.pack_trellis_viterbi, 0),
                     (self.ber_computer_trellis_viterbi, 1))
        self.connect((self.pack_viterbi, 0), (self.ber_computer_viterbi, 1))
        self.connect((self.pack_lazy, 0), (self.ber_computer_lazy, 1))
        self.connect((self.pack_viterbi_vb, 0),
                     (self.ber_computer_viterbi_vb, 1))
        self.connect((self.pack_viterbi_vs, 0),
                     (self.ber_computer_viterbi_vs, 1))

        self.connect((self.ber_computer_trellis_viterbi, 0),
                     (self.vector_sink_trellis_viterbi, 0))
        self.connect((self.ber_computer_viterbi, 0),
                     (self.vector_sink_viterbi, 0))
        self.connect((self.ber_computer_lazy, 0), (self.vector_sink_lazy, 0))
        self.connect((self.ber_computer_viterbi_vb, 0),
                     (self.vector_sink_viterbi_vb, 0))
        self.connect((self.ber_computer_viterbi_vs, 0),
                     (self.vector_sink_viterbi_vs, 0))