Skip to content

Instantly share code, notes, and snippets.

@rxseger
Created June 22, 2016 07:33
Show Gist options
  • Save rxseger/37f81328b1c87418d09866877338ded8 to your computer and use it in GitHub Desktop.
Save rxseger/37f81328b1c87418d09866877338ded8 to your computer and use it in GitHub Desktop.
Generated file_atsc_rx2.py from file_atsc_rx2.grc
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# see https://gist.github.com/rxseger/4c6fce39cffa149424a4780a37fae426
##################################################
# GNU Radio Python Flow Graph
# Title: Receive ATSC from UHD
# Generated: Wed Jun 22 00:27:50 2016
##################################################
from gnuradio import analog
from gnuradio import blocks
from gnuradio import dtv
from gnuradio import eng_notation
from gnuradio import filter
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
import osmosdr
import time
class file_atsc_rx2(gr.top_block):
def __init__(self):
gr.top_block.__init__(self, "Receive ATSC from UHD")
##################################################
# Variables
##################################################
self.sps = sps = 1.1
self.atsc_sym_rate = atsc_sym_rate = 4.5e6/286*684
self.samp_rate = samp_rate = 8e6
self.oversampled_rate = oversampled_rate = atsc_sym_rate*sps
self.ATSC_CHANNEL_BW = ATSC_CHANNEL_BW = 6.0e6
##################################################
# Blocks
##################################################
self.rational_resampler_xxx_0 = filter.rational_resampler_ccc(
interpolation=1,
decimation=1,
taps=None,
fractional_bw=None,
)
self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" )
self.osmosdr_source_0.set_sample_rate(samp_rate)
self.osmosdr_source_0.set_center_freq(605e6, 0)
self.osmosdr_source_0.set_freq_corr(0, 0)
self.osmosdr_source_0.set_dc_offset_mode(0, 0)
self.osmosdr_source_0.set_iq_balance_mode(0, 0)
self.osmosdr_source_0.set_gain_mode(False, 0)
self.osmosdr_source_0.set_gain(14, 0)
self.osmosdr_source_0.set_if_gain(16, 0)
self.osmosdr_source_0.set_bb_gain(20, 0)
self.osmosdr_source_0.set_antenna("", 0)
self.osmosdr_source_0.set_bandwidth(0, 0)
self.dtv_atsc_viterbi_decoder_0 = dtv.atsc_viterbi_decoder()
self.dtv_atsc_sync_0 = dtv.atsc_sync(oversampled_rate)
self.dtv_atsc_rx_filter_0 = dtv.atsc_rx_filter(samp_rate,sps)
self.dtv_atsc_rs_decoder_0 = dtv.atsc_rs_decoder()
self.dtv_atsc_fs_checker_0 = dtv.atsc_fs_checker()
self.dtv_atsc_fpll_0 = dtv.atsc_fpll(atsc_sym_rate*sps)
self.dtv_atsc_equalizer_0 = dtv.atsc_equalizer()
self.dtv_atsc_derandomizer_0 = dtv.atsc_derandomizer()
self.dtv_atsc_depad_0 = dtv.atsc_depad()
self.dtv_atsc_deinterleaver_0 = dtv.atsc_deinterleaver()
self.dc_blocker_xx_0 = filter.dc_blocker_ff(int(4.096e3), True)
self.blocks_file_descriptor_sink_0 = blocks.file_descriptor_sink(gr.sizeof_char*1, 1)
self.analog_agc_xx_0 = analog.agc_ff(1e-5, 4.0, 1.0)
self.analog_agc_xx_0.set_max_gain(65536)
##################################################
# Connections
##################################################
self.connect((self.analog_agc_xx_0, 0), (self.dtv_atsc_sync_0, 0))
self.connect((self.dc_blocker_xx_0, 0), (self.analog_agc_xx_0, 0))
self.connect((self.dtv_atsc_deinterleaver_0, 0), (self.dtv_atsc_rs_decoder_0, 0))
self.connect((self.dtv_atsc_depad_0, 0), (self.blocks_file_descriptor_sink_0, 0))
self.connect((self.dtv_atsc_derandomizer_0, 0), (self.dtv_atsc_depad_0, 0))
self.connect((self.dtv_atsc_equalizer_0, 0), (self.dtv_atsc_viterbi_decoder_0, 0))
self.connect((self.dtv_atsc_fpll_0, 0), (self.dc_blocker_xx_0, 0))
self.connect((self.dtv_atsc_fs_checker_0, 0), (self.dtv_atsc_equalizer_0, 0))
self.connect((self.dtv_atsc_rs_decoder_0, 0), (self.dtv_atsc_derandomizer_0, 0))
self.connect((self.dtv_atsc_rx_filter_0, 0), (self.dtv_atsc_fpll_0, 0))
self.connect((self.dtv_atsc_sync_0, 0), (self.dtv_atsc_fs_checker_0, 0))
self.connect((self.dtv_atsc_viterbi_decoder_0, 0), (self.dtv_atsc_deinterleaver_0, 0))
self.connect((self.osmosdr_source_0, 0), (self.rational_resampler_xxx_0, 0))
self.connect((self.rational_resampler_xxx_0, 0), (self.dtv_atsc_rx_filter_0, 0))
def get_sps(self):
return self.sps
def set_sps(self, sps):
self.sps = sps
self.set_oversampled_rate(self.atsc_sym_rate*self.sps)
def get_atsc_sym_rate(self):
return self.atsc_sym_rate
def set_atsc_sym_rate(self, atsc_sym_rate):
self.atsc_sym_rate = atsc_sym_rate
self.set_oversampled_rate(self.atsc_sym_rate*self.sps)
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.osmosdr_source_0.set_sample_rate(self.samp_rate)
def get_oversampled_rate(self):
return self.oversampled_rate
def set_oversampled_rate(self, oversampled_rate):
self.oversampled_rate = oversampled_rate
def get_ATSC_CHANNEL_BW(self):
return self.ATSC_CHANNEL_BW
def set_ATSC_CHANNEL_BW(self, ATSC_CHANNEL_BW):
self.ATSC_CHANNEL_BW = ATSC_CHANNEL_BW
def main(top_block_cls=file_atsc_rx2, options=None):
tb = top_block_cls()
tb.start()
tb.wait()
if __name__ == '__main__':
main()
@mathisono
Copy link

Excellent work and documentation! Im wondering if you have attempted to decode atsc again with your flow chart? 
I don't know if you have seen the Shiny sdr project? https://github.com/kpreid/shinysdr
Im wondering if your interested in porting this flow chart to a shinySDR plugin? https://shinysdr.switchb.org/manual/programming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment