Example #1
0
    def __init__(self):
        gr.top_block.__init__(self)
        parser = OptionParser(option_class=eng_option)

        parser.add_option("-c", "--calibration", type="int", default=0, help="freq offset")
        parser.add_option("-i", "--input-file", type="string", default="in.dat", help="specify the input file")
        parser.add_option("-l", "--log", action="store_true", default=False, help="dump debug .dat files")
        parser.add_option("-L", "--low-pass", type="eng_float", default=15e3, 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("-s", "--sample-rate", type="int", default=250000, help="input sample rate")
        parser.add_option("-v", "--verbose", action="store_true", default=False, help="dump demodulation data")
        (options, args) = parser.parse_args()
 
        sample_rate = options.sample_rate
        symbol_rate = 4800
        sps = 10
        # output rate will be 48,000
        ntaps = 11 * sps
        new_sample_rate = symbol_rate * sps
        lcm = gru.lcm(sample_rate, new_sample_rate)
        interp = lcm // sample_rate
        decim  = lcm // new_sample_rate

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

        FILTER = gr.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate)

        sys.stderr.write("interp: %d decim: %d\n" %(interp, decim))

        bpf_taps = gr.firdes.low_pass(1.0, sample_rate * interp, options.low_pass, options.low_pass * 0.1, gr.firdes.WIN_HANN)
        INTERPOLATOR = gr.interp_fir_filter_ccf (int(interp), bpf_taps)
        DECIMATOR = blks2.rational_resampler_ccf(1, int(decim))

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

        DEMOD = blks2.cqpsk_demod( samples_per_symbol = sps,
                                 excess_bw=0.35,
                                 costas_alpha=0.03,
                                 gain_mu=0.05,
                                 mu=0.05,
                                 omega_relative_limit=0.05,
                                 log=options.log,
                                 verbose=options.verbose)

        msgq = gr.msg_queue()
        DECODER = fsk4.apco25_f(msgq,0)

        self.connect(IN, FILTER, INTERPOLATOR, DECIMATOR, DEMOD, DECODER)
