def test_004(self): vlen = 4 tune = counter4(self, 1) tune_delay = 1 dwell_delay = 2 msgq = gr.msg_queue() src_data = tuple([ float(x) for x in (1, 2, 3, 4, 9, 6, 11, 8, 5, 10, 7, 12, 13, 14, 15, 16) ]) expected_results = tuple([float(x) for x in (9, 10, 11, 12)]) src = blocks.vector_source_f(src_data, False) s2v = blocks.stream_to_vector(gr.sizeof_float, vlen) stats = blocks.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay) self.tb.connect(src, s2v, stats) self.tb.run() self.assertEqual(1, msgq.count()) for i in range(1): m = parse_msg(msgq.delete_head()) #print "m =", m.center_freq, m.data self.assertEqual(expected_results[vlen * i:vlen * i + vlen], m.data)
def test_004(self): vlen = 4 tune = counter4(self, 1) tune_delay = 1 dwell_delay = 2 msgq = gr.msg_queue() src_data = tuple([float(x) for x in ( 1, 2, 3, 4, 9, 6, 11, 8, 5, 10, 7, 12, 13, 14, 15, 16 )]) expected_results = tuple([float(x) for x in ( 9, 10, 11, 12)]) src = blocks.vector_source_f(src_data, False) s2v = blocks.stream_to_vector(gr.sizeof_float, vlen) stats = blocks.bin_statistics_f(vlen, msgq, tune, tune_delay, dwell_delay) self.tb.connect(src, s2v, stats) self.tb.run() self.assertEqual(1, msgq.count()) for i in range(1): m = parse_msg(msgq.delete_head()) #print "m =", m.center_freq, m.data self.assertEqual(expected_results[vlen*i:vlen*i + vlen], m.data)
def __init__(self): gr.top_block.__init__(self) usage = "usage: %prog [options] min_freq max_freq" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option( "-a", "--args", type="string", default="", help="UHD device device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate [default=%default]") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option( "", "--tune-delay", type="eng_float", default=0.25, metavar="SECS", help= "time to delay (in seconds) after changing frequency [default=%default]" ) parser.add_option( "", "--dwell-delay", type="eng_float", default=0.25, metavar="SECS", help= "time to dwell (in seconds) at a given frequency [default=%default]" ) parser.add_option( "-b", "--channel-bandwidth", type="eng_float", default=6.25e3, metavar="Hz", help="channel bandwidth of fft bins in Hz [default=%default]") parser.add_option("-l", "--lo-offset", type="eng_float", default=0, metavar="Hz", help="lo_offset in Hz [default=%default]") parser.add_option("-q", "--squelch-threshold", type="eng_float", default=None, metavar="dB", help="squelch threshold in dB [default=%default]") parser.add_option( "-F", "--fft-size", type="int", default=None, help="specify number of FFT bins [default=samp_rate/channel_bw]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") (options, args) = parser.parse_args() if len(args) != 2: parser.print_help() sys.exit(1) self.channel_bandwidth = options.channel_bandwidth self.min_freq = eng_notation.str_to_num(args[0]) self.max_freq = eng_notation.str_to_num(args[1]) if self.min_freq > self.max_freq: # swap them self.min_freq, self.max_freq = self.max_freq, self.min_freq if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" # build graph self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if (options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if (options.antenna): self.u.set_antenna(options.antenna, 0) self.u.set_samp_rate(options.samp_rate) self.usrp_rate = usrp_rate = self.u.get_samp_rate() self.lo_offset = options.lo_offset if options.fft_size is None: self.fft_size = int(self.usrp_rate / self.channel_bandwidth) else: self.fft_size = options.fft_size self.squelch_threshold = options.squelch_threshold s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = filter.window.blackmanharris(self.fft_size) ffter = fft.fft_vcc(self.fft_size, True, mywindow, True) power = 0 for tap in mywindow: power += tap * tap c2mag = blocks.complex_to_mag_squared(self.fft_size) # FIXME the log10 primitive is dog slow #log = blocks.nlog10_ff(10, self.fft_size, # -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) # Set the freq_step to 75% of the actual data throughput. # This allows us to discard the bins on both ends of the spectrum. self.freq_step = self.nearest_freq((0.75 * self.usrp_rate), self.channel_bandwidth) self.min_center_freq = self.min_freq + (self.freq_step / 2) nsteps = math.ceil((self.max_freq - self.min_freq) / self.freq_step) self.nstep = nsteps self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq tune_delay = max( 0, int(round(options.tune_delay * usrp_rate / self.fft_size))) #调频延时转化为 FFT 计算时忽略的向量个数。 in fft_frames dwell_delay = max( 1, int(round(options.dwell_delay * usrp_rate / self.fft_size) )) # in fft_frames,一个扫频范围内停留的时间.(原输入参数是一个频点的扫的时间,) self.msgq = gr.msg_queue(1) self._tune_callback = tune( self) # hang on to this to keep it from being GC'd stats = blocks.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) #mydata = open('mydata.log', mode = 'a+') print "usrp_rate=",self.usrp_rate,"channel_bandwidth(频谱分辨率)=",self.channel_bandwidth,\ "fft_size= ",self.fft_size ,"freq_step(扫频长度)=", self.freq_step,"nsteps=",nsteps #,"tune_delay=",tune_delay,"dwell_delay=",dwell_delay #mydata.close() # FIXME leave out the log10 until we speed it up #self.connect(self.u, s2v, ffter, c2mag, log, stats) self.connect(self.u, s2v, ffter, c2mag, stats) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start() + g.stop()) / 2.0 self.set_gain(options.gain) print "gain =", options.gain
def __init__(self): gr.top_block.__init__(self) usage = "usage: %prog [options] down_freq" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-a", "--args", type="string", default="addr=192.168.20.2", help="UHD device device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate [default=%default]") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("", "--tune-delay", type="eng_float", default=0.25, metavar="SECS", help="time to delay (in seconds) after changing frequency [default=%default]") parser.add_option("", "--dwell-delay", type="eng_float", default=0.25, metavar="SECS", help="time to dwell (in seconds) at a given frequency [default=%default]") parser.add_option("-b", "--channel-bandwidth", type="eng_float", default=976.56, metavar="Hz", help="channel bandwidth of fft bins in Hz [default=%default]") parser.add_option("-l", "--lo-offset", type="eng_float", default=0, metavar="Hz", help="lo_offset in Hz [default=%default]") parser.add_option("-q", "--squelch-threshold", type="eng_float", default=None, metavar="dB", help="squelch threshold in dB [default=%default]") parser.add_option("-F", "--fft-size", type="int", default=None, help="specify number of FFT bins [default=samp_rate/channel_bw]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") (options, args) = parser.parse_args() if len(args) != 1: parser.print_help() sys.exit(1) self.channel_bandwidth = options.channel_bandwidth self.down_freq = eng_notation.str_to_num(args[0]) self.up_freq = (self.down_freq) - 45e6 if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" # build graph self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if(options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if(options.antenna): self.u.set_antenna(options.antenna, 0) self.u.set_samp_rate(options.samp_rate) self.usrp_rate = usrp_rate = self.u.get_samp_rate() self.lo_offset = options.lo_offset if options.fft_size is None: self.fft_size = int(self.usrp_rate/self.channel_bandwidth) else: self.fft_size = options.fft_size self.squelch_threshold = options.squelch_threshold s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = filter.window.blackmanharris(self.fft_size) ffter = fft.fft_vcc(self.fft_size, True, mywindow, True) power = 0 for tap in mywindow: power += tap*tap c2mag = blocks.complex_to_mag_squared(self.fft_size) tune_delay = max(0, int(round(options.tune_delay * usrp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int(round(options.dwell_delay * usrp_rate / self.fft_size))) # in fft_frames self.msgq = gr.msg_queue(1) self._tune_callback = tune(self) # hang on to this to keep it from being GC'd stats = blocks.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) # FIXME leave out the log10 until we speed it up #self.connect(self.u, s2v, ffter, c2mag, log, stats) self.connect(self.u, s2v, ffter, c2mag, stats) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start()+g.stop())/2.0 self.set_gain(options.gain) print "gain =", options.gain
def __init__(self, set_min_freq=False, set_max_freq=False): gr.top_block.__init__(self) usage = "usage: %prog [options] min_freq max_freq" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-a", "--args", type="string", default="", help="UHD device device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default='RX2', help="select Rx Antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate [default=%default]") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("", "--tune-delay", type="eng_float", default=0.05, metavar="SECS",#change default from #.25 to .05 -GW help="time to delay (in seconds) after changing frequency [default=%default]") parser.add_option("", "--dwell-delay", type="eng_float", default=0.05, metavar="SECS",#changed default from #.25 to .05 - GW help="time to dwell (in seconds) at a given frequency [default=%default]") parser.add_option("-b", "--channel-bandwidth", type="eng_float", default=6.25e3, metavar="Hz", help="channel bandwidth of fft bins in Hz [default=%default]") parser.add_option("-l", "--lo-offset", type="eng_float", default=0, metavar="Hz", help="lo_offset in Hz [default=%default]") parser.add_option("-q", "--squelch-threshold", type="eng_float", default=None, metavar="dB", help="squelch threshold in dB [default=%default]") parser.add_option("-F", "--fft-size", type="int", default=None, help="specify number of FFT bins [default=samp_rate/channel_bw]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") parser.add_option("-G", "--gps", type='int', dest="gps_flag", default=0, help="toggle gps recording : 1 or 0") parser.add_option("-r", "--rawstore", type='int', dest="raw_store", default=0, help="store raw data from channel FFT bins : 1 or 0") parser.add_option("-S", "--spstore", type="int", default='0', help="store signal properties in JSON format: 1 or 0") parser.add_option("-T", "--training", type="int", dest= "training_scan", default='0', help="set as training scan for data collection: 1 or 0") (options, args) = parser.parse_args() #modded : set freq to directly passed frequencies for explicit call of class #from channel object. Can still use passed args direct from cmd line.GW if len(args) == 2: self.min_freq = eng_notation.str_to_num(args[0]) self.max_freq = eng_notation.str_to_num(args[1]) if len(args) !=2 and (not set_min_freq or not set_max_freq): parser.print_help() sys.exit(1) if set_min_freq and set_max_freq: self.min_freq = set_min_freq self.max_freq = set_max_freq self.channel_bandwidth = options.channel_bandwidth if self.min_freq > self.max_freq: # swap them self.min_freq, self.max_freq = self.max_freq, self.min_freq if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" # build graph self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if(options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if(options.antenna): self.u.set_antenna(options.antenna, 0) self.u.set_samp_rate(options.samp_rate) self.usrp_rate = usrp_rate = self.u.get_samp_rate() self.lo_offset = options.lo_offset if options.fft_size is None: self.fft_size = int(self.usrp_rate/self.channel_bandwidth) else: self.fft_size = options.fft_size self.squelch_threshold = options.squelch_threshold s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) #creating DC blocker block to remove DC component - GW dc_blocker = filter.dc_blocker_cc(80, True) mywindow = filter.window.blackmanharris(self.fft_size) ffter = fft.fft_vcc(self.fft_size, True, mywindow, True) power = 0 for tap in mywindow: power += tap*tap c2mag = blocks.complex_to_mag_squared(self.fft_size) # print c2mag # FIXME the log10 primitive is dog slow #log = blocks.nlog10_ff(10, self.fft_size, # -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) # Set the freq_step to 75% of the actual data throughput. # This allows us to discard the bins on both ends of the spectrum. self.freq_step = self.nearest_freq((0.75 * self.usrp_rate), self.channel_bandwidth) self.min_center_freq = self.min_freq + (self.freq_step/2) nsteps = math.ceil((self.max_freq - self.min_freq) / self.freq_step) self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq tune_delay = max(0, int(round(options.tune_delay * usrp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int(round(options.dwell_delay * usrp_rate / self.fft_size))) # in fft_frames self.msgq = gr.msg_queue(1) self._tune_callback = tune(self) # hang on to this to keep it from being GC'd stats = blocks.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) # FIXME leave out the log10 until we speed it up #self.connect(self.u, s2v, ffter, c2mag, log, stats) self.connect(self.u, dc_blocker, s2v, ffter, c2mag, stats) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start()+g.stop())/2.0 self.set_gain(options.gain) print "gain =", options.gain
def __init__(self): gr.top_block.__init__(self) # usage = "usage: %prog [options] min_freq max_freq" usage = "usage: %prog [options] mycenter_freq show_band" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-a", "--args", type="string", default="", help="UHD device device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate [default=%default]") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("", "--tune-delay", type="eng_float", default=0.25, metavar="SECS", help="time to delay (in seconds) after changing frequency [default=%default]") parser.add_option("", "--dwell-delay", type="eng_float", default=0.25, metavar="SECS", help="time to dwell (in seconds) at a given frequency [default=%default]") # parser.add_option("-b", "--channel-bandwidth", type="eng_float", # default=6.25e3, metavar="Hz", # help="channel bandwidth of fft bins in Hz [default=%default]")#这个应该是频率分辨度(的而他f) parser.add_option("-l", "--lo-offset", type="eng_float", default=0, metavar="Hz", help="lo_offset in Hz [default=%default]") parser.add_option("-q", "--squelch-threshold", type="eng_float", default=None, metavar="dB", help="squelch threshold in dB [default=%default]") parser.add_option("-F", "--fft-size", type="int", default=None, help="specify number of FFT bins [default=1024]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") (options, args) = parser.parse_args() if len(args) != 2: parser.print_help() sys.exit(1) # self.channel_bandwidth = options.channel_bandwidth myusrprate=options.samp_rate self.fft_size = options.fft_size self.channel_bandwidth = myusrprate/self.fft_size self.mycenter_freq = eng_notation.str_to_num(args[0]) self.show_band = eng_notation.str_to_num(args[1]) if self.show_band >myusrprate: sys.stderr.write("error:show_band must be smaller than samplerate\n") sys.exit(1) show_band=self.show_band #add temp_varible=show_band/2 self.min_freq = self.mycenter_freq - temp_varible self.max_freq = self.mycenter_freq + temp_varible args[0]=eng_notation.num_to_str(self.min_freq) args[1]=eng_notation.num_to_str(self.max_freq) # if self.min_freq > self.max_freq: # # swap them # self.min_freq, self.max_freq = self.max_freq, self.min_freq if not options.real_time:#尝试使用实时调度 realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" # build graph应该是调用真实的usrp的信号self.u有地址和数据 self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if(options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if(options.antenna): self.u.set_antenna(options.antenna, 0) self.u.set_samp_rate(options.samp_rate) self.usrp_rate = usrp_rate = self.u.get_samp_rate() self.lo_offset = options.lo_offset self.squelch_threshold = options.squelch_threshold s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)#stream_to_vector mywindow = filter.window.blackmanharris(self.fft_size) ffter = fft.fft_vcc(self.fft_size, True, mywindow, True)#滤波参数 power = 0 for tap in mywindow: power += tap*tap c2mag = blocks.complex_to_mag_squared(self.fft_size)#平方运算 # FIXME the log10 primitive is dog slow #log = blocks.nlog10_ff(10, self.fft_size, # -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) # Set the freq_step to 75% of the actual data throughput. # This allows us to discard the bins on both ends of the spectrum. self.freq_step = self.nearest_freq(show_band, self.channel_bandwidth)#频率分辨率的整数倍(并不等于自己设置的那个),也是扫频长度 self.center_freq = self.min_freq + (self.freq_step/2)#算最小中心频率 # nsteps = math.ceil((self.max_freq - self.min_freq) / self.freq_step) # self.center_freq = self.min_center_freq + self.freq_step self.next_freq = self.center_freq tune_delay = max(0, int(round(options.tune_delay * usrp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int(round(options.dwell_delay * usrp_rate / self.fft_size))) # in fft_frames self.msgq = gr.msg_queue(1) self._tune_callback = tune(self) # 是USRP调谐频率过程的一个程序句柄,有了它,stats就可以调用调谐子程序了hang on to this to keep it from being GC'd stats = blocks.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay,#等待时间,扫频时间等可能都在这个函数中实现 dwell_delay) #构建一个bin统计数据块(可能是计算出下一个的中心频率) print "usrp_rate=",self.usrp_rate,"channel_bandwidth(频谱分辨率)=",self.channel_bandwidth,\ "fft_size= ",self.fft_size ,"freq_step(扫频长度)=", self.freq_step # FIXME leave out the log10 until we speed it up #self.connect(self.u, s2v, ffter, c2mag, log, stats) self.connect(self.u, s2v, ffter, c2mag, stats) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start()+g.stop())/2.0 self.set_gain(options.gain) print "gain =", options.gain
def __init__(self): gr.top_block.__init__(self) usage = "usage: %prog [options] min_freq max_freq" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option( "-a", "--args", type="string", default="", help="UHD device device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate [default=%default]") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option( "", "--tune-delay", type="eng_float", default=20e-3, metavar="SECS", help= "time to delay (in seconds) after changing frequency [default=%default]" ) parser.add_option( "", "--dwell-delay", type="eng_float", default=1e-3, metavar="SECS", help= "time to dwell (in seconds) at a given frequncy [default=%default]" ) parser.add_option("-F", "--fft-size", type="int", default=2048, help="specify number of FFT bins [default=%default]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") parser.add_option("-d", "--decim", type="intx", default=4, help="set decimation to DECIM [default=%default]") (options, args) = parser.parse_args() if len(args) != 2: parser.print_help() sys.exit(1) Freq = Value('i', 9475 * 10**5) self.min_freq = Freq.value - ( 10 * 10**6 ) # same as that of the transmitter bandwidth ie 6MHZ approx for a given value of decimation line option any more self.max_freq = Freq.value + (10 * 10**6) if self.min_freq > self.max_freq: self.min_freq, self.max_freq = self.max_freq, self.min_freq self.fft_size = options.fft_size if not options.real_time: realtime = False else: r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) if (options.spec): self.u.set_subdev_spec(options.spec, 0) if (options.antenna): self.u.set_antenna(options.antenna, 0) global size size = self.fft_size global samp_rate samp_rate = 100e6 / options.decim self.u.set_samp_rate(samp_rate) s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = fft.window.blackmanharris(self.fft_size) fftvar = fft.fft_vcc(self.fft_size, True, mywindow) power = 0 for tap in mywindow: power += tap * tap c2mag = blocks.complex_to_mag_squared(self.fft_size) log = blocks.nlog10_ff( 10, self.fft_size, -20 * math.log10(self.fft_size) - 10 * math.log10(power / self.fft_size)) self.freq_step = 0 #0.75 * usrp_rate # Modified self.min_center_freq = (self.min_freq + self.max_freq) / 2 nsteps = 100 #math.ceil((self.max_freq - self.min_freq) / self.freq_step) self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq tune_delay = max(0, int( round(options.tune_delay * samp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int( round(options.dwell_delay * samp_rate / self.fft_size))) # in fft_frames self.msgq = gr.msg_queue(16) self._tune_callback = tune( self) # hang on to this to keep it from being GC'd stats = blocks.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) self.connect(self.u, s2v, fftvar, c2mag, stats) if options.gain is None: g = self.u.get_gain_range() options.gain = float(g.start() + g.stop()) / 2.0
def __init__(self): gr.top_block.__init__(self) usage = "usage: %prog [options] down_freq" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option( "-a", "--args", type="string", default="", help="UHD device device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=10e6, help="set sample rate [default=%default]") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option( "", "--tune-delay", type="eng_float", default=0.25, metavar="SECS", help= "time to delay (in seconds) after changing frequency [default=%default]" ) parser.add_option( "", "--dwell-delay", type="eng_float", default=0.25, metavar="SECS", help= "time to dwell (in seconds) at a given frequency [default=%default]" ) parser.add_option( "-b", "--channel-bandwidth", type="eng_float", default=9.7656e3, metavar="Hz", help="channel bandwidth of fft bins in Hz [default=%default]") parser.add_option("-l", "--lo-offset", type="eng_float", default=0, metavar="Hz", help="lo_offset in Hz [default=%default]") parser.add_option("-q", "--squelch-threshold", type="eng_float", default=None, metavar="dB", help="squelch threshold in dB [default=%default]") parser.add_option( "-F", "--fft-size", type="int", default=None, help="specify number of FFT bins [default=samp_rate/channel_bw]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") (options, args) = parser.parse_args() if len(args) != 1: parser.print_help() sys.exit(1) self.channel_bandwidth = options.channel_bandwidth self.down_freq = eng_notation.str_to_num(args[0]) self.up_freq = self.down_freq - 45e6 if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" # build graph self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if (options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if (options.antenna): self.u.set_antenna(options.antenna, 0) self.u.set_samp_rate(options.samp_rate) self.usrp_rate = usrp_rate = self.u.get_samp_rate() self.lo_offset = options.lo_offset if options.fft_size is None: self.fft_size = int(self.usrp_rate / self.channel_bandwidth) else: self.fft_size = options.fft_size self.squelch_threshold = options.squelch_threshold s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = filter.window.blackmanharris(self.fft_size) ffter = fft.fft_vcc(self.fft_size, True, mywindow, True) power = 0 for tap in mywindow: power += tap * tap c2mag = blocks.complex_to_mag_squared(self.fft_size) tune_delay = max(0, int( round(options.tune_delay * usrp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int( round(options.dwell_delay * usrp_rate / self.fft_size))) # in fft_frames self.msgq = gr.msg_queue(1) self._tune_callback = tune( self) # hang on to this to keep it from being GC'd stats = blocks.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) # FIXME leave out the log10 until we speed it up #self.connect(self.u, s2v, ffter, c2mag, log, stats) self.connect(self.u, s2v, ffter, c2mag, stats) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start() + g.stop()) / 2.0 self.set_gain(options.gain) print "gain =", options.gain
def __init__(self): gr.top_block.__init__(self) usage = "usage: %prog [options] min_freq max_freq" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-a", "--args", type="string", default="addr=192.168.10.2", help="UHD device device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default="TX/RX", help="select Rx Antenna where appropriate [default=%default]") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate [default=%default]") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-i", "--ip", type="string", default='192.168.10.1', help="ip address of server [default=%default]") parser.add_option("-p", "--port", type="int", default=9001, help="port for network connection [default=%default]") parser.add_option("", "--tune-delay", type="eng_float", default=0.25, metavar="SECS", help="time to delay (in seconds) after changing frequency [default=%default]") parser.add_option("", "--dwell-delay", type="eng_float", default=0.25, metavar="SECS", help="time to dwell (in seconds) at a given frequency [default=%default]") parser.add_option("-b", "--channel-bandwidth", type="eng_float", default=6.25e3, metavar="Hz", help="channel bandwidth of fft bins in Hz [default=%default]") parser.add_option("-l", "--lo-offset", type="eng_float", default=0, metavar="Hz", help="lo_offset in Hz [default=%default]") parser.add_option("-q", "--squelch-threshold", type="eng_float", default=None, metavar="dB", help="squelch threshold in dB [default=%default]") parser.add_option("-F", "--fft-size", type="int", default=None, help="specify number of FFT bins [default=samp_rate/channel_bw]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") #Parse options (options, args) = parser.parse_args() if len(args) != 2: parser.print_help() min_fbound = '400e6' max_fbound = '4.4e9' else: max_fbound = args[1] min_fbound = args[0] self.channel_bandwidth = options.channel_bandwidth #self.min_freq = eng_notation.str_to_num(args[0]) #self.max_freq = eng_notation.str_to_num(args[1]) #if self.min_freq > self.max_freq: # swap them #self.min_freq, self.max_freq = self.max_freq, self.min_freq if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" # USRP SOURCE CONFIG self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if(options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if(options.antenna): self.u.set_antenna(options.antenna, 0) self.u.set_samp_rate(options.samp_rate) self.usrp_rate = usrp_rate = self.u.get_samp_rate() #FFT CONFIG self.lo_offset = options.lo_offset if options.fft_size is None: self.fft_size = int(self.usrp_rate/self.channel_bandwidth) else: self.fft_size = options.fft_size self.squelch_threshold = options.squelch_threshold self.freq_step = self.nearest_freq((0.75 * self.usrp_rate), self.channel_bandwidth) self.set_fbounds(max_fbound, min_fbound) s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = filter.window.blackmanharris(self.fft_size) ffter = fft.fft_vcc(self.fft_size, True, mywindow, True) power = 0 for tap in mywindow: power += tap*tap #COMPLEX TO MAG CONFIG c2mag = blocks.complex_to_mag_squared(self.fft_size) # FIXME the log10 primitive is dog slow #log = blocks.nlog10_ff(10, self.fft_size, # -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) # Set the freq_step to 75% of the actual data throughput. # This allows us to discard the bins on both ends of the spectrum. tune_delay = max(0, int(round(options.tune_delay * usrp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int(round(options.dwell_delay * usrp_rate / self.fft_size))) # in fft_frames #BIN_STATISTICS CONFIG self.msgq = gr.msg_queue(1) self._tune_callback = tune(self) # hang on to this to keep it from being GC'd stats = blocks.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) #IP CORE CONFIG self.ip = options.ip self.port = options.port self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.s.bind(("",self.port)) #self.s.listen(1) print "Waiting for connection at", self.ip, "using port", self.port data, self.connAdd = self.s.recvfrom(self.port) self.s.sendto("Ack", self.connAdd) print "Connection recieved from", self.connAdd #CONNECT ALL THE THINGS # FIXME leave out the log10 until we speed it up #self.connect(self.u, s2v, ffter, c2mag, log, stats) self.connect(self.u, s2v, ffter, c2mag, stats) #Do gain things if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start()+g.stop())/2.0 self.set_gain(options.gain)
def __init__(self): gr.top_block.__init__(self) usage = "usage: %prog [options] min_freq max_freq" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-R", "--rx-antenna", type="string", default="RX2", help="select RX antenna where appropriate") parser.add_option("-T", "--tx-antenna", type="string", default="TX/RX", help="select TX antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate [default=%default]") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option( "", "--tune-delay", type="eng_float", default=0.25, metavar="SECS", help= "time to delay (in seconds) after changing frequency [default=%default]" ) parser.add_option( "", "--dwell-delay", type="eng_float", default=0.25, metavar="SECS", help= "time to delay (in seconds) at a given frequency [default=%default]" ) parser.add_option( "-b", "--channel-bandwidth", type="eng_float", default=6.25e3, metavar="Hz", help="channel bandwidth of fft bins in Hz [default=%default]") parser.add_option("-l", "--lo-offset", type="eng_float", default=0, metavar="Hz", help="lo_offset in Hz [default=%default]") parser.add_option("-q", "--squelch-threshold", type="eng_float", default=None, metavar="dB", help="squelch threshold in dB [default=%default]") parser.add_option( "-F", "--fft-size", type="int", default=None, help="specify the number of FFT bins [default=samp_rate/channel_bw]" ) parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") parser.add_option( "-w", "--tx-bandwidth", type="eng_float", default=6e6, metavar="Hz", help="transmit frequency bandwidth [default=%default]") (options, args) = parser.parse_args() if len(args) != 2: parser.print_help() sys.exit(1) self.channel_bandwidth = options.channel_bandwidth #fft channel bandwidth self.tx_bandwidth = options.tx_bandwidth self.min_freq = eng_notation.str_to_num(args[0]) self.max_freq = eng_notation.str_to_num(args[1]) if self.min_freq < 1e6: self.min_freq *= 1e6 if self.max_freq < 1e6: self.max_freq *= 1e6 self.n_channel_grps = 5 #number of channel groups self.curr_channel_grp = 0 self.n_channels = 5 #number of channels / channel group self.curr_channel = 0 self.tx_guard_band = 4e6 if self.min_freq > self.max_freq: #swap them self.min_freq, self.max_freq = self.max_freq, self.min_freq self.channel_grp_bw = (self.max_freq - self.min_freq) / self.n_channel_grps self.tx_channel_bw = self.channel_grp_bw / self.n_channels # tx channel bw if not options.real_time: real_time = False else: #Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" #build graph self.u_rx = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) #Set the subdevice spec if options.spec: self.u_rx.set_subdev_spec(options.spec, 0) #Set the antenna if options.rx_antenna: self.u_rx.set_antenna(options.rx_antenna, 0) self.u_rx.set_samp_rate(options.samp_rate) self.usrp_rate = usrp_rate = self.u_rx.get_samp_rate() self.lo_offset = options.lo_offset if options.fft_size is None: self.fft_size = int(self.usrp_rate / self.channel_bandwidth) else: self.fft_size = options.fft_size print "FFT Size: %d, USRP Samp Rate: %d, Channel Bandwidth: %d" % ( self.fft_size, self.usrp_rate, self.channel_bandwidth) self.squelch_threshold = options.squelch_threshold s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = filter.window.blackmanharris(self.fft_size) ffter = fft.fft_vcc(self.fft_size, True, mywindow, True) c2mag = blocks.complex_to_mag_squared(self.fft_size) tune_delay = max(0, int( round(options.tune_delay * usrp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int( round(options.dwell_delay * usrp_rate / self.fft_size))) # in fft frames self.msgq = gr.msg_queue(1) self._tune_callback = tune( self) #hang on to this to keep it from being GC'd stats = blocks.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) self.connect(self.u_rx, s2v, ffter, c2mag, stats) #transmit chain d = uhd.find_devices(uhd.device_addr(options.args)) if d: uhd_type = d[0].get('type') print "\nFound '%s'" % uhd_type else: print "\nNo device found" self.u_tx = None return #check version of USRP and set num_channels if uhd_type == "usrp": tx_nchan = 2 rx_nchan = 2 else: tx_nchan = 1 rx_nchan = 1 #setup transmit chain (usrp sink, signal source) #usrp sink stream_args = uhd.stream_args('fc32', channels=range(tx_nchan)) self.u_tx = uhd.usrp_sink(device_addr=options.args, stream_args=stream_args) self.u_tx.set_samp_rate(self.usrp_rate) if options.tx_antenna: self.u_tx.set_antenna(options.tx_antenna, 0) #analog signal source - sig_source_c(sampling_freq,waveform, wave_freq, ampl, offset=0) self.tx_src0 = analog.sig_source_c(self.u_tx.get_samp_rate(), analog.GR_CONST_WAVE, 0, 1.0, 0) #connect blocks self.connect(self.tx_src0, self.u_tx) if options.gain is None: # if no gain was specified use the midpoint in dB g = self.u_rx.get_gain_range() options.gain = float(g.start() + g.stop()) / 2.0 self.set_gain(options.gain) print "gain =", options.gain #initialize transmission parameters self.set_channel_group(3) self.step_count = 0
def __init__(self): gr.top_block.__init__(self) usage = "usage: %prog [options] min_freq max_freq" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-a", "--args", type="string", default="", help="UHD device device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate [default=%default]") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("", "--tune-delay", type="eng_float", default=20e-3, metavar="SECS", help="time to delay (in seconds) after changing frequency [default=%default]") parser.add_option("", "--dwell-delay", type="eng_float", default=1e-3, metavar="SECS", help="time to dwell (in seconds) at a given frequncy [default=%default]") parser.add_option("-F", "--fft-size", type="int", default=2048 , help="specify number of FFT bins [default=%default]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") parser.add_option("-d", "--decim", type="intx", default=4, help="set decimation to DECIM [default=%default]") (options, args) = parser.parse_args() if len(args) != 2: parser.print_help() sys.exit(1) Freq=Value('i',9475*10**5) self.min_freq = Freq.value-(10*10**6) # same as that of the transmitter bandwidth ie 6MHZ approx for a given value of decimation line option any more self.max_freq = Freq.value+(10*10**6) if self.min_freq > self.max_freq: self.min_freq, self.max_freq = self.max_freq, self.min_freq self.fft_size = options.fft_size if not options.real_time: realtime = False else: r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) if(options.spec): self.u.set_subdev_spec(options.spec, 0) if(options.antenna): self.u.set_antenna(options.antenna, 0) global size size=self.fft_size global samp_rate samp_rate = 100e6/options.decim self.u.set_samp_rate(samp_rate) s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = fft.window.blackmanharris(self.fft_size) fftvar = fft.fft_vcc(self.fft_size, True, mywindow) power = 0 for tap in mywindow: power += tap*tap c2mag = blocks.complex_to_mag_squared(self.fft_size) log = blocks.nlog10_ff(10, self.fft_size, -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) self.freq_step = 0 #0.75 * usrp_rate # Modified self.min_center_freq = (self.min_freq + self.max_freq)/2 nsteps = 100 #math.ceil((self.max_freq - self.min_freq) / self.freq_step) self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq tune_delay = max(0, int(round(options.tune_delay * samp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int(round(options.dwell_delay * samp_rate / self.fft_size))) # in fft_frames self.msgq = gr.msg_queue(16) self._tune_callback = tune(self) # hang on to this to keep it from being GC'd stats = blocks.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) self.connect(self.u, s2v, fftvar, c2mag, stats) if options.gain is None: g = self.u.get_gain_range() options.gain = float(g.start()+g.stop())/2.0
def __init__(self): gr.top_block.__init__(self) usage = "usage: %prog [options] min_freq max_freq" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option( "-a", "--args", type="string", default="addr=192.168.10.2", help="UHD device device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option( "-A", "--antenna", type="string", default="TX/RX", help="select Rx Antenna where appropriate [default=%default]") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate [default=%default]") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-i", "--ip", type="string", default='192.168.10.1', help="ip address of server [default=%default]") parser.add_option( "-p", "--port", type="int", default=9001, help="port for network connection [default=%default]") parser.add_option( "", "--tune-delay", type="eng_float", default=0.25, metavar="SECS", help= "time to delay (in seconds) after changing frequency [default=%default]" ) parser.add_option( "", "--dwell-delay", type="eng_float", default=0.25, metavar="SECS", help= "time to dwell (in seconds) at a given frequency [default=%default]" ) parser.add_option( "-b", "--channel-bandwidth", type="eng_float", default=6.25e3, metavar="Hz", help="channel bandwidth of fft bins in Hz [default=%default]") parser.add_option("-l", "--lo-offset", type="eng_float", default=0, metavar="Hz", help="lo_offset in Hz [default=%default]") parser.add_option("-q", "--squelch-threshold", type="eng_float", default=None, metavar="dB", help="squelch threshold in dB [default=%default]") parser.add_option( "-F", "--fft-size", type="int", default=None, help="specify number of FFT bins [default=samp_rate/channel_bw]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") #Parse options (options, args) = parser.parse_args() if len(args) != 2: parser.print_help() min_fbound = '400e6' max_fbound = '4.4e9' else: max_fbound = args[1] min_fbound = args[0] self.channel_bandwidth = options.channel_bandwidth #self.min_freq = eng_notation.str_to_num(args[0]) #self.max_freq = eng_notation.str_to_num(args[1]) #if self.min_freq > self.max_freq: # swap them #self.min_freq, self.max_freq = self.max_freq, self.min_freq if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" # USRP SOURCE CONFIG self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if (options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if (options.antenna): self.u.set_antenna(options.antenna, 0) self.u.set_samp_rate(options.samp_rate) self.usrp_rate = usrp_rate = self.u.get_samp_rate() #FFT CONFIG self.lo_offset = options.lo_offset if options.fft_size is None: self.fft_size = int(self.usrp_rate / self.channel_bandwidth) else: self.fft_size = options.fft_size self.squelch_threshold = options.squelch_threshold self.freq_step = self.nearest_freq((0.75 * self.usrp_rate), self.channel_bandwidth) self.set_fbounds(max_fbound, min_fbound) s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = filter.window.blackmanharris(self.fft_size) ffter = fft.fft_vcc(self.fft_size, True, mywindow, True) power = 0 for tap in mywindow: power += tap * tap #COMPLEX TO MAG CONFIG c2mag = blocks.complex_to_mag_squared(self.fft_size) # FIXME the log10 primitive is dog slow #log = blocks.nlog10_ff(10, self.fft_size, # -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) # Set the freq_step to 75% of the actual data throughput. # This allows us to discard the bins on both ends of the spectrum. tune_delay = max(0, int( round(options.tune_delay * usrp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int( round(options.dwell_delay * usrp_rate / self.fft_size))) # in fft_frames #BIN_STATISTICS CONFIG self.msgq = gr.msg_queue(1) self._tune_callback = tune( self) # hang on to this to keep it from being GC'd stats = blocks.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) #IP CORE CONFIG self.ip = options.ip self.port = options.port self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.s.bind(("", self.port)) #self.s.listen(1) print "Waiting for connection at", self.ip, "using port", self.port data, self.connAdd = self.s.recvfrom(self.port) self.s.sendto("Ack", self.connAdd) print "Connection recieved from", self.connAdd #CONNECT ALL THE THINGS # FIXME leave out the log10 until we speed it up #self.connect(self.u, s2v, ffter, c2mag, log, stats) self.connect(self.u, s2v, ffter, c2mag, stats) #Do gain things if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start() + g.stop()) / 2.0 self.set_gain(options.gain)
def __init__(self): gr.top_block.__init__(self) usage = "usage: %prog [options] min_freq max_freq" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-a", "--args", type="string", default="", help="Device args [default=%default]") parser.add_option("-A", "--antenna", type="string", default=None, help="Select antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=None, help="Set sample rate (bandwidth), minimum by default") parser.add_option("-g", "--gain", type="eng_float", default=None, help="Set gain in dB (default is midpoint)") parser.add_option("", "--tune-delay", type="eng_float", default=0.25, metavar="SECS", help="Time to delay (in seconds) after changing frequency [default=%default]") parser.add_option("", "--dwell-delay", type="eng_float", default=0.25, metavar="SECS", help="Time to dwell (in seconds) at a given frequency [default=%default]") parser.add_option("-b", "--channel-bandwidth", type="eng_float", default=6.25e3, metavar="Hz", help="Channel bandwidth of fft bins in Hz [default=%default]") parser.add_option("-q", "--squelch-threshold", type="eng_float", default=None, metavar="dB", help="Squelch threshold in dB [default=%default]") parser.add_option("-F", "--fft-size", type="int", default=None, help="Specify number of FFT bins [default=samp_rate/channel_bw]") parser.add_option("", "--real-time", action="store_true", default=False, help="Attempt to enable real-time scheduling") parser.add_option("-m", "--amp-multiply",type="eng_float",default=25.5, help="Specify amplitude multiplier") (options, args) = parser.parse_args() if len(args) != 2: parser.print_help() sys.exit(1) self.channel_bandwidth = options.channel_bandwidth self.min_freq = eng_notation.str_to_num(args[0]) self.max_freq = eng_notation.str_to_num(args[1]) try: if options.amp_multiply > 1 or options.amp_multiply <255: self.amp_multiply = options.amp_multiply except: print 'amplification multiplier not valid' if self.min_freq > self.max_freq: # swap them self.min_freq, self.max_freq = self.max_freq, self.min_freq if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" # build graph self.u = osmosdr.source(options.args) try: self.u.get_sample_rates().start() except RuntimeError: print "Source has no sample rates (wrong device arguments?)." sys.exit(1) # Set the antenna if(options.antenna): self.u.set_antenna(options.antenna, 0) if options.samp_rate is None: options.samp_rate = self.u.get_sample_rates().start() self.u.set_sample_rate(options.samp_rate) self.usrp_rate = usrp_rate = self.u.get_sample_rate() if options.fft_size is None: self.fft_size = int(self.usrp_rate/self.channel_bandwidth) else: self.fft_size = options.fft_size self.squelch_threshold = options.squelch_threshold s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = filter.window.blackmanharris(self.fft_size) ffter = fft.fft_vcc(self.fft_size, True, mywindow, True) power = 0 for tap in mywindow: power += tap*tap c2mag = blocks.complex_to_mag_squared(self.fft_size) # FIXME the log10 primitive is dog slow #log = blocks.nlog10_ff(10, self.fft_size, # -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size)) # Set the freq_step to 75% of the actual data throughput. # This allows us to discard the bins on both ends of the spectrum. self.freq_step = self.nearest_freq((0.75 * self.usrp_rate), self.channel_bandwidth) self.min_center_freq = self.min_freq + (self.freq_step/2) nsteps = math.ceil((self.max_freq - self.min_freq) / self.freq_step) self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq tune_delay = max(0, int(round(options.tune_delay * usrp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int(round(options.dwell_delay * usrp_rate / self.fft_size))) # in fft_frames self.msgq = gr.msg_queue(1) self._tune_callback = tune(self) # hang on to this to keep it from being GC'd stats = blocks.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) # FIXME leave out the log10 until we speed it up #self.connect(self.u, s2v, ffter, c2mag, log, stats) self.connect(self.u, s2v, ffter, c2mag, stats) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start()+g.stop())/2.0 self.set_gain(options.gain) print "gain =", options.gain
def __init__(self, parser): gr.top_block.__init__(self) (options, args) = parser.parse_args() self.channel_bandwidth = options.channel_bandwidth self.min_freq = eng_notation.str_to_num(args[0]) self.max_freq = eng_notation.str_to_num(args[1]) if self.min_freq > self.max_freq: # swap them self.min_freq, self.max_freq = self.max_freq, self.min_freq if not options.real_time: realtime = False else: # Attempt to enable realtime scheduling r = gr.enable_realtime_scheduling() if r == gr.RT_OK: realtime = True else: realtime = False print "Note: failed to enable realtime scheduling" # build graph self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if (options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if (options.antenna): self.u.set_antenna(options.antenna, 0) self.u.set_samp_rate(options.samp_rate) self.usrp_rate = usrp_rate = self.u.get_samp_rate() self.lo_offset = options.lo_offset if options.fft_size is None: self.fft_size = int(self.usrp_rate / self.channel_bandwidth) else: self.fft_size = options.fft_size self.squelch_threshold = options.squelch_threshold s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) mywindow = filter.window.blackmanharris(self.fft_size) ffter = fft.fft_vcc(self.fft_size, True, mywindow, True) power = 0 for tap in mywindow: power += tap * tap c2mag = blocks.complex_to_mag_squared(self.fft_size) # Set the freq_step to 75% of the actual data throughput. # This allows us to discard the bins on both ends of the spectrum. self.freq_step = self.nearest_freq((0.75 * self.usrp_rate), self.channel_bandwidth) self.min_center_freq = self.min_freq + (self.freq_step / 2) nsteps = math.ceil((self.max_freq - self.min_freq) / self.freq_step) self.max_center_freq = self.min_center_freq + (nsteps * self.freq_step) self.next_freq = self.min_center_freq tune_delay = max(0, int( round(options.tune_delay * usrp_rate / self.fft_size))) # in fft_frames dwell_delay = max(1, int( round(options.dwell_delay * usrp_rate / self.fft_size))) # in fft_frames self.msgq = gr.msg_queue(1) self._tune_callback = tune(self) stats = blocks.bin_statistics_f(self.fft_size, self.msgq, self._tune_callback, tune_delay, dwell_delay) self.connect(self.u, s2v, ffter, c2mag, stats) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start() + g.stop()) / 2.0 self.set_gain(options.gain) print "gain =", options.gain