Example #1
0
    def __init__(self, fg, pkt_queue, spb, alpha,  use_barker=0,
                 check_crc=True):
        # RRC data filter
	ntaps = 2 * spb - 1

	self.rrc_taps = gr.firdes.root_raised_cosine(
		1,		# gain  FIXME may need to be spb
		spb,             # sampling freq
		1.0,		# symbol_rate
		alpha,
                ntaps)

        self.barker_taps = bbn.firdes_barker(spb)

        if use_barker == 1:
            self.rx_filter = gr.fir_filter_ccf(1, self.barker_taps)
        else:
            self.rx_filter = gr.fir_filter_ccf(1, self.rrc_taps)

        self.slicer = bbn.slicer_cc(spb, 16);
        self.demod = bbn.dpsk_demod_cb();
        self.descramble = bbn.scrambler_bb(False);
        self.plcp = bbn.plcp80211_bb(pkt_queue, check_crc);

        fg.connect(self.rx_filter, self.slicer);
        fg.connect(self.slicer, self.demod);
        fg.connect((self.demod, 0), (self.plcp, 0));
        fg.connect((self.demod, 1), (self.plcp, 1));

        gr.hier_block.__init__(self, fg, self.rx_filter, self.plcp)
        bbn.crc16_init()
Example #2
0
    def __init__(self, usrp_offset):
        gr.top_block.__init__(self)

        u = usrp.source_c(decim_rate=decim)
        s = usrp.pick_subdev(u, (usrp_dbid.DBS_RX, ))
        u.set_mux(usrp.determine_rx_mux_value(u, s))
        subdev = usrp.selected_subdev(u, s)

        if subdev.dbid() != usrp_dbid.DBS_RX:
            raise Exception('dbs daughterboard not detected!')

        subdev.set_gain(gain)

        sps = u.adc_freq() / u.decim_rate()
        if sps < 2 * gsm_rate:
            raise Exception('sample rate too low')

        u.tune(0, subdev, c0 + usrp_offset)

        xcf = 150e3
        xtw = 50e3
        xt = gr.firdes.low_pass(1.0, sps, xcf, xtw, gr.firdes.WIN_HAMMING)
        xf = gr.fir_filter_ccf(1, xt)

        g = gssm.sink(sps)

        self.connect(u, xf, g)
Example #3
0
	def __init__(self):
		gr.top_block.__init__ (self)
		
		self.u = usrp.source_c(0, usrp_decim)
		print "USRP Serial: ", self.u.serial_number()
		usrp_rate = self.u.adc_rate() / usrp_decim		# 256 kS/s
		rx_subdev_spec = usrp.pick_subdev(self.u, dblist)
		self.u.set_mux(usrp.determine_rx_mux_value(self.u, rx_subdev_spec))
		self.subdev = usrp.selected_subdev(self.u, rx_subdev_spec)
		print "Using d'board", self.subdev.side_and_name()
		
		self.gain = self.subdev.gain_range()[1]
		self.subdev.set_gain(self.gain)
		r = usrp.tune(self.u, 0, self.subdev, freq)
		if r:
			print "Freq: ", freq/1e6, "MHz"
		else:
			print "Failed to set frequency, quitting!"
			sys.exit(1)
		
		chan_filter_coeffs = gr.firdes.low_pass(
			1.0,			# gain
			usrp_rate,		# sampling rate
			80e3,			# passband cutoff
			35e3,			# transition width
			gr.firdes.WIN_HAMMING)
		self.chan_filter = gr.fir_filter_ccf(1, chan_filter_coeffs)
		print "# channel filter:", len(chan_filter_coeffs), "taps"
		
		self.file_sink = gr.file_sink(gr.sizeof_gr_complex*1, "/home/sdr/rds_samples.dat")
		
		self.connect(self.u, self.chan_filter, self.file_sink)
Example #4
0
    def __init__(self):
        gr.top_block.__init__(self)

        self.u = usrp.source_c(0, usrp_decim)
        print "USRP Serial: ", self.u.serial_number()
        usrp_rate = self.u.adc_rate() / usrp_decim  # 256 kS/s
        rx_subdev_spec = usrp.pick_subdev(self.u, dblist)
        self.u.set_mux(usrp.determine_rx_mux_value(self.u, rx_subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, rx_subdev_spec)
        print "Using d'board", self.subdev.side_and_name()

        self.gain = self.subdev.gain_range()[1]
        self.subdev.set_gain(self.gain)
        r = usrp.tune(self.u, 0, self.subdev, freq)
        if r:
            print "Freq: ", freq / 1e6, "MHz"
        else:
            print "Failed to set frequency, quitting!"
            sys.exit(1)

        chan_filter_coeffs = gr.firdes.low_pass(
            1.0,  # gain
            usrp_rate,  # sampling rate
            80e3,  # passband cutoff
            35e3,  # transition width
            gr.firdes.WIN_HAMMING)
        self.chan_filter = gr.fir_filter_ccf(1, chan_filter_coeffs)
        print "# channel filter:", len(chan_filter_coeffs), "taps"

        self.file_sink = gr.file_sink(gr.sizeof_gr_complex * 1,
                                      "/home/sdr/rds_samples.dat")

        self.connect(self.u, self.chan_filter, self.file_sink)
Example #5
0
    def __init__(self, input_path, sample_rate, output_path):
        gr.top_block.__init__(self)

        # We don't use the existing NBFM demodulator block because it
        # contains a lowpass output filter which is unsuitable for 9600
        # GMSK (it's designed for voice).

        self.source = gr.file_source(gr.sizeof_gr_complex * 1, input_path, False)
        self.low_pass_filter = gr.fir_filter_ccf(
            4, firdes.low_pass(1, sample_rate, 15000, 100, firdes.WIN_HAMMING, 6.76)
        )

        # High pass filter to remove the DC component. This is important
        # when the signal is near the SDR's local oscillator.
        # NOTE(tstranex): Disabled since we are now shifting the FCD
        # center frequency instead.
        # self.high_pass_filter = gr.fir_filter_ccf(1, firdes.high_pass(
        # 	1, sample_rate/4, 100, 100, firdes.WIN_HAMMING, 6.76))

        self.quadrature_demod = gr.quadrature_demod_cf(sample_rate / 4 / (2 * 3.14 * 3000))
        self.fm_deemph = blks2.fm_deemph(fs=sample_rate / 4, tau=75e-6)
        self.boost_volume = gr.multiply_const_vff((1.52,))
        self.sink = gr.wavfile_sink(output_path, 1, sample_rate / 4, 16)

        self.connect((self.source, 0), (self.low_pass_filter, 0))
        # self.connect((self.low_pass_filter, 0), (self.high_pass_filter, 0))
        # self.connect((self.high_pass_filter, 0), (self.quadrature_demod, 0))
        self.connect((self.low_pass_filter, 0), (self.quadrature_demod, 0))

        self.connect((self.quadrature_demod, 0), (self.fm_deemph, 0))
        self.connect((self.fm_deemph, 0), (self.boost_volume, 0))
        self.connect((self.boost_volume, 0), (self.sink, 0))
Example #6
0
    def __init__(self, rx_callback, spb, alpha, SNR):
        # m is constellation size
        # if diff==True we are doing DxPSK
        gr.flow_graph.__init__(self)

        fg = self

        # transmitter
        self.packet_transmitter = bbn_80211b_mod_pkts(fg, spb=spb, alpha=alpha,
                                                      gain=1)

        # add some noise
        add = gr.add_cc()
        noise = gr.noise_source_c(gr.GR_GAUSSIAN, pow(10.0,-SNR/20.0))

        # channel filter
        rx_filt_taps = gr.firdes.low_pass(1,spb,0.8,0.1,gr.firdes.WIN_HANN)
        rx_filt = gr.fir_filter_ccf(1,rx_filt_taps)

        # receiver
        self.bit_receiver = bbn_80211b_demod_pkts(self, spb=spb, alpha=alpha,
                                                  callback=rx_callback)

        fg.connect(self.packet_transmitter, (add,0))
        fg.connect(noise, (add,1))

        #xfile=gr.file_sink(gr.sizeof_gr_complex,"txdata");
        #fg.connect(add, xfile)

        fg.connect(add, rx_filt)
        fg.connect(rx_filt, self.bit_receiver)
Example #7
0
	def __init__(self, usrp_offset):
		gr.top_block.__init__(self)

		u = usrp.source_c(decim_rate = decim)
		s = usrp.pick_subdev(u, (usrp_dbid.DBS_RX,))
		u.set_mux(usrp.determine_rx_mux_value(u, s))
		subdev = usrp.selected_subdev(u, s)

		if subdev.dbid() != usrp_dbid.DBS_RX:
			raise Exception('dbs daughterboard not detected!')

		subdev.set_gain(gain)

		sps = u.adc_freq() / u.decim_rate()
		if sps < 2 * gsm_rate:
			raise Exception('sample rate too low')

		u.tune(0, subdev, c0 + usrp_offset)

		xcf = 150e3
		xtw = 50e3
		xt = gr.firdes.low_pass(1.0, sps, xcf, xtw,
		   gr.firdes.WIN_HAMMING)
		xf = gr.fir_filter_ccf(1, xt)

		g = gssm.sink(sps)

		self.connect(u, xf, g)
Example #8
0
  def __init__(self, fft_length, pn_weights):
    gr.hier_block2.__init__(self, "modified_timing_metric",
        gr.io_signature(1,1,gr.sizeof_gr_complex),
        gr.io_signature(1,1,gr.sizeof_float))

    assert(len(pn_weights) == fft_length)

    self.input = gr.kludge_copy(gr.sizeof_gr_complex)
    self.connect(self,self.input)

    # P(d) = sum(0 to L-1, conj(delayed(r)) * r)
    conj = gr.conjugate_cc()
    mixer = gr.multiply_cc()
    nominator = gr.fir_filter_ccf(1,[pn_weights[fft_length-i-1]*pn_weights[fft_length/2-i-1] for i in range(fft_length/2)])

    self.connect(self.input, delay(gr.sizeof_gr_complex,fft_length/2), conj, (mixer,0))
    self.connect(self.input, (mixer,1))
    self.connect(mixer, nominator)
    # moving_avg = P(d)

    # R(d)
    denominator = schmidl_denominator(fft_length)

    # |P(d)| ** 2 / (R(d)) ** 2
    p_mag_sqrd = gr.complex_to_mag_squared()
    r_sqrd = gr.multiply_ff()
    self.timing_metric = gr.divide_ff()

    self.connect(nominator, p_mag_sqrd, (self.timing_metric,0))
    self.connect(self.input, denominator, (r_sqrd,0))
    self.connect(denominator, (r_sqrd,1))
    self.connect(r_sqrd, (self.timing_metric,1))
    self.connect(self.timing_metric, self)
Example #9
0
    def __init__(self, usrp_offset):
        gr.flow_graph.__init__(self)

        print "decim = %d, gain = %d, offset = %.2f" % (decim, gain, usrp_offset)
        print "filter center %.2f, filter width %.2f" % (xcf, xtw)

        u = usrp.source_c(decim_rate=decim)
        s = usrp.pick_subdev(u, (usrp_dbid.DBS_RX,))
        u.set_mux(usrp.determine_rx_mux_value(u, s))
        subdev = usrp.selected_subdev(u, s)

        if subdev.dbid() != usrp_dbid.DBS_RX:
            raise Exception("dbs daughterboard not detected!")

        subdev.set_gain(gain)

        sps = u.adc_freq() / u.decim_rate()
        if sps < 2 * gsm_rate:
            raise Exception("sample rate too low")

        u.tune(0, subdev, c0 + usrp_offset)

        xt = gr.firdes.low_pass(1.0, sps, xcf, xtw, gr.firdes.WIN_HAMMING)
        xf = gr.fir_filter_ccf(1, xt)

        self.gs = gs = gssm.sink(sps)

        self.connect(u, xf, gs)
Example #10
0
    def __init__(self, input_path, sample_rate, output_path):
        gr.top_block.__init__(self)

        # We don't use the existing NBFM demodulator block because it
        # contains a lowpass output filter which is unsuitable for 9600
        # GMSK (it's designed for voice).

        self.source = gr.file_source(gr.sizeof_gr_complex * 1, input_path,
                                     False)
        self.low_pass_filter = gr.fir_filter_ccf(
            4,
            firdes.low_pass(1, sample_rate, 15000, 100, firdes.WIN_HAMMING,
                            6.76))

        # High pass filter to remove the DC component. This is important
        # when the signal is near the SDR's local oscillator.
        # NOTE(tstranex): Disabled since we are now shifting the FCD
        # center frequency instead.
        #self.high_pass_filter = gr.fir_filter_ccf(1, firdes.high_pass(
        #	1, sample_rate/4, 100, 100, firdes.WIN_HAMMING, 6.76))

        self.quadrature_demod = gr.quadrature_demod_cf(sample_rate / 4 /
                                                       (2 * 3.14 * 3000))
        self.fm_deemph = blks2.fm_deemph(fs=sample_rate / 4, tau=75e-6)
        self.boost_volume = gr.multiply_const_vff((1.52, ))
        self.sink = gr.wavfile_sink(output_path, 1, sample_rate / 4, 16)

        self.connect((self.source, 0), (self.low_pass_filter, 0))
        #self.connect((self.low_pass_filter, 0), (self.high_pass_filter, 0))
        #self.connect((self.high_pass_filter, 0), (self.quadrature_demod, 0))
        self.connect((self.low_pass_filter, 0), (self.quadrature_demod, 0))

        self.connect((self.quadrature_demod, 0), (self.fm_deemph, 0))
        self.connect((self.fm_deemph, 0), (self.boost_volume, 0))
        self.connect((self.boost_volume, 0), (self.sink, 0))
def graph (args):

    nargs = len (args)
    if nargs == 1:
	infile = args[0]
    else:
	sys.stderr.write('usage: interp.py input_file\n')
	sys.exit (1)

    sampling_freq = 6400000

    fg = gr.flow_graph ()

    src0 = gr.file_source (gr.sizeof_gr_complex,infile)
    src1 = gr.sig_source_c (sampling_freq, gr.GR_CONST_WAVE, 1, 0)
    src2 = gr.sig_source_c (sampling_freq, gr.GR_CONST_WAVE, 1, 0)

    interlv = gr.interleave(gr.sizeof_gr_complex)

    lp_coeffs = gr.firdes.low_pass ( 3, 19.2e6, 3.2e6, .5e6, gr.firdes.WIN_HAMMING )
    lp = gr.fir_filter_ccf ( 1, lp_coeffs )

    file = gr.file_sink(gr.sizeof_gr_complex,"/tmp/atsc_pipe_1")

    fg.connect( src0, (interlv, 0) )
    fg.connect( src1, (interlv, 1) )
    fg.connect( src2, (interlv, 2) )
    fg.connect( interlv, lp, file )

    fg.start()
    raw_input ('Head End: Press Enter to stop')
    fg.stop()
Example #12
0
    def __init__(self, options, args, queue):
        gr.top_block.__init__(self)

        self.options = options
        self.args = args
        rate = int(options.rate)

        if options.filename is None:
            self.u = uhd.single_usrp_source("", uhd.io_type_t.COMPLEX_FLOAT32,
                                            1)
            time_spec = uhd.time_spec(0.0)
            self.u.set_time_now(time_spec)

            #if(options.rx_subdev_spec is None):
            #  options.rx_subdev_spec = ""
            #self.u.set_subdev_spec(options.rx_subdev_spec)
            if not options.antenna is None:
                self.u.set_antenna(options.antenna)

            self.u.set_samp_rate(rate)
            rate = int(self.u.get_samp_rate())  #retrieve actual

            if options.gain is None:  #set to halfway
                g = self.u.get_gain_range()
                options.gain = (g.start() + g.stop()) / 2.0

            if not (self.tune(options.freq)):
                print "Failed to set initial frequency"

            print "Setting gain to %i" % (options.gain, )
            self.u.set_gain(options.gain)
            print "Gain is %i" % (self.u.get_gain(), )

        else:
            self.u = gr.file_source(gr.sizeof_gr_complex, options.filename)

        print "Rate is %i" % (rate, )

        pass_all = 0
        if options.output_all:
            pass_all = 1

        self.demod = gr.complex_to_mag()
        self.avg = gr.moving_average_ff(100, 1.0 / 100, 400)

        #the DBSRX especially tends to be spur-prone; the LPF keeps out the
        #spur multiple that shows up at 2MHz
        self.lpfiltcoeffs = gr.firdes.low_pass(1, rate, 1.8e6, 100e3)
        self.lpfilter = gr.fir_filter_ccf(1, self.lpfiltcoeffs)

        self.preamble = air.modes_preamble(rate, options.threshold)
        #self.framer = air.modes_framer(rate)
        self.slicer = air.modes_slicer(rate, queue)

        self.connect(self.u, self.lpfilter, self.demod)
        self.connect(self.demod, self.avg)
        self.connect(self.demod, (self.preamble, 0))
        self.connect(self.avg, (self.preamble, 1))
        self.connect((self.preamble, 0), (self.slicer, 0))
Example #13
0
File: ec3k.py Project: asdil12/ec3k
	def _setup_top_block(self):

		self.tb = gr.top_block()

		samp_rate = 96000
		oversample = 10
		center_freq = 868.280e6

		# Radio receiver, initial downsampling
		args = str("nchan=1 rtl=%s,buffers=16,offset_tune=1" % self.device)
		osmosdr_source = osmosdr.source_c(args=args)
		osmosdr_source.set_sample_rate(samp_rate*oversample)
		osmosdr_source.set_center_freq(center_freq, 0)
		osmosdr_source.set_freq_corr(0, 0)
		osmosdr_source.set_gain_mode(1, 0)
		osmosdr_source.set_gain(0, 0)

		low_pass_filter = gr.fir_filter_ccf(oversample, 
				firdes.low_pass(1, samp_rate*oversample, 90e3, 8e3, firdes.WIN_HAMMING, 6.76))

		self.tb.connect((osmosdr_source, 0), (low_pass_filter, 0))

		# Squelch
		self.noise_probe = gr.probe_avg_mag_sqrd_c(0, 1.0/samp_rate/1e2)
		self.squelch = gr.simple_squelch_cc(self.noise_level, 1)

		noise_probe_thread = threading.Thread(target=self._noise_probe_thread)
		noise_probe_thread.start()
		self.threads.append(noise_probe_thread)

		self.tb.connect((low_pass_filter, 0), (self.noise_probe, 0))
		self.tb.connect((low_pass_filter, 0), (self.squelch, 0))

		# FM demodulation
		quadrature_demod = gr.quadrature_demod_cf(1)

		self.tb.connect((self.squelch, 0), (quadrature_demod, 0))

		# Binary slicing, transformation into capture-compatible format

		add_offset = gr.add_const_vff((-1e-3, ))

		binary_slicer = digital.binary_slicer_fb()

		char_to_float = gr.char_to_float(1, 1)

		multiply_const = gr.multiply_const_vff((255, ))

		float_to_uchar = gr.float_to_uchar()

		pipe_sink = gr.file_sink(gr.sizeof_char*1, self.pipe)
		pipe_sink.set_unbuffered(False)

		self.tb.connect((quadrature_demod, 0), (add_offset, 0))
		self.tb.connect((add_offset, 0), (binary_slicer, 0))
		self.tb.connect((binary_slicer, 0), (char_to_float, 0))
		self.tb.connect((char_to_float, 0), (multiply_const, 0))
		self.tb.connect((multiply_const, 0), (float_to_uchar, 0))
		self.tb.connect((float_to_uchar, 0), (pipe_sink, 0))
Example #14
0
  def __init__(self, options, args, queue):
    gr.top_block.__init__(self)

    self.options = options
    self.args = args
    rate = int(options.rate)

    if options.filename is None:
      self.u = uhd.single_usrp_source("", uhd.io_type_t.COMPLEX_FLOAT32, 1)
      time_spec = uhd.time_spec(0.0)
      self.u.set_time_now(time_spec)

      #if(options.rx_subdev_spec is None):
      #  options.rx_subdev_spec = ""
      #self.u.set_subdev_spec(options.rx_subdev_spec)
      if not options.antenna is None:
        self.u.set_antenna(options.antenna)

      self.u.set_samp_rate(rate)
      rate = int(self.u.get_samp_rate()) #retrieve actual

      if options.gain is None: #set to halfway
        g = self.u.get_gain_range()
        options.gain = (g.start()+g.stop()) / 2.0

      if not(self.tune(options.freq)):
        print "Failed to set initial frequency"

      print "Setting gain to %i" % (options.gain,)
      self.u.set_gain(options.gain)
      print "Gain is %i" % (self.u.get_gain(),)

    else:
      self.u = gr.file_source(gr.sizeof_gr_complex, options.filename)

    print "Rate is %i" % (rate,)

    pass_all = 0
    if options.output_all :
      pass_all = 1

    self.demod = gr.complex_to_mag()
    self.avg = gr.moving_average_ff(100, 1.0/100, 400)
    
    #the DBSRX especially tends to be spur-prone; the LPF keeps out the
    #spur multiple that shows up at 2MHz
    self.lpfiltcoeffs = gr.firdes.low_pass(1, rate, 1.8e6, 100e3)
    self.lpfilter = gr.fir_filter_ccf(1, self.lpfiltcoeffs)
    
    self.preamble = air.modes_preamble(rate, options.threshold)
    #self.framer = air.modes_framer(rate)
    self.slicer = air.modes_slicer(rate, queue)
    
    self.connect(self.u, self.lpfilter, self.demod)
    self.connect(self.demod, self.avg)
    self.connect(self.demod, (self.preamble, 0))
    self.connect(self.avg, (self.preamble, 1))
    self.connect((self.preamble, 0), (self.slicer, 0))
	def __init__(self):
		gr.top_block.__init__(self, "FM Receiver")

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 96000
		self.xlate_filter_taps = xlate_filter_taps = firdes.low_pass(1, samp_rate, 48000, 5000, firdes.WIN_HAMMING, 6.76)
		self.sql_lev = sql_lev = -100
		self.rf_gain = rf_gain = 20
		self.freq = freq = 144800000
		self.af_gain = af_gain = 2
		self.sat_file_name = sat_file_name = "Undefined"

		##################################################
		# Blocks
		##################################################
		self.xlating_fir_filter = gr.freq_xlating_fir_filter_ccc(1, (xlate_filter_taps), 0, samp_rate)
		self.nbfm_normal = blks2.nbfm_rx(
			audio_rate=48000,
			quad_rate=96000,
			tau=75e-6,
			max_dev=5e3,
		)
		self.low_pass_filter = gr.fir_filter_ccf(1, firdes.low_pass(
			1, samp_rate, 12500, 1500, firdes.WIN_HAMMING, 6.76))
		self.gr_simple_squelch_cc_0 = gr.simple_squelch_cc(sql_lev, 1)
		self.gr_multiply_const_vxx_1 = gr.multiply_const_vff((af_gain, ))
		self.fcd_source_c_1 = fcd.source_c("hw:1")
		self.fcd_source_c_1.set_freq(freq)
		self.fcd_source_c_1.set_freq_corr(-32)
		    
		self.audio_sink = audio.sink(48000, "", True)
		
		self.wavfile_sink = gr.wavfile_sink(self.sat_file_name, 1, 11025, 16)
		self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_fff(
			interpolation=11025,
			decimation=48000,
			taps=None,
			fractional_bw=None,
		)
		

		##################################################
		# Connections
		##################################################
		self.connect((self.xlating_fir_filter, 0), (self.low_pass_filter, 0))
		self.connect((self.low_pass_filter, 0), (self.gr_simple_squelch_cc_0, 0))
		self.connect((self.gr_multiply_const_vxx_1, 0), (self.audio_sink, 1))
		self.connect((self.gr_multiply_const_vxx_1, 0), (self.audio_sink, 0))
		self.connect((self.gr_simple_squelch_cc_0, 0), (self.nbfm_normal, 0))
		self.connect((self.nbfm_normal, 0), (self.gr_multiply_const_vxx_1, 0))
		self.connect((self.fcd_source_c_1, 0), (self.xlating_fir_filter, 0))
		self.connect((self.nbfm_normal, 0), (self.blks2_rational_resampler_xxx_0, 0))
		self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.wavfile_sink, 0))
