Пример #1
0
	def setup_flowgraph(self, mode, ber_skipbytes=0):
		# parameters
		self.dp.set_mode(mode)
		self.rp.set_mode(mode)
		self.vlen = self.dp.num_carriers/4
		self.ber_skipbytes = ber_skipbytes

		# trigger signals
		frame_trigger = [1]+[0]*(self.dp.symbols_per_frame-2)
		self.frame_start = frame_trigger*(len(self.random_bytes)/(self.vlen*(self.dp.symbols_per_frame-1)))+frame_trigger[0:(len(self.random_bytes)/self.vlen)%(self.dp.symbols_per_frame-1)]

		# sources/sinks
		self.source    = gr.vector_source_b(self.random_bytes, False)
		self.trig      = gr.vector_source_b(self.frame_start, False)
		if self.ber_sink:
			self.sink = grdab.blocks.measure_ber_b()
		else:
			self.sink = gr.vector_sink_b()

		# self.noise_start      = gr.noise_source_c(gr.GR_GAUSSIAN, math.sqrt(2), random.randint(0,10000))
		# self.noise_start_head = gr.head(gr.sizeof_gr_complex, NOISE_SAMPLES_AT_START)
		# self.noise_end        = gr.noise_source_c(gr.GR_GAUSSIAN, math.sqrt(2), random.randint(0,10000))
		# self.noise_end_head   = gr.head(gr.sizeof_gr_complex, NOISE_SAMPLES_AT_END)
		
		# blocks
		self.s2v       = gr.stream_to_vector(gr.sizeof_char, self.vlen)
		self.v2s       = gr.vector_to_stream(gr.sizeof_char, self.vlen)
		if self.ber_sink:
			self.ber_skipbytes0 = gr.skiphead(gr.sizeof_char, self.ber_skipbytes)
			self.ber_skipbytes1 = gr.skiphead(gr.sizeof_char, self.ber_skipbytes+self.dp.bytes_per_frame)
		
		# more blocks (they have state, so better reinitialise them)
		self.mod       = grdab.ofdm_mod(self.dp, debug = False)
		self.rescale   = gr.multiply_const_cc(1)
		self.amp       = gr.multiply_const_cc(1)
		self.channel   = blks2.channel_model(noise_voltage=0, noise_seed=random.randint(0,10000))
		# self.cat       = grdab.concatenate_signals(gr.sizeof_gr_complex)
		self.demod     = grdab.ofdm_demod(self.dp, self.rp, debug = False, verbose = True)

		# connect it all
		if self.ber_sink:
			self.connect(self.source, self.s2v, (self.mod,0), self.rescale, self.amp, self.channel, (self.demod,0), self.v2s, self.ber_skipbytes0, self.sink)
			self.connect(self.source, self.ber_skipbytes1, (self.sink,1))
		else:
			self.connect(self.source, self.s2v, (self.mod,0), self.rescale, self.amp, self.channel, (self.demod,0), self.v2s, self.sink)
		self.connect(self.trig, (self.mod,1))

		# SNR calculation and prober
		self.probe_signal = gr.probe_avg_mag_sqrd_c(0,0.00001)
		self.probe_total  = gr.probe_avg_mag_sqrd_c(0,0.00001)
		self.connect(self.amp, self.probe_signal)
		self.connect(self.channel, self.probe_total)
Пример #2
0
	def clear_state(self):
		if self.ber_sink:
			self.ber_skipbytes0.rewind()
			self.ber_skipbytes1.rewind()
		# self.cat.reset()
		self.demod.clear_state()

		# TODO some state is still left in the demod block - for now just make a new one
		self.disconnect(self.channel, self.demod)
		self.disconnect((self.demod,0), self.v2s)
		self.demod = grdab.ofdm_demod(self.dp, self.rp, debug = False, verbose = True)
		self.connect(self.channel, self.demod)
		self.connect((self.demod,0), self.v2s)
Пример #3
0
    def clear_state(self):
        if self.ber_sink:
            self.ber_skipbytes0.rewind()
            self.ber_skipbytes1.rewind()
        # self.cat.reset()
        self.demod.clear_state()

        # TODO some state is still left in the demod block - for now just make a new one
        self.disconnect(self.channel, self.demod)
        self.disconnect((self.demod, 0), self.v2s)
        self.demod = grdab.ofdm_demod(self.dp,
                                      self.rp,
                                      debug=False,
                                      verbose=True)
        self.connect(self.channel, self.demod)
        self.connect((self.demod, 0), self.v2s)
Пример #4
0
	def __init__(self):
		gr.top_block.__init__(self)

		usage = "%prog: [options] samples_file"
		parser = OptionParser(option_class=eng_option, usage=usage)
  		parser.add_option("-m", "--dab-mode", type="int", default=1,
        	     	help="DAB mode [default=%default]")
		parser.add_option("-F", "--filter-input", action="store_true", default=False,
                          help="Enable FFT filter at input")
  		parser.add_option("-s", "--resample-fixed", type="eng_float", default=1,
			help="resample by a fixed factor (fractional interpolation)")
		parser.add_option("-S", "--autocorrect-sample-rate", action="store_true", default=False,
                          help="Estimate sample rate offset and resample (dynamic fractional interpolation)")
  		parser.add_option('-u', '--usrp-source', action="store_true", default=False,
	     		help="Samples from USRP (-> adjust params for 2 MSPS)")
  		parser.add_option('-d', '--debug', action="store_true", default=False,
	     		help="Write output to files")
  		parser.add_option('-v', '--verbose', action="store_true", default=False,
	     		help="Print status messages")
		(options, args) = parser.parse_args ()
	
		if options.usrp_source:
			dp = grdab.dab_parameters(options.dab_mode, verbose=options.verbose, sample_rate=2000000)
		else:
			dp = grdab.dab_parameters(options.dab_mode, verbose=options.verbose)

		rp = grdab.receiver_parameters(options.dab_mode, softbits=True, input_fft_filter=options.filter_input, autocorrect_sample_rate=options.autocorrect_sample_rate, sample_rate_correction_factor=options.resample_fixed, correct_ffe=True, equalize_magnitude=True, verbose=options.verbose)

		if len(args)<1:
			print "error: need file with samples"
			sys.exit(1)
		else:
			filename = args[0]
			if options.verbose: print "--> using samples from file " + filename
			self.src = gr.file_source(gr.sizeof_gr_complex, filename, False)

		
		self.dab_demod = grdab.ofdm_demod(dp, rp, verbose=options.verbose, debug=options.debug)
		self.fic_dec   = grdab.fic_decode(dp, verbose=options.verbose, debug=options.debug)
		
		self.connect(self.src, self.dab_demod, self.fic_dec)
		self.connect((self.dab_demod,1), (self.fic_dec,1))