Example #2
0
    def __init__(self):
        gr.top_block.__init__(self)
        parser = OptionParser(option_class=eng_option)

        parser.add_option("-c",
                          "--calibration",
                          type="int",
                          default=0,
                          help="freq offset")
        parser.add_option("-i",
                          "--input-file",
                          type="string",
                          default="in.dat",
                          help="specify the input file")
        parser.add_option("-l",
                          "--log",
                          action="store_true",
                          default=False,
                          help="dump debug .dat files")
        parser.add_option("-L",
                          "--low-pass",
                          type="eng_float",
                          default=15e3,
                          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("-s",
                          "--sample-rate",
                          type="int",
                          default=250000,
                          help="input sample rate")
        parser.add_option("-v",
                          "--verbose",
                          action="store_true",
                          default=False,
                          help="dump demodulation data")
        (options, args) = parser.parse_args()

        sample_rate = options.sample_rate
        symbol_rate = 4800
        sps = 10
        # output rate will be 48,000
        ntaps = 11 * sps
        new_sample_rate = symbol_rate * sps
        lcm = gru.lcm(sample_rate, new_sample_rate)
        interp = lcm // sample_rate
        decim = lcm // new_sample_rate

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

        FILTER = gr.freq_xlating_fir_filter_ccf(1, channel_taps,
                                                options.calibration,
                                                sample_rate)

        sys.stderr.write("interp: %d decim: %d\n" % (interp, decim))

        bpf_taps = gr.firdes.low_pass(1.0, sample_rate * interp,
                                      options.low_pass, options.low_pass * 0.1,
                                      gr.firdes.WIN_HANN)
        INTERPOLATOR = gr.interp_fir_filter_ccf(int(interp), bpf_taps)
        DECIMATOR = blks2.rational_resampler_ccf(1, int(decim))

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

        DEMOD = blks2.cqpsk_demod(samples_per_symbol=sps,
                                  excess_bw=0.35,
                                  costas_alpha=0.03,
                                  gain_mu=0.05,
                                  mu=0.05,
                                  omega_relative_limit=0.05,
                                  log=options.log,
                                  verbose=options.verbose)

        msgq = gr.msg_queue()
        DECODER = fsk4.apco25_f(msgq, 0)

        self.connect(IN, FILTER, INTERPOLATOR, DECIMATOR, DEMOD, DECODER)
    def __init__(self, options, queue):
        gr.top_block.__init__(self, "usrp_flex")
        self.options = options
	self.offset = 0.0
	self.file_offset = 0.0
	self.adj_time = time.time()
	self.verbose = options.verbose
			
	if options.from_file is None:
        
        
        self.rtlsdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + '' )
        self.rtlsdr_source_0.set_sample_rate(samp_rate)
        self.rtlsdr_source_0.set_center_freq(options.frequency, 0)
        self.rtlsdr_source_0.set_freq_corr(0, 0)
        self.rtlsdr_source_0.set_dc_offset_mode(0, 0)
        self.rtlsdr_source_0.set_iq_balance_mode(0, 0)
        self.rtlsdr_source_0.set_gain_mode(True, 0)
        self.rtlsdr_source_0.set_gain(50, 0)
        self.rtlsdr_source_0.set_if_gain(20, 0)
        self.rtlsdr_source_0.set_bb_gain(20, 0)
        self.rtlsdr_source_0.set_antenna('', 0)
        self.rtlsdr_source_0.set_bandwidth(0, 0)


                    
        else:
            # Use supplied file as source of samples
	    self.file_offset = options.calibration
            print "File input offset", self.offset
            self.src = gr.file_source(gr.sizeof_gr_complex, options.from_file)
            if options.verbose:
                print "Reading samples from", options.from_file
	    
        if options.log and not options.from_file:
            usrp_sink = gr.file_sink(gr.sizeof_gr_complex, 'usrp.dat')
            self.connect(self.src, usrp_sink)

        # following is rig to allow fast and easy swapping of signal configuration
        # blocks between this example and the oscope example which uses self.msgq
	self.msgq = queue


        #-------------------------------------------------------------------------------


        if options.protocol == 0:

  	  # ---------- RD-LAP 19.2 kbps (9600 ksps), 25kHz channel, 
          self.symbol_rate = 9600				# symbol rate; at 2 bits/symbol this corresponds to 19.2kbps
 	  self.channel_decimation = 10				# decimation (final rate should be at least several symbol rate)
	  self.max_frequency_offset = 12000.0			# coarse carrier tracker leash, ~ half a channel either way
	  self.symbol_deviation = 1200.0			# this is frequency offset from center of channel to +1 / -1 symbols
          self.input_sample_rate = 64e6 / options.decim		# for USRP: 64MHz / FPGA decimation rate	
	  self.protocol_processing = fsk4.rdlap_f(self.msgq, 0)	# desired protocol processing block selected here

          self.channel_rate = self.input_sample_rate / self.channel_decimation

          # channel selection filter characteristics
          channel_taps = optfir.low_pass(1.0,   # Filter gain
                               self.input_sample_rate, # Sample rate
                               10000, # One-sided modulation bandwidth
                               12000, # One-sided channel bandwidth
                               0.1,   # Passband ripple
                               60)    # Stopband attenuation

	  # symbol shaping filter characteristics
          symbol_coeffs = gr.firdes.root_raised_cosine (1.0,            	# gain
                                          self.channel_rate ,       	# sampling rate
                                          self.symbol_rate,             # symbol rate
                                          0.2,                		# width of trans. band
                                          500) 				# filter type 


        if options.protocol == 1:

	  # ---------- APCO-25 C4FM Test Data
          self.symbol_rate = 4800					# symbol rate; at 2 bits/symbol this corresponds to 19.2kbps
	  self.channel_decimation = 20				# decimation
	  self.max_frequency_offset = 6000.0			# coarse carrier tracker leash 
	  self.symbol_deviation = 600.0				# this is frequency offset from center of channel to +1 / -1 symbols
          self.input_sample_rate = 64e6 / options.decim		# for USRP: 64MHz / FPGA decimation rate	
	  self.protocol_processing = fsk4.apco25_f(self.msgq, 0)
          self.channel_rate = self.input_sample_rate / self.channel_decimation


          # channel selection filter
          channel_taps = optfir.low_pass(1.0,   # Filter gain
                               self.input_sample_rate, # Sample rate
                               5000, # One-sided modulation bandwidth
                               6500, # One-sided channel bandwidth
                               0.1,   # Passband ripple
                               60)    # Stopband attenuation

	  # symbol shaping filter
          symbol_coeffs = gr.firdes.root_raised_cosine (1.0,            	# gain
                                          self.channel_rate ,       	# sampling rate
                                          self.symbol_rate,             # symbol rate
                                          0.2,                		# width of trans. band
                                          500) 				# filter type 



        # ---------- End of configuration 

	
	if options.verbose:
	    print "Channel filter has", len(channel_taps), "taps."


        self.chan = gr.freq_xlating_fir_filter_ccf(self.channel_decimation ,    # Decimation rate
                                              channel_taps,  # Filter taps
                                              0.0,   # Offset frequency
                                              self.input_sample_rate) # Sample rate


	# also note: 
        # this specifies the nominal frequency deviation for the 4-level fsk signal
	self.fm_demod_gain = self.channel_rate / (2.0 * pi * self.symbol_deviation)
        self.fm_demod = gr.quadrature_demod_cf (self.fm_demod_gain)
        symbol_decim = 1
        self.symbol_filter = gr.fir_filter_fff (symbol_decim, symbol_coeffs)

        # eventually specify: sample rate, symbol rate
        self.demod_fsk4 = fsk4.demod_ff(self.msgq, self.channel_rate , self.symbol_rate)


	if options.log:
	    chan_sink = gr.file_sink(gr.sizeof_gr_complex, 'chan.dat')
	    self.connect(self.chan, chan_sink)


        if options.log:
          chan_sink2 = gr.file_sink(gr.sizeof_float, 'demod.dat')
          self.connect(self.demod_fsk4, chan_sink2)

	self.connect(self.src, self.chan, self.fm_demod, self.symbol_filter, self.demod_fsk4, self.protocol_processing)
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        self.frame = frame
        self.panel = panel

        self.offset = 0.0

        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=first one with a daughterboard)"
        )
        parser.add_option(
            "-d",
            "--decim",
            type="int",
            default=256,
            help="set fgpa decimation rate to DECIM [default=%default]")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=None,
                          help="set frequency to FREQ",
                          metavar="FREQ")
        parser.add_option(
            "-p",
            "--protocol",
            type="int",
            default=0,
            help="set protocol: 0 = RDLAP 19.2kbps (default); 1 = APCO25")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option("-8",
                          "--width-8",
                          action="store_true",
                          default=False,
                          help="Enable 8-bit samples across USB")
        parser.add_option("--no-hb",
                          action="store_true",
                          default=False,
                          help="don't use halfband filter in usrp")
        parser.add_option(
            "-C",
            "--basic-complex",
            action="store_true",
            default=False,
            help=
            "Use both inputs of a basicRX or LFRX as a single Complex input channel"
        )
        parser.add_option(
            "-D",
            "--basic-dualchan",
            action="store_true",
            default=False,
            help=
            "Use both inputs of a basicRX or LFRX as seperate Real input channels"
        )
        parser.add_option(
            "-n",
            "--frame-decim",
            type="int",
            default=1,
            help="set oscope frame decimation factor to n [default=1]")
        parser.add_option(
            "-v",
            "--v-scale",
            type="eng_float",
            default=1000,
            help="set oscope initial V/div to SCALE [default=%default]")
        parser.add_option(
            "-t",
            "--t-scale",
            type="eng_float",
            default=49e-6,
            help="set oscope initial s/div to SCALE [default=50us]")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        self.show_debug_info = True

        # build the graph
        if options.basic_dualchan:
            self.num_inputs = 2
        else:
            self.num_inputs = 1
        if options.no_hb or (options.decim < 8):
            #Min decimation of this firmware is 4.
            #contains 4 Rx paths without halfbands and 0 tx paths.
            self.fpga_filename = "std_4rx_0tx.rbf"
            self.u = usrp.source_c(nchan=self.num_inputs,
                                   decim_rate=options.decim,
                                   fpga_filename=self.fpga_filename)
        else:
            #Min decimation of standard firmware is 8.
            #standard fpga firmware "std_2rxhb_2tx.rbf"
            #contains 2 Rx paths with halfband filters and 2 tx paths (the default)
            self.u = usrp.source_c(nchan=self.num_inputs,
                                   decim_rate=options.decim)

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

        if options.width_8:
            width = 8
            shift = 8
            format = self.u.make_format(width, shift)
            #print "format =", hex(format)
            r = self.u.set_format(format)
            #print "set_format =", r

        # determine the daughterboard subdevice we're using
        self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
        if (options.basic_complex or options.basic_dualchan):
            if ((self.subdev.dbid() == usrp_dbid.BASIC_RX)
                    or (self.subdev.dbid() == usrp_dbid.LF_RX)):
                side = options.rx_subdev_spec[0]  # side A = 0, side B = 1
                if options.basic_complex:
                    #force Basic_RX and LF_RX in complex mode (use both I and Q channel)
                    print "Receiver daughterboard forced in complex mode. Both inputs will combined to form a single complex channel."
                    self.dualchan = False
                    if side == 0:
                        self.u.set_mux(
                            0x00000010
                        )  #enable adc 0 and 1 to form a single complex input on side A
                    else:  #side ==1
                        self.u.set_mux(
                            0x00000032
                        )  #enable adc 3 and 2 to form a single complex input on side B
                elif options.basic_dualchan:
                    #force Basic_RX and LF_RX in dualchan mode (use input A  for channel 0 and input B for channel 1)
                    print "Receiver daughterboard forced in dualchannel mode. Each input will be used to form a seperate channel."
                    self.dualchan = True
                    if side == 0:
                        self.u.set_mux(
                            gru.hexint(0xf0f0f1f0)
                        )  #enable adc 0, side A to form a real input on channel 0 and adc1,side A to form a real input on channel 1
                    else:  #side ==1
                        self.u.set_mux(
                            0xf0f0f3f2
                        )  #enable adc 2, side B to form a real input on channel 0 and adc3,side B to form a real input on channel 1
            else:
                sys.stderr.write(
                    'options basic_dualchan or basic_complex is only supported for Basic Rx or LFRX at the moment\n'
                )
                sys.exit(1)
        else:
            self.dualchan = False
            self.u.set_mux(
                usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))

        input_rate = self.u.adc_freq() / self.u.decim_rate()

        self.scope = scopesink2.scope_sink_c(panel,
                                             sample_rate=input_rate,
                                             frame_decim=options.frame_decim,
                                             v_scale=options.v_scale,
                                             t_scale=options.t_scale,
                                             num_inputs=self.num_inputs)

        if self.dualchan:
            # deinterleave two channels from FPGA
            self.di = gr.deinterleave(gr.sizeof_gr_complex)
            self.connect(self.u, self.di)
            self.connect((self.di, 0), (self.scope, 0))
            self.connect((self.di, 1), (self.scope, 1))
        else:
            self.connect(self.u, self.scope)

        self.msgq = gr.msg_queue(2)  # queue that holds a maximum of 2 messages
        self.queue_watcher = queue_watcher(self.msgq, self.adjust_freq_norm)

        #-------------------------------------------------------------------------------

        if options.protocol == 0:

            # ---------- RD-LAP 19.2 kbps (9600 ksps), 25kHz channel,
            self.symbol_rate = 9600  # symbol rate; at 2 bits/symbol this corresponds to 19.2kbps
            self.channel_decimation = 10  # decimation (final rate should be at least several symbol rate)
            self.max_frequency_offset = 12000.0  # coarse carrier tracker leash, ~ half a channel either way
            self.symbol_deviation = 1200.0  # this is frequency offset from center of channel to +1 / -1 symbols
            self.input_sample_rate = 64e6 / options.decim  # for USRP: 64MHz / FPGA decimation rate
            self.protocol_processing = fsk4.rdlap_f(
                self.msgq,
                0)  # desired protocol processing block selected here

            self.channel_rate = self.input_sample_rate / self.channel_decimation

            # channel selection filter characteristics
            channel_taps = optfir.low_pass(
                1.0,  # Filter gain
                self.input_sample_rate,  # Sample rate
                10000,  # One-sided modulation bandwidth
                12000,  # One-sided channel bandwidth
                0.1,  # Passband ripple
                60)  # Stopband attenuation

            # symbol shaping filter characteristics
            symbol_coeffs = gr.firdes.root_raised_cosine(
                1.0,  # gain
                self.channel_rate,  # sampling rate
                self.symbol_rate,  # symbol rate
                0.2,  # width of trans. band
                500)  # filter type

        if options.protocol == 1:

            # ---------- APCO-25 C4FM Test Data
            self.symbol_rate = 4800  # symbol rate; at 2 bits/symbol this corresponds to 19.2kbps
            self.channel_decimation = 20  # decimation
            self.max_frequency_offset = 6000.0  # coarse carrier tracker leash
            self.symbol_deviation = 600.0  # this is frequency offset from center of channel to +1 / -1 symbols
            self.input_sample_rate = 64e6 / options.decim  # for USRP: 64MHz / FPGA decimation rate
            self.protocol_processing = fsk4.apco25_f(self.msgq, 0)
            self.channel_rate = self.input_sample_rate / self.channel_decimation

            # channel selection filter
            channel_taps = optfir.low_pass(
                1.0,  # Filter gain
                self.input_sample_rate,  # Sample rate
                5000,  # One-sided modulation bandwidth
                6500,  # One-sided channel bandwidth
                0.1,  # Passband ripple
                60)  # Stopband attenuation

            # symbol shaping filter
            symbol_coeffs = gr.firdes.root_raised_cosine(
                1.0,  # gain
                self.channel_rate,  # sampling rate
                self.symbol_rate,  # symbol rate
                0.2,  # width of trans. band
                500)  # filter type

        # ----------------- End of setup block

        self.chan = gr.freq_xlating_fir_filter_ccf(
            self.channel_decimation,  # Decimation rate
            channel_taps,  # Filter taps
            0.0,  # Offset frequency
            self.input_sample_rate)  # Sample rate

        self.scope2 = scopesink2.scope_sink_f(panel,
                                              sample_rate=self.symbol_rate,
                                              frame_decim=1,
                                              v_scale=2,
                                              t_scale=0.025,
                                              num_inputs=self.num_inputs)

        # also note:
        # this specifies the nominal frequency deviation for the 4-level fsk signal
        self.fm_demod_gain = self.channel_rate / (2.0 * pi *
                                                  self.symbol_deviation)
        self.fm_demod = gr.quadrature_demod_cf(self.fm_demod_gain)
        symbol_decim = 1
        self.symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)

        # eventually specify: sample rate, symbol rate
        self.demod_fsk4 = fsk4.demod_ff(self.msgq, self.channel_rate,
                                        self.symbol_rate)

        #self.rdlap_processing = fsk4.rdlap_f(self.msgq, 0)

        self.connect(self.u, self.chan, self.fm_demod, self.symbol_filter,
                     self.demod_fsk4, self.protocol_processing)

        self.connect(self.demod_fsk4, self.scope2)

        # --------------- End of most of the 4L-FSK hack & slash

        self._build_gui(vbox)

        # set initial values

        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.freq is None:
            if ((self.subdev.dbid() == usrp_dbid.BASIC_RX)
                    or (self.subdev.dbid() == usrp_dbid.LF_RX)):
                #for Basic RX and LFRX if no freq is specified you probably want 0.0 Hz and not 45 GHz
                options.freq = 0.0
            else:
                # if no freq was specified, use the mid-point
                r = self.subdev.freq_range()
                options.freq = float(r[0] + r[1]) / 2

        self.set_gain(options.gain)

        if self.show_debug_info:
            #            self.myform['decim'].set_value(self.u.decim_rate())
            self.myform['fs@usb'].set_value(self.u.adc_freq() /
                                            self.u.decim_rate())
            self.myform['dbname'].set_value(self.subdev.name())
            self.myform['baseband'].set_value(0)
            self.myform['ddc'].set_value(0)
            if self.num_inputs == 2:
                self.myform['baseband2'].set_value(0)
                self.myform['ddc2'].set_value(0)

        if not (self.set_freq(options.freq)):
            self._set_status_msg("Failed to set initial frequency")
        if self.num_inputs == 2:
            if not (self.set_freq2(options.freq)):
                self._set_status_msg(
                    "Failed to set initial frequency for channel 2")
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        self.frame = frame
        self.panel = panel

        self.offset = 0.0

        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=first one with a daughterboard)"
        )
        parser.add_option(
            "-d",
            "--decim",
            type="int",
            default=1,
            help="set fgpa decimation rate to DECIM [default=%default]")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=None,
                          help="set frequency to FREQ",
                          metavar="FREQ")
        parser.add_option(
            "-p",
            "--protocol",
            type="int",
            default=0,
            help="set protocol: 0 = RDLAP 19.2kbps (default); 1 = APCO25")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=1,
                          help="set gain multiplier")
        parser.add_option("-8",
                          "--width-8",
                          action="store_true",
                          default=False,
                          help="Enable 8-bit samples across USB")
        parser.add_option("--no-hb",
                          action="store_true",
                          default=False,
                          help="don't use halfband filter in usrp")
        parser.add_option(
            "-C",
            "--basic-complex",
            action="store_true",
            default=False,
            help=
            "Use both inputs of a basicRX or LFRX as a single Complex input channel"
        )
        parser.add_option(
            "-D",
            "--basic-dualchan",
            action="store_true",
            default=False,
            help=
            "Use both inputs of a basicRX or LFRX as seperate Real input channels"
        )
        parser.add_option(
            "-n",
            "--frame-decim",
            type="int",
            default=1,
            help="set oscope frame decimation factor to n [default=1]")
        parser.add_option(
            "-I",
            "--audio-input",
            type="string",
            default="",
            help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
        parser.add_option("-s",
                          "--sample-rate",
                          type="int",
                          default=48000,
                          help="sound card input sample rate")
        parser.add_option(
            "-v",
            "--v-scale",
            type="eng_float",
            default=1000,
            help="set oscope initial V/div to SCALE [default=%default]")
        parser.add_option(
            "-t",
            "--t-scale",
            type="eng_float",
            default=49e-6,
            help="set oscope initial s/div to SCALE [default=50us]")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        self.show_debug_info = True

        # build the graph
        self.num_inputs = 1

        self.msgq = gr.msg_queue(2)  # queue that holds a maximum of 2 messages

        if options.protocol == 0:

            # ---------- RD-LAP 19.2 kbps (9600 ksps), 25kHz channel,
            self.symbol_rate = 9600  # symbol rate; at 2 bits/symbol this corresponds to 19.2kbps
            self.channel_decimation = 1  # decimation (final rate should be at least several symbol rate)
            self.input_sample_rate = options.sample_rate / options.decim  # for USRP: 64MHz / FPGA decimation rate
            self.protocol_processing = fsk4.rdlap_f(
                self.msgq,
                0)  # desired protocol processing block selected here

            self.channel_rate = self.input_sample_rate / self.channel_decimation

            # symbol shaping filter characteristics
            symbol_coeffs = gr.firdes.root_raised_cosine(
                1.0,  # gain
                self.channel_rate,  # sampling rate
                self.symbol_rate,  # symbol rate
                0.2,  # width of trans. band
                500)  # filter type

        if options.protocol == 1:

            # ---------- APCO-25 C4FM Test Data
            self.symbol_rate = 4800  # symbol rate; at 2 bits/symbol this corresponds to 19.2kbps
            self.channel_decimation = 1  # decimation
            self.input_sample_rate = options.sample_rate / options.decim  # for USRP: 64MHz / FPGA decimation rate
            self.protocol_processing = fsk4.apco25_f(self.msgq, 0)
            self.channel_rate = self.input_sample_rate / self.channel_decimation

            # symbol shaping filter
            symbol_coeffs = gr.firdes.root_raised_cosine(
                1.0,  # gain
                self.channel_rate,  # sampling rate
                self.symbol_rate,  # symbol rate
                0.2,  # width of trans. band
                500)  # filter type

        # ----------------- End of setup block

        self.audio_input = audio.source(options.sample_rate,
                                        options.audio_input)
        self.audio_gain = gr.multiply_const_ff(options.gain)

        self.scope2 = scopesink2.scope_sink_f(panel,
                                              sample_rate=self.symbol_rate,
                                              frame_decim=1,
                                              v_scale=2,
                                              t_scale=0.025,
                                              num_inputs=self.num_inputs)

        # also note:
        # this specifies the nominal frequency deviation for the 4-level fsk signal
        symbol_decim = 1
        self.symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)

        # eventually specify: sample rate, symbol rate
        self.demod_fsk4 = fsk4.demod_ff(self.msgq, self.channel_rate,
                                        self.symbol_rate)

        #self.rdlap_processing = fsk4.rdlap_f(self.msgq, 0)

        self.connect(self.audio_input, self.audio_gain, self.symbol_filter,
                     self.demod_fsk4, self.protocol_processing)

        self.connect(self.demod_fsk4, self.scope2)

        # --------------- End of most of the 4L-FSK hack & slash

        self._build_gui(vbox)

        # set initial values

        self.set_gain(options.gain)

        if self.show_debug_info:
            #            self.myform['decim'].set_value(self.u.decim_rate())
            self.myform['dbname'].set_value("alsa")
            self.myform['baseband'].set_value(0)
            self.myform['ddc'].set_value(0)
            if self.num_inputs == 2:
                self.myform['baseband2'].set_value(0)
                self.myform['ddc2'].set_value(0)