Example #16
0
    def __init__(self, options, args):
        gr.top_block.__init__(self)

        self.options = options
        self.args = args

        frekvens = options.freq

        # u = usrp.source_c(0)
        # u.set_decim_rate(256)
        # subdev_spec = (1,0)
        # u.set_mux(usrp.determine_rx_mux_value(u,subdev_spec))
        # subdev = usrp.selected_subdev(u,subdev_spec)
        # subdev.set_auto_tr(True)
        # subdev.set_gain(57)
        # usrp.tune(u,0,subdev,frekvens)#106.3e6)
        # samplerate = 64000000/256 # 250000
        self.u = uhd.usrp_source("", uhd.io_type_t.COMPLEX_FLOAT32, 1)
        self.u.set_subdev_spec("")
        # default should be good?
        self.u.set_samp_rate(250e3)
        samplerate = self.u.get_samp_rate()  # Retrieve what it actually does
        self.u.set_antenna("RX2", 0)

        if options.gain is None:  # set to halfway
            g = self.u.get_gain_range()
            options.gain = (g.start() + g.stop()) / 2.0

        if not (self.u.set_center_freq(frekvens, 0)):
            print "Failed to set frequency"
            sys.exit(1)

        print "Setting gain to %i" % options.gain
        self.u.set_gain(options.gain)

        coeffs = gr.firdes.low_pass(1, samplerate, 10000, 10000)
        filter = gr.fir_filter_ccf(5, coeffs)
        gang = gr.multiply_const_ff(10)

        lpcoeffs = gr.firdes.low_pass(1, samplerate, 8000, 3000)
        lpfilter = gr.fir_filter_fff(1, lpcoeffs)
        demod = gr.quadrature_demod_cf(0.5)

        clockrec = gr.clock_recovery_mm_ff(
            float(samplerate) / 5 / 9600, 0.25 * 0.175 * 0.175, 0.5, 0.175,
            0.005)
        #datadec = ais.ais_decoder_mysql("localhost","diverse","aisblock","elgelg")
        self.datadec = ais.ais_decoder_gearth(30003)

        slicer = gr.binary_slicer_fb()
        diff = gr.diff_decoder_bb(2)
        invert = ais.invert10_bb()
        # print subdev.name()
        self.connect(self.u, filter, demod, lpfilter, gang, clockrec, slicer,
                     diff, invert, self.datadec)
	def __init__(self):
		gr.top_block.__init__(self, "CW/SSB Receiver")

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 96000
		self.xlate_filter_taps = xlate_filter_taps = firdes.low_pass(1, samp_rate, 48000, 5000, firdes.WIN_HAMMING, 6.76)
		self.sql_lev = sql_lev = -100
		self.rf_gain = rf_gain = 20
		self.pass_trans = pass_trans = 600
		self.pass_low = pass_low = 300
		self.pass_high = pass_high = 1200
		self.freq = freq = 144800000
		self.af_gain = af_gain = 5
		self.sat_file_name = sat_file_name = "Undefined"

		##################################################
		# Blocks
		##################################################
		self.xlating_fir_filter = gr.freq_xlating_fir_filter_ccc(1, (xlate_filter_taps), 0, samp_rate)
		self.gr_simple_squelch_cc_0 = gr.simple_squelch_cc(sql_lev, 1)
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((af_gain, ))
		self.gr_complex_to_real_0 = gr.complex_to_real(1)
		self.gr_agc2_xx_0 = gr.agc2_cc(1e-1, 20.8e-6, 0.3, 1.0, 0.0)
		self.fcd_source_c_1 = fcd.source_c("hw:1")
		self.fcd_source_c_1.set_freq(freq)
		self.fcd_source_c_1.set_freq_corr(-10)
		    
		self.band_pass_filter_0 = gr.fir_filter_ccf(2, firdes.band_pass(
			1, samp_rate, pass_low, pass_high, pass_trans, firdes.WIN_HAMMING, 6.76))
		self.audio_sink = audio.sink(48000, "", True)

		self.wavfile_sink = gr.wavfile_sink(self.sat_file_name, 1, 11025, 16)
		self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_fff(
			interpolation=11025,
			decimation=48000,
			taps=None,
			fractional_bw=None,
		)

		##################################################
		# Connections
		##################################################
		self.connect((self.fcd_source_c_1, 0), (self.xlating_fir_filter, 0))
		self.connect((self.xlating_fir_filter, 0), (self.gr_simple_squelch_cc_0, 0))
		self.connect((self.band_pass_filter_0, 0), (self.gr_agc2_xx_0, 0))
		self.connect((self.gr_complex_to_real_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.gr_agc2_xx_0, 0), (self.gr_complex_to_real_0, 0))
		self.connect((self.gr_simple_squelch_cc_0, 0), (self.band_pass_filter_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.audio_sink, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.audio_sink, 1))
		self.connect((self.gr_complex_to_real_0, 0), (self.blks2_rational_resampler_xxx_0, 0))
		self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.wavfile_sink, 0))
Example #18
0
  def __init__(self, options, args, queue):
    gr.top_block.__init__(self)

    self.options = options
    self.args = args
    rate = int(options.rate)

    if options.filename is None:
      self.u = rtl_source_c()

      #if(options.rx_subdev_spec is None):
      #  options.rx_subdev_spec = ""
      #self.u.set_subdev_spec(options.rx_subdev_spec)
      if not options.antenna is None:
        self.u.set_antenna(options.antenna)

      self.u.set_sample_rate(rate)

      if not(self.tune(options.freq)):
        print "Failed to set initial frequency"

      print "Setting gain to %i" % (options.gain,)
      self.u.set_gain(options.gain)
      print "Gain is %i" % (options.gain,)

      self.u.set_verbose(0)
    else:
      self.u = gr.file_source(gr.sizeof_gr_complex, options.filename)

    print "Rate is %i" % (rate,)

    pass_all = 0
    if options.output_all :
      pass_all = 1

    self.demod = gr.complex_to_mag()
    self.avg = gr.moving_average_ff(100, 1.0/100, 400)
    
    #the DBSRX especially tends to be spur-prone; the LPF keeps out the
    #spur multiple that shows up at 2MHz
#    self.lpfiltcoeffs = gr.firdes.low_pass(1, rate, 0.9*rate/2, 50e3)
#    self.lpfiltcoeffs = gr.firdes.low_pass(1, rate, 0.9*rate/2, 100e3)
    self.lpfiltcoeffs = gr.firdes.high_pass(1, rate, 1e3, 100e3)
    self.lpfilter = gr.fir_filter_ccf(1, self.lpfiltcoeffs)
    
    self.preamble = air.modes_preamble(rate, options.threshold)
    #self.framer = air.modes_framer(rate)
    self.slicer = air.modes_slicer(rate, queue)
    
    self.connect(self.u, self.lpfilter, self.demod)
    self.connect(self.demod, self.avg)
    self.connect(self.demod, (self.preamble, 0))
    self.connect(self.avg, (self.preamble, 1))
    self.connect((self.preamble, 0), (self.slicer, 0))
Example #19
0
    def __init__(self):
        gr.top_block.__init__(self)
        #build graph now

        #usrp_source
        self.usrp = usrp.source_c()
        adc_rate = self.usrp.adc_rate()  #64MHz
        hw_decim = 16  #so Sample rate into host is 4MHz
        self.usrp.set_decim_rate(hw_decim)
        self.subdev = usrp.selected_subdev(self.usrp,
                                           usrp.pick_rx_subdevice(self.usrp))
        self.usrp.set_mux(
            usrp.determine_rx_mux_value(self.usrp,
                                        usrp.pick_rx_subdevice(self.usrp)))
        print "Using RX d'board %s" % (self.subdev.side_and_name(), )
        self.subdev.set_gain(30)
        rf_freq = 106800000  # 106.8MHz
        self.set_freq(rf_freq)
        print "Freq: ", rf_freq
        self.subdev.select_rx_antenna("TX/RX")

        #low pass filter
        self.sample_rate = adc_rate / hw_decim
        self.lpf_decim = 20  # so after channel filter, the sample rate is 200KHz
        self.lp_filter = gr.fir_filter_ccf(
            self.lpf_decim,
            gr.firdes.low_pass(
                1,
                self.sample_rate,
                100e3,  # cut off freq
                10e3,  # transition band
                gr.firdes.WIN_BLACKMAN,  # Window function
                6.76  # not used
            ))
        # WBFM receiver
        quad_rate = self.sample_rate  #input rate of demodulator
        max_dev = 75e3  #max deviation of FM Broadcast
        fm_demod_gain = quad_rate / (2 * math.pi * max_dev)
        self.fm_decoder = gr.quadrature_demod_cf(fm_demod_gain)

        # Rational Resampler
        self.audio_sample_rate = 96000
        self.rational_resampler = blks2.rational_resampler_fff(
            interpolation=int(self.audio_sample_rate / 1000),
            decimation=int(self.sample_rate / self.lpf_decim / 1000),
            taps=None,
            fractional_bw=None,
        )
        self.audio_sink = audio.sink(int(self.audio_sample_rate), "", True)

        #connections
        self.connect(self.usrp, self.lp_filter, self.fm_decoder,
                     self.rational_resampler, self.audio_sink)
Example #20
0
    def __init__(self, options, args):
        gr.top_block.__init__(self)

        self.options = options
        self.args = args

        frekvens = options.freq

        # u = usrp.source_c(0)
        # u.set_decim_rate(256)
        # subdev_spec = (1,0)
        # u.set_mux(usrp.determine_rx_mux_value(u,subdev_spec))
        # subdev = usrp.selected_subdev(u,subdev_spec)
        # subdev.set_auto_tr(True)
        # subdev.set_gain(57)
        # usrp.tune(u,0,subdev,frekvens)#106.3e6)
        # samplerate = 64000000/256 # 250000
        self.u = uhd.usrp_source("", uhd.io_type_t.COMPLEX_FLOAT32,1)
        self.u.set_subdev_spec("");   # default should be good?
        self.u.set_samp_rate(250e3);
        samplerate = self.u.get_samp_rate() # Retrieve what it actually does
        self.u.set_antenna("RX2",0)

        if options.gain is None: # set to halfway
            g = self.u.get_gain_range()
            options.gain = (g.start()+g.stop()) / 2.0

        if not(self.u.set_center_freq(frekvens, 0)):
            print "Failed to set frequency"
            sys.exit(1)

        print "Setting gain to %i" % options.gain
        self.u.set_gain(options.gain)

        coeffs = gr.firdes.low_pass(1,samplerate,10000,10000)
        filter = gr.fir_filter_ccf(5,coeffs)
        gang = gr.multiply_const_ff(10)

        lpcoeffs = gr.firdes.low_pass(1,samplerate,8000,3000)
        lpfilter = gr.fir_filter_fff(1,lpcoeffs)
        demod = gr.quadrature_demod_cf(0.5)

        clockrec = gr.clock_recovery_mm_ff(float(samplerate)/5/9600,0.25*0.175*0.175,0.5,0.175,0.005)
        #datadec = ais.ais_decoder_mysql("localhost","diverse","aisblock","elgelg")
        self.datadec = ais.ais_decoder_gearth(30003)

        slicer = gr.binary_slicer_fb()
        diff = gr.diff_decoder_bb(2)
        invert = ais.invert10_bb()
        # print subdev.name()
        self.connect(self.u,filter,demod,lpfilter,gang,clockrec,
                     slicer,diff,invert,self.datadec)
Example #21
0
    def __init__(self):
        gr.top_block.__init__(self)

        self._N = 10000000  # number of samples to use
        self._fs = 10000  # initial sampling rate
        self._decim = 20  # Decimation rate

        # Generate the prototype filter taps for the decimators with a 200 Hz bandwidth
        self._taps = gr.firdes.low_pass_2(1,
                                          self._fs,
                                          200,
                                          150,
                                          attenuation_dB=120,
                                          window=gr.firdes.WIN_BLACKMAN_hARRIS)

        # Calculate the number of taps per channel for our own information
        tpc = scipy.ceil(float(len(self._taps)) / float(self._decim))
        print "Number of taps:     ", len(self._taps)
        print "Number of filters:  ", self._decim
        print "Taps per channel:   ", tpc

        # Build the input signal source
        # We create a list of freqs, and a sine wave is generated and added to the source
        # for each one of these frequencies.
        self.signals = list()
        self.add = gr.add_cc()
        freqs = [10, 20, 2040]
        for i in xrange(len(freqs)):
            self.signals.append(
                gr.sig_source_c(self._fs, gr.GR_SIN_WAVE, freqs[i], 1))
            self.connect(self.signals[i], (self.add, i))

        self.head = gr.head(gr.sizeof_gr_complex, self._N)

        # Construct a PFB decimator filter
        self.pfb = blks2.pfb_decimator_ccf(self._decim, self._taps, 0)

        # Construct a standard FIR decimating filter
        self.dec = gr.fir_filter_ccf(self._decim, self._taps)

        self.snk_i = gr.vector_sink_c()

        # Connect the blocks
        self.connect(self.add, self.head, self.pfb)
        self.connect(self.add, self.snk_i)

        # Create the sink for the decimated siganl
        self.snk = gr.vector_sink_c()
        self.connect(self.pfb, self.snk)
Example #22
0
 def create_correlators(self, rate_var):
     h_s_pos = array([1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0])
     h_s_neg = -1 * h_s_pos
     #preamble taps +1 +1 +1 -1 -1 -1 -1 +1 +1 -1 -1 +1
     preamble_taps = array([
         h_s_pos, h_s_pos, h_s_pos, h_s_neg, h_s_neg, h_s_neg, h_s_neg,
         h_s_pos, h_s_pos, h_s_neg, h_s_neg, h_s_pos
     ]).flatten()
     #normalize
     preamble_taps = preamble_taps / sqrt(dot(preamble_taps, preamble_taps))
     #auto-correlation filter, flip the taps for match filter
     self.correlators = []
     for ii in range(2 * rate_var + 1):
         self.correlators.append(gr.fir_filter_ccf(1,
                                                   flipud(preamble_taps)))
Example #23
0
    def __init__(self):
        gr.top_block.__init__(self)
        #build graph now

        #usrp_source
        self.usrp = usrp.source_c()
        adc_rate  = self.usrp.adc_rate()  #64MHz
        hw_decim  = 16                    #so Sample rate into host is 4MHz
        self.usrp.set_decim_rate(hw_decim)
        self.subdev = usrp.selected_subdev(self.usrp, usrp.pick_rx_subdevice(self.usrp))
        self.usrp.set_mux(usrp.determine_rx_mux_value(self.usrp, usrp.pick_rx_subdevice(self.usrp)))
        print "Using RX d'board %s" % (self.subdev.side_and_name(),)
        self.subdev.set_gain(30)
        rf_freq = 106800000               # 106.8MHz
        self.set_freq(rf_freq)
        print "Freq: ", rf_freq
        self.subdev.select_rx_antenna("TX/RX")

        #low pass filter
        self.sample_rate = adc_rate / hw_decim
        self.lpf_decim = 20               # so after channel filter, the sample rate is 200KHz
        self.lp_filter = gr.fir_filter_ccf( self.lpf_decim, gr.firdes.low_pass ( 1, 
                                                                                self.sample_rate, 
                                                                                100e3, # cut off freq
                                                                                10e3,  # transition band
                                                                                gr.firdes.WIN_BLACKMAN, # Window function
                                                                                6.76              # not used
                                                                                 ))
        # WBFM receiver
        quad_rate = self.sample_rate  #input rate of demodulator
        max_dev = 75e3        #max deviation of FM Broadcast
        fm_demod_gain = quad_rate/(2 * math.pi * max_dev)
        self.fm_decoder = gr.quadrature_demod_cf (fm_demod_gain)


        # Rational Resampler
        self.audio_sample_rate  = 96000
        self.rational_resampler = blks2.rational_resampler_fff ( interpolation = int(self.audio_sample_rate/1000),
                                                                decimation    = int(self.sample_rate/self.lpf_decim/1000),
                                                                taps          = None,
                                                                fractional_bw = None,
                                                              )
        self.audio_sink = audio.sink (int(self.audio_sample_rate), "", True)

        #connections
        self.connect ( self.usrp, self.lp_filter, self.fm_decoder, self.rational_resampler, self.audio_sink )