Пример #5
0
def main(rf_gain, if_gain, bb_gain, ppm, use_zeromq_in=False, server="tcp://127.0.0.1:10444", server_control="tcp://127.0.0.1:10445"):
    global src
    global decoder
    global dab_ofdm_demod_0
    global c2f
    global f2c
    global audio_sink_0
    global fg
    global xrun_monitor
    global use_zeromq
    global rpc_mgr_server
    global dab_ofdm_demod_0
    global ppm_shared
    frequency=220.352e6
    audio_sample_rate=48000
    ppm_shared = ppm
    dab_bit_rate=64
    dab_address=304
    dab_subch_size=64
    dab_protect_level=1
    use_zeromq=use_zeromq_in
    if use_zeromq:
        from gnuradio import zeromq
    else:
        import osmosdr
    import time

    if len(channel_list) > 0:
        ch = channel_list[0]
        frequency = float(ch['frequency'])*1e6
    else:
        ch = {"bit_rate" : 64, "address" : 304, "subch_size" : 64, "protect_level" : 1}

    print("Setting frequency: %0.3f MHz" % (frequency/1e6))

    if not use_zeromq:
        osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + '' )
        osmosdr_source_0.set_sample_rate(samp_rate)
        osmosdr_source_0.set_center_freq(frequency, 0)
        osmosdr_source_0.set_freq_corr(0, 0)
        osmosdr_source_0.set_dc_offset_mode(0, 0)
        osmosdr_source_0.set_iq_balance_mode(0, 0)
        osmosdr_source_0.set_gain_mode(False, 0)
        osmosdr_source_0.set_gain(rf_gain, 0)
        osmosdr_source_0.set_if_gain(if_gain, 0)
        osmosdr_source_0.set_bb_gain(bb_gain, 0)
        osmosdr_source_0.set_antenna('RX2', 0)
        osmosdr_source_0.set_bandwidth(2000000, 0)
    else:
        zeromq_source = zeromq.sub_source(gr.sizeof_gr_complex, 1, server, 100, False, -1)
        rpc_mgr_server = zeromq.rpc_manager()
        rpc_mgr_server.set_request_socket(server_control)
        rpc_mgr_server.request("set_sample_rate",[samp_rate])
        rpc_mgr_server.request("set_rf_gain",[rf_gain])
        rpc_mgr_server.request("set_if_gain",[if_gain])
        rpc_mgr_server.request("set_bb_gain",[bb_gain])
        rpc_mgr_server.request("set_ppm",[0]) # Not using hardware correction since it behaves differently on different hardware
        rpc_mgr_server.request("set_frequency",[frequency])
        time.sleep(0.7)

    sample_rate_correction_factor = 1 + float(ppm_shared)*1e-6
    dab_ofdm_demod_0 = grdab.ofdm_demod(
              grdab.parameters.dab_parameters(
                mode=1,
                sample_rate=samp_rate,
                verbose=False
              ),
              grdab.parameters.receiver_parameters(
                mode=1,
                softbits=True,
                input_fft_filter=True,
                autocorrect_sample_rate=False,
                sample_rate_correction_factor=sample_rate_correction_factor,
                always_include_resample=True,
                verbose=False,
                correct_ffe=True,
                equalize_magnitude=True
              )
            )

    if 'classic' in ch and ch['classic'] == True:
        dabplus = False
    else:
        dabplus = True

    if dabplus:
        decoder = grdab.dabplus_audio_decoder_ff(grdab.parameters.dab_parameters(mode=1, sample_rate=samp_rate, verbose=False), ch['bit_rate'], ch['address'], ch['subch_size'], ch['protect_level'], True)
    else:
        decoder = grdab.dab_audio_decoder_ff(grdab.parameters.dab_parameters(mode=1, sample_rate=samp_rate, verbose=False), ch['bit_rate'], ch['address'], ch['subch_size'], ch['protect_level'], True)

    xrun_monitor = grdab.xrun_monitor_cc(100000)
    xrun_monitor.set_report_fill(False)
    f2c = blocks.float_to_complex()
    c2f = blocks.complex_to_float()

    audio_sink_0 = audio.sink(audio_sample_rate, '', True)


    fg = gr.top_block()

    if not use_zeromq:
        src = osmosdr_source_0
    else:
        src = zeromq_source

    fg.connect(src, dab_ofdm_demod_0, decoder)
    fg.connect((decoder, 0), (f2c, 0))
    fg.connect((decoder, 1), (f2c, 1))
    fg.connect(f2c, xrun_monitor)
    fg.connect(xrun_monitor, c2f)
    fg.connect((c2f, 0), (audio_sink_0, 0))
    fg.connect((c2f, 1), (audio_sink_0, 1))




    fg.start()
    curses.wrapper(draw_menu)
	def __init__(self, frame, panel, vbox, argv):
		stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

		self.frame = frame
		self.panel = panel

		parser = OptionParser(option_class=eng_option, usage="%prog: [options] <filename>")
  		parser.add_option("-m", "--dab-mode", type="int", default=1,
        	     	help="DAB mode [default=%default]")
		parser.add_option("-F", "--filter-input", action="store_true", default=False,
                          help="Enable FFT filter at input")
		parser.add_option('-c', '--correct-ffe', action="store_true", default=False,
		     help="do fine frequency correction")
		parser.add_option('-u', '--correct-ffe-usrp', action="store_true", default=False,
		     help="do fine frequency correction by retuning the USRP instead of in software")
		parser.add_option('-e', '--equalize-magnitude', action="store_true", default=False,
		     help="do magnitude equalization")
  		parser.add_option("-s", "--resample-fixed", type="eng_float", default=1,
			help="resample by a fixed factor (fractional interpolation)")
		parser.add_option("-S", "--autocorrect-sample-rate", action="store_true", default=False,
                          help="Estimate sample rate offset and resample (dynamic fractional interpolation)")
		parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0),
		     help="select USRP Rx side A or B [default=A]")
		parser.add_option("-f", "--freq", type="eng_float", default=227.36e6,
		     help="set frequency to FREQ [default=%default]")
		parser.add_option("-p", "--ppm", type="int", default=0,
		     help="set frequency correction in ppm [default=%default]")
		parser.add_option("-r", "--sample-rate", type="int", default=2000000,
		     help="set sample rate to SAMPLE_RATE [default=%default]")
		parser.add_option("-d", "--decim", type="intx", default=32,
		     help="set decimation rate to DECIM [default=%default]")
		parser.add_option("-g", "--rx-gain", type="eng_float", default=None,
		     help="set receive gain in dB (default is midpoint)")
		parser.add_option('-v', '--verbose', action="store_true", default=False,
		     help="verbose output")
		(options, args) = parser.parse_args()

		
		self.verbose = options.verbose
                self.sample_rate = options.sample_rate

		if len(args) == 0:
			if self.verbose:
				print "--> receiving from RTL-SDR"
			self.src = osmosdr.source()
			self.src.set_sample_rate(self.sample_rate)
			self.src.set_freq_corr(options.ppm)
			# tune frequency
			self.frequency = options.freq
			self.set_freq(options.freq)

			# set gain      
                        if options.rx_gain is None:
                                # if no gain was specified, use AGC
                                self.src.set_gain_mode(True, 0)
                        else:
                                self.src.set_gain(options.rx_gain, 0)

		else:
			if self.verbose:
				print "--> receiving from file: " + args[0]
			self.filename = args[0]
			self.src = blocks.file_source(gr.sizeof_gr_complex, self.filename, False)
		
		
		self.dab_params = grdab.parameters.dab_parameters(mode=options.dab_mode, sample_rate=self.sample_rate, verbose=options.verbose)
		self.rx_params = grdab.parameters.receiver_parameters(mode=options.dab_mode, softbits=True, input_fft_filter=options.filter_input, autocorrect_sample_rate=options.autocorrect_sample_rate, sample_rate_correction_factor=options.resample_fixed, verbose=options.verbose, correct_ffe=options.correct_ffe, equalize_magnitude=options.equalize_magnitude)
	
		
		self.demod = grdab.ofdm_demod(self.dab_params, self.rx_params, verbose=self.verbose) 

		self.v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, self.dab_params.num_carriers)
		self.scope = scopesink2.scope_sink_c(self.panel, title="DAB constellation sink", sample_rate=self.dab_params.sample_rate, xy_mode=True)

		self.sink = blocks.null_sink(gr.sizeof_float*self.dab_params.num_carriers*2)

		self.connect(self.src, self.demod, self.sink)
        
		# build GUI
		self.connect(self.demod.deinterleave, self.v2s, self.scope)
		vbox.Add(self.scope.win, 10, wx.EXPAND)

                # FFT Sink
		self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
			self.panel,
			baseband_freq=0,
			y_per_div=10,
			y_divs=10,
			ref_level=0,
			ref_scale=2.0,
			sample_rate=self.sample_rate,
			fft_size=1024,
			fft_rate=15,
			average=False,
			avg_alpha=None,
			title="FFT Plot",
			peak_hold=False,
		)
		vbox.Add(self.wxgui_fftsink2_0.win)
		self.connect((self.src, 0), (self.wxgui_fftsink2_0, 0))
		
		# retune USRP to correct FFE?
		self.correct_ffe_usrp = options.correct_ffe_usrp
		if self.correct_ffe_usrp:
			print "--> correcting FFE on USRP"
			self.run_correct_ffe_thread = True
			self.ffe_updater = threading.Timer(0.1, self.correct_ffe)
			self.ffe_updater.setDaemon(True)
			self.ffe_updater.start()
Пример #7
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option,
                              usage="%prog: [options] <filename>")
        parser.add_option("-m",
                          "--dab-mode",
                          type="int",
                          default=1,
                          help="DAB mode [default=%default]")
        parser.add_option("-F",
                          "--filter-input",
                          action="store_true",
                          default=False,
                          help="Enable FFT filter at input")
        parser.add_option('-c',
                          '--correct-ffe',
                          action="store_true",
                          default=False,
                          help="do fine frequency correction")
        parser.add_option(
            '-u',
            '--correct-ffe-usrp',
            action="store_true",
            default=False,
            help=
            "do fine frequency correction by retuning the USRP instead of in software"
        )
        parser.add_option('-e',
                          '--equalize-magnitude',
                          action="store_true",
                          default=False,
                          help="do magnitude equalization")
        parser.add_option(
            "-s",
            "--resample-fixed",
            type="eng_float",
            default=1,
            help="resample by a fixed factor (fractional interpolation)")
        parser.add_option(
            "-S",
            "--autocorrect-sample-rate",
            action="store_true",
            default=False,
            help=
            "Estimate sample rate offset and resample (dynamic fractional interpolation)"
        )
        parser.add_option("-R",
                          "--rx-subdev-spec",
                          type="subdev",
                          default=(0, 0),
                          help="select USRP Rx side A or B [default=A]")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=227.36e6,
                          help="set frequency to FREQ [default=%default]")
        parser.add_option(
            "-r",
            "--sample-rate",
            type="int",
            default=2000000,
            help="set sample rate to SAMPLE_RATE [default=%default]")
        parser.add_option(
            "-d",
            "--decim",
            type="intx",
            default=32,
            help="set decimation rate to DECIM [default=%default]")
        parser.add_option("-g",
                          "--rx-gain",
                          type="eng_float",
                          default=None,
                          help="set receive gain in dB (default is midpoint)")
        parser.add_option('-v',
                          '--verbose',
                          action="store_true",
                          default=False,
                          help="verbose output")
        (options, args) = parser.parse_args()

        self.verbose = options.verbose
        self.sample_rate = options.sample_rate

        if len(args) == 0:
            if self.verbose:
                print "--> receiving from USRP"
            self.src = osmosdr.source()
            self.src.set_sample_rate(self.sample_rate)
            self.src.set_freq_corr(0)
            # tune frequency
            self.frequency = options.freq
            self.orig_frequency = options.freq
            self.set_freq(options.freq)

            self.src.set_freq_corr(0)

            # set gain
            if options.rx_gain is None:
                # if no gain was specified, use AGC
                self.src.set_gain_mode(True, 0)
            else:
                self.src.set_gain(options.rx_gain, 0)

        else:
            if self.verbose:
                print "--> receiving from file: " + args[0]
            self.filename = args[0]
            self.src = blocks.file_source(gr.sizeof_gr_complex, self.filename,
                                          False)

        self.dab_params = grdab.parameters.dab_parameters(
            mode=options.dab_mode,
            sample_rate=self.sample_rate,
            verbose=options.verbose)
        self.rx_params = grdab.parameters.receiver_parameters(
            mode=options.dab_mode,
            softbits=True,
            input_fft_filter=options.filter_input,
            autocorrect_sample_rate=options.autocorrect_sample_rate,
            sample_rate_correction_factor=options.resample_fixed,
            verbose=options.verbose,
            correct_ffe=options.correct_ffe,
            equalize_magnitude=options.equalize_magnitude)

        self.demod = grdab.ofdm_demod(self.dab_params,
                                      self.rx_params,
                                      verbose=self.verbose)

        self.v2s = blocks.vector_to_stream(gr.sizeof_gr_complex,
                                           self.dab_params.num_carriers)

        self.sink = blocks.null_sink(gr.sizeof_float *
                                     self.dab_params.num_carriers * 2)

        self.connect(self.src, self.demod, self.sink)

        # retune USRP to correct FFE?
        self.correct_ffe_usrp = options.correct_ffe_usrp
        if self.correct_ffe_usrp:
            print "--> correcting FFE on USRP"
            self.run_correct_ffe_thread = True
            self.ffe_updater = threading.Timer(0.1, self.correct_ffe)
            self.ffe_updater.setDaemon(True)
            self.ffe_updater.start()
