Example #1
0
    def est_loopback_003(self):
        """
        Loopback randomizer/rs_encoder/interleaver/trellis_encoder
	via ds_to_softds to
	viterbi_decoder/deinterleaver/rs_decoder/derandomizer
        """
        src_data = make_transport_stream()
        interleaver_delay = 52
        viterbi_delay = 12
        expected_result = src_data[0:len(src_data) - (
            (interleaver_delay + viterbi_delay) * atsc.ATSC_MPEG_PKT_LENGTH)]

        src = vector_source_ts(src_data)
        rand = atsc.randomizer()
        rs_enc = atsc.rs_encoder()
        inter = atsc.interleaver()
        trellis = atsc.trellis_encoder()
        softds = atsc.ds_to_softds()
        viterbi = atsc.viterbi_decoder()
        deinter = atsc.deinterleaver()
        rs_dec = atsc.rs_decoder()
        derand = atsc.derandomizer()
        dst = vector_sink_ts()
        self.tb.connect(src, rand, rs_enc, inter, trellis, softds, viterbi,
                        deinter, rs_dec, derand, dst)
        self.tb.run()
        result_data = dst.data()[((interleaver_delay + viterbi_delay) *
                                  atsc.ATSC_MPEG_PKT_LENGTH):len(dst.data())]
        self.assertEqual(expected_result, result_data)
Example #2
0
    def est_loopback_003(self):
        """
        Loopback randomizer/rs_encoder/interleaver/trellis_encoder
	via ds_to_softds to
	viterbi_decoder/deinterleaver/rs_decoder/derandomizer
        """
        src_data = make_transport_stream()
	interleaver_delay = 52
	viterbi_delay = 12
        expected_result = src_data[0:len(src_data)-((interleaver_delay+viterbi_delay)*atsc.ATSC_MPEG_PKT_LENGTH)]

        src = vector_source_ts(src_data)
        rand = atsc.randomizer()
        rs_enc = atsc.rs_encoder()
        inter = atsc.interleaver()
	trellis = atsc.trellis_encoder()
	softds = atsc.ds_to_softds()
	viterbi = atsc.viterbi_decoder()
        deinter = atsc.deinterleaver()
        rs_dec = atsc.rs_decoder()
        derand = atsc.derandomizer()
        dst = vector_sink_ts()
	self.tb.connect(src, rand, rs_enc, inter, trellis, softds, viterbi, deinter, rs_dec, derand, dst)
        self.tb.run ()
        result_data = dst.data ()[((interleaver_delay+viterbi_delay)*atsc.ATSC_MPEG_PKT_LENGTH):len(dst.data())]
        self.assertEqual (expected_result, result_data)
def main(args):
    nargs = len(args)
    if nargs == 1:
        infile = args[0]
        outfile = None
    elif nargs == 2:
        infile = args[0]
        outfile = args[1]
    else:
        sys.stderr.write("Usage: atsc-blade.py input_file [output_file]\n")
        sys.exit(1)

    symbol_rate = 4500000.0 / 286 * 684
    pilot_freq = 309441
    center_freq = 441000000
    txvga1_gain = -4
    txvga2_gain = 25

    tb = gr.top_block()

    src = blocks.file_source(gr.sizeof_char, infile, True)

    pad = atsc.pad()
    rand = atsc.randomizer()
    rs_enc = atsc.rs_encoder()
    inter = atsc.interleaver()
    trell = atsc.trellis_encoder()
    fsm = atsc.field_sync_mux()

    v2s = blocks.vector_to_stream(gr.sizeof_char, 1024)
    minn = blocks.keep_m_in_n(gr.sizeof_char, 832, 1024, 4)
    c2sym = digital.chunks_to_symbols_bc(
        ([symbol + 1.25 for symbol in [-7, -5, -3, -1, 1, 3, 5, 7]]), 1)
    offset = analog.sig_source_c(symbol_rate, analog.GR_COS_WAVE,
                                 -3000000 + pilot_freq, 0.9, 0)
    mix = blocks.multiply_vcc(1)
    rrc = filter.fft_filter_ccc(
        1,
        firdes.root_raised_cosine(0.1, symbol_rate, symbol_rate / 2, 0.1152,
                                  100))

    out = osmosdr.sink(args="bladerf=0,buffers=128,buflen=32768")
    out.set_sample_rate(symbol_rate)
    out.set_center_freq(center_freq, 0)
    out.set_freq_corr(0, 0)
    out.set_gain(txvga2_gain, 0)
    out.set_bb_gain(txvga1_gain, 0)
    out.set_bandwidth(6000000, 0)

    tb.connect(src, pad, rand, rs_enc, inter, trell, fsm, v2s, minn, c2sym)
    tb.connect((c2sym, 0), (mix, 0))
    tb.connect((offset, 0), (mix, 1))
    tb.connect(mix, rrc, out)

    if outfile:
        dst = blocks.file_sink(gr.sizeof_gr_complex, outfile)
        tb.connect(rrc, dst)

    tb.run()