Example #24
0
    def __init__(self, outputfile, options):
        gr.top_block.__init__(self)

        if options.dsp:
            self.dst = audio.sink( options.dsp_sample_rate )
        else:
            self.dst = gr.wavfile_sink(outputfile, 2, options.wav_sample_rate, 16)

        self.c_to_iq = gr.complex_to_float()
        self.connect( (self.c_to_iq, 0), (self.dst, 0))
        self.connect( (self.c_to_iq, 1), (self.dst, 1))

        # settings for the modulator: /usr/local/lib/python2.5/site-packages/gnuradio/blks2impl/gmsk.py

        self.modulator = blks2.gmsk_mod(samples_per_symbol=options.samples_per_symbol)
        self.pkt_queue = blks2.mod_pkts( modulator=self.modulator )

        if options.carrier_frequency == 0:
            self.mixer = self.pkt_queue
        else:
            self.mixer   = gr.multiply_vcc(1)
            self.carrier = gr.sig_source_c( options.carrier_sample_rate, gr.GR_SIN_WAVE, options.carrier_frequency, 1.0 )
            self.lowpass = gr.fir_filter_ccf(1, firdes.low_pass(1, 48000, 48000/(2*options.samples_per_symbol)+500, 500, firdes.WIN_HAMMING, 6.76))
            self.connect(self.pkt_queue, self.lowpass, (self.mixer, 0) )
            self.connect(self.carrier,   (self.mixer, 1) )

        self.amp = gr.multiply_const_cc(1); self.amp.set_k(options.amp_amplitude)
        self.connect(self.mixer, self.amp, self.c_to_iq)

        if options.debug_wavs:
            from myblks import debugwav
            self._dpassw = debugwav("tx_passband", options)
            self._dprefw = debugwav("tx_prefband", options)
            self._dbasew = debugwav("tx_baseband", options)
            self.connect(self.amp, self._dpassw)
            self.connect(self.lowpass, self._dbasew)
            self.connect(self.pkt_queue, self._dprefw)

        if options.debug_files:
            self._dpassf = gr.file_sink(gr.sizeof_gr_complex*1, "debug_tx_passband.d_c")
            self._dpreff = gr.file_sink(gr.sizeof_gr_complex*1, "debug_tx_prefband.d_c")
            self._dbasef = gr.file_sink(gr.sizeof_gr_complex*1, "debug_tx_baseband.d_c")
            self.connect(self.amp, self._dpassf)
            self.connect(self.pkt_queue, self._dpreff)
            self.connect(self.lowpass, self._dbasef)
Example #25
0
 def __init__(self,ampl_i,band,symbol_rate,sps):
     gr.hier_block2.__init__(self,"Channel",
                             gr.io_signature(1,1,gr.sizeof_gr_complex),
                             gr.io_signature(1,1,gr.sizeof_gr_complex))
     
     self.symbol_rate = symbol_rate
     self.sample_rate=symbol_rate*sps
     self.fading = False
     self.adder = gr.add_cc()
     self.noise = gr.noise_source_c(gr.GR_GAUSSIAN, 1, -42)
     self.ampl = gr.multiply_const_cc(ampl_i)
     self.taps = gr.firdes.low_pass_2 (1,280,band/2,5,80,gr.firdes.WIN_KAISER)
     self.filter=gr.fir_filter_ccf(1,self.taps)
     
     #Connects
     self.connect(self,self.filter,(self.adder,0))
     self.connect(self.noise, self.ampl, (self.adder,1))
     self.connect(self.adder, self)
Example #26
0
	def __init__(self, input_path, sample_rate, output_path):
		gr.top_block.__init__(self)

		self.source = gr.file_source(
			gr.sizeof_gr_complex, input_path, False)
		self.lowpass_and_decimate = gr.fir_filter_ccf(
			8, firdes.low_pass(1, sample_rate, FREQ_SPACE, 100))
		self.lsb_tune = gr.freq_xlating_fir_filter_ccc(
			1, (1,), -FREQ_SPACE, sample_rate/8)
		self.boost_volume = gr.multiply_const_vcc((10, ))
		self.complex_to_real = gr.complex_to_real(1)
		self.sink = gr.wavfile_sink(output_path, 1, sample_rate/8, 16)

		self.connect((self.source, 0), (self.lowpass_and_decimate, 0))
		self.connect((self.lowpass_and_decimate, 0), (self.lsb_tune, 0))
		self.connect((self.lsb_tune, 0), (self.boost_volume, 0))
		self.connect((self.boost_volume, 0), (self.complex_to_real, 0))
		self.connect((self.complex_to_real, 0), (self.sink, 0))
Example #27
0
    def __init__(self):
        gr.top_block.__init__(self)

        self._N = 10000000      # number of samples to use
        self._fs = 10000        # initial sampling rate
        self._decim = 20        # Decimation rate
        
        # Generate the prototype filter taps for the decimators with a 200 Hz bandwidth
        self._taps = gr.firdes.low_pass_2(1, self._fs, 200, 150,
                                          attenuation_dB=120, window=gr.firdes.WIN_BLACKMAN_hARRIS)

        # Calculate the number of taps per channel for our own information
        tpc = scipy.ceil(float(len(self._taps)) /  float(self._decim))
        print "Number of taps:     ", len(self._taps)
        print "Number of filters:  ", self._decim
        print "Taps per channel:   ", tpc
        
        # Build the input signal source
        # We create a list of freqs, and a sine wave is generated and added to the source
        # for each one of these frequencies.
        self.signals = list()
        self.add = gr.add_cc()
        freqs = [10, 20, 2040]
        for i in xrange(len(freqs)):
            self.signals.append(gr.sig_source_c(self._fs, gr.GR_SIN_WAVE, freqs[i], 1))
            self.connect(self.signals[i], (self.add,i))

        self.head = gr.head(gr.sizeof_gr_complex, self._N)
        
        # Construct a PFB decimator filter
        self.pfb = blks2.pfb_decimator_ccf(self._decim, self._taps, 0)

        # Construct a standard FIR decimating filter
        self.dec = gr.fir_filter_ccf(self._decim, self._taps)

        self.snk_i = gr.vector_sink_c()

        # Connect the blocks
        self.connect(self.add, self.head, self.pfb)
        self.connect(self.add, self.snk_i)

        # Create the sink for the decimated siganl
        self.snk = gr.vector_sink_c()
        self.connect(self.pfb, self.snk)
Example #28
0
	def __init__(self):
		gr.top_block.__init__(self, "FM Receiver")

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 96000
		self.xlate_filter_taps = xlate_filter_taps = firdes.low_pass(1, samp_rate, 48000, 5000, firdes.WIN_HAMMING, 6.76)
		self.sql_lev = sql_lev = -100
		self.rf_gain = rf_gain = 20
		self.freq = freq = 144800000
		self.af_gain = af_gain = 2

		##################################################
		# Blocks
		##################################################
		self.xlating_fir_filter = gr.freq_xlating_fir_filter_ccc(1, (xlate_filter_taps), 0, samp_rate)
		self.nbfm_normal = blks2.nbfm_rx(
			audio_rate=48000,
			quad_rate=96000,
			tau=75e-6,
			max_dev=5e3,
		)
		self.low_pass_filter = gr.fir_filter_ccf(1, firdes.low_pass(
			1, samp_rate, 12500, 1500, firdes.WIN_HAMMING, 6.76))
		self.gr_simple_squelch_cc_0 = gr.simple_squelch_cc(sql_lev, 1)
		self.gr_multiply_const_vxx_1 = gr.multiply_const_vff((af_gain, ))
		self.fcd_source_c_1 = fcd.source_c("hw:1")
		self.fcd_source_c_1.set_freq(freq)
		self.fcd_source_c_1.set_freq_corr(-32)
		    
		self.audio_sink = audio.sink(48000, "", True)

		##################################################
		# Connections
		##################################################
		self.connect((self.xlating_fir_filter, 0), (self.low_pass_filter, 0))
		self.connect((self.low_pass_filter, 0), (self.gr_simple_squelch_cc_0, 0))
		self.connect((self.gr_multiply_const_vxx_1, 0), (self.audio_sink, 1))
		self.connect((self.gr_multiply_const_vxx_1, 0), (self.audio_sink, 0))
		self.connect((self.gr_simple_squelch_cc_0, 0), (self.nbfm_normal, 0))
		self.connect((self.nbfm_normal, 0), (self.gr_multiply_const_vxx_1, 0))
		self.connect((self.fcd_source_c_1, 0), (self.xlating_fir_filter, 0))
Example #29
0
	def __init__(self):
		gr.top_block.__init__(self, "CW/SSB Receiver")

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 96000
		self.xlate_filter_taps = xlate_filter_taps = firdes.low_pass(1, samp_rate, 48000, 5000, firdes.WIN_HAMMING, 6.76)
		self.sql_lev = sql_lev = -100
		self.rf_gain = rf_gain = 20
		self.pass_trans = pass_trans = 600
		self.pass_low = pass_low = 300
		self.pass_high = pass_high = 1200
		self.freq = freq = 144800000
		self.af_gain = af_gain = 5

		##################################################
		# Blocks
		##################################################
		self.xlating_fir_filter = gr.freq_xlating_fir_filter_ccc(1, (xlate_filter_taps), 0, samp_rate)
		self.gr_simple_squelch_cc_0 = gr.simple_squelch_cc(sql_lev, 1)
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((af_gain, ))
		self.gr_complex_to_real_0 = gr.complex_to_real(1)
		self.gr_agc2_xx_0 = gr.agc2_cc(1e-1, 20.8e-6, 0.3, 1.0, 0.0)
		self.fcd_source_c_1 = fcd.source_c("hw:1")
		self.fcd_source_c_1.set_freq(freq)
		self.fcd_source_c_1.set_freq_corr(-10)
		    
		self.band_pass_filter_0 = gr.fir_filter_ccf(2, firdes.band_pass(
			1, samp_rate, pass_low, pass_high, pass_trans, firdes.WIN_HAMMING, 6.76))
		self.audio_sink = audio.sink(48000, "", True)

		##################################################
		# Connections
		##################################################
		self.connect((self.fcd_source_c_1, 0), (self.xlating_fir_filter, 0))
		self.connect((self.xlating_fir_filter, 0), (self.gr_simple_squelch_cc_0, 0))
		self.connect((self.band_pass_filter_0, 0), (self.gr_agc2_xx_0, 0))
		self.connect((self.gr_complex_to_real_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.gr_agc2_xx_0, 0), (self.gr_complex_to_real_0, 0))
		self.connect((self.gr_simple_squelch_cc_0, 0), (self.band_pass_filter_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.audio_sink, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.audio_sink, 1))
Example #30
0
    def __init__(self, ampl_i, band, symbol_rate, sps):
        gr.hier_block2.__init__(self, "Channel",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))

        self.symbol_rate = symbol_rate
        self.sample_rate = symbol_rate * sps
        self.fading = False
        self.adder = gr.add_cc()
        self.noise = gr.noise_source_c(gr.GR_GAUSSIAN, 1, -42)
        self.ampl = gr.multiply_const_cc(ampl_i)
        self.taps = gr.firdes.low_pass_2(1, 280, band / 2, 5, 80,
                                         gr.firdes.WIN_KAISER)
        self.filter = gr.fir_filter_ccf(1, self.taps)

        #Connects
        self.connect(self, self.filter, (self.adder, 0))
        self.connect(self.noise, self.ampl, (self.adder, 1))
        self.connect(self.adder, self)
Example #31
0
	def __init__(self, samp_rate=1600000, samp_per_sym=16, freq_error=-0.0025000):
		gr.hier_block2.__init__(
			self, "Wireless M-Bus Demod",
			gr.io_signature(1, 1, gr.sizeof_gr_complex*1),
			gr.io_signature(1, 1, gr.sizeof_char*1),
		)

		##################################################
		# Parameters
		##################################################
		self.samp_rate = samp_rate
		self.samp_per_sym = samp_per_sym
		self.freq_error = freq_error

		##################################################
		# Variables
		##################################################
		self.cutoff = cutoff = 120e3
		self.chip_rate = chip_rate = samp_rate/samp_per_sym

		##################################################
		# Blocks
		##################################################
		self.low_pass_filter_0 = gr.fir_filter_ccf(1, firdes.low_pass(
			1, samp_rate, cutoff, cutoff/2, firdes.WIN_HAMMING, 6.76))
		self.gr_sub_xx_0 = gr.sub_ff(1)
		self.gr_single_pole_iir_filter_xx_0 = gr.single_pole_iir_filter_ff(0.0512/samp_per_sym, 1)
		self.gr_quadrature_demod_cf_0 = gr.quadrature_demod_cf(1)
		self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_ff(samp_per_sym*(1+freq_error), .25 *0.06*0.06*4, 0.5, 0.06*2, 0.002*2)
		self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb()

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_quadrature_demod_cf_0, 0), (self.gr_single_pole_iir_filter_xx_0, 0))
		self.connect((self.gr_single_pole_iir_filter_xx_0, 0), (self.gr_sub_xx_0, 1))
		self.connect((self.gr_quadrature_demod_cf_0, 0), (self.gr_sub_xx_0, 0))
		self.connect((self.gr_sub_xx_0, 0), (self.digital_clock_recovery_mm_xx_0, 0))
		self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.digital_binary_slicer_fb_0, 0))
		self.connect((self.low_pass_filter_0, 0), (self.gr_quadrature_demod_cf_0, 0))
		self.connect((self.digital_binary_slicer_fb_0, 0), (self, 0))
		self.connect((self, 0), (self.low_pass_filter_0, 0))
Example #32
0
    def __init__(self):
        gr.hier_block2.__init__(self, "symbol_mapper",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))
        half_sym_taps = array([1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0])
        #normalize
        half_sym_taps = half_sym_taps / sqrt(dot(half_sym_taps, half_sym_taps))
        self.mf = gr.fir_filter_ccf(1, half_sym_taps)
        self.timing_recovery = rfidbts.elg_timing_cc(phase_offset=0,
                                                     samples_per_symbol=8,
                                                     in_frame_size=500,
                                                     out_frame_size=7 + 12 +
                                                     32,
                                                     dco_gain=0.04,
                                                     order_1_gain=0.1,
                                                     order_2_gain=0.01)

        timing_s = gr.file_sink(gr.sizeof_gr_complex, "timing/symbols.dat")
        self.connect(self.timing_recovery, timing_s)
        self.connect(self, self.mf, self.timing_recovery, self)
Example #33
0
    def __init__(self):
        gr.hier_block2.__init__(self,
                                "symbol_mapper",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))
        half_sym_taps = array([1.0, 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0])
#normalize
        half_sym_taps = half_sym_taps / sqrt(dot(half_sym_taps,half_sym_taps))
        self.mf = gr.fir_filter_ccf(1, half_sym_taps)
        self.timing_recovery = rfidbts.elg_timing_cc(phase_offset = 0,
                                                     samples_per_symbol = 8,
                                                     in_frame_size = 500,
                                                     out_frame_size = 7 + 12 + 32,
                                                     dco_gain = 0.04,
                                                     order_1_gain = 0.1,
                                                     order_2_gain = 0.01)

        timing_s = gr.file_sink(gr.sizeof_gr_complex, "timing/symbols.dat")
        self.connect(self.timing_recovery, timing_s)
        self.connect(self, self.mf, self.timing_recovery, self)
Example #34
0
  def __init__(self, fft_length):
    gr.hier_block2.__init__(self, "schmidl_nominator",
        gr.io_signature(1,1,gr.sizeof_gr_complex),
        gr.io_signature(1,1,gr.sizeof_gr_complex))

    self.input=gr.kludge_copy(gr.sizeof_gr_complex)

    # P(d) = sum(0 to L-1, conj(delayed(r)) * r)
    conj = gr.conjugate_cc()
    mixer = gr.multiply_cc()
    moving_avg = gr.fir_filter_ccf(1,[1.0 for i in range(fft_length/2)])

    self.connect(self, self.input, delay(gr.sizeof_gr_complex,fft_length/2), conj, (mixer,0))
    self.connect(self.input, (mixer,1))
    self.connect(mixer, moving_avg, self)
    # moving_avg = P(d)
    try:
        gr.hier_block.update_var_names(self, "schmidl_nom", vars())
        gr.hier_block.update_var_names(self, "schmidl_nom", vars(self))
    except:
        pass
Example #35
0
    def create_correlators(self,rate_var):
        h_s_pos = array([1.0,1.0,-1.0,-1.0,1.0,1.0,-1.0,-1.0])
        h_s_neg = -1 * h_s_pos
#preamble taps +1 +1 +1 -1 -1 -1 -1 +1 +1 -1 -1 +1   
        preamble_taps = array([h_s_pos,
                              h_s_pos,
                              h_s_pos,
                              h_s_neg,
                              h_s_neg,
                              h_s_neg,
                              h_s_neg,
                              h_s_pos,
                              h_s_pos,
                              h_s_neg,
                              h_s_neg,
                              h_s_pos]).flatten()
#normalize
        preamble_taps = preamble_taps / sqrt(dot(preamble_taps, preamble_taps))
#auto-correlation filter, flip the taps for match filter
        self.correlators = []
        for ii in range(2 * rate_var + 1):
            self.correlators.append(gr.fir_filter_ccf(1,flipud(preamble_taps)))
Example #36
0
    def __init__(self, fft_length):
        gr.hier_block2.__init__(self, "schmidl_nominator",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))

        self.input = gr.kludge_copy(gr.sizeof_gr_complex)

        # P(d) = sum(0 to L-1, conj(delayed(r)) * r)
        conj = gr.conjugate_cc()
        mixer = gr.multiply_cc()
        moving_avg = gr.fir_filter_ccf(1, [1.0 for i in range(fft_length / 2)])

        self.connect(self, self.input,
                     delay(gr.sizeof_gr_complex, fft_length / 2), conj,
                     (mixer, 0))
        self.connect(self.input, (mixer, 1))
        self.connect(mixer, moving_avg, self)
        # moving_avg = P(d)
        try:
            gr.hier_block.update_var_names(self, "schmidl_nom", vars())
            gr.hier_block.update_var_names(self, "schmidl_nom", vars(self))
        except:
            pass
Example #37
0
    def __init__(self, fft_length, pn_weights):
        gr.hier_block2.__init__(self, "modified_timing_metric",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(1, 1, gr.sizeof_float))

        assert (len(pn_weights) == fft_length)

        self.input = gr.kludge_copy(gr.sizeof_gr_complex)
        self.connect(self, self.input)

        # P(d) = sum(0 to L-1, conj(delayed(r)) * r)
        conj = gr.conjugate_cc()
        mixer = gr.multiply_cc()
        nominator = gr.fir_filter_ccf(1, [
            pn_weights[fft_length - i - 1] * pn_weights[fft_length / 2 - i - 1]
            for i in range(fft_length / 2)
        ])

        self.connect(self.input, delay(gr.sizeof_gr_complex, fft_length / 2),
                     conj, (mixer, 0))
        self.connect(self.input, (mixer, 1))
        self.connect(mixer, nominator)
        # moving_avg = P(d)

        # R(d)
        denominator = schmidl_denominator(fft_length)

        # |P(d)| ** 2 / (R(d)) ** 2
        p_mag_sqrd = gr.complex_to_mag_squared()
        r_sqrd = gr.multiply_ff()
        self.timing_metric = gr.divide_ff()

        self.connect(nominator, p_mag_sqrd, (self.timing_metric, 0))
        self.connect(self.input, denominator, (r_sqrd, 0))
        self.connect(denominator, (r_sqrd, 1))
        self.connect(r_sqrd, (self.timing_metric, 1))
        self.connect(self.timing_metric, self)