Example #6
0
    def __init__(self, options, queue):
        gr.top_block.__init__(self, "usrp_flex")
        self.options = options
        self.offset = 0.0
        self.file_offset = 0.0
        self.adj_time = time.time()
        self.verbose = options.verbose

        if options.from_file is None:
            # Set up USRP source with specified RX daughterboard
            self.src = usrp.source_c()
            if options.rx_subdev_spec == None:
                options.rx_subdev_spec = usrp.pick_rx_subdevice(self.src)
            self.subdev = usrp.selected_subdev(self.src,
                                               options.rx_subdev_spec)
            self.src.set_mux(
                usrp.determine_rx_mux_value(self.src, options.rx_subdev_spec))

            # set FPGA decimation rate
            self.src.set_decim_rate(options.decim)

            # If no gain specified, set to midrange
            if options.gain is None:
                g = self.subdev.gain_range()
                options.gain = (g[0] + g[1]) / 2.0
            self.subdev.set_gain(options.gain)

            # Tune daughterboard
            actual_frequency = options.frequency + options.calibration
            tune_result = usrp.tune(self.src, 0, self.subdev, actual_frequency)
            if not tune_result:
                sys.stderr.write("Failed to set center frequency to " +
                                 ` actual_frequency ` + "\n")
                sys.exit(1)

            if options.verbose:
                print "Using RX daughterboard", self.subdev.side_and_name()
                print "USRP gain is", options.gain
                print "USRP tuned to", actual_frequency

        else:
            # Use supplied file as source of samples
            self.file_offset = options.calibration
            print "File input offset", self.offset
            self.src = gr.file_source(gr.sizeof_gr_complex, options.from_file)
            if options.verbose:
                print "Reading samples from", options.from_file

        if options.log and not options.from_file:
            usrp_sink = gr.file_sink(gr.sizeof_gr_complex, 'usrp.dat')
            self.connect(self.src, usrp_sink)

        # following is rig to allow fast and easy swapping of signal configuration
        # blocks between this example and the oscope example which uses self.msgq
        self.msgq = queue

        #-------------------------------------------------------------------------------

        if options.protocol == 0:

            # ---------- RD-LAP 19.2 kbps (9600 ksps), 25kHz channel,
            self.symbol_rate = 9600  # symbol rate; at 2 bits/symbol this corresponds to 19.2kbps
            self.channel_decimation = 10  # decimation (final rate should be at least several symbol rate)
            self.max_frequency_offset = 12000.0  # coarse carrier tracker leash, ~ half a channel either way
            self.symbol_deviation = 1200.0  # this is frequency offset from center of channel to +1 / -1 symbols
            self.input_sample_rate = 64e6 / options.decim  # for USRP: 64MHz / FPGA decimation rate
            self.protocol_processing = fsk4.rdlap_f(
                self.msgq,
                0)  # desired protocol processing block selected here

            self.channel_rate = self.input_sample_rate / self.channel_decimation

            # channel selection filter characteristics
            channel_taps = optfir.low_pass(
                1.0,  # Filter gain
                self.input_sample_rate,  # Sample rate
                10000,  # One-sided modulation bandwidth
                12000,  # One-sided channel bandwidth
                0.1,  # Passband ripple
                60)  # Stopband attenuation

            # symbol shaping filter characteristics
            symbol_coeffs = gr.firdes.root_raised_cosine(
                1.0,  # gain
                self.channel_rate,  # sampling rate
                self.symbol_rate,  # symbol rate
                0.2,  # width of trans. band
                500)  # filter type

        if options.protocol == 1:

            # ---------- APCO-25 C4FM Test Data
            self.symbol_rate = 4800  # symbol rate; at 2 bits/symbol this corresponds to 19.2kbps
            self.channel_decimation = 20  # decimation
            self.max_frequency_offset = 6000.0  # coarse carrier tracker leash
            self.symbol_deviation = 600.0  # this is frequency offset from center of channel to +1 / -1 symbols
            self.input_sample_rate = 64e6 / options.decim  # for USRP: 64MHz / FPGA decimation rate
            self.protocol_processing = fsk4.apco25_f(self.msgq, 0)
            self.channel_rate = self.input_sample_rate / self.channel_decimation

            # channel selection filter
            channel_taps = optfir.low_pass(
                1.0,  # Filter gain
                self.input_sample_rate,  # Sample rate
                5000,  # One-sided modulation bandwidth
                6500,  # One-sided channel bandwidth
                0.1,  # Passband ripple
                60)  # Stopband attenuation

            # symbol shaping filter
            symbol_coeffs = gr.firdes.root_raised_cosine(
                1.0,  # gain
                self.channel_rate,  # sampling rate
                self.symbol_rate,  # symbol rate
                0.2,  # width of trans. band
                500)  # filter type

        # ---------- End of configuration

        if options.verbose:
            print "Channel filter has", len(channel_taps), "taps."

        self.chan = gr.freq_xlating_fir_filter_ccf(
            self.channel_decimation,  # Decimation rate
            channel_taps,  # Filter taps
            0.0,  # Offset frequency
            self.input_sample_rate)  # Sample rate

        # also note:
        # this specifies the nominal frequency deviation for the 4-level fsk signal
        self.fm_demod_gain = self.channel_rate / (2.0 * pi *
                                                  self.symbol_deviation)
        self.fm_demod = gr.quadrature_demod_cf(self.fm_demod_gain)
        symbol_decim = 1
        self.symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)

        # eventually specify: sample rate, symbol rate
        self.demod_fsk4 = fsk4.demod_ff(self.msgq, self.channel_rate,
                                        self.symbol_rate)

        if options.log:
            chan_sink = gr.file_sink(gr.sizeof_gr_complex, 'chan.dat')
            self.connect(self.chan, chan_sink)

        if options.log:
            chan_sink2 = gr.file_sink(gr.sizeof_float, 'demod.dat')
            self.connect(self.demod_fsk4, chan_sink2)

        self.connect(self.src, self.chan, self.fm_demod, self.symbol_filter,
                     self.demod_fsk4, self.protocol_processing)