Example #4
0
def main(args):
    nargs = len(args)
    if nargs == 1:
        port    = int(args[0])
        outfile = None
    elif nargs == 2:
        port    = int(args[0])
        outfile  = args[1]
    else:
        sys.stderr.write("Usage: atsc-blade.py port [output_file]\n");
        sys.exit(1)

    symbol_rate = 4500000.0 / 286 * 684
    pilot_freq = 309441
    center_freq = 441000000
    tx_gain = 83 # max 89.5

    tb = gr.top_block()

    out = uhd.usrp_sink(
        	device_addr="recv_frame_size=65536,num_recv_frames=128,send_frame_size=65536,num_send_frames=128,master_clock_rate=" + str(symbol_rate*4),
        	stream_args=uhd.stream_args(
        		cpu_format="fc32",
        		otw_format="sc16",
        		channels=range(1),
        	),
        )
    out.set_samp_rate(symbol_rate)
    out.set_center_freq(center_freq, 0)
    out.set_gain(tx_gain, 0)

    #src = blocks.udp_source(gr.sizeof_char*1, "127.0.0.1", port, 18800, True)
    src = grc_blks2.tcp_source(gr.sizeof_char*1, "127.0.0.1", port, True)

    pad = atsc.pad()
    rand = atsc.randomizer()
    rs_enc = atsc.rs_encoder()
    inter = atsc.interleaver()
    trell = atsc.trellis_encoder()
    fsm = atsc.field_sync_mux()

    v2s = blocks.vector_to_stream(gr.sizeof_char, 1024)
    minn = blocks.keep_m_in_n(gr.sizeof_char, 832, 1024, 4)
    c2sym = digital.chunks_to_symbols_bc(([symbol + 1.25 for symbol in [-7,-5,-3,-1,1,3,5,7]]), 1)
    offset = analog.sig_source_c(symbol_rate, analog.GR_COS_WAVE, -3000000 + pilot_freq, 0.9, 0)
    mix = blocks.multiply_vcc(1)
    rrc = filter.fft_filter_ccc(1, firdes.root_raised_cosine(0.1, symbol_rate, symbol_rate/2, 0.1152, 100))

    tb.connect(src, pad, rand, rs_enc, inter, trell, fsm, v2s, minn, c2sym)
    tb.connect((c2sym, 0), (mix, 0))
    tb.connect((offset, 0), (mix, 1))
    tb.connect(mix, rrc, out)

    if outfile:
        dst = blocks.file_sink(gr.sizeof_gr_complex, outfile)
        tb.connect(rrc, dst)

    tb.run()