Example #38
0
    def __init__(self, options):
        gr.top_block.__init__(self, "ofdm_benchmark")

        self._bandwidth = options.bandwidth
        self.servants = []
        self._verbose = options.verbose

        self._options = copy.copy(options)

        self.ideal = options.ideal
        self.ideal2 = options.ideal2

        rms_amp = options.rms_amplitude

        self._interpolation = 1

        f1 = numpy.array([
            -107, 0, 445, 0, -1271, 0, 2959, 0, -6107, 0, 11953, 0, -24706, 0,
            82359, 262144 / 2, 82359, 0, -24706, 0, 11953, 0, -6107, 0, 2959,
            0, -1271, 0, 445, 0, -107
        ], numpy.float64) / 262144.

        print "Software interpolation: %d" % (self._interpolation)

        bw = 1.0 / self._interpolation
        tb = bw / 5
        if self._interpolation > 1:
            self.tx_filter = gr.hier_block2(
                "filter", gr.io_signature(1, 1, gr.sizeof_gr_complex),
                gr.io_signature(1, 1, gr.sizeof_gr_complex))
            self.tx_filter.connect(self.tx_filter,
                                   gr.interp_fir_filter_ccf(2, f1),
                                   gr.interp_fir_filter_ccf(2, f1),
                                   self.tx_filter)

            print "New"

        else:
            self.tx_filter = None

        self.decimation = 1

        if self.decimation > 1:
            bw = 0.5 / self.decimation * 1
            tb = bw / 5
            # gain, sampling rate, passband cutoff, stopband cutoff
            # passband ripple in dB, stopband attenuation in dB
            # extra taps
            filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw + tb, 0.1, 60.0, 1)
            print "Software decimation filter length: %d" % (len(filt_coeff))
            self.rx_filter = gr.fir_filter_ccf(self.decimation, filt_coeff)
        else:
            self.rx_filter = None

        self._setup_tx_path(options)
        self._setup_rx_path(options)
        self._setup_rpc_manager()

        config = self.config = station_configuration()

        if options.imgxfer:
            self.rxpath.setup_imgtransfer_sink()

        if not options.no_decoding:
            self.rxpath.publish_rx_performance_measure()

            # capture transmitter's stream to disk
        #self.dst  = gr.file_sink(gr.sizeof_gr_complex,options.to_file)
        self.dst = self.rxpath
        if options.force_rx_filter:
            print "Forcing rx filter usage"
            self.connect(self.rx_filter, self.dst)
            self.dst = self.rx_filter

        if options.ideal or self.ideal2:
            self._amplifier = ofdm.multiply_const_ccf(1.0)
            self.connect(self._amplifier, self.dst)
            self.dst = self._amplifier
            self.set_rms_amplitude(rms_amp)

        if options.measure:
            self.m = throughput_measure(gr.sizeof_gr_complex)
            self.connect(self.m, self.dst)
            self.dst = self.m

        if options.snr is not None:
            if options.berm is not None:
                noise_sigma = 380 / 32767.0  #empirically given, gives the received SNR range of (1:28) for tx amp. range of (500:10000) which is set in rm_ber_measurement.py
                #check for fading channel
            else:
                snr_db = options.snr
                snr = 10.0**(snr_db / 10.0)
                noise_sigma = sqrt(config.rms_amplitude**2 / snr)

            print " Noise St. Dev. %f" % (noise_sigma)

            awgn_chan = blocks.add_cc()
            #awgn_noise_src = ofdm.complex_white_noise( 0.0, noise_sigma )
            awgn_noise_src = analog.fastnoise_source_c(analog.GR_GAUSSIAN,
                                                       noise_sigma, 0, 8192)
            self.connect(awgn_noise_src, (awgn_chan, 1))
            self.connect(awgn_chan, self.dst)
            self.dst = awgn_chan

        if options.freqoff is not None:
            freq_off = self.freq_off = channel.freq_offset(options.freqoff)
            dst = self.dst
            self.connect(freq_off, dst)
            self.dst = freq_off
            self.rpc_mgr_tx.add_interface("set_freq_offset",
                                          self.freq_off.set_freqoff)

        if options.multipath:
            if options.itu_channel:
                self.fad_chan = channel.itpp_channel(options.bandwidth)
                self.rpc_mgr_tx.add_interface(
                    "set_channel_profile", self.fad_chan.set_channel_profile)
                self.rpc_mgr_tx.add_interface("set_norm_doppler",
                                              self.fad_chan.set_norm_doppler)
            else:
                #self.fad_chan = filter.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j])
                # filter coefficients for the lab exercise
                self.fad_chan = filter.fir_filter_ccc(1,
                                                      [0.3267, 0.8868, 0.3267])
                #self.fad_chan = filter.fir_filter_ccc(1,[0,0,0.1,0.2,0.01,0.3])#0.3267,0.8868,0.3267])
                #self.fad_chan = channels.selective_fading_model(5, 0.1, False, 1, -1, [0, 0, 0], [0.3267,0.8868,0.3267], 10 )
                #self.fad_chan = channels.fading_model(6, 0.05, False);
                #self.fad_chan = channels.dynamic_channel_model(1000000, 0, 0, 0, 0, 3, 0.01, False, 0, [2e-6,4e-6,8e-6],[0.3267,0.8868,0.3267], 20, 0, 0)

            self.connect(self.fad_chan, self.dst)
            self.dst = self.fad_chan

        if options.samplingoffset is not None:
            soff = options.samplingoffset
            interp = moms(1000000 * (1.0 + soff), 1000000)
            #interp = filter.fractional_resampler_cc(0,1000000*(1.0+soff)/1000000.0)
            self.connect(interp, self.dst)
            self.dst = interp

            if options.record:
                log_to_file(self, interp, "data/interp_out.compl")

        tmm = blocks.throttle(gr.sizeof_gr_complex, options.bandwidth)
        self.connect(tmm, self.dst)
        self.dst = tmm
        if options.force_tx_filter:
            print "Forcing tx filter usage"
            self.connect(self.tx_filter, self.dst)
            self.dst = self.tx_filter
        if options.record:
            log_to_file(self, self.txpath, "data/txpath_out.compl")

        if options.scatterplot:
            print "Scatterplot enabled"

        self.connect(self.txpath, self.dst)

        print "Hit Strg^C to terminate"

        print "Hit Strg^C to terminate"

        # Display some information about the setup
        if self._verbose:
            self._print_verbage()
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        parser = OptionParser(option_class=eng_option)
        parser.add_option(
            "-R", "--rx-subdev-spec", type="subdev", default=None, help="select USRP Rx side A or B (default=A)"
        )
        parser.add_option(
            "-f", "--freq", type="eng_float", default=100.1e6, help="set frequency to FREQ", metavar="FREQ"
        )
        parser.add_option("-g", "--gain", type="eng_float", default=65, help="set gain in dB (default is midpoint)")
        parser.add_option("-s", "--squelch", type="eng_float", default=0, help="set squelch level (default is 0)")
        parser.add_option("-V", "--volume", type="eng_float", default=None, help="set volume (default is midpoint)")
        parser.add_option(
            "-O",
            "--audio-output",
            type="string",
            default="",
            help="pcm device name.  E.g., hw:0,0 or surround51 or /dev/dsp",
        )

        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        self.frame = frame
        self.panel = panel

        self.vol = 0
        self.state = "FREQ"
        self.freq = 0

        # build graph

        self.u = usrp.source_c()  # usrp is data source

        adc_rate = self.u.adc_rate()  # 64 MS/s
        usrp_decim = 200
        self.u.set_decim_rate(usrp_decim)
        usrp_rate = adc_rate / usrp_decim  # 320 kS/s
        chanfilt_decim = 1
        demod_rate = usrp_rate / chanfilt_decim
        audio_decimation = 10
        audio_rate = demod_rate / audio_decimation  # 32 kHz

        if options.rx_subdev_spec is None:
            options.rx_subdev_spec = pick_subdevice(self.u)

        self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)

        chan_filt_coeffs = optfir.low_pass(
            1,  # gain
            usrp_rate,  # sampling rate
            80e3,  # passband cutoff
            115e3,  # stopband cutoff
            0.1,  # passband ripple
            60,
        )  # stopband attenuation
        # print len(chan_filt_coeffs)
        chan_filt = gr.fir_filter_ccf(chanfilt_decim, chan_filt_coeffs)

        # self.guts = blks2.wfm_rcv (demod_rate, audio_decimation)
        self.guts = blks2.wfm_rcv_pll(demod_rate, audio_decimation)

        # FIXME rework {add,multiply}_const_* to handle multiple streams
        self.volume_control_l = gr.multiply_const_ff(self.vol)
        self.volume_control_r = gr.multiply_const_ff(self.vol)

        # sound card as final sink
        audio_sink = audio.sink(int(audio_rate), options.audio_output, False)  # ok_to_block

        # now wire it all together
        self.connect(self.u, chan_filt, self.guts)
        self.connect((self.guts, 0), self.volume_control_l, (audio_sink, 0))
        self.connect((self.guts, 1), self.volume_control_r, (audio_sink, 1))
        try:
            self.guts.stereo_carrier_pll_recovery.squelch_enable(True)
        except:
            print "FYI: This implementation of the stereo_carrier_pll_recovery has no squelch implementation yet"

        self._build_gui(vbox, usrp_rate, demod_rate, audio_rate)

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.subdev.gain_range()
            options.gain = float(g[0] + g[1]) / 2

        if options.volume is None:
            g = self.volume_range()
            options.volume = float(g[0] + g[1]) / 2

        if abs(options.freq) < 1e6:
            options.freq *= 1e6

        # set initial values

        self.set_gain(options.gain)
        self.set_vol(options.volume)
        try:
            self.guts.stereo_carrier_pll_recovery.set_lock_threshold(options.squelch)
        except:
            print "FYI: This implementation of the stereo_carrier_pll_recovery has no squelch implementation yet"

        if not (self.set_freq(options.freq)):
            self._set_status_msg("Failed to set initial frequency")
    def __init__(self):
        gr.top_block.__init__(self)
        parser = OptionParser(option_class=eng_option)

        parser.add_option("-1",
                          "--one-channel",
                          action="store_true",
                          default=False,
                          help="software synthesized Q channel")
        parser.add_option("-a",
                          "--agc",
                          action="store_true",
                          default=False,
                          help="automatic gain control (overrides --gain)")
        parser.add_option("-c",
                          "--calibration",
                          type="eng_float",
                          default=0,
                          help="freq offset")
        parser.add_option("-d",
                          "--debug",
                          action="store_true",
                          default=False,
                          help="allow time at init to attach gdb")
        parser.add_option("-C",
                          "--costas-alpha",
                          type="eng_float",
                          default=0.125,
                          help="Costas alpha")
        parser.add_option("-g", "--gain", type="eng_float", default=1.0)
        parser.add_option("-i",
                          "--input-file",
                          type="string",
                          default="in.dat",
                          help="specify the input file")
        parser.add_option("-I",
                          "--imbe",
                          action="store_true",
                          default=False,
                          help="output IMBE codewords")
        parser.add_option("-L",
                          "--low-pass",
                          type="eng_float",
                          default=6.5e3,
                          help="low pass cut-off",
                          metavar="Hz")
        parser.add_option("-o",
                          "--output-file",
                          type="string",
                          default="out.dat",
                          help="specify the output file")
        parser.add_option("-p",
                          "--polarity",
                          action="store_true",
                          default=False,
                          help="use reversed polarity")
        parser.add_option("-r",
                          "--raw-symbols",
                          type="string",
                          default=None,
                          help="dump decoded symbols to file")
        parser.add_option("-s",
                          "--sample-rate",
                          type="int",
                          default=96000,
                          help="input sample rate")
        parser.add_option("-t",
                          "--tone-detect",
                          action="store_true",
                          default=False,
                          help="use experimental tone detect algorithm")
        parser.add_option("-v",
                          "--verbose",
                          action="store_true",
                          default=False,
                          help="additional output")
        parser.add_option("-6",
                          "--k6k",
                          action="store_true",
                          default=False,
                          help="use 6K symbol rate")
        (options, args) = parser.parse_args()

        sample_rate = options.sample_rate
        if options.k6k:
            symbol_rate = 6000
        else:
            symbol_rate = 4800
        samples_per_symbol = sample_rate // symbol_rate

        IN = gr.file_source(gr.sizeof_gr_complex, options.input_file)

        if options.one_channel:
            C2F = gr.complex_to_float()
            F2C = gr.float_to_complex()

        # osc./mixer for mixing signal down to approx. zero IF
        LO = gr.sig_source_c(sample_rate, gr.GR_COS_WAVE, options.calibration,
                             1.0, 0)
        MIXER = gr.multiply_cc()

        # get signal into normalized range (-1.0 - +1.0)
        if options.agc:
            AMP = gr.feedforward_agc_cc(16, 1.0)
        else:
            AMP = gr.multiply_const_cc(options.gain)

        lpf_taps = gr.firdes.low_pass(1.0, sample_rate, options.low_pass,
                                      options.low_pass * 0.1,
                                      gr.firdes.WIN_HANN)

        decim_amt = 1
        if options.tone_detect:
            if sample_rate != 96000:
                print "warning, only 96K has been tested."
                print "other rates may require theta to be reviewed/adjusted."
            step_size = 7.5e-8
            theta = -4  # optimum timing sampling point
            cic_length = 48
            DEMOD = repeater.tdetect_cc(samples_per_symbol, step_size, theta,
                                        cic_length)
        else:
            # decim by 2 to get 48k rate
            samples_per_symbol /= 2  # for DECIM
            sample_rate /= 2  # for DECIM
            decim_amt = 2
            # create Gardner/Costas loop
            # the loop will not work if the sample levels aren't normalized (above)
            timing_error_gain = 0.025  # loop error gain
            gain_omega = 0.25 * timing_error_gain * timing_error_gain
            alpha = options.costas_alpha
            beta = 0.125 * alpha * alpha
            fmin = -0.025  # fmin and fmax are in radians/s
            fmax = 0.025
            DEMOD = repeater.gardner_costas_cc(samples_per_symbol,
                                               timing_error_gain, gain_omega,
                                               alpha, beta, fmax, fmin)
        DECIM = gr.fir_filter_ccf(decim_amt, lpf_taps)

        # probably too much phase noise etc to attempt coherent demodulation
        # so we use differential
        DIFF = gr.diff_phasor_cc()

        # take angle of the phase difference (in radians)
        TOFLOAT = gr.complex_to_arg()

        # convert from radians such that signal is in [-3, -1, +1, +3]
        RESCALE = gr.multiply_const_ff(1 / (pi / 4.0))

        # optional polarity reversal (should be unnec. - now autodetected)
        p = 1.0
        if options.polarity:
            p = -1.0
        POLARITY = gr.multiply_const_ff(p)

        # hard decision at specified points
        levels = [-2.0, 0.0, 2.0, 4.0]
        SLICER = repeater.fsk4_slicer_fb(levels)

        # assemble received frames and route to Wireshark via UDP
        hostname = "127.0.0.1"
        port = 23456
        debug = 0
        if options.verbose:
            debug = 255
        do_imbe = False
        if options.imbe:
            do_imbe = True
        do_output = True  # enable block's output stream
        do_msgq = False  # msgq output not yet implemented
        msgq = gr.msg_queue(2)
        DECODER = repeater.p25_frame_assembler(hostname, port, debug, do_imbe,
                                               do_output, do_msgq, msgq)

        OUT = gr.file_sink(gr.sizeof_char, options.output_file)

        if options.one_channel:
            self.connect(IN, C2F, F2C, (MIXER, 0))
        else:
            self.connect(IN, (MIXER, 0))
        self.connect(LO, (MIXER, 1))
        self.connect(MIXER, AMP, DECIM, DEMOD, DIFF, TOFLOAT, RESCALE,
                     POLARITY, SLICER, DECODER, OUT)

        if options.raw_symbols:
            SINKC = gr.file_sink(gr.sizeof_char, options.raw_symbols)
            self.connect(SLICER, SINKC)

        if options.debug:
            print 'Ready for GDB to attach (pid = %d)' % (os.getpid(), )
            raw_input("Press 'Enter' to continue...")
Example #41
0
    def __init__(
        self,
        agc_max=100,
        agc_decay=0.1,
        freq_offset=1000000,
        outfile="datafifo",
        bandpass_bandwidth=20,
        threshold_buffer=0.25,
        threshold_center=0.5,
        agc_attack=0.1,
        bandpass_transition_width=1000000,
    ):
        gr.top_block.__init__(self, "Collect")

        ##################################################
        # Parameters
        ##################################################
        self.agc_max = agc_max
        self.agc_decay = agc_decay
        self.freq_offset = freq_offset
        self.outfile = outfile
        self.bandpass_bandwidth = bandpass_bandwidth
        self.threshold_buffer = threshold_buffer
        self.threshold_center = threshold_center
        self.agc_attack = agc_attack
        self.bandpass_transition_width = bandpass_transition_width

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 64000000

        ##################################################
        # Blocks
        ##################################################
        self.uhd_usrp_source_0 = uhd.usrp_source(device_addr="", io_type=uhd.io_type.COMPLEX_FLOAT32, num_channels=1)
        self.uhd_usrp_source_0.set_samp_rate(samp_rate)
        self.uhd_usrp_source_0.set_center_freq(915000000 - freq_offset, 0)
        self.uhd_usrp_source_0.set_gain(0, 0)
        self.uhd_usrp_source_0.set_antenna("TX/RX", 0)
        self.gr_threshold_ff_0 = gr.threshold_ff(
            threshold_center - threshold_buffer, threshold_center + threshold_buffer, 0
        )
        self.gr_map_bb_0 = gr.map_bb(([48, 49]))
        self.gr_float_to_char_0 = gr.float_to_char()
        self.gr_file_sink_0 = gr.file_sink(gr.sizeof_char * 1, outfile)
        self.gr_file_sink_0.set_unbuffered(False)
        self.gr_complex_to_mag_0 = gr.complex_to_mag(1)
        self.gr_agc2_xx_0_0 = gr.agc2_cc(agc_attack, agc_decay, 1.0, 1.0, agc_max)
        self.band_pass_filter_0 = gr.fir_filter_ccf(
            1,
            firdes.band_pass(
                1,
                samp_rate,
                freq_offset - bandpass_bandwidth / 2,
                freq_offset + bandpass_bandwidth / 2,
                bandpass_transition_width,
                firdes.WIN_HAMMING,
                6.76,
            ),
        )

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_float_to_char_0, 0), (self.gr_map_bb_0, 0))
        self.connect((self.gr_map_bb_0, 0), (self.gr_file_sink_0, 0))
        self.connect((self.uhd_usrp_source_0, 0), (self.gr_agc2_xx_0_0, 0))
        self.connect((self.gr_agc2_xx_0_0, 0), (self.band_pass_filter_0, 0))
        self.connect((self.gr_threshold_ff_0, 0), (self.gr_float_to_char_0, 0))
        self.connect((self.gr_complex_to_mag_0, 0), (self.gr_threshold_ff_0, 0))
        self.connect((self.band_pass_filter_0, 0), (self.gr_complex_to_mag_0, 0))
