Exemple #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)
    def __init__(self, address, callback, options):
        gr.top_block.__init__(self)

        self._address = address
        self._rx_freq = options.rx_freq         # receiver's center frequency
        self._rx_gain = options.rx_gain         # receiver's gain
        self._decim   = options.decim           # Decimating rate for the USRP (prelim)

        if self._rx_freq is None:
            sys.stderr.write("-f FREQ or --freq FREQ or --rx-freq FREQ must be specified\n")
            raise SystemExit

        # Set up USRP source
        self._setup_source()

        #taps = gr.firdes.low_pass(1, 1, 0.4, 0.2)
        #self.resample = gr.rational_resampler_base_ccf(5, 8, taps)
        self.resample = blks2.rational_resampler_ccf(5, 8)

        # Set up receive path
        self.rxpath = receive_path(callback, options)

        self.connect(self.src, self.resample, self.rxpath)
Exemple #3
0
    def __init__(self, address, callback, options):
        gr.top_block.__init__(self)

        self._address = address
        self._rx_freq = options.rx_freq  # receiver's center frequency
        self._rx_gain = options.rx_gain  # receiver's gain
        self._decim = options.decim  # Decimating rate for the USRP (prelim)

        if self._rx_freq is None:
            sys.stderr.write(
                "-f FREQ or --freq FREQ or --rx-freq FREQ must be specified\n")
            raise SystemExit

        # Set up USRP source
        self._setup_source()

        #taps = gr.firdes.low_pass(1, 1, 0.4, 0.2)
        #self.resample = gr.rational_resampler_base_ccf(5, 8, taps)
        self.resample = blks2.rational_resampler_ccf(5, 8)

        # Set up receive path
        self.rxpath = receive_path(callback, options)

        self.connect(self.src, self.resample, self.rxpath)
Exemple #4
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)
Exemple #5
0
  def __init__(self, options, args, queue):
    gr.top_block.__init__(self)

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

    if options.filename is None and options.udp is None and not options.rtlsdr:
      #UHD source by default
      from gnuradio import uhd
      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()
      
    elif options.rtlsdr: #RTLSDR dongle
        import osmosdr
        self.u = osmosdr.source_c()
        self.u.set_sample_rate(2.4e6) #fixed for RTL dongles
        if not self.u.set_center_freq(options.freq):
            print "Failed to set initial frequency"

        self.u.set_gain_mode(0) #manual gain mode
        if options.gain is None:
            options.gain = 49
            
        self.u.set_gain(options.gain)
        print "Gain is %i" % self.u.get_gain()

        use_resampler = True
                
    else:
      if options.filename is not None:
        self.u = gr.file_source(gr.sizeof_gr_complex, options.filename)
      elif options.udp is not None:
        self.u = gr.udp_source(gr.sizeof_gr_complex, "localhost", options.udp)
      else:
        raise Exception("No valid source selected")
        

    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)
    
    self.preamble = air_modes.modes_preamble(rate, options.threshold)
    #self.framer = air_modes.modes_framer(rate)
    self.slicer = air_modes.modes_slicer(rate, queue)

    if use_resampler:
        self.lpfiltcoeffs = gr.firdes.low_pass(1, 5*2.4e6, 1.2e6, 300e3)
        self.resample = blks2.rational_resampler_ccf(interpolation=5, decimation=3, taps=self.lpfiltcoeffs)
        self.connect(self.u, self.resample, self.demod)
    else:
        self.connect(self.u, 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))