Example #5
0
def main(args):
    nargs = len(args)
    if nargs == 1:
        infile  = args[0]
        outfile = None
    elif nargs == 2:
        infile  = args[0]
        outfile  = args[1]
    else:
        sys.stderr.write("Usage: atsc-blade.py input_file [output_file]\n");
        sys.exit(1)

    symbol_rate = 4500000.0 / 286 * 684
    pilot_freq = 309441
    center_freq = 441000000
    txvga1_gain = -4
    txvga2_gain = 25

    tb = gr.top_block()

    src = blocks.file_source(gr.sizeof_char, infile, True)

    pad = atsc.pad()
    rand = atsc.randomizer()
    rs_enc = atsc.rs_encoder()
    inter = atsc.interleaver()
    trell = atsc.trellis_encoder()
    fsm = atsc.field_sync_mux()

    v2s = blocks.vector_to_stream(gr.sizeof_char, 1024)
    minn = blocks.keep_m_in_n(gr.sizeof_char, 832, 1024, 4)
    c2sym = digital.chunks_to_symbols_bc(([symbol + 1.25 for symbol in [-7,-5,-3,-1,1,3,5,7]]), 1)
    offset = analog.sig_source_c(symbol_rate, analog.GR_COS_WAVE, -3000000 + pilot_freq, 0.9, 0)
    mix = blocks.multiply_vcc(1)
    rrc_taps = firdes.root_raised_cosine(0.1, symbol_rate*2, symbol_rate/2, 0.1152, 200)
    rrc = filter.rational_resampler_ccc(interpolation=2, decimation=3, taps=rrc_taps, fractional_bw=None, )

    out = osmosdr.sink(args="bladerf=0,buffers=128,buflen=32768")
    out.set_sample_rate(symbol_rate * 2 / 3)
    out.set_center_freq(center_freq, 0)
    out.set_freq_corr(0, 0)
    out.set_gain(txvga2_gain, 0)
    out.set_bb_gain(txvga1_gain, 0)
    out.set_bandwidth(6000000, 0)

    tb.connect(src, pad, rand, rs_enc, inter, trell, fsm, v2s, minn, c2sym)
    tb.connect((c2sym, 0), (mix, 0))
    tb.connect((offset, 0), (mix, 1))
    tb.connect(mix, rrc, out)

    if outfile:
        dst = blocks.file_sink(gr.sizeof_gr_complex, outfile)
        tb.connect(rrc, dst)

    tb.run()
Example #6
0
def main(args):
    nargs = len(args)
    if nargs == 1:
        port    = int(args[0])
        outfile = None
    elif nargs == 2:
        port    = int(args[0])
        outfile  = args[1]
    else:
        sys.stderr.write("Usage: atsc-hackrf.py port [output_file]\n");
        sys.exit(1)

    symbol_rate = 4500000.0 / 286 * 684
    pilot_freq = 309441
    center_freq = 441000000
    rf_gain = 14
    if_gain = 40

    tb = gr.top_block()

    src = grc_blks2.tcp_source(gr.sizeof_char*1, "127.0.0.1", port, True)

    pad = atsc.pad()
    rand = atsc.randomizer()
    rs_enc = atsc.rs_encoder()
    inter = atsc.interleaver()
    trell = atsc.trellis_encoder()
    fsm = atsc.field_sync_mux()

    v2s = blocks.vector_to_stream(gr.sizeof_char, 1024)
    minn = blocks.keep_m_in_n(gr.sizeof_char, 832, 1024, 4)
    c2sym = digital.chunks_to_symbols_bc(([symbol + 1.25 for symbol in [-7,-5,-3,-1,1,3,5,7]]), 1)
    offset = analog.sig_source_c(symbol_rate, analog.GR_COS_WAVE, -3000000 + pilot_freq, 0.9, 0)
    mix = blocks.multiply_vcc(1)
    rrc = filter.fft_filter_ccc(1, firdes.root_raised_cosine(0.1, symbol_rate, symbol_rate/2, 0.1152, 100))

    out = osmosdr.sink(args="hackrf=0")
    out.set_sample_rate(symbol_rate)
    out.set_center_freq(center_freq, 0)
    out.set_freq_corr(0, 0)
    out.set_gain(rf_gain, 0)
    out.set_if_gain(if_gain, 0)
    out.set_bandwidth(6000000, 0)

    tb.connect(src, pad, rand, rs_enc, inter, trell, fsm, v2s, minn, c2sym)
    tb.connect((c2sym, 0), (mix, 0))
    tb.connect((offset, 0), (mix, 1))
    tb.connect(mix, rrc, out)

    if outfile:
        dst = blocks.file_sink(gr.sizeof_gr_complex, outfile)
        tb.connect(rrc, dst)

    tb.run()