Example #42
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-a",
                          "--args",
                          type="string",
                          default="",
                          help="UHD device address args [default=%default]")
        parser.add_option("",
                          "--spec",
                          type="string",
                          default=None,
                          help="Subdevice of UHD device where appropriate")
        parser.add_option("-A",
                          "--antenna",
                          type="string",
                          default=None,
                          help="select Rx Antenna where appropriate")
        parser.add_option(
            "-s",
            "--samp-rate",
            type="eng_float",
            default=1e6,
            help="set sample rate (bandwidth) [default=%default]")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=1008.0e3,
                          help="set frequency to FREQ",
                          metavar="FREQ")
        parser.add_option(
            "-I",
            "--use-if-freq",
            action="store_true",
            default=False,
            help=
            "use intermediate freq (compensates DC problems in quadrature boards)"
        )
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=None,
                          help="set gain in dB (default is maximum)")
        parser.add_option("-V",
                          "--volume",
                          type="eng_float",
                          default=None,
                          help="set volume (default is midpoint)")
        parser.add_option(
            "-O",
            "--audio-output",
            type="string",
            default="",
            help="pcm device name.  E.g., hw:0,0 or surround51 or /dev/dsp")

        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        self.frame = frame
        self.panel = panel
        self.use_IF = options.use_if_freq
        if self.use_IF:
            self.IF_freq = 64000.0
        else:
            self.IF_freq = 0.0

        self.vol = 0
        self.state = "FREQ"
        self.freq = 0

        # build graph
        self.u = uhd.usrp_source(device_addr=options.args,
                                 stream_args=uhd.stream_args('fc32'))

        usrp_rate = 256e3
        demod_rate = 64e3
        audio_rate = 32e3
        chanfilt_decim = int(usrp_rate // demod_rate)
        audio_decim = int(demod_rate // audio_rate)

        self.u.set_samp_rate(usrp_rate)
        dev_rate = self.u.get_samp_rate()

        # Resample signal to exactly self.usrp_rate
        # FIXME: make one of the follow-on filters an arb resampler
        rrate = usrp_rate / dev_rate
        self.resamp = blks2.pfb_arb_resampler_ccf(rrate)

        chan_filt_coeffs = gr.firdes.low_pass_2(
            1,  # gain
            usrp_rate,  # sampling rate
            8e3,  # passband cutoff
            4e3,  # transition bw
            60)  # stopband attenuation

        if self.use_IF:
            # Turn If to baseband and filter.
            self.chan_filt = gr.freq_xlating_fir_filter_ccf(
                chanfilt_decim, chan_filt_coeffs, self.IF_freq, usrp_rate)
        else:
            self.chan_filt = gr.fir_filter_ccf(chanfilt_decim,
                                               chan_filt_coeffs)

        self.agc = gr.agc_cc(0.1, 1, 1, 100000)
        self.am_demod = gr.complex_to_mag()
        self.volume_control = gr.multiply_const_ff(self.vol)

        audio_filt_coeffs = gr.firdes.low_pass_2(
            1,  # gain
            demod_rate,  # sampling rate
            8e3,  # passband cutoff
            2e3,  # transition bw
            60)  # stopband attenuation
        self.audio_filt = gr.fir_filter_fff(audio_decim, audio_filt_coeffs)

        # sound card as final sink
        self.audio_sink = audio.sink(int(audio_rate), options.audio_output,
                                     False)  # ok_to_block

        # now wire it all together
        self.connect(self.u, self.resamp, self.chan_filt, self.agc,
                     self.am_demod, self.audio_filt, self.volume_control,
                     self.audio_sink)

        self._build_gui(vbox, usrp_rate, demod_rate, audio_rate)

        if options.gain is None:
            g = self.u.get_gain_range()
            if True:
                # if no gain was specified, use the mid gain
                options.gain = (g.start() + g.stop()) / 2.0
                options.gain = g.stop()

        if options.volume is None:
            v = self.volume_range()
            options.volume = float(v[0] * 3 + v[1]) / 4.0

        if abs(options.freq) < 1e3:
            options.freq *= 1e3

        # set initial values

        self.set_gain(options.gain)
        self.set_vol(options.volume)
        if not (self.set_freq(options.freq)):
            self._set_status_msg("Failed to set initial frequency")

        # Set the subdevice spec
        if (options.spec):
            self.u.set_subdev_spec(options.spec, 0)

        # Set the antenna
        if (options.antenna):
            self.u.set_antenna(options.antenna, 0)
Example #43
0
    def __init__(self):
        gr.top_block.__init__(self)

        self.qapp = QtGui.QApplication(sys.argv)

        self._sample_rate = 2000e3

        self.sps = 2
        self.excess_bw = 0.35
        self.gray_code = digital.mod_codes.GRAY_CODE
        
        fftsize = 2048

        self.data = scipy.random.randint(0, 255, 1000)
        self.src = gr.vector_source_b(self.data.tolist(), True)
        self.mod = digital.dqpsk_mod(self.gray_code,
                                     samples_per_symbol=self.sps,
                                     excess_bw=self.excess_bw,
                                     verbose=False, log=False)

        self.rrctaps = gr.firdes.root_raised_cosine(1, self.sps, 1, self.excess_bw, 21)
        self.rx_rrc = gr.fir_filter_ccf(1, self.rrctaps)


        # Set up the carrier & clock recovery parameters
        self.arity = 4
        self.mu = 0.5
        self.gain_mu = 0.05
        self.omega = self.sps
        self.gain_omega = .25 * self.gain_mu * self.gain_mu
        self.omega_rel_lim = 0.05
        
        self._loop_bw = 2*scipy.pi/100.0
        self.fmin = -1000/self.sample_rate()
        self.fmax = 1000/self.sample_rate()
        
        self.receiver = digital.mpsk_receiver_cc(self.arity, 0,
                                                 self._loop_bw,
                                                 self.fmin, self.fmax,
                                                 self.mu, self.gain_mu,
                                                 self.omega, self.gain_omega,
                                                 self.omega_rel_lim)
        
        
        self.snr_dB = 15
        noise = self.get_noise_voltage(self.snr_dB)
        self.fo = 100/self.sample_rate()
        self.to = 1.0
        self.channel = gr.channel_model(noise, self.fo, self.to)

        self.thr = gr.throttle(gr.sizeof_char, self._sample_rate)
        self.snk_tx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS, 
                                   0, self._sample_rate*self.sps,
                                   "Tx", True, True, True, True)

        self.snk_rx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                   0, self._sample_rate,
                                   "Rx", True, True, True, True)

        self.connect(self.src, self.thr, self.mod, self.channel, self.snk_tx)
        self.connect(self.channel, self.rx_rrc, self.receiver, self.snk_rx)
        
        pyTxQt  = self.snk_tx.pyqwidget()
        pyTx = sip.wrapinstance(pyTxQt, QtGui.QWidget)

        pyRxQt  = self.snk_rx.pyqwidget()
        pyRx = sip.wrapinstance(pyRxQt, QtGui.QWidget)

        self.main_box = dialog_box(pyTx, pyRx, self);
        self.main_box.show()
Example #44
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 2.5e6
        self.decim = decim = 1
        self.post_decim = post_decim = samp_rate / decim
        self.freq_ctr2 = freq_ctr2 = 990e6
        self.freq_ctr1 = freq_ctr1 = 990e6
        self.cutoff = cutoff = 1e4 * 5

        ##################################################
        # Blocks
        ##################################################
        self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "1")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "2")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "3")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "4")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "5")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "6")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "7")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "8")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "9")
        self.Add(self.notebook_0)
        _freq_ctr1_sizer = wx.BoxSizer(wx.VERTICAL)
        self._freq_ctr1_text_box = forms.text_box(
            parent=self.notebook_0.GetPage(0).GetWin(),
            sizer=_freq_ctr1_sizer,
            value=self.freq_ctr1,
            callback=self.set_freq_ctr1,
            label="center frequency",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._freq_ctr1_slider = forms.slider(
            parent=self.notebook_0.GetPage(0).GetWin(),
            sizer=_freq_ctr1_sizer,
            value=self.freq_ctr1,
            callback=self.set_freq_ctr1,
            minimum=989.1e6,
            maximum=990.1e6,
            num_steps=1000,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.notebook_0.GetPage(0).Add(_freq_ctr1_sizer)
        self.wxgui_scopesink2_1_0 = scopesink2.scope_sink_c(
            self.notebook_0.GetPage(3).GetWin(),
            title="Scope Plot",
            sample_rate=post_decim,
            v_scale=0,
            v_offset=0,
            t_scale=0,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
            trig_mode=gr.gr_TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.notebook_0.GetPage(3).Add(self.wxgui_scopesink2_1_0.win)
        self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
            self.notebook_0.GetPage(2).GetWin(),
            title="Scope Plot",
            sample_rate=post_decim,
            v_scale=0,
            v_offset=0,
            t_scale=0,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
            trig_mode=gr.gr_TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.notebook_0.GetPage(2).Add(self.wxgui_scopesink2_1.win)
        self.wxgui_numbersink2_0_0_0_1 = numbersink2.number_sink_f(
            self.notebook_0.GetPage(1).GetWin(),
            unit="Hz",
            minval=-100,
            maxval=100,
            factor=1.0,
            decimal_places=10,
            ref_level=0,
            sample_rate=samp_rate * 0 + post_decim,
            number_rate=15,
            average=False,
            avg_alpha=0.001,
            label="phase",
            peak_hold=False,
            show_gauge=False,
        )
        self.notebook_0.GetPage(1).Add(self.wxgui_numbersink2_0_0_0_1.win)
        self.wxgui_numbersink2_0_0_0_0 = numbersink2.number_sink_f(
            self.notebook_0.GetPage(1).GetWin(),
            unit="Hz",
            minval=-100,
            maxval=100,
            factor=1.0,
            decimal_places=10,
            ref_level=0,
            sample_rate=samp_rate * 0 + post_decim,
            number_rate=15,
            average=False,
            avg_alpha=0.001,
            label="error",
            peak_hold=False,
            show_gauge=False,
        )
        self.notebook_0.GetPage(1).Add(self.wxgui_numbersink2_0_0_0_0.win)
        self.wxgui_numbersink2_0_0_0 = numbersink2.number_sink_f(
            self.notebook_0.GetPage(1).GetWin(),
            unit="Hz",
            minval=-100,
            maxval=100,
            factor=1.0,
            decimal_places=10,
            ref_level=0,
            sample_rate=samp_rate * 0 + post_decim,
            number_rate=15,
            average=False,
            avg_alpha=0.001,
            label="freq",
            peak_hold=False,
            show_gauge=False,
        )
        self.notebook_0.GetPage(1).Add(self.wxgui_numbersink2_0_0_0.win)
        self.wxgui_numbersink2_0_0 = numbersink2.number_sink_c(
            self.notebook_0.GetPage(1).GetWin(),
            unit="",
            minval=-100,
            maxval=100,
            factor=1.0,
            decimal_places=10,
            ref_level=0,
            sample_rate=samp_rate * 0 + post_decim,
            number_rate=15,
            average=False,
            avg_alpha=0.001,
            label="signal",
            peak_hold=False,
            show_gauge=False,
        )
        self.notebook_0.GetPage(1).Add(self.wxgui_numbersink2_0_0.win)
        self.wxgui_fftsink2_0_0 = fftsink2.fft_sink_c(
            self.notebook_0.GetPage(0).GetWin(),
            baseband_freq=freq_ctr1,
            y_per_div=10,
            y_divs=5,
            ref_level=-10,
            ref_scale=2.0,
            sample_rate=samp_rate * 0 + post_decim,
            fft_size=1024,
            fft_rate=15,
            average=True,
            avg_alpha=0.2,
            title="FFT Plot",
            peak_hold=False,
        )
        self.notebook_0.GetPage(0).Add(self.wxgui_fftsink2_0_0.win)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
            self.notebook_0.GetPage(0).GetWin(),
            baseband_freq=freq_ctr1,
            y_per_div=10,
            y_divs=5,
            ref_level=-10,
            ref_scale=2.0,
            sample_rate=samp_rate * 0 + post_decim,
            fft_size=1024,
            fft_rate=15,
            average=True,
            avg_alpha=0.2,
            title="FFT Plot",
            peak_hold=False,
        )
        self.notebook_0.GetPage(0).Add(self.wxgui_fftsink2_0.win)
        self.osmosdr_source_c_0 = osmosdr.source_c(args="nchan=" + str(1) + " " + "rtl=0,xtal=28.8e6,tuner_xtal=28.8e6")
        self.osmosdr_source_c_0.set_sample_rate(samp_rate)
        self.osmosdr_source_c_0.set_center_freq(freq_ctr1, 0)
        self.osmosdr_source_c_0.set_freq_corr(0, 0)
        self.osmosdr_source_c_0.set_iq_balance_mode(2, 0)
        self.osmosdr_source_c_0.set_gain_mode(1, 0)
        self.osmosdr_source_c_0.set_gain(0, 0)
        self.osmosdr_source_c_0.set_if_gain(0, 0)

        self.low_pass_filter_0 = gr.fir_filter_ccf(
            decim, firdes.low_pass(1, samp_rate, samp_rate / 4, samp_rate / 4, firdes.WIN_HAMMING, 6.76)
        )
        _freq_ctr2_sizer = wx.BoxSizer(wx.VERTICAL)
        self._freq_ctr2_text_box = forms.text_box(
            parent=self.notebook_0.GetPage(4).GetWin(),
            sizer=_freq_ctr2_sizer,
            value=self.freq_ctr2,
            callback=self.set_freq_ctr2,
            label="center frequency",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._freq_ctr2_slider = forms.slider(
            parent=self.notebook_0.GetPage(4).GetWin(),
            sizer=_freq_ctr2_sizer,
            value=self.freq_ctr2,
            callback=self.set_freq_ctr2,
            minimum=989.1e6,
            maximum=990.1e6,
            num_steps=1000,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.notebook_0.GetPage(4).Add(_freq_ctr2_sizer)
        self.digital_fll_band_edge_cc_0 = digital.fll_band_edge_cc(2, 0.05, 512, 0.008)
        self.analog_pll_refout_cc_0 = analog.pll_refout_cc(math.pi / 1000, 2, -2)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.low_pass_filter_0, 0), (self.wxgui_fftsink2_0_0, 0))
        self.connect((self.low_pass_filter_0, 0), (self.wxgui_scopesink2_1_0, 0))
        self.connect((self.digital_fll_band_edge_cc_0, 2), (self.wxgui_numbersink2_0_0_0_1, 0))
        self.connect((self.digital_fll_band_edge_cc_0, 3), (self.wxgui_numbersink2_0_0_0_0, 0))
        self.connect((self.osmosdr_source_c_0, 0), (self.low_pass_filter_0, 0))
        self.connect((self.low_pass_filter_0, 0), (self.digital_fll_band_edge_cc_0, 0))
        self.connect((self.digital_fll_band_edge_cc_0, 1), (self.wxgui_numbersink2_0_0_0, 0))
        self.connect((self.digital_fll_band_edge_cc_0, 0), (self.analog_pll_refout_cc_0, 0))
        self.connect((self.analog_pll_refout_cc_0, 0), (self.wxgui_fftsink2_0, 0))
        self.connect((self.analog_pll_refout_cc_0, 0), (self.wxgui_scopesink2_1, 0))
        self.connect((self.analog_pll_refout_cc_0, 0), (self.wxgui_numbersink2_0_0, 0))
Example #45
0
    def __init__(self,
                 if_rate,        # Incoming sample rate
                 symbol_rate,    # Original symbol rate
                 excess_bw,      # RRC excess bandwidth, typically 0.35-0.5
                 costas_alpha,   # Costas loop 1st order gain, typically 0.01-0.2
                 costas_beta,    # Costas loop 2nd order gain, typically alpha^2/4.0
                 costas_max,     # Costas loop max frequency offset in radians/sample
                 mm_gain_mu,     # M&M loop 1st order gain, typically 0.001-0.2
                 mm_gain_omega,  # M&M loop 2nd order gain, typically alpha^2/4.0
                 mm_omega_limit, # M&M loop max timing error
                 ):
        
        gr.hier_block2.__init__(self, "receive_path",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
                                gr.io_signature(0, 0, 0))                    # Output signature
        
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        
        self._if_rate = if_rate
        self._sps = int(self._if_rate/symbol_rate)
        print "IF sample rate:", n2s(self._if_rate)
        print "Symbol rate:", n2s(symbol_rate)
        print "Samples/symbol:", self._sps
        print "RRC bandwidth:", excess_bw
        
        # Create AGC to scale input to unity
        self._agc = gr.agc_cc(1e-5, 1.0, 1.0, 1.0)

	# Create RRC with specified excess bandwidth
	taps = gr.firdes.root_raised_cosine(1.0,          # Gain
					    self._sps,    # Sampling rate
					    1.0,          # Symbol rate
					    excess_bw,    # Roll-off factor
					    11*self._sps) # Number of taps

	self._rrc = gr.fir_filter_ccf(1, taps)
        
        # Create a Costas loop frequency/phase recovery block

        print "Costas alpha:", costas_alpha
        print "Costas beta:", costas_beta
        print "Costas max:", costas_max
        
        self._costas = gr.costas_loop_cc(costas_alpha,  # PLL first order gain
                                         costas_beta,   # PLL second order gain
                                         costas_max,    # Max frequency offset rad/sample
                                         -costas_max,   # Min frequency offset rad/sample
                                         2)             # BPSK

        # Create a M&M bit synchronization retiming block
        mm_mu = 0.5
        mm_omega = self._sps

        print "MM gain mu:", mm_gain_mu
        print "MM gain omega:", mm_gain_omega
        print "MM omega limit:", mm_omega_limit
        
        self._mm = gr.clock_recovery_mm_cc(mm_omega,       # Initial samples/symbol
                                           mm_gain_omega,  # Second order gain
                                           mm_mu,          # Initial symbol phase
                                           mm_gain_mu,     # First order gain
                                           mm_omega_limit) # Maximum timing offset

        # Add an SNR probe on the demodulated constellation
        self._snr_probe = gr.probe_mpsk_snr_c(10.0/symbol_rate)
        
#        #Null for recuperate the out of snr
#        self.gr_null_sink_0 = gr.null_sink(gr.sizeof_double)
#        
#        self.connect(self._snr_probe, (self.gr_null_sink_0,0))
        
        self.connect(self._mm, self._snr_probe)
        
        # Slice the resulting constellation into bits.
        # Get inphase channel and make decision about 0
        self._c2r = gr.complex_to_real()
        self._slicer = gr.binary_slicer_fb() 
        
        # Descramble BERT sequence.  A channel error will create 3 incorrect bits
        self._descrambler = gr.descrambler_bb(0x8A, 0x7F, 7) # CCSDS 7-bit descrambler

        # Measure BER by the density of 0s in the stream
        self._ber = gr.probe_density_b(1.0/symbol_rate)
        
#        #Null for recuperate the out of ber
#        self.gr_null_sink_1 = gr.null_sink(gr.sizeof_double)
#        
#        self.connect(self._ber, self.gr_null_sink_1)
        
        self.create_number_sink(self._sps)
        self.connect((self._snr_probe, 0), (self.wxgui_numbersink2_0, 0))
        self.connect((self._ber, 0), (self.wxgui_numbersink2_1, 0))

        self.connect(self, self._agc, self._rrc, self._costas, self._mm, 
                     self._c2r, self._slicer, self._descrambler, self._ber)
Example #46
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-R",
                          "--rx-subdev-spec",
                          type="subdev",
                          default=None,
                          help="select USRP Rx side A or B (default=A)")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=91.2e6,
                          help="set frequency to FREQ",
                          metavar="FREQ")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=None,
                          help="set gain in dB")
        parser.add_option("-s",
                          "--squelch",
                          type="eng_float",
                          default=0,
                          help="set squelch level (default is 0)")
        parser.add_option("-V",
                          "--volume",
                          type="eng_float",
                          default=None,
                          help="set volume (default is midpoint)")
        parser.add_option("-O",
                          "--audio-output",
                          type="string",
                          default="plughw:0,0",
                          help="pcm device name (default is plughw:0,0)")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        # connect to USRP
        usrp_decim = 250
        self.u = usrp.source_c(0, usrp_decim)
        print "USRP Serial: ", self.u.serial_number()
        demod_rate = self.u.adc_rate() / usrp_decim  # 256 kS/s
        audio_decim = 8
        audio_rate = demod_rate / audio_decim  # 32 kS/s
        if options.rx_subdev_spec is None:
            options.rx_subdev_spec = usrp.pick_subdev(self.u, dblist)

        self.u.set_mux(
            usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
        print "Using d'board", self.subdev.side_and_name()

        # gain, volume, frequency
        self.gain = options.gain
        if options.gain is None:
            self.gain = self.subdev.gain_range()[1]

        self.vol = options.volume
        if self.vol is None:
            g = self.volume_range()
            self.vol = float(g[0] + g[1]) / 2

        self.freq = options.freq
        if abs(self.freq) < 1e6:
            self.freq *= 1e6

        print "Volume:%r, Gain:%r, Freq:%3.1f MHz" % (self.vol, self.gain,
                                                      self.freq / 1e6)

        # channel filter, wfm_rcv_pll
        chan_filt_coeffs = optfir.low_pass(
            1,  # gain
            demod_rate,  # rate
            80e3,  # passband cutoff
            115e3,  # stopband cutoff
            0.1,  # passband ripple
            60)  # stopband attenuation
        self.chan_filt = gr.fir_filter_ccf(1, chan_filt_coeffs)
        self.guts = blks2.wfm_rcv_pll(demod_rate, audio_decim)
        self.connect(self.u, self.chan_filt, self.guts)

        # volume control, audio sink
        self.volume_control_l = gr.multiply_const_ff(self.vol)
        self.volume_control_r = gr.multiply_const_ff(self.vol)
        self.audio_sink = audio.sink(int(audio_rate), options.audio_output,
                                     False)
        self.connect((self.guts, 0), self.volume_control_l,
                     (self.audio_sink, 0))
        self.connect((self.guts, 1), self.volume_control_r,
                     (self.audio_sink, 1))

        # pilot channel filter (band-pass, 18.5-19.5kHz)
        pilot_filter_coeffs = gr.firdes.band_pass(
            1,  # gain
            demod_rate,  # sampling rate
            18.5e3,  # low cutoff
            19.5e3,  # high cutoff
            1e3,  # transition width
            gr.firdes.WIN_HAMMING)
        self.pilot_filter = gr.fir_filter_fff(1, pilot_filter_coeffs)
        self.connect(self.guts.fm_demod, self.pilot_filter)

        # RDS channel filter (band-pass, 54-60kHz)
        rds_filter_coeffs = gr.firdes.band_pass(
            1,  # gain
            demod_rate,  # sampling rate
            54e3,  # low cutoff
            60e3,  # high cutoff
            3e3,  # transition width
            gr.firdes.WIN_HAMMING)
        self.rds_filter = gr.fir_filter_fff(1, rds_filter_coeffs)
        self.connect(self.guts.fm_demod, self.rds_filter)

        # create 57kHz subcarrier from 19kHz pilot, downconvert RDS channel
        self.mixer = gr.multiply_ff()
        self.connect(self.pilot_filter, (self.mixer, 0))
        self.connect(self.pilot_filter, (self.mixer, 1))
        self.connect(self.pilot_filter, (self.mixer, 2))
        self.connect(self.rds_filter, (self.mixer, 3))

        # low-pass the baseband RDS signal at 1.5kHz
        rds_bb_filter_coeffs = gr.firdes.low_pass(
            1,  # gain
            demod_rate,  # sampling rate
            1.5e3,  # passband cutoff
            2e3,  # transition width
            gr.firdes.WIN_HAMMING)
        self.rds_bb_filter = gr.fir_filter_fff(1, rds_bb_filter_coeffs)
        self.connect(self.mixer, self.rds_bb_filter)

        # 1187.5bps = 19kHz/16
        self.rds_clock = rds.freq_divider(16)
        clock_taps = gr.firdes.low_pass(
            1,  # gain
            demod_rate,  # sampling rate
            1.2e3,  # passband cutoff
            1.5e3,  # transition width
            gr.firdes.WIN_HANN)
        self.clock_filter = gr.fir_filter_fff(1, clock_taps)
        self.connect(self.pilot_filter, self.rds_clock, self.clock_filter)

        # bpsk_demod, diff_decoder, rds_decoder
        self.bpsk_demod = rds.bpsk_demod(demod_rate)
        self.differential_decoder = gr.diff_decoder_bb(2)
        self.msgq = gr.msg_queue()
        self.rds_decoder = rds.data_decoder(self.msgq)
        self.connect(self.rds_bb_filter, (self.bpsk_demod, 0))
        self.connect(self.clock_filter, (self.bpsk_demod, 1))
        self.connect(self.bpsk_demod, self.differential_decoder)
        self.connect(self.differential_decoder, self.rds_decoder)

        # set initial values
        self.subdev.set_gain(self.gain)
        self.set_vol(self.vol)
        self.set_freq(self.freq)
Example #47
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-e",
                          "--interface",
                          type="string",
                          default="eth0",
                          help="select Ethernet interface, default is eth0")
        parser.add_option(
            "-m",
            "--mac-addr",
            type="string",
            default="",
            help="select USRP by MAC address, default is auto-select")
        #parser.add_option("-A", "--antenna", default=None,
        #                  help="select Rx Antenna (only on RFX-series boards)")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=100.1,
                          help="set frequency to FREQ",
                          metavar="FREQ")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-V",
                          "--volume",
                          type="eng_float",
                          default=None,
                          help="set volume (default is midpoint)")
        parser.add_option(
            "-O",
            "--audio-output",
            type="string",
            default="",
            help="pcm device name.  E.g., hw:0,0 or surround51 or /dev/dsp")

        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        self.frame = frame
        self.panel = panel

        self.vol = 0
        self.state = "FREQ"
        self.freq = 0

        # build graph

        self.u = usrp2.source_32fc(options.interface, options.mac_addr)

        adc_rate = self.u.adc_rate()  # 100 MS/s
        usrp_decim = 312
        self.u.set_decim(usrp_decim)
        usrp_rate = adc_rate / usrp_decim  # ~320 kS/s
        chanfilt_decim = 1
        demod_rate = usrp_rate / chanfilt_decim
        audio_decimation = 10
        audio_rate = demod_rate / audio_decimation  # ~32 kHz

        #FIXME: need named constants and text descriptions available to (gr-)usrp2 even
        #when usrp(1) module is not built.  A usrp_common module, perhaps?
        dbid = self.u.daughterboard_id()
        print "Using RX d'board 0x%04X" % (dbid, )
        if not (dbid == 0x0001 or  #usrp_dbid.BASIC_RX
                dbid == 0x0003 or  #usrp_dbid.TV_RX
                dbid == 0x000c or  #usrp_dbid.TV_RX_REV_2
                dbid == 0x0040 or  #usrp_dbid.TV_RX_REV_3
                dbid == 0x0043 or  #usrp_dbid.TV_RX_MIMO
                dbid == 0x0044 or  #usrp_dbid.TV_RX_REV_2_MIMO
                dbid == 0x0045):  #usrp_dbid.TV_RX_REV_3_MIMO
            print "This daughterboard does not cover the required frequency range"
            print "for this application.  Please use a BasicRX or TVRX daughterboard."
            raw_input("Press ENTER to continue anyway, or Ctrl-C to exit.")

        chan_filt_coeffs = optfir.low_pass(
            1,  # gain
            usrp_rate,  # sampling rate
            80e3,  # passband cutoff
            115e3,  # stopband cutoff
            0.1,  # passband ripple
            60)  # stopband attenuation
        #print len(chan_filt_coeffs)
        chan_filt = gr.fir_filter_ccf(chanfilt_decim, chan_filt_coeffs)

        self.guts = blks2.wfm_rcv(demod_rate, audio_decimation)

        self.volume_control = gr.multiply_const_ff(self.vol)

        # sound card as final sink
        audio_sink = audio.sink(int(audio_rate), options.audio_output,
                                False)  # ok_to_block

        # now wire it all together
        self.connect(self.u, chan_filt, self.guts, self.volume_control,
                     audio_sink)

        self._build_gui(vbox, usrp_rate, demod_rate, audio_rate)

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.u.gain_range()
            options.gain = float(g[0] + g[1]) / 2

        if options.volume is None:
            g = self.volume_range()
            options.volume = float(g[0] + g[1]) / 2

        if abs(options.freq) < 1e6:
            options.freq *= 1e6

        # set initial values

        self.set_gain(options.gain)
        self.set_vol(options.volume)
        if not (self.set_freq(options.freq)):
            self._set_status_msg("Failed to set initial frequency")