Example #7
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        self.frame = frame
        self.panel = panel

        self.offset = 0.0  # Channel frequency offset

        parser = OptionParser(option_class=eng_option)

        parser.add_option(
            "-p",
            "--protocol",
            type="int",
            default=1,
            help="set protocol: 0 = RDLAP 19.2kbps; 1 = APCO25 (default)")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=1.0,
                          help="set linear input gain (default: %default)")
        parser.add_option("-x",
                          "--freq-translation",
                          type="eng_float",
                          default=0.0,
                          help="initial channel frequency translation")

        parser.add_option(
            "-n",
            "--frame-decim",
            type="int",
            default=1,
            help="set oscope frame decimation factor to n [default=1]")
        parser.add_option(
            "-v",
            "--v-scale",
            type="eng_float",
            default=5000,
            help="set oscope initial V/div to SCALE [default=%default]")
        parser.add_option(
            "-t",
            "--t-scale",
            type="eng_float",
            default=49e-6,
            help="set oscope initial s/div to SCALE [default=50us]")

        parser.add_option(
            "-I",
            "--audio-input",
            type="string",
            default="",
            help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
        parser.add_option("-r",
                          "--sample-rate",
                          type="eng_float",
                          default=48000,
                          help="set sample rate to RATE (default: %default)")

        parser.add_option(
            "-d",
            "--channel-decim",
            type="int",
            default=None,
            help=
            "set channel decimation factor to n [default depends on protocol]")

        parser.add_option("-w",
                          "--wav-file",
                          type="string",
                          default=None,
                          help="WAV input path")
        parser.add_option("-f",
                          "--data-file",
                          type="string",
                          default=None,
                          help="Data input path")
        parser.add_option("-B",
                          "--base-band",
                          action="store_true",
                          default=False)
        parser.add_option("-R", "--repeat", action="store_true", default=False)

        parser.add_option("-o",
                          "--wav-out",
                          type="string",
                          default=None,
                          help="WAV output path")
        parser.add_option("-G",
                          "--wav-out-gain",
                          type="eng_float",
                          default=0.05,
                          help="set WAV output gain (default: %default)")

        parser.add_option("-F",
                          "--data-out",
                          type="string",
                          default=None,
                          help="Data output path")

        parser.add_option("-C",
                          "--carrier-freq",
                          type="eng_float",
                          default=None,
                          help="set data output carrier frequency to FREQ",
                          metavar="FREQ")

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

        self.options = options

        if options.wav_file is not None:
            #try:
            self.input_file = gr.wavfile_source(options.wav_file,
                                                options.repeat)
            #except:
            #    print "WAV file not found or not a WAV file"
            #    sys.exit(1)

            print "WAV input: %i Hz, %i bits, %i channels" % (
                self.input_file.sample_rate(),
                self.input_file.bits_per_sample(), self.input_file.channels())

            self.sample_rate = self.input_file.sample_rate()
            self.input_stream = gr.throttle(gr.sizeof_float, self.sample_rate)
            self.connect(self.input_file, self.input_stream)
            self.src = gr.multiply_const_ff(options.gain)
        elif options.data_file is not None:
            if options.base_band:
                sample_size = gr.sizeof_float
                print "Data file is baseband (float)"
                self.src = gr.multiply_const_ff(options.gain)
            else:
                sample_size = gr.sizeof_gr_complex
                print "Data file is IF (complex)"
                self.src = gr.multiply_const_cc(options.gain)

            self.input_file = gr.file_source(sample_size, options.data_file,
                                             options.repeat)
            self.sample_rate = options.sample_rate  # E.g. 250000

            print "Data file sampling rate = " + str(self.sample_rate)

            self.input_stream = gr.throttle(sample_size, self.sample_rate)
            self.connect(self.input_file, self.input_stream)
        else:
            self.sample_rate = options.sample_rate
            print "Soundcard sampling rate = " + str(self.sample_rate)
            self.input_stream = audio.source(
                self.sample_rate, options.audio_input)  # float samples
            self.src = gr.multiply_const_ff(options.gain)

        print "Fixed input gain = " + str(options.gain)
        self.connect(self.input_stream, self.src)

        if options.wav_out is not None:
            output_rate = int(self.sample_rate)
            if options.channel_decim is not None:
                output_rate /= options.channel_decim
            self.wav_out = gr.wavfile_sink(options.wav_out, 1, output_rate, 16)
            print "Opened WAV output file: " + options.wav_out + " at rate: " + str(
                output_rate)
        else:
            self.wav_out = None

        if options.data_out is not None:
            if options.carrier_freq is None:
                self.data_out = gr.file_sink(gr.sizeof_float, options.data_out)
                print "Opened float data output file: " + options.data_out
            else:
                self.data_out = gr.file_sink(gr.sizeof_gr_complex,
                                             options.data_out)
                print "Opened complex data output file: " + options.data_out
        else:
            self.data_out = None

        self.num_inputs = 1

        input_rate = self.sample_rate
        #title='IF',
        #size=(1024,800),
        if (options.data_file is not None) and (options.base_band == False):
            self.scope = scopesink2.scope_sink_c(
                panel,
                sample_rate=input_rate,
                frame_decim=options.frame_decim,
                v_scale=options.v_scale,
                t_scale=options.t_scale,
                num_inputs=self.num_inputs)
        else:
            self.scope = scopesink2.scope_sink_f(
                panel,
                sample_rate=input_rate,
                frame_decim=options.frame_decim,
                v_scale=options.v_scale,
                t_scale=options.t_scale,
                num_inputs=self.num_inputs)

        #self.di = gr.deinterleave(gr.sizeof_float)
        #self.di = gr.complex_to_float(1)
        #self.di = gr.complex_to_imag()
        #self.dr = gr.complex_to_real()
        #self.connect(self.src,self.dr)
        #self.connect(self.src,self.di)
        #self.null = gr.null_sink(gr.sizeof_double)
        #self.connect(self.src,self.di)
        #self.connect((self.di,0),(self.scope,0))
        #self.connect((self.di,1),(self.scope,1))
        #self.connect(self.dr,(self.scope,0))
        #self.connect(self.di,(self.scope,1))

        self.msgq = gr.msg_queue(2)  # queue that holds a maximum of 2 messages
        self.queue_watcher = queue_watcher(self.msgq, self.adjust_freq_norm)

        #-------------------------------------------------------------------------------

        if options.protocol == 0:
            # ---------- RD-LAP 19.2 kbps (9600 ksps), 25kHz channel,
            print "RD-LAP selected"
            self.symbol_rate = 9600  # symbol rate; at 2 bits/symbol this corresponds to 19.2kbps

            if options.channel_decim is None:
                self.channel_decimation = 10  # decimation (final rate should be at least several symbol rate)
            else:
                self.channel_decimation = options.channel_decim

            self.max_frequency_offset = 12000.0  # coarse carrier tracker leash, ~ half a channel either way
            self.symbol_deviation = 1200.0  # this is frequency offset from center of channel to +1 / -1 symbols

            self.input_sample_rate = self.sample_rate

            self.protocol_processing = fsk4.rdlap_f(
                self.msgq,
                0)  # desired protocol processing block selected here

            self.channel_rate = self.input_sample_rate / self.channel_decimation

            # channel selection filter characteristics
            channel_taps = optfir.low_pass(
                1.0,  # Filter gain
                self.input_sample_rate,  # Sample rate
                10000,  # One-sided modulation bandwidth
                12000,  # One-sided channel bandwidth
                0.1,  # Passband ripple
                60)  # Stopband attenuation

            # symbol shaping filter characteristics
            symbol_coeffs = gr.firdes.root_raised_cosine(
                1.0,  # gain
                self.channel_rate,  # sampling rate
                self.symbol_rate,  # symbol rate
                0.2,  # alpha
                500)  # taps

        if options.protocol == 1:
            # ---------- APCO-25 C4FM Test Data
            print "APCO selected"
            self.symbol_rate = 4800  # symbol rate

            if options.channel_decim is None:
                self.channel_decimation = 20  # decimation
            else:
                self.channel_decimation = options.channel_decim

            self.max_frequency_offset = 6000.0  # coarse carrier tracker leash
            self.symbol_deviation = 600.0  # this is frequency offset from center of channel to +1 / -1 symbols

            self.input_sample_rate = self.sample_rate

            self.protocol_processing = fsk4.apco25_f(self.msgq, 0)
            self.channel_rate = self.input_sample_rate / self.channel_decimation

            # channel selection filter
            if (options.data_file is not None) and (options.base_band
                                                    == False):
                channel_taps = optfir.low_pass(
                    1.0,  # Filter gain
                    self.input_sample_rate,  # Sample rate
                    5000,  # One-sided modulation bandwidth
                    6500,  # One-sided channel bandwidth
                    0.2,  # Passband ripple (was 0.1)
                    60)  # Stopband attenuation
            else:
                channel_taps = None

            # symbol shaping filter
            symbol_coeffs = gr.firdes.root_raised_cosine(
                1.0,  # gain
                self.channel_rate,  # sampling rate
                self.symbol_rate,  # symbol rate
                0.2,  # alpha
                500)  # taps

        # ----------------- End of setup block

        print "Input rate = " + str(self.input_sample_rate)
        print "Channel decimation = " + str(self.channel_decimation)
        print "Channel rate = " + str(self.channel_rate)

        if channel_taps is not None:
            self.chan = gr.freq_xlating_fir_filter_ccf(
                self.channel_decimation,  # Decimation rate
                channel_taps,  # Filter taps
                0.0,  # Offset frequency
                self.input_sample_rate)  # Sample rate
            if (options.freq_translation != 0):
                print "Channel center frequency = " + str(
                    options.freq_translation)
                self.chan.set_center_freq(options.freq_translation)
        else:
            self.chan = None

        if options.carrier_freq is not None:
            print "Carrier frequency = " + str(options.carrier_freq)
            self.sig_carrier = gr.sig_source_c(self.channel_rate,
                                               gr.GR_COS_WAVE,
                                               options.carrier_freq, 1, 0)
            self.carrier_mul = gr.multiply_vcc(1)  # cc(gr.sizeof_gr_complex)

            self.connect(self.sig_carrier, (self.carrier_mul, 0))
            self.connect(self.chan, (self.carrier_mul, 1))

            self.sig_i_carrier = gr.sig_source_f(self.channel_rate,
                                                 gr.GR_COS_WAVE,
                                                 options.carrier_freq, 1, 0)
            self.sig_q_carrier = gr.sig_source_f(self.channel_rate,
                                                 gr.GR_COS_WAVE,
                                                 options.carrier_freq, 1,
                                                 (pi / 2.0))
            self.carrier_i_mul = gr.multiply_ff(1)
            self.carrier_q_mul = gr.multiply_ff(1)
            self.iq_to_float = gr.complex_to_float(1)
            self.carrier_iq_add = gr.add_ff(1)

            self.connect(self.carrier_mul, self.iq_to_float)
            self.connect((self.iq_to_float, 0), (self.carrier_i_mul, 0))
            self.connect((self.iq_to_float, 1), (self.carrier_q_mul, 0))
            self.connect(self.sig_i_carrier, (self.carrier_i_mul, 1))
            self.connect(self.sig_q_carrier, (self.carrier_q_mul, 1))
            self.connect(self.carrier_i_mul, (self.carrier_iq_add, 0))
            self.connect(self.carrier_q_mul, (self.carrier_iq_add, 1))
        else:
            self.sig_carrier = None
            self.carrier_mul = None

        #lf_channel_taps = optfir.low_pass(1.0,   # Filter gain
        #            self.input_sample_rate, # Sample rate
        #            2500, # One-sided modulation bandwidth
        #            3250, # One-sided channel bandwidth
        #            0.1,   # Passband ripple (0.1)
        #            60,    # Stopband attenuation
        #            9)     # Extra taps (default 2, which doesn't work at 48kHz)
        #self.lf = gr.fir_filter_fff(self.channel_decimation, lf_channel_taps)

        self.scope2 = scopesink2.scope_sink_f(panel,
                                              sample_rate=self.symbol_rate,
                                              frame_decim=1,
                                              v_scale=2,
                                              t_scale=0.025,
                                              num_inputs=self.num_inputs)

        # also note: this specifies the nominal frequency deviation for the 4-level fsk signal
        self.fm_demod_gain = self.channel_rate / (2.0 * pi *
                                                  self.symbol_deviation)
        self.fm_demod = gr.quadrature_demod_cf(self.fm_demod_gain)

        symbol_decim = 1
        self.symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)

        # eventually specify: sample rate, symbol rate
        self.demod_fsk4 = fsk4.demod_ff(self.msgq, self.channel_rate,
                                        self.symbol_rate)

        if (self.chan is not None):
            self.connect(self.src, self.chan, self.fm_demod,
                         self.symbol_filter, self.demod_fsk4,
                         self.protocol_processing)

            if options.wav_out is not None:
                print "WAV output gain = " + str(options.wav_out_gain)
                self.scaled_wav_data = gr.multiply_const_ff(
                    float(options.wav_out_gain))
                self.connect(self.scaled_wav_data, self.wav_out)

                if self.carrier_mul is None:
                    self.connect(self.fm_demod, self.scaled_wav_data)
                else:
                    self.connect(self.carrier_iq_add, self.scaled_wav_data)

            if self.data_out is not None:
                if self.carrier_mul is None:
                    self.connect(self.fm_demod, self.data_out)
                else:
                    self.connect(self.carrier_mul, self.data_out)

            # During signal, -4..4
            #self.connect(self.fm_demod, self.scope2)
        else:
            self.connect(self.src, self.symbol_filter, self.demod_fsk4,
                         self.protocol_processing)

        self.connect(self.src, self.scope)
        #self.connect(self.lf, self.scope)

        self.connect(self.demod_fsk4, self.scope2)
        #self.connect(self.symbol_filter, self.scope2)

        # --------------- End of most of the 4L-FSK hack & slash

        self._build_gui(vbox)

        # set initial values

        if options.gain is None:
            options.gain = 0

        self.set_gain(options.gain)