Example #7
0
def main(args):
    nargs = len(args)
    if nargs == 1:
        infile = args[0]
        outfile = None
    elif nargs == 2:
        infile = args[0]
        outfile = args[1]
    else:
        sys.stderr.write(
            "Usage: atsc-blade-fpga.py input_file [output_file]\n")
        sys.exit(1)

    symbol_rate = (4500000.0 / 286 * 684) * 3
    center_freq = 429000000
    txvga1_gain = -6
    txvga2_gain = 20

    tb = gr.top_block()

    src = blocks.file_source(gr.sizeof_char, infile, True)

    pad = atsc.pad()
    rand = atsc.randomizer()
    rs_enc = atsc.rs_encoder()
    inter = atsc.interleaver()
    trell = atsc.trellis_encoder()
    fsm = atsc.field_sync_mux()

    v2s = blocks.vector_to_stream(gr.sizeof_char, 1024)
    minn = blocks.keep_m_in_n(gr.sizeof_char, 832, 1024, 4)
    symmap = atscmap.atscmap_bc()

    out = osmosdr.sink(args="bladerf=0")
    out.set_sample_rate(symbol_rate)
    out.set_center_freq(center_freq, 0)
    out.set_freq_corr(0, 0)
    out.set_gain(txvga2_gain, 0)
    out.set_bb_gain(txvga1_gain, 0)
    out.set_bandwidth(6000000, 0)

    tb.connect(src, pad, rand, rs_enc, inter, trell, fsm, v2s, minn, symmap)
    tb.connect(symmap, out)

    if outfile:
        dst = blocks.file_sink(gr.sizeof_gr_complex, outfile)
        tb.connect(symmap, dst)

    tb.run()
Example #8
0
def main(args):
    nargs = len(args)
    if nargs == 1:
        port = int(args[0])
        outfile = None
    elif nargs == 2:
        port = int(args[0])
        outfile = args[1]
    else:
        sys.stderr.write("Usage: atsc-blade.py port [output_file]\n")
        sys.exit(1)

    symbol_rate = 4500000.0 / 286 * 684
    pilot_freq = 309441
    center_freq = 441000000
    tx_gain = 83  # max 89.5

    tb = gr.top_block()

    out = uhd.usrp_sink(
        device_addr=
        "recv_frame_size=65536,num_recv_frames=128,send_frame_size=65536,num_send_frames=128,master_clock_rate="
        + str(symbol_rate * 4),
        stream_args=uhd.stream_args(
            cpu_format="fc32",
            otw_format="sc16",
            channels=range(1),
        ),
    )
    out.set_samp_rate(symbol_rate)
    out.set_center_freq(center_freq, 0)
    out.set_gain(tx_gain, 0)

    #src = blocks.udp_source(gr.sizeof_char*1, "127.0.0.1", port, 18800, True)
    src = grc_blks2.tcp_source(gr.sizeof_char * 1, "127.0.0.1", port, True)

    pad = atsc.pad()
    rand = atsc.randomizer()
    rs_enc = atsc.rs_encoder()
    inter = atsc.interleaver()
    trell = atsc.trellis_encoder()
    fsm = atsc.field_sync_mux()

    v2s = blocks.vector_to_stream(gr.sizeof_char, 1024)
    minn = blocks.keep_m_in_n(gr.sizeof_char, 832, 1024, 4)
    c2sym = digital.chunks_to_symbols_bc(
        ([symbol + 1.25 for symbol in [-7, -5, -3, -1, 1, 3, 5, 7]]), 1)
    offset = analog.sig_source_c(symbol_rate, analog.GR_COS_WAVE,
                                 -3000000 + pilot_freq, 0.9, 0)
    mix = blocks.multiply_vcc(1)
    rrc = filter.fft_filter_ccc(
        1,
        firdes.root_raised_cosine(0.1, symbol_rate, symbol_rate / 2, 0.1152,
                                  100))

    tb.connect(src, pad, rand, rs_enc, inter, trell, fsm, v2s, minn, c2sym)
    tb.connect((c2sym, 0), (mix, 0))
    tb.connect((offset, 0), (mix, 1))
    tb.connect(mix, rrc, out)

    if outfile:
        dst = blocks.file_sink(gr.sizeof_gr_complex, outfile)
        tb.connect(rrc, dst)

    tb.run()