Example #48
0
    def __init__(self,
                 if_rate,        # Incoming sample rate
                 symbol_rate,    # Original symbol rate
                 excess_bw,      # RRC excess bandwidth, typically 0.35-0.5
                 costas_alpha,   # Costas loop 1st order gain, typically 0.01-0.2
                 costas_beta,    # Costas loop 2nd order gain, typically alpha^2/4.0
                 costas_max,     # Costas loop max frequency offset in radians/sample
                 mm_gain_mu,     # M&M loop 1st order gain, typically 0.001-0.2
                 mm_gain_omega,  # M&M loop 2nd order gain, typically alpha^2/4.0
                 mm_omega_limit, # M&M loop max timing error
                 ):
        
        gr.hier_block2.__init__(self, "receive_path",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
                                gr.io_signature(0, 0, 0))                    # Output signature

        self._if_rate = if_rate
        self._sps = int(self._if_rate/symbol_rate)
        print "IF sample rate:", n2s(self._if_rate)
        print "Symbol rate:", n2s(symbol_rate)
        print "Samples/symbol:", self._sps
        print "RRC bandwidth:", excess_bw
        
        # Create AGC to scale input to unity
        self._agc = gr.agc_cc(1e-5, 1.0, 1.0, 1.0)

	# Create RRC with specified excess bandwidth
	taps = gr.firdes.root_raised_cosine(1.0,          # Gain
					    self._sps,    # Sampling rate
					    1.0,          # Symbol rate
					    excess_bw,    # Roll-off factor
					    11*self._sps) # Number of taps

	self._rrc = gr.fir_filter_ccf(1, taps)
        
        # Create a Costas loop frequency/phase recovery block

        print "Costas alpha:", costas_alpha
        print "Costas beta:", costas_beta
        print "Costas max:", costas_max
        
        self._costas = gr.costas_loop_cc(costas_alpha,  # PLL first order gain
                                         costas_beta,   # PLL second order gain
                                         costas_max,    # Max frequency offset rad/sample
                                         -costas_max,   # Min frequency offset rad/sample
                                         2)             # BPSK

        # Create a M&M bit synchronization retiming block
        mm_mu = 0.5
        mm_omega = self._sps

        print "MM gain mu:", mm_gain_mu
        print "MM gain omega:", mm_gain_omega
        print "MM omega limit:", mm_omega_limit
        
        self._mm = gr.clock_recovery_mm_cc(mm_omega,       # Initial samples/symbol
                                           mm_gain_omega,  # Second order gain
                                           mm_mu,          # Initial symbol phase
                                           mm_gain_mu,     # First order gain
                                           mm_omega_limit) # Maximum timing offset

        # Add an SNR probe on the demodulated constellation
        self._snr_probe = gr.probe_mpsk_snr_c(10.0/symbol_rate)
        self.connect(self._mm, self._snr_probe)
        
        # Slice the resulting constellation into bits.
        # Get inphase channel and make decision about 0
        self._c2r = gr.complex_to_real()
        self._slicer = gr.binary_slicer_fb() 
        
        # Descramble BERT sequence.  A channel error will create 3 incorrect bits
        self._descrambler = gr.descrambler_bb(0x8A, 0x7F, 7) # CCSDS 7-bit descrambler

        # Measure BER by the density of 0s in the stream
        self._ber = gr.probe_density_b(1.0/symbol_rate)

        self.connect(self, self._agc, self._rrc, self._costas, self._mm, 
                     self._c2r, self._slicer, self._descrambler, self._ber)
Example #49
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage = "usage: %prog [options] input-samples-320kS.dat output.wav"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-V",
                          "--volume",
                          type="eng_float",
                          default=None,
                          help="set volume (default is midpoint)")

        (options, args) = parser.parse_args()
        if len(args) != 2:
            parser.print_help()
            sys.exit(1)

        input_filename = args[0]
        output_filename = args[1]

        self.vol = 0

        # build graph

        self.src = gr.file_source(gr.sizeof_gr_complex, input_filename, False)

        adc_rate = 64e6  # 64 MS/s
        usrp_decim = 200
        usrp_rate = adc_rate / usrp_decim  # 320 kS/s
        chanfilt_decim = 1
        demod_rate = usrp_rate / chanfilt_decim
        audio_decimation = 10
        audio_rate = demod_rate / audio_decimation  # 32 kHz

        chan_filt_coeffs = optfir.low_pass(
            1,  # gain
            usrp_rate,  # sampling rate
            80e3,  # passband cutoff
            115e3,  # stopband cutoff
            0.1,  # passband ripple
            60)  # stopband attenuation
        #print len(chan_filt_coeffs)
        chan_filt = gr.fir_filter_ccf(chanfilt_decim, chan_filt_coeffs)

        #self.guts = blks2.wfm_rcv (demod_rate, audio_decimation)
        self.guts = blks2.wfm_rcv_pll(demod_rate, audio_decimation)

        # FIXME rework {add,multiply}_const_* to handle multiple streams
        self.volume_control_l = gr.multiply_const_ff(self.vol)
        self.volume_control_r = gr.multiply_const_ff(self.vol)

        # wave file as final sink
        if 1:
            sink = gr.wavfile_sink(output_filename, 2, int(audio_rate), 16)
        else:
            sink = audio.sink(int(audio_rate), options.audio_output,
                              False)  # ok_to_block

        # now wire it all together
        self.connect(self.src, chan_filt, self.guts)
        self.connect((self.guts, 0), self.volume_control_l, (sink, 0))
        self.connect((self.guts, 1), self.volume_control_r, (sink, 1))
        try:
            self.guts.stereo_carrier_pll_recovery.squelch_enable(True)
        except:
            pass
            #print "FYI: This implementation of the stereo_carrier_pll_recovery has no squelch implementation yet"

        if options.volume is None:
            g = self.volume_range()
            options.volume = float(g[0] + g[1]) / 2

        # set initial values

        self.set_vol(options.volume)
        try:
            self.guts.stereo_carrier_pll_recovery.set_lock_threshold(
                options.squelch)
        except:
            pass
Example #50
0
  def __init__ (self, options):
    gr.top_block.__init__(self, "ofdm_benchmark")

    ##self._tx_freq            = options.tx_freq         # tranmitter's center frequency
    ##self._tx_subdev_spec     = options.tx_subdev_spec  # daughterboard to use
    ##self._fusb_block_size    = options.fusb_block_size # usb info for USRP
    ##self._fusb_nblocks       = options.fusb_nblocks    # usb info for USRP
    ##self._which              = options.which_usrp
    self._bandwidth          = options.bandwidth
    self.servants = []
    self._verbose            = options.verbose
    
    ##self._interface          = options.interface
    ##self._mac_addr           = options.mac_addr

    self._options = copy.copy( options )


    self._interpolation = 1
    
    f1 = numpy.array([-107,0,445,0,-1271,0,2959,0,-6107,0,11953,
                      0,-24706,0,82359,262144/2,82359,0,-24706,0,
                      11953,0,-6107,0,2959,0,-1271,0,445,0,-107],
                      numpy.float64)/262144.
    
    print "Software interpolation: %d" % (self._interpolation)

    bw = 1.0/self._interpolation
    tb = bw/5
    if self._interpolation > 1:
      self.tx_filter = gr.hier_block2("filter",
                                   gr.io_signature(1,1,gr.sizeof_gr_complex),
                                   gr.io_signature(1,1,gr.sizeof_gr_complex))
      self.tx_filter2 = gr.hier_block2("filter",
                                   gr.io_signature(1,1,gr.sizeof_gr_complex),
                                   gr.io_signature(1,1,gr.sizeof_gr_complex))
      self.tx_filter.connect( self.tx_filter, gr.interp_fir_filter_ccf(2,f1),
                           gr.interp_fir_filter_ccf(2,f1), self.tx_filter )
      self.tx_filter2.connect( self.tx_filter2, gr.interp_fir_filter_ccf(2,f1),
                           gr.interp_fir_filter_ccf(2,f1), self.tx_filter2 )
      print "New"

    else:
      self.tx_filter = None
      self.tx_filter2 = None
      
    self.decimation = 1
    
    if self.decimation > 1:
      bw = 0.5/self.decimation * 1
      tb = bw/5
      # gain, sampling rate, passband cutoff, stopband cutoff
      # passband ripple in dB, stopband attenuation in dB
      # extra taps
      filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw+tb, 0.1, 60.0, 1)
      print "Software decimation filter length: %d" % (len(filt_coeff))
      self.rx_filter = gr.fir_filter_ccf(self.decimation,filt_coeff)
      self.rx_filter2 = gr.fir_filter_ccf(self.decimation,filt_coeff)
    else:
      self.rx_filter = None
      self.rx_filter2 = None
      
      
##    if not options.from_file is None:
##      # sent captured file to usrp
##      self.src = gr.file_source(gr.sizeof_gr_complex,options.from_file)
##      self._setup_usrp_sink()
##      if hasattr(self, "filter"):
##        self.connect(self.src,self.filter,self.u) #,self.filter
##      else:
##        self.connect(self.src,self.u)
##      
##      return 
    
    
    
    self._setup_tx_path(options)
    self._setup_rx_path(options)
    
    config = station_configuration()
    
    self.enable_info_tx("info_tx", "pa_user")