Exemple #6
0
    def __init__(self, options, rx_callback):
        gr.top_block.__init__(self)

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

        self.usrp_decim = 4
        self.samples_per_symbol = 2
        self.filter_decim = 5
        self.resamp_interp = 4
        self.resamp_decim = 5

        self.data_rate = int(u.adc_rate() / self.samples_per_symbol /
                             self.usrp_decim / self.filter_decim *
                             self.resamp_interp / self.resamp_decim)
        self.sampling_rate = int(u.adc_rate() / self.usrp_decim)

        print "data_rate = ", eng_notation.num_to_str(self.data_rate)
        print "samples_per_symbol = ", self.samples_per_symbol
        print "usrp_decim = ", self.usrp_decim
        print "usrp2_gain = ", options.gain
        print "Squelch filter = ", options.squelch

        self.chan1_freq = ieee802_15_4_pkt.chan_802_15_4.chan_map[
            options.channel1]
        self.chan1_num = options.channel1
        self.chan2_num = self.chan1_num + 1
        self.chan3_num = self.chan2_num + 1
        self.chan4_num = self.chan3_num + 1
        self.chan5_num = self.chan4_num + 1

        self.chan5_freq = ieee802_15_4_pkt.chan_802_15_4.chan_map[
            self.chan5_num]

        self.usrp_freq = (self.chan1_freq + self.chan5_freq) / 2

        self.chan1_offset = self.usrp_freq - self.chan1_freq
        self.chan2_offset = self.chan1_offset - 5000000
        self.chan3_offset = self.chan2_offset - 5000000
        self.chan4_offset = self.chan3_offset - 5000000
        self.chan5_offset = self.chan4_offset - 5000000

        print "Centering USRP2 at = ", self.usrp_freq
        print "Channel ", self.chan1_num, " freq = ", self.usrp_freq - self.chan1_offset
        print "Channel ", self.chan2_num, " freq = ", self.usrp_freq - self.chan2_offset
        print "Channel ", self.chan3_num, " freq = ", self.usrp_freq - self.chan3_offset
        print "Channel ", self.chan4_num, " freq = ", self.usrp_freq - self.chan4_offset
        print "Channel ", self.chan5_num, " freq = ", self.usrp_freq - self.chan5_offset

        u.set_center_freq(self.usrp_freq)
        u.set_decim(self.usrp_decim)
        u.set_gain(options.gain)

        # Creating a filter for channel selection
        chan_coeffs = gr.firdes.low_pass(
            1.0,  # filter gain
            self.sampling_rate,  # sampling rate
            2e6,  # cutoff frequency  
            2e6,  # bandwidth
            gr.firdes.WIN_HANN)  # filter type

        print "Length of chan_coeffs = ", len(chan_coeffs)

        # Decimating channel filters
        self.ddc1 = gr.freq_xlating_fir_filter_ccf(
            self.filter_decim,  # decimation rate
            chan_coeffs,  # taps
            self.chan1_offset,  # frequency translation amount  
            self.sampling_rate)  # input sampling rate

        self.ddc2 = gr.freq_xlating_fir_filter_ccf(
            self.filter_decim,  # decimation rate
            chan_coeffs,  # taps
            self.chan2_offset,  # frequency translation amount  
            self.sampling_rate)  # input sampling rate

        self.ddc3 = gr.fir_filter_ccf(self.filter_decim, chan_coeffs)

        self.ddc4 = gr.freq_xlating_fir_filter_ccf(
            self.filter_decim,  # decimation rate
            chan_coeffs,  # taps
            self.chan4_offset,  # frequency translation amount  
            self.sampling_rate)  # input sampling rate

        self.ddc5 = gr.freq_xlating_fir_filter_ccf(
            self.filter_decim,  # decimation rate
            chan_coeffs,  # taps
            self.chan5_offset,  # frequency translation amount  
            self.sampling_rate)  # input sampling rate

        self.packet_receiver1 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts(
            self,
            callback=rx_callback,
            sps=self.samples_per_symbol,
            channel=self.chan1_num,
            threshold=-1)
        self.packet_receiver2 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts(
            self,
            callback=rx_callback,
            sps=self.samples_per_symbol,
            channel=self.chan2_num,
            threshold=-1)
        self.packet_receiver3 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts(
            self,
            callback=rx_callback,
            sps=self.samples_per_symbol,
            channel=self.chan3_num,
            threshold=-1)
        self.packet_receiver4 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts(
            self,
            callback=rx_callback,
            sps=self.samples_per_symbol,
            channel=self.chan4_num,
            threshold=-1)
        self.packet_receiver5 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts(
            self,
            callback=rx_callback,
            sps=self.samples_per_symbol,
            channel=self.chan5_num,
            threshold=-1)

        self.resampler1 = blks2.rational_resampler_ccf(self.resamp_interp,
                                                       self.resamp_decim)
        self.resampler2 = blks2.rational_resampler_ccf(self.resamp_interp,
                                                       self.resamp_decim)
        self.resampler3 = blks2.rational_resampler_ccf(self.resamp_interp,
                                                       self.resamp_decim)
        self.resampler4 = blks2.rational_resampler_ccf(self.resamp_interp,
                                                       self.resamp_decim)
        self.resampler5 = blks2.rational_resampler_ccf(self.resamp_interp,
                                                       self.resamp_decim)

        self.u = u
        self.squelch = gr.pwr_squelch_cc(options.squelch, gate=True)

        self.connect(self.u, self.squelch)
        self.connect(self.squelch, self.ddc1, self.resampler1,
                     self.packet_receiver1)
        self.connect(self.squelch, self.ddc2, self.resampler2,
                     self.packet_receiver2)
        self.connect(self.squelch, self.ddc3, self.resampler3,
                     self.packet_receiver3)
        self.connect(self.squelch, self.ddc4, self.resampler4,
                     self.packet_receiver4)
        self.connect(self.squelch, self.ddc5, self.resampler5,
                     self.packet_receiver5)
    def __init__(self, options, rx_callback):
        gr.top_block.__init__(self)

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

        self.usrp_decim = 4
        self.samples_per_symbol = 2
        self.filter_decim = 5
        self.resamp_interp = 4
        self.resamp_decim = 5

        self.data_rate = int (u.adc_rate()
                              / self.samples_per_symbol
                              / self.usrp_decim
                              / self.filter_decim
                              * self.resamp_interp
                              / self.resamp_decim)
        self.sampling_rate = int (u.adc_rate() / self.usrp_decim)

        print "data_rate = ", eng_notation.num_to_str(self.data_rate)
        print "samples_per_symbol = ", self.samples_per_symbol
        print "usrp_decim = ", self.usrp_decim
        print "usrp2_gain = ", options.gain
        print "Squelch filter = ", options.squelch

        self.chan1_freq = ieee802_15_4_pkt.chan_802_15_4.chan_map[options.channel1]
        self.chan1_num = options.channel1
        self.chan2_num = self.chan1_num + 1
        self.chan3_num = self.chan2_num + 1
        self.chan4_num = self.chan3_num + 1
        self.chan5_num = self.chan4_num + 1

        self.chan5_freq = ieee802_15_4_pkt.chan_802_15_4.chan_map[self.chan5_num]

        self.usrp_freq = (self.chan1_freq + self.chan5_freq) / 2

        self.chan1_offset = self.usrp_freq - self.chan1_freq
        self.chan2_offset = self.chan1_offset - 5000000
        self.chan3_offset = self.chan2_offset - 5000000
        self.chan4_offset = self.chan3_offset - 5000000
        self.chan5_offset = self.chan4_offset - 5000000

        print "Centering USRP2 at = ", self.usrp_freq
        print "Channel ", self.chan1_num, " freq = ", self.usrp_freq - self.chan1_offset
        print "Channel ", self.chan2_num, " freq = ", self.usrp_freq - self.chan2_offset
        print "Channel ", self.chan3_num, " freq = ", self.usrp_freq - self.chan3_offset
        print "Channel ", self.chan4_num, " freq = ", self.usrp_freq - self.chan4_offset
        print "Channel ", self.chan5_num, " freq = ", self.usrp_freq - self.chan5_offset

        u.set_center_freq(self.usrp_freq)
        u.set_decim(self.usrp_decim)
        u.set_gain(options.gain)


        # Creating a filter for channel selection
        chan_coeffs = gr.firdes.low_pass(   1.0, # filter gain
                self.sampling_rate,              # sampling rate
                2e6,                           # cutoff frequency  
                2e6,                           # bandwidth
                gr.firdes.WIN_HANN)              # filter type           

        print "Length of chan_coeffs = ", len(chan_coeffs)

        # Decimating channel filters 
        self.ddc1 = gr.freq_xlating_fir_filter_ccf(
                     self.filter_decim,  # decimation rate
                     chan_coeffs,        # taps
                     self.chan1_offset,  # frequency translation amount  
                     self.sampling_rate) # input sampling rate   

        self.ddc2 = gr.freq_xlating_fir_filter_ccf(
                     self.filter_decim,  # decimation rate
                     chan_coeffs,        # taps
                     self.chan2_offset,  # frequency translation amount  
                     self.sampling_rate) # input sampling rate   

        self.ddc3 = gr.fir_filter_ccf(self.filter_decim, chan_coeffs)

        self.ddc4 = gr.freq_xlating_fir_filter_ccf(
                     self.filter_decim,  # decimation rate
                     chan_coeffs,        # taps
                     self.chan4_offset,  # frequency translation amount  
                     self.sampling_rate) # input sampling rate   

        self.ddc5 = gr.freq_xlating_fir_filter_ccf(
                     self.filter_decim,  # decimation rate
                     chan_coeffs,        # taps
                     self.chan5_offset,  # frequency translation amount  
                     self.sampling_rate) # input sampling rate   

        self.packet_receiver1 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts(
            self,
            callback=rx_callback,
            sps=self.samples_per_symbol,
            channel=self.chan1_num,
            threshold=-1)
        self.packet_receiver2 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts(
            self,
            callback=rx_callback,
            sps=self.samples_per_symbol,
            channel=self.chan2_num,
            threshold=-1)
        self.packet_receiver3 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts(
            self,
            callback=rx_callback,
            sps=self.samples_per_symbol,
            channel=self.chan3_num,
            threshold=-1)
        self.packet_receiver4 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts(
            self,
            callback=rx_callback,
            sps=self.samples_per_symbol,
            channel=self.chan4_num,
            threshold=-1)
        self.packet_receiver5 = ieee802_15_4_pkt.ieee802_15_4_demod_pkts(
            self,
            callback=rx_callback,
            sps=self.samples_per_symbol,
            channel=self.chan5_num,
            threshold=-1)

        self.resampler1 = blks2.rational_resampler_ccf(self.resamp_interp,self.resamp_decim)
        self.resampler2 = blks2.rational_resampler_ccf(self.resamp_interp,self.resamp_decim)
        self.resampler3 = blks2.rational_resampler_ccf(self.resamp_interp,self.resamp_decim)
        self.resampler4 = blks2.rational_resampler_ccf(self.resamp_interp,self.resamp_decim)
        self.resampler5 = blks2.rational_resampler_ccf(self.resamp_interp,self.resamp_decim)

        self.u = u
        self.squelch = gr.pwr_squelch_cc(options.squelch, gate=True)

        self.connect(self.u,self.squelch)
        self.connect(self.squelch, self.ddc1,
                self.resampler1,
                self.packet_receiver1)
        self.connect(self.squelch, self.ddc2,
                self.resampler2,
                self.packet_receiver2)
        self.connect(self.squelch, self.ddc3,
                self.resampler3,
                self.packet_receiver3)
        self.connect(self.squelch, self.ddc4,
                self.resampler4,
                self.packet_receiver4)
        self.connect(self.squelch, self.ddc5,
                self.resampler5,
                self.packet_receiver5)