Example #9
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Atsc Blade Fpga")

        ##################################################
        # Variables
        ##################################################
        self.vga2_gain = vga2_gain = 20
        self.vga1_gain = vga1_gain = -8
        self.symbol_rate = symbol_rate = (4500000.0 / 286 * 684) * 3

        ##################################################
        # Blocks
        ##################################################
        _vga2_gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._vga2_gain_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_vga2_gain_sizer,
            value=self.vga2_gain,
            callback=self.set_vga2_gain,
            label="VGA2 Gain",
            converter=forms.int_converter(),
            proportion=0,
        )
        self._vga2_gain_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_vga2_gain_sizer,
            value=self.vga2_gain,
            callback=self.set_vga2_gain,
            minimum=0,
            maximum=25,
            num_steps=25,
            style=wx.SL_HORIZONTAL,
            cast=int,
            proportion=1,
        )
        self.Add(_vga2_gain_sizer)
        _vga1_gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._vga1_gain_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_vga1_gain_sizer,
            value=self.vga1_gain,
            callback=self.set_vga1_gain,
            label="VGA1 Gain",
            converter=forms.int_converter(),
            proportion=0,
        )
        self._vga1_gain_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_vga1_gain_sizer,
            value=self.vga1_gain,
            callback=self.set_vga1_gain,
            minimum=-35,
            maximum=-4,
            num_steps=31,
            style=wx.SL_HORIZONTAL,
            cast=int,
            proportion=1,
        )
        self.Add(_vga1_gain_sizer)
        self.osmosdr_sink_0 = osmosdr.sink(args="numchan=" + str(1) + " " + "")
        self.osmosdr_sink_0.set_sample_rate(symbol_rate)
        self.osmosdr_sink_0.set_center_freq(429000000, 0)
        self.osmosdr_sink_0.set_freq_corr(0, 0)
        self.osmosdr_sink_0.set_gain(vga2_gain, 0)
        self.osmosdr_sink_0.set_if_gain(20, 0)
        self.osmosdr_sink_0.set_bb_gain(vga1_gain, 0)
        self.osmosdr_sink_0.set_antenna("", 0)
        self.osmosdr_sink_0.set_bandwidth(6000000, 0)

        self.blocks_vector_to_stream_1 = blocks.vector_to_stream(
            gr.sizeof_char * 1, 1024)
        self.blocks_keep_m_in_n_0 = blocks.keep_m_in_n(gr.sizeof_char, 832,
                                                       1024, 4)
        self.blocks_file_source_0 = blocks.file_source(
            gr.sizeof_char * 1, "/home/re/xfer/glitchatsc.ts", True)
        self.atscmap_atscmap_bc_0 = atscmap.atscmap_bc()
        self.atsc_trellis_encoder_0 = atsc.trellis_encoder()
        self.atsc_rs_encoder_0 = atsc.rs_encoder()
        self.atsc_random_0 = atsc.randomizer()
        self.atsc_pad_0 = atsc.pad()
        self.atsc_interleaver_0 = atsc.interleaver()
        self.atsc_field_sync_mux_0 = atsc.field_sync_mux()

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_file_source_0, 0), (self.atsc_pad_0, 0))
        self.connect((self.atsc_pad_0, 0), (self.atsc_random_0, 0))
        self.connect((self.atsc_random_0, 0), (self.atsc_rs_encoder_0, 0))
        self.connect((self.atsc_rs_encoder_0, 0), (self.atsc_interleaver_0, 0))
        self.connect((self.atsc_interleaver_0, 0),
                     (self.atsc_trellis_encoder_0, 0))
        self.connect((self.atsc_trellis_encoder_0, 0),
                     (self.atsc_field_sync_mux_0, 0))
        self.connect((self.atsc_field_sync_mux_0, 0),
                     (self.blocks_vector_to_stream_1, 0))
        self.connect((self.blocks_vector_to_stream_1, 0),
                     (self.blocks_keep_m_in_n_0, 0))
        self.connect((self.blocks_keep_m_in_n_0, 0),
                     (self.atscmap_atscmap_bc_0, 0))
        self.connect((self.atscmap_atscmap_bc_0, 0), (self.osmosdr_sink_0, 0))