#    if not options.no_cheat:
#      self.txpath.enable_channel_cheating("channelcheat")
    self.txpath.enable_txpower_adjust("txpower")
    self.txpath.publish_txpower("txpower_info")
    
    if options.disable_equalization or options.ideal:
        #print "CHANGE set_k"
        self.rxpath.enable_estim_power_adjust("estim_power")
        #self.rxpath.publish_estim_power("txpower_info")
         
    #self.enable_txfreq_adjust("txfreq")
    
    

    if options.imgxfer:
      self.rxpath.setup_imgtransfer_sink()
    
    if not options.no_decoding:
      self.rxpath.publish_rx_performance_measure()
      
    


    self.dst	= (self.rxpath,0)
    self.dst2 	= (self.rxpath,1)
    
    if options.force_rx_filter:
      print "Forcing rx filter usage"
      self.connect( self.rx_filter, self.dst )
      self.connect( self.rx_filter2, self.dst2 )
      self.dst = self.rx_filter
      self.dst2 = self.rx_filter2
    
    
    if options.measure:
      self.m = throughput_measure(gr.sizeof_gr_complex)
      self.m2 = throughput_measure(gr.sizeof_gr_complex)
      self.connect( self.m, self.dst )
      self.connect( self.m2, self.dst2 )
      self.dst = self.m
      self.dst2 = self.m2


    if options.snr is not None:
      if options.berm is not False:
          noise_sigma = 380 #empirically given, gives the received SNR range of (1:28) for tx amp. range of (500:10000) which is set in rm_ber_measurement.py
          #check for fading channel 
      else:
          snr_db = options.snr
          snr = 10.0**(snr_db/10.0)
          noise_sigma = sqrt( config.rms_amplitude**2 / snr )
          
      print " Noise St. Dev. %d" % (noise_sigma)
      awgn_chan = blocks.add_cc()
      awgn_chan2 = blocks.add_cc()
      awgn_noise_src = ofdm.complex_white_noise( 0.0, noise_sigma )
      awgn_noise_src2 = ofdm.complex_white_noise( 0.0, noise_sigma )
      self.connect( awgn_chan, self.dst )
      self.connect( awgn_chan2, self.dst2 )
      self.connect( awgn_noise_src, (awgn_chan,1) )
      self.connect( awgn_noise_src2, (awgn_chan2,1) )  
      self.dst = awgn_chan
      self.dst2 = awgn_chan2



    if options.freqoff is not None:
      freq_shift = blocks.multiply_cc()
      freq_shift2 = blocks.multiply_cc()
      norm_freq = options.freqoff / config.fft_length
      freq_off_src = analog.sig_source_c(1.0, analog.GR_SIN_WAVE, norm_freq, 1.0, 0.0 )
      freq_off_src2 = analog.sig_source_c(1.0, analog.GR_SIN_WAVE, norm_freq, 1.0, 0.0 )
      self.connect( freq_off_src, ( freq_shift, 1 ) )
      self.connect( freq_off_src2, ( freq_shift2, 1 ) )
      dst = self.dst
      dst2 = self.dst2
      self.connect( freq_shift, dst )
      self.connect( freq_shift2, dst2 )
      self.dst = freq_shift
      self.dst2 = freq_shift2


    if options.multipath:
      if options.itu_channel:
        fad_chan = itpp.tdl_channel(  ) #[0, -7, -20], [0, 2, 6]
          #fad_chan.set_norm_doppler( 1e-9 )
          #fad_chan.set_LOS( [500.,0,0] )
        fad_chan2 = itpp.tdl_channel(  )
        fad_chan.set_channel_profile( itpp.ITU_Pedestrian_A, 5e-8 )
        fad_chan.set_norm_doppler( 1e-8 )
        fad_chan2.set_channel_profile( itpp.ITU_Pedestrian_A, 5e-8 )
        fad_chan2.set_norm_doppler( 1e-8 )
      else:
        fad_chan = gr.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j])
        fad_chan2 = gr.fir_filter_ccc(1,[1.0,0.0,2e-1+0.1j,1e-4-0.04j])
        
      self.connect( fad_chan, self.dst )
      self.connect( fad_chan2, self.dst2 )
      self.dst = fad_chan
      self.dst2 = fad_chan2

    if options.samplingoffset is not None:
      soff = options.samplingoffset
      interp = moms(1000000+soff,1000000)
      interp2 = moms(1000000+soff,1000000)
      self.connect( interp, self.dst )
      self.connect( interp2, self.dst2 )
      self.dst = interp
      self.dst2 = interp2
      
      if options.record:
       log_to_file( self, interp, "data/interp_out.compl" )
       log_to_file( self, interp2, "data/interp2_out.compl" )
    
    tmm =blocks.throttle(gr.sizeof_gr_complex,self._bandwidth)
    tmm2 =blocks.throttle(gr.sizeof_gr_complex,self._bandwidth)
    tmm_add = blocks.add_cc()
    tmm2_add = blocks.add_cc()
    self.connect( tmm, tmm_add )
    self.connect( tmm2, (tmm_add,1) )
    self.connect( tmm, tmm2_add )
    self.connect( tmm2, (tmm2_add,1) )
    self.connect( tmm_add, self.dst )
    self.connect( tmm2_add, self.dst2 )
    self.dst = tmm
    self.dst2 = tmm2
    
    inter = blocks.interleave(gr.sizeof_gr_complex)
    deinter = blocks.deinterleave(gr.sizeof_gr_complex)
    
    self.connect(inter, deinter)
    self.connect((deinter,0),self.dst)
    self.connect((deinter,1),self.dst2)
    self.dst = inter
    self.dst2 = (inter,1)
    
    
    if options.force_tx_filter:
      print "Forcing tx filter usage"
      self.connect( self.tx_filter, self.dst )
      self.connect( self.tx_filter2, self.dst2 )
      self.dst = self.tx_filter
      self.dst2 = self.tx_filter2
    if options.record:
      log_to_file( self, self.txpath, "data/txpath_out.compl" )
      log_to_file( self, self.txpath2, "data/txpath2_out.compl" )
      
    if options.nullsink:
        self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst)
        self.connect(gr.null_source(gr.sizeof_gr_complex), self.dst2)
        self.dst = gr.null_sink(gr.sizeof_gr_complex)
        self.dst2 = gr.null_sink(gr.sizeof_gr_complex)
        
    
    self.connect( self.txpath,self.dst )
    self.connect( (self.txpath,1),self.dst2 )
    
    
    if options.cheat:
      self.txpath.enable_channel_cheating("channelcheat")

    
      
    print "Hit Strg^C to terminate"

    if options.event_rxbaseband:
      self.publish_rx_baseband_measure()
      
      
    if options.with_old_gui:
      self.publish_spectrum(256)
      self.rxpath.publish_ctf("ctf_display")
      self.rxpath.publish_ber_measurement(["ber"])
      self.rxpath.publish_average_snr(["totalsnr"])
      if options.sinr_est:
        self.rxpath.publish_sinrsc("sinrsc_display")
      

    
    print "Hit Strg^C to terminate"


    # Display some information about the setup
    if self._verbose:
        self._print_verbage()
Example #51
0
    def __init__(self,
                 deframer_insync_frames=2,
                 viterbi_insync_frames=5,
                 deframer_outsync_frames=5,
                 viterbi_outsync_frames=20,
                 viterbi_sync_check=True,
                 viterbi_sync_threshold=0.1,
                 deframer_sync_check=True,
                 clock_alpha=0.005,
                 symb_rate=293883,
                 pll_alpha=0.005,
                 satellite='GOES-LRIT',
                 freq=1691.02e6,
                 gain=23,
                 decim=108,
                 side="A",
                 frames_file=os.environ['HOME'] +
                 '/GOES-LRIT_cadu_frames.cadu',
                 baseband_file=os.environ['HOME'] + '/GOES-LRIT_baseband.dat'):
        grc_wxgui.top_block_gui.__init__(
            self, title="LRIT Receiver from baseband file")

        ##################################################
        # Parameters
        ##################################################
        self.deframer_insync_frames = deframer_insync_frames
        self.viterbi_insync_frames = viterbi_insync_frames
        self.deframer_outsync_frames = deframer_outsync_frames
        self.viterbi_outsync_frames = viterbi_outsync_frames
        self.viterbi_sync_check = viterbi_sync_check
        self.viterbi_sync_threshold = viterbi_sync_threshold
        self.deframer_sync_check = deframer_sync_check
        self.clock_alpha = clock_alpha
        self.symb_rate = symb_rate
        self.pll_alpha = pll_alpha
        self.satellite = satellite
        self.freq = freq
        self.gain = gain
        self.decim = decim
        self.side = side
        self.frames_file = frames_file
        self.baseband_file = baseband_file

        ##################################################
        # Variables
        ##################################################
        self.decim_tb = decim_tb = decim
        self.symb_rate_tb = symb_rate_tb = symb_rate
        self.samp_rate = samp_rate = 64e6 / decim_tb
        self.viterbi_sync_threshold_text = viterbi_sync_threshold_text = viterbi_sync_threshold
        self.viterbi_sync_after_text = viterbi_sync_after_text = viterbi_insync_frames
        self.viterbi_outofsync_after_text = viterbi_outofsync_after_text = viterbi_outsync_frames
        self.viterbi_node_sync_text = viterbi_node_sync_text = viterbi_sync_check
        self.sps = sps = samp_rate / symb_rate_tb
        self.satellite_text = satellite_text = satellite
        self.samp_rate_st = samp_rate_st = samp_rate
        self.pll_alpha_sl = pll_alpha_sl = pll_alpha
        self.gain_tb = gain_tb = gain
        self.freq_tb = freq_tb = freq
        self.frames_file_text_inf = frames_file_text_inf = frames_file
        self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
        self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
        self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
        self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S",
                                                      localtime())
        self.clock_alpha_sl = clock_alpha_sl = clock_alpha
        self.baseband_file_text_inf = baseband_file_text_inf = 'no output file'

        ##################################################
        # Notebooks
        ##################################################
        self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "USRP Receiver")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb),
                            "PLL demodulator and Clock sync")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Viterbi decoder")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
        self.Add(self.rx_ntb)

        ##################################################
        # Controls
        ##################################################
        self._decim_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.decim_tb,
            callback=self.set_decim_tb,
            label="Decimation",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
        self._symb_rate_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            value=self.symb_rate_tb,
            callback=self.set_symb_rate_tb,
            label="Symbol rate",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
        self._viterbi_sync_threshold_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_sync_threshold_text,
            callback=self.set_viterbi_sync_threshold_text,
            label="Viterbi node sync threshold [BER]",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_sync_threshold_text_static_text, 3, 0, 1, 1)
        self._viterbi_sync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_sync_after_text,
            callback=self.set_viterbi_sync_after_text,
            label="Valid frames for Viterbi decoder sync",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_sync_after_text_static_text, 4, 0, 1, 1)
        self._viterbi_outofsync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_outofsync_after_text,
            callback=self.set_viterbi_outofsync_after_text,
            label="Invalid frames for Viterbi decoder out of sync",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_outofsync_after_text_static_text, 5, 0, 1, 1)
        self._viterbi_node_sync_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_node_sync_text,
            callback=self.set_viterbi_node_sync_text,
            label="Viterbi node sync enable",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_node_sync_text_static_text, 2, 0, 1, 1)
        self._satellite_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.satellite_text,
            callback=self.set_satellite_text,
            label="Sat ",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0,
                                       1, 1)
        self._samp_rate_st_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.samp_rate_st,
            callback=self.set_samp_rate_st,
            label="Sample rate",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1,
                                       1)
        _pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._pll_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            label="PLL Alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._pll_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
        self._gain_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.gain_tb,
            callback=self.set_gain_tb,
            label="RX gain [dB]",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._gain_tb_text_box, 1, 2, 1, 1)
        self._freq_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.freq_tb,
            callback=self.set_freq_tb,
            label="Frequency",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._freq_tb_text_box, 1, 1, 1, 1)
        self._frames_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.frames_file_text_inf,
            callback=self.set_frames_file_text_inf,
            label="Frames filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(self._frames_file_text_inf_static_text,
                                       3, 0, 1, 1)
        self._deframer_sync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_sync_after_text,
            callback=self.set_deframer_sync_after_text,
            label="Deframe sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
        self._deframer_nosync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_nosync_after_text,
            callback=self.set_deframer_nosync_after_text,
            label="Deframer out of sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
        self._deframer_check_sync_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_check_sync_text,
            callback=self.set_deframer_check_sync_text,
            label="Deframer check sync enable",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
        self._datetime_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.datetime_text,
            callback=self.set_datetime_text,
            label="Local time of aquisition start",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(self._datetime_text_static_text, 1, 0,
                                       1, 1)
        _clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._clock_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            label="Clock alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._clock_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
        self._baseband_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.baseband_file_text_inf,
            callback=self.set_baseband_file_text_inf,
            label="Baseband filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(
            self._baseband_file_text_inf_static_text, 4, 0, 1, 1)

        ##################################################
        # Blocks
        ##################################################
        self.fec_decode_viterbi_bpsk_fb_0 = fec.decode_viterbi_bpsk_fb(
            viterbi_sync_check, viterbi_sync_threshold, viterbi_insync_frames,
            viterbi_outsync_frames, viterbi_outsync_frames * 3)
        self.gr_agc_xx_0 = gr.agc_cc(10e-6, 1, 1.0 / 32767.0, 1.0)
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(
            sps, clock_alpha_sl * clock_alpha_sl / 4.0, 0.5, clock_alpha_sl,
            0.05)
        self.gr_complex_to_real_0 = gr.complex_to_real(1)
        self.gr_costas_loop_cc_0 = gr.costas_loop_cc(
            pll_alpha_sl, pll_alpha_sl * pll_alpha_sl / 4.0, 0.07, -0.07, 2)
        self.gr_file_source_0 = gr.file_source(
            gr.sizeof_gr_complex * 1,
            "/home/martin/GNURadioData/lrit/goes_lrit_D108AD64MHz.sam", True)
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((1, ))
        self.gr_null_sink_0 = gr.null_sink(gr.sizeof_char * 1)
        self.gr_packed_to_unpacked_xx_0 = gr.packed_to_unpacked_bb(
            1, gr.GR_MSB_FIRST)
        self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex * 1, samp_rate)
        self.poesweather_metop_cadu_deframer_0 = poesweather.metop_cadu_deframer(
            True, 1024, deframer_insync_frames, deframer_outsync_frames)
        self.root_raised_cosine_filter_0 = gr.fir_filter_ccf(
            1,
            firdes.root_raised_cosine(1, samp_rate, symb_rate, 0.25,
                                      int(11 * samp_rate / symb_rate)))
        self.wxgui_fftsink1 = fftsink2.fft_sink_c(
            self.rx_ntb.GetPage(0).GetWin(),
            baseband_freq=freq,
            y_per_div=2,
            y_divs=10,
            ref_level=12,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="Not filtered spectrum",
            peak_hold=False,
        )
        self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
        self.wxgui_fftsink2 = fftsink2.fft_sink_c(
            self.rx_ntb.GetPage(0).GetWin(),
            baseband_freq=0,
            y_per_div=2,
            y_divs=10,
            ref_level=12,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="RRC filtered spectrum",
            peak_hold=False,
        )
        self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink2.win)
        self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
            self.rx_ntb.GetPage(1).GetWin(),
            title="BPSK constellation diagram",
            sample_rate=symb_rate,
            v_scale=0.4,
            v_offset=0,
            t_scale=1 / samp_rate,
            ac_couple=False,
            xy_mode=True,
            num_inputs=1,
        )
        self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_agc_xx_0, 0),
                     (self.root_raised_cosine_filter_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.gr_complex_to_real_0, 0))
        self.connect((self.fec_decode_viterbi_bpsk_fb_0, 0),
                     (self.gr_packed_to_unpacked_xx_0, 0))
        self.connect((self.gr_packed_to_unpacked_xx_0, 0),
                     (self.poesweather_metop_cadu_deframer_0, 0))
        self.connect((self.gr_complex_to_real_0, 0),
                     (self.fec_decode_viterbi_bpsk_fb_0, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.gr_costas_loop_cc_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.root_raised_cosine_filter_0, 0),
                     (self.gr_costas_loop_cc_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.wxgui_scopesink2_1, 0))
        self.connect((self.root_raised_cosine_filter_0, 0),
                     (self.wxgui_fftsink2, 0))
        self.connect((self.gr_agc_xx_0, 0), (self.wxgui_fftsink1, 0))
        self.connect((self.poesweather_metop_cadu_deframer_0, 0),
                     (self.gr_null_sink_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.gr_agc_xx_0, 0))
        self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0))
Example #52
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")

        #gsm_reciever callback & options & options
        self.tuner_callback = tuner(self)
        self.synchronizer_callback = synchronizer(self)

        (options, args) = self._process_options()
        self.options    = options
        self.args       = args

        ##################################################
        # Variables
        ##################################################
        self.samp_rate_gsm = samp_rate_gsm = 400e3
        self.samp_rate = samp_rate = 8e6
        self.lowpass = lowpass = samp_rate_gsm/2
        self.f_xlate_fine = f_xlate_fine = 0
        self.f_xlate = f_xlate = 0

        ##################################################
        # Blocks
        ##################################################
        #self.freq_text_box = forms.text_box(
        #    parent=self.GetWin(),
        #    value=self.f_xlate,
        #    callback=self.set_f_xlate,
        #    label='Frequency',
        #    converter=forms.float_converter(),
        #    proportion=0,
        #)
        self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c(
            self.GetWin(),
            baseband_freq=0,
            dynamic_range=100,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=512,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title="Waterfall Plot",
        )
        self.Add(self.wxgui_waterfallsink2_0.win)

        self.src = self.source()
        #self.src = self.source( "gsm.cfile")
        self.freq_xlating_fir = filter.freq_xlating_fir_filter_ccc(1, (1, ), f_xlate + f_xlate_fine, samp_rate)
        self.recv_blcks, self.recv = self.gsm_receiver()# self.samp_rate)

        self.low_corase = gr.fir_filter_ccf(int(samp_rate/400e3), firdes.low_pass(1, samp_rate, 200e3, 100000, firdes.WIN_HAMMING, 6.76))

        ##################################################
        # Connections
        ##################################################
        #src
        self.connect((self.src, 0), (self.freq_xlating_fir, 0))

        #freq xlate
        self.connect((self.freq_xlating_fir, 0), (self.wxgui_waterfallsink2_0, 0))

        #filter and recv
        self.connect((self.freq_xlating_fir, 0), (self.low_corase, 0))
        self.connect((self.low_corase, 0), (self.recv, 0))