Пример #8
0
    def setup_flowgraph(self, mode, ber_skipbytes=0):
        # parameters
        self.dp.set_mode(mode)
        self.rp.set_mode(mode)
        self.vlen = self.dp.num_carriers / 4
        self.ber_skipbytes = ber_skipbytes

        # trigger signals
        frame_trigger = [1] + [0] * (self.dp.symbols_per_frame - 2)
        self.frame_start = frame_trigger * (
            len(self.random_bytes) / (self.vlen *
                                      (self.dp.symbols_per_frame - 1))
        ) + frame_trigger[0:(len(self.random_bytes) / self.vlen) %
                          (self.dp.symbols_per_frame - 1)]

        # sources/sinks
        self.source = gr.vector_source_b(self.random_bytes, False)
        self.trig = gr.vector_source_b(self.frame_start, False)
        if self.ber_sink:
            self.sink = grdab.blocks.measure_ber_b()
        else:
            self.sink = gr.vector_sink_b()

        # self.noise_start      = gr.noise_source_c(gr.GR_GAUSSIAN, math.sqrt(2), random.randint(0,10000))
        # self.noise_start_head = gr.head(gr.sizeof_gr_complex, NOISE_SAMPLES_AT_START)
        # self.noise_end        = gr.noise_source_c(gr.GR_GAUSSIAN, math.sqrt(2), random.randint(0,10000))
        # self.noise_end_head   = gr.head(gr.sizeof_gr_complex, NOISE_SAMPLES_AT_END)

        # blocks
        self.s2v = gr.stream_to_vector(gr.sizeof_char, self.vlen)
        self.v2s = gr.vector_to_stream(gr.sizeof_char, self.vlen)
        if self.ber_sink:
            self.ber_skipbytes0 = gr.skiphead(gr.sizeof_char,
                                              self.ber_skipbytes)
            self.ber_skipbytes1 = gr.skiphead(
                gr.sizeof_char, self.ber_skipbytes + self.dp.bytes_per_frame)

        # more blocks (they have state, so better reinitialise them)
        self.mod = grdab.ofdm_mod(self.dp, debug=False)
        self.rescale = gr.multiply_const_cc(1)
        self.amp = gr.multiply_const_cc(1)
        self.channel = blks2.channel_model(noise_voltage=0,
                                           noise_seed=random.randint(0, 10000))
        # self.cat       = grdab.concatenate_signals(gr.sizeof_gr_complex)
        self.demod = grdab.ofdm_demod(self.dp,
                                      self.rp,
                                      debug=False,
                                      verbose=True)

        # connect it all
        if self.ber_sink:
            self.connect(self.source, self.s2v, (self.mod, 0), self.rescale,
                         self.amp, self.channel, (self.demod, 0), self.v2s,
                         self.ber_skipbytes0, self.sink)
            self.connect(self.source, self.ber_skipbytes1, (self.sink, 1))
        else:
            self.connect(self.source, self.s2v, (self.mod, 0), self.rescale,
                         self.amp, self.channel, (self.demod, 0), self.v2s,
                         self.sink)
        self.connect(self.trig, (self.mod, 1))

        # SNR calculation and prober
        self.probe_signal = gr.probe_avg_mag_sqrd_c(0, 0.00001)
        self.probe_total = gr.probe_avg_mag_sqrd_c(0, 0.00001)
        self.connect(self.amp, self.probe_signal)
        self.connect(self.channel, self.probe_total)
Пример #9
0
def get_channels(frequency=220.352e6, rf_gain=25, if_gain=0, bb_gain=0, ppm=0, use_zeromq=False, server="tcp://127.0.0.1:10444", server_control="tcp://127.0.0.1:10445"):
    from gnuradio import gr, blocks, audio
    if use_zeromq:
        from gnuradio import zeromq

    import osmosdr
    import grdab
    import time

    samp_rate = samp_rate = 2000000

    print("Setting frequency: %0.3f MHz" % (frequency/1e6))

    if not use_zeromq:
        osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + '' )
        osmosdr_source_0.set_sample_rate(samp_rate)
        osmosdr_source_0.set_center_freq(frequency, 0)
        osmosdr_source_0.set_freq_corr(0, 0)
        osmosdr_source_0.set_dc_offset_mode(0, 0)
        osmosdr_source_0.set_iq_balance_mode(0, 0)
        osmosdr_source_0.set_gain_mode(False, 0)
        osmosdr_source_0.set_gain(rf_gain, 0)
        osmosdr_source_0.set_if_gain(if_gain, 0)
        osmosdr_source_0.set_bb_gain(bb_gain, 0)
        osmosdr_source_0.set_antenna('RX2', 0)
        osmosdr_source_0.set_bandwidth(2000000, 0)
    else:
        zeromq_source = zeromq.sub_source(gr.sizeof_gr_complex, 1, server, 100, False, -1)
        rpc_mgr_server = zeromq.rpc_manager()
        rpc_mgr_server.set_request_socket(server_control)
        rpc_mgr_server.request("set_sample_rate",[samp_rate])
        rpc_mgr_server.request("set_rf_gain",[rf_gain])
        rpc_mgr_server.request("set_if_gain",[if_gain])
        rpc_mgr_server.request("set_bb_gain",[bb_gain])
        rpc_mgr_server.request("set_ppm",[0]) # Not using hardware correction since it behaves differently on different hardware
        rpc_mgr_server.request("set_frequency",[frequency])
        time.sleep(0.7)

    sample_rate_correction_factor = 1 + float(ppm)*1e-6
    dab_ofdm_demod_0 = grdab.ofdm_demod(
              grdab.parameters.dab_parameters(
                mode=1,
                sample_rate=samp_rate,
                verbose=False
              ),
              grdab.parameters.receiver_parameters(
                mode=1,
                softbits=True,
                input_fft_filter=True,
                autocorrect_sample_rate=False,
                sample_rate_correction_factor=sample_rate_correction_factor,
                always_include_resample=True,
                verbose=False,
                correct_ffe=True,
                equalize_magnitude=True
              )
            )

    dab_fic_decode_0 = grdab.fic_decode(
              grdab.parameters.dab_parameters(
                mode=1,
                sample_rate=samp_rate,
                verbose=False
              )
            )
    #dab_fic_decode_0.set_print_channel_info(True)

    fg = gr.top_block()

    if not use_zeromq:
        fg.connect(osmosdr_source_0, dab_ofdm_demod_0)
    else:
        fg.connect(zeromq_source, dab_ofdm_demod_0)
    fg.connect(dab_ofdm_demod_0, dab_fic_decode_0)



    fg.start()

    attempt = 0
    maxattempts = 9
    channels = {}
    while True:
        service_labels = dab_fic_decode_0.get_service_labels()
        if service_labels.strip() != "":
            service_labels_json = json.loads(service_labels.strip())
            for s in service_labels_json:
                if s['reference'] not in channels:
                    channels[s['reference']] = {}
                channels[s['reference']]['label'] = s['label']
            subch_info = dab_fic_decode_0.get_subch_info()
        service_info = dab_fic_decode_0.get_service_info() # mapping between service_labels number and subch_info number
        if service_info.strip() != "":
            service_info_json = json.loads(service_info.strip())
            for s in service_info_json:
                if s['reference'] not in channels:
                    channels[s['reference']] = {}
                channels[s['reference']]['id'] = s['ID']
                channels[s['reference']]['dabplus'] = s['DAB+']
        subch_info = dab_fic_decode_0.get_subch_info() # settings needed for setting channel
        if subch_info.strip() != "":
            subch_info_json = json.loads(subch_info.strip())
            for s in subch_info_json:
                if 'ID' in s:
                    current_id = s['ID']
                    for key,val in channels.items():
                        if 'id' in val:
                            if val['id'] == current_id:
                                channels[key]['subch_info'] = s
                                break

        all_have_label = True
        for c,item in channels.items():
            if 'label' not in item:
                all_have_label = False
        if attempt == maxattempts-1:
            all_have_label = True
        complete = False
        if len(channels) > 0 and all_have_label:
            print("Channels:")
            for c,item in channels.items():
                if 'subch_info' in item:
                    conv_table = [ 128, 8, 6, 5];
                    protect_level = item['subch_info']['protection']
                    subch_size = item['subch_info']['size']
                    if protect_level <= 4:
                        if 'label' in item:
                            label = item['label']
                        else:
                            label = "UNKNOWN"
                        bit_rate = subch_size * 8 / (conv_table[protect_level]);

                        print("%s: (address: %3d, subch_size: %3d, protect_level: %1d, bit_rate: %3d, classic: %1d)" % (label, item['subch_info']['address'], item['subch_info']['size'], item['subch_info']['protection'], bit_rate, not item['dabplus']))
                complete = True

        if complete:
            break
        attempt = attempt + 1
        time.sleep(1)
    fg.stop()