Example #8
0
    def __init__( self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__( self, frame, panel, vbox, argv)

        self.frame = frame
        self.panel = panel

	self.offset = 0.0
        
        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=first one with a daughterboard)")
        parser.add_option("-d", "--decim", type="int", default=1,
                          help="set fgpa decimation rate to DECIM [default=%default]")
        parser.add_option("-f", "--freq", type="eng_float", default=None,
                          help="set frequency to FREQ", metavar="FREQ")
        parser.add_option("-p", "--protocol", type="int", default=0,
                          help="set protocol: 0 = RDLAP 19.2kbps (default); 1 = APCO25")
        parser.add_option("-g", "--gain", type="eng_float", default=1,
                          help="set gain multiplier")
        parser.add_option("-8", "--width-8", action="store_true", default=False,
                          help="Enable 8-bit samples across USB")
        parser.add_option( "--no-hb", action="store_true", default=False,
                          help="don't use halfband filter in usrp")
        parser.add_option("-C", "--basic-complex", action="store_true", default=False,
                          help="Use both inputs of a basicRX or LFRX as a single Complex input channel")
        parser.add_option("-D", "--basic-dualchan", action="store_true", default=False,
                          help="Use both inputs of a basicRX or LFRX as seperate Real input channels")
        parser.add_option("-n", "--frame-decim", type="int", default=1,
                          help="set oscope frame decimation factor to n [default=1]")
        parser.add_option("-I", "--audio-input", type="string", default="", help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
        parser.add_option("-s", "--sample-rate", type="int", default=48000, help="sound card input sample rate")
        parser.add_option("-v", "--v-scale", type="eng_float", default=1000,
                          help="set oscope initial V/div to SCALE [default=%default]")
        parser.add_option("-t", "--t-scale", type="eng_float", default=49e-6,
                          help="set oscope initial s/div to SCALE [default=50us]")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        self.show_debug_info = True
        
        # build the graph
        self.num_inputs=1

        self.msgq = gr.msg_queue(2)         # queue that holds a maximum of 2 messages

        if options.protocol == 0:

  	  # ---------- RD-LAP 19.2 kbps (9600 ksps), 25kHz channel, 
          self.symbol_rate = 9600				# symbol rate; at 2 bits/symbol this corresponds to 19.2kbps
 	  self.channel_decimation = 1 				# decimation (final rate should be at least several symbol rate)
          self.input_sample_rate = options.sample_rate / options.decim		# for USRP: 64MHz / FPGA decimation rate	
	  self.protocol_processing = fsk4.rdlap_f(self.msgq, 0)	# desired protocol processing block selected here

          self.channel_rate = self.input_sample_rate / self.channel_decimation

	  # symbol shaping filter characteristics
          symbol_coeffs = gr.firdes.root_raised_cosine (1.0,            	# gain
                                          self.channel_rate ,       	# sampling rate
                                          self.symbol_rate,             # symbol rate
                                          0.2,                		# width of trans. band
                                          500) 				# filter type 


        if options.protocol == 1:

	  # ---------- APCO-25 C4FM Test Data
          self.symbol_rate = 4800					# symbol rate; at 2 bits/symbol this corresponds to 19.2kbps
	  self.channel_decimation = 1 				# decimation
          self.input_sample_rate = options.sample_rate / options.decim		# for USRP: 64MHz / FPGA decimation rate	
	  self.protocol_processing = fsk4.apco25_f(self.msgq, 0)
          self.channel_rate = self.input_sample_rate / self.channel_decimation

	  # symbol shaping filter
          symbol_coeffs = gr.firdes.root_raised_cosine (1.0,            	# gain
                                          self.channel_rate ,       	# sampling rate
                                          self.symbol_rate,             # symbol rate
                                          0.2,                		# width of trans. band
                                          500) 				# filter type 


        # ----------------- End of setup block




        self.audio_input = audio.source(options.sample_rate, options.audio_input)
        self.audio_gain = gr.multiply_const_ff(options.gain)

        self.scope2 = scopesink2.scope_sink_f(panel, sample_rate=self.symbol_rate,
                                            frame_decim=1,
                                            v_scale=2,
                                            t_scale= 0.025,
                                            num_inputs=self.num_inputs)



	# also note: 
        # this specifies the nominal frequency deviation for the 4-level fsk signal
        symbol_decim = 1
        self.symbol_filter = gr.fir_filter_fff (symbol_decim, symbol_coeffs)

        # eventually specify: sample rate, symbol rate
        self.demod_fsk4 = fsk4.demod_ff(self.msgq, self.channel_rate ,  self.symbol_rate)

	#self.rdlap_processing = fsk4.rdlap_f(self.msgq, 0)

	self.connect(self.audio_input, self.audio_gain, self.symbol_filter, self.demod_fsk4, self.protocol_processing)

        self.connect(self.demod_fsk4, self.scope2)


	# --------------- End of most of the 4L-FSK hack & slash



        self._build_gui(vbox)

        # set initial values

        self.set_gain(options.gain)

        if self.show_debug_info:
#            self.myform['decim'].set_value(self.u.decim_rate())
            self.myform['dbname'].set_value("alsa")
            self.myform['baseband'].set_value(0)
            self.myform['ddc'].set_value(0)
            if self.num_inputs==2:
              self.myform['baseband2'].set_value(0)
              self.myform['ddc2'].set_value(0)              
Example #9
0
    def __init__( self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__( self, frame, panel, vbox, argv)

        self.frame = frame
        self.panel = panel

        self.offset = 0.0   # Channel frequency offset

        parser = OptionParser(option_class=eng_option)

        parser.add_option("-p", "--protocol", type="int", default=1,
                          help="set protocol: 0 = RDLAP 19.2kbps; 1 = APCO25 (default)")
        parser.add_option("-g", "--gain", type="eng_float", default=1.0,
                          help="set linear input gain (default: %default)")
        parser.add_option("-x", "--freq-translation", type="eng_float", default=0.0,
                          help="initial channel frequency translation")

        parser.add_option("-n", "--frame-decim", type="int", default=1,
                          help="set oscope frame decimation factor to n [default=1]")
        parser.add_option("-v", "--v-scale", type="eng_float", default=5000,
                          help="set oscope initial V/div to SCALE [default=%default]")
        parser.add_option("-t", "--t-scale", type="eng_float", default=49e-6,
                          help="set oscope initial s/div to SCALE [default=50us]")
        
        parser.add_option("-I", "--audio-input", type="string", default="",
                          help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
        parser.add_option("-r", "--sample-rate", type="eng_float", default=48000,
                          help="set sample rate to RATE (default: %default)")
        
        parser.add_option("-d", "--channel-decim", type="int", default=None,
                          help="set channel decimation factor to n [default depends on protocol]")
        
        parser.add_option("-w", "--wav-file", type="string", default=None,
                          help="WAV input path")
        parser.add_option("-f", "--data-file", type="string", default=None,
                          help="Data input path")
        parser.add_option("-B", "--base-band", action="store_true", default=False)
        parser.add_option("-R", "--repeat", action="store_true", default=False)
        
        parser.add_option("-o", "--wav-out", type="string", default=None,
                          help="WAV output path")
        parser.add_option("-G", "--wav-out-gain", type="eng_float", default=0.05,
                          help="set WAV output gain (default: %default)")
        
        parser.add_option("-F", "--data-out", type="string", default=None,
                          help="Data output path")
        
        parser.add_option("-C", "--carrier-freq", type="eng_float", default=None,
                          help="set data output carrier frequency to FREQ", metavar="FREQ")

        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)
        
        self.options = options
        
        if options.wav_file is not None:
            #try:
            self.input_file = gr.wavfile_source(options.wav_file, options.repeat)
            #except:
            #    print "WAV file not found or not a WAV file"
            #    sys.exit(1)
            
            print "WAV input: %i Hz, %i bits, %i channels" % (self.input_file.sample_rate(), self.input_file.bits_per_sample(), self.input_file.channels())
            
            self.sample_rate = self.input_file.sample_rate()
            self.input_stream = gr.throttle(gr.sizeof_float, self.sample_rate)
            self.connect(self.input_file, self.input_stream)
            self.src = gr.multiply_const_ff(options.gain)
        elif options.data_file is not None:
            if options.base_band:
                sample_size = gr.sizeof_float
                print "Data file is baseband (float)"
                self.src = gr.multiply_const_ff(options.gain)
            else:
                sample_size = gr.sizeof_gr_complex
                print "Data file is IF (complex)"
                self.src = gr.multiply_const_cc(options.gain)
            
            self.input_file = gr.file_source(sample_size, options.data_file, options.repeat)
            self.sample_rate = options.sample_rate  # E.g. 250000
            
            print "Data file sampling rate = " + str(self.sample_rate)
            
            self.input_stream = gr.throttle(sample_size, self.sample_rate)
            self.connect(self.input_file, self.input_stream)
        else:
            self.sample_rate = options.sample_rate
            print "Soundcard sampling rate = " + str(self.sample_rate)
            self.input_stream = audio.source(self.sample_rate, options.audio_input)  # float samples
            self.src = gr.multiply_const_ff(options.gain)
        
        print "Fixed input gain = " + str(options.gain)
        self.connect(self.input_stream, self.src)
        
        if options.wav_out is not None:
            output_rate = int(self.sample_rate)
            if options.channel_decim is not None:
                output_rate /= options.channel_decim
            self.wav_out = gr.wavfile_sink(options.wav_out, 1, output_rate, 16)
            print "Opened WAV output file: " + options.wav_out + " at rate: " + str(output_rate)
        else:
            self.wav_out = None
        
        if options.data_out is not None:
            if options.carrier_freq is None:
                self.data_out = gr.file_sink(gr.sizeof_float, options.data_out)
                print "Opened float data output file: " + options.data_out
            else:
                self.data_out = gr.file_sink(gr.sizeof_gr_complex, options.data_out)
                print "Opened complex data output file: " + options.data_out
        else:
            self.data_out = None
        
        self.num_inputs = 1
        
        input_rate = self.sample_rate
        #title='IF',
        #size=(1024,800),
        if (options.data_file is not None) and (options.base_band == False):
            self.scope = scopesink2.scope_sink_c(panel,
                                                sample_rate=input_rate,
                                                frame_decim=options.frame_decim,
                                                v_scale=options.v_scale,
                                                t_scale=options.t_scale,
                                                num_inputs=self.num_inputs)
        else:
            self.scope = scopesink2.scope_sink_f(panel,
                                                sample_rate=input_rate,
                                                frame_decim=options.frame_decim,
                                                v_scale=options.v_scale,
                                                t_scale=options.t_scale,
                                                num_inputs=self.num_inputs)
        
        #self.di = gr.deinterleave(gr.sizeof_float)
        #self.di = gr.complex_to_float(1)
        #self.di = gr.complex_to_imag()
        #self.dr = gr.complex_to_real()
        #self.connect(self.src,self.dr)
        #self.connect(self.src,self.di)
        #self.null = gr.null_sink(gr.sizeof_double)
        #self.connect(self.src,self.di)
        #self.connect((self.di,0),(self.scope,0))
        #self.connect((self.di,1),(self.scope,1))
        #self.connect(self.dr,(self.scope,0))
        #self.connect(self.di,(self.scope,1))

        self.msgq = gr.msg_queue(2)         # queue that holds a maximum of 2 messages
        self.queue_watcher = queue_watcher(self.msgq, self.adjust_freq_norm)

        #-------------------------------------------------------------------------------

        if options.protocol == 0:
          # ---------- RD-LAP 19.2 kbps (9600 ksps), 25kHz channel,
          print "RD-LAP selected"
          self.symbol_rate = 9600				# symbol rate; at 2 bits/symbol this corresponds to 19.2kbps

          if options.channel_decim is None:
            self.channel_decimation = 10				# decimation (final rate should be at least several symbol rate)
          else:
            self.channel_decimation = options.channel_decim

          self.max_frequency_offset = 12000.0			# coarse carrier tracker leash, ~ half a channel either way
          self.symbol_deviation = 1200.0			# this is frequency offset from center of channel to +1 / -1 symbols

          self.input_sample_rate = self.sample_rate

          self.protocol_processing = fsk4.rdlap_f(self.msgq, 0)	# desired protocol processing block selected here

          self.channel_rate = self.input_sample_rate / self.channel_decimation

          # channel selection filter characteristics
          channel_taps = optfir.low_pass(1.0,   # Filter gain
                               self.input_sample_rate, # Sample rate
                               10000, # One-sided modulation bandwidth
                               12000, # One-sided channel bandwidth
                               0.1,   # Passband ripple
                               60)    # Stopband attenuation

          # symbol shaping filter characteristics
          symbol_coeffs = gr.firdes.root_raised_cosine (1.0,            	# gain
                                          self.channel_rate ,       	# sampling rate
                                          self.symbol_rate,             # symbol rate
                                          0.2,                		# alpha
                                          500) 				# taps

        if options.protocol == 1:
          # ---------- APCO-25 C4FM Test Data
          print "APCO selected"
          self.symbol_rate = 4800					# symbol rate
          
          if options.channel_decim is None:
            self.channel_decimation = 20				# decimation
          else:
            self.channel_decimation = options.channel_decim
            
          self.max_frequency_offset = 6000.0			# coarse carrier tracker leash 
          self.symbol_deviation = 600.0				# this is frequency offset from center of channel to +1 / -1 symbols
          
          self.input_sample_rate = self.sample_rate
          
          self.protocol_processing = fsk4.apco25_f(self.msgq, 0)
          self.channel_rate = self.input_sample_rate / self.channel_decimation

          # channel selection filter
          if (options.data_file is not None) and (options.base_band == False):
                channel_taps = optfir.low_pass(1.0,   # Filter gain
                                     self.input_sample_rate, # Sample rate
                                     5000, # One-sided modulation bandwidth
                                     6500, # One-sided channel bandwidth
                                     0.2,   # Passband ripple (was 0.1)
                                     60)    # Stopband attenuation
          else:
            channel_taps = None

          # symbol shaping filter
          symbol_coeffs = gr.firdes.root_raised_cosine (1.0,            # gain
                                          self.channel_rate,       	# sampling rate
                                          self.symbol_rate,             # symbol rate
                                          0.2,                		# alpha
                                          500) 				# taps

        # ----------------- End of setup block
        
        print "Input rate = " + str(self.input_sample_rate)
        print "Channel decimation = " + str(self.channel_decimation)
        print "Channel rate = " + str(self.channel_rate)

        if channel_taps is not None:
            self.chan = gr.freq_xlating_fir_filter_ccf(self.channel_decimation,    # Decimation rate
                                                  channel_taps,  # Filter taps
                                                  0.0,   # Offset frequency
                                                  self.input_sample_rate) # Sample rate
            if (options.freq_translation != 0):
                print "Channel center frequency = " + str(options.freq_translation)
                self.chan.set_center_freq(options.freq_translation)
        else:
            self.chan = None
        
        if options.carrier_freq is not None:
            print "Carrier frequency = " + str(options.carrier_freq)
            self.sig_carrier = gr.sig_source_c(self.channel_rate, gr.GR_COS_WAVE, options.carrier_freq, 1, 0)
            self.carrier_mul = gr.multiply_vcc(1)   # cc(gr.sizeof_gr_complex)
            
            self.connect(self.sig_carrier, (self.carrier_mul, 0))
            self.connect(self.chan, (self.carrier_mul, 1))
            
            self.sig_i_carrier = gr.sig_source_f(self.channel_rate, gr.GR_COS_WAVE, options.carrier_freq, 1, 0)
            self.sig_q_carrier = gr.sig_source_f(self.channel_rate, gr.GR_COS_WAVE, options.carrier_freq, 1, (pi / 2.0))
            self.carrier_i_mul = gr.multiply_ff(1)
            self.carrier_q_mul = gr.multiply_ff(1)
            self.iq_to_float = gr.complex_to_float(1)
            self.carrier_iq_add = gr.add_ff(1)
            
            self.connect(self.carrier_mul, self.iq_to_float)
            self.connect((self.iq_to_float, 0), (self.carrier_i_mul, 0))
            self.connect((self.iq_to_float, 1), (self.carrier_q_mul, 0))
            self.connect(self.sig_i_carrier, (self.carrier_i_mul, 1))
            self.connect(self.sig_q_carrier, (self.carrier_q_mul, 1))
            self.connect(self.carrier_i_mul, (self.carrier_iq_add, 0))
            self.connect(self.carrier_q_mul, (self.carrier_iq_add, 1))
        else:
            self.sig_carrier = None
            self.carrier_mul = None
        
        #lf_channel_taps = optfir.low_pass(1.0,   # Filter gain
        #            self.input_sample_rate, # Sample rate
        #            2500, # One-sided modulation bandwidth
        #            3250, # One-sided channel bandwidth
        #            0.1,   # Passband ripple (0.1)
        #            60,    # Stopband attenuation
        #            9)     # Extra taps (default 2, which doesn't work at 48kHz)
        #self.lf = gr.fir_filter_fff(self.channel_decimation, lf_channel_taps)

        self.scope2 = scopesink2.scope_sink_f(panel, sample_rate=self.symbol_rate,
                                            frame_decim=1,
                                            v_scale=2,
                                            t_scale=0.025,
                                            num_inputs=self.num_inputs)

        # also note: this specifies the nominal frequency deviation for the 4-level fsk signal
        self.fm_demod_gain = self.channel_rate / (2.0 * pi * self.symbol_deviation)
        self.fm_demod = gr.quadrature_demod_cf(self.fm_demod_gain)
        
        symbol_decim = 1
        self.symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)

        # eventually specify: sample rate, symbol rate
        self.demod_fsk4 = fsk4.demod_ff(self.msgq, self.channel_rate, self.symbol_rate)

        if (self.chan is not None):
            self.connect(self.src, self.chan, self.fm_demod, self.symbol_filter, self.demod_fsk4, self.protocol_processing)
            
            if options.wav_out is not None:
                print "WAV output gain = " + str(options.wav_out_gain)
                self.scaled_wav_data = gr.multiply_const_ff(float(options.wav_out_gain))
                self.connect(self.scaled_wav_data, self.wav_out)
                
                if self.carrier_mul is None:
                    self.connect(self.fm_demod, self.scaled_wav_data)
                else:
                    self.connect(self.carrier_iq_add, self.scaled_wav_data)
            
            if self.data_out is not None:
                if self.carrier_mul is None:
                    self.connect(self.fm_demod, self.data_out)
                else:
                    self.connect(self.carrier_mul, self.data_out)
            
            # During signal, -4..4
            #self.connect(self.fm_demod, self.scope2)
        else:
            self.connect(self.src, self.symbol_filter, self.demod_fsk4, self.protocol_processing)
        
        self.connect(self.src, self.scope)
        #self.connect(self.lf, self.scope)
        
        self.connect(self.demod_fsk4, self.scope2)
        #self.connect(self.symbol_filter, self.scope2)

	# --------------- End of most of the 4L-FSK hack & slash

        self._build_gui(vbox)

        # set initial values

        if options.gain is None:
            options.gain = 0

        self.set_gain(options.gain)