def __init__(self, options, queue): gr.top_block.__init__(self, "rtl_flex_noX") self.options = options self.offset = 0.0 self.adj_time = time.time() self.verbose = options.verbose self.log = options.log # Set up rtl source self.u = osmosdr.source(args="%s" % (options.device)) # set Freq self.u.set_center_freq(options.freq + options.calibration, 0) # Grab 250 KHz of spectrum self.u.set_sample_rate(250e3) rate = self.u.get_sample_rate() if rate != 250e3: print "Unable to set required sample rate of 250 Ksps (got %f)" % rate sys.exit(1) # Set gain if options.rx_gain is None: grange = self.u.get_gain_range() options.rx_gain = float(grange.start() + grange.stop()) / 2.0 print "\nNo gain specified." print "Setting gain to %f (from [%f, %f])" % (options.rx_gain, grange.start(), grange.stop()) self.u.set_gain(options.rx_gain, 0) taps = optfir.low_pass(1.0, 250e3, 11000, 12500, 0.1, 60) self.chan = filter.freq_xlating_fir_filter_ccf(10, taps, 0.0, 250e3) self.flex = pager.flex_demod(queue, options.freq, options.verbose, options.log) self.connect(self.u, self.chan, self.flex)
def __init__(self, options, queue): gr.top_block.__init__(self, "rtl_flex_noX") self.options = options self.offset = 0.0 self.adj_time = time.time() self.verbose = options.verbose self.log = options.log # Set up rtl source self.u = osmosdr.source(args="%s" % (options.device)) #set Freq self.u.set_center_freq(options.freq + options.calibration, 0) # Grab 250 KHz of spectrum self.u.set_sample_rate(250e3) rate = self.u.get_sample_rate() if rate != 250e3: print "Unable to set required sample rate of 250 Ksps (got %f)" % rate sys.exit(1) #Set gain if options.rx_gain is None: grange = self.u.get_gain_range() options.rx_gain = float(grange.start() + grange.stop()) / 2.0 print "\nNo gain specified." print "Setting gain to %f (from [%f, %f])" % \ (options.rx_gain, grange.start(), grange.stop()) self.u.set_gain(options.rx_gain, 0) taps = optfir.low_pass(1.0, 250e3, 11000, 12500, 0.1, 60) self.chan = filter.freq_xlating_fir_filter_ccf(10, taps, 0.0, 250e3) self.flex = pager.flex_demod(queue, options.freq, options.verbose, options.log) self.connect(self.u, self.chan, self.flex)
def __init__(self, options, queue): grc_wxgui.top_block_gui.__init__(self, title="RTL FLEX reciever") self.options = options self.offset = 0.0 self.adj_time = time.time() self.verbose = options.verbose self.log = options.log self.fft_enable = options.fft # Set up rtl source self.u = osmosdr.source( args="%s"%(options.device) ) #set Freq self.u.set_center_freq(options.freq+options.calibration, 0) # Grab 250 KHz of spectrum self.u.set_sample_rate(250e3) rate = self.u.get_sample_rate() if rate != 250e3: print "Unable to set required sample rate of 250 Ksps (got %f)" % rate sys.exit(1) #Set gain if options.rx_gain is None: grange = self.u.get_gain_range() options.rx_gain = float(grange.start()+grange.stop())/2.0 print "\nNo gain specified." print "Setting gain to %f (from [%f, %f])" % \ (options.rx_gain, grange.start(), grange.stop()) self.u.set_gain(options.rx_gain, 0) taps = optfir.low_pass(1.0, 250e3, 11000, 12500, 0.1, 60) self.chan = filter.freq_xlating_fir_filter_ccf(10, taps, 0.0, 250e3) if self.fft_enable: self.fftsink = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=options.freq+options.calibration, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=250e3, fft_size=1024, fft_rate=15, average=True, avg_alpha=None, title="RTL Output", peak_hold=False, ) self.Add(self.fftsink.win) self.fftsink2 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=options.freq+options.calibration, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=250e3, fft_size=1024, fft_rate=15, average=True, avg_alpha=None, title="Decoder input (After the filters)", peak_hold=False, ) self.Add(self.fftsink2.win) self.flex = pager.flex_demod(queue, options.freq, options.verbose, options.log) self.connect(self.u, self.chan, self.flex) if self.fft_enable: self.connect(self.u, self.fftsink) self.connect(self.chan, self.fftsink2)
def __init__(self, options, queue): grc_wxgui.top_block_gui.__init__(self, title="RTL FLEX reciever") self.options = options self.offset = 0.0 self.adj_time = time.time() self.verbose = options.verbose self.log = options.log self.fft_enable = options.fft # Set up rtl source self.u = osmosdr.source(args="%s" % (options.device)) #set Freq self.u.set_center_freq(options.freq + options.calibration, 0) # Grab 250 KHz of spectrum self.u.set_sample_rate(250e3) rate = self.u.get_sample_rate() if rate != 250e3: print "Unable to set required sample rate of 250 Ksps (got %f)" % rate sys.exit(1) #Set gain if options.rx_gain is None: grange = self.u.get_gain_range() options.rx_gain = float(grange.start() + grange.stop()) / 2.0 print "\nNo gain specified." print "Setting gain to %f (from [%f, %f])" % \ (options.rx_gain, grange.start(), grange.stop()) self.u.set_gain(options.rx_gain, 0) taps = optfir.low_pass(1.0, 250e3, 11000, 12500, 0.1, 60) self.chan = filter.freq_xlating_fir_filter_ccf(10, taps, 0.0, 250e3) if self.fft_enable: self.fftsink = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=options.freq + options.calibration, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=250e3, fft_size=1024, fft_rate=15, average=True, avg_alpha=None, title="RTL Output", peak_hold=False, ) self.Add(self.fftsink.win) self.fftsink2 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=options.freq + options.calibration, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=250e3, fft_size=1024, fft_rate=15, average=True, avg_alpha=None, title="Decoder input (After the filters)", peak_hold=False, ) self.Add(self.fftsink2.win) self.flex = pager.flex_demod(queue, options.freq, options.verbose, options.log) self.connect(self.u, self.chan, self.flex) if self.fft_enable: self.connect(self.u, self.fftsink) self.connect(self.chan, self.fftsink2)
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) # station is the frequency to be received station = parseargs(argv[1:]) adc_rate = 64e6 #output sample rate of the ADC, 64Ms/s usrp_decim = 250 usrp_rate = adc_rate / usrp_decim # output sample rate of the usrp, 256 ks/s lpf_decim = 4 lpf_rate = usrp_rate / lpf_decim # 64 kHz # usrp is data source # tells which usrp board is used and what the dec rate is #src = usrp.source_c (0, usrp_decim) #Tell USRP what daughter board to use and displays name #(1,0) means side B, 1st channel - picks daughterboard #rx_subdev_spec = (1,0) #src.set_mux(usrp.determine_rx_mux_value(src,rx_subdev_spec)) #subdev = usrp.selected_subdev(src,rx_subdev_spec) #print "Using daughterboard",subdev.name() #sets the shift frequency of the ddc (on FPGA) Note: must be minus or FFT display is reversed JF 08-08-08 #src.set_rx_freq (0, -station) #Turn up USRP gain to maximum #g = subdev.gain_range() #subdev.set_gain(float(g[1])) # checks the actual shift frequency #actual_shift_freq =src.rx_freq(0) #this line is to allow playback without usrp actual_shift_freq = -710000 #print "Actual DDC shift frequency", actual_shift_freq #print "USRP gain ", float(g[1]) # set gain on USRP #src.set_pga(0,20) #defines a file to collect usrp output #am_usrp_sink = gr.file_sink(gr.sizeof_gr_complex, "am_usrp710.dat") #self.connect(src, am_usrp_sink) #defines the file to playback the usrp data from am_usrp_source = blocks.file_source(gr.sizeof_gr_complex, "am_usrp710.dat") # computes taps for LPF and creates channel filter with those taps channel_coeffs = optfir.low_pass( 1.0, # gain usrp_rate, # sampling rate 4.5e3, # low pass cutoff freq 5e3, # width of trans. band 0.1, #passband ripple 60) #stopband attenuation #set frequency shift for picking up other signals offset = 0 chan_filter = filter.freq_xlating_fir_filter_ccf( lpf_decim, channel_coeffs, offset, usrp_rate) # define a file to collect channel filter output and connect #chan_sink = gr.file_sink(gr.sizeof_gr_complex, "chan.dat") #self.connect(chan_filter, chan_sink) #create an automatic gain control (AGC) block with 1 second time constant decay .1 attack. my_agc = analog.agc2_cc(1.5e-4, 1.5e-5, 10, 1) # create a block to take the magnitude (envelope) of the AM Signal magblock = blocks.complex_to_mag() # define and connect a sink of collect the output of the magnitude block #mag_sink = gr.file_sink(gr.sizeof_float, "mag.dat") #self.connect(magblock, mag_sink) #create a volume control and collect data into a file volumecontrol = blocks.multiply_const_ff(.04) #volcont_sink = gr.file_sink(gr.sizeof_float, "volcont.dat") #self.connect(volumecontrol, volcont_sink) # compute FIR filter taps for audio filter audio_coeffs = optfir.low_pass( 1.0, # gain lpf_rate, # sampling rate 4.5e3, # edge of passband 5e3, # edge of stopband, 0.1, #passband ripple 60) # stopband ripple # create audio filter and a file for its output audio_filter = filter.fir_filter_fff(1, audio_coeffs) #audio_filt_sink = gr.file_sink(gr.sizeof_float, "audio_filt.dat") #self.connect(audio_filter, audio_filt_sink) # create a resampler to bring 64ks/s rate to 48ks/s for audio card and data file rsamp = filter.rational_resampler_fff(3, 4) #rsamp_sink = gr.file_sink(gr.sizeof_float, "rsamp.dat") #self.connect(rsamp, rsamp_sink) #create a sink representing the audio card audio_sink = audio.sink(int(48000)) # now wire it all together #use this line to receive from usrp #self.connect (src,chan_filter) #use this line to playback recorded data self.connect(am_usrp_source, chan_filter) self.connect(chan_filter, my_agc) self.connect(my_agc, magblock) self.connect(magblock, volumecontrol) self.connect(volumecontrol, audio_filter) self.connect(audio_filter, rsamp) self.connect(rsamp, (audio_sink, 0)) if 1: pre_demod = fftsink2.fft_sink_c(panel, title="USRP Output", ref_level=70, fft_size=512, sample_rate=usrp_rate) self.connect(am_usrp_source, pre_demod) vbox.Add(pre_demod.win, 1, wx.EXPAND) #Sets offset for floating pointer in FFT window pre_demod.win.set_baseband_freq(-actual_shift_freq) if False: post_demod = fftsink2.fft_sink_c(panel, title="Post Channel Filter", fft_size=256, sample_rate=lpf_rate) self.connect(chan_filter, post_demod) vbox.Add(post_demod.win, 1, wx.EXPAND) if False: post_filt = fftsink2.fft_sink_f(panel, title="Post Envelope Detector", fft_size=512, sample_rate=lpf_rate) self.connect(magblock, post_filt) vbox.Add(post_filt.win, 1, wx.EXPAND)
def __init__(self): gr.top_block.__init__(self, 'receiver') self.log = logging.getLogger('frontend') try: gr.enable_realtime_scheduling() except: pass self.access_lock = threading.RLock() self.access_lock.acquire() self.last_channel_cleanup = time.time() self.channel_idle_timeout = 300 self.config = config = rc_config() try: self.scan_mode = config.scan_mode except: self.scan_mode = False self.realsources = config.sources self.sources = {} numsources = 0 for source in self.realsources: if config.receiver_split2: newsource1 = copy.copy(self.realsources[source]) newsource2 = copy.copy(self.realsources[source]) decim = 2 samp_rate = self.realsources[source]['samp_rate'] channel_rate = (samp_rate / decim) / 2 transition = channel_rate * 0.5 taps = firdes.low_pass(1, samp_rate, channel_rate, transition) filt1 = filter.freq_xlating_fir_filter_ccc( decim, (taps), -samp_rate / 4, samp_rate) filt2 = filter.freq_xlating_fir_filter_ccc( decim, (taps), samp_rate / 4, samp_rate) if self.realsources[source]['type'] == 'usrp': from gnuradio import uhd this_dev = uhd.usrp_source( device_addr=self.realsources[source]['device_addr'], stream_args=uhd.stream_args( cpu_format="fc32", otw_format=self.realsources[source]['otw_format'], args=self.realsources[source]['args'], ), ) this_dev.set_samp_rate(self.realsources[source]['samp_rate']) this_dev.set_center_freq( self.realsources[source]['center_freq']) this_dev.set_gain(self.realsources[source]['rf_gain']) try: null_sink = gr.null_sink(gr.sizeof_gr_complex * 1) except: null_sink = blocks.null_sink(gr.sizeof_gr_complex * 1) #self.connect(this_dev, null_sink) self.realsources[source]['block'] = this_dev if self.realsources[source]['type'] == 'usrp2x': from gnuradio import uhd this_dev = uhd.usrp_source( device_addr=self.realsources[source]['device_addr'], stream_args=uhd.stream_args( cpu_format="fc32", otw_format=self.realsources[source]['otw_format'], args=self.realsources[source]['args'], channels=range(2), ), ) this_dev.set_subdev_spec('A:RX1 A:RX2', 0) this_dev.set_samp_rate(self.realsources[source]['samp_rate']) this_dev.set_center_freq( self.realsources[source]['center_freq'], 0) this_dev.set_center_freq( self.realsources[source + 1]['center_freq'], 1) this_dev.set_gain(self.realsources[source]['rf_gain'], 0) this_dev.set_gain(self.realsources[source + 1]['rf_gain'], 1) multiply = blocks.multiply_const_vcc((1, )) try: null_sink = gr.null_sink(gr.sizeof_gr_complex * 1) except: null_sink = blocks.null_sink(gr.sizeof_gr_complex * 1) #self.connect((this_dev,0), multiply, null_sink) self.realsources[source]['block'] = multiply multiply = blocks.multiply_const_vcc((1, )) try: null_sink = gr.null_sink(gr.sizeof_gr_complex * 1) except: null_sink = blocks.null_sink(gr.sizeof_gr_complex * 1) #self.connect((this_dev,1), multiply, null_sink) self.realsources[source + 1]['block'] = multiply if self.realsources[source]['type'] == 'bladerf': import osmosdr this_dev = osmosdr.source( args=self.realsources[source]['args']) this_dev.set_sample_rate(self.realsources[source]['samp_rate']) this_dev.set_center_freq( self.realsources[source]['center_freq'], 0) this_dev.set_freq_corr(0, 0) #this_dev.set_dc_offset_mode(0, 0) #this_dev.set_iq_balance_mode(0, 0) this_dev.set_gain_mode(0, 0) this_dev.set_gain(self.realsources[source]['rf_gain'], 0) this_dev.set_if_gain(20, 0) this_dev.set_bb_gain(self.realsources[source]['bb_gain'], 0) this_dev.set_antenna("", 0) this_dev.set_bandwidth(0, 0) try: null_sink = gr.null_sink(gr.sizeof_gr_complex * 1) except: null_sink = blocks.null_sink(gr.sizeof_gr_complex * 1) #self.connect(this_dev, null_sink) self.realsources[source]['block'] = this_dev if self.realsources[source]['type'] == 'rtlsdr': import osmosdr #process = os.popen('CellSearch -i '+ str(self.realsources[source]['serial']) +' -s 739e6 -e 739e6 -b | grep 739M | awk \'{sum+=$10} END { printf("%.10f", sum/NR)}\'') #output = float(process.read()) #process.close() #self.realsources[source]['offset'] = (1000000-(output*1000000)) #self.realsources[source]['offset'] = 0 #print 'Measured PPM - Dev#%s: %s' % (source, self.realsources[source]['offset']) this_dev = osmosdr.source( args=self.realsources[source]['args']) this_dev.set_sample_rate(self.realsources[source]['samp_rate']) this_dev.set_center_freq( self.realsources[source]['center_freq'] + self.realsources[source]['offset'], 0) #this_dev.set_freq_corr(self.realsources[source]['offset'], 0) this_dev.set_max_output_buffer(65535 * 64) this_dev.set_dc_offset_mode(1, 0) this_dev.set_iq_balance_mode(1, 0) this_dev.set_gain_mode(False, 0) this_dev.set_gain(self.realsources[source]['rf_gain'], 0) this_dev.set_if_gain(30, 0) this_dev.set_bb_gain(self.realsources[source]['bb_gain'], 0) try: null_sink = gr.null_sink(gr.sizeof_gr_complex * 1) except: null_sink = blocks.null_sink(gr.sizeof_gr_complex * 1) self.connect(this_dev, null_sink) self.realsources[source]['block'] = this_dev if config.receiver_split2: newsource1 = copy.copy(self.realsources[source]) newsource2 = copy.copy(self.realsources[source]) decim = 2 samp_rate = self.realsources[source]['samp_rate'] channel_rate = (samp_rate / decim) / 2 transition = channel_rate * 0.5 taps = firdes.low_pass(1, samp_rate, channel_rate, transition) filt1 = filter.freq_xlating_fir_filter_ccc( decim, (taps), -samp_rate / 4, samp_rate) filt2 = filter.freq_xlating_fir_filter_ccc( decim, (taps), samp_rate / 4, samp_rate) null_sink1 = blocks.null_sink(gr.sizeof_gr_complex * 1) null_sink2 = blocks.null_sink(gr.sizeof_gr_complex * 1) self.connect(self.realsources[source]['block'], filt1, null_sink1) self.connect(self.realsources[source]['block'], filt2, null_sink2) newsource1['block'] = filt1 newsource1['center_freq'] = self.realsources[source][ 'center_freq'] - self.realsources[source]['samp_rate'] / 4 newsource1['samp_rate'] = newsource1['samp_rate'] / decim newsource2['block'] = filt2 newsource2['center_freq'] = self.realsources[source][ 'center_freq'] + self.realsources[source]['samp_rate'] / 4 newsource2['samp_rate'] = newsource2['samp_rate'] / decim self.sources[numsources] = newsource1 numsources = numsources + 1 self.sources[numsources] = newsource2 numsources = numsources + 1 else: self.sources[numsources] = self.realsources[source] numsources = numsources + 1 if self.config.frontend_mode == 'pfb': for source in self.sources: self.target_size = target_size = 400000 if (self.sources[source]['samp_rate'] % target_size): raise Exception('samp_rate not round enough') num_channels = int( math.ceil(self.sources[source]['samp_rate'] / target_size)) self.sources[source]['pfb'] = pfb.channelizer_ccf( num_channels, (optfir.low_pass( 1, num_channels, 0.5, 0.5 + 0.2, 0.1, 80)), 1.0, 100) self.sources[source]['pfb'].set_channel_map(([])) #null_sink = blocks.null_sink(gr.sizeof_gr_complex*1) #self.connect((self.sources[source]['pfb'], 0), null_sink) for x in range(0, num_channels): null_sink = blocks.null_sink(gr.sizeof_gr_complex * 1) self.connect((self.sources[source]['pfb'], x), null_sink) self.connect(self.sources[source]['block'], self.sources[source]['pfb']) self.channels = {} #for i in self.sources.keys(): # self.channels[i] = [] self.start() self.access_lock.release()
def __init__(self, sample_rate, freq_offset, sys_id, chan, group_id, save_dir): gr.hier_block2.__init__( self, "SmartZone Audio Channel", gr.io_signature(1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature(0, 0, 0), # output signature ) # audio constants self._audio_sample_rate = 8000 self._audio_passband = 3.6e3 self._audio_stopband = 4e3 self._audio_gain = 1.0 # fm constants self._deviation = 2.5e3 self._fm_passband = self._audio_stopband + self._deviation self._fm_stopband = self._fm_passband + 8e3 # 3 * audio_bw # fm channel values desired_channel_rate = 40e3 channel_decimation = int(round(sample_rate / desired_channel_rate)) channel_rate = sample_rate / channel_decimation # audio channel values desired_audio_rate = 8e3 audio_decimation = int(round(channel_rate / desired_audio_rate)) audio_rate = channel_rate / audio_decimation # translate desired fm audio frequency to baseband; decimate to channel rate channel_taps = optfir.low_pass(1, sample_rate, self._fm_passband, self._fm_stopband, 0.1, 60) channel_filter = filter.freq_xlating_fir_filter_ccf( channel_decimation, optfir.low_pass(1, sample_rate, self._fm_passband, self._fm_stopband, 0.1, 60), freq_offset, sample_rate, ) # power squelch squelch = analog.pwr_squelch_cc(-50, alpha=1, ramp=0, gate=True) # fm demodulation audio_demod = analog.fm_demod_cf( channel_rate, audio_decimation, self._deviation, self._audio_passband, self._audio_stopband, self._audio_gain, 75e-6, ) # remove sub-audible data XXX demodulate sa_filter = filter.fir_filter_fff(1, firdes.band_pass(1, audio_rate, 400, 3900, 100, filter.firdes.WIN_HANN)) # audio output # ensure directory exists create_directory(save_dir, sys_id) # asink = audio.sink(audio_rate) wavfile_sink = blocks.wavfile_sink( "%s/%x/%s" % (save_dir, sys_id, audio_name(group_id, chan)), 1, int(round(audio_rate)), 8 ) self.connect(self, channel_filter, squelch, audio_demod, sa_filter, wavfile_sink)