Example #10
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")

        ##################################################
        # Variables
        ##################################################
        self.symbol_rate = 4500000.0 / 286 * 684
        self.pilot_freq = 309441
        self.center_freq = 683000000
        # increase these to get proper transmission
        self.tx_gain = 75
        self.bandwidth = 6000000

        ##################################################
        # Blocks
        ##################################################
        self.uhd_usrp_sink_0 = uhd.usrp_sink(
            ",".join(("", "")),
            uhd.stream_args(
                cpu_format="fc32",
                channels=range(1),
            ),
        )
        self.uhd_usrp_sink_0.set_samp_rate(self.symbol_rate)
        self.uhd_usrp_sink_0.set_center_freq(self.center_freq, 0)
        self.uhd_usrp_sink_0.set_gain(self.tx_gain, 0)
        self.uhd_usrp_sink_0.set_bandwidth(self.bandwidth, 0)

        pad = atsc.pad()
        rand = atsc.randomizer()
        rs_enc = atsc.rs_encoder()
        inter = atsc.interleaver()
        trell = atsc.trellis_encoder()
        fsm = atsc.field_sync_mux()

        v2s = blocks.vector_to_stream(gr.sizeof_char, 1024)
        minn = blocks.keep_m_in_n(gr.sizeof_char, 832, 1024, 4)
        b2f = blocks.uchar_to_float()
        mul = blocks.multiply_const_vff((2, ))
        add = blocks.add_const_vff((-7 + 1.25, ))
        zero = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 0)
        # rrc = filter.fir_filter_ccf(1, firdes.root_raised_cosine(0.1, symbol_rate, symbol_rate/2, 0.1152, TAPS))
        rrc = filter.fft_filter_ccc(
            1,
            firdes.root_raised_cosine(0.1, self.symbol_rate,
                                      self.symbol_rate / 2, 0.1152, TAPS))
        offset = analog.sig_source_c(self.symbol_rate, analog.GR_COS_WAVE,
                                     -3000000 + self.pilot_freq, 0.9, 0)
        mix = blocks.multiply_vcc(1)
        f2c = blocks.float_to_complex(1)

        src = blocks.file_source(gr.sizeof_char, streamfile, True)

        ##################################################
        # Connections
        ##################################################
        self.connect(src, pad, rand, rs_enc, inter, trell, fsm, v2s, minn, b2f,
                     mul, add)
        self.connect((add, 0), (f2c, 0))
        self.connect((zero, 0), (f2c, 1))
        self.connect((f2c, 0), (mix, 0))
        self.connect((offset, 0), (mix, 1))
        self.connect(mix, rrc, self.uhd_usrp_sink_0)