Пример #10
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Top Block")
        qtgui.util.check_set_qss()
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "top_block")

        try:
            if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
                self.restoreGeometry(
                    self.settings.value("geometry").toByteArray())
            else:
                self.restoreGeometry(self.settings.value("geometry"))
        except:
            pass

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 2000000
        self.gain_slider = gain_slider = 50

        ##################################################
        # Blocks
        ##################################################
        self.rtlsdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " +
                                              "")
        self.rtlsdr_source_0.set_time_unknown_pps(osmosdr.time_spec_t())
        self.rtlsdr_source_0.set_sample_rate(samp_rate)
        self.rtlsdr_source_0.set_center_freq(201072000, 0)
        self.rtlsdr_source_0.set_freq_corr(0, 0)
        self.rtlsdr_source_0.set_dc_offset_mode(0, 0)
        self.rtlsdr_source_0.set_iq_balance_mode(0, 0)
        self.rtlsdr_source_0.set_gain_mode(False, 0)
        self.rtlsdr_source_0.set_gain(10, 0)
        self.rtlsdr_source_0.set_if_gain(20, 0)
        self.rtlsdr_source_0.set_bb_gain(20, 0)
        self.rtlsdr_source_0.set_antenna('', 0)
        self.rtlsdr_source_0.set_bandwidth(0, 0)
        self._gain_slider_range = Range(0, 100, 1, 50, 200)
        self._gain_slider_win = RangeWidget(self._gain_slider_range,
                                            self.set_gain_slider, 'Gain',
                                            "counter_slider", float)
        self.top_grid_layout.addWidget(self._gain_slider_win)
        self.dab_ofdm_demod_0 = grdab.ofdm_demod(
            grdab.parameters.dab_parameters(mode=1,
                                            sample_rate=samp_rate,
                                            verbose=False),
            grdab.parameters.receiver_parameters(
                mode=1,
                softbits=True,
                input_fft_filter=True,
                autocorrect_sample_rate=True,
                sample_rate_correction_factor=1 + float(0) * 1e-6,
                always_include_resample=True,
                verbose=False,
                correct_ffe=True,
                equalize_magnitude=True))

        self.dab_dabplus_audio_decoder_ff_0 = grdab.dabplus_audio_decoder_ff(
            grdab.parameters.dab_parameters(mode=1,
                                            sample_rate=samp_rate,
                                            verbose=False), 112, 234, 84, 2,
            True)
        self.audio_sink_0 = audio.sink(48000, '', True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.dab_dabplus_audio_decoder_ff_0, 1),
                     (self.audio_sink_0, 1))
        self.connect((self.dab_dabplus_audio_decoder_ff_0, 0),
                     (self.audio_sink_0, 0))
        self.connect((self.dab_ofdm_demod_0, 0),
                     (self.dab_dabplus_audio_decoder_ff_0, 0))
        self.connect((self.rtlsdr_source_0, 0), (self.dab_ofdm_demod_0, 0))
Пример #11
0
	def __init__(self):
		gr.top_block.__init__(self)
        
		
		parser = OptionParser(option_class=eng_option, usage="%prog: [options] output-filename")
  		parser.add_option("-m", "--dab-mode", type="int", default=1,
        	     	help="DAB mode [default=%default]")
		parser.add_option("-F", "--filter-input", action="store_true", default=False,
                          help="Enable FFT filter at input")
		parser.add_option('-c', '--correct-ffe', action="store_true", default=False,
		     help="do fine frequency correction")
		parser.add_option('-u', '--correct-ffe-usrp', action="store_true", default=False,
		     help="do fine frequency correction by retuning the USRP instead of in software")
		parser.add_option('-e', '--equalize-magnitude', action="store_true", default=False,
		     help="do magnitude equalization")
  		parser.add_option("-s", "--resample-fixed", type="eng_float", default=1,
			help="resample by a fixed factor (fractional interpolation)")
		parser.add_option("-S", "--autocorrect-sample-rate", action="store_true", default=False,
                          help="Estimate sample rate offset and resample (dynamic fractional interpolation)")
		parser.add_option("-f", "--freq", type="eng_float", default=227.36e6,
		     help="set frequency to FREQ [default=%default]")
		parser.add_option("-p", "--ppm", type="int", default=0,
		     help="set frequency correction in ppm [default=%default]")
		parser.add_option("-r", "--sample-rate", type="int", default=2000000,
		     help="set sample rate to SAMPLE_RATE [default=%default]")
		parser.add_option("-g", "--rx-gain", type="eng_float", default=None,
		     help="set receive gain in dB (default is midpoint)")
		parser.add_option('-v', '--verbose', action="store_true", default=False,
		     help="verbose output")
        	(options, args) = parser.parse_args ()

		# if len(args)!=1:
			# parser.print_help()
			# sys.exit(1)
		# else:
			# self.filename = args[0]

		# if gr.enable_realtime_scheduling() != gr.RT_OK:
		#       print "-> failed to enable realtime scheduling"

		self.verbose = options.verbose

		self.sample_rate = sample_rate = options.sample_rate

		self.src = osmosdr.source()
		self.src.set_sample_rate(sample_rate)
		#self.src.set_center_freq(209.936e6, 0)
		self.src.set_freq_corr(options.ppm)
		self.src.set_gain_mode(True, 0)
		self.src.set_gain(0, 0)

		self.dab_params = grdab.parameters.dab_parameters(
                        mode=options.dab_mode,
                        sample_rate=self.sample_rate,
                        verbose=options.verbose
                        )
		self.rx_params = grdab.parameters.receiver_parameters(
                        mode=options.dab_mode,
                        softbits=True,
                        input_fft_filter=options.filter_input,
                        autocorrect_sample_rate=options.autocorrect_sample_rate,
                        sample_rate_correction_factor=options.resample_fixed,
                        verbose=options.verbose,
                        correct_ffe=options.correct_ffe,
                        equalize_magnitude=options.equalize_magnitude
                        )

		self.demod = grdab.ofdm_demod(self.dab_params, self.rx_params, verbose=options.verbose) 

                if len(args) >= 1:
                        self.filename = args[0]
                        self.sink = blocks.file_sink(gr.sizeof_char*12288, self.filename)
                        #self.sink = gr.file_sink(gr.sizeof_char*3072, self.filename)
                        self.connect(self.demod, self.sink)


		
		self.fic_dec = grdab.fic_decode(self.dab_params)
		self.connect(self.src, self.demod, self.fic_dec)

		# tune frequency
		self.frequency = options.freq
		self.set_freq(options.freq)

		# set gain      
		if options.rx_gain is None:
			# if no gain was specified, use AGC
                        self.src.set_gain_mode(True, 0)
                else:
                        self.src.set_gain(options.rx_gain, 0)

		self.update_ui = options.verbose
		if self.update_ui:
			self.run_ui_update_thread = True
			self.ui_updater = threading.Timer(0.1,self.update_ui_function)
			self.ui_updater.setDaemon(True)
			self.ui_updater.start()

		self.correct_ffe_usrp = options.correct_ffe_usrp
		if self.correct_ffe_usrp:
			print "--> correcting FFE on USRP"
			self.run_correct_ffe_thread = True
			self.ffe_updater = threading.Timer(0.1, self.correct_ffe)
			self.ffe_updater.setDaemon(True)
			self.ffe_updater.start()