Example #53
0
    def __init__(self, fft_length, cp_length, logging=False):
        """
        OFDM synchronization using PN Correlation:
        T. M. Schmidl and D. C. Cox, "Robust Frequency and Timing
        Synchonization for OFDM," IEEE Trans. Communications, vol. 45,
        no. 12, 1997.
        """
        
	gr.hier_block2.__init__(self, "ofdm_sync_pn",
				gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
                                gr.io_signature2(2, 2, gr.sizeof_float, gr.sizeof_char)) # Output signature

        self.input = gr.add_const_cc(0)

        # PN Sync

        # Create a delay line
        self.delay = gr.delay(gr.sizeof_gr_complex, fft_length/2)

        # Correlation from ML Sync
        self.conjg = gr.conjugate_cc();
        self.corr = gr.multiply_cc();

        # Create a moving sum filter for the corr output
        if 1:
            moving_sum_taps = [1.0 for i in range(fft_length//2)]
            self.moving_sum_filter = gr.fir_filter_ccf(1,moving_sum_taps)
        else:
            moving_sum_taps = [complex(1.0,0.0) for i in range(fft_length//2)]
            self.moving_sum_filter = gr.fft_filter_ccc(1,moving_sum_taps)

        # Create a moving sum filter for the input
        self.inputmag2 = gr.complex_to_mag_squared()

        # Modified by Yong (12.06.27)
        #movingsum2_taps = [1.0 for i in range(fft_length//2)]
        movingsum2_taps = [0.5 for i in range(fft_length)]

        if 1:
            self.inputmovingsum = gr.fir_filter_fff(1,movingsum2_taps)
        else:
            self.inputmovingsum = gr.fft_filter_fff(1,movingsum2_taps)

        self.square = gr.multiply_ff()
        self.normalize = gr.divide_ff()
     
        # Get magnitude (peaks) and angle (phase/freq error)
        self.c2mag = gr.complex_to_mag_squared()
        self.angle = gr.complex_to_arg()

        self.sample_and_hold = gr.sample_and_hold_ff()

        #ML measurements input to sampler block and detect
        self.sub1 = gr.add_const_ff(-1)
        self.pk_detect = gr.peak_detector_fb(0.20, 0.20, 30, 0.001)
        #self.pk_detect = gr.peak_detector2_fb(9)

        self.connect(self, self.input)
        
        # Calculate the frequency offset from the correlation of the preamble
        self.connect(self.input, self.delay)
        self.connect(self.input, (self.corr,0))
        self.connect(self.delay, self.conjg)
        self.connect(self.conjg, (self.corr,1))
        self.connect(self.corr, self.moving_sum_filter)
        self.connect(self.moving_sum_filter, self.c2mag)
        self.connect(self.moving_sum_filter, self.angle)
        self.connect(self.angle, (self.sample_and_hold,0))

        # Get the power of the input signal to normalize the output of the correlation
        self.connect(self.input, self.inputmag2, self.inputmovingsum)
        self.connect(self.inputmovingsum, (self.square,0))
        self.connect(self.inputmovingsum, (self.square,1))
        self.connect(self.square, (self.normalize,1))
        self.connect(self.c2mag, (self.normalize,0))

        # Create a moving sum filter for the corr output
        matched_filter_taps = [1.0/cp_length for i in range(cp_length)]
        self.matched_filter = gr.fir_filter_fff(1,matched_filter_taps)
        self.connect(self.normalize, self.matched_filter)
        
        self.connect(self.matched_filter, self.sub1, self.pk_detect)
        #self.connect(self.matched_filter, self.pk_detect)
        self.connect(self.pk_detect, (self.sample_and_hold,1))

        # Set output signals
        #    Output 0: fine frequency correction value
        #    Output 1: timing signal
        self.connect(self.sample_and_hold, (self,0))
        self.connect(self.pk_detect, (self,1))

        if logging:
            self.connect(self.matched_filter, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-mf_f.dat"))
            self.connect(self.c2mag, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-nominator_f.dat"))
            self.connect(self.square, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-denominator_f.dat"))
            self.connect(self.normalize, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-theta_f.dat"))
            self.connect(self.angle, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-epsilon_f.dat"))
            self.connect(self.pk_detect, gr.file_sink(gr.sizeof_char, "ofdm_sync_pn-peaks_b.dat"))
            self.connect(self.sample_and_hold, gr.file_sink(gr.sizeof_float, "ofdm_sync_pn-sample_and_hold_f.dat"))
            self.connect(self.input, gr.file_sink(gr.sizeof_gr_complex, "ofdm_sync_pn-input_c.dat"))
Example #54
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-R",
                          "--rx-subdev-spec",
                          type="subdev",
                          default=None,
                          help="select USRP Rx side A or B (default=A)")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=100.1e6,
                          help="set frequency to FREQ",
                          metavar="FREQ")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=65,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-s",
                          "--squelch",
                          type="eng_float",
                          default=0,
                          help="set squelch level (default is 0)")
        parser.add_option("-V",
                          "--volume",
                          type="eng_float",
                          default=None,
                          help="set volume (default is midpoint)")
        parser.add_option(
            "-O",
            "--audio-output",
            type="string",
            default="",
            help="pcm device name.  E.g., hw:0,0 or surround51 or /dev/dsp")

        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        self.frame = frame
        self.panel = panel

        self.vol = 0
        self.state = "FREQ"
        self.freq = 0

        # build graph

        self.u = usrp.source_c()  # usrp is data source

        adc_rate = self.u.adc_rate()  # 64 MS/s
        usrp_decim = 200
        self.u.set_decim_rate(usrp_decim)
        usrp_rate = adc_rate / usrp_decim  #  320 kS/s
        chanfilt_decim = 1
        demod_rate = usrp_rate / chanfilt_decim
        audio_decimation = 10
        audio_rate = 3 * demod_rate / audio_decimation / 2  # 48 kHz

        if options.rx_subdev_spec is None:
            options.rx_subdev_spec = pick_subdevice(self.u)

        self.u.set_mux(
            usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))
        self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)

        chan_filt_coeffs = gr.firdes.low_pass_2(
            1,  # gain
            usrp_rate,  # sampling rate
            90e3,  # passband cutoff
            30e3,  # transition bandwidth
            70,  # stopband attenuation
            gr.firdes.WIN_BLACKMAN)
        print len(chan_filt_coeffs)
        chan_filt = gr.fir_filter_ccf(chanfilt_decim, chan_filt_coeffs)

        self.rchan_sample = blks2.rational_resampler_fff(3, 2)
        self.lchan_sample = blks2.rational_resampler_fff(3, 2)

        #self.guts = blks2.wfm_rcv (demod_rate, audio_decimation)
        self.guts = blks2.wfm_rcv_fmdet(demod_rate, audio_decimation)

        # FIXME rework {add,multiply}_const_* to handle multiple streams
        self.volume_control_l = gr.multiply_const_ff(self.vol)
        self.volume_control_r = gr.multiply_const_ff(self.vol)

        # sound card as final sink
        audio_sink = audio.sink(int(audio_rate), options.audio_output,
                                False)  # ok_to_block

        # now wire it all together
        self.connect(self.u, chan_filt, self.guts)
        self.connect((self.guts, 0), self.lchan_sample, self.volume_control_l,
                     (audio_sink, 0))
        self.connect((self.guts, 1), self.rchan_sample, self.volume_control_r,
                     (audio_sink, 1))

        try:
            self.guts.stereo_carrier_pll_recovery.squelch_enable(True)
        except:
            print "FYI: This implementation of the stereo_carrier_pll_recovery has no squelch implementation yet"

        self._build_gui(vbox, usrp_rate, demod_rate, audio_rate)

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.subdev.gain_range()
            options.gain = float(g[0] + g[1]) / 2

        if options.volume is None:
            g = self.volume_range()
            options.volume = float(g[0] + g[1]) / 2

        if abs(options.freq) < 1e6:
            options.freq *= 1e6

        # set initial values

        self.set_gain(options.gain)
        self.set_vol(options.volume)
        try:
            self.guts.stereo_carrier_pll_recovery.set_lock_threshold(
                options.squelch)
        except:
            print "FYI: This implementation of the stereo_carrier_pll_recovery has no squelch implementation yet"

        if not (self.set_freq(options.freq)):
            self._set_status_msg("Failed to set initial frequency")
Example #55
0
    def __init__(self,frame,panel,vbox,argv):
        stdgui2.std_top_block.__init__ (self,frame,panel,vbox,argv)

        parser = OptionParser(option_class=eng_option)
        parser.add_option("-e", "--interface", type="string", default="eth0",
                          help="select Ethernet interface, default is eth0")
        parser.add_option("-m", "--mac-addr", type="string", default="",
                          help="select USRP by MAC address, default is auto-select")
        #parser.add_option("-A", "--antenna", default=None,
        #                  help="select Rx Antenna (only on RFX-series boards)")
        parser.add_option("-f", "--freq", type="eng_float", default=100.1,
                          help="set frequency to FREQ", metavar="FREQ")
        parser.add_option("-g", "--gain", type="eng_float", default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-V", "--volume", type="eng_float", default=None,
                          help="set volume (default is midpoint)")
        parser.add_option("-O", "--audio-output", type="string", default="",
                          help="pcm device name.  E.g., hw:0,0 or surround51 or /dev/dsp")

        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)
        
        self.frame = frame
        self.panel = panel
        
        self.vol = 0
        self.state = "FREQ"
        self.freq = 0

        # build graph
        
        self.u = usrp2.source_32fc(options.interface, options.mac_addr)

        adc_rate = self.u.adc_rate()                # 100 MS/s
        usrp_decim = 312
        self.u.set_decim(usrp_decim)
        usrp_rate = adc_rate / usrp_decim           # ~320 kS/s
        chanfilt_decim = 1
        demod_rate = usrp_rate / chanfilt_decim
        audio_decimation = 10
        audio_rate = demod_rate / audio_decimation  # ~32 kHz

        #FIXME: need named constants and text descriptions available to (gr-)usrp2 even
        #when usrp(1) module is not built.  A usrp_common module, perhaps?
        dbid = self.u.daughterboard_id()
        print "Using RX d'board 0x%04X" % (dbid,)
        if not (dbid == 0x0001 or #usrp_dbid.BASIC_RX
                dbid == 0x0003 or #usrp_dbid.TV_RX
                dbid == 0x000c or #usrp_dbid.TV_RX_REV_2
                dbid == 0x0040 or #usrp_dbid.TV_RX_REV_3
                dbid == 0x0043 or #usrp_dbid.TV_RX_MIMO
                dbid == 0x0044 or #usrp_dbid.TV_RX_REV_2_MIMO
                dbid == 0x0045 ): #usrp_dbid.TV_RX_REV_3_MIMO
            print "This daughterboard does not cover the required frequency range"
            print "for this application.  Please use a BasicRX or TVRX daughterboard."
            raw_input("Press ENTER to continue anyway, or Ctrl-C to exit.")

        chan_filt_coeffs = optfir.low_pass (1,           # gain
                                            usrp_rate,   # sampling rate
                                            80e3,        # passband cutoff
                                            115e3,       # stopband cutoff
                                            0.1,         # passband ripple
                                            60)          # stopband attenuation
        #print len(chan_filt_coeffs)
        chan_filt = gr.fir_filter_ccf (chanfilt_decim, chan_filt_coeffs)

        self.guts = blks2.wfm_rcv (demod_rate, audio_decimation)

        self.volume_control = gr.multiply_const_ff(self.vol)

        # sound card as final sink
        audio_sink = audio.sink (int (audio_rate),
                                 options.audio_output,
                                 False)  # ok_to_block
        
        # now wire it all together
        self.connect (self.u, chan_filt, self.guts, self.volume_control, audio_sink)

        self._build_gui(vbox, usrp_rate, demod_rate, audio_rate)

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.u.gain_range()
            options.gain = float(g[0]+g[1])/2

        if options.volume is None:
            g = self.volume_range()
            options.volume = float(g[0]+g[1])/2
            
        if abs(options.freq) < 1e6:
            options.freq *= 1e6

        # set initial values

        self.set_gain(options.gain)
        self.set_vol(options.volume)
        if not(self.set_freq(options.freq)):
            self._set_status_msg("Failed to set initial frequency")
Example #56
0
    def __init__(self):
        gr.top_block.__init__(self)

        self.qapp = QtGui.QApplication(sys.argv)

        self._sample_rate = 2000e3

        self.sps = 2
        self.excess_bw = 0.35
        self.gray_code = True
        
        fftsize = 2048

        self.data = scipy.random.randint(0, 255, 1000)
        self.src = gr.vector_source_b(self.data.tolist(), True)
        self.mod = blks2.dqpsk_mod(self.sps, self.excess_bw, self.gray_code, False, False)

        self.rrctaps = gr.firdes.root_raised_cosine(1, self.sps, 1, self.excess_bw, 21)
        self.rx_rrc = gr.fir_filter_ccf(1, self.rrctaps)


        # Set up the carrier & clock recovery parameters
        self.arity = 4
        self.mu = 0.5
        self.gain_mu = 0.05
        self.omega = self.sps
        self.gain_omega = .25 * self.gain_mu * self.gain_mu
        self.omega_rel_lim = 0.05
        
        self.alpha = 0.15
        self.beta  = 0.25 * self.alpha * self.alpha
        self.fmin = -1000/self.sample_rate()
        self.fmax = 1000/self.sample_rate()
        
        self.receiver = gr.mpsk_receiver_cc(self.arity, 0,
                                            self.alpha, self.beta,
                                            self.fmin, self.fmax,
                                            self.mu, self.gain_mu,
                                            self.omega, self.gain_omega,
                                            self.omega_rel_lim)
        
        
        self.snr_dB = 15
        noise = self.get_noise_voltage(self.snr_dB)
        self.fo = 100/self.sample_rate()
        self.to = 1.0
        self.channel = gr.channel_model(noise, self.fo, self.to)

        self.thr = gr.throttle(gr.sizeof_char, self._sample_rate)
        self.snk_tx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS, 
                                   0, self._sample_rate*self.sps,
                                   "Tx", True, True, True, True)

        self.snk_rx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                   0, self._sample_rate,
                                   "Rx", True, True, True, True)

        self.connect(self.src, self.thr, self.mod, self.channel, self.snk_tx)
        self.connect(self.channel, self.rx_rrc, self.receiver, self.snk_rx)
        
        pyTxQt  = self.snk_tx.pyqwidget()
        pyTx = sip.wrapinstance(pyTxQt, QtGui.QWidget)

        pyRxQt  = self.snk_rx.pyqwidget()
        pyRx = sip.wrapinstance(pyRxQt, QtGui.QWidget)

        self.main_box = dialog_box(pyTx, pyRx, self);
        self.main_box.show()
Example #57
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Example bitcpf - FM Rx")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 8e6
        self.rx_gain = rx_gain = 15
        self.lpf_decim = lpf_decim = 20
        self.freq = freq = 106.7e6
        self.audio_samp_rate = audio_samp_rate = 96e3

        ##################################################
        # Blocks
        ##################################################
        _rx_gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._rx_gain_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_rx_gain_sizer,
            value=self.rx_gain,
            callback=self.set_rx_gain,
            label='rx_gain',
            converter=forms.float_converter(),
            proportion=0,
        )
        self._rx_gain_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_rx_gain_sizer,
            value=self.rx_gain,
            callback=self.set_rx_gain,
            minimum=0,
            maximum=30,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_rx_gain_sizer)
        self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(),
                                                        style=wx.NB_TOP)
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "RF")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Audio")
        self.Add(self.notebook_0)
        self._freq_text_box = forms.text_box(
            parent=self.GetWin(),
            value=self.freq,
            callback=self.set_freq,
            label='freq',
            converter=forms.float_converter(),
        )
        self.Add(self._freq_text_box)
        self.wxgui_fftsink2_1 = fftsink2.fft_sink_f(
            self.notebook_0.GetPage(1).GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=samp_rate / lpf_decim,
            fft_size=1024,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title="FFT Plot",
            peak_hold=False,
        )
        self.notebook_0.GetPage(1).Add(self.wxgui_fftsink2_1.win)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
            self.notebook_0.GetPage(0).GetWin(),
            baseband_freq=freq,
            y_per_div=10,
            y_divs=10,
            ref_level=0,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title="FFT Plot",
            peak_hold=False,
        )
        self.notebook_0.GetPage(0).Add(self.wxgui_fftsink2_0.win)
        self.uhd_usrp_source_0 = uhd.usrp_source(
            device_addr="",
            stream_args=uhd.stream_args(
                cpu_format="fc32",
                channels=range(1),
            ),
        )
        self.uhd_usrp_source_0.set_samp_rate(samp_rate)
        self.uhd_usrp_source_0.set_center_freq(freq, 0)
        self.uhd_usrp_source_0.set_gain(rx_gain, 0)
        self.uhd_usrp_source_0.set_antenna("TX/RX", 0)
        self.low_pass_filter_0 = gr.fir_filter_ccf(
            lpf_decim,
            firdes.low_pass(1, samp_rate, 100e3, 10e3, firdes.WIN_HAMMING,
                            6.76))
        self.gr_wavfile_sink_0 = gr.wavfile_sink("fm_record.wav", 1,
                                                 int(audio_samp_rate), 8)
        self.blks2_wfm_rcv_0 = blks2.wfm_rcv(
            quad_rate=samp_rate / lpf_decim,
            audio_decimation=1,
        )
        self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_fff(
            interpolation=96,
            decimation=int(samp_rate / lpf_decim / 1000),
            taps=None,
            fractional_bw=None,
        )
        self.audio_sink_0 = audio.sink(int(audio_samp_rate), "", True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.low_pass_filter_0, 0), (self.blks2_wfm_rcv_0, 0))
        self.connect((self.blks2_wfm_rcv_0, 0),
                     (self.blks2_rational_resampler_xxx_0, 0))
        self.connect((self.blks2_rational_resampler_xxx_0, 0),
                     (self.gr_wavfile_sink_0, 0))
        self.connect((self.blks2_rational_resampler_xxx_0, 0),
                     (self.audio_sink_0, 0))
        self.connect((self.blks2_wfm_rcv_0, 0), (self.wxgui_fftsink2_1, 0))
        self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_0, 0))
        self.connect((self.uhd_usrp_source_0, 0), (self.wxgui_fftsink2_0, 0))
    def __init__(self, fft_length, cp_length, snr, kstime, logging):
        ''' Maximum Likelihood OFDM synchronizer:
        J. van de Beek, M. Sandell, and P. O. Borjesson, "ML Estimation
        of Time and Frequency Offset in OFDM Systems," IEEE Trans.
        Signal Processing, vol. 45, no. 7, pp. 1800-1805, 1997.
        '''

	gr.hier_block2.__init__(self, "ofdm_sync_ml",
				gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
                                gr.io_signature2(2, 2, gr.sizeof_float, gr.sizeof_char)) # Output signature

        self.input = gr.add_const_cc(0)

        SNR = 10.0**(snr/10.0)
        rho = SNR / (SNR + 1.0)
        symbol_length = fft_length + cp_length

        # ML Sync

        # Energy Detection from ML Sync

        self.connect(self, self.input)

        # Create a delay line
        self.delay = gr.delay(gr.sizeof_gr_complex, fft_length)
        self.connect(self.input, self.delay)

        # magnitude squared blocks
        self.magsqrd1 = gr.complex_to_mag_squared()
        self.magsqrd2 = gr.complex_to_mag_squared()
        self.adder = gr.add_ff()

        moving_sum_taps = [rho/2 for i in range(cp_length)]
        self.moving_sum_filter = gr.fir_filter_fff(1,moving_sum_taps)
        
        self.connect(self.input,self.magsqrd1)
        self.connect(self.delay,self.magsqrd2)
        self.connect(self.magsqrd1,(self.adder,0))
        self.connect(self.magsqrd2,(self.adder,1))
        self.connect(self.adder,self.moving_sum_filter)
        

        # Correlation from ML Sync
        self.conjg = gr.conjugate_cc();
        self.mixer = gr.multiply_cc();

        movingsum2_taps = [1.0 for i in range(cp_length)]
        self.movingsum2 = gr.fir_filter_ccf(1,movingsum2_taps)
        
        # Correlator data handler
        self.c2mag = gr.complex_to_mag()
        self.angle = gr.complex_to_arg()
        self.connect(self.input,(self.mixer,1))
        self.connect(self.delay,self.conjg,(self.mixer,0))
        self.connect(self.mixer,self.movingsum2,self.c2mag)
        self.connect(self.movingsum2,self.angle)

        # ML Sync output arg, need to find maximum point of this
        self.diff = gr.sub_ff()
        self.connect(self.c2mag,(self.diff,0))
        self.connect(self.moving_sum_filter,(self.diff,1))

        #ML measurements input to sampler block and detect
        self.f2c = gr.float_to_complex()
        self.pk_detect = gr.peak_detector_fb(0.2, 0.25, 30, 0.0005)
        self.sample_and_hold = gr.sample_and_hold_ff()

        # use the sync loop values to set the sampler and the NCO
        #     self.diff = theta
        #     self.angle = epsilon
                          
        self.connect(self.diff, self.pk_detect)

        # The DPLL corrects for timing differences between CP correlations
        use_dpll = 0
        if use_dpll:
            self.dpll = gr.dpll_bb(float(symbol_length),0.01)
            self.connect(self.pk_detect, self.dpll)
            self.connect(self.dpll, (self.sample_and_hold,1))
        else:
            self.connect(self.pk_detect, (self.sample_and_hold,1))
            
        self.connect(self.angle, (self.sample_and_hold,0))

        ################################
        # correlate against known symbol
        # This gives us the same timing signal as the PN sync block only on the preamble
        # we don't use the signal generated from the CP correlation because we don't want
        # to readjust the timing in the middle of the packet or we ruin the equalizer settings.
        kstime = [k.conjugate() for k in kstime]
        kstime.reverse()
        self.kscorr = gr.fir_filter_ccc(1, kstime)
        self.corrmag = gr.complex_to_mag_squared()
        self.div = gr.divide_ff()

        # The output signature of the correlation has a few spikes because the rest of the
        # system uses the repeated preamble symbol. It needs to work that generically if 
        # anyone wants to use this against a WiMAX-like signal since it, too, repeats.
        # The output theta of the correlator above is multiplied with this correlation to
        # identify the proper peak and remove other products in this cross-correlation
        self.threshold_factor = 0.1
        self.slice = gr.threshold_ff(self.threshold_factor, self.threshold_factor, 0)
        self.f2b = gr.float_to_char()
        self.b2f = gr.char_to_float()
        self.mul = gr.multiply_ff()
        
        # Normalize the power of the corr output by the energy. This is not really needed
        # and could be removed for performance, but it makes for a cleaner signal.
        # if this is removed, the threshold value needs adjustment.
        self.connect(self.input, self.kscorr, self.corrmag, (self.div,0))
        self.connect(self.moving_sum_filter, (self.div,1))
        
        self.connect(self.div, (self.mul,0))
        self.connect(self.pk_detect, self.b2f, (self.mul,1))
        self.connect(self.mul, self.slice)
        
        # Set output signals
        #    Output 0: fine frequency correction value
        #    Output 1: timing signal
        self.connect(self.sample_and_hold, (self,0))
        self.connect(self.slice, self.f2b, (self,1))


        if logging:
            self.connect(self.moving_sum_filter, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-energy_f.dat"))
            self.connect(self.diff, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-theta_f.dat"))
            self.connect(self.angle, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-epsilon_f.dat"))
            self.connect(self.corrmag, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-corrmag_f.dat"))
            self.connect(self.kscorr, gr.file_sink(gr.sizeof_gr_complex, "ofdm_sync_ml-kscorr_c.dat"))
            self.connect(self.div, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-div_f.dat"))
            self.connect(self.mul, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-mul_f.dat"))
            self.connect(self.slice, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-slice_f.dat"))
            self.connect(self.pk_detect, gr.file_sink(gr.sizeof_char, "ofdm_sync_ml-peaks_b.dat"))
            if use_dpll:
                self.connect(self.dpll, gr.file_sink(gr.sizeof_char, "ofdm_sync_ml-dpll_b.dat"))

            self.connect(self.sample_and_hold, gr.file_sink(gr.sizeof_float, "ofdm_sync_ml-sample_and_hold_f.dat"))
            self.connect(self.input, gr.file_sink(gr.sizeof_gr_complex, "ofdm_sync_ml-input_c.dat"))