Sie sind auf Seite 1von 3

#!

/usr/bin/env python 2 #this file isn't ready to use now - gsm-receiver lacks realtime processi ng capability 3 #there are many underruns of buffer fom usrp's samples, many blocks of s amples get lost and 4 #receiver isn't prepared for this situation too well 5 6 from gnuradio import gr, gru, blks2 7 #, gsm 8 from gnuradio import usrp 9 from gnuradio.eng_option import eng_option 10 from optparse import OptionParser 11 from os import sys 12 13 for extdir in ['../../debug/src/lib','../../debug/src/lib/.libs']: 14 if extdir not in sys.path: 15 sys.path.append(extdir) 16 import gsm 17 18 def pick_subdevice(u): 19 if u.db[0][0].dbid() >= 0: 20 return (0, 0) 21 if u.db[1][0].dbid() >= 0: 22 return (1, 0) 23 return (0, 0) 24 25 class tune(gr.feval_dd): 26 def __init__(self, top_block): 27 gr.feval_dd.__init__(self) 28 self.top_block = top_block 29 # self.center_freq = 0 30 def eval(self, freq_offet): 31 # self.center_freq = self.center_freq - freq_offet 32 self.top_block.set_frequency(freq_offet) 33 return freq_offet 34 35 class gsm_receiver_first_blood(gr.top_block): 36 def __init__(self): 37 gr.top_block.__init__(self) 38 (options, args) = self._process_options() 39 self.tune_callback = tune(self) 40 self.options = options 41 self.args = args 42 self._set_rates() 43 self.source = self._set_source() 44 self.filtr = self._set_filter() 45 self.interpolator = self._set_interpolator() 46 self.receiver = self._set_receiver() 47 self.converter = self._set_converter() 48 self.sink = self._set_sink() 49 50 self.connect(self.source, self.filtr, self.interpolator, self.r eceiver, self.converter, self.sink) 51 52 def _set_sink(self): 53 nazwa_pliku_wy = self.options.outputfile 54 ujscie = gr.file_sink(gr.sizeof_float, nazwa_pliku_wy) 55 return ujscie 56 57 def _set_source(self):

58 options = self.options 59 fusb_block_size = gr.prefs().get_long('fusb', 'block_size', 4096 ) 60 fusb_nblocks = gr.prefs().get_long('fusb', 'nblocks', 16) 61 self.usrp = usrp.source_c(decim_rate=options.decim, fusb_block_s ize=fusb_block_size, fusb_nblocks=fusb_nblocks) 62 63 if options.rx_subdev_spec is None: 64 options.rx_subdev_spec = pick_subdevice(self.usrp) 65 66 self.usrp.set_mux(usrp.determine_rx_mux_value(self.usrp, options .rx_subdev_spec)) 67 # determine the daughterboard subdevice 68 self.subdev = usrp.selected_subdev(self.usrp, options.rx_subdev_ spec) 69 input_rate = self.usrp.adc_freq() / self.usrp.decim_rate() 70 71 # set initial values 72 if options.gain is None: 73 # if no gain was specified, use the mid-point in dB 74 g = self.subdev.gain_range() 75 options.gain = float(g[0]+g[1])/2 76 77 r = self.usrp.tune(0, self.subdev, options.freq) 78 self.subdev.set_gain(options.gain) 79 return self.usrp 80 81 def _set_rates(self): 82 options = self.options 83 clock_rate = 64e6 84 self.clock_rate = clock_rate 85 self.input_rate = clock_rate / options.decim 86 self.gsm_symb_rate = 1625000.0 / 6.0 87 self.sps = self.input_rate / self.gsm_symb_rate / self.options.o sr 88 89 def _set_filter(self): 90 filter_cutoff = 145e3 91 filter_t_width = 10e3 92 offset = 0 93 # print "input_rate:", self.input_rate, "sample rate:", self.sps, " filter_cutoff:", filter_cutoff, " filter_t_width:", filter_t_width 94 filter_taps = gr.firdes.low_pass(1.0, self.input_rate, filte r_cutoff, filter_t_width, gr.firdes.WIN_HAMMING) 95 filtr = gr.freq_xlating_fir_filter_ccf(1, filter_taps, offset, self.input_rate) 96 return filtr 97 98 def _set_converter(self): 99 v2s = gr.vector_to_stream(gr.sizeof_float, 142) 100 return v2s 101 102 def _set_interpolator(self): 103 interpolator = gr.fractional_interpolator_cc(0, self.sps) 104 return interpolator 105 106 def _set_receiver(self): 107 receiver = gsm.receiver_cf(self.tune_callback, self.options.osr) 108 return receiver 109

110 def _process_options(self): 111 parser = OptionParser(option_class=eng_option) 112 parser.add_option("-d", "--decim", type="int", default=128, 113 help="Set USRP decimation rate to DE CIM [default=%default]") 114 parser.add_option("-I", "--inputfile", type="string", default="c file", 115 help="Input filename") 116 parser.add_option("-O", "--outputfile", type="string", default=" cfile2.out", 117 help="Output filename") 118 parser.add_option("-R", "--rx-subdev-spec", type="subdev", defau lt=None, 119 help="Select USRP Rx side A or B (de fault=first one with a daughterboard)") 120 parser.add_option("-r", "--osr", type="int", default=4, 121 help="Oversampling ratio [default=%default]") 122 parser.add_option("-f", "--freq", type="eng_float", default="950 .4M", 123 help="set frequency to FREQ", metava r="FREQ") 124 parser.add_option("-g", "--gain", type="eng_float", default=None , 125 help="Set gain in dB (default is mid point)") 126 (options, args) = parser.parse_args () 127 return (options, args) 128 129 def set_frequency(self, center_freq): 130 self.filtr.set_center_freq(center_freq) 131 132 def main(): 133 try: 134 gsm_receiver_first_blood().run() 135 except KeyboardInterrupt: 136 pass 137 138 if __name__ == '__main__': 139 main()

Das könnte Ihnen auch gefallen