Пример #12
0
def get_channels(frequency=220.352e6,
                 rf_gain=25,
                 if_gain=0,
                 bb_gain=0,
                 ppm=0,
                 use_zeromq=False,
                 server="tcp://127.0.0.1:10444",
                 server_control="tcp://127.0.0.1:10445",
                 from_file=None,
                 from_file_repeat=False):
    from gnuradio import gr, blocks, audio
    if use_zeromq:
        from gnuradio import zeromq

    import osmosdr
    import grdab
    import time

    samp_rate = samp_rate = 2048000

    print("Setting frequency: %0.3f MHz" % (frequency / 1e6))

    fg = gr.top_block()

    if from_file != None:
        file_input = blocks.file_source(gr.sizeof_gr_complex, from_file,
                                        True)  # Makes sense to always repeat
        src = file_input
        print("Run from file %s" % from_file)
    elif not use_zeromq:
        osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + '')
        osmosdr_source_0.set_sample_rate(samp_rate)
        osmosdr_source_0.set_center_freq(frequency, 0)
        osmosdr_source_0.set_freq_corr(0, 0)
        osmosdr_source_0.set_dc_offset_mode(0, 0)
        osmosdr_source_0.set_iq_balance_mode(0, 0)
        osmosdr_source_0.set_gain_mode(False, 0)
        osmosdr_source_0.set_gain(rf_gain, 0)
        osmosdr_source_0.set_if_gain(if_gain, 0)
        osmosdr_source_0.set_bb_gain(bb_gain, 0)
        osmosdr_source_0.set_antenna('RX2', 0)
        osmosdr_source_0.set_bandwidth(2000000, 0)
        src = osmosdr_source_0
    else:
        zeromq_source = zeromq.sub_source(gr.sizeof_gr_complex, 1, server, 100,
                                          False, -1)
        rpc_mgr_server = zeromq.rpc_manager()
        rpc_mgr_server.set_request_socket(server_control)
        rpc_mgr_server.request("set_sample_rate", [samp_rate])
        rpc_mgr_server.request("set_rf_gain", [rf_gain])
        rpc_mgr_server.request("set_if_gain", [if_gain])
        rpc_mgr_server.request("set_bb_gain", [bb_gain])
        rpc_mgr_server.request(
            "set_ppm", [0]
        )  # Not using hardware correction since it behaves differently on different hardware
        rpc_mgr_server.request("set_frequency", [frequency])
        time.sleep(0.7)
        src = zeromq_source

    sample_rate_correction_factor = 1 + float(ppm) * 1e-6
    dab_ofdm_demod_0 = grdab.ofdm_demod(
        grdab.parameters.dab_parameters(mode=1,
                                        sample_rate=samp_rate,
                                        verbose=False),
        grdab.parameters.receiver_parameters(
            mode=1,
            softbits=True,
            input_fft_filter=True,
            autocorrect_sample_rate=False,
            sample_rate_correction_factor=sample_rate_correction_factor,
            always_include_resample=True,
            verbose=False,
            correct_ffe=True,
            equalize_magnitude=True))

    dab_fic_decode_0 = grdab.fic_decode(
        grdab.parameters.dab_parameters(mode=1,
                                        sample_rate=samp_rate,
                                        verbose=False))
    #dab_fic_decode_0.set_print_channel_info(True)

    fg.connect(src, dab_ofdm_demod_0)
    fg.connect(dab_ofdm_demod_0, dab_fic_decode_0)

    fg.start()

    attempt = 0
    maxattempts = 9
    channels = {}
    while True:
        service_labels = dab_fic_decode_0.get_service_labels()
        if service_labels.strip() != "":
            service_labels_json = json.loads(service_labels.strip())
            for s in service_labels_json:
                if s['reference'] not in channels:
                    channels[s['reference']] = {}
                channels[s['reference']]['label'] = s['label']
            subch_info = dab_fic_decode_0.get_subch_info()
        service_info = dab_fic_decode_0.get_service_info(
        )  # mapping between service_labels number and subch_info number
        if service_info.strip() != "":
            service_info_json = json.loads(service_info.strip())
            for s in service_info_json:
                if s['reference'] not in channels:
                    channels[s['reference']] = {}
                channels[s['reference']]['id'] = s['ID']
                channels[s['reference']]['dabplus'] = s['DAB+']
        subch_info = dab_fic_decode_0.get_subch_info(
        )  # settings needed for setting channel
        if subch_info.strip() != "":
            subch_info_json = json.loads(subch_info.strip())
            for s in subch_info_json:
                if 'ID' in s:
                    current_id = s['ID']
                    for key, val in channels.items():
                        if 'id' in val:
                            if val['id'] == current_id:
                                channels[key]['subch_info'] = s
                                break

        all_have_label = True
        for c, item in channels.items():
            if 'label' not in item:
                all_have_label = False
        if attempt == maxattempts - 1:
            all_have_label = True
        complete = False
        if len(channels) > 0 and all_have_label:
            print("Channels:")
            for c, item in channels.items():
                if 'subch_info' in item:
                    conv_table = [128, 8, 6, 5]
                    protect_level = item['subch_info']['protection']
                    subch_size = item['subch_info']['size']
                    if protect_level <= 4:
                        if 'label' in item:
                            label = item['label']
                        else:
                            label = "UNKNOWN"
                        bit_rate = subch_size * 8 / (conv_table[protect_level])

                        print(
                            "%s: (address: %3d, subch_size: %3d, protect_level: %1d, bit_rate: %3d, classic: %1d)"
                            % (label, item['subch_info']['address'],
                               item['subch_info']['size'],
                               item['subch_info']['protection'], bit_rate,
                               not item['dabplus']))
                complete = True

        if complete:
            break
        attempt = attempt + 1
        time.sleep(1)
    fg.stop()
Пример #13
0
	def __init__(self):
		gr.top_block.__init__(self)
        
		
		parser = OptionParser(option_class=eng_option, usage="%prog: [options] output-filename")
  		parser.add_option("-m", "--dab-mode", type="int", default=1,
        	     	help="DAB mode [default=%default]")
		parser.add_option("-F", "--filter-input", action="store_true", default=False,
                          help="Enable FFT filter at input")
		parser.add_option('-c', '--correct-ffe', action="store_true", default=False,
		     help="do fine frequency correction")
		parser.add_option('-u', '--correct-ffe-usrp', action="store_true", default=False,
		     help="do fine frequency correction by retuning the USRP instead of in software")
		parser.add_option('-e', '--equalize-magnitude', action="store_true", default=False,
		     help="do magnitude equalization")
  		parser.add_option("-s", "--resample-fixed", type="eng_float", default=1,
			help="resample by a fixed factor (fractional interpolation)")
		parser.add_option("-S", "--autocorrect-sample-rate", action="store_true", default=False,
                          help="Estimate sample rate offset and resample (dynamic fractional interpolation)")
		parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0),
		     help="select USRP Rx side A or B [default=A]")
		parser.add_option("-f", "--freq", type="eng_float", default=227.36e6,
		     help="set frequency to FREQ [default=%default]")
		parser.add_option("-d", "--decim", type="intx", default=32,
		     help="set decimation rate to DECIM [default=%default]")
		parser.add_option("-g", "--rx-gain", type="eng_float", default=None,
		     help="set receive gain in dB (default is midpoint)")
		parser.add_option('-v', '--verbose', action="store_true", default=False,
		     help="verbose output")
		parser.add_option('-a', '--antenna', type="string", default="TX/RX",
		     help="select antenna")
        	(options, args) = parser.parse_args ()

		# if len(args)!=1:
			# parser.print_help()
			# sys.exit(1)
		# else:
			# self.filename = args[0]

		# if gr.enable_realtime_scheduling() != gr.RT_OK:
		#       print "-> failed to enable realtime scheduling"

		self.verbose = options.verbose

		self.src = uhd.usrp_source("",uhd.io_type.COMPLEX_FLOAT32,1)
        	#self.src.set_mux(usrp.determine_rx_mux_value(self.src, options.rx_subdev_spec))
        	#self.subdev = uhd.selected_subdev(self.src, options.rx_subdev_spec)
        	#print "--> using RX dboard " + self.subdev.side_and_name()
		
		self.sample_rate = 2e6#self.src.adc_rate()/options.decim
		self.src.set_samp_rate(self.sample_rate)
		self.src.set_antenna(options.antenna)
		self.dab_params = grdab.parameters.dab_parameters(mode=options.dab_mode, sample_rate=self.sample_rate, verbose=options.verbose)
		self.rx_params = grdab.parameters.receiver_parameters(mode=options.dab_mode, softbits=True, input_fft_filter=options.filter_input, autocorrect_sample_rate=options.autocorrect_sample_rate, sample_rate_correction_factor=options.resample_fixed, verbose=options.verbose, correct_ffe=options.correct_ffe, equalize_magnitude=options.equalize_magnitude)

		self.demod = grdab.ofdm_demod(self.dab_params, self.rx_params, verbose=options.verbose) 

		# self.sink = gr.file_sink(gr.sizeof_char*384, self.filename)
		# self.trigsink = gr.null_sink(gr.sizeof_char)
		# self.connect(self.src, self.demod, self.sink)
		# self.connect((self.demod,1), self.trigsink)
		
		self.fic_dec = grdab.fic_decode(self.dab_params)
		self.connect(self.src, self.demod, (self.fic_dec,0))
		self.connect((self.demod,1), (self.fic_dec,1))

		# tune frequency
		self.frequency = options.freq
		self.set_freq(options.freq)

		# set gain      
		if options.rx_gain is None:
			# if no gain was specified, use the mid-point in dB
			g = self.src.get_gain_range()
			options.rx_gain = float(g.start()+g.stop())/2
		self.src.set_gain(options.rx_gain)
		#self.subdev.set_gain(options.rx_gain)

		self.update_ui = options.verbose
		if self.update_ui:
			self.run_ui_update_thread = True
			self.ui_updater = threading.Timer(0.1,self.update_ui_function)
			self.ui_updater.setDaemon(True)
			self.ui_updater.start()

		self.correct_ffe_usrp = options.correct_ffe_usrp
		if self.correct_ffe_usrp:
			print "--> correcting FFE on USRP"
			self.run_correct_ffe_thread = True
			self.ffe_updater = threading.Timer(0.1, self.correct_ffe)
			self.ffe_updater.setDaemon(True)
			self.ffe_updater.start()
