def __init__(self): gr.top_block.__init__(self) #build graph now #usrp_source self.usrp = usrp.source_c() adc_rate = self.usrp.adc_rate() #64MHz hw_decim = 16 #so Sample rate into host is 4MHz self.usrp.set_decim_rate(hw_decim) self.subdev = usrp.selected_subdev(self.usrp, usrp.pick_rx_subdevice(self.usrp)) self.usrp.set_mux( usrp.determine_rx_mux_value(self.usrp, usrp.pick_rx_subdevice(self.usrp))) print "Using RX d'board %s" % (self.subdev.side_and_name(), ) self.subdev.set_gain(30) rf_freq = 106800000 # 106.8MHz self.set_freq(rf_freq) print "Freq: ", rf_freq self.subdev.select_rx_antenna("TX/RX") #low pass filter self.sample_rate = adc_rate / hw_decim self.lpf_decim = 20 # so after channel filter, the sample rate is 200KHz self.lp_filter = gr.fir_filter_ccf( self.lpf_decim, gr.firdes.low_pass( 1, self.sample_rate, 100e3, # cut off freq 10e3, # transition band gr.firdes.WIN_BLACKMAN, # Window function 6.76 # not used )) # WBFM receiver self.fm_decoder = blks2.wfm_rcv(quad_rate=200000, audio_decimation=1) # Rational Resampler self.audio_sample_rate = 96000 self.rational_resampler = blks2.rational_resampler_fff( interpolation=int(self.audio_sample_rate / 1000), decimation=int(self.sample_rate / self.lpf_decim / 1000), taps=None, fractional_bw=None, ) self.audio_sink = audio.sink(int(self.audio_sample_rate), "", True) #connections self.connect(self.usrp, self.lp_filter, self.fm_decoder, self.rational_resampler, self.audio_sink)
def __init__(self): gr.top_block.__init__(self) #build graph now #usrp_source self.usrp = usrp.source_c() adc_rate = self.usrp.adc_rate() #64MHz hw_decim = 16 #so Sample rate into host is 4MHz self.usrp.set_decim_rate(hw_decim) self.subdev = usrp.selected_subdev(self.usrp, usrp.pick_rx_subdevice(self.usrp)) self.usrp.set_mux(usrp.determine_rx_mux_value(self.usrp, usrp.pick_rx_subdevice(self.usrp))) print "Using RX d'board %s" % (self.subdev.side_and_name(),) self.subdev.set_gain(30) rf_freq = 106800000 # 106.8MHz self.set_freq(rf_freq) print "Freq: ", rf_freq self.subdev.select_rx_antenna("TX/RX") #low pass filter self.sample_rate = adc_rate / hw_decim self.lpf_decim = 20 # so after channel filter, the sample rate is 200KHz self.lp_filter = gr.fir_filter_ccf( self.lpf_decim, gr.firdes.low_pass ( 1, self.sample_rate, 100e3, # cut off freq 10e3, # transition band gr.firdes.WIN_BLACKMAN, # Window function 6.76 # not used )) # WBFM receiver self.fm_decoder = blks2.wfm_rcv ( quad_rate = 200000, audio_decimation = 1 ) # Rational Resampler self.audio_sample_rate = 96000 self.rational_resampler = blks2.rational_resampler_fff ( interpolation = int(self.audio_sample_rate/1000), decimation = int(self.sample_rate/self.lpf_decim/1000), taps = None, fractional_bw = None, ) self.audio_sink = audio.sink (int(self.audio_sample_rate), "", True) #connections self.connect ( self.usrp, self.lp_filter, self.fm_decoder, self.rational_resampler, self.audio_sink )
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-f", "--freq", type="eng_float", default=100.1e6, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-V", "--volume", type="eng_float", default=None, help="set volume (default is midpoint)") parser.add_option( "-O", "--audio-output", type="string", default="default", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") parser.add_option("", "--freq-min", type="eng_float", default=87.9e6, help="Set a minimum frequency [default=%default]") parser.add_option("", "--freq-max", type="eng_float", default=108.1e6, help="Set a maximum frequency [default=%default]") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.state = "FREQ" self.freq = 0 self.fm_freq_min = options.freq_min self.fm_freq_max = options.freq_max # 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) usrp_rate = 320e3 demod_rate = 320e3 audio_rate = 32e3 audio_decim = int(demod_rate / audio_rate) self.u.set_samp_rate(usrp_rate) dev_rate = self.u.get_samp_rate() nfilts = 32 chan_coeffs = optfir.low_pass( nfilts, # gain nfilts * usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation rrate = usrp_rate / dev_rate self.chan_filt = blks2.pfb_arb_resampler_ccf(rrate, chan_coeffs, nfilts) self.guts = blks2.wfm_rcv(demod_rate, audio_decim) self.volume_control = gr.multiply_const_ff(1) # sound card as final sink self.audio_sink = audio.sink(int(audio_rate), options.audio_output, False) # ok_to_block # now wire it all together self.connect(self.u, self.chan_filt, self.guts, self.volume_control, self.audio_sink) 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 if options.volume is None: g = self.volume_range() options.volume = float(g[0] + g[1]) / 2 frange = self.u.get_freq_range() if (frange.start() > self.fm_freq_max or frange.stop() < self.fm_freq_min): sys.stderr.write( "Radio does not support required frequency range.\n") sys.exit(1) if (options.freq < self.fm_freq_min or options.freq > self.fm_freq_max): sys.stderr.write( "Requested frequency is outside of required frequency range.\n" ) sys.exit(1) # set initial values self.set_gain(options.gain) self.set_vol(options.volume) if not (self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-e", "--interface", type="string", default="eth0", help="select Ethernet interface, default is eth0") parser.add_option("-m", "--mac-addr", type="string", default="", help="select USRP by MAC address, default is auto-select") #parser.add_option("-A", "--antenna", default=None, # help="select Rx Antenna (only on RFX-series boards)") parser.add_option("-f", "--freq", type="eng_float", default=100.1, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-V", "--volume", type="eng_float", default=None, help="set volume (default is midpoint)") parser.add_option("-O", "--audio-output", type="string", default="", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self._volume = options.volume self._usrp_freq = options.freq self._usrp_gain = options.gain self._audio_rate = int(32e3) # build graph self.u = usrp2.source_32fc(options.interface, options.mac_addr) # calculate decimation values to get USRP BW at 320 kHz self.calculate_usrp_bw(320e3) self.set_decim(self._usrp_decim) #FIXME: need named constants and text descriptions available to (gr-)usrp2 even #when usrp(1) module is not built. A usrp_common module, perhaps? dbid = self.u.daughterboard_id() print "Using RX d'board 0x%04X" % (dbid,) #if not (dbid == 0x0001 or #usrp_dbid.BASIC_RX # dbid == 0x0003 or #usrp_dbid.TV_RX # dbid == 0x000c or #usrp_dbid.TV_RX_REV_2 # dbid == 0x0040 or #usrp_dbid.TV_RX_REV_3 # dbid == 0x0043 or #usrp_dbid.TV_RX_MIMO # dbid == 0x0044 or #usrp_dbid.TV_RX_REV_2_MIMO # dbid == 0x0045 ): #usrp_dbid.TV_RX_REV_3_MIMO # print "This daughterboard does not cover the required frequency range" # print "for this application. Please use a BasicRX or TVRX daughterboard." # raw_input("Press ENTER to continue anyway, or Ctrl-C to exit.") chan_filt_coeffs = optfir.low_pass (1, # gain self._usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) chan_filt = gr.fir_filter_ccf (self._chanfilt_decim, chan_filt_coeffs) self.guts = blks2.wfm_rcv (self._demod_rate, self._audio_decim) self.volume_control = gr.multiply_const_ff(1) # sound card as final sink #audio_sink = audio.sink (int (audio_rate), # options.audio_output, # False) # ok_to_block audio_sink = audio.sink (self._audio_rate, options.audio_output) if self._usrp_gain is None: # if no gain was specified, use the mid-point in dB g = self.u.gain_range() print "Gain range: ", g self._usrp_gain = float(g[0]+g[1])/2 if self._volume is None: g = self.volume_range() self._volume = float(g[0]+g[1])/2 if abs(self._usrp_freq) < 1e6: self._usrp_freq *= 1e6 # set initial values self.set_gain(self._usrp_gain) self.set_volume(self._volume) if not(self.set_freq(self._usrp_freq)): print ("Failed to set initial frequency") # Define a GUI sink to display the received signal self.qapp = QtGui.QApplication(sys.argv) fftsize = 2048 self.usrp_rx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS, -self._usrp_rate/2.0, self._usrp_rate/2.0, "Received Signal", True, True, False, True, False, use_openGL=False) self.usrp_rx2 = qtgui.sink_f(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS, -self._usrp_rate/2.0, self._usrp_rate/2.0, "Received Signal", True, True, False, True, False) # now wire it all together self.connect (self.u, chan_filt, self.guts, self.volume_control, audio_sink) self.connect (self.u, self.usrp_rx) self.connect (self.volume_control, self.usrp_rx2) usrp_rx_widget = sip.wrapinstance(self.usrp_rx.pyqwidget(), QtGui.QWidget) usrp_rx2_widget = sip.wrapinstance(self.usrp_rx2.pyqwidget(), QtGui.QWidget) self.main_box = dialog_box(usrp_rx_widget, usrp_rx2_widget, self) self.main_box.show()
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Victor's FM Receiver") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.freq_fine = freq_fine = 0 self.volume = volume = 1 self.transition = transition = 1000000 self.samp_rate = samp_rate = 2000000 self.quadrature = quadrature = 500000 self.freq = freq = 96900000+freq_fine self.cutoff = cutoff = 100000 self.audio_dec = audio_dec = 10 ################################################## # Blocks ################################################## _volume_sizer = wx.BoxSizer(wx.VERTICAL) self._volume_text_box = forms.text_box( parent=self.GetWin(), sizer=_volume_sizer, value=self.volume, callback=self.set_volume, label="Volume", converter=forms.float_converter(), proportion=0, ) self._volume_slider = forms.slider( parent=self.GetWin(), sizer=_volume_sizer, value=self.volume, callback=self.set_volume, minimum=0, maximum=10, num_steps=10, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_volume_sizer, 1, 0, 1, 10) _transition_sizer = wx.BoxSizer(wx.VERTICAL) self._transition_text_box = forms.text_box( parent=self.GetWin(), sizer=_transition_sizer, value=self.transition, callback=self.set_transition, label="Filter Transition Band", converter=forms.float_converter(), proportion=0, ) self._transition_slider = forms.slider( parent=self.GetWin(), sizer=_transition_sizer, value=self.transition, callback=self.set_transition, minimum=100000, maximum=3000000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_transition_sizer, 1, 26, 1, 13) self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Pre- Filter FFT") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Pre- Filter Waterfall") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Post- Filter FFT") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Post- Filter Waterfall") self.Add(self.notebook_0) self._freq_text_box = forms.text_box( parent=self.GetWin(), value=self.freq, callback=self.set_freq, label="Exact Frequency", converter=forms.float_converter(), ) self.GridAdd(self._freq_text_box, 0, 0, 1, 10) _cutoff_sizer = wx.BoxSizer(wx.VERTICAL) self._cutoff_text_box = forms.text_box( parent=self.GetWin(), sizer=_cutoff_sizer, value=self.cutoff, callback=self.set_cutoff, label="Filter Cutoff", converter=forms.float_converter(), proportion=0, ) self._cutoff_slider = forms.slider( parent=self.GetWin(), sizer=_cutoff_sizer, value=self.cutoff, callback=self.set_cutoff, minimum=1000, maximum=1000000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_cutoff_sizer, 1, 11, 1, 13) self.wxgui_waterfallsink2_1 = waterfallsink2.waterfall_sink_c( self.notebook_0.GetPage(1).GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", ) self.notebook_0.GetPage(1).Add(self.wxgui_waterfallsink2_1.win) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.notebook_0.GetPage(3).GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", ) self.notebook_0.GetPage(3).Add(self.wxgui_waterfallsink2_0.win) self.wxgui_fftsink2_1 = fftsink2.fft_sink_c( self.notebook_0.GetPage(0).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.notebook_0.GetPage(0).Add(self.wxgui_fftsink2_1.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.notebook_0.GetPage(2).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, win=window.flattop, ) self.notebook_0.GetPage(2).Add(self.wxgui_fftsink2_0.win) self.osmosdr_source_c_0 = osmosdr.source_c( args="nchan=" + str(1) + " " + "" ) self.osmosdr_source_c_0.set_sample_rate(samp_rate) self.osmosdr_source_c_0.set_center_freq(freq, 0) self.osmosdr_source_c_0.set_freq_corr(0, 0) self.osmosdr_source_c_0.set_dc_offset_mode(0, 0) self.osmosdr_source_c_0.set_iq_balance_mode(0, 0) self.osmosdr_source_c_0.set_gain_mode(0, 0) self.osmosdr_source_c_0.set_gain(10, 0) self.osmosdr_source_c_0.set_if_gain(20, 0) self.osmosdr_source_c_0.set_bb_gain(20, 0) self.osmosdr_source_c_0.set_antenna("", 0) self.osmosdr_source_c_0.set_bandwidth(0, 0) self.low_pass_filter_0 = gr.fir_filter_ccf(1, firdes.low_pass( 1, samp_rate, cutoff, transition, firdes.WIN_HAMMING, 6.76)) _freq_fine_sizer = wx.BoxSizer(wx.VERTICAL) self._freq_fine_text_box = forms.text_box( parent=self.GetWin(), sizer=_freq_fine_sizer, value=self.freq_fine, callback=self.set_freq_fine, label="Fine Frequency Adjust", converter=forms.float_converter(), proportion=0, ) self._freq_fine_slider = forms.slider( parent=self.GetWin(), sizer=_freq_fine_sizer, value=self.freq_fine, callback=self.set_freq_fine, minimum=-2000000, maximum=2000000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_freq_fine_sizer, 0, 11, 1, 30) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((volume, )) self.blks2_wfm_rcv_0 = blks2.wfm_rcv( quad_rate=quadrature, audio_decimation=audio_dec, ) self.audio_sink_0 = audio.sink(samp_rate, "", True) ################################################## # Connections ################################################## self.connect((self.low_pass_filter_0, 0), (self.blks2_wfm_rcv_0, 0)) self.connect((self.osmosdr_source_c_0, 0), (self.wxgui_fftsink2_1, 0)) self.connect((self.osmosdr_source_c_0, 0), (self.wxgui_waterfallsink2_1, 0)) self.connect((self.osmosdr_source_c_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.wxgui_waterfallsink2_0, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 0))
def __init__(self): gr.top_block.__init__(self, "FM Demodulation - 91.9 MHz") Qt.QWidget.__init__(self) self.setWindowTitle("FM Demodulation - 91.9 MHz") self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 1152e3 ################################################## # Blocks ################################################## self.rtlsdr_source_c_0 = osmosdr.source_c( args="nchan=" + str(1) + " " + "" ) self.rtlsdr_source_c_0.set_sample_rate(samp_rate) self.rtlsdr_source_c_0.set_center_freq(91.9e6, 0) self.rtlsdr_source_c_0.set_freq_corr(0, 0) self.rtlsdr_source_c_0.set_dc_offset_mode(0, 0) self.rtlsdr_source_c_0.set_iq_balance_mode(0, 0) self.rtlsdr_source_c_0.set_gain_mode(0, 0) self.rtlsdr_source_c_0.set_gain(10, 0) self.rtlsdr_source_c_0.set_if_gain(20, 0) self.rtlsdr_source_c_0.set_bb_gain(20, 0) self.rtlsdr_source_c_0.set_antenna("", 0) self.rtlsdr_source_c_0.set_bandwidth(0, 0) self.qtgui_sink_x_1 = qtgui.sink_f( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate/24, #bw "QT GUI Plot - Demodulated Signal", #name True, #plotfreq True, #plotwaterfall True, #plottime True, #plotconst ) self.qtgui_sink_x_1.set_update_time(1.0 / 10) self._qtgui_sink_x_1_win = sip.wrapinstance(self.qtgui_sink_x_1.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_sink_x_1_win) self.qtgui_sink_x_0 = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 91.9e6, #fc samp_rate, #bw "QT GUI Plot - Source", #name True, #plotfreq True, #plotwaterfall True, #plottime True, #plotconst ) self.qtgui_sink_x_0.set_update_time(1.0 / 10) self._qtgui_sink_x_0_win = sip.wrapinstance(self.qtgui_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_sink_x_0_win) self.blks2_wfm_rcv_0 = blks2.wfm_rcv( quad_rate=samp_rate, audio_decimation=24, ) self.audio_sink_0 = audio.sink(48000, "", True) ################################################## # Connections ################################################## self.connect((self.rtlsdr_source_c_0, 0), (self.blks2_wfm_rcv_0, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.audio_sink_0, 0)) self.connect((self.rtlsdr_source_c_0, 0), (self.qtgui_sink_x_0, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.qtgui_sink_x_1, 0))
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None, help="select USRP Rx side A or B (default=A)") parser.add_option("", "--f1", type="eng_float", default=100.7e6, help="set 1st station frequency to FREQ", metavar="FREQ") parser.add_option("", "--f2", type="eng_float", default=102.5e6, help="set 2nd station freq to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=40, help="set gain in dB (default is midpoint)") parser.add_option( "-O", "--audio-output", type="string", default="", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) if abs(options.f1) < 1e6: options.f1 *= 1e6 if abs(options.f2) < 1e6: options.f2 *= 1e6 if abs(options.f1 - options.f2) > 5.5e6: print "Sorry, two stations must be within 5.5MHz of each other" raise SystemExit f = (options.f1, options.f2) self.vol = .1 self.state = "FREQ" # build graph self.u = usrp.source_c(0, nchan=2) # usrp is data source adc_rate = self.u.adc_rate() # 64 MS/s usrp_decim = 200 self.u.set_decim_rate(usrp_decim) usrp_rate = adc_rate / usrp_decim # 320 kS/s chanfilt_decim = 1 demod_rate = usrp_rate / chanfilt_decim audio_decimation = 10 audio_rate = demod_rate / audio_decimation # 32 kHz if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.u) mv = usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec) mv |= (mv << 8) & 0xff00 # both DDC inputs setup same way self.u.set_mux(mv) self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) print "Using RX d'board %s" % (self.subdev.side_and_name(), ) # deinterleave two channels from FPGA di = gr.deinterleave(gr.sizeof_gr_complex) # wire up the head of the chain self.connect(self.u, di) # sound card as final sink audio_sink = audio.sink(int(audio_rate), options.audio_output) # taps for channel filter chan_filt_coeffs = optfir.low_pass( 1, # gain usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) mid_freq = (f[0] + f[1]) / 2 # set front end PLL to middle frequency tune_result = self.subdev.set_freq(mid_freq) for n in range(2): chan_filt = gr.fir_filter_ccf(chanfilt_decim, chan_filt_coeffs) guts = blks2.wfm_rcv(demod_rate, audio_decimation) volume_control = gr.multiply_const_ff(self.vol) self.connect((di, n), chan_filt) self.connect(chan_filt, guts, volume_control) self.connect(volume_control, (audio_sink, n)) dxc_freq, inverted = calc_dxc_freq(f[n], tune_result.baseband_freq, self.u.converter_rate()) self.u.set_rx_freq(n, dxc_freq) 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 # set initial values self.set_gain(options.gain)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Example bitcpf - FM Rx") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 8e6 self.rx_gain = rx_gain = 15 self.lpf_decim = lpf_decim = 20 self.freq = freq = 106.7e6 self.audio_samp_rate = audio_samp_rate = 96e3 ################################################## # Blocks ################################################## _rx_gain_sizer = wx.BoxSizer(wx.VERTICAL) self._rx_gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_rx_gain_sizer, value=self.rx_gain, callback=self.set_rx_gain, label='rx_gain', converter=forms.float_converter(), proportion=0, ) self._rx_gain_slider = forms.slider( parent=self.GetWin(), sizer=_rx_gain_sizer, value=self.rx_gain, callback=self.set_rx_gain, minimum=0, maximum=30, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_rx_gain_sizer) self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "RF") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Audio") self.Add(self.notebook_0) self._freq_text_box = forms.text_box( parent=self.GetWin(), value=self.freq, callback=self.set_freq, label='freq', converter=forms.float_converter(), ) self.Add(self._freq_text_box) self.wxgui_fftsink2_1 = fftsink2.fft_sink_f( self.notebook_0.GetPage(1).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate / lpf_decim, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.notebook_0.GetPage(1).Add(self.wxgui_fftsink2_1.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.notebook_0.GetPage(0).GetWin(), baseband_freq=freq, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.notebook_0.GetPage(0).Add(self.wxgui_fftsink2_0.win) self.uhd_usrp_source_0 = uhd.usrp_source( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(freq, 0) self.uhd_usrp_source_0.set_gain(rx_gain, 0) self.uhd_usrp_source_0.set_antenna("TX/RX", 0) self.low_pass_filter_0 = gr.fir_filter_ccf( lpf_decim, firdes.low_pass(1, samp_rate, 100e3, 10e3, firdes.WIN_HAMMING, 6.76)) self.gr_wavfile_sink_0 = gr.wavfile_sink("fm_record.wav", 1, int(audio_samp_rate), 8) self.blks2_wfm_rcv_0 = blks2.wfm_rcv( quad_rate=samp_rate / lpf_decim, audio_decimation=1, ) self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_fff( interpolation=96, decimation=int(samp_rate / lpf_decim / 1000), taps=None, fractional_bw=None, ) self.audio_sink_0 = audio.sink(int(audio_samp_rate), "", True) ################################################## # Connections ################################################## self.connect((self.low_pass_filter_0, 0), (self.blks2_wfm_rcv_0, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.blks2_rational_resampler_xxx_0, 0)) self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.gr_wavfile_sink_0, 0)) self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.wxgui_fftsink2_1, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.wxgui_fftsink2_0, 0))
def __init__(self): gr.top_block.__init__(self) parser=OptionParser(option_class=eng_option) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-f", "--freq", type="eng_float", default=100.1e6, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-V", "--volume", type="eng_float", default=None, help="set volume (default is midpoint)") parser.add_option("-O", "--audio-output", type="string", default="", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") parser.add_option("", "--freq-min", type="eng_float", default=87.9e6, help="Set a minimum frequency [default=%default]") parser.add_option("", "--freq-max", type="eng_float", default=108.1e6, help="Set a maximum frequency [default=%default]") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.state = "FREQ" self.freq = 0 self.fm_freq_min = options.freq_min self.fm_freq_max = options.freq_max # build graph self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) usrp_rate = 320e3 demod_rate = 320e3 audio_rate = 32e3 audio_decim = int(demod_rate / audio_rate) self.u.set_samp_rate(usrp_rate) dev_rate = self.u.get_samp_rate() nfilts = 32 chan_coeffs = optfir.low_pass (nfilts, # gain nfilts*usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation rrate = usrp_rate / dev_rate self.chan_filt = blks2.pfb_arb_resampler_ccf(rrate, chan_coeffs, nfilts) self.guts = blks2.wfm_rcv (demod_rate, audio_decim) self.volume_control = gr.multiply_const_ff(1) # sound card as final sink self.audio_sink = audio.sink(int(audio_rate), options.audio_output, False) # ok_to_block # now wire it all together self.connect (self.u, self.chan_filt, self.guts, self.volume_control, self.audio_sink) 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 if options.volume is None: g = self.volume_range() options.volume = float(g[0]+g[1])/2 frange = self.u.get_freq_range() if(frange.start() > self.fm_freq_max or frange.stop() < self.fm_freq_min): sys.stderr.write("Radio does not support required frequency range.\n") sys.exit(1) if(options.freq < self.fm_freq_min or options.freq > self.fm_freq_max): sys.stderr.write("Requested frequency is outside of required frequency range.\n") sys.exit(1) # set initial values self.set_gain(options.gain) self.set_vol(options.volume) if not(self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency") # Set the subdevice spec if(options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if(options.antenna): self.u.set_antenna(options.antenna, 0)
def __init__(self, gain=0, audio_output="", samp_rate=400e3, address="addr=192.168.10.2", freq=96e6): grc_wxgui.top_block_gui.__init__(self, title="UHD WBFM Receive") ################################################## # Parameters ################################################## self.gain = gain self.audio_output = audio_output self.samp_rate = samp_rate self.address = address self.freq = freq ################################################## # Variables ################################################## self.volume = volume = 1 self.tun_gain = tun_gain = gain self.tun_freq = tun_freq = freq self.fine = fine = 0 self.audio_decim = audio_decim = 10 ################################################## # Blocks ################################################## _volume_sizer = wx.BoxSizer(wx.VERTICAL) self._volume_text_box = forms.text_box( parent=self.GetWin(), sizer=_volume_sizer, value=self.volume, callback=self.set_volume, label="Volume", converter=forms.float_converter(), proportion=0, ) self._volume_slider = forms.slider( parent=self.GetWin(), sizer=_volume_sizer, value=self.volume, callback=self.set_volume, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_volume_sizer, 1, 0, 1, 4) _tun_gain_sizer = wx.BoxSizer(wx.VERTICAL) self._tun_gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_tun_gain_sizer, value=self.tun_gain, callback=self.set_tun_gain, label="UHD Gain", converter=forms.float_converter(), proportion=0, ) self._tun_gain_slider = forms.slider( parent=self.GetWin(), sizer=_tun_gain_sizer, value=self.tun_gain, callback=self.set_tun_gain, minimum=0, maximum=20, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_tun_gain_sizer) _tun_freq_sizer = wx.BoxSizer(wx.VERTICAL) self._tun_freq_text_box = forms.text_box( parent=self.GetWin(), sizer=_tun_freq_sizer, value=self.tun_freq, callback=self.set_tun_freq, label="Freq (Hz)", converter=forms.float_converter(), proportion=0, ) self._tun_freq_slider = forms.slider( parent=self.GetWin(), sizer=_tun_freq_sizer, value=self.tun_freq, callback=self.set_tun_freq, minimum=87.9e6, maximum=108.1e6, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_tun_freq_sizer) _fine_sizer = wx.BoxSizer(wx.VERTICAL) self._fine_text_box = forms.text_box( parent=self.GetWin(), sizer=_fine_sizer, value=self.fine, callback=self.set_fine, label="Fine Freq (MHz)", converter=forms.float_converter(), proportion=0, ) self._fine_slider = forms.slider( parent=self.GetWin(), sizer=_fine_sizer, value=self.fine, callback=self.set_fine, minimum=-.1, maximum=.1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_fine_sizer, 0, 2, 1, 2) self.wxgui_fftsink2 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=(freq + fine), y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.GridAdd(self.wxgui_fftsink2.win, 2, 0, 2, 4) self.uhd_usrp_source_0 = uhd.usrp_source( device_addr=address, stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(tun_freq + fine, 0) self.uhd_usrp_source_0.set_gain(tun_gain, 0) self.uhd_usrp_source_0.set_antenna("TX/RX", 0) self.low_pass_filter_0 = gr.fir_filter_ccf( 1, firdes.low_pass(1, samp_rate, 115e3, 30e3, firdes.WIN_HANN, 6.76)) self.gr_multiply_const_vxx = gr.multiply_const_vff((volume, )) self.blks2_wfm_rcv = blks2.wfm_rcv( quad_rate=samp_rate, audio_decimation=audio_decim, ) self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_fff( interpolation=48, decimation=40, taps=None, fractional_bw=None, ) self.audio_sink = audio.sink(48000, audio_output, True) ################################################## # Connections ################################################## self.connect((self.gr_multiply_const_vxx, 0), (self.audio_sink, 0)) self.connect((self.low_pass_filter_0, 0), (self.blks2_wfm_rcv, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.wxgui_fftsink2, 0)) self.connect((self.blks2_wfm_rcv, 0), (self.blks2_rational_resampler_xxx_0, 0)) self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.gr_multiply_const_vxx, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Ettus Fm") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 5e6 self.freq = freq = 93.5e6 ################################################## # Blocks ################################################## self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "RF Spectrum") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Demod Spectrum") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Audio") self.Add(self.notebook_0) self._freq_text_box = forms.text_box( parent=self.GetWin(), value=self.freq, callback=self.set_freq, label='freq', converter=forms.float_converter(), ) self.Add(self._freq_text_box) self.wxgui_fftsink2_2 = fftsink2.fft_sink_f( self.notebook_0.GetPage(2).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=48e3, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.notebook_0.GetPage(2).Add(self.wxgui_fftsink2_2.win) self.wxgui_fftsink2_1 = fftsink2.fft_sink_f( self.notebook_0.GetPage(1).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=250e3, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.notebook_0.GetPage(1).Add(self.wxgui_fftsink2_1.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.notebook_0.GetPage(0).GetWin(), baseband_freq=freq, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.notebook_0.GetPage(0).Add(self.wxgui_fftsink2_0.win) self.uhd_usrp_source_0 = uhd.usrp_source( device_addr="addr=192.168.10.2", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(freq, 0) self.uhd_usrp_source_0.set_gain(25, 0) self.uhd_usrp_source_0.set_antenna("TX/RX", 0) self.uhd_usrp_source_0.set_bandwidth(200e3, 0) self.low_pass_filter_0 = gr.fir_filter_ccf( 20, firdes.low_pass(1, samp_rate, 100e3, 10e3, firdes.WIN_HAMMING, 6.76)) self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((5, )) self.blks2_wfm_rcv_0 = blks2.wfm_rcv( quad_rate=250e3, audio_decimation=1, ) self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_fff( interpolation=48, decimation=250, taps=None, fractional_bw=None, ) self.audio_sink_0 = audio.sink(48000, "", True) ################################################## # Connections ################################################## self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.blks2_wfm_rcv_0, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.blks2_rational_resampler_xxx_0, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.wxgui_fftsink2_1, 0)) self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.wxgui_fftsink2_2, 0))
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) parser = OptionParser(option_class=eng_option) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None, help="select USRP Rx side A or B (default=A)") parser.add_option("-f", "--freq", type="eng_float", default=100.1e6, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=40, help="set gain in dB (default is midpoint)") parser.add_option("-V", "--volume", type="eng_float", default=None, help="set volume (default is midpoint)") parser.add_option( "-O", "--audio-output", type="string", default="", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.frame = frame self.panel = panel self.vol = 0 self.state = "FREQ" self.freq = 0 # build graph self.u = usrp.source_c() # usrp is data source adc_rate = self.u.adc_rate() # 64 MS/s usrp_decim = 200 self.u.set_decim_rate(usrp_decim) usrp_rate = adc_rate / usrp_decim # 320 kS/s chanfilt_decim = 1 demod_rate = usrp_rate / chanfilt_decim audio_decimation = 10 audio_rate = demod_rate / audio_decimation # 32 kHz if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.u) self.u.set_mux( usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) print "Using RX d'board %s" % (self.subdev.side_and_name(), ) dbid = self.subdev.dbid() if not (dbid == usrp_dbid.BASIC_RX or dbid == usrp_dbid.TV_RX or dbid == usrp_dbid.TV_RX_REV_2 or dbid == usrp_dbid.TV_RX_REV_3): print "This daughterboard does not cover the required frequency range" print "for this application. Please use a BasicRX or TVRX daughterboard." raw_input("Press ENTER to continue anyway, or Ctrl-C to exit.") chan_filt_coeffs = optfir.low_pass( 1, # gain usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) chan_filt = gr.fir_filter_ccf(chanfilt_decim, chan_filt_coeffs) self.guts = blks2.wfm_rcv(demod_rate, audio_decimation) self.volume_control = gr.multiply_const_ff(self.vol) # sound card as final sink audio_sink = audio.sink(int(audio_rate), options.audio_output, False) # ok_to_block # now wire it all together self.connect(self.u, chan_filt, self.guts, self.volume_control, audio_sink) self._build_gui(vbox, usrp_rate, demod_rate, audio_rate) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.subdev.gain_range() options.gain = float(g[0] + g[1]) / 2 if options.volume is None: g = self.volume_range() options.volume = float(g[0] + g[1]) / 2 if abs(options.freq) < 1e6: options.freq *= 1e6 # set initial values self.set_gain(options.gain) self.set_vol(options.volume) if not (self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def __init__(self): gr.top_block.__init__(self) parser=OptionParser(option_class=eng_option) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None, help="select USRP Rx side A or B (default=A)") parser.add_option("", "--f1", type="eng_float", default=100.7e6, help="set 1st station frequency to FREQ", metavar="FREQ") parser.add_option("", "--f2", type="eng_float", default=102.5e6, help="set 2nd station freq to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=40, help="set gain in dB (default is midpoint)") parser.add_option("-O", "--audio-output", type="string", default="", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) if abs(options.f1) < 1e6: options.f1 *= 1e6 if abs(options.f2) < 1e6: options.f2 *= 1e6 if abs(options.f1 - options.f2) > 5.5e6: print "Sorry, two stations must be within 5.5MHz of each other" raise SystemExit f = (options.f1, options.f2) self.vol = .1 self.state = "FREQ" # build graph self.u = usrp.source_c(0, nchan=2) # usrp is data source adc_rate = self.u.adc_rate() # 64 MS/s usrp_decim = 200 self.u.set_decim_rate(usrp_decim) usrp_rate = adc_rate / usrp_decim # 320 kS/s chanfilt_decim = 1 demod_rate = usrp_rate / chanfilt_decim audio_decimation = 10 audio_rate = demod_rate / audio_decimation # 32 kHz if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.u) mv = usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec) mv |= (mv << 8) & 0xff00 # both DDC inputs setup same way self.u.set_mux(mv) self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) print "Using RX d'board %s" % (self.subdev.side_and_name(),) # deinterleave two channels from FPGA di = gr.deinterleave(gr.sizeof_gr_complex) # wire up the head of the chain self.connect(self.u, di) # sound card as final sink audio_sink = audio.sink(int(audio_rate), options.audio_output) # taps for channel filter chan_filt_coeffs = optfir.low_pass (1, # gain usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) mid_freq = (f[0] + f[1]) / 2 # set front end PLL to middle frequency ok, baseband_freq = self.subdev.set_freq(mid_freq) for n in range(2): chan_filt = gr.fir_filter_ccf (chanfilt_decim, chan_filt_coeffs) guts = blks2.wfm_rcv (demod_rate, audio_decimation) volume_control = gr.multiply_const_ff(self.vol) self.connect((di, n), chan_filt) self.connect(chan_filt, guts, volume_control) self.connect(volume_control, (audio_sink, n)) dxc_freq, inverted = usrp.calc_dxc_freq(f[n], baseband_freq, self.u.converter_rate()) self.u.set_rx_freq(n, dxc_freq) 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 # set initial values self.set_gain(options.gain)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Simple Fm") ################################################## # Variables ################################################## self.frequency = frequency = 101500000 self.volume = volume = 2 self.samp_rate = samp_rate = 1400000 self.freq = freq = frequency self.bandwidth = bandwidth = 1500000 ################################################## # Blocks ################################################## _volume_sizer = wx.BoxSizer(wx.VERTICAL) self._volume_text_box = forms.text_box( parent=self.GetWin(), sizer=_volume_sizer, value=self.volume, callback=self.set_volume, label="Volume", converter=forms.float_converter(), proportion=0, ) self._volume_slider = forms.slider( parent=self.GetWin(), sizer=_volume_sizer, value=self.volume, callback=self.set_volume, minimum=1, maximum=10, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_volume_sizer) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=freq, y_per_div=10, y_divs=10, ref_level=20, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="Plot", peak_hold=False, ) self.Add(self.wxgui_fftsink2_0.win) self.rtl2832_source_0 = baz.rtl_source_c(defer_creation=True, output_size=gr.sizeof_gr_complex) self.rtl2832_source_0.set_verbose(True) self.rtl2832_source_0.set_vid(0x0) self.rtl2832_source_0.set_pid(0x0) self.rtl2832_source_0.set_tuner_name("") self.rtl2832_source_0.set_default_timeout(0) self.rtl2832_source_0.set_use_buffer(True) self.rtl2832_source_0.set_fir_coefficients(([])) self.rtl2832_source_0.set_read_length(0) if self.rtl2832_source_0.create() == False: raise Exception("Failed to create RTL2832 Source: rtl2832_source_0") self.rtl2832_source_0.set_bandwidth(bandwidth) self.rtl2832_source_0.set_sample_rate(samp_rate) self.rtl2832_source_0.set_frequency(freq) self.rtl2832_source_0.set_auto_gain_mode(False) self.rtl2832_source_0.set_relative_gain(True) self.rtl2832_source_0.set_gain(20) self.low_pass_filter_0 = gr.fir_filter_ccf(4, firdes.low_pass( 2, samp_rate, 25000, 50000, firdes.WIN_HAMMING, 6.76)) self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((volume, )) _frequency_sizer = wx.BoxSizer(wx.VERTICAL) self._frequency_text_box = forms.text_box( parent=self.GetWin(), sizer=_frequency_sizer, value=self.frequency, callback=self.set_frequency, label="Frequenz", converter=forms.float_converter(), proportion=0, ) self._frequency_slider = forms.slider( parent=self.GetWin(), sizer=_frequency_sizer, value=self.frequency, callback=self.set_frequency, minimum=90000000, maximum=110000000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_frequency_sizer) self.blks2_wfm_rcv_0 = blks2.wfm_rcv( quad_rate=samp_rate, audio_decimation=8, ) self.audio_sink_0 = audio.sink(44100, "", True) ################################################## # Connections ################################################## self.connect((self.low_pass_filter_0, 0), (self.blks2_wfm_rcv_0, 0)) self.connect((self.rtl2832_source_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.rtl2832_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.audio_sink_0, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="rtl-sdr") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.xlate_tune = xlate_tune = 0 self.samp_rate = samp_rate = 1024000 self.noxon_central_freq = noxon_central_freq = 103e6 self.rx_freq = rx_freq = noxon_central_freq + xlate_tune self.filter_taps = filter_taps = firdes.low_pass( 1, samp_rate, 100e3, 1e3) self.af_gain = af_gain = 3 ################################################## # Blocks ################################################## _xlate_tune_sizer = wx.BoxSizer(wx.VERTICAL) self._xlate_tune_text_box = forms.text_box( parent=self.GetWin(), sizer=_xlate_tune_sizer, value=self.xlate_tune, callback=self.set_xlate_tune, label="xlate tune", converter=forms.float_converter(), proportion=0, ) self._xlate_tune_slider = forms.slider( parent=self.GetWin(), sizer=_xlate_tune_sizer, value=self.xlate_tune, callback=self.set_xlate_tune, minimum=-500e3, maximum=+500e3, num_steps=500, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_xlate_tune_sizer, 0, 0, 1, 1) self._noxon_central_freq_static_text = forms.static_text( parent=self.GetWin(), value=self.noxon_central_freq, callback=self.set_noxon_central_freq, label="Noxon central frequency ", converter=forms.float_converter(), ) self.GridAdd(self._noxon_central_freq_static_text, 1, 0, 1, 1) _af_gain_sizer = wx.BoxSizer(wx.VERTICAL) self._af_gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_af_gain_sizer, value=self.af_gain, callback=self.set_af_gain, label="AF gain", converter=forms.float_converter(), proportion=0, ) self._af_gain_slider = forms.slider( parent=self.GetWin(), sizer=_af_gain_sizer, value=self.af_gain, callback=self.set_af_gain, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_af_gain_sizer, 0, 2, 1, 1) self.xlating_fir_filter = gr.freq_xlating_fir_filter_ccc( 4, (filter_taps), -xlate_tune, samp_rate) self.wfm_rcv = blks2.wfm_rcv( quad_rate=samp_rate / 4, audio_decimation=5, ) self._rx_freq_static_text = forms.static_text( parent=self.GetWin(), value=self.rx_freq, callback=self.set_rx_freq, label="rx frequency ", converter=forms.float_converter(), ) self.GridAdd(self._rx_freq_static_text, 1, 3, 1, 1) self.rtl2832_source_0 = baz.rtl_source_c(defer_creation=True) self.rtl2832_source_0.set_verbose(True) self.rtl2832_source_0.set_vid(0x0) self.rtl2832_source_0.set_pid(0x0) self.rtl2832_source_0.set_tuner_name("") self.rtl2832_source_0.set_default_timeout(0) self.rtl2832_source_0.set_use_buffer(True) self.rtl2832_source_0.set_fir_coefficients(([])) if self.rtl2832_source_0.create() == False: raise Exception( "Failed to create RTL2832 Source: rtl2832_source_0") self.rtl2832_source_0.set_sample_rate(samp_rate) self.rtl2832_source_0.set_frequency(102722000) self.rtl2832_source_0.set_auto_gain_mode(False) self.rtl2832_source_0.set_relative_gain(True) self.rtl2832_source_0.set_gain(3) self.rr_stereo_right = blks2.rational_resampler_fff( interpolation=48, decimation=50, taps=None, fractional_bw=None, ) self.fftsink_rf_0 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=noxon_central_freq, y_per_div=5, y_divs=10, ref_level=0, ref_scale=.5, sample_rate=samp_rate, fft_size=1024, fft_rate=10, average=True, avg_alpha=0.25, title="Total bandwidth", peak_hold=False, win=window.blackmanharris, size=(800, 200), ) self.Add(self.fftsink_rf_0.win) self.fftsink_rf = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=0, y_per_div=5, y_divs=10, ref_level=0, ref_scale=.5, sample_rate=samp_rate / 4, fft_size=1024, fft_rate=10, average=True, avg_alpha=0.25, title="Baseband", peak_hold=False, size=(800, 200), ) self.Add(self.fftsink_rf.win) self.audio_sink = audio.sink(48000, "pulse", True) self.af_gain_stereo_left = gr.multiply_const_vff((af_gain, )) ################################################## # Connections ################################################## self.connect((self.xlating_fir_filter, 0), (self.fftsink_rf, 0)) self.connect((self.af_gain_stereo_left, 0), (self.audio_sink, 0)) self.connect((self.wfm_rcv, 0), (self.rr_stereo_right, 0)) self.connect((self.xlating_fir_filter, 0), (self.wfm_rcv, 0)) self.connect((self.rr_stereo_right, 0), (self.af_gain_stereo_left, 0)) self.connect((self.af_gain_stereo_left, 0), (self.audio_sink, 1)) self.connect((self.xlating_fir_filter, 0), (self.fftsink_rf_0, 0)) self.connect((self.rtl2832_source_0, 0), (self.xlating_fir_filter, 0))
def __init__(self): gr.top_block.__init__(self) parser=OptionParser(option_class=eng_option) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None, help="select USRP Rx side A or B (default=A)") parser.add_option("-f", "--freq", type="eng_float", default=100.1e6, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-O", "--audio-output", type="string", default="", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.vol = .1 self.state = "FREQ" self.freq = 0 # build graph self.u = usrp.source_c() # usrp is data source adc_rate = self.u.adc_rate() # 64 MS/s usrp_decim = 200 self.u.set_decim_rate(usrp_decim) usrp_rate = adc_rate / usrp_decim # 320 kS/s chanfilt_decim = 1 demod_rate = usrp_rate / chanfilt_decim audio_decimation = 10 audio_rate = demod_rate / audio_decimation # 32 kHz if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.u) self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) print "Using RX d'board %s" % (self.subdev.side_and_name(),) chan_filt_coeffs = optfir.low_pass (1, # gain usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) chan_filt = gr.fir_filter_ccf (chanfilt_decim, chan_filt_coeffs) self.guts = blks2.wfm_rcv (demod_rate, audio_decimation) self.volume_control = gr.multiply_const_ff(self.vol) # sound card as final sink audio_sink = audio.sink(int(audio_rate), options.audio_output, False) # ok_to_block # now wire it all together self.connect (self.u, chan_filt, self.guts, self.volume_control, audio_sink) 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 abs(options.freq) < 1e6: options.freq *= 1e6 # set initial values self.set_gain(options.gain) if not(self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def __init__(self, devid="type=b100", rdsfile="rds_fifo", gain=35.0, freq=101.1e6, xmlport=13777, arate=int(48e3), mute=-15.0, ftune=0, ant="J1", subdev="A:0", ahw="pulse", deemph=75.0e-6, prenames='["UWRF","89.3","950","WEVR"]', prefreqs="[88.715e6,89.3e6,950.735e6,106.317e6]", volume=1.0): grc_wxgui.top_block_gui.__init__(self, title="Simple FM (Stereo) Receiver") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.devid = devid self.rdsfile = rdsfile self.gain = gain self.freq = freq self.xmlport = xmlport self.arate = arate self.mute = mute self.ftune = ftune self.ant = ant self.subdev = subdev self.ahw = ahw self.deemph = deemph self.prenames = prenames self.prefreqs = prefreqs self.volume = volume ################################################## # Variables ################################################## self.pthresh = pthresh = 350 self.preselect = preselect = eval(prefreqs)[0] self.pilot_level = pilot_level = 0 self.ifreq = ifreq = freq self.stpilotdet = stpilotdet = True if (pilot_level > pthresh) else False self.stereo = stereo = True self.rf_pwr_lvl = rf_pwr_lvl = 0 self.cur_freq = cur_freq = simple_fm_helper.freq_select(ifreq,preselect) self.vol = vol = volume self.variable_static_text_0 = variable_static_text_0 = 10.0*math.log(rf_pwr_lvl+1.0e-11)/math.log(10) self.tone_med = tone_med = 5 self.tone_low = tone_low = 5 self.tone_high = tone_high = 5 self.stereo_0 = stereo_0 = stpilotdet self.st_enabled = st_enabled = 1 if (stereo == True and pilot_level > pthresh) else 0 self.squelch_probe = squelch_probe = 0 self.sq_thresh = sq_thresh = mute self.samp_rate = samp_rate = 250e3 self.rtext_0 = rtext_0 = cur_freq self.record = record = False self.rdsrate = rdsrate = 25e3 self.osmo_taps = osmo_taps = firdes.low_pass(1.0,1.00e6,95e3,20e3,firdes.WIN_HAMMING,6.76) self.mod_reset = mod_reset = 0 self.igain = igain = gain self.fine = fine = ftune self.farate = farate = arate self.dm = dm = deemph self.discrim_dc = discrim_dc = 0 self.capture_file = capture_file = "capture.wav" self.asrate = asrate = 125e3 ################################################## # Blocks ################################################## _sq_thresh_sizer = wx.BoxSizer(wx.VERTICAL) self._sq_thresh_text_box = forms.text_box( parent=self.GetWin(), sizer=_sq_thresh_sizer, value=self.sq_thresh, callback=self.set_sq_thresh, label="Mute Level", converter=forms.float_converter(), proportion=0, ) self._sq_thresh_slider = forms.slider( parent=self.GetWin(), sizer=_sq_thresh_sizer, value=self.sq_thresh, callback=self.set_sq_thresh, minimum=-30.0, maximum=-5.0, num_steps=40, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_sq_thresh_sizer, 1, 5, 1, 1) self.input_power = gr.probe_avg_mag_sqrd_c(sq_thresh, 1.0/(samp_rate/10)) self.dc_level = gr.probe_signal_f() _vol_sizer = wx.BoxSizer(wx.VERTICAL) self._vol_text_box = forms.text_box( parent=self.GetWin(), sizer=_vol_sizer, value=self.vol, callback=self.set_vol, label="Volume", converter=forms.float_converter(), proportion=0, ) self._vol_slider = forms.slider( parent=self.GetWin(), sizer=_vol_sizer, value=self.vol, callback=self.set_vol, minimum=0, maximum=11, num_steps=110, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_vol_sizer, 0, 3, 1, 1) _tone_med_sizer = wx.BoxSizer(wx.VERTICAL) self._tone_med_text_box = forms.text_box( parent=self.GetWin(), sizer=_tone_med_sizer, value=self.tone_med, callback=self.set_tone_med, label="1Khz-4Khz", converter=forms.float_converter(), proportion=0, ) self._tone_med_slider = forms.slider( parent=self.GetWin(), sizer=_tone_med_sizer, value=self.tone_med, callback=self.set_tone_med, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_tone_med_sizer, 1, 3, 1, 1) _tone_low_sizer = wx.BoxSizer(wx.VERTICAL) self._tone_low_text_box = forms.text_box( parent=self.GetWin(), sizer=_tone_low_sizer, value=self.tone_low, callback=self.set_tone_low, label="0-1Khz", converter=forms.float_converter(), proportion=0, ) self._tone_low_slider = forms.slider( parent=self.GetWin(), sizer=_tone_low_sizer, value=self.tone_low, callback=self.set_tone_low, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_tone_low_sizer, 1, 2, 1, 1) _tone_high_sizer = wx.BoxSizer(wx.VERTICAL) self._tone_high_text_box = forms.text_box( parent=self.GetWin(), sizer=_tone_high_sizer, value=self.tone_high, callback=self.set_tone_high, label="4Khz-15Khz", converter=forms.float_converter(), proportion=0, ) self._tone_high_slider = forms.slider( parent=self.GetWin(), sizer=_tone_high_sizer, value=self.tone_high, callback=self.set_tone_high, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_tone_high_sizer, 1, 4, 1, 1) def _squelch_probe_probe(): while True: val = self.input_power.unmuted() try: self.set_squelch_probe(val) except AttributeError, e: pass time.sleep(1.0/(10)) _squelch_probe_thread = threading.Thread(target=_squelch_probe_probe) _squelch_probe_thread.daemon = True _squelch_probe_thread.start() self._record_check_box = forms.check_box( parent=self.GetWin(), value=self.record, callback=self.set_record, label="Record Audio", true=True, false=False, ) self.GridAdd(self._record_check_box, 2, 2, 1, 1) self.pilot_probe = gr.probe_signal_f() _fine_sizer = wx.BoxSizer(wx.VERTICAL) self._fine_text_box = forms.text_box( parent=self.GetWin(), sizer=_fine_sizer, value=self.fine, callback=self.set_fine, label="Fine Tuning", converter=forms.float_converter(), proportion=0, ) self._fine_slider = forms.slider( parent=self.GetWin(), sizer=_fine_sizer, value=self.fine, callback=self.set_fine, minimum=-50.0e3, maximum=50.e03, num_steps=400, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_fine_sizer, 1, 0, 1, 1) def _discrim_dc_probe(): while True: val = self.dc_level.level() try: self.set_discrim_dc(val) except AttributeError, e: pass time.sleep(1.0/(2.5)) _discrim_dc_thread = threading.Thread(target=_discrim_dc_probe) _discrim_dc_thread.daemon = True _discrim_dc_thread.start() self._capture_file_text_box = forms.text_box( parent=self.GetWin(), value=self.capture_file, callback=self.set_capture_file, label="Record Filename", converter=forms.str_converter(), ) self.GridAdd(self._capture_file_text_box, 2, 0, 1, 2) self.Main = self.Main = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.Main.AddPage(grc_wxgui.Panel(self.Main), "L/R") self.Main.AddPage(grc_wxgui.Panel(self.Main), "FM Demod Spectrum") self.Add(self.Main) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", ) self.Add(self.wxgui_waterfallsink2_0.win) self.wxgui_scopesink2_0 = scopesink2.scope_sink_f( self.Main.GetPage(0).GetWin(), title="Audio Channels (L and R)", sample_rate=farate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=2, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Rel. Audio Level", ) self.Main.GetPage(0).Add(self.wxgui_scopesink2_0.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_f( self.Main.GetPage(1).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=asrate, fft_size=1024, fft_rate=6, average=True, avg_alpha=0.1, title="FM Demod Spectrum", peak_hold=False, ) self.Main.GetPage(1).Add(self.wxgui_fftsink2_0.win) self._variable_static_text_0_static_text = forms.static_text( parent=self.GetWin(), value=self.variable_static_text_0, callback=self.set_variable_static_text_0, label="RF Power ", converter=forms.float_converter(formatter=lambda x: "%4.1f" % x), ) self.GridAdd(self._variable_static_text_0_static_text, 0, 2, 1, 1) self._stereo_0_check_box = forms.check_box( parent=self.GetWin(), value=self.stereo_0, callback=self.set_stereo_0, label="Stereo Detect", true=True, false=False, ) self.GridAdd(self._stereo_0_check_box, 2, 5, 1, 1) self._stereo_check_box = forms.check_box( parent=self.GetWin(), value=self.stereo, callback=self.set_stereo, label="Stereo", true=True, false=False, ) self.GridAdd(self._stereo_check_box, 2, 4, 1, 1) self.rtl2832_source_0 = baz.rtl_source_c(defer_creation=True) self.rtl2832_source_0.set_verbose(True) self.rtl2832_source_0.set_vid(0x0) self.rtl2832_source_0.set_pid(0x0) self.rtl2832_source_0.set_tuner_name("") self.rtl2832_source_0.set_default_timeout(0) self.rtl2832_source_0.set_use_buffer(True) self.rtl2832_source_0.set_fir_coefficients(([])) if self.rtl2832_source_0.create() == False: raise Exception("Failed to create RTL2832 Source: rtl2832_source_0") self.rtl2832_source_0.set_sample_rate(1.0e6) self.rtl2832_source_0.set_frequency(cur_freq+200e3) self.rtl2832_source_0.set_auto_gain_mode(False) self.rtl2832_source_0.set_relative_gain(True) self.rtl2832_source_0.set_gain(gain) self._rtext_0_static_text = forms.static_text( parent=self.GetWin(), value=self.rtext_0, callback=self.set_rtext_0, label="CURRENT FREQUENCY>>", converter=forms.float_converter(), ) self.GridAdd(self._rtext_0_static_text, 0, 1, 1, 1) def _rf_pwr_lvl_probe(): while True: val = self.input_power.level() try: self.set_rf_pwr_lvl(val) except AttributeError, e: pass time.sleep(1.0/(2)) _rf_pwr_lvl_thread = threading.Thread(target=_rf_pwr_lvl_probe) _rf_pwr_lvl_thread.daemon = True _rf_pwr_lvl_thread.start() self._preselect_chooser = forms.radio_buttons( parent=self.GetWin(), value=self.preselect, callback=self.set_preselect, label='preselect', choices=eval(prefreqs), labels=eval(prenames), style=wx.RA_HORIZONTAL, ) self.GridAdd(self._preselect_chooser, 0, 4, 1, 1) def _pilot_level_probe(): while True: val = self.pilot_probe.level() try: self.set_pilot_level(val) except AttributeError, e: pass time.sleep(1.0/(5)) _pilot_level_thread = threading.Thread(target=_pilot_level_probe) _pilot_level_thread.daemon = True _pilot_level_thread.start() self.low_pass_filter_3 = gr.fir_filter_fff(1, firdes.low_pass( 3, asrate/500, 10, 3, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_2 = gr.fir_filter_fff(10, firdes.low_pass( 3, asrate/50, 100, 30, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_1 = gr.fir_filter_fff(10, firdes.low_pass( 3, asrate/5, 1e3, 200, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0 = gr.fir_filter_fff(5, firdes.low_pass( 3, asrate, 10e3, 2e3, firdes.WIN_HAMMING, 6.76)) _igain_sizer = wx.BoxSizer(wx.VERTICAL) self._igain_text_box = forms.text_box( parent=self.GetWin(), sizer=_igain_sizer, value=self.igain, callback=self.set_igain, label="RF Gain", converter=forms.float_converter(), proportion=0, ) self._igain_slider = forms.slider( parent=self.GetWin(), sizer=_igain_sizer, value=self.igain, callback=self.set_igain, minimum=0, maximum=50, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_igain_sizer, 1, 1, 1, 1) _ifreq_sizer = wx.BoxSizer(wx.VERTICAL) self._ifreq_text_box = forms.text_box( parent=self.GetWin(), sizer=_ifreq_sizer, value=self.ifreq, callback=self.set_ifreq, label="Center Frequency", converter=forms.float_converter(), proportion=0, ) self._ifreq_slider = forms.slider( parent=self.GetWin(), sizer=_ifreq_sizer, value=self.ifreq, callback=self.set_ifreq, minimum=88.1e6, maximum=108.1e6, num_steps=200, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_ifreq_sizer, 0, 0, 1, 1) self.gr_wavfile_sink_0 = gr.wavfile_sink("/dev/null" if record == False else capture_file, 2, int(farate), 16) self.gr_sub_xx_0 = gr.sub_ff(1) self.gr_single_pole_iir_filter_xx_1 = gr.single_pole_iir_filter_ff(2.5/(asrate/500), 1) self.gr_single_pole_iir_filter_xx_0 = gr.single_pole_iir_filter_ff(1.0/(asrate/3), 1) self.gr_multiply_xx_1 = gr.multiply_vff(1) self.gr_multiply_xx_0_0 = gr.multiply_vff(1) self.gr_multiply_xx_0 = gr.multiply_vff(1) self.gr_multiply_const_vxx_3 = gr.multiply_const_vff((3.16e3 if st_enabled else 0, )) self.gr_multiply_const_vxx_2 = gr.multiply_const_vff((1.0 if st_enabled else 1.414, )) self.gr_multiply_const_vxx_1_0 = gr.multiply_const_vff((0 if st_enabled else 1, )) self.gr_multiply_const_vxx_1 = gr.multiply_const_vff((0 if squelch_probe == 0 else 1.0, )) self.gr_multiply_const_vxx_0_0 = gr.multiply_const_vff((vol*1.5*10.0, )) self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((vol*1.5*10.0 if st_enabled else 0, )) self.gr_keep_one_in_n_0 = gr.keep_one_in_n(gr.sizeof_float*1, int(asrate/3)) self.gr_freq_xlating_fir_filter_xxx_0 = gr.freq_xlating_fir_filter_ccc(4, (osmo_taps), 200e3+fine+(-12e3*discrim_dc), 1.0e6) self.gr_fractional_interpolator_xx_0_0 = gr.fractional_interpolator_ff(0, asrate/farate) self.gr_fractional_interpolator_xx_0 = gr.fractional_interpolator_ff(0, asrate/farate) self.gr_fft_filter_xxx_1_0_0 = gr.fft_filter_fff(1, (firdes.band_pass(tone_high/10.0,asrate,3.5e3,15.0e3,5.0e3,firdes.WIN_HAMMING)), 1) self.gr_fft_filter_xxx_1_0 = gr.fft_filter_fff(1, (firdes.band_pass(tone_med/10.0,asrate,1.0e3,4.0e3,2.0e3,firdes.WIN_HAMMING)), 1) self.gr_fft_filter_xxx_1 = gr.fft_filter_fff(1, (firdes.low_pass(tone_low/10.0,asrate,1.2e3,500,firdes.WIN_HAMMING)), 1) self.gr_fft_filter_xxx_0_0_0 = gr.fft_filter_fff(1, (firdes.band_pass(tone_high/10.0,asrate,3.5e3,13.5e3,3.5e3,firdes.WIN_HAMMING)), 1) self.gr_fft_filter_xxx_0_0 = gr.fft_filter_fff(1, (firdes.band_pass(tone_med/10.0,asrate,1.0e3,4.0e3,2.0e3,firdes.WIN_HAMMING)), 1) self.gr_fft_filter_xxx_0 = gr.fft_filter_fff(1, (firdes.low_pass(tone_low/10.0,asrate,1.2e3,500,firdes.WIN_HAMMING)), 1) self.gr_divide_xx_0 = gr.divide_ff(1) self.gr_agc_xx_1 = gr.agc_cc(1e-2, 0.35, 1.0, 5000) self.gr_add_xx_2_0 = gr.add_vff(1) self.gr_add_xx_2 = gr.add_vff(1) self.gr_add_xx_1 = gr.add_vff(1) self.gr_add_xx_0 = gr.add_vff(1) self.gr_add_const_vxx_0 = gr.add_const_vff((1.0e-7, )) self._dm_chooser = forms.radio_buttons( parent=self.GetWin(), value=self.dm, callback=self.set_dm, label="FM Deemphasis", choices=[75.0e-6, 50.0e-6], labels=["NA", "EU"], style=wx.RA_HORIZONTAL, ) self.GridAdd(self._dm_chooser, 0, 5, 1, 1) self.blks2_wfm_rcv_0 = blks2.wfm_rcv( quad_rate=samp_rate, audio_decimation=2, ) self.blks2_fm_deemph_0_0 = blks2.fm_deemph(fs=farate, tau=deemph) self.blks2_fm_deemph_0 = blks2.fm_deemph(fs=farate, tau=deemph) self.band_pass_filter_2_0 = gr.fir_filter_fff(1, firdes.band_pass( 20, asrate, 17.5e3, 17.9e3, 250, firdes.WIN_HAMMING, 6.76)) self.band_pass_filter_2 = gr.fir_filter_fff(1, firdes.band_pass( 10, asrate, 18.8e3, 19.2e3, 350, firdes.WIN_HAMMING, 6.76)) self.band_pass_filter_0_0 = gr.fir_filter_fff(1, firdes.band_pass( 1, asrate, 38e3-(15e3), 38e3+(15e3), 4.0e3, firdes.WIN_HAMMING, 6.76)) self.audio_sink_0 = audio.sink(int(farate), "" if ahw == "Default" else ahw, True) ################################################## # Connections ################################################## self.connect((self.gr_add_xx_1, 0), (self.gr_fractional_interpolator_xx_0, 0)) self.connect((self.gr_sub_xx_0, 0), (self.gr_fractional_interpolator_xx_0_0, 0)) self.connect((self.band_pass_filter_0_0, 0), (self.gr_multiply_xx_1, 0)) self.connect((self.gr_multiply_const_vxx_1_0, 0), (self.gr_add_xx_0, 0)) self.connect((self.band_pass_filter_2_0, 0), (self.gr_multiply_xx_0, 0)) self.connect((self.band_pass_filter_2_0, 0), (self.gr_multiply_xx_0, 1)) self.connect((self.gr_multiply_xx_0_0, 0), (self.gr_divide_xx_0, 0)) self.connect((self.gr_divide_xx_0, 0), (self.gr_single_pole_iir_filter_xx_0, 0)) self.connect((self.gr_multiply_xx_0, 0), (self.gr_add_const_vxx_0, 0)) self.connect((self.gr_add_const_vxx_0, 0), (self.gr_divide_xx_0, 1)) self.connect((self.gr_single_pole_iir_filter_xx_0, 0), (self.gr_keep_one_in_n_0, 0)) self.connect((self.gr_keep_one_in_n_0, 0), (self.pilot_probe, 0)) self.connect((self.band_pass_filter_2, 0), (self.gr_multiply_xx_1, 2)) self.connect((self.band_pass_filter_2, 0), (self.gr_multiply_xx_0_0, 0)) self.connect((self.gr_multiply_const_vxx_2, 0), (self.gr_add_xx_1, 0)) self.connect((self.gr_multiply_const_vxx_2, 0), (self.gr_sub_xx_0, 0)) self.connect((self.gr_multiply_const_vxx_3, 0), (self.gr_sub_xx_0, 1)) self.connect((self.gr_multiply_const_vxx_3, 0), (self.gr_add_xx_1, 1)) self.connect((self.gr_fractional_interpolator_xx_0, 0), (self.gr_multiply_const_vxx_0_0, 0)) self.connect((self.gr_fractional_interpolator_xx_0_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.band_pass_filter_2, 0), (self.gr_multiply_xx_1, 1)) self.connect((self.gr_multiply_xx_1, 0), (self.gr_fft_filter_xxx_0, 0)) self.connect((self.gr_fft_filter_xxx_1, 0), (self.gr_add_xx_2, 0)) self.connect((self.gr_fft_filter_xxx_1_0, 0), (self.gr_add_xx_2, 1)) self.connect((self.gr_fft_filter_xxx_1_0_0, 0), (self.gr_add_xx_2, 2)) self.connect((self.gr_add_xx_2, 0), (self.gr_multiply_const_vxx_2, 0)) self.connect((self.gr_add_xx_2_0, 0), (self.gr_multiply_const_vxx_3, 0)) self.connect((self.gr_fft_filter_xxx_0, 0), (self.gr_add_xx_2_0, 0)) self.connect((self.gr_fft_filter_xxx_0_0, 0), (self.gr_add_xx_2_0, 1)) self.connect((self.gr_multiply_xx_1, 0), (self.gr_fft_filter_xxx_0_0, 0)) self.connect((self.gr_fft_filter_xxx_0_0_0, 0), (self.gr_add_xx_2_0, 2)) self.connect((self.gr_multiply_xx_1, 0), (self.gr_fft_filter_xxx_0_0_0, 0)) self.connect((self.blks2_fm_deemph_0, 0), (self.gr_multiply_const_vxx_1_0, 0)) self.connect((self.blks2_fm_deemph_0, 0), (self.gr_wavfile_sink_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.gr_fft_filter_xxx_1, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.gr_fft_filter_xxx_1_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.gr_fft_filter_xxx_1_0_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.gr_multiply_const_vxx_0_0, 0), (self.blks2_fm_deemph_0, 0)) self.connect((self.gr_add_xx_0, 0), (self.audio_sink_0, 1)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.blks2_fm_deemph_0_0, 0)) self.connect((self.blks2_fm_deemph_0_0, 0), (self.gr_add_xx_0, 1)) self.connect((self.band_pass_filter_2, 0), (self.gr_multiply_xx_0_0, 1)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.band_pass_filter_2, 0)) self.connect((self.blks2_fm_deemph_0, 0), (self.audio_sink_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.band_pass_filter_2_0, 0)) self.connect((self.gr_multiply_const_vxx_1, 0), (self.band_pass_filter_0_0, 0)) self.connect((self.gr_add_xx_0, 0), (self.gr_wavfile_sink_0, 1)) self.connect((self.blks2_fm_deemph_0, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.gr_add_xx_0, 0), (self.wxgui_scopesink2_0, 1)) self.connect((self.blks2_wfm_rcv_0, 0), (self.gr_multiply_const_vxx_1, 0)) self.connect((self.gr_agc_xx_1, 0), (self.blks2_wfm_rcv_0, 0)) self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.gr_agc_xx_1, 0)) self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.input_power, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.low_pass_filter_1, 0)) self.connect((self.low_pass_filter_1, 0), (self.low_pass_filter_2, 0)) self.connect((self.low_pass_filter_2, 0), (self.low_pass_filter_3, 0)) self.connect((self.gr_single_pole_iir_filter_xx_1, 0), (self.dc_level, 0)) self.connect((self.low_pass_filter_3, 0), (self.gr_single_pole_iir_filter_xx_1, 0)) self.connect((self.rtl2832_source_0, 0), (self.gr_freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.wxgui_waterfallsink2_0, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="rtl-sdr") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.xlate_tune = xlate_tune = 0 self.samp_rate = samp_rate = 1024000 self.noxon_central_freq = noxon_central_freq = 103e6 self.rx_freq = rx_freq = noxon_central_freq+xlate_tune self.filter_taps = filter_taps = firdes.low_pass(1,samp_rate,100e3,1e3) self.af_gain = af_gain = 3 ################################################## # Blocks ################################################## _xlate_tune_sizer = wx.BoxSizer(wx.VERTICAL) self._xlate_tune_text_box = forms.text_box( parent=self.GetWin(), sizer=_xlate_tune_sizer, value=self.xlate_tune, callback=self.set_xlate_tune, label="xlate tune", converter=forms.float_converter(), proportion=0, ) self._xlate_tune_slider = forms.slider( parent=self.GetWin(), sizer=_xlate_tune_sizer, value=self.xlate_tune, callback=self.set_xlate_tune, minimum=-500e3, maximum=+500e3, num_steps=500, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_xlate_tune_sizer, 0, 0, 1, 1) self._noxon_central_freq_static_text = forms.static_text( parent=self.GetWin(), value=self.noxon_central_freq, callback=self.set_noxon_central_freq, label="Noxon central frequency ", converter=forms.float_converter(), ) self.GridAdd(self._noxon_central_freq_static_text, 1, 0, 1, 1) _af_gain_sizer = wx.BoxSizer(wx.VERTICAL) self._af_gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_af_gain_sizer, value=self.af_gain, callback=self.set_af_gain, label="AF gain", converter=forms.float_converter(), proportion=0, ) self._af_gain_slider = forms.slider( parent=self.GetWin(), sizer=_af_gain_sizer, value=self.af_gain, callback=self.set_af_gain, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_af_gain_sizer, 0, 2, 1, 1) self.xlating_fir_filter = gr.freq_xlating_fir_filter_ccc(4, (filter_taps), -xlate_tune, samp_rate) self.wfm_rcv = blks2.wfm_rcv( quad_rate=samp_rate/4, audio_decimation=5, ) self._rx_freq_static_text = forms.static_text( parent=self.GetWin(), value=self.rx_freq, callback=self.set_rx_freq, label="rx frequency ", converter=forms.float_converter(), ) self.GridAdd(self._rx_freq_static_text, 1, 3, 1, 1) self.rtl2832_source_0 = baz.rtl_source_c(defer_creation=True) self.rtl2832_source_0.set_verbose(True) self.rtl2832_source_0.set_vid(0x0) self.rtl2832_source_0.set_pid(0x0) self.rtl2832_source_0.set_tuner_name("") self.rtl2832_source_0.set_default_timeout(0) self.rtl2832_source_0.set_use_buffer(True) self.rtl2832_source_0.set_fir_coefficients(([])) if self.rtl2832_source_0.create() == False: raise Exception("Failed to create RTL2832 Source: rtl2832_source_0") self.rtl2832_source_0.set_sample_rate(samp_rate) self.rtl2832_source_0.set_frequency(102722000) self.rtl2832_source_0.set_auto_gain_mode(False) self.rtl2832_source_0.set_relative_gain(True) self.rtl2832_source_0.set_gain(3) self.rr_stereo_right = blks2.rational_resampler_fff( interpolation=48, decimation=50, taps=None, fractional_bw=None, ) self.fftsink_rf_0 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=noxon_central_freq, y_per_div=5, y_divs=10, ref_level=0, ref_scale=.5, sample_rate=samp_rate, fft_size=1024, fft_rate=10, average=True, avg_alpha=0.25, title="Total bandwidth", peak_hold=False, win=window.blackmanharris, size=(800,200), ) self.Add(self.fftsink_rf_0.win) self.fftsink_rf = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=0, y_per_div=5, y_divs=10, ref_level=0, ref_scale=.5, sample_rate=samp_rate/4, fft_size=1024, fft_rate=10, average=True, avg_alpha=0.25, title="Baseband", peak_hold=False, size=(800,200), ) self.Add(self.fftsink_rf.win) self.audio_sink = audio.sink(48000, "pulse", True) self.af_gain_stereo_left = gr.multiply_const_vff((af_gain, )) ################################################## # Connections ################################################## self.connect((self.xlating_fir_filter, 0), (self.fftsink_rf, 0)) self.connect((self.af_gain_stereo_left, 0), (self.audio_sink, 0)) self.connect((self.wfm_rcv, 0), (self.rr_stereo_right, 0)) self.connect((self.xlating_fir_filter, 0), (self.wfm_rcv, 0)) self.connect((self.rr_stereo_right, 0), (self.af_gain_stereo_left, 0)) self.connect((self.af_gain_stereo_left, 0), (self.audio_sink, 1)) self.connect((self.xlating_fir_filter, 0), (self.fftsink_rf_0, 0)) self.connect((self.rtl2832_source_0, 0), (self.xlating_fir_filter, 0))
def __init__(self): gr.top_block.__init__(self) parser=OptionParser(option_class=eng_option) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--spec", type="string", default="A:0 A:0", 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("", "--f1", type="eng_float", default=100.7e6, help="set 1st station frequency to FREQ", metavar="FREQ") parser.add_option("", "--f2", type="eng_float", default=102.5e6, help="set 2nd station freq to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-O", "--audio-output", type="string", default="default", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") parser.add_option("", "--freq-min", type="eng_float", default=87.9e6, help="Set a minimum frequency [default=%default]") parser.add_option("", "--freq-max", type="eng_float", default=108.1e6, help="Set a maximum frequency [default=%default]") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) if abs(options.f1 - options.f2) > 5.5e6: print "Sorry, two stations must be within 5.5MHz of each other" raise SystemExit f = (options.f1, options.f2) self.vol = .1 self.state = "FREQ" self.fm_freq_min = options.freq_min self.fm_freq_max = options.freq_max # build graph stream_args = uhd.stream_args('fc32', channels=range(2)) self.u = uhd.usrp_source(device_addr=options.args, stream_args=stream_args) # Set front end channel mapping self.u.set_subdev_spec(options.spec) usrp_rate = 320e3 demod_rate = 320e3 audio_rate = 32e3 audio_decim = int(demod_rate / audio_rate) self.u.set_samp_rate(usrp_rate) dev_rate = self.u.get_samp_rate() # Make sure dboard can suppor the required frequencies frange = self.u.get_freq_range() if(frange.start() > self.fm_freq_max or frange.stop() < self.fm_freq_min): sys.stderr.write("Radio does not support required frequency range.\n") sys.exit(1) # sound card as final sink self.audio_sink = audio.sink(int(audio_rate), options.audio_output) # taps for channel filter nfilts = 32 chan_coeffs = optfir.low_pass (nfilts, # gain nfilts*usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation rrate = usrp_rate / dev_rate # set front end PLL to middle frequency mid_freq = (f[0] + f[1]) / 2.0 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 for n in range(2): chan_filt = blks2.pfb_arb_resampler_ccf(rrate, chan_coeffs, nfilts) guts = blks2.wfm_rcv (demod_rate, audio_decim) volume_control = gr.multiply_const_ff(self.vol) #self.connect((self.di, n), chan_filt) self.connect((self.u, n), chan_filt) self.connect(chan_filt, guts, volume_control) self.connect(volume_control, (self.audio_sink, n)) # Test the the requested frequencies are in range if(f[n] < self.fm_freq_min or f[n] > self.fm_freq_max): sys.stderr.write("Requested frequency is outside of required frequency range.\n") sys.exit(1) # Tune each channel by setting the RF freq to mid_freq and the # DDC freq to f[n]. tr = uhd.tune_request(f[n], rf_freq=mid_freq, rf_freq_policy=uhd.tune_request.POLICY_MANUAL) self.u.set_center_freq(tr, n) # Set gain for each channel self.set_gain(options.gain, n) # Set the antenna if(options.antenna): self.u.set_antenna(options.antenna, n)
def __init__(self, gain=0, audio_output="", samp_rate=400e3, address="addr=192.168.10.2", freq=96e6): grc_wxgui.top_block_gui.__init__(self, title="UHD WBFM Receive") ################################################## # Parameters ################################################## self.gain = gain self.audio_output = audio_output self.samp_rate = samp_rate self.address = address self.freq = freq ################################################## # Variables ################################################## self.volume = volume = 1 self.tun_gain = tun_gain = gain self.tun_freq = tun_freq = freq self.fine = fine = 0 self.audio_decim = audio_decim = 10 ################################################## # Blocks ################################################## _volume_sizer = wx.BoxSizer(wx.VERTICAL) self._volume_text_box = forms.text_box( parent=self.GetWin(), sizer=_volume_sizer, value=self.volume, callback=self.set_volume, label="Volume", converter=forms.float_converter(), proportion=0, ) self._volume_slider = forms.slider( parent=self.GetWin(), sizer=_volume_sizer, value=self.volume, callback=self.set_volume, minimum=0, maximum=10, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_volume_sizer, 1, 0, 1, 4) _tun_gain_sizer = wx.BoxSizer(wx.VERTICAL) self._tun_gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_tun_gain_sizer, value=self.tun_gain, callback=self.set_tun_gain, label="UHD Gain", converter=forms.float_converter(), proportion=0, ) self._tun_gain_slider = forms.slider( parent=self.GetWin(), sizer=_tun_gain_sizer, value=self.tun_gain, callback=self.set_tun_gain, minimum=0, maximum=20, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_tun_gain_sizer) _tun_freq_sizer = wx.BoxSizer(wx.VERTICAL) self._tun_freq_text_box = forms.text_box( parent=self.GetWin(), sizer=_tun_freq_sizer, value=self.tun_freq, callback=self.set_tun_freq, label="Freq (Hz)", converter=forms.float_converter(), proportion=0, ) self._tun_freq_slider = forms.slider( parent=self.GetWin(), sizer=_tun_freq_sizer, value=self.tun_freq, callback=self.set_tun_freq, minimum=87.9e6, maximum=108.1e6, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_tun_freq_sizer) _fine_sizer = wx.BoxSizer(wx.VERTICAL) self._fine_text_box = forms.text_box( parent=self.GetWin(), sizer=_fine_sizer, value=self.fine, callback=self.set_fine, label="Fine Freq (MHz)", converter=forms.float_converter(), proportion=0, ) self._fine_slider = forms.slider( parent=self.GetWin(), sizer=_fine_sizer, value=self.fine, callback=self.set_fine, minimum=-.1, maximum=.1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_fine_sizer, 0, 2, 1, 2) self.wxgui_fftsink2 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=(freq+fine), y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.GridAdd(self.wxgui_fftsink2.win, 2, 0, 2, 4) self.uhd_usrp_source_0 = uhd.usrp_source( device_addr=address, stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(tun_freq+fine, 0) self.uhd_usrp_source_0.set_gain(tun_gain, 0) self.uhd_usrp_source_0.set_antenna("TX/RX", 0) self.low_pass_filter_0 = gr.fir_filter_ccf(1, firdes.low_pass( 1, samp_rate, 115e3, 30e3, firdes.WIN_HANN, 6.76)) self.gr_multiply_const_vxx = gr.multiply_const_vff((volume, )) self.blks2_wfm_rcv = blks2.wfm_rcv( quad_rate=samp_rate, audio_decimation=audio_decim, ) self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_fff( interpolation=48, decimation=40, taps=None, fractional_bw=None, ) self.audio_sink = audio.sink(48000, audio_output, True) ################################################## # Connections ################################################## self.connect((self.gr_multiply_const_vxx, 0), (self.audio_sink, 0)) self.connect((self.low_pass_filter_0, 0), (self.blks2_wfm_rcv, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.wxgui_fftsink2, 0)) self.connect((self.blks2_wfm_rcv, 0), (self.blks2_rational_resampler_xxx_0, 0)) self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.gr_multiply_const_vxx, 0))
def __init__(self,frame,panel,vbox,argv): stdgui2.std_top_block.__init__ (self,frame,panel,vbox,argv) parser=OptionParser(option_class=eng_option) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None, help="select USRP Rx side A or B (default=A)") parser.add_option("-f", "--freq", type="eng_float", default=137.5e6, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-V", "--volume", type="eng_float", default=None, help="set volume (default is midpoint)") parser.add_option("-O", "--audio-output", type="string", default="", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.frame = frame self.panel = panel self.vol = 0 self.state = "FREQ" self.freq = 0 # build graph self.u = usrp.source_c() # usrp is data source adc_rate = self.u.adc_rate() # 64 MS/s usrp_decim = 200 self.u.set_decim_rate(usrp_decim) usrp_rate = adc_rate / usrp_decim # 320 kS/s chanfilt_decim = 4 demod_rate = usrp_rate / chanfilt_decim audio_decimation = 10 audio_rate = demod_rate / audio_decimation # 32 kHz if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.u) self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) print "Using RX d'board %s" % (self.subdev.side_and_name(),) chan_filt_coeffs = optfir.low_pass (1, # gain usrp_rate, # sampling rate 40e3, # passband cutoff 60e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) chan_filt = gr.fir_filter_ccf (chanfilt_decim, chan_filt_coeffs) self.guts = blks2.wfm_rcv (demod_rate, audio_decimation) self.volume_control = gr.multiply_const_ff(self.vol) # sound card as final sink audio_sink = audio.sink (int (audio_rate), options.audio_output) # now wire it all together self.connect (self.u, chan_filt, self.guts, self.volume_control, audio_sink) self._build_gui(vbox, usrp_rate, demod_rate, audio_rate) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.subdev.gain_range() options.gain = float(g[0]+g[1])/2 if options.volume is None: g = self.volume_range() options.volume = float(g[0]+g[1])/2 if abs(options.freq) < 1e6: options.freq *= 1e6 # set initial values self.set_gain(options.gain) self.set_vol(options.volume) if not(self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--spec", type="string", default="A:0 A:0", 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("", "--f1", type="eng_float", default=100.7e6, help="set 1st station frequency to FREQ", metavar="FREQ") parser.add_option("", "--f2", type="eng_float", default=102.5e6, help="set 2nd station freq to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=40, help="set gain in dB (default is midpoint)") parser.add_option( "-O", "--audio-output", type="string", default="", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") parser.add_option("", "--freq-min", type="eng_float", default=87.9e6, help="Set a minimum frequency [default=%default]") parser.add_option("", "--freq-max", type="eng_float", default=108.1e6, help="Set a maximum frequency [default=%default]") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) if abs(options.f1 - options.f2) > 5.5e6: print "Sorry, two stations must be within 5.5MHz of each other" raise SystemExit f = (options.f1, options.f2) self.vol = .1 self.state = "FREQ" self.fm_freq_min = options.freq_min self.fm_freq_max = options.freq_max # build graph stream_args = uhd.stream_args('fc32', channels=range(2)) self.u = uhd.usrp_source(device_addr=options.args, stream_args=stream_args) # Set front end channel mapping self.u.set_subdev_spec(options.spec) usrp_rate = 320e3 demod_rate = 320e3 audio_rate = 32e3 audio_decim = int(demod_rate / audio_rate) self.u.set_samp_rate(usrp_rate) dev_rate = self.u.get_samp_rate() # Make sure dboard can suppor the required frequencies frange = self.u.get_freq_range() if (frange.start() > self.fm_freq_max or frange.stop() < self.fm_freq_min): sys.stderr.write( "Radio does not support required frequency range.\n") sys.exit(1) # sound card as final sink self.audio_sink = audio.sink(int(audio_rate), options.audio_output) # taps for channel filter nfilts = 32 chan_coeffs = optfir.low_pass( nfilts, # gain nfilts * usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation rrate = usrp_rate / dev_rate # set front end PLL to middle frequency mid_freq = (f[0] + f[1]) / 2.0 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 for n in range(2): chan_filt = blks2.pfb_arb_resampler_ccf(rrate, chan_coeffs, nfilts) guts = blks2.wfm_rcv(demod_rate, audio_decim) volume_control = gr.multiply_const_ff(self.vol) #self.connect((self.di, n), chan_filt) self.connect((self.u, n), chan_filt) self.connect(chan_filt, guts, volume_control) self.connect(volume_control, (self.audio_sink, n)) # Test the the requested frequencies are in range if (f[n] < self.fm_freq_min or f[n] > self.fm_freq_max): sys.stderr.write( "Requested frequency is outside of required frequency range.\n" ) sys.exit(1) # Tune each channel by setting the RF freq to mid_freq and the # DDC freq to f[n]. tr = uhd.tune_request( f[n], rf_freq=mid_freq, rf_freq_policy=uhd.tune_request.POLICY_MANUAL) self.u.set_center_freq(tr, n) # Set gain for each channel self.set_gain(options.gain, n) # Set the antenna if (options.antenna): self.u.set_antenna(options.antenna, n)
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) parser = OptionParser(option_class=eng_option) parser.add_option("-e", "--interface", type="string", default="eth0", help="select Ethernet interface, default is eth0") parser.add_option( "-m", "--mac-addr", type="string", default="", help="select USRP by MAC address, default is auto-select") #parser.add_option("-A", "--antenna", default=None, # help="select Rx Antenna (only on RFX-series boards)") parser.add_option("-f", "--freq", type="eng_float", default=100.1, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-V", "--volume", type="eng_float", default=None, help="set volume (default is midpoint)") parser.add_option( "-O", "--audio-output", type="string", default="", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.frame = frame self.panel = panel self.vol = 0 self.state = "FREQ" self.freq = 0 # build graph self.u = usrp2.source_32fc(options.interface, options.mac_addr) adc_rate = self.u.adc_rate() # 100 MS/s usrp_decim = 312 self.u.set_decim(usrp_decim) usrp_rate = adc_rate / usrp_decim # ~320 kS/s chanfilt_decim = 1 demod_rate = usrp_rate / chanfilt_decim audio_decimation = 10 audio_rate = demod_rate / audio_decimation # ~32 kHz #FIXME: need named constants and text descriptions available to (gr-)usrp2 even #when usrp(1) module is not built. A usrp_common module, perhaps? dbid = self.u.daughterboard_id() print "Using RX d'board 0x%04X" % (dbid, ) if not (dbid == 0x0001 or #usrp_dbid.BASIC_RX dbid == 0x0003 or #usrp_dbid.TV_RX dbid == 0x000c or #usrp_dbid.TV_RX_REV_2 dbid == 0x0040 or #usrp_dbid.TV_RX_REV_3 dbid == 0x0043 or #usrp_dbid.TV_RX_MIMO dbid == 0x0044 or #usrp_dbid.TV_RX_REV_2_MIMO dbid == 0x0045): #usrp_dbid.TV_RX_REV_3_MIMO print "This daughterboard does not cover the required frequency range" print "for this application. Please use a BasicRX or TVRX daughterboard." raw_input("Press ENTER to continue anyway, or Ctrl-C to exit.") chan_filt_coeffs = optfir.low_pass( 1, # gain usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) chan_filt = gr.fir_filter_ccf(chanfilt_decim, chan_filt_coeffs) self.guts = blks2.wfm_rcv(demod_rate, audio_decimation) self.volume_control = gr.multiply_const_ff(self.vol) # sound card as final sink audio_sink = audio.sink(int(audio_rate), options.audio_output, False) # ok_to_block # now wire it all together self.connect(self.u, chan_filt, self.guts, self.volume_control, audio_sink) self._build_gui(vbox, usrp_rate, demod_rate, audio_rate) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.gain_range() options.gain = float(g[0] + g[1]) / 2 if options.volume is None: g = self.volume_range() options.volume = float(g[0] + g[1]) / 2 if abs(options.freq) < 1e6: options.freq *= 1e6 # set initial values self.set_gain(options.gain) self.set_vol(options.volume) if not (self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Example bitcpf - FM Rx") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 8e6 self.rx_gain = rx_gain = 15 self.lpf_decim = lpf_decim = 20 self.freq = freq = 106.7e6 self.audio_samp_rate = audio_samp_rate = 96e3 ################################################## # Blocks ################################################## _rx_gain_sizer = wx.BoxSizer(wx.VERTICAL) self._rx_gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_rx_gain_sizer, value=self.rx_gain, callback=self.set_rx_gain, label='rx_gain', converter=forms.float_converter(), proportion=0, ) self._rx_gain_slider = forms.slider( parent=self.GetWin(), sizer=_rx_gain_sizer, value=self.rx_gain, callback=self.set_rx_gain, minimum=0, maximum=30, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_rx_gain_sizer) self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "RF") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Audio") self.Add(self.notebook_0) self._freq_text_box = forms.text_box( parent=self.GetWin(), value=self.freq, callback=self.set_freq, label='freq', converter=forms.float_converter(), ) self.Add(self._freq_text_box) self.wxgui_fftsink2_1 = fftsink2.fft_sink_f( self.notebook_0.GetPage(1).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate/lpf_decim, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.notebook_0.GetPage(1).Add(self.wxgui_fftsink2_1.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.notebook_0.GetPage(0).GetWin(), baseband_freq=freq, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.notebook_0.GetPage(0).Add(self.wxgui_fftsink2_0.win) self.uhd_usrp_source_0 = uhd.usrp_source( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(freq, 0) self.uhd_usrp_source_0.set_gain(rx_gain, 0) self.uhd_usrp_source_0.set_antenna("TX/RX", 0) self.low_pass_filter_0 = gr.fir_filter_ccf(lpf_decim, firdes.low_pass( 1, samp_rate, 100e3, 10e3, firdes.WIN_HAMMING, 6.76)) self.gr_wavfile_sink_0 = gr.wavfile_sink("fm_record.wav", 1, int(audio_samp_rate), 8) self.blks2_wfm_rcv_0 = blks2.wfm_rcv( quad_rate=samp_rate/lpf_decim, audio_decimation=1, ) self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_fff( interpolation=96, decimation=int(samp_rate/lpf_decim/1000), taps=None, fractional_bw=None, ) self.audio_sink_0 = audio.sink(int(audio_samp_rate), "", True) ################################################## # Connections ################################################## self.connect((self.low_pass_filter_0, 0), (self.blks2_wfm_rcv_0, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.blks2_rational_resampler_xxx_0, 0)) self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.gr_wavfile_sink_0, 0)) self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.wxgui_fftsink2_1, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.wxgui_fftsink2_0, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Ettus Fm") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 5e6 self.freq = freq = 93.5e6 ################################################## # Blocks ################################################## self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "RF Spectrum") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Demod Spectrum") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "Audio") self.Add(self.notebook_0) self._freq_text_box = forms.text_box( parent=self.GetWin(), value=self.freq, callback=self.set_freq, label='freq', converter=forms.float_converter(), ) self.Add(self._freq_text_box) self.wxgui_fftsink2_2 = fftsink2.fft_sink_f( self.notebook_0.GetPage(2).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=48e3, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.notebook_0.GetPage(2).Add(self.wxgui_fftsink2_2.win) self.wxgui_fftsink2_1 = fftsink2.fft_sink_f( self.notebook_0.GetPage(1).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=250e3, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.notebook_0.GetPage(1).Add(self.wxgui_fftsink2_1.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.notebook_0.GetPage(0).GetWin(), baseband_freq=freq, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.notebook_0.GetPage(0).Add(self.wxgui_fftsink2_0.win) self.uhd_usrp_source_0 = uhd.usrp_source( device_addr="addr=192.168.10.2", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(freq, 0) self.uhd_usrp_source_0.set_gain(25, 0) self.uhd_usrp_source_0.set_antenna("TX/RX", 0) self.uhd_usrp_source_0.set_bandwidth(200e3, 0) self.low_pass_filter_0 = gr.fir_filter_ccf(20, firdes.low_pass( 1, samp_rate, 100e3, 10e3, firdes.WIN_HAMMING, 6.76)) self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((5, )) self.blks2_wfm_rcv_0 = blks2.wfm_rcv( quad_rate=250e3, audio_decimation=1, ) self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_fff( interpolation=48, decimation=250, taps=None, fractional_bw=None, ) self.audio_sink_0 = audio.sink(48000, "", True) ################################################## # Connections ################################################## self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.blks2_wfm_rcv_0, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.blks2_rational_resampler_xxx_0, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.wxgui_fftsink2_1, 0)) self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.gr_multiply_const_vxx_0, 0)) self.connect((self.gr_multiply_const_vxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.wxgui_fftsink2_2, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.trans_width = trans_width = 20e3 self.samp_rate = samp_rate = 1152e3 self.quad_rate = quad_rate = 192e3 self.freq = freq = 91.9e6 self.cutoff_freq = cutoff_freq = 100e3 ################################################## # Blocks ################################################## self._trans_width_text_box = forms.text_box( parent=self.GetWin(), value=self.trans_width, callback=self.set_trans_width, label="Transition Width", converter=forms.float_converter(), ) self.Add(self._trans_width_text_box) self._quad_rate_text_box = forms.text_box( parent=self.GetWin(), value=self.quad_rate, callback=self.set_quad_rate, label="Quadrature Rate", converter=forms.float_converter(), ) self.Add(self._quad_rate_text_box) self._freq_text_box = forms.text_box( parent=self.GetWin(), value=self.freq, callback=self.set_freq, label="Frequency", converter=forms.float_converter(), ) self.Add(self._freq_text_box) self._cutoff_freq_text_box = forms.text_box( parent=self.GetWin(), value=self.cutoff_freq, callback=self.set_cutoff_freq, label="Cutoff Frequency", converter=forms.float_converter(), ) self.Add(self._cutoff_freq_text_box) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot - Source", peak_hold=False, ) self.Add(self.wxgui_fftsink2_0.win) self.rtlsdr_source_c_0 = osmosdr.source_c( args="nchan=" + str(1) + " " + "" ) self.rtlsdr_source_c_0.set_sample_rate(samp_rate) self.rtlsdr_source_c_0.set_center_freq(freq, 0) self.rtlsdr_source_c_0.set_freq_corr(0, 0) self.rtlsdr_source_c_0.set_dc_offset_mode(0, 0) self.rtlsdr_source_c_0.set_iq_balance_mode(0, 0) self.rtlsdr_source_c_0.set_gain_mode(0, 0) self.rtlsdr_source_c_0.set_gain(10, 0) self.rtlsdr_source_c_0.set_if_gain(20, 0) self.rtlsdr_source_c_0.set_bb_gain(20, 0) self.rtlsdr_source_c_0.set_antenna("", 0) self.rtlsdr_source_c_0.set_bandwidth(0, 0) self.low_pass_filter_0 = gr.fir_filter_ccf(6, firdes.low_pass( 2, samp_rate, cutoff_freq, trans_width, firdes.WIN_HAMMING, 6.76)) self.blks2_wfm_rcv_0 = blks2.wfm_rcv( quad_rate=quad_rate, audio_decimation=4, ) self.audio_sink_0 = audio.sink(48000, "", True) ################################################## # Connections ################################################## self.connect((self.low_pass_filter_0, 0), (self.blks2_wfm_rcv_0, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.audio_sink_0, 0)) self.connect((self.rtlsdr_source_c_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.rtlsdr_source_c_0, 0), (self.low_pass_filter_0, 0))
def __init__(self,frame,panel,vbox,argv): stdgui2.std_top_block.__init__ (self,frame,panel,vbox,argv) parser = OptionParser(option_class=eng_option) parser.add_option("-e", "--interface", type="string", default="eth0", help="select Ethernet interface, default is eth0") parser.add_option("-m", "--mac-addr", type="string", default="", help="select USRP by MAC address, default is auto-select") #parser.add_option("-A", "--antenna", default=None, # help="select Rx Antenna (only on RFX-series boards)") parser.add_option("-f", "--freq", type="eng_float", default=100.1, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-V", "--volume", type="eng_float", default=None, help="set volume (default is midpoint)") parser.add_option("-O", "--audio-output", type="string", default="", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.frame = frame self.panel = panel self.vol = 0 self.state = "FREQ" self.freq = 0 # build graph self.u = usrp2.source_32fc(options.interface, options.mac_addr) adc_rate = self.u.adc_rate() # 100 MS/s usrp_decim = 312 self.u.set_decim(usrp_decim) usrp_rate = adc_rate / usrp_decim # ~320 kS/s chanfilt_decim = 1 demod_rate = usrp_rate / chanfilt_decim audio_decimation = 10 audio_rate = demod_rate / audio_decimation # ~32 kHz #FIXME: need named constants and text descriptions available to (gr-)usrp2 even #when usrp(1) module is not built. A usrp_common module, perhaps? dbid = self.u.daughterboard_id() print "Using RX d'board 0x%04X" % (dbid,) if not (dbid == 0x0001 or #usrp_dbid.BASIC_RX dbid == 0x0003 or #usrp_dbid.TV_RX dbid == 0x000c or #usrp_dbid.TV_RX_REV_2 dbid == 0x0040 or #usrp_dbid.TV_RX_REV_3 dbid == 0x0043 or #usrp_dbid.TV_RX_MIMO dbid == 0x0044 or #usrp_dbid.TV_RX_REV_2_MIMO dbid == 0x0045 ): #usrp_dbid.TV_RX_REV_3_MIMO print "This daughterboard does not cover the required frequency range" print "for this application. Please use a BasicRX or TVRX daughterboard." raw_input("Press ENTER to continue anyway, or Ctrl-C to exit.") chan_filt_coeffs = optfir.low_pass (1, # gain usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation #print len(chan_filt_coeffs) chan_filt = gr.fir_filter_ccf (chanfilt_decim, chan_filt_coeffs) self.guts = blks2.wfm_rcv (demod_rate, audio_decimation) self.volume_control = gr.multiply_const_ff(self.vol) # sound card as final sink audio_sink = audio.sink (int (audio_rate), options.audio_output, False) # ok_to_block # now wire it all together self.connect (self.u, chan_filt, self.guts, self.volume_control, audio_sink) self._build_gui(vbox, usrp_rate, demod_rate, audio_rate) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.gain_range() options.gain = float(g[0]+g[1])/2 if options.volume is None: g = self.volume_range() options.volume = float(g[0]+g[1])/2 if abs(options.freq) < 1e6: options.freq *= 1e6 # set initial values self.set_gain(options.gain) self.set_vol(options.volume) if not(self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Fm1") _icon_path = "/usr/local/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 1000000 self.frq_offset = frq_offset = 0 self.base_freq_slider = base_freq_slider = 88.5e6 ################################################## # Blocks ################################################## _frq_offset_sizer = wx.BoxSizer(wx.VERTICAL) self._frq_offset_text_box = forms.text_box( parent=self.GetWin(), sizer=_frq_offset_sizer, value=self.frq_offset, callback=self.set_frq_offset, label='frq_offset', converter=forms.float_converter(), proportion=0, ) self._frq_offset_slider = forms.slider( parent=self.GetWin(), sizer=_frq_offset_sizer, value=self.frq_offset, callback=self.set_frq_offset, minimum=-200000, maximum=200000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_frq_offset_sizer) _base_freq_slider_sizer = wx.BoxSizer(wx.VERTICAL) self._base_freq_slider_text_box = forms.text_box( parent=self.GetWin(), sizer=_base_freq_slider_sizer, value=self.base_freq_slider, callback=self.set_base_freq_slider, label='base_freq_slider', converter=forms.float_converter(), proportion=0, ) self._base_freq_slider_slider = forms.slider( parent=self.GetWin(), sizer=_base_freq_slider_sizer, value=self.base_freq_slider, callback=self.set_base_freq_slider, minimum=88e6, maximum=108e6, num_steps=400, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_base_freq_slider_sizer) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=512, fft_rate=2, average=False, avg_alpha=None, title="Waterfall Plot", ) self.Add(self.wxgui_waterfallsink2_0.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=512, fft_rate=1, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.Add(self.wxgui_fftsink2_0.win) self.rtl2832_source_0 = baz.rtl_source_c(defer_creation=True) self.rtl2832_source_0.set_verbose(True) self.rtl2832_source_0.set_vid(0x0) self.rtl2832_source_0.set_pid(0x0) self.rtl2832_source_0.set_tuner_name("") self.rtl2832_source_0.set_default_timeout(0) self.rtl2832_source_0.set_use_buffer(True) self.rtl2832_source_0.set_fir_coefficients(([])) if self.rtl2832_source_0.create() == False: raise Exception("Failed to create RTL2832 Source: rtl2832_source_0") self.rtl2832_source_0.set_bandwidth(200000) self.rtl2832_source_0.set_sample_rate(samp_rate) self.rtl2832_source_0.set_frequency(base_freq_slider) self.rtl2832_source_0.set_auto_gain_mode(False) self.rtl2832_source_0.set_relative_gain(True) self.rtl2832_source_0.set_gain(1) self.gr_freq_xlating_fir_filter_xxx_0 = gr.freq_xlating_fir_filter_ccc(1, (10, ), frq_offset, samp_rate) self.blks2_wfm_rcv_0 = blks2.wfm_rcv( quad_rate=48000, audio_decimation=1, ) self.blks2_rational_resampler_xxx_0 = blks2.rational_resampler_ccc( interpolation=48000, decimation=1000000, taps=None, fractional_bw=None, ) self.audio_sink_0 = audio.sink(48000, "pulse", True) ################################################## # Connections ################################################## self.connect((self.blks2_rational_resampler_xxx_0, 0), (self.blks2_wfm_rcv_0, 0)) self.connect((self.blks2_wfm_rcv_0, 0), (self.audio_sink_0, 0)) self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.blks2_rational_resampler_xxx_0, 0)) self.connect((self.rtl2832_source_0, 0), (self.gr_freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.wxgui_waterfallsink2_0, 0))