Пример #14
0
def receive_dabplus(frequency=220.352e6, rf_gain=25, if_gain=0, bb_gain=0, ppm=80, audio_sample_rate=48000, dab_bit_rate=64, dab_address=304, dab_subch_size=64, dab_protect_level=1, use_zeromq=False, dabplus=True, server="tcp://127.0.0.1:10444", server_control="tcp://127.0.0.1:10445"):
    from gnuradio import gr, blocks, audio
    if use_zeromq:
        from gnuradio import zeromq

    import time
    import osmosdr
    import grdab

    samp_rate = samp_rate = 2000000

    print("Setting frequency: %0.3f MHz" % (frequency/1e6))
    print("Setting RF gain to: %d" % rf_gain)
    print("Setting Frequency error (ppm) to: %d" % ppm)

    if not use_zeromq:
        osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + '' )
        osmosdr_source_0.set_sample_rate(samp_rate)
        osmosdr_source_0.set_center_freq(frequency, 0)
        osmosdr_source_0.set_freq_corr(0, 0)
        osmosdr_source_0.set_dc_offset_mode(0, 0)
        osmosdr_source_0.set_iq_balance_mode(0, 0)
        osmosdr_source_0.set_gain_mode(False, 0)
        osmosdr_source_0.set_gain(rf_gain, 0)
        osmosdr_source_0.set_if_gain(if_gain, 0)
        osmosdr_source_0.set_bb_gain(bb_gain, 0)
        osmosdr_source_0.set_antenna('RX2', 0)
        osmosdr_source_0.set_bandwidth(2000000, 0)
    else:
        zeromq_source = zeromq.sub_source(gr.sizeof_gr_complex, 1, server, 100, False, -1)
        rpc_mgr_server = zeromq.rpc_manager()
        rpc_mgr_server.set_request_socket(server_control)
        rpc_mgr_server.request("set_sample_rate",[samp_rate])
        rpc_mgr_server.request("set_rf_gain",[rf_gain])
        rpc_mgr_server.request("set_if_gain",[if_gain])
        rpc_mgr_server.request("set_bb_gain",[bb_gain])
        rpc_mgr_server.request("set_ppm",[0]) # Not using hardware correction since it behaves differently on different hardware
        rpc_mgr_server.request("set_frequency",[frequency])
        time.sleep(0.7)

    sample_rate_correction_factor = 1 + float(ppm)*1e-6
    dab_ofdm_demod_0 = grdab.ofdm_demod(
              grdab.parameters.dab_parameters(
                mode=1,
                sample_rate=samp_rate,
                verbose=False
              ),
              grdab.parameters.receiver_parameters(
                mode=1,
                softbits=True,
                input_fft_filter=True,
                autocorrect_sample_rate=False,
                sample_rate_correction_factor=sample_rate_correction_factor,
                always_include_resample=True,
                verbose=False,
                correct_ffe=True,
                equalize_magnitude=True
              )
            )

    if dabplus:
        decoder = grdab.dabplus_audio_decoder_ff(grdab.parameters.dab_parameters(mode=1, sample_rate=samp_rate, verbose=False), dab_bit_rate, dab_address, dab_subch_size, dab_protect_level, True)
    else:
        decoder = grdab.dab_audio_decoder_ff(grdab.parameters.dab_parameters(mode=1, sample_rate=samp_rate, verbose=False), dab_bit_rate, dab_address, dab_subch_size, dab_protect_level, True)

    xrun_monitor = grdab.xrun_monitor_cc(100000)
    f2c = blocks.float_to_complex()
    c2f = blocks.complex_to_float()

    audio_sink_0 = audio.sink(audio_sample_rate, '', True)

    fg = gr.top_block()

    if not use_zeromq:
        src = osmosdr_source_0
    else:
        src = zeromq_source

    fg.connect(src, dab_ofdm_demod_0, decoder)
    fg.connect((decoder, 0), (f2c, 0))
    fg.connect((decoder, 1), (f2c, 1))
    fg.connect(f2c, xrun_monitor)
    fg.connect(xrun_monitor, c2f)
    fg.connect((c2f, 0), (audio_sink_0, 0))
    fg.connect((c2f, 1), (audio_sink_0, 1))



    fg.start()
    raw_input("Running..")
    #new = grdab.dabplus_audio_decoder_ff(grdab.parameters.dab_parameters(mode=1, sample_rate=samp_rate, verbose=False), 64, 304, 64, 1, True)
    #newaudio = audio.sink(44100, '', True)
    fg.stop()
Пример #15
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option,
                              usage="%prog: [options] output-filename")
        parser.add_option("-m",
                          "--dab-mode",
                          type="int",
                          default=1,
                          help="DAB mode [default=%default]")
        parser.add_option("-F",
                          "--filter-input",
                          action="store_true",
                          default=False,
                          help="Enable FFT filter at input")
        parser.add_option('-c',
                          '--correct-ffe',
                          action="store_true",
                          default=False,
                          help="do fine frequency correction")
        parser.add_option(
            '-u',
            '--correct-ffe-usrp',
            action="store_true",
            default=False,
            help=
            "do fine frequency correction by retuning the USRP instead of in software"
        )
        parser.add_option('-e',
                          '--equalize-magnitude',
                          action="store_true",
                          default=False,
                          help="do magnitude equalization")
        parser.add_option(
            "-s",
            "--resample-fixed",
            type="eng_float",
            default=1,
            help="resample by a fixed factor (fractional interpolation)")
        parser.add_option(
            "-S",
            "--autocorrect-sample-rate",
            action="store_true",
            default=False,
            help=
            "Estimate sample rate offset and resample (dynamic fractional interpolation)"
        )
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=227.36e6,
                          help="set frequency to FREQ [default=%default]")
        parser.add_option(
            "-p",
            "--ppm",
            type="int",
            default=0,
            help="set frequency correction in ppm [default=%default]")
        parser.add_option(
            "-r",
            "--sample-rate",
            type="int",
            default=2000000,
            help="set sample rate to SAMPLE_RATE [default=%default]")
        parser.add_option("-g",
                          "--rx-gain",
                          type="eng_float",
                          default=None,
                          help="set receive gain in dB (default is midpoint)")
        parser.add_option('-v',
                          '--verbose',
                          action="store_true",
                          default=False,
                          help="verbose output")
        (options, args) = parser.parse_args()

        # if len(args)!=1:
        # parser.print_help()
        # sys.exit(1)
        # else:
        # self.filename = args[0]

        # if gr.enable_realtime_scheduling() != gr.RT_OK:
        #       print "-> failed to enable realtime scheduling"

        self.verbose = options.verbose

        self.sample_rate = sample_rate = options.sample_rate

        self.src = osmosdr.source()
        self.src.set_sample_rate(sample_rate)
        #self.src.set_center_freq(209.936e6, 0)
        self.src.set_freq_corr(options.ppm)
        self.src.set_gain_mode(True, 0)
        self.src.set_gain(0, 0)

        self.dab_params = grdab.parameters.dab_parameters(
            mode=options.dab_mode,
            sample_rate=self.sample_rate,
            verbose=options.verbose)
        self.rx_params = grdab.parameters.receiver_parameters(
            mode=options.dab_mode,
            softbits=True,
            input_fft_filter=options.filter_input,
            autocorrect_sample_rate=options.autocorrect_sample_rate,
            sample_rate_correction_factor=options.resample_fixed,
            verbose=options.verbose,
            correct_ffe=options.correct_ffe,
            equalize_magnitude=options.equalize_magnitude)

        self.demod = grdab.ofdm_demod(self.dab_params,
                                      self.rx_params,
                                      verbose=options.verbose)

        if len(args) >= 1:
            self.filename = args[0]
            self.sink = blocks.file_sink(gr.sizeof_char * 12288, self.filename)
            #self.sink = gr.file_sink(gr.sizeof_char*3072, self.filename)
            self.connect(self.demod, self.sink)

        self.fic_dec = grdab.fic_decode(self.dab_params)
        self.connect(self.src, self.demod, self.fic_dec)

        # tune frequency
        self.frequency = options.freq
        self.set_freq(options.freq)

        # set gain
        if options.rx_gain is None:
            # if no gain was specified, use AGC
            self.src.set_gain_mode(True, 0)
        else:
            self.src.set_gain(options.rx_gain, 0)

        self.update_ui = options.verbose
        if self.update_ui:
            self.run_ui_update_thread = True
            self.ui_updater = threading.Timer(0.1, self.update_ui_function)
            self.ui_updater.setDaemon(True)
            self.ui_updater.start()

        self.correct_ffe_usrp = options.correct_ffe_usrp
        if self.correct_ffe_usrp:
            print "--> correcting FFE on USRP"
            self.run_correct_ffe_thread = True
            self.ffe_updater = threading.Timer(0.1, self.correct_ffe)
            self.ffe_updater.setDaemon(True)
            self.ffe_updater.start()
Пример #16
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        self.frame = frame
        self.panel = panel

        parser = OptionParser(option_class=eng_option,
                              usage="%prog: [options] <filename>")
        parser.add_option("-m",
                          "--dab-mode",
                          type="int",
                          default=1,
                          help="DAB mode [default=%default]")
        parser.add_option("-F",
                          "--filter-input",
                          action="store_true",
                          default=False,
                          help="Enable FFT filter at input")
        parser.add_option('-c',
                          '--correct-ffe',
                          action="store_true",
                          default=False,
                          help="do fine frequency correction")
        parser.add_option(
            '-u',
            '--correct-ffe-usrp',
            action="store_true",
            default=False,
            help=
            "do fine frequency correction by retuning the USRP instead of in software"
        )
        parser.add_option('-e',
                          '--equalize-magnitude',
                          action="store_true",
                          default=False,
                          help="do magnitude equalization")
        parser.add_option(
            "-s",
            "--resample-fixed",
            type="eng_float",
            default=1,
            help="resample by a fixed factor (fractional interpolation)")
        parser.add_option(
            "-S",
            "--autocorrect-sample-rate",
            action="store_true",
            default=False,
            help=
            "Estimate sample rate offset and resample (dynamic fractional interpolation)"
        )
        parser.add_option("-R",
                          "--rx-subdev-spec",
                          type="subdev",
                          default=(0, 0),
                          help="select USRP Rx side A or B [default=A]")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=227.36e6,
                          help="set frequency to FREQ [default=%default]")
        parser.add_option(
            "-r",
            "--sample-rate",
            type="int",
            default=2000000,
            help="set sample rate to SAMPLE_RATE [default=%default]")
        parser.add_option(
            "-d",
            "--decim",
            type="intx",
            default=32,
            help="set decimation rate to DECIM [default=%default]")
        parser.add_option("-g",
                          "--rx-gain",
                          type="eng_float",
                          default=None,
                          help="set receive gain in dB (default is midpoint)")
        parser.add_option('-v',
                          '--verbose',
                          action="store_true",
                          default=False,
                          help="verbose output")
        parser.add_option('-a',
                          '--antenna',
                          type="string",
                          default="TX/RX",
                          help="select antenna")
        (options, args) = parser.parse_args()

        self.verbose = options.verbose

        if len(args) == 0:
            if self.verbose:
                print "--> receiving from USRP"
            self.src = uhd.usrp_source("", uhd.io_type.COMPLEX_FLOAT32, 1)
            #self.src.set_mux(usrp.determine_rx_mux_value(self.src, options.rx_subdev_spec))
            #self.subdev = usrp.selected_subdev(self.src, options.rx_subdev_spec)
            #if self.verbose:
            #	print "--> using RX dboard " + self.subdev.side_and_name()
            # tune frequency
            self.frequency = options.freq
            self.set_freq(options.freq)

            # set gain
            if options.rx_gain is None:
                # if no gain was specified, use the mid-point in dB
                g = self.src.get_gain_range()
                options.rx_gain = float(g.start() + g.stop()) / 2
            self.src.set_gain(options.rx_gain)
            self.sample_rate = 2e6  #self.src.adc_rate()/options.decim
            self.src.set_samp_rate(self.sample_rate)
            self.src.set_antenna(options.antenna)
        else:
            if self.verbose:
                print "--> receiving from file: " + args[0]
            self.filename = args[0]
            self.src = blocks.file_source(gr.sizeof_gr_complex, self.filename,
                                          False)
            self.sample_rate = options.sample_rate

        self.dab_params = grdab.parameters.dab_parameters(
            mode=options.dab_mode,
            sample_rate=self.sample_rate,
            verbose=options.verbose)
        self.rx_params = grdab.parameters.receiver_parameters(
            mode=options.dab_mode,
            softbits=True,
            input_fft_filter=options.filter_input,
            autocorrect_sample_rate=options.autocorrect_sample_rate,
            sample_rate_correction_factor=options.resample_fixed,
            verbose=options.verbose,
            correct_ffe=options.correct_ffe,
            equalize_magnitude=options.equalize_magnitude)

        self.demod = grdab.ofdm_demod(self.dab_params,
                                      self.rx_params,
                                      verbose=self.verbose)

        self.v2s = blocks.vector_to_stream(gr.sizeof_gr_complex,
                                           self.dab_params.num_carriers)
        self.scope = scopesink2.scope_sink_c(
            self.panel,
            title="DAB constellation sink",
            sample_rate=self.dab_params.sample_rate,
            xy_mode=True)

        self.sink = blocks.null_sink(gr.sizeof_float *
                                     self.dab_params.num_carriers * 2)

        self.connect(self.src, self.demod, self.sink)

        # build GUI
        self.connect(self.demod.deinterleave, self.v2s, self.scope)
        vbox.Add(self.scope.win, 10, wx.EXPAND)

        self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
            self.panel,
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=self.sample_rate,
            fft_size=1024,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title="FFT Plot",
            peak_hold=False,
        )
        vbox.Add(self.wxgui_fftsink2_0.win)
        self.connect((self.src, 0), (self.wxgui_fftsink2_0, 0))

        # retune USRP to correct FFE?
        self.correct_ffe_usrp = options.correct_ffe_usrp
        if self.correct_ffe_usrp:
            print "--> correcting FFE on USRP"
            self.run_correct_ffe_thread = True
            self.ffe_updater = threading.Timer(0.1, self.correct_ffe)
            self.ffe_updater.setDaemon(True)
            self.ffe_updater.start()
Пример #17
0
	def __init__(self):
		gr.top_block.__init__(self)

		parser = OptionParser(option_class=eng_option, usage="%prog: [options] <filename>")
		parser.add_option("-m", "--dab-mode", type="int", default=1,
				help="DAB mode [default=%default]")
		parser.add_option("-F", "--filter-input", action="store_true", default=False,
				help="Enable FFT filter at input")
		parser.add_option('-c', '--correct-ffe', action="store_true", default=False,
			help="do fine frequency correction")
		parser.add_option('-u', '--correct-ffe-usrp', action="store_true", default=False,
			help="do fine frequency correction by retuning the USRP instead of in software")
		parser.add_option('-e', '--equalize-magnitude', action="store_true", default=False,
			help="do magnitude equalization")
		parser.add_option("-s", "--resample-fixed", type="eng_float", default=1,
			help="resample by a fixed factor (fractional interpolation)")
		parser.add_option("-S", "--autocorrect-sample-rate", action="store_true", default=False,
				help="Estimate sample rate offset and resample (dynamic fractional interpolation)")
		parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0),
			help="select USRP Rx side A or B [default=A]")
		parser.add_option("-f", "--freq", type="eng_float", default=227.36e6,
			help="set frequency to FREQ [default=%default]")
		parser.add_option("-r", "--sample-rate", type="int", default=2000000,
			help="set sample rate to SAMPLE_RATE [default=%default]")
		parser.add_option("-d", "--decim", type="intx", default=32,
			help="set decimation rate to DECIM [default=%default]")
		parser.add_option("-g", "--rx-gain", type="eng_float", default=None,
			help="set receive gain in dB (default is midpoint)")
		parser.add_option('-v', '--verbose', action="store_true", default=False,
			help="verbose output")
		(options, args) = parser.parse_args()

		
		self.verbose = options.verbose
		self.sample_rate = options.sample_rate

		if len(args) == 0:
			if self.verbose:
				print "--> receiving from USRP"
			self.src = osmosdr.source()
			self.src.set_sample_rate(self.sample_rate)
			self.src.set_freq_corr(0)
			# tune frequency
			self.frequency = options.freq
			self.orig_frequency = options.freq
			self.set_freq(options.freq)

			self.src.set_freq_corr(0)

			# set gain 
			if options.rx_gain is None:
				# if no gain was specified, use AGC
				self.src.set_gain_mode(True, 0)
			else:
				self.src.set_gain(options.rx_gain, 0)

		else:
			if self.verbose:
				print "--> receiving from file: " + args[0]
			self.filename = args[0]
			self.src = blocks.file_source(gr.sizeof_gr_complex, self.filename, False)
		
		
		self.dab_params = grdab.parameters.dab_parameters(mode=options.dab_mode, sample_rate=self.sample_rate, verbose=options.verbose)
		self.rx_params = grdab.parameters.receiver_parameters(mode=options.dab_mode, softbits=True, input_fft_filter=options.filter_input, 			autocorrect_sample_rate=options.autocorrect_sample_rate, sample_rate_correction_factor=options.resample_fixed, verbose=options.verbose, correct_ffe=options.correct_ffe, equalize_magnitude=options.equalize_magnitude)

		self.demod = grdab.ofdm_demod(self.dab_params, self.rx_params, verbose=self.verbose) 

		self.v2s = blocks.vector_to_stream(gr.sizeof_gr_complex, self.dab_params.num_carriers)

		self.sink = blocks.null_sink(gr.sizeof_float*self.dab_params.num_carriers*2)

		self.connect(self.src, self.demod, self.sink)

		# retune USRP to correct FFE?
		self.correct_ffe_usrp = options.correct_ffe_usrp
		if self.correct_ffe_usrp:
			print "--> correcting FFE on USRP"
			self.run_correct_ffe_thread = True
			self.ffe_updater = threading.Timer(0.1, self.correct_ffe)
			self.ffe_updater.setDaemon(True)
			self.ffe_updater.start()
Пример #18
0
def receive_dabplus(frequency=220.352e6,
                    rf_gain=25,
                    if_gain=0,
                    bb_gain=0,
                    ppm=80,
                    audio_sample_rate=48000,
                    dab_bit_rate=64,
                    dab_address=304,
                    dab_subch_size=64,
                    dab_protect_level=1,
                    use_zeromq=False,
                    dabplus=True,
                    server="tcp://127.0.0.1:10444",
                    server_control="tcp://127.0.0.1:10445",
                    from_file=None,
                    from_file_repeat=False,
                    skip_xrun_monitor=False):
    from gnuradio import gr, blocks, audio
    if use_zeromq:
        from gnuradio import zeromq

    import time
    import osmosdr
    import grdab

    samp_rate = samp_rate = 2048000

    print("Setting frequency: %0.3f MHz" % (frequency / 1e6))
    print("Setting RF gain to: %d" % rf_gain)
    print("Setting Frequency error (ppm) to: %d" % ppm)

    fg = gr.top_block()

    if from_file != None:
        file_input = blocks.file_source(gr.sizeof_gr_complex, from_file,
                                        from_file_repeat)
        if skip_xrun_monitor:
            src = file_input
        else:
            fthrottle = blocks.throttle(gr.sizeof_gr_complex, samp_rate)
            fg.connect(file_input, fthrottle)
            src = fthrottle
        print("Run from file %s" % from_file)
    elif not use_zeromq:
        osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + '')
        osmosdr_source_0.set_sample_rate(samp_rate)
        osmosdr_source_0.set_center_freq(frequency, 0)
        osmosdr_source_0.set_freq_corr(0, 0)
        osmosdr_source_0.set_dc_offset_mode(0, 0)
        osmosdr_source_0.set_iq_balance_mode(0, 0)
        osmosdr_source_0.set_gain_mode(False, 0)
        osmosdr_source_0.set_gain(rf_gain, 0)
        osmosdr_source_0.set_if_gain(if_gain, 0)
        osmosdr_source_0.set_bb_gain(bb_gain, 0)
        osmosdr_source_0.set_antenna('RX2', 0)
        osmosdr_source_0.set_bandwidth(2000000, 0)
        src = osmosdr_source_0
    else:
        zeromq_source = zeromq.sub_source(gr.sizeof_gr_complex, 1, server, 100,
                                          False, -1)
        rpc_mgr_server = zeromq.rpc_manager()
        rpc_mgr_server.set_request_socket(server_control)
        rpc_mgr_server.request("set_sample_rate", [samp_rate])
        rpc_mgr_server.request("set_rf_gain", [rf_gain])
        rpc_mgr_server.request("set_if_gain", [if_gain])
        rpc_mgr_server.request("set_bb_gain", [bb_gain])
        rpc_mgr_server.request(
            "set_ppm", [0]
        )  # Not using hardware correction since it behaves differently on different hardware
        rpc_mgr_server.request("set_frequency", [frequency])
        time.sleep(0.7)
        src = zeromq_source

    sample_rate_correction_factor = 1 + float(ppm) * 1e-6
    dab_ofdm_demod_0 = grdab.ofdm_demod(
        grdab.parameters.dab_parameters(mode=1,
                                        sample_rate=samp_rate,
                                        verbose=False),
        grdab.parameters.receiver_parameters(
            mode=1,
            softbits=True,
            input_fft_filter=True,
            autocorrect_sample_rate=False,
            sample_rate_correction_factor=sample_rate_correction_factor,
            always_include_resample=True,
            verbose=False,
            correct_ffe=True,
            equalize_magnitude=True))

    if dabplus:
        decoder = grdab.dabplus_audio_decoder_ff(
            grdab.parameters.dab_parameters(mode=1,
                                            sample_rate=samp_rate,
                                            verbose=False), dab_bit_rate,
            dab_address, dab_subch_size, dab_protect_level, True)
    else:
        decoder = grdab.dab_audio_decoder_ff(
            grdab.parameters.dab_parameters(mode=1,
                                            sample_rate=samp_rate,
                                            verbose=False), dab_bit_rate,
            dab_address, dab_subch_size, dab_protect_level, True)

    xrun_monitor = grdab.xrun_monitor_cc(100000)
    f2c = blocks.float_to_complex()
    c2f = blocks.complex_to_float()

    audio_sink_0 = audio.sink(audio_sample_rate, '', True)

    fg.connect(src, dab_ofdm_demod_0, decoder)
    fg.connect((decoder, 0), (f2c, 0))
    fg.connect((decoder, 1), (f2c, 1))
    if skip_xrun_monitor:
        fg.connect(f2c, c2f)
    else:
        fg.connect(f2c, xrun_monitor)
        fg.connect(xrun_monitor, c2f)
    fg.connect((c2f, 0), (audio_sink_0, 0))
    fg.connect((c2f, 1), (audio_sink_0, 1))

    if from_file != None and from_file_repeat == False and skip_xrun_monitor:
        fg.run()
    else:
        fg.start()
        input("Running..")
        fg.stop()
Пример #19
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option,
                              usage="%prog: [options] output-filename")
        parser.add_option("-m",
                          "--dab-mode",
                          type="int",
                          default=1,
                          help="DAB mode [default=%default]")
        parser.add_option("-F",
                          "--filter-input",
                          action="store_true",
                          default=False,
                          help="Enable FFT filter at input")
        parser.add_option('-c',
                          '--correct-ffe',
                          action="store_true",
                          default=False,
                          help="do fine frequency correction")
        parser.add_option(
            '-u',
            '--correct-ffe-usrp',
            action="store_true",
            default=False,
            help=
            "do fine frequency correction by retuning the USRP instead of in software"
        )
        parser.add_option('-e',
                          '--equalize-magnitude',
                          action="store_true",
                          default=False,
                          help="do magnitude equalization")
        parser.add_option(
            "-s",
            "--resample-fixed",
            type="eng_float",
            default=1,
            help="resample by a fixed factor (fractional interpolation)")
        parser.add_option(
            "-S",
            "--autocorrect-sample-rate",
            action="store_true",
            default=False,
            help=
            "Estimate sample rate offset and resample (dynamic fractional interpolation)"
        )
        parser.add_option("-R",
                          "--rx-subdev-spec",
                          type="subdev",
                          default=(0, 0),
                          help="select USRP Rx side A or B [default=A]")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=227.36e6,
                          help="set frequency to FREQ [default=%default]")
        parser.add_option(
            "-d",
            "--decim",
            type="intx",
            default=32,
            help="set decimation rate to DECIM [default=%default]")
        parser.add_option("-g",
                          "--rx-gain",
                          type="eng_float",
                          default=None,
                          help="set receive gain in dB (default is midpoint)")
        parser.add_option('-v',
                          '--verbose',
                          action="store_true",
                          default=False,
                          help="verbose output")
        parser.add_option('-a',
                          '--antenna',
                          type="string",
                          default="TX/RX",
                          help="select antenna")
        (options, args) = parser.parse_args()

        # if len(args)!=1:
        # parser.print_help()
        # sys.exit(1)
        # else:
        # self.filename = args[0]

        # if gr.enable_realtime_scheduling() != gr.RT_OK:
        #       print "-> failed to enable realtime scheduling"

        self.verbose = options.verbose

        self.src = uhd.usrp_source("", uhd.io_type.COMPLEX_FLOAT32, 1)
        #self.src.set_mux(usrp.determine_rx_mux_value(self.src, options.rx_subdev_spec))
        #self.subdev = uhd.selected_subdev(self.src, options.rx_subdev_spec)
        #print "--> using RX dboard " + self.subdev.side_and_name()

        self.sample_rate = 2e6  #self.src.adc_rate()/options.decim
        self.src.set_samp_rate(self.sample_rate)
        self.src.set_antenna(options.antenna)
        self.dab_params = grdab.parameters.dab_parameters(
            mode=options.dab_mode,
            sample_rate=self.sample_rate,
            verbose=options.verbose)
        self.rx_params = grdab.parameters.receiver_parameters(
            mode=options.dab_mode,
            softbits=True,
            input_fft_filter=options.filter_input,
            autocorrect_sample_rate=options.autocorrect_sample_rate,
            sample_rate_correction_factor=options.resample_fixed,
            verbose=options.verbose,
            correct_ffe=options.correct_ffe,
            equalize_magnitude=options.equalize_magnitude)

        self.demod = grdab.ofdm_demod(self.dab_params,
                                      self.rx_params,
                                      verbose=options.verbose)

        # self.sink = gr.file_sink(gr.sizeof_char*384, self.filename)
        # self.trigsink = gr.null_sink(gr.sizeof_char)
        # self.connect(self.src, self.demod, self.sink)
        # self.connect((self.demod,1), self.trigsink)

        self.fic_dec = grdab.fic_decode(self.dab_params)
        self.connect(self.src, self.demod, self.fic_dec)

        # add MSC chain
        self.dabplus = grdab.dabplus_audio_decoder_ff(self.dab_params, 112, 54,
                                                      84, 2, True)
        self.audio = audio.sink_make(32000)
        self.connect(self.demod, self.dabplus)
        # left stereo channel
        self.connect((self.dabplus, 0), (self.audio, 0))
        # right stereo channel
        self.connect((self.dabplus, 1), (self.audio, 1))

        # tune frequency
        self.frequency = options.freq
        self.set_freq(options.freq)

        # set gain
        if options.rx_gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.src.get_gain_range()
            options.rx_gain = float(g.start() + g.stop()) / 2
        self.src.set_gain(options.rx_gain)
        #self.subdev.set_gain(options.rx_gain)

        self.update_ui = options.verbose
        if self.update_ui:
            self.run_ui_update_thread = True
            self.ui_updater = threading.Timer(0.1, self.update_ui_function)
            self.ui_updater.setDaemon(True)
            self.ui_updater.start()

        self.correct_ffe_usrp = options.correct_ffe_usrp
        if self.correct_ffe_usrp:
            print "--> correcting FFE on USRP"
            self.run_correct_ffe_thread = True
            self.ffe_updater = threading.Timer(0.1, self.correct_ffe)
            self.ffe_updater.setDaemon(True)
            self.ffe_updater.start()