def __init__(self):
        gr.top_block.__init__(self)

        self.sample_rate = 5000000
        self.ampl = 0.1
        self.freq = 144000000

        self.uhd = uhd.usrp_source(
            ",".join(("", "")),
            uhd.stream_args(
                cpu_format="fc32",
                channels=range(1),
            ),
        )
        self.uhd.set_samp_rate(self.sample_rate)
        self.uhd.set_center_freq(self.freq, 0)
        self.uhd.set_gain(0, 0)
        self.uhd.set_antenna("RX2", 0)
        self.fft_vxx_0 = fft.fft_vcc(1024, True, (window.blackmanharris(1024)), True, 1)
        
        self.throttle = blocks.throttle(gr.sizeof_gr_complex*1, self.sample_rate,True)
        
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, self.sample_rate,True)

        self.stream = blocks.stream_to_vector_decimator(
            item_size=gr.sizeof_gr_complex,
            sample_rate=self.sample_rate,
            vec_rate=30,
            vec_len=1024,
        )

        self.probe = blocks.probe_signal_vf(1024)
        self.fft = fft.fft_vcc(1024, True, (window.blackmanharris(1024)), True, 1)

        src0 = analog.sig_source_c(self.sample_rate, analog.GR_SIN_WAVE, self.freq, self.ampl)
        dst = audio.sink(self.sample_rate, "")

        self.sqrt = blocks.complex_to_mag_squared(1024)

        def fft_out():
            while 1:
                val = self.probe.level()
                print max(val)
                freq = (val.index(max(val)) * (self.sample_rate/1024.0)) + (self.freq - (self.sample_rate/2.0))
                print freq
                time.sleep(1)

        fft_thread = threading.Thread(target=fft_out)

        fft_thread.daemon = True
        fft_thread.start()

        self.connect((self.uhd,0),(self.throttle, 0))
        self.connect((self.throttle,0),(self.stream,0))
        self.connect((self.stream, 0),(self.fft, 0))
        self.connect((self.fft, 0),(self.sqrt, 0))
        self.connect((self.sqrt, 0),(self.probe, 0))
 def set_fft_size(self, fft_size):
     self.fft_size = fft_size
     self.set_mywindow(window.blackmanharris(self.fft_size))
     self.set_meas_period(max(1, int(round(self.meas_interval * self.samp_rate / self.fft_size))))
     self._fft_size_callback(self.fft_size)
     self.set_Vsq2W_dB(-10.0 * math.log10(self.fft_size * int(self.window_power) * self.impedance))
     self.set_hz_per_bin(self.samp_rate / self.fft_size)
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Fft To Tcp")

        ##################################################
        # Variables
        ##################################################
        self.veclen = veclen = 8192
        self.test = test = 1420e6
        self.samp_rate = samp_rate = 1500000

        ##################################################
        # Blocks
        ##################################################
        self.xmlrpc_server_0 = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8080), allow_none=True)
        self.xmlrpc_server_0.register_instance(self)
        threading.Thread(target=self.xmlrpc_server_0.serve_forever).start()
        self.rtlsdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + "")
        self.rtlsdr_source_0.set_sample_rate(samp_rate)
        self.rtlsdr_source_0.set_center_freq(test, 0)
        self.rtlsdr_source_0.set_freq_corr(0, 0)
        self.rtlsdr_source_0.set_dc_offset_mode(0, 0)
        self.rtlsdr_source_0.set_iq_balance_mode(0, 0)
        self.rtlsdr_source_0.set_gain_mode(False, 0)
        self.rtlsdr_source_0.set_gain(1, 0)
        self.rtlsdr_source_0.set_if_gain(20, 0)
        self.rtlsdr_source_0.set_bb_gain(20, 0)
        self.rtlsdr_source_0.set_antenna("", 0)
        self.rtlsdr_source_0.set_bandwidth(0, 0)

        self.fft_vxx_0 = fft.fft_vcc(veclen, True, (window.blackmanharris(veclen)), True, 1)
        self.blocks_stream_to_vector_1 = blocks.stream_to_vector(gr.sizeof_gr_complex * 1, samp_rate)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex * 1, veclen)
        self.blocks_complex_to_mag_0 = blocks.complex_to_mag(veclen)
        self.blks2_tcp_sink_0_0 = grc_blks2.tcp_sink(
            itemsize=gr.sizeof_gr_complex * samp_rate, addr="127.0.0.1", port=10002, server=True
        )
        self.blks2_tcp_sink_0 = grc_blks2.tcp_sink(
            itemsize=gr.sizeof_float * veclen, addr="127.0.0.1", port=10001, server=True
        )

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_complex_to_mag_0, 0), (self.blks2_tcp_sink_0, 0))
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))
        self.connect((self.blocks_stream_to_vector_1, 0), (self.blks2_tcp_sink_0_0, 0))
        self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_0, 0))
        self.connect((self.rtlsdr_source_0, 0), (self.blocks_stream_to_vector_0, 0))
        self.connect((self.rtlsdr_source_0, 0), (self.blocks_stream_to_vector_1, 0))
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="File Fft To Tcp Nogui")

        ##################################################
        # Variables
        ##################################################
        self.veclen = veclen = 8192
        self.test = test = 1420e6
        self.samp_rate = samp_rate = 1500000

        ##################################################
        # Blocks
        ##################################################
        self.xmlrpc_server_0 = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8080), allow_none=True)
        self.xmlrpc_server_0.register_instance(self)
        threading.Thread(target=self.xmlrpc_server_0.serve_forever).start()
        self.fft_vxx_0 = fft.fft_vcc(veclen, True, (window.blackmanharris(veclen)), True, 1)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_stream_to_vector_1 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, samp_rate)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, veclen)
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_gr_complex*1, "/Users/bill/Desktop/radiotelescope/default.iqstream", True)
        self.blocks_complex_to_mag_0 = blocks.complex_to_mag(veclen)
        self.blks2_tcp_sink_0_0 = grc_blks2.tcp_sink(
        	itemsize=gr.sizeof_gr_complex*samp_rate,
        	addr="127.0.0.1",
        	port=10002,
        	server=True,
        )
        self.blks2_tcp_sink_0 = grc_blks2.tcp_sink(
        	itemsize=gr.sizeof_float*veclen,
        	addr="127.0.0.1",
        	port=10001,
        	server=True,
        )

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_complex_to_mag_0, 0), (self.blks2_tcp_sink_0, 0))    
        self.connect((self.blocks_file_source_0, 0), (self.blocks_throttle_0, 0))    
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))    
        self.connect((self.blocks_stream_to_vector_1, 0), (self.blks2_tcp_sink_0_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.blocks_stream_to_vector_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.blocks_stream_to_vector_1, 0))    
        self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_0, 0))    
Example #5
0
    def __init__(self, options):

        gr.hier_block2.__init__(self, "sensing_path",
                gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
                gr.io_signature(0, 0, 0)) # Output signature


        options = copy.copy(options)    # make a copy so we can destructively modify

        self._verbose        = options.verbose
       
        # linklab, fft size for sensing, different from fft length for tx/rx
        self.fft_size = FFT_SIZE

        # interpolation rate: sensing fft size / ofdm fft size
        self.interp_rate = self.fft_size/options.fft_length

        self._fft_length      = options.fft_length
        self._occupied_tones  = options.occupied_tones
        self.msgq             = gr.msg_queue()

        # linklab , setup the sensing path
        # FIXME: some components are not necessary
        self.s2p = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)
        mywindow = window.blackmanharris(self.fft_size)
        self.fft = fft.fft_vcc(self.fft_size, True, mywindow)
        power = 0
        for tap in mywindow:
            power += tap*tap
        self.c2mag = blocks.complex_to_mag(self.fft_size)
        self.avg = filter.single_pole_iir_filter_ff(1.0, self.fft_size)

        # linklab, ref scale value from default ref_scale in usrp_fft.py
        ref_scale = 13490.0

        # FIXME  We need to add 3dB to all bins but the DC bin
        self.log = blocks.nlog10_ff(20, self.fft_size,
                                -10*math.log10(self.fft_size)              # Adjust for number of bins
                                -10*math.log10(power/self.fft_size)        # Adjust for windowing loss
                                -20*math.log10(ref_scale/2))               # Adjust for reference scale

        self.sink = blocks.message_sink(gr.sizeof_float * self.fft_size, self.msgq, True)
        self.connect(self, self.s2p, self.fft, self.c2mag, self.avg, self.log, self.sink)
Example #6
0
    def __init__(self):
        gr.top_block.__init__(self, "Salsa Eceiver")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 5000000.0
        self.outfile = outfile = "/tmp/vale.dat"
        self.int_time = int_time = 10
        self.gain = gain = 60
        self.fftsize = fftsize = 4096
        self.c_freq = c_freq = 1420.4e6

        ##################################################
        # Blocks
        ##################################################
        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(c_freq, 0)
        self.uhd_usrp_source_0.set_gain(gain, 0)
        self.fft_vxx_0 = fft.fft_vcc(fftsize, True, (window.blackmanharris(fftsize)), True, 1)
        self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_gr_complex*1, fftsize)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fftsize)
        self.blocks_head_0 = blocks.head(gr.sizeof_float*1, int(int_time*samp_rate))
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_float*1, outfile, False)
        self.blocks_file_sink_0.set_unbuffered(False)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.fft_vxx_0, 0), (self.blocks_vector_to_stream_0, 0))
        self.connect((self.uhd_usrp_source_0, 0), (self.blocks_stream_to_vector_0, 0))
        self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_complex_to_mag_squared_0, 0))
        self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_head_0, 0))
        self.connect((self.blocks_head_0, 0), (self.blocks_file_sink_0, 0))
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))
    def __init__(self):
        gr.top_block.__init__(self)

        self.sample_rate = 5000000
        self.ampl = 0.1
        self.freq = 144000000

        self.stream = blocks.stream_to_vector_decimator(
            item_size=gr.sizeof_gr_complex,
            sample_rate=self.sample_rate,
            vec_rate=30,
            vec_len=1024,
        )

        self.probe = blocks.probe_signal_vf(1024)
        self.fft = fft.fft_vcc(1024, True, (window.blackmanharris(1024)), True, 1)

        src0 = analog.sig_source_c(self.sample_rate, analog.GR_SIN_WAVE, self.freq, self.ampl)
        dst = audio.sink(self.sample_rate, "")

        self.sqrt = blocks.complex_to_mag_squared(1024)

        def fft_out():
            while 1:
                val = self.probe.level()
                print max(val)
                freq = (val.index(max(val)) - 512) * (self.sample_rate/1024.0)
                print freq
                time.sleep(1)

        fft_thread = threading.Thread(target=fft_out)

        fft_thread.daemon = True
        fft_thread.start()

        self.connect((src0,0),(self.stream, 0))
        self.connect((self.stream, 0),(self.fft, 0))
        self.connect((self.fft, 0),(self.sqrt, 0))
        self.connect((self.sqrt, 0),(self.probe, 0))
Example #8
0
    def setup_top_block(self):
        self.tb = gr.top_block()

        uhd_usrp_source = uhd.usrp_source("", uhd.stream_args(cpu_format="fc32", channels=range(1)))
        uhd_usrp_source.set_samp_rate(self.samp_rate)
        uhd_usrp_source.set_center_freq(self.center_freq, 0)
        uhd_usrp_source.set_gain(self.gain, 0)

        blocks_stream_to_vector = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)

        fft_vxx = fft.fft_vcc(self.fft_size, True, (window.blackmanharris(self.fft_size)), True, 1)

        blocks_complex_to_mag_squared = blocks.complex_to_mag_squared(self.fft_size)

        avg_size = int(self.samp_rate / self.fft_size * self.time_window)
        specest_moving_average_vff = specest.moving_average_vff(avg_size, self.fft_size, 1.0 / avg_size, 4096)

        self.probe_signal = blocks.probe_signal_vf(self.fft_size)

        self.tb.connect((uhd_usrp_source, 0), (blocks_stream_to_vector, 0))
        self.tb.connect((blocks_stream_to_vector, 0), (fft_vxx, 0))
        self.tb.connect((fft_vxx, 0), (blocks_complex_to_mag_squared, 0))
        self.tb.connect((blocks_complex_to_mag_squared, 0), (specest_moving_average_vff, 0))
        self.tb.connect((specest_moving_average_vff, 0), (self.probe_signal, 0))
Example #9
0
    def __init__(self):
        gr.top_block.__init__(self, "RX logic")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 192000
        self.mode = mode = 2
        self.bw = bw = 3200
        self.aud_rate = aud_rate = 22050
        self.visualsq = visualsq = 1
        self.st = st = 1
        self.sq = sq = -700
        self.sb_pos = sb_pos = ((bw*mode==2)-(bw*mode==3))
        self.rec = rec = 1
        self.laj_0 = laj_0 = 0
        self.laj = laj = 0
        self.lai_0 = lai_0 = 0
        self.lai = lai = 0
        self.freq = freq = 98500000
        self.device = device = "fcd=0,type=2"
        self.dev = dev = 19000
        self.decimation = decimation = samp_rate/aud_rate
        self.batswitch = batswitch = 0
        self.batido = batido = 2950
        self.VEC = VEC = 1280

        ##################################################
        # Blocks
        ##################################################
        self.rtlsdr_source_0 = osmosdr.source( args="nchan=" + str(1) + " " + device )
        self.rtlsdr_source_0.set_sample_rate(samp_rate)
        self.rtlsdr_source_0.set_center_freq(freq, 0)
        self.rtlsdr_source_0.set_freq_corr(7, 0)
        self.rtlsdr_source_0.set_dc_offset_mode(0, 0)
        self.rtlsdr_source_0.set_iq_balance_mode(0, 0)
        self.rtlsdr_source_0.set_gain_mode(0, 0)
        self.rtlsdr_source_0.set_gain(14, 0)
        self.rtlsdr_source_0.set_if_gain(14, 0)
        self.rtlsdr_source_0.set_bb_gain(14, 0)
        self.rtlsdr_source_0.set_antenna("", 0)
        self.rtlsdr_source_0.set_bandwidth(0, 0)
          
        self.probe_st = analog.probe_avg_mag_sqrd_f(10, 1)
        self.low_pass_filter_0_2 = filter.fir_filter_ccf(decimation, firdes.low_pass(
        	1, samp_rate, bw*(2+(mode==2)+(mode==3)), 500, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_0_1_0_0_0 = filter.fir_filter_fff(1, firdes.low_pass(
        	1, samp_rate, 14000, 1000, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_0_1 = filter.fir_filter_fff(1, firdes.low_pass(
        	30, samp_rate, 14000, 1000, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_0_0_0_0 = filter.interp_fir_filter_fff(1, firdes.low_pass(
        	visualsq, samp_rate/decimation, bw, 10, firdes.WIN_HAMMING, 6.76))
        self.low_pass_filter_0_0_0 = filter.fir_filter_ccf(1, firdes.low_pass(
        	1, samp_rate/decimation, bw, 10, firdes.WIN_HAMMING, 6.76))
        self.high_pass_filter_0 = filter.fir_filter_ccf(1, firdes.high_pass(
        	1, samp_rate/decimation, bw, 10, firdes.WIN_HAMMING, 6.76))
        self.fractional_resampler_xx_0_0_0 = filter.fractional_resampler_ff(0, samp_rate/48000.0)
        self.fractional_resampler_xx_0_0 = filter.fractional_resampler_ff(0, samp_rate/48000.0)
        self.fractional_resampler_xx_0 = filter.fractional_resampler_ff(0, (samp_rate/decimation)/48000.0)
        self.fft_vxx_0 = fft.fft_vcc(VEC, True, (window.blackmanharris(1024)), True, 1)
        self.fft_probe = blocks.probe_signal_vf(VEC)
        self.blocks_wavfile_sink_0 = blocks.wavfile_sink("/tmp/CAPTURE.WAV", 2, 48000, 16)
        self.blocks_sub_xx_0 = blocks.sub_ff(1)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, VEC)
        self.blocks_multiply_xx_0_1_0 = blocks.multiply_vff(1)
        self.blocks_multiply_xx_0_0_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_complex_to_real_0_0_0_0 = blocks.complex_to_real(1)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(VEC)
        self.blocks_add_xx_0 = blocks.add_vff(1)
        self.blocks_add_const_vxx_0 = blocks.add_const_vcc((-complex(lai,laj), ))
        self.blks2_valve_0_1 = grc_blks2.valve(item_size=gr.sizeof_float*1, open=bool(rec))
        self.blks2_valve_0_0_1 = grc_blks2.valve(item_size=gr.sizeof_gr_complex*1, open=bool(mode!=5))
        self.blks2_valve_0_0_0 = grc_blks2.valve(item_size=gr.sizeof_gr_complex*1, open=bool(0))
        self.blks2_valve_0_0 = grc_blks2.valve(item_size=gr.sizeof_gr_complex*1, open=bool(mode!=4))
        self.blks2_valve_0 = grc_blks2.valve(item_size=gr.sizeof_float*1, open=bool(rec))
        self.blks2_selector_0_1_0 = grc_blks2.selector(
        	item_size=gr.sizeof_gr_complex*1,
        	num_inputs=2,
        	num_outputs=1,
        	input_index=(mode==3),
        	output_index=0,
        )
        self.blks2_selector_0_0_1_0 = grc_blks2.selector(
        	item_size=gr.sizeof_float*1,
        	num_inputs=3,
        	num_outputs=1,
        	input_index=(mode>3)+(mode>4),
        	output_index=0,
        )
        self.blks2_selector_0_0_1 = grc_blks2.selector(
        	item_size=gr.sizeof_float*1,
        	num_inputs=3,
        	num_outputs=1,
        	input_index=(mode>3)+(mode>4),
        	output_index=0,
        )
        self.blks2_selector_0_0 = grc_blks2.selector(
        	item_size=gr.sizeof_float*1,
        	num_inputs=4,
        	num_outputs=1,
        	input_index=mode,
        	output_index=0,
        )
        self.blks2_selector_0 = grc_blks2.selector(
        	item_size=gr.sizeof_gr_complex*1,
        	num_inputs=1,
        	num_outputs=4,
        	input_index=0,
        	output_index=mode,
        )
        self.band_pass_filter_0_0_0 = filter.fir_filter_fff(1, firdes.band_pass(
        	250, samp_rate, 18500, 19500, 500, firdes.WIN_HAMMING, 6.76))
        self.band_pass_filter_0_0 = filter.fir_filter_fff(1, firdes.band_pass(
        	120, samp_rate, 24000, 52000, 1000, firdes.WIN_HAMMING, 6.76))
        self.audio_sink_0 = audio.sink(48000, "dmix:CARD=Pro,DEV=0", False)
        self.analog_wfm_rcv_1 = analog.wfm_rcv(
        	quad_rate=samp_rate,
        	audio_decimation=1,
        )
        self.analog_sig_source_x_0_0_0 = analog.sig_source_c(samp_rate/decimation, analog.GR_COS_WAVE, -bw, 1, 0)
        self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, dev+(bw*mode==2)+(bw*mode==3), 1, 0)
        self.analog_quadrature_demod_cf_0 = analog.quadrature_demod_cf(0.25)
        self.analog_fm_demod_cf_0 = analog.fm_demod_cf(
        	channel_rate=samp_rate,
        	audio_decim=samp_rate/48000,
        	deviation=50000,
        	audio_pass=15000,
        	audio_stop=16000,
        	gain=3.0,
        	tau=50e-6,
        )
        self.analog_fm_deemph_0_0 = analog.fm_deemph(fs=48000, tau=50e-6)
        self.analog_fm_deemph_0 = analog.fm_deemph(fs=48000, tau=50e-6)
        self.analog_feedforward_agc_cc_0 = analog.feedforward_agc_cc(64, 0.9)
        self.analog_am_demod_cf_0 = analog.am_demod_cf(
        	channel_rate=samp_rate/decimation,
        	audio_decim=samp_rate/decimation/aud_rate,
        	audio_pass=(samp_rate/decimation/2)-500,
        	audio_stop=(samp_rate/decimation/2)-100,
        )
        self.analog_agc3_xx_0 = analog.agc3_cc(0.0001, 0.0001, 0.9, 0.1)
        self.analog_agc3_xx_0.set_max_gain(200)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.fft_probe, 0))
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1))
        self.connect((self.blks2_valve_0_0_0, 0), (self.blocks_multiply_xx_0, 0))
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))
        self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0))
        self.connect((self.blocks_add_const_vxx_0, 0), (self.blks2_valve_0_0, 0))
        self.connect((self.band_pass_filter_0_0, 0), (self.blocks_multiply_xx_0_1_0, 0))
        self.connect((self.low_pass_filter_0_1, 0), (self.analog_fm_deemph_0, 0))
        self.connect((self.analog_fm_deemph_0, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.analog_wfm_rcv_1, 0), (self.low_pass_filter_0_1, 0))
        self.connect((self.analog_wfm_rcv_1, 0), (self.band_pass_filter_0_0, 0))
        self.connect((self.analog_wfm_rcv_1, 0), (self.band_pass_filter_0_0_0, 0))
        self.connect((self.analog_fm_deemph_0_0, 0), (self.blocks_add_xx_0, 1))
        self.connect((self.low_pass_filter_0_1_0_0_0, 0), (self.analog_fm_deemph_0_0, 0))
        self.connect((self.analog_agc3_xx_0, 0), (self.analog_wfm_rcv_1, 0))
        self.connect((self.blks2_valve_0_0_1, 0), (self.analog_agc3_xx_0, 0))
        self.connect((self.blocks_add_const_vxx_0, 0), (self.blks2_valve_0_0_1, 0))
        self.connect((self.blocks_multiply_xx_0_1_0, 0), (self.low_pass_filter_0_1_0_0_0, 0))
        self.connect((self.band_pass_filter_0_0_0, 0), (self.blocks_multiply_xx_0_1_0, 1))
        self.connect((self.band_pass_filter_0_0_0, 0), (self.blocks_multiply_xx_0_1_0, 2))
        self.connect((self.analog_fm_deemph_0_0, 0), (self.blocks_sub_xx_0, 1))
        self.connect((self.analog_fm_deemph_0, 0), (self.blocks_sub_xx_0, 0))
        self.connect((self.blocks_sub_xx_0, 0), (self.fractional_resampler_xx_0_0_0, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.fractional_resampler_xx_0_0, 0))
        self.connect((self.blks2_valve_0_0, 0), (self.analog_fm_demod_cf_0, 0))
        self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_stream_to_vector_0, 0))
        self.connect((self.blocks_add_const_vxx_0, 0), (self.blks2_valve_0_0_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_0_2, 0))
        self.connect((self.blocks_complex_to_real_0_0_0_0, 0), (self.blks2_selector_0_0, 3))
        self.connect((self.blocks_complex_to_real_0_0_0_0, 0), (self.blks2_selector_0_0, 2))
        self.connect((self.blks2_selector_0_1_0, 0), (self.blocks_multiply_xx_0_0_0, 0))
        self.connect((self.blocks_multiply_xx_0_0_0, 0), (self.blocks_complex_to_real_0_0_0_0, 0))
        self.connect((self.analog_sig_source_x_0_0_0, 0), (self.blocks_multiply_xx_0_0_0, 1))
        self.connect((self.analog_am_demod_cf_0, 0), (self.blks2_selector_0_0, 0))
        self.connect((self.blks2_selector_0, 0), (self.analog_am_demod_cf_0, 0))
        self.connect((self.analog_quadrature_demod_cf_0, 0), (self.blks2_selector_0_0, 1))
        self.connect((self.blks2_selector_0, 1), (self.analog_quadrature_demod_cf_0, 0))
        self.connect((self.blks2_selector_0_0, 0), (self.low_pass_filter_0_0_0_0, 0))
        self.connect((self.blks2_selector_0, 2), (self.high_pass_filter_0, 0))
        self.connect((self.blks2_selector_0, 3), (self.low_pass_filter_0_0_0, 0))
        self.connect((self.high_pass_filter_0, 0), (self.blks2_selector_0_1_0, 0))
        self.connect((self.low_pass_filter_0_0_0, 0), (self.blks2_selector_0_1_0, 1))
        self.connect((self.analog_fm_demod_cf_0, 0), (self.blks2_selector_0_0_1, 1))
        self.connect((self.analog_fm_demod_cf_0, 0), (self.blks2_selector_0_0_1_0, 1))
        self.connect((self.fractional_resampler_xx_0_0_0, 0), (self.blks2_selector_0_0_1_0, 2))
        self.connect((self.fractional_resampler_xx_0_0, 0), (self.blks2_selector_0_0_1, 2))
        self.connect((self.blks2_selector_0_0_1_0, 0), (self.audio_sink_0, 1))
        self.connect((self.blks2_selector_0_0_1, 0), (self.audio_sink_0, 0))
        self.connect((self.blks2_valve_0, 0), (self.blocks_wavfile_sink_0, 1))
        self.connect((self.blks2_selector_0_0_1_0, 0), (self.blks2_valve_0, 0))
        self.connect((self.blks2_selector_0_0_1, 0), (self.blks2_valve_0_1, 0))
        self.connect((self.blks2_valve_0_1, 0), (self.blocks_wavfile_sink_0, 0))
        self.connect((self.fractional_resampler_xx_0, 0), (self.blks2_selector_0_0_1_0, 0))
        self.connect((self.fractional_resampler_xx_0, 0), (self.blks2_selector_0_0_1, 0))
        self.connect((self.low_pass_filter_0_2, 0), (self.analog_feedforward_agc_cc_0, 0))
        self.connect((self.rtlsdr_source_0, 0), (self.blocks_add_const_vxx_0, 0))
        self.connect((self.low_pass_filter_0_0_0_0, 0), (self.fractional_resampler_xx_0, 0))
        self.connect((self.analog_feedforward_agc_cc_0, 0), (self.blks2_selector_0, 0))
        self.connect((self.band_pass_filter_0_0_0, 0), (self.probe_st, 0))
 def set_fft_size(self, fft_size):
     self.fft_size = fft_size
     self.set_k(-20*math.log10(self.fft_size)-10*math.log10(self.power/self.fft_size)-20*math.log10(2.0/2))
     self.set_fft_window(window.blackmanharris(self.fft_size))
     self.set_n(max(1, int(self.samp_rate/self.fft_size/15L)))
Example #11
0
    def __init__(self, fftsize, samp_rate, gain, c_freq):
        gr.top_block.__init__(self, "Receiver")

        # Class variables
        self.samp_rate = samp_rate
        self.gain = gain
        self.fftsize = fftsize
        self.c_freq = c_freq
        self.dump1 = "/tmp/ramdisk/dump1"  # View as null sinks
        self.dump2 = "/tmp/ramdisk/dump2"
        self.dump3 = "/tmp/ramdisk/dump3"
        self.dump4 = "/tmp/ramdisk/dump4"
        self.alpha = 0.01  # Integrate 100 FFTS 0.01
        self.N = 100  # 100
        self.probe_var = probe_var = 0
        self.probe_var_1 = probe_var_1 = 0

        ########## GNURADIO BLOCKS #########
        ####################################
        self.uhd_usrp_source_0 = uhd.usrp_source(
            ",".join(("", "")),  # Set the master_clock_rate, default = 200 MHz, alt 184.32 MHz and 120 MHz (Set)
            uhd.stream_args(cpu_format="fc32", channels=range(2)),
        )
        # Configure USRP channel 0
        self.uhd_usrp_source_0.set_antenna("RX2", 0)
        self.uhd_usrp_source_0.set_samp_rate(self.samp_rate)
        self.uhd_usrp_source_0.set_center_freq(self.c_freq, 0)
        self.uhd_usrp_source_0.set_gain(self.gain, 0)
        self.uhd_usrp_source_0.set_bandwidth(self.samp_rate, 0)
        self.uhd_usrp_source_0.set_clock_source("external")

        # Configure USRP channel 1
        self.uhd_usrp_source_0.set_antenna("RX2", 1)
        self.uhd_usrp_source_0.set_center_freq(self.c_freq, 1)
        self.uhd_usrp_source_0.set_gain(self.gain, 1)
        self.uhd_usrp_source_0.set_bandwidth(self.samp_rate, 1)
        # self.uhd_usrp_source_0.set_clock_source('external', 1)

        # Signal and reference file sinks channel 0
        self.signal_file_sink_1 = blocks.file_sink(gr.sizeof_float * 1, self.dump1, False)
        self.signal_file_sink_1.set_unbuffered(False)
        self.signal_file_sink_2 = blocks.file_sink(gr.sizeof_float * 1, self.dump2, False)
        self.signal_file_sink_2.set_unbuffered(False)

        # Signal and reference file sinks channel 1
        self.signal_file_sink_3 = blocks.file_sink(gr.sizeof_float * 1, self.dump3, False)
        self.signal_file_sink_3.set_unbuffered(False)
        self.signal_file_sink_4 = blocks.file_sink(gr.sizeof_float * 1, self.dump4, False)
        self.signal_file_sink_4.set_unbuffered(False)

        # Selector for GPIO switch channel 0
        self.blks2_selector_0 = grc_blks2.selector(
            item_size=gr.sizeof_float * 1,
            num_inputs=1,
            num_outputs=3,  # +1 for the null sink
            input_index=0,
            output_index=0,
        )
        # Selector for GPIO switch channel 1
        self.blks2_selector_1 = grc_blks2.selector(
            item_size=gr.sizeof_float * 1,
            num_inputs=1,
            num_outputs=3,  # +1 for the null sink
            input_index=0,
            output_index=0,
        )

        # Div blocks channel 0
        self.blocks_null_sink = blocks.null_sink(gr.sizeof_float * 1)
        self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff(self.alpha, self.fftsize)
        self.fft_vxx_0 = fft.fft_vcc(
            self.fftsize, True, (window.blackmanharris(self.fftsize)), True, 1
        )  # Last argument threads, 1 default
        self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_float * 1, self.fftsize)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex * 1, self.fftsize)
        self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n(gr.sizeof_float * self.fftsize, self.N)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(self.fftsize)
        # Div blocks channel 1
        self.blocks_null_sink_1 = blocks.null_sink(gr.sizeof_float * 1)
        self.single_pole_iir_filter_xx_1 = filter.single_pole_iir_filter_ff(self.alpha, self.fftsize)
        self.fft_vxx_1 = fft.fft_vcc(self.fftsize, True, (window.blackmanharris(self.fftsize)), True, 1)
        self.blocks_vector_to_stream_1 = blocks.vector_to_stream(gr.sizeof_float * 1, self.fftsize)
        self.blocks_stream_to_vector_1 = blocks.stream_to_vector(gr.sizeof_gr_complex * 1, self.fftsize)
        self.blocks_keep_one_in_n_1 = blocks.keep_one_in_n(gr.sizeof_float * self.fftsize, self.N)
        self.blocks_complex_to_mag_squared_1 = blocks.complex_to_mag_squared(self.fftsize)

        # Block connections channel 0
        self.connect((self.uhd_usrp_source_0, 0), self.blocks_stream_to_vector_0)
        self.connect(self.blocks_stream_to_vector_0, self.fft_vxx_0)
        self.connect(self.fft_vxx_0, self.blocks_complex_to_mag_squared_0)
        self.connect(self.blocks_complex_to_mag_squared_0, self.single_pole_iir_filter_xx_0)
        self.connect(self.single_pole_iir_filter_xx_0, self.blocks_keep_one_in_n_0)
        self.connect(self.blocks_keep_one_in_n_0, self.blocks_vector_to_stream_0)
        self.connect(self.blocks_vector_to_stream_0, self.blks2_selector_0)

        # Block connections channel 1
        self.connect((self.uhd_usrp_source_0, 1), self.blocks_stream_to_vector_1)
        self.connect(self.blocks_stream_to_vector_1, self.fft_vxx_1)
        self.connect(self.fft_vxx_1, self.blocks_complex_to_mag_squared_1)
        self.connect(self.blocks_complex_to_mag_squared_1, self.single_pole_iir_filter_xx_1)
        self.connect(self.single_pole_iir_filter_xx_1, self.blocks_keep_one_in_n_1)
        self.connect(self.blocks_keep_one_in_n_1, self.blocks_vector_to_stream_1)
        self.connect(self.blocks_vector_to_stream_1, self.blks2_selector_1)

        # Selector connections channel 0
        self.connect((self.blks2_selector_0, 1), self.signal_file_sink_1)
        self.connect((self.blks2_selector_0, 2), self.signal_file_sink_2)

        # Selector connections channel 1
        self.connect((self.blks2_selector_1, 1), self.signal_file_sink_3)
        self.connect((self.blks2_selector_1, 2), self.signal_file_sink_4)

        # Null sink connection channel 0
        self.connect((self.blks2_selector_0, 0), self.blocks_null_sink)

        # Null sink connection channel 1
        self.connect((self.blks2_selector_1, 0), self.blocks_null_sink_1)

        #########PROBE SAMPLES channel 0##########
        self.probe_signal = blocks.probe_signal_f()
        self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1)

        self.connect((self.uhd_usrp_source_0, 0), (self.blocks_complex_to_mag_0, 0))
        self.connect((self.blocks_complex_to_mag_0, 0), (self.probe_signal, 0))

        #########PROBE SAMPLES channel 1##########
        self.probe_signal_1 = blocks.probe_signal_f()
        self.blocks_complex_to_mag_1 = blocks.complex_to_mag(1)

        self.connect((self.uhd_usrp_source_0, 1), (self.blocks_complex_to_mag_1, 0))
        self.connect((self.blocks_complex_to_mag_1, 0), (self.probe_signal_1, 0))

        # Probe update rate
        def _probe_var_probe():
            while True:
                val = self.probe_signal.level()
                try:
                    self.set_probe_var(val)
                except AttributeError:
                    pass
                time.sleep(10 / (self.samp_rate))  # Update probe variabel every 10/samp_rate seconds

        _probe_var_thread = threading.Thread(target=_probe_var_probe)
        _probe_var_thread.daemon = True
        _probe_var_thread.start()

        # Probe update rate
        def _probe_var_probe_1():
            while True:
                val = self.probe_signal_1.level()
                try:
                    self.set_probe_var_1(val)
                except AttributeError:
                    pass
                time.sleep(10 / (self.samp_rate))  # Update probe variabel every 10/samp_rate seconds

        _probe_var_thread_1 = threading.Thread(target=_probe_var_probe_1)
        _probe_var_thread_1.daemon = True
        _probe_var_thread_1.start()
Example #12
0
    def __init__(self):
        gr.top_block.__init__(self)

        self.sample_rate = 5000000
        self.ampl = 1
        self.freq = 144000000
        self.counter = 0

    # --- Sources ----

        self.uhd = uhd.usrp_source(
            ",".join(("", "")),
            uhd.stream_args(
                cpu_format="fc32",
                channels=range(1),
            ),
        )
        self.uhd.set_samp_rate(self.sample_rate)
        self.uhd.set_center_freq(self.freq, 0)
        self.uhd.set_gain(0, 0)
        self.uhd.set_antenna("RX2", 0)

    # --- Blocks -----

        self.throttle = blocks.throttle(gr.sizeof_gr_complex*1, self.sample_rate,True)

        self.streamToVector = blocks.stream_to_vector_decimator(
            item_size=gr.sizeof_gr_complex,
            sample_rate=self.sample_rate,
            vec_rate=30,
            vec_len=1024,
        )

        self.fft = fft.fft_vcc(1024, True, (window.blackmanharris(1024)), 1)
        
        self.complexToMag = blocks.complex_to_mag_squared(1024)
        
        self.probe = blocks.probe_signal_vf(1024)

    # --- Functions ----

        def fft_cal():
            while 1:
                val = self.probe.level()
                print "Index: {} Max: {}".format(val.index(max(val)),max(val))

                if max(val):
                    pow_ran = []
                    freq_ran = []
                    for i in val:
                        pow_ran.append(float(i)/max(val))
                    for i in range(1024):
                        freq_ran.append((i*self.sample_rate/1024.0) + (self.freq - (self.sample_rate/2.0)) )
                    fig = plt.plot(freq_ran,pow_ran)
                    plt.ylim(-0.3,1.2)
                    plt.xlim(min(freq_ran),max(freq_ran))
                    plt.show()
                    time.sleep(1)

                

    # --- Start Thread ---

        fft_thread = threading.Thread(target=fft_cal)
        fft_thread.daemon = True
        fft_thread.start()

    # --- Conections ---

        self.connect((self.uhd, 0), (self.throttle, 0))
        self.connect((self.throttle, 0), (self.streamToVector, 0))
        self.connect((self.streamToVector, 0), (self.fft, 0))
        self.connect((self.fft, 0),(self.complexToMag, 0))
        self.connect((self.complexToMag, 0),(self.probe, 0))
Example #13
0
        self.c_freq = c_freq = 1420.4e6

        ##################################################
        # Blocks
        ##################################################
        self.uhd_usrp_source_0 = uhd.usrp_source(
        	device_addr="addr=192.168.20.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(c_freq, 0)
        self.uhd_usrp_source_0.set_gain(gain, 0)
        self.fft_vxx_0 = fft.fft_vcc(fftsize, True, (window.blackmanharris(fftsize)), True, 1)
        self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_gr_complex*1, fftsize)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fftsize)
        self.blocks_head_0 = blocks.head(gr.sizeof_float*1, int(int_time*samp_rate))
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_float*1, outfile, False)
        self.blocks_file_sink_0.set_unbuffered(False)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.fft_vxx_0, 0), (self.blocks_vector_to_stream_0, 0))
        self.connect((self.uhd_usrp_source_0, 0), (self.blocks_stream_to_vector_0, 0))
        self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_complex_to_mag_squared_0, 0))
        self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_head_0, 0))
        self.connect((self.blocks_head_0, 0), (self.blocks_file_sink_0, 0))
Example #14
0
    def __init__(self, ask_samp_rate=4E6, num_demod=4, type_demod=0,
                 hw_args="uhd", freq_correction=0, record=True):
        # Call the initialization method from the parent class
        gr.top_block.__init__(self, "Receiver")

        # Default values
        self.center_freq = 144E6
        self.gain_db = 10
        self.squelch_db = -70
        self.volume_db = 0
        audio_rate = 8000

        # Setup the USRP source, or use the USRP sim
        self.src = osmosdr.source(args="numchan=" + str(1) + " " + hw_args)
        self.src.set_sample_rate(ask_samp_rate)
        self.src.set_gain(self.gain_db)
        self.src.set_center_freq(self.center_freq)
        self.src.set_freq_corr(freq_correction)

        # Get the sample rate and center frequency from the hardware
        self.samp_rate = self.src.get_sample_rate()
        self.center_freq = self.src.get_center_freq()

        # Set the I/Q bandwidth to 80 % of sample rate
        self.src.set_bandwidth(0.8 * self.samp_rate)

        # NBFM channel is about 10 KHz wide
        # Want  about 3 FFT bins to span a channel
        # Use length FFT so 4 Msps / 1024 = 3906.25 Hz/bin
        # This also means 3906.25 vectors/second
        # Using below formula keeps FFT size a power of two
        # Also keeps bin size constant for power of two sampling rates
        # Use of 256 sets 3906.25 Hz/bin; increase to reduce bin size
        samp_ratio = self.samp_rate / 1E6
        fft_length = 256 * int(pow(2, np.ceil(np.log(samp_ratio)/np.log(2))))

        # -----------Flow for FFT--------------

        # Convert USRP steam to vector
        stream_to_vector = blocks.stream_to_vector(gr.sizeof_gr_complex*1,
                                                   fft_length)

        # Want about 1000 vector/sec
        amount = int(round(self.samp_rate/fft_length/1000))
        keep_one_in_n = blocks.keep_one_in_n(gr.sizeof_gr_complex*
                                             fft_length, amount)

        # Take FFT
        fft_vcc = fft.fft_vcc(fft_length, True,
                              window.blackmanharris(fft_length), True, 1)

        # Compute the power
        complex_to_mag_squared = blocks.complex_to_mag_squared(fft_length)

        # Video average and decimate from 1000 vector/sec to 10 vector/sec
        integrate_ff = blocks.integrate_ff(100, fft_length)

        # Probe vector
        self.probe_signal_vf = blocks.probe_signal_vf(fft_length)

        # Connect the blocks
        self.connect(self.src, stream_to_vector, keep_one_in_n,
                     fft_vcc, complex_to_mag_squared,
                     integrate_ff, self.probe_signal_vf)

        # -----------Flow for Demod--------------

        # Create N parallel demodulators as a list of objects
        # Default to NBFM demod
        self.demodulators = []
        for idx in range(num_demod):
            if type_demod == 1:
                self.demodulators.append(TunerDemodAM(self.samp_rate,
                                                      audio_rate, record))
            else:
                self.demodulators.append(TunerDemodNBFM(self.samp_rate,
                                                        audio_rate, record))

        # Create an adder
        add_ff = blocks.add_ff(1)

        # Connect the demodulators between the source and adder
        for idx, demodulator in enumerate(self.demodulators):
            self.connect(self.src, demodulator, (add_ff, idx))

        # Audio sink
        audio_sink = audio.sink(audio_rate)

         # Connect the blocks for the demod
        self.connect(add_ff, audio_sink)
Example #15
0
    def __init__(self):
        gr.top_block.__init__(self, "Rfile Non Rfnoc")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Rfile Non Rfnoc")
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme("gnuradio-grc"))
        except:
            pass
        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)

        self.settings = Qt.QSettings("GNU Radio", "rfile_non_RFNoC")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 12.5e6
        self.fft_size = fft_size = 625
        self.num_ch = num_ch = 56
        self.mywindow = mywindow = window.blackmanharris(fft_size)
        self.hz_per_bin = hz_per_bin = samp_rate / fft_size
        self.bandwidth = bandwidth = 10.08e6
        self.window_power = window_power = sum(map(lambda x: x * x, mywindow))
        self.meas_interval = meas_interval = 1e-3
        self.impedance = impedance = 50.0
        self.channel_bw = channel_bw = hz_per_bin * round(bandwidth / num_ch / hz_per_bin)
        self.rx_gain = rx_gain = 0
        self.meas_period = meas_period = max(1, int(round(meas_interval * samp_rate / fft_size)))
        self.dest_host = dest_host = "129.6.142.138"
        self.center_freq = center_freq = 724e6
        self.Vsq2W_dB = Vsq2W_dB = -10.0 * math.log10(fft_size * int(window_power) * impedance)
        self.ActualBW = ActualBW = channel_bw * num_ch

        ##################################################
        # Blocks
        ##################################################
        self._samp_rate_options = (12.5e6, 15.36e6, 7.68e6, 3.84e6, 1.92e6)
        self._samp_rate_labels = ("12.5e6", "15.36e6", "7.68e6", "3.84e6", "1.92e6")
        self._samp_rate_group_box = Qt.QGroupBox("samp_rate")
        self._samp_rate_box = Qt.QVBoxLayout()

        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)

            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)

        self._samp_rate_button_group = variable_chooser_button_group()
        self._samp_rate_group_box.setLayout(self._samp_rate_box)
        for i, label in enumerate(self._samp_rate_labels):
            radio_button = Qt.QRadioButton(label)
            self._samp_rate_box.addWidget(radio_button)
            self._samp_rate_button_group.addButton(radio_button, i)
        self._samp_rate_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._samp_rate_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._samp_rate_options.index(i))
        )
        self._samp_rate_callback(self.samp_rate)
        self._samp_rate_button_group.buttonClicked[int].connect(
            lambda i: self.set_samp_rate(self._samp_rate_options[i])
        )
        self.top_layout.addWidget(self._samp_rate_group_box)
        self._rx_gain_range = Range(0, 31.5, 0.5, 0, 200)
        self._rx_gain_win = RangeWidget(self._rx_gain_range, self.set_rx_gain, "rx_gain", "counter_slider", float)
        self.top_layout.addWidget(self._rx_gain_win)
        self._num_ch_options = (56, 50, 25, 15, 8)
        self._num_ch_labels = ("56", "50", "25", "15", "8")
        self._num_ch_group_box = Qt.QGroupBox("num_ch")
        self._num_ch_box = Qt.QVBoxLayout()

        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)

            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)

        self._num_ch_button_group = variable_chooser_button_group()
        self._num_ch_group_box.setLayout(self._num_ch_box)
        for i, label in enumerate(self._num_ch_labels):
            radio_button = Qt.QRadioButton(label)
            self._num_ch_box.addWidget(radio_button)
            self._num_ch_button_group.addButton(radio_button, i)
        self._num_ch_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._num_ch_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._num_ch_options.index(i))
        )
        self._num_ch_callback(self.num_ch)
        self._num_ch_button_group.buttonClicked[int].connect(lambda i: self.set_num_ch(self._num_ch_options[i]))
        self.top_layout.addWidget(self._num_ch_group_box)
        self._fft_size_options = (625, 1024, 512, 256, 128)
        self._fft_size_labels = ("625", "1024", "512", "256", "128")
        self._fft_size_tool_bar = Qt.QToolBar(self)
        self._fft_size_tool_bar.addWidget(Qt.QLabel("fft_size" + ": "))
        self._fft_size_combo_box = Qt.QComboBox()
        self._fft_size_tool_bar.addWidget(self._fft_size_combo_box)
        for label in self._fft_size_labels:
            self._fft_size_combo_box.addItem(label)
        self._fft_size_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._fft_size_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._fft_size_options.index(i))
        )
        self._fft_size_callback(self.fft_size)
        self._fft_size_combo_box.currentIndexChanged.connect(lambda i: self.set_fft_size(self._fft_size_options[i]))
        self.top_layout.addWidget(self._fft_size_tool_bar)
        self._dest_host_options = ("pwct1.ctl.nist.gov", "129.6.230.12", "129.6.142.181", "129.6.142.138")
        self._dest_host_labels = ("pwct1", "Naceur Laptop", "pwct5Desktop", "Pwct5")
        self._dest_host_tool_bar = Qt.QToolBar(self)
        self._dest_host_tool_bar.addWidget(Qt.QLabel(dest_host + ": "))
        self._dest_host_combo_box = Qt.QComboBox()
        self._dest_host_tool_bar.addWidget(self._dest_host_combo_box)
        for label in self._dest_host_labels:
            self._dest_host_combo_box.addItem(label)
        self._dest_host_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._dest_host_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._dest_host_options.index(i))
        )
        self._dest_host_callback(self.dest_host)
        self._dest_host_combo_box.currentIndexChanged.connect(lambda i: self.set_dest_host(self._dest_host_options[i]))
        self.top_layout.addWidget(self._dest_host_tool_bar)
        self._center_freq_options = (709.01e6, 782e6, 724e6)
        self._center_freq_labels = ("AT&T", "Verizon", "ChannelEmulator")
        self._center_freq_tool_bar = Qt.QToolBar(self)
        self._center_freq_tool_bar.addWidget(Qt.QLabel("center_freq" + ": "))
        self._center_freq_combo_box = Qt.QComboBox()
        self._center_freq_tool_bar.addWidget(self._center_freq_combo_box)
        for label in self._center_freq_labels:
            self._center_freq_combo_box.addItem(label)
        self._center_freq_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._center_freq_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._center_freq_options.index(i))
        )
        self._center_freq_callback(self.center_freq)
        self._center_freq_combo_box.currentIndexChanged.connect(
            lambda i: self.set_center_freq(self._center_freq_options[i])
        )
        self.top_layout.addWidget(self._center_freq_tool_bar)
        self.uhd_usrp_source_0 = uhd.usrp_source(
            ",".join(("addr=172.16.20.2", "")), 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(center_freq, 0)
        self.uhd_usrp_source_0.set_gain(rx_gain, 0)
        self.uhd_usrp_source_0.set_antenna("TX/RX", 0)
        self.myblocks_sslsocket_sink_0 = myblocks.sslsocket_sink(
            num_ch,
            dest_host,
            "/home/naceur/Documents/spectrum_monitor_sensors/gr-myblocks/examples/utils/sensor.loc",
            "/home/naceur/Documents/spectrum_monitor_sensors/gr-myblocks/examples/utils/sensor.sys",
            "E6R16W5XS",
            "NaN",
            center_freq,
            ActualBW,
            meas_interval,
            0,
        )
        self.myblocks_bin_statistics_0 = myblocks.bin_statistics(num_ch, meas_period)
        self.myblocks_bin_aggregator_0 = myblocks.bin_aggregator(
            fft_size, num_ch, samp_rate, fft_size, center_freq, ActualBW, channel_bw, [0] * fft_size
        )
        self.fft_vxx_0 = fft.fft_vcc(fft_size, True, (mywindow), True, 1)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex * 1, fft_size)
        self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, num_ch, 30.0 + Vsq2W_dB)
        self.blocks_float_to_char_0 = blocks.float_to_char(num_ch, 1.0)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(fft_size)
        self._bandwidth_options = (10.08e6, 9e6, 4.5e6, 2.7e6, 1.08e6)
        self._bandwidth_labels = ("10.08e6", "9e6", "4.5e6", "2.7e6", "1.08e6")
        self._bandwidth_tool_bar = Qt.QToolBar(self)
        self._bandwidth_tool_bar.addWidget(Qt.QLabel("bandwidth" + ": "))
        self._bandwidth_combo_box = Qt.QComboBox()
        self._bandwidth_tool_bar.addWidget(self._bandwidth_combo_box)
        for label in self._bandwidth_labels:
            self._bandwidth_combo_box.addItem(label)
        self._bandwidth_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._bandwidth_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._bandwidth_options.index(i))
        )
        self._bandwidth_callback(self.bandwidth)
        self._bandwidth_combo_box.currentIndexChanged.connect(lambda i: self.set_bandwidth(self._bandwidth_options[i]))
        self.top_layout.addWidget(self._bandwidth_tool_bar)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_float_to_char_0, 0), (self.myblocks_sslsocket_sink_0, 0))
        self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_float_to_char_0, 0))
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))
        self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0))
        self.connect((self.myblocks_bin_aggregator_0, 0), (self.myblocks_bin_statistics_0, 0))
        self.connect((self.myblocks_bin_statistics_0, 0), (self.blocks_nlog10_ff_0, 0))
        self.connect((self.uhd_usrp_source_0, 0), (self.blocks_stream_to_vector_0, 0))
        self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.myblocks_bin_aggregator_0, 0))
Example #16
0
    def __init__(self):
        gr.top_block.__init__(self, "Ham2Mon NBFM Receiver Flow Example")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Ham2Mon NBFM Receiver Flow Example")
        try:
             self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
             pass
        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)

        self.settings = Qt.QSettings("GNU Radio", "nbfm_flow_example")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 1E6
        self.initial_decim = initial_decim = 5
        self.samp_ratio = samp_ratio = samp_rate/1E6
        self.final_rate = final_rate = samp_rate/initial_decim**2/int(samp_rate/1E6)
        
        self.variable_low_pass_filter_taps_2 = variable_low_pass_filter_taps_2 = firdes.low_pass(1.0, final_rate, 3500, 500, firdes.WIN_HAMMING, 6.76)
          
        
        self.variable_low_pass_filter_taps_1 = variable_low_pass_filter_taps_1 = firdes.low_pass(1.0, samp_rate/25, 12.5E3, 1E3, firdes.WIN_HAMMING, 6.76)
          
        
        self.variable_low_pass_filter_taps_0 = variable_low_pass_filter_taps_0 = firdes.low_pass(1.0, 1, 0.090, 0.010, firdes.WIN_HAMMING, 6.76)
          
        self.squelch_dB = squelch_dB = -70
        self.gain_db = gain_db = 30
        self.final_decim = final_decim = int(samp_rate/1E6)
        self.file_name = file_name = "test.wav"
        self.fft_length = fft_length = 256 * int(pow(2, np.ceil(np.log(samp_ratio)/np.log(2))))
        self.demod_bb_freq = demod_bb_freq = 390E3
        self.center_freq = center_freq = 144E6

        ##################################################
        # Blocks
        ##################################################
        self._squelch_dB_range = Range(-100, 0, 5, -70, 200)
        self._squelch_dB_win = RangeWidget(self._squelch_dB_range, self.set_squelch_dB, "Squelch (dB)", "counter_slider", float)
        self.top_grid_layout.addWidget(self._squelch_dB_win, 5,1,1,3)
        self._gain_db_range = Range(0, 70, 1, 30, 200)
        self._gain_db_win = RangeWidget(self._gain_db_range, self.set_gain_db, "HW Gain (dB)", "counter_slider", float)
        self.top_grid_layout.addWidget(self._gain_db_win, 4,1,1,3)
        self._demod_bb_freq_range = Range(-samp_rate/2, samp_rate/2, 5E3, 390E3, 200)
        self._demod_bb_freq_win = RangeWidget(self._demod_bb_freq_range, self.set_demod_bb_freq, "Demod BB Freq (Hz)", "counter_slider", float)
        self.top_grid_layout.addWidget(self._demod_bb_freq_win, 3,1,1,3)
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
        	fft_length, #size
        	samp_rate, #samp_rate
        	"Averaged Spectrum", #name
        	1 #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0.set_y_axis(-60, 40)
        
        self.qtgui_time_sink_x_0.set_y_label("Power", "")
        
        self.qtgui_time_sink_x_0.enable_tags(-1, True)
        self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self.qtgui_time_sink_x_0.enable_autoscale(False)
        self.qtgui_time_sink_x_0.enable_grid(False)
        self.qtgui_time_sink_x_0.enable_control_panel(False)
        
        if not True:
          self.qtgui_time_sink_x_0.disable_legend()
        
        labels = ["", "", "", "", "",
                  "", "", "", "", ""]
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "dark red", "dark green", "blue"]
        styles = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1,
                   -1, -1, -1, -1, -1]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        
        for i in xrange(1):
            if len(labels[i]) == 0:
                self.qtgui_time_sink_x_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_time_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_0.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_0.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win, 0,1,3,1)
        self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	final_rate, #bw
        	"Decimated Channel", #name
        	1 #number of inputs
        )
        self.qtgui_freq_sink_x_0_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0_0.set_y_axis(-200, -60)
        self.qtgui_freq_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
        self.qtgui_freq_sink_x_0_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0_0.enable_grid(False)
        self.qtgui_freq_sink_x_0_0.set_fft_average(1.0)
        self.qtgui_freq_sink_x_0_0.enable_control_panel(False)
        
        if not True:
          self.qtgui_freq_sink_x_0_0.disable_legend()
        
        if complex == type(float()):
          self.qtgui_freq_sink_x_0_0.set_plot_pos_half(not True)
        
        labels = ["", "", "", "", "",
                  "", "", "", "", ""]
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "dark red", "dark green", "dark blue"]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(1):
            if len(labels[i]) == 0:
                self.qtgui_freq_sink_x_0_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_0_0.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_0_0.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_0_0.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_0_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_freq_sink_x_0_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_0_win, 3,0,3,1)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
        	fft_length, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	144E6, #fc
        	samp_rate, #bw
        	"Spectrum", #name
        	1 #number of inputs
        )
        self.qtgui_freq_sink_x_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0.set_y_axis(-120, -20)
        self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
        self.qtgui_freq_sink_x_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0.enable_grid(False)
        self.qtgui_freq_sink_x_0.set_fft_average(1.0)
        self.qtgui_freq_sink_x_0.enable_control_panel(False)
        
        if not True:
          self.qtgui_freq_sink_x_0.disable_legend()
        
        if complex == type(float()):
          self.qtgui_freq_sink_x_0.set_plot_pos_half(not True)
        
        labels = ["", "", "", "", "",
                  "", "", "", "", ""]
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "dark red", "dark green", "dark blue"]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(1):
            if len(labels[i]) == 0:
                self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 0,0,3,1)
        self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_fff(
        	  16E3/float(final_rate/5),
                  taps=None,
        	  flt_size=32)
        self.pfb_arb_resampler_xxx_0.declare_sample_delay(0)
        	
        self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "uhd" )
        self.osmosdr_source_0.set_sample_rate(samp_rate)
        self.osmosdr_source_0.set_center_freq(center_freq, 0)
        self.osmosdr_source_0.set_freq_corr(0, 0)
        self.osmosdr_source_0.set_dc_offset_mode(0, 0)
        self.osmosdr_source_0.set_iq_balance_mode(0, 0)
        self.osmosdr_source_0.set_gain_mode(False, 0)
        self.osmosdr_source_0.set_gain(gain_db, 0)
        self.osmosdr_source_0.set_if_gain(20, 0)
        self.osmosdr_source_0.set_bb_gain(20, 0)
        self.osmosdr_source_0.set_antenna("", 0)
        self.osmosdr_source_0.set_bandwidth(samp_rate*0.8, 0)
          
        self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(initial_decim, (variable_low_pass_filter_taps_0), demod_bb_freq, samp_rate)
        self.fir_filter_xxx_0_1 = filter.fir_filter_fff(initial_decim, (variable_low_pass_filter_taps_0))
        self.fir_filter_xxx_0_1.declare_sample_delay(0)
        self.fir_filter_xxx_0_0 = filter.fir_filter_ccc(int(samp_rate/1E6), (variable_low_pass_filter_taps_0))
        self.fir_filter_xxx_0_0.declare_sample_delay(0)
        self.fir_filter_xxx_0 = filter.fir_filter_ccc(initial_decim, (variable_low_pass_filter_taps_0))
        self.fir_filter_xxx_0.declare_sample_delay(0)
        self.fft_vxx_0 = fft.fft_vcc(fft_length, True, (window.blackmanharris(fft_length)), True, 1)
        self.blocks_wavfile_sink_0 = blocks.wavfile_sink(file_name, 1, 16000, 8)
        self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_float*1, fft_length)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_length)
        self.blocks_probe_signal_vx_0 = blocks.probe_signal_vf(fft_length)
        self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, fft_length, 0)
        self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n(gr.sizeof_gr_complex*fft_length, int(round(samp_rate/fft_length/1000)))
        self.blocks_integrate_xx_0 = blocks.integrate_ff(100, fft_length)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(fft_length)
        self.audio_sink_0 = audio.sink(16000, "", True)
        self.analog_quadrature_demod_cf_0 = analog.quadrature_demod_cf(0.050)
        self.analog_pwr_squelch_xx_0_0 = analog.pwr_squelch_ff(-200, 0.1, 0, True)
        self.analog_pwr_squelch_xx_0 = analog.pwr_squelch_cc(squelch_dB, 0.1, 0, False)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_pwr_squelch_xx_0, 0), (self.analog_quadrature_demod_cf_0, 0))    
        self.connect((self.analog_pwr_squelch_xx_0_0, 0), (self.blocks_wavfile_sink_0, 0))    
        self.connect((self.analog_quadrature_demod_cf_0, 0), (self.fir_filter_xxx_0_1, 0))    
        self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_integrate_xx_0, 0))    
        self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_nlog10_ff_0, 0))    
        self.connect((self.blocks_keep_one_in_n_0, 0), (self.fft_vxx_0, 0))    
        self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_probe_signal_vx_0, 0))    
        self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_vector_to_stream_0, 0))    
        self.connect((self.blocks_stream_to_vector_0, 0), (self.blocks_keep_one_in_n_0, 0))    
        self.connect((self.blocks_vector_to_stream_0, 0), (self.qtgui_time_sink_x_0, 0))    
        self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0))    
        self.connect((self.fir_filter_xxx_0, 0), (self.fir_filter_xxx_0_0, 0))    
        self.connect((self.fir_filter_xxx_0_0, 0), (self.analog_pwr_squelch_xx_0, 0))    
        self.connect((self.fir_filter_xxx_0_0, 0), (self.qtgui_freq_sink_x_0_0, 0))    
        self.connect((self.fir_filter_xxx_0_1, 0), (self.pfb_arb_resampler_xxx_0, 0))    
        self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.fir_filter_xxx_0, 0))    
        self.connect((self.osmosdr_source_0, 0), (self.blocks_stream_to_vector_0, 0))    
        self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))    
        self.connect((self.osmosdr_source_0, 0), (self.qtgui_freq_sink_x_0, 0))    
        self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.analog_pwr_squelch_xx_0_0, 0))    
        self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.audio_sink_0, 0))    
Example #17
0
    def __init__(self):
        gr.top_block.__init__(self, "Spectrum Sensing")

        ##################################################
        # APP CONTROL
        ##################################################
        self.system_run = True

        ##################################################
        # Variables
        ##################################################
        self.center_freq = center_freq = 2.412e9
        self.samp_rate = samp_rate = 5e6
        self.bw = bw = 20e6
        self.time_resolution = time_resolution = 10e-6
        self.nsamples = nsamples = int(samp_rate * time_resolution)
        self.fft_size = fft_size = 256
        self.ch = 1

        ##################################################
        # Blocks
        ##################################################
        self.spec_sensing_fft_average_cc_0 = spec_sensing.fft_average_cc(10, fft_size)
        self.spec_sensing_energy_cf_0 = spec_sensing.energy_cf(nsamples)
        self.osmosdr_source = osmosdr.source( args="numchan=" + str(1) + " " + "bladerf=1" )
        self.osmosdr_source.set_sample_rate(samp_rate)
        self.osmosdr_source.set_center_freq(center_freq, 0)
        self.osmosdr_source.set_freq_corr(0, 0)
        self.osmosdr_source.set_dc_offset_mode(0, 0)
        self.osmosdr_source.set_iq_balance_mode(1, 0)
        self.osmosdr_source.set_gain_mode(False, 0)
        self.osmosdr_source.set_gain(0, 0)
        self.osmosdr_source.set_if_gain(0, 0)
        self.osmosdr_source.set_bb_gain(0, 0)
        self.osmosdr_source.set_antenna("", 0)
        self.osmosdr_source.set_bandwidth(bw, 0)
          
        self.fft_vxx_0 = fft.fft_vcc(fft_size, True, (window.blackmanharris(fft_size)), True, 1)
        self.dc_blocker = filter.dc_blocker_cc(fft_size, True)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_size)
        self.blocks_null_sink_energy = blocks.null_sink(gr.sizeof_float*1)
        self.blocks_null_sink_fft_avg = blocks.null_sink(gr.sizeof_float*fft_size)
        self.blocks_complex_to_mag_0 = blocks.complex_to_mag(fft_size)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.osmosdr_source, 0), (self.dc_blocker, 0))
        
        self.connect((self.dc_blocker, 0), (self.spec_sensing_energy_cf_0, 0))
        self.connect((self.spec_sensing_energy_cf_0, 0), (self.blocks_null_sink_energy, 0))
        
        self.connect((self.dc_blocker, 0), (self.blocks_stream_to_vector_0, 0))
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))
        self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_0, 0))
        self.connect((self.blocks_complex_to_mag_0, 0), (self.spec_sensing_fft_average_cc_0, 0))
        self.connect((self.spec_sensing_fft_average_cc_0, 0), (self.blocks_null_sink_fft_avg, 0))

        ##################################################
        # MESSAGE PASSING
        ##################################################
        self.message_block = messaging.message_block(self)
        self.msg_connect(self.spec_sensing_energy_cf_0, "out_port", self.message_block, "in_energy")
        self.msg_connect(self.spec_sensing_fft_average_cc_0, "out_port", self.message_block, "in_fft_average")
        self.msg_connect(self.message_block, "out_energy", self.spec_sensing_energy_cf_0, "in_port")
        self.msg_connect(self.message_block, "out_fft_average", self.spec_sensing_fft_average_cc_0, "in_port")

        ##################################################
        # FILE SINKS
        ##################################################
        ##self.energy_file_sink = blocks.file_sink(gr.sizeof_float*1, 'energy.dat', False)
        ##self.connect((self.spec_sensing_energy_cf_0, 0), (self.energy_file_sink, 0))

        ##################################################
        # FLAGS
        ##################################################
        self.energy_finish = False
        self.fft_finish = False

        ##################################################
        # DATA
        ##################################################
        # PKT DATA
        self.energy_data = [[0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0]]
        self.rho = [0 for x in range(13)]
        self.delta = [0 for x in range(13)]
        self.pkt = [0 for x in range(13)]
        self.n_pkt = [0 for x in range(13)]
    def __init__(self, angle=0, samp_rate=1e6, fft_len=pow(2,20), samp_rate_sink=8000, tx_amp=10e-3, max_num_of_targets=10, lowpass_cutoff_freq=1700, RF=2.49e9, speed_samp_rate=1, DC_filter_num_elements=4, threshold_dB=-70, rx_gain=0, highpass_cutoff_freq=0, doppler_signal_bw=20):
        grc_wxgui.top_block_gui.__init__(self, title="CW Doppler Radar Simulator Multiple Targets")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Parameters
        ##################################################
        self.angle = angle
        self.samp_rate = samp_rate
        self.fft_len = fft_len
        self.samp_rate_sink = samp_rate_sink
        self.tx_amp = tx_amp
        self.max_num_of_targets = max_num_of_targets
        self.lowpass_cutoff_freq = lowpass_cutoff_freq
        self.RF = RF
        self.speed_samp_rate = speed_samp_rate
        self.DC_filter_num_elements = DC_filter_num_elements
        self.threshold_dB = threshold_dB
        self.rx_gain = rx_gain
        self.highpass_cutoff_freq = highpass_cutoff_freq
        self.doppler_signal_bw = doppler_signal_bw

        ##################################################
        # Variables
        ##################################################
        self.target_speed_vector = target_speed_vector = 0
        self.target_direction_vector = target_direction_vector = 0
        self.num_targets = num_targets = 0
        self.tx_amp_tuner = tx_amp_tuner = tx_amp
        self.threshold_dB_tuner = threshold_dB_tuner = threshold_dB
        self.speed_textbox = speed_textbox = target_speed_vector
        self.rx_gain_tuner = rx_gain_tuner = rx_gain
        self.num_targets_textbox = num_targets_textbox = num_targets
        self.max_num_of_targets_tuner = max_num_of_targets_tuner = max_num_of_targets
        self.lowpass_cutoff_freq_tuner = lowpass_cutoff_freq_tuner = lowpass_cutoff_freq
        self.highpass_cutoff_freq_tuner = highpass_cutoff_freq_tuner = highpass_cutoff_freq
        self.doppler_signal_bw_tuner = doppler_signal_bw_tuner = doppler_signal_bw
        self.doppler_freq_sim_tuner = doppler_freq_sim_tuner = 100
        self.direction_textbox = direction_textbox = target_direction_vector
        self.angle_tuner = angle_tuner = angle
        self.RF_tuner = RF_tuner = RF

        ##################################################
        # Blocks
        ##################################################
        _tx_amp_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._tx_amp_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_tx_amp_tuner_sizer,
        	value=self.tx_amp_tuner,
        	callback=self.set_tx_amp_tuner,
        	label="TX Signal Amp",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._tx_amp_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_tx_amp_tuner_sizer,
        	value=self.tx_amp_tuner,
        	callback=self.set_tx_amp_tuner,
        	minimum=0,
        	maximum=100e-3,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_tx_amp_tuner_sizer, 0, 8, 1, 21)
        _threshold_dB_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._threshold_dB_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_threshold_dB_tuner_sizer,
        	value=self.threshold_dB_tuner,
        	callback=self.set_threshold_dB_tuner,
        	label="Detected Target Threshold (dB)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._threshold_dB_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_threshold_dB_tuner_sizer,
        	value=self.threshold_dB_tuner,
        	callback=self.set_threshold_dB_tuner,
        	minimum=-90,
        	maximum=-30,
        	num_steps=60,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_threshold_dB_tuner_sizer, 2, 0, 1, 8)
        self.speed_vector_probe = blocks.probe_signal_vf(max_num_of_targets)
        self.notebook = self.notebook = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "FFT CW Doppler Radar Receiver")
        self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "Frequency/Time CW Doppler Radar Receiver")
        self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "FFT CW Doppler Radar Receiver Full Spectrum")
        self.GridAdd(self.notebook, 6, 0, 13, 53)
        _max_num_of_targets_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._max_num_of_targets_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_max_num_of_targets_tuner_sizer,
        	value=self.max_num_of_targets_tuner,
        	callback=self.set_max_num_of_targets_tuner,
        	label="Maximum Number of Targets",
        	converter=forms.int_converter(),
        	proportion=0,
        )
        self._max_num_of_targets_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_max_num_of_targets_tuner_sizer,
        	value=self.max_num_of_targets_tuner,
        	callback=self.set_max_num_of_targets_tuner,
        	minimum=0,
        	maximum=100,
        	num_steps=100,
        	style=wx.SL_HORIZONTAL,
        	cast=int,
        	proportion=1,
        )
        self.GridAdd(_max_num_of_targets_tuner_sizer, 2, 8, 1, 21)
        _lowpass_cutoff_freq_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._lowpass_cutoff_freq_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_lowpass_cutoff_freq_tuner_sizer,
        	value=self.lowpass_cutoff_freq_tuner,
        	callback=self.set_lowpass_cutoff_freq_tuner,
        	label="Low-Pass Cutoff Frequency (Hz)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._lowpass_cutoff_freq_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_lowpass_cutoff_freq_tuner_sizer,
        	value=self.lowpass_cutoff_freq_tuner,
        	callback=self.set_lowpass_cutoff_freq_tuner,
        	minimum=0,
        	maximum=3000,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_lowpass_cutoff_freq_tuner_sizer, 1, 29, 1, 24)
        _highpass_cutoff_freq_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._highpass_cutoff_freq_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_highpass_cutoff_freq_tuner_sizer,
        	value=self.highpass_cutoff_freq_tuner,
        	callback=self.set_highpass_cutoff_freq_tuner,
        	label="High-Pass Cutoff Frequency (Hz)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._highpass_cutoff_freq_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_highpass_cutoff_freq_tuner_sizer,
        	value=self.highpass_cutoff_freq_tuner,
        	callback=self.set_highpass_cutoff_freq_tuner,
        	minimum=0,
        	maximum=1600,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_highpass_cutoff_freq_tuner_sizer, 0, 29, 1, 24)
        _doppler_signal_bw_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._doppler_signal_bw_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_doppler_signal_bw_tuner_sizer,
        	value=self.doppler_signal_bw_tuner,
        	callback=self.set_doppler_signal_bw_tuner,
        	label="Doppler Spectrum Bandwidth (Hz)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._doppler_signal_bw_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_doppler_signal_bw_tuner_sizer,
        	value=self.doppler_signal_bw_tuner,
        	callback=self.set_doppler_signal_bw_tuner,
        	minimum=0,
        	maximum=100,
        	num_steps=100,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_doppler_signal_bw_tuner_sizer, 2, 29, 1, 24)
        _doppler_freq_sim_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._doppler_freq_sim_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_doppler_freq_sim_tuner_sizer,
        	value=self.doppler_freq_sim_tuner,
        	callback=self.set_doppler_freq_sim_tuner,
        	label="Doppler Frequency Simulator (Hz)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._doppler_freq_sim_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_doppler_freq_sim_tuner_sizer,
        	value=self.doppler_freq_sim_tuner,
        	callback=self.set_doppler_freq_sim_tuner,
        	minimum=-2000,
        	maximum=2000,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_doppler_freq_sim_tuner_sizer, 3, 29, 1, 24)
        self.direction_vector_probe = blocks.probe_signal_vi(max_num_of_targets)
        _angle_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._angle_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_angle_tuner_sizer,
        	value=self.angle_tuner,
        	callback=self.set_angle_tuner,
        	label="Angle of Approach of the Target (Deg)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._angle_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_angle_tuner_sizer,
        	value=self.angle_tuner,
        	callback=self.set_angle_tuner,
        	minimum=0,
        	maximum=89,
        	num_steps=890,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_angle_tuner_sizer, 1, 8, 1, 21)
        _RF_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._RF_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_RF_tuner_sizer,
        	value=self.RF_tuner,
        	callback=self.set_RF_tuner,
        	label="Radar Frequency (Hz)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._RF_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_RF_tuner_sizer,
        	value=self.RF_tuner,
        	callback=self.set_RF_tuner,
        	minimum=2.4e9,
        	maximum=2.5e9,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_RF_tuner_sizer, 1, 0, 1, 8)
        self.wxgui_waterfallsink2_time_frequency = waterfallsink2.waterfall_sink_c(
        	self.notebook.GetPage(1).GetWin(),
        	baseband_freq=0,
        	dynamic_range=100,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate_sink,
        	fft_size=1024,
        	fft_rate=15,
        	average=True,
        	avg_alpha=None,
        	title="Time/Frequency CW Doppler Radar Receiver",
        	win=window.blackmanharris,
        )
        self.notebook.GetPage(1).Add(self.wxgui_waterfallsink2_time_frequency.win)
        self.wxgui_fftsink2_full_spectrum = fftsink2.fft_sink_c(
        	self.notebook.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=4096,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="FFT CW Doppler Radar Receiver Full Spectrum",
        	peak_hold=False,
        	win=window.blackmanharris,
        )
        self.notebook.GetPage(2).Add(self.wxgui_fftsink2_full_spectrum.win)
        self.wxgui_fftsink2 = fftsink2.fft_sink_c(
        	self.notebook.GetPage(0).GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate_sink,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="FFT CW Doppler Radar Receiver ",
        	peak_hold=False,
        	win=window.blackmanharris,
        )
        self.notebook.GetPage(0).Add(self.wxgui_fftsink2.win)
        self.vector_to_stream_positive = blocks.vector_to_stream(gr.sizeof_float*1, fft_len)
        self.vector_to_stream_negative = blocks.vector_to_stream(gr.sizeof_float*1, fft_len)
        self.tx_signal = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 0, 1, 0)
        self.throtle_block = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        def _target_speed_vector_probe():
            while True:
                val = self.speed_vector_probe.level()
                try:
                    self.set_target_speed_vector(val)
                except AttributeError:
                    pass
                time.sleep(1.0 / (speed_samp_rate))
        _target_speed_vector_thread = threading.Thread(target=_target_speed_vector_probe)
        _target_speed_vector_thread.daemon = True
        _target_speed_vector_thread.start()
        def _target_direction_vector_probe():
            while True:
                val = self.direction_vector_probe.level()
                try:
                    self.set_target_direction_vector(val)
                except AttributeError:
                    pass
                time.sleep(1.0 / (speed_samp_rate))
        _target_direction_vector_thread = threading.Thread(target=_target_direction_vector_probe)
        _target_direction_vector_thread.daemon = True
        _target_direction_vector_thread.start()
        self.stream_to_vector_positive = blocks.stream_to_vector(gr.sizeof_float*1, fft_len/2)
        self.stream_to_vector_negative = blocks.stream_to_vector(gr.sizeof_float*1, fft_len/2)
        self.stream_to_vector_for_fft = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_len)
        self._speed_textbox_text_box = forms.text_box(
        	parent=self.GetWin(),
        	value=self.speed_textbox,
        	callback=self.set_speed_textbox,
        	label="Targets Speed (Kph)",
        	converter=forms.str_converter(),
        )
        self.GridAdd(self._speed_textbox_text_box, 4, 0, 1, 53)
        self.rx_signal_2 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, doppler_freq_sim_tuner+15, tx_amp_tuner-5e-3, 0)
        self.rx_signal_1 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, doppler_freq_sim_tuner-1300, tx_amp+10e-3, 0)
        self.rx_signal_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, doppler_freq_sim_tuner, tx_amp_tuner, 0)
        _rx_gain_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._rx_gain_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_rx_gain_tuner_sizer,
        	value=self.rx_gain_tuner,
        	callback=self.set_rx_gain_tuner,
        	label="USRP RX Gain (dB)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._rx_gain_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_rx_gain_tuner_sizer,
        	value=self.rx_gain_tuner,
        	callback=self.set_rx_gain_tuner,
        	minimum=0,
        	maximum=70,
        	num_steps=70,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_rx_gain_tuner_sizer, 0, 0, 1, 8)
        self.rational_resampler = filter.rational_resampler_ccc(
                interpolation=1,
                decimation=int(samp_rate/samp_rate_sink),
                taps=None,
                fractional_bw=None,
        )
        self._num_targets_textbox_text_box = forms.text_box(
        	parent=self.GetWin(),
        	value=self.num_targets_textbox,
        	callback=self.set_num_targets_textbox,
        	label="Number of Targets Detected",
        	converter=forms.int_converter(),
        )
        self.GridAdd(self._num_targets_textbox_text_box, 3, 0, 1, 4)
        self.num_targets_probe = blocks.probe_signal_i()
        def _num_targets_probe():
            while True:
                val = self.num_targets_probe.level()
                try:
                    self.set_num_targets(val)
                except AttributeError:
                    pass
                time.sleep(1.0 / (speed_samp_rate))
        _num_targets_thread = threading.Thread(target=_num_targets_probe)
        _num_targets_thread.daemon = True
        _num_targets_thread.start()
        self.mixer = blocks.multiply_vcc(1)
        self.keep_m_in_n_positive = blocks.keep_m_in_n(gr.sizeof_float, fft_len/2, fft_len, fft_len/2)
        self.keep_m_in_n_negative = blocks.keep_m_in_n(gr.sizeof_float, fft_len/2, fft_len, 0)
        self.fft_vxx_0 = fft.fft_vcc(fft_len, True, (window.blackmanharris(fft_len)), True, 1)
        self._direction_textbox_text_box = forms.text_box(
        	parent=self.GetWin(),
        	value=self.direction_textbox,
        	callback=self.set_direction_textbox,
        	label="Targets Direction",
        	converter=forms.str_converter(),
        )
        self.GridAdd(self._direction_textbox_text_box, 5, 0, 1, 53)
        self.cwradar_vector_flip_ff = cwradar.vector_flip_ff(fft_len/2)
        self.cwradar_doppler_velocity_multiple_targets_ff = cwradar.doppler_velocity_multiple_targets_ff(fft_len/2, samp_rate, RF_tuner, threshold_dB_tuner, angle_tuner, lowpass_cutoff_freq_tuner, highpass_cutoff_freq_tuner, max_num_of_targets_tuner, doppler_signal_bw_tuner)
        self.blocks_complex_to_mag = blocks.complex_to_mag(fft_len)
        self.awgn_channel_simulator = analog.noise_source_c(analog.GR_GAUSSIAN, 1e-3, 0)
        self.adder_2 = blocks.add_vcc(1)
        self.adder_1 = blocks.add_vcc(1)
        self.DC_filter_positive = blocks.multiply_const_vff(([0]*DC_filter_num_elements+[1]*((fft_len/2)-DC_filter_num_elements)))
        self.DC_filter_negative = blocks.multiply_const_vff(([0]*DC_filter_num_elements+[1]*((fft_len/2)-DC_filter_num_elements)))

        ##################################################
        # Connections
        ##################################################
        self.connect((self.DC_filter_negative, 0), (self.cwradar_doppler_velocity_multiple_targets_ff, 0))
        self.connect((self.DC_filter_positive, 0), (self.cwradar_doppler_velocity_multiple_targets_ff, 1))
        self.connect((self.cwradar_doppler_velocity_multiple_targets_ff, 2), (self.num_targets_probe, 0))
        self.connect((self.cwradar_doppler_velocity_multiple_targets_ff, 1), (self.direction_vector_probe, 0))
        self.connect((self.cwradar_doppler_velocity_multiple_targets_ff, 0), (self.speed_vector_probe, 0))
        self.connect((self.awgn_channel_simulator, 0), (self.adder_2, 0))
        self.connect((self.tx_signal, 0), (self.adder_2, 1))
        self.connect((self.adder_2, 0), (self.mixer, 0))
        self.connect((self.awgn_channel_simulator, 0), (self.adder_1, 0))
        self.connect((self.mixer, 0), (self.throtle_block, 0))
        self.connect((self.mixer, 0), (self.stream_to_vector_for_fft, 0))
        self.connect((self.throtle_block, 0), (self.wxgui_fftsink2_full_spectrum, 0))
        self.connect((self.throtle_block, 0), (self.rational_resampler, 0))
        self.connect((self.adder_1, 0), (self.mixer, 1))
        self.connect((self.rational_resampler, 0), (self.wxgui_waterfallsink2_time_frequency, 0))
        self.connect((self.stream_to_vector_for_fft, 0), (self.fft_vxx_0, 0))
        self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag, 0))
        self.connect((self.blocks_complex_to_mag, 0), (self.vector_to_stream_negative, 0))
        self.connect((self.blocks_complex_to_mag, 0), (self.vector_to_stream_positive, 0))
        self.connect((self.vector_to_stream_positive, 0), (self.keep_m_in_n_positive, 0))
        self.connect((self.keep_m_in_n_negative, 0), (self.stream_to_vector_negative, 0))
        self.connect((self.keep_m_in_n_positive, 0), (self.stream_to_vector_positive, 0))
        self.connect((self.vector_to_stream_negative, 0), (self.keep_m_in_n_negative, 0))
        self.connect((self.stream_to_vector_positive, 0), (self.DC_filter_positive, 0))
        self.connect((self.stream_to_vector_negative, 0), (self.cwradar_vector_flip_ff, 0))
        self.connect((self.cwradar_vector_flip_ff, 0), (self.DC_filter_negative, 0))
        self.connect((self.rx_signal_1, 0), (self.adder_1, 3))
        self.connect((self.rx_signal_0, 0), (self.adder_1, 2))
        self.connect((self.tx_signal, 0), (self.adder_1, 1))
        self.connect((self.rx_signal_2, 0), (self.adder_1, 4))
        self.connect((self.rational_resampler, 0), (self.wxgui_fftsink2, 0))
Example #19
0
    def __do_connect(self):
        itemsize = self.__itemsize
        
        if self.__signal_type.is_analytic():
            input_length = self.__freq_resolution
            output_length = self.__freq_resolution
            self.__after_fft = None
        else:
            # use vector_to_streams to cut the output in half and discard the redundant part
            input_length = self.__freq_resolution * 2
            output_length = self.__freq_resolution
            self.__after_fft = blocks.vector_to_streams(itemsize=output_length * gr.sizeof_float, nstreams=2)
        
        sample_rate = self.__signal_type.get_sample_rate()
        overlap_factor = int(math.ceil(_maximum_fft_rate * input_length / sample_rate))
        # sanity limit -- OverlapGimmick is not free
        overlap_factor = min(16, overlap_factor)
        
        self.__frame_rate_to_decimation_conversion = sample_rate * overlap_factor / input_length
        
        self.__gate = blocks.copy(itemsize)
        self.__gate.set_enabled(not self.__paused)
        
        overlapper = _OverlappedStreamToVector(
            size=input_length,
            factor=overlap_factor,
            itemsize=itemsize)
        
        self.__frame_dec = blocks.keep_one_in_n(
            itemsize=itemsize * input_length,
            n=int(round(self.__frame_rate_to_decimation_conversion / self.__frame_rate)))
        
        # the actual FFT logic, which is similar to GR's logpwrfft_c
        window = windows.blackmanharris(input_length)
        window_power = sum(x * x for x in window)
        # TODO: use fft_vfc when applicable
        fft_block = (fft_vcc if itemsize == gr.sizeof_gr_complex else fft_vfc)(
            fft_size=input_length,
            forward=True,
            window=window)
        mag_squared = blocks.complex_to_mag_squared(input_length)
        logarithmizer = blocks.nlog10_ff(
            n=10,  # the "deci" in "decibel"
            vlen=input_length,
            k=(
                -to_dB(window_power) +  # compensate for window
                -to_dB(sample_rate) +  # convert from power-per-sample to power-per-Hz
                self.__power_offset  # offset for packing into bytes
            ))
        
        # It would make slightly more sense to use unsigned chars, but blocks.float_to_uchar does not support vlen.
        self.__fft_converter = blocks.float_to_char(vlen=self.__freq_resolution, scale=1.0)
        
        self.__fft_sink = MessageDistributorSink(
            itemsize=output_length * gr.sizeof_char,
            context=self.__context,
            migrate=self.__fft_sink,
            notify=self.__update_interested)
    
        self.__scope_sink = MessageDistributorSink(
            itemsize=self.__time_length * gr.sizeof_gr_complex,
            context=self.__context,
            migrate=self.__scope_sink,
            notify=self.__update_interested)
        scope_chunker = blocks.stream_to_vector_decimator(
            item_size=gr.sizeof_gr_complex,
            sample_rate=sample_rate,
            vec_rate=self.__frame_rate,  # TODO doesn't need to be coupled
            vec_len=self.__time_length)

        # connect everything
        self.__context.lock()
        try:
            self.disconnect_all()
            self.connect(
                self,
                self.__gate,
                overlapper,
                self.__frame_dec,
                fft_block,
                mag_squared,
                logarithmizer)
            if self.__after_fft is not None:
                self.connect(logarithmizer, self.__after_fft)
                self.connect(self.__after_fft, self.__fft_converter, self.__fft_sink)
                self.connect((self.__after_fft, 1), blocks.null_sink(gr.sizeof_float * self.__freq_resolution))
            else:
                self.connect(logarithmizer, self.__fft_converter, self.__fft_sink)
            if self.__enable_scope:
                self.connect(
                    self.__gate,
                    scope_chunker,
                    self.__scope_sink)
        finally:
            self.__context.unlock()
Example #20
0
    def __init__(self):
        gr.top_block.__init__(self)

        self.sample_rate = 3000
        self.ampl = 1
        self.freq = 1900
        self.cen_freq = 0
        self.counter = 0

    # --- Sources ----
        self.src0 = analog.sig_source_f(self.sample_rate, analog.GR_COS_WAVE, self.freq, 1, 0)
        self.src1 = analog.sig_source_f(self.sample_rate, analog.GR_COS_WAVE, self.freq/2, 1, 0)

    # --- Audio Out ---

        self.audioOut = audio.sink(32000, "", True) 

    # --- Blocks ----- 

        self.add = blocks.add_vff(1)   #Add Block

        #self.throttle = blocks.throttle(gr.sizeof_float*1, self.sample_rate,True)

        self.streamToVector = blocks.stream_to_vector_decimator(
            item_size=gr.sizeof_float,
            sample_rate=self.sample_rate,
            vec_rate=30,
            vec_len=1024,
        )

        self.fft = fft.fft_vfc(1024, True, (window.blackmanharris(1024)), 1)
        
        self.complexToMag = blocks.complex_to_mag_squared(1024)
        
        self.probe = blocks.probe_signal_vf(1024)

    # --- Functions ----

        def fft_cal():
            while 1:
                val = self.probe.level()
                print "Index: {}".format(val.index(max(val)))
                freq = (val.index(max(val))) * (self.sample_rate/1024.0)
                print freq
                print len(val)
                time.sleep(1)
                
                #self.set_freq(self.freq+100)

                pow_ran = []
                freq_ran = []

                if self.counter:
                    for i in val:
                        pow_ran.append(float(i)/max(val))
                    for i in range(1024):
                        freq_ran.append(i*self.sample_rate/1024.0)

                    fig = plt.plot(freq_ran,pow_ran)
                    plt.ylim(-0.3,1.2)
                    plt.xlim(min(freq_ran),max(freq_ran))
                    plt.show()

                self.counter+=1



    # --- Start Thread ---

        fft_thread = threading.Thread(target=fft_cal)
        fft_thread.daemon = True
        fft_thread.start()

    # --- Conections ---

        #self.connect((self.src0, 0), (self.add, 0))
        #self.connect((self.src1, 0), (self.add, 1))

        #self.connect((self.add, 0), (self.audioOut, 0))
        #self.connect((self.src0, 0), (self.throttle, 0))
        #self.connect((self.throttle, 0), (self.streamToVector, 0))
        self.connect((self.src0, 0), (self.streamToVector, 0))
        self.connect((self.streamToVector, 0), (self.fft, 0))
        self.connect((self.fft, 0),(self.complexToMag, 0))
        self.connect((self.complexToMag, 0),(self.probe, 0))
Example #21
0
    def __init__(self, fftsize, samp_rate, gain, c_freq, windows):
		gr.top_block.__init__(self, "CalculateFFT")
        
		#Class variables
		self.samp_rate = samp_rate
		self.gain = gain
		self.fftsize = fftsize
		self.c_freq = c_freq
		self.dump1 = "/tmp/ramdisk/dump1" #View as null sinks
		self.dump2 = "/tmp/ramdisk/dump2"
		self.alpha = 0.01 #Integrate 100 FFTS 0.01
		self.N = 100 #100
		self.probe_var = probe_var = 0
		
		blackman_harris = window.blackmanharris(self.fftsize)
		hanning = window.hanning(self.fftsize)
		rectangular = window.rectangular(self.fftsize)
		self.window = blackman_harris #Default window
		self.select_window = windows
		
		###Selectable FFT Windows###
		if self.select_window == "blackman-harris":
			self.window = blackman_harris
		elif self.select_window == "hanning":	
			self.window = hanning
		elif self.select_window == "rectangular":
			self.window = rectangular
			
		
		########## GNURADIO BLOCKS #########
		####################################
		self.uhd_usrp_source_0 = uhd.usrp_source(
			",".join(("", "master_clock_rate=120e6")), #Set the master_clock_rate, default = 200 MHz, alt 184.32 MHz and 120 MHz (Set)
			uhd.stream_args(
				cpu_format="fc32",
				channels=range(1),
			),
        )
        #Configure USRP channel 0
		self.uhd_usrp_source_0.set_samp_rate(self.samp_rate)
		self.uhd_usrp_source_0.set_center_freq(self.c_freq, 0)
		self.uhd_usrp_source_0.set_gain(self.gain, 0)
		self.uhd_usrp_source_0.set_bandwidth(self.samp_rate, 0)
		self.uhd_usrp_source_0.set_clock_source('internal', 0)
		
		#Signal and reference file sinks
		self.signal_file_sink_1 = blocks.file_sink(gr.sizeof_float*1, self.dump1, False)
		self.signal_file_sink_1.set_unbuffered(False)
		self.signal_file_sink_2 = blocks.file_sink(gr.sizeof_float*1, self.dump2, False)
		self.signal_file_sink_2.set_unbuffered(False)
	
		#Selector for GPIO switch
		self.blks2_selector_0 = grc_blks2.selector(
        	item_size=gr.sizeof_float*1,
        	num_inputs=1,
        	num_outputs=2+1, #+1 for the null sink
        	input_index=0,
        	output_index=0,
        )
		self.blocks_null_sink = blocks.null_sink(gr.sizeof_float*1)
		self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff(self.alpha, self.fftsize)
		self.fft_vxx_0 = fft.fft_vcc(self.fftsize, True, (self.window), True, 1)
		self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_float*1, self.fftsize)
		self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, self.fftsize)
		self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n(gr.sizeof_float*self.fftsize, self.N)
		self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(self.fftsize)
	
		#Block connections
		self.connect((self.uhd_usrp_source_0, 0), (self.blocks_stream_to_vector_0, 0))
		self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))
		self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0))
		self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.single_pole_iir_filter_xx_0, 0))
		self.connect((self.single_pole_iir_filter_xx_0, 0), (self.blocks_keep_one_in_n_0, 0))
		self.connect((self.blocks_keep_one_in_n_0, 0), (self.blocks_vector_to_stream_0, 0))
		self.connect((self.blocks_vector_to_stream_0, 0), (self.blks2_selector_0, 0)) 
		
		#Selector connections
		self.connect((self.blks2_selector_0, 1), (self.signal_file_sink_1, 0))
		self.connect((self.blks2_selector_0, 2), (self.signal_file_sink_2, 0))
		
		#Null sink connection
		self.connect((self.blks2_selector_0, 0), (self.blocks_null_sink, 0))
		
		#PROBE SAMPLES
		self.probe_signal = blocks.probe_signal_f()
		self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1)
		
		self.connect((self.blocks_complex_to_mag_0, 0), (self.probe_signal, 0))    
		self.connect((self.uhd_usrp_source_0, 0), (self.blocks_complex_to_mag_0, 0))
		
		#Probe update rate
		def _probe_var_probe():
			while True:
				val = self.probe_signal.level()
				try:
					self.set_probe_var(val)
				except AttributeError:
					pass
				time.sleep(10 / (self.samp_rate)) #Update probe variabel every 10/samp_rate seconds

		_probe_var_thread = threading.Thread(target=_probe_var_probe)
		_probe_var_thread.daemon = True
		_probe_var_thread.start()
Example #22
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Top Block")
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        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)

        self.settings = Qt.QSettings("GNU Radio", "top_block")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000

        ##################################################
        # Blocks
        ##################################################
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	samp_rate, #bw
        	"", #name
        	1 #number of inputs
        )
        self.qtgui_freq_sink_x_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0.set_y_axis(-140, 10)
        self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
        self.qtgui_freq_sink_x_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0.enable_grid(False)
        self.qtgui_freq_sink_x_0.set_fft_average(1.0)
        self.qtgui_freq_sink_x_0.enable_control_panel(False)
        
        if not True:
          self.qtgui_freq_sink_x_0.disable_legend()
        
        if "complex" == "float" or "complex" == "msg_float":
          self.qtgui_freq_sink_x_0.set_plot_pos_half(not True)
        
        labels = ["", "", "", "", "",
                  "", "", "", "", ""]
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "dark red", "dark green", "dark blue"]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(1):
            if len(labels[i]) == 0:
                self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_freq_sink_x_0_win)
        self.fft_vxx_0 = fft.fft_vcc(1024, True, (window.blackmanharris(1024)), True, 1)
        self.blocks_wavfile_source_0 = blocks.wavfile_source("/home/iocoder/school/networks/project/radio_waves/src/radio_waves.wav", True)
        self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_gr_complex*1, 1024)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, 1024)
        self.blocks_float_to_complex_0 = blocks.float_to_complex(1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_stream_to_vector_0, 0))    
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))    
        self.connect((self.blocks_vector_to_stream_0, 0), (self.qtgui_freq_sink_x_0, 0))    
        self.connect((self.blocks_wavfile_source_0, 0), (self.blocks_float_to_complex_0, 0))    
        self.connect((self.fft_vxx_0, 0), (self.blocks_vector_to_stream_0, 0))    
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="File Fft To Tcp")

        ##################################################
        # Variables
        ##################################################
        self.veclen = veclen = 8192
        self.test = test = 1420e6
        self.samp_rate = samp_rate = 1500000

        ##################################################
        # Blocks
        ##################################################
        self.xmlrpc_server_0 = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8080), allow_none=True)
        self.xmlrpc_server_0.register_instance(self)
        threading.Thread(target=self.xmlrpc_server_0.serve_forever).start()
        self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c(
        	self.GetWin(),
        	baseband_freq=1420e6,
        	dynamic_range=100,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=veclen,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="Waterfall Plot",
        )
        self.Add(self.wxgui_waterfallsink2_0.win)
        self.wxgui_fftsink2_1 = fftsink2.fft_sink_c(
        	self.GetWin(),
        	baseband_freq=test,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=veclen,
        	fft_rate=8,
        	average=False,
        	avg_alpha=None,
        	title="FFT Plot",
        	peak_hold=False,
        )
        self.Add(self.wxgui_fftsink2_1.win)
        self.fft_vxx_0 = fft.fft_vcc(veclen, True, (window.blackmanharris(veclen)), True, 1)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_stream_to_vector_1 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, samp_rate)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, veclen)
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_gr_complex*1, "/Users/bill/Desktop/radiotelescope/default.iqstream", True)
        self.blocks_complex_to_mag_0 = blocks.complex_to_mag(veclen)
        self.blks2_tcp_sink_0_0 = grc_blks2.tcp_sink(
        	itemsize=gr.sizeof_gr_complex*samp_rate,
        	addr="127.0.0.1",
        	port=10002,
        	server=True,
        )
        self.blks2_tcp_sink_0 = grc_blks2.tcp_sink(
        	itemsize=gr.sizeof_float*veclen,
        	addr="127.0.0.1",
        	port=10001,
        	server=True,
        )

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_complex_to_mag_0, 0), (self.blks2_tcp_sink_0, 0))    
        self.connect((self.blocks_file_source_0, 0), (self.blocks_throttle_0, 0))    
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))    
        self.connect((self.blocks_stream_to_vector_1, 0), (self.blks2_tcp_sink_0_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.blocks_stream_to_vector_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.blocks_stream_to_vector_1, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.wxgui_fftsink2_1, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.wxgui_waterfallsink2_0, 0))    
        self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_0, 0))    
    def __init__(self, lo_offset_freq=1e6, threshold_dB=-70, RF=2.49e9, DC_filter_num_elements=4, speed_samp_rate=1, samp_rate=1e6, highpass_cutoff_freq=0, lowpass_cutoff_freq=1700, fft_len=pow(2,20), samp_rate_sink=8000, angle=0, tx_amp=1, rx_gain=30.5):
        grc_wxgui.top_block_gui.__init__(self, title="CW Radar Single Target")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Parameters
        ##################################################
        self.lo_offset_freq = lo_offset_freq
        self.threshold_dB = threshold_dB
        self.RF = RF
        self.DC_filter_num_elements = DC_filter_num_elements
        self.speed_samp_rate = speed_samp_rate
        self.samp_rate = samp_rate
        self.highpass_cutoff_freq = highpass_cutoff_freq
        self.lowpass_cutoff_freq = lowpass_cutoff_freq
        self.fft_len = fft_len
        self.samp_rate_sink = samp_rate_sink
        self.angle = angle
        self.tx_amp = tx_amp
        self.rx_gain = rx_gain

        ##################################################
        # Variables
        ##################################################
        self.target_speed = target_speed = 0
        self.target_direction = target_direction = 0
        self.tx_amp_tuner = tx_amp_tuner = tx_amp
        self.threshold_dB_tuner = threshold_dB_tuner = threshold_dB
        self.speed_textbox = speed_textbox = target_speed
        self.rx_gain_tuner = rx_gain_tuner = rx_gain
        self.lowpass_cutoff_freq_tuner = lowpass_cutoff_freq_tuner = lowpass_cutoff_freq
        self.highpass_cutoff_freq_tuner = highpass_cutoff_freq_tuner = highpass_cutoff_freq
        self.direction_textbox = direction_textbox = target_direction
        self.angle_tuner = angle_tuner = angle
        self.RF_tuner = RF_tuner = RF

        ##################################################
        # Blocks
        ##################################################
        _tx_amp_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._tx_amp_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_tx_amp_tuner_sizer,
        	value=self.tx_amp_tuner,
        	callback=self.set_tx_amp_tuner,
        	label="TX Signal Amp",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._tx_amp_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_tx_amp_tuner_sizer,
        	value=self.tx_amp_tuner,
        	callback=self.set_tx_amp_tuner,
        	minimum=0,
        	maximum=1,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_tx_amp_tuner_sizer, 0, 17, 1, 26)
        _threshold_dB_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._threshold_dB_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_threshold_dB_tuner_sizer,
        	value=self.threshold_dB_tuner,
        	callback=self.set_threshold_dB_tuner,
        	label="Detected Target Threshold (dB)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._threshold_dB_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_threshold_dB_tuner_sizer,
        	value=self.threshold_dB_tuner,
        	callback=self.set_threshold_dB_tuner,
        	minimum=-90,
        	maximum=-30,
        	num_steps=60,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_threshold_dB_tuner_sizer, 2, 0, 1, 17)
        self.speed_probe = blocks.probe_signal_f()
        _rx_gain_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._rx_gain_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_rx_gain_tuner_sizer,
        	value=self.rx_gain_tuner,
        	callback=self.set_rx_gain_tuner,
        	label="USRP RX Gain (dB)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._rx_gain_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_rx_gain_tuner_sizer,
        	value=self.rx_gain_tuner,
        	callback=self.set_rx_gain_tuner,
        	minimum=0,
        	maximum=30.5 + 62,
        	num_steps=185,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_rx_gain_tuner_sizer, 0, 0, 1, 17)
        self.notebook = self.notebook = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "FFT CW Doppler Radar Receiver")
        self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "Frequency/Time CW Doppler Radar Receiver")
        self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "FFT CW Doppler Radar Receiver Full Spectrum")
        self.GridAdd(self.notebook, 5, 0, 13, 75)
        _lowpass_cutoff_freq_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._lowpass_cutoff_freq_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_lowpass_cutoff_freq_tuner_sizer,
        	value=self.lowpass_cutoff_freq_tuner,
        	callback=self.set_lowpass_cutoff_freq_tuner,
        	label="Lowpass Cutoff Frequency (Hz)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._lowpass_cutoff_freq_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_lowpass_cutoff_freq_tuner_sizer,
        	value=self.lowpass_cutoff_freq_tuner,
        	callback=self.set_lowpass_cutoff_freq_tuner,
        	minimum=0,
        	maximum=3000,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_lowpass_cutoff_freq_tuner_sizer, 1, 43, 1, 32)
        _highpass_cutoff_freq_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._highpass_cutoff_freq_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_highpass_cutoff_freq_tuner_sizer,
        	value=self.highpass_cutoff_freq_tuner,
        	callback=self.set_highpass_cutoff_freq_tuner,
        	label="High-Pass Cutoff Frequency (Hz)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._highpass_cutoff_freq_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_highpass_cutoff_freq_tuner_sizer,
        	value=self.highpass_cutoff_freq_tuner,
        	callback=self.set_highpass_cutoff_freq_tuner,
        	minimum=0,
        	maximum=1600,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_highpass_cutoff_freq_tuner_sizer, 0, 43, 1, 32)
        self.direction_probe = blocks.probe_signal_i()
        _angle_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._angle_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_angle_tuner_sizer,
        	value=self.angle_tuner,
        	callback=self.set_angle_tuner,
        	label="Angle of Approach of the Target (Deg)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._angle_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_angle_tuner_sizer,
        	value=self.angle_tuner,
        	callback=self.set_angle_tuner,
        	minimum=0,
        	maximum=89,
        	num_steps=890,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_angle_tuner_sizer, 1, 17, 1, 26)
        _RF_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._RF_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_RF_tuner_sizer,
        	value=self.RF_tuner,
        	callback=self.set_RF_tuner,
        	label="Radar Frequency (Hz)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._RF_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_RF_tuner_sizer,
        	value=self.RF_tuner,
        	callback=self.set_RF_tuner,
        	minimum=2.4e9,
        	maximum=2.5e9,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_RF_tuner_sizer, 1, 0, 1, 17)
        self.wxgui_waterfallsink = waterfallsink2.waterfall_sink_c(
        	self.notebook.GetPage(1).GetWin(),
        	baseband_freq=0,
        	dynamic_range=100,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate_sink,
        	fft_size=1024,
        	fft_rate=100,
        	average=False,
        	avg_alpha=None,
        	title="Time/Frequency CW Doppler Radar",
        	win=window.blackmanharris,
        )
        self.notebook.GetPage(1).Add(self.wxgui_waterfallsink.win)
        self.wxgui_fftsink2_full_spectrum = fftsink2.fft_sink_c(
        	self.notebook.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=4096,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="FFT CW Doppler Radar Receiver Full Spectrum",
        	peak_hold=False,
        	win=window.blackmanharris,
        )
        self.notebook.GetPage(2).Add(self.wxgui_fftsink2_full_spectrum.win)
        self.wxgui_fftsink = fftsink2.fft_sink_c(
        	self.notebook.GetPage(0).GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate_sink,
        	fft_size=1024,
        	fft_rate=100,
        	average=False,
        	avg_alpha=None,
        	title="FFT CW Doppler Radar Receiver ",
        	peak_hold=False,
        	win=window.blackmanharris,
        )
        self.notebook.GetPage(0).Add(self.wxgui_fftsink.win)
        self.usrp_transmitter = uhd.usrp_sink(
        	",".join(('addr=192.168.10.2', "")),
        	uhd.stream_args(
        		cpu_format="fc32",
        		channels=range(1),
        	),
        )
        self.usrp_transmitter.set_clock_source("internal", 0)
        self.usrp_transmitter.set_samp_rate(samp_rate)
        self.usrp_transmitter.set_center_freq(RF_tuner, 0)
        self.usrp_transmitter.set_gain(0, 0)
        self.usrp_transmitter.set_antenna('TX/RX', 0)
        self.usrp_receiver = uhd.usrp_source(
        	",".join(('addr=192.168.10.3', "")),
        	uhd.stream_args(
        		cpu_format="fc32",
        		channels=range(1),
        	),
        )
        self.usrp_receiver.set_clock_source("mimo", 0)
        self.usrp_receiver.set_time_source("mimo", 0)
        self.usrp_receiver.set_samp_rate(samp_rate)
        self.usrp_receiver.set_center_freq(uhd.tune_request(RF_tuner, lo_offset_freq), 0)
        self.usrp_receiver.set_gain(rx_gain_tuner, 0)
        self.usrp_receiver.set_antenna("J1", 0)
        self.usrp_receiver.set_bandwidth(15e6, 0)
        def _target_speed_probe():
            while True:
                val = self.speed_probe.level()
                try:
                    self.set_target_speed(val)
                except AttributeError:
                    pass
                time.sleep(1.0 / (2))
        _target_speed_thread = threading.Thread(target=_target_speed_probe)
        _target_speed_thread.daemon = True
        _target_speed_thread.start()
        def _target_direction_probe():
            while True:
                val = self.direction_probe.level()
                try:
                    self.set_target_direction(val)
                except AttributeError:
                    pass
                time.sleep(1.0 / (2))
        _target_direction_thread = threading.Thread(target=_target_direction_probe)
        _target_direction_thread.daemon = True
        _target_direction_thread.start()
        self._speed_textbox_text_box = forms.text_box(
        	parent=self.GetWin(),
        	value=self.speed_textbox,
        	callback=self.set_speed_textbox,
        	label="Target Speed (Kph)",
        	converter=forms.float_converter(),
        )
        self.GridAdd(self._speed_textbox_text_box, 3, 0, 1, 17)
        self.rational_resampler = filter.rational_resampler_ccc(
                interpolation=1,
                decimation=int(samp_rate/samp_rate_sink),
                taps=None,
                fractional_bw=None,
        )
        self.fft_vxx_0 = fft.fft_vcc(fft_len, True, (window.blackmanharris(fft_len)), True, 1)
        self._direction_textbox_text_box = forms.text_box(
        	parent=self.GetWin(),
        	value=self.direction_textbox,
        	callback=self.set_direction_textbox,
        	label="Target Direction",
        	converter=forms.str_converter(),
        )
        self.GridAdd(self._direction_textbox_text_box, 4, 0, 1, 17)
        self.cwradar_vector_flip_ff = cwradar.vector_flip_ff(fft_len/2)
        self.cwradar_doppler_velocity_single_target_ff_0 = cwradar.doppler_velocity_single_target_ff(fft_len/2, samp_rate, RF_tuner, threshold_dB_tuner, angle_tuner, lowpass_cutoff_freq_tuner, highpass_cutoff_freq_tuner)
        self.complex_to_mag = blocks.complex_to_mag(fft_len)
        self.blocks_vector_to_stream_0_0 = blocks.vector_to_stream(gr.sizeof_float*1, fft_len)
        self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_float*1, fft_len)
        self.blocks_stream_to_vector_1_0 = blocks.stream_to_vector(gr.sizeof_float*1, fft_len/2)
        self.blocks_stream_to_vector_1 = blocks.stream_to_vector(gr.sizeof_float*1, fft_len/2)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_len)
        self.blocks_keep_m_in_n_0_0 = blocks.keep_m_in_n(gr.sizeof_float, fft_len/2, fft_len, fft_len/2)
        self.blocks_keep_m_in_n_0 = blocks.keep_m_in_n(gr.sizeof_float, fft_len/2, fft_len, 0)
        self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 0, tx_amp_tuner, 0)
        self.DC_filter_0 = blocks.multiply_const_vff(([0]*DC_filter_num_elements+[1]*((fft_len/2)-DC_filter_num_elements)))
        self.DC_filter = blocks.multiply_const_vff(([0]*DC_filter_num_elements+[1]*((fft_len/2)-DC_filter_num_elements)))

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_vector_to_stream_0_0, 0), (self.blocks_keep_m_in_n_0_0, 0))
        self.connect((self.blocks_keep_m_in_n_0, 0), (self.blocks_stream_to_vector_1, 0))
        self.connect((self.blocks_keep_m_in_n_0_0, 0), (self.blocks_stream_to_vector_1_0, 0))
        self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_keep_m_in_n_0, 0))
        self.connect((self.blocks_stream_to_vector_1_0, 0), (self.DC_filter_0, 0))
        self.connect((self.blocks_stream_to_vector_1, 0), (self.cwradar_vector_flip_ff, 0))
        self.connect((self.cwradar_vector_flip_ff, 0), (self.DC_filter, 0))
        self.connect((self.rational_resampler, 0), (self.wxgui_waterfallsink, 0))
        self.connect((self.rational_resampler, 0), (self.wxgui_fftsink, 0))
        self.connect((self.fft_vxx_0, 0), (self.complex_to_mag, 0))
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))
        self.connect((self.complex_to_mag, 0), (self.blocks_vector_to_stream_0, 0))
        self.connect((self.complex_to_mag, 0), (self.blocks_vector_to_stream_0_0, 0))
        self.connect((self.DC_filter_0, 0), (self.cwradar_doppler_velocity_single_target_ff_0, 1))
        self.connect((self.DC_filter, 0), (self.cwradar_doppler_velocity_single_target_ff_0, 0))
        self.connect((self.cwradar_doppler_velocity_single_target_ff_0, 0), (self.speed_probe, 0))
        self.connect((self.cwradar_doppler_velocity_single_target_ff_0, 1), (self.direction_probe, 0))
        self.connect((self.usrp_receiver, 0), (self.wxgui_fftsink2_full_spectrum, 0))
        self.connect((self.usrp_receiver, 0), (self.rational_resampler, 0))
        self.connect((self.usrp_receiver, 0), (self.blocks_stream_to_vector_0, 0))
        self.connect((self.analog_sig_source_x_0, 0), (self.usrp_transmitter, 0))
Example #25
0
    def __init__(self, c_freq, int_time, samp_rate, fftsize, username, config):
        gr.top_block.__init__(self, "Salsa Receiver")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate
        self.outfile = outfile = config.get("USRP", "tmpdir") + "/SALSA_" + username + ".tmp"  # Not used
        self.int_time = int_time
        self.gain = gain = config.getfloat("USRP", "usrp_gain")
        self.fftsize = fftsize
        self.c_freq = c_freq
        self.probe_var = probe_var = 0

        # Integrate 10 FFTS using IIR block and keep 1 in N, increase for higher bandwidths to lower processing times.
        self.alpha = 0.1
        self.N = 10

        ##################################################
        # Blocks
        ##################################################
        self.uhd_usrp_source_0 = uhd.usrp_source(
            device_addr="addr=" + config.get("USRP", "host"),
            stream_args=uhd.stream_args(
                cpu_format="fc32",
                channels=range(1),
                # recv_frame_size=4096, #Problems with overflow at bw>5 MHz, this might be a solution (depends on ethernet connection capabilities)
                # recv_buff_size=4096,
            ),
        )
        self.uhd_usrp_source_0.set_samp_rate(samp_rate)
        self.uhd_usrp_source_0.set_center_freq(c_freq, 0)
        self.uhd_usrp_source_0.set_gain(gain, 0)

        self.fft_vxx_0 = fft.fft_vcc(fftsize, True, (window.blackmanharris(fftsize)), True, 1)
        self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_float * 1, fftsize)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex * 1, fftsize)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(fftsize)
        self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff(self.alpha, fftsize)
        self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n(gr.sizeof_float * fftsize, self.N)

        # Signal and reference file sinks
        self.signal_file_sink_1 = blocks.file_sink(gr.sizeof_float * 1, self.outfile, False)
        self.signal_file_sink_1.set_unbuffered(False)
        self.signal_file_sink_2 = blocks.file_sink(gr.sizeof_float * 1, self.outfile, False)
        self.signal_file_sink_2.set_unbuffered(False)
        self.blocks_null_sink = blocks.null_sink(gr.sizeof_float * 1)
        # Selector for switch
        self.blks2_selector_0 = grc_blks2.selector(
            item_size=gr.sizeof_float * 1,
            num_inputs=1,
            num_outputs=2 + 1,  # +1 for the null sink
            input_index=0,
            output_index=0,
        )

        ##################################################
        # Connections
        ##################################################
        self.connect((self.uhd_usrp_source_0, 0), (self.blocks_stream_to_vector_0, 0))
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))
        self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0))
        self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.single_pole_iir_filter_xx_0, 0))
        self.connect((self.single_pole_iir_filter_xx_0, 0), (self.blocks_keep_one_in_n_0, 0))
        self.connect((self.blocks_keep_one_in_n_0, 0), (self.blocks_vector_to_stream_0, 0))
        self.connect((self.blocks_vector_to_stream_0, 0), (self.blks2_selector_0, 0))

        # Selector connections
        self.connect((self.blks2_selector_0, 1), (self.signal_file_sink_1, 0))
        self.connect((self.blks2_selector_0, 2), (self.signal_file_sink_2, 0))

        # Null sink connection
        self.connect((self.blks2_selector_0, 0), (self.blocks_null_sink, 0))
    def __init__(self):
        gr.top_block.__init__(self, "Msod Sslsensor Hackrf")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Msod Sslsensor Hackrf")
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        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)

        self.settings = Qt.QSettings("GNU Radio", "MSOD_SSLSensor_HackRF")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 10e6
        self.fft_size = fft_size = 1000
        self.num_ch = num_ch = 50
        self.mywindow = mywindow = window.blackmanharris(fft_size)
        self.hz_per_bin = hz_per_bin = samp_rate / fft_size
        self.bandwidth = bandwidth = 9e6
        self.window_power = window_power = sum(map(lambda x: x*x, mywindow))
        self.meas_interval = meas_interval = 1e-3
        self.impedance = impedance = 50.0
        self.channel_bw = channel_bw = hz_per_bin * round(bandwidth / num_ch / hz_per_bin)
        self.rx_gain = rx_gain = 0
        self.meas_period = meas_period = max(1, int(round(meas_interval * samp_rate / fft_size)))
        self.dest_host = dest_host = "pwct5.ctl.nist.gov"
        self.center_freq = center_freq = 724e6
        self.Vsq2W_dB = Vsq2W_dB = -10.0 * math.log10(fft_size * int(window_power) * impedance)
        self.ActualBW = ActualBW = channel_bw * num_ch

        ##################################################
        # Blocks
        ##################################################
        self._samp_rate_options = (10e6, 15.36e6, 7.68e6, 3.84e6, 1.92e6, )
        self._samp_rate_labels = ("10e6", "15.36e6", "7.68e6", "3.84e6", "1.92e6", )
        self._samp_rate_group_box = Qt.QGroupBox("samp_rate")
        self._samp_rate_box = Qt.QVBoxLayout()
        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)
            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)
        self._samp_rate_button_group = variable_chooser_button_group()
        self._samp_rate_group_box.setLayout(self._samp_rate_box)
        for i, label in enumerate(self._samp_rate_labels):
        	radio_button = Qt.QRadioButton(label)
        	self._samp_rate_box.addWidget(radio_button)
        	self._samp_rate_button_group.addButton(radio_button, i)
        self._samp_rate_callback = lambda i: Qt.QMetaObject.invokeMethod(self._samp_rate_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._samp_rate_options.index(i)))
        self._samp_rate_callback(self.samp_rate)
        self._samp_rate_button_group.buttonClicked[int].connect(
        	lambda i: self.set_samp_rate(self._samp_rate_options[i]))
        self.top_layout.addWidget(self._samp_rate_group_box)
        self._num_ch_options = (56, 50, 25, 15, 8, )
        self._num_ch_labels = ("56", "50", "25", "15", "8", )
        self._num_ch_group_box = Qt.QGroupBox("num_ch")
        self._num_ch_box = Qt.QVBoxLayout()
        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)
            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)
        self._num_ch_button_group = variable_chooser_button_group()
        self._num_ch_group_box.setLayout(self._num_ch_box)
        for i, label in enumerate(self._num_ch_labels):
        	radio_button = Qt.QRadioButton(label)
        	self._num_ch_box.addWidget(radio_button)
        	self._num_ch_button_group.addButton(radio_button, i)
        self._num_ch_callback = lambda i: Qt.QMetaObject.invokeMethod(self._num_ch_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._num_ch_options.index(i)))
        self._num_ch_callback(self.num_ch)
        self._num_ch_button_group.buttonClicked[int].connect(
        	lambda i: self.set_num_ch(self._num_ch_options[i]))
        self.top_layout.addWidget(self._num_ch_group_box)
        self._fft_size_options = (1000, 1024, 512, 256, 128, )
        self._fft_size_labels = ("1000", "1024", "512", "256", "128", )
        self._fft_size_tool_bar = Qt.QToolBar(self)
        self._fft_size_tool_bar.addWidget(Qt.QLabel("fft_size"+": "))
        self._fft_size_combo_box = Qt.QComboBox()
        self._fft_size_tool_bar.addWidget(self._fft_size_combo_box)
        for label in self._fft_size_labels: self._fft_size_combo_box.addItem(label)
        self._fft_size_callback = lambda i: Qt.QMetaObject.invokeMethod(self._fft_size_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._fft_size_options.index(i)))
        self._fft_size_callback(self.fft_size)
        self._fft_size_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_fft_size(self._fft_size_options[i]))
        self.top_layout.addWidget(self._fft_size_tool_bar)
        self._dest_host_options = ("pwct1.ctl.nist.gov", "129.6.230.12", "pwc8.ctl.nist.gov", "pwct5.ctl.nist.gov", )
        self._dest_host_labels = ("pwct1", "Naceur Laptop", "pwct5Desktop", "Pwct5", )
        self._dest_host_tool_bar = Qt.QToolBar(self)
        self._dest_host_tool_bar.addWidget(Qt.QLabel(dest_host+": "))
        self._dest_host_combo_box = Qt.QComboBox()
        self._dest_host_tool_bar.addWidget(self._dest_host_combo_box)
        for label in self._dest_host_labels: self._dest_host_combo_box.addItem(label)
        self._dest_host_callback = lambda i: Qt.QMetaObject.invokeMethod(self._dest_host_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._dest_host_options.index(i)))
        self._dest_host_callback(self.dest_host)
        self._dest_host_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_dest_host(self._dest_host_options[i]))
        self.top_layout.addWidget(self._dest_host_tool_bar)
        self._center_freq_options = (709.01e6, 782e6, 724e6, 729e6, )
        self._center_freq_labels = ("AT&T", "Verizon", "ChannelEmulator", "HackRF Shifted Freq", )
        self._center_freq_tool_bar = Qt.QToolBar(self)
        self._center_freq_tool_bar.addWidget(Qt.QLabel("center_freq"+": "))
        self._center_freq_combo_box = Qt.QComboBox()
        self._center_freq_tool_bar.addWidget(self._center_freq_combo_box)
        for label in self._center_freq_labels: self._center_freq_combo_box.addItem(label)
        self._center_freq_callback = lambda i: Qt.QMetaObject.invokeMethod(self._center_freq_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._center_freq_options.index(i)))
        self._center_freq_callback(self.center_freq)
        self._center_freq_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_center_freq(self._center_freq_options[i]))
        self.top_layout.addWidget(self._center_freq_tool_bar)
        self._rx_gain_range = Range(0, 31.5, 0.5, 0, 200)
        self._rx_gain_win = RangeWidget(self._rx_gain_range, self.set_rx_gain, "rx_gain", "counter_slider", float)
        self.top_layout.addWidget(self._rx_gain_win)
        self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "hackrf=0" )
        self.osmosdr_source_0.set_sample_rate(samp_rate)
        self.osmosdr_source_0.set_center_freq(center_freq, 0)
        self.osmosdr_source_0.set_freq_corr(0, 0)
        self.osmosdr_source_0.set_dc_offset_mode(1, 0)
        self.osmosdr_source_0.set_iq_balance_mode(2, 0)
        self.osmosdr_source_0.set_gain_mode(True, 0)
        self.osmosdr_source_0.set_gain(0, 0)
        self.osmosdr_source_0.set_if_gain(32, 0)
        self.osmosdr_source_0.set_bb_gain(40, 0)
        self.osmosdr_source_0.set_antenna("", 0)
        self.osmosdr_source_0.set_bandwidth(20e6, 0)
          
        self.msod_sensor_sslsocket_sink_0 = msod_sensor.sslsocket_sink(num_ch, dest_host, "/raid/nae/pybombs/src/gr-msod_latency/examples/sensor_HackRF.loc", "/raid/nae/pybombs/src/gr-msod_latency/examples/sensor_HackRF.sys", "HackRF", "NaN", center_freq, ActualBW, meas_interval, 0, samp_rate, False)
        self.msod_sensor_bin_statistics_0 = msod_sensor.bin_statistics(num_ch, meas_period)
        self.msod_sensor_bin_aggregator_0 = msod_sensor.bin_aggregator(fft_size, num_ch, samp_rate, fft_size, center_freq, ActualBW, channel_bw, [0] * fft_size, False)
        self.fft_vxx_0 = fft.fft_vcc(fft_size, True, (mywindow), True, 1)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_size)
        self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, num_ch, 30.0 + Vsq2W_dB)
        self.blocks_float_to_char_0 = blocks.float_to_char(num_ch, 1.0)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(fft_size)
        self._bandwidth_options = (10.08e6, 9e6, 4.5e6, 2.7e6, 1.08e6, )
        self._bandwidth_labels = ("10.08e6", "9e6", "4.5e6", "2.7e6", "1.08e6", )
        self._bandwidth_tool_bar = Qt.QToolBar(self)
        self._bandwidth_tool_bar.addWidget(Qt.QLabel("bandwidth"+": "))
        self._bandwidth_combo_box = Qt.QComboBox()
        self._bandwidth_tool_bar.addWidget(self._bandwidth_combo_box)
        for label in self._bandwidth_labels: self._bandwidth_combo_box.addItem(label)
        self._bandwidth_callback = lambda i: Qt.QMetaObject.invokeMethod(self._bandwidth_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._bandwidth_options.index(i)))
        self._bandwidth_callback(self.bandwidth)
        self._bandwidth_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_bandwidth(self._bandwidth_options[i]))
        self.top_layout.addWidget(self._bandwidth_tool_bar)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.msod_sensor_bin_aggregator_0, 0))    
        self.connect((self.blocks_float_to_char_0, 0), (self.msod_sensor_sslsocket_sink_0, 0))    
        self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_float_to_char_0, 0))    
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))    
        self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0))    
        self.connect((self.msod_sensor_bin_aggregator_0, 0), (self.msod_sensor_bin_statistics_0, 0))    
        self.connect((self.msod_sensor_bin_statistics_0, 0), (self.blocks_nlog10_ff_0, 0))    
        self.connect((self.osmosdr_source_0, 0), (self.blocks_stream_to_vector_0, 0))    
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")

        ##################################################
        # Variables
        ##################################################
        self.threshold = threshold = -70
        self.samp_rate = samp_rate = 2048000
        self.freq = freq = 525200000
        self.fft_size = fft_size = 1024

        ##################################################
        # Blocks
        ##################################################
        _threshold_sizer = wx.BoxSizer(wx.VERTICAL)
        self._threshold_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_threshold_sizer,
        	value=self.threshold,
        	callback=self.set_threshold,
        	label="Threshold",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._threshold_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_threshold_sizer,
        	value=self.threshold,
        	callback=self.set_threshold,
        	minimum=-100,
        	maximum=0,
        	num_steps=100,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.Add(_threshold_sizer)
        _freq_sizer = wx.BoxSizer(wx.VERTICAL)
        self._freq_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_freq_sizer,
        	value=self.freq,
        	callback=self.set_freq,
        	label="freq",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._freq_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_freq_sizer,
        	value=self.freq,
        	callback=self.set_freq,
        	minimum=478000000,
        	maximum=862000000,
        	num_steps=100,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.Add(_freq_sizer)
        self.wxgui_numbersink2_1 = numbersink2.number_sink_f(
        	self.GetWin(),
        	unit="signal present",
        	minval=0,
        	maxval=1,
        	factor=1.0,
        	decimal_places=0,
        	ref_level=0,
        	sample_rate=samp_rate,
        	number_rate=15,
        	average=False,
        	avg_alpha=None,
        	label="Signal Detection",
        	peak_hold=False,
        	show_gauge=True,
        )
        self.Add(self.wxgui_numbersink2_1.win)
        self.wxgui_numbersink2_0 = numbersink2.number_sink_f(
        	self.GetWin(),
        	unit="dB",
        	minval=-120,
        	maxval=0,
        	factor=1.0,
        	decimal_places=0,
        	ref_level=0,
        	sample_rate=samp_rate,
        	number_rate=15,
        	average=True,
        	avg_alpha=0.030,
        	label="Level",
        	peak_hold=False,
        	show_gauge=True,
        )
        self.Add(self.wxgui_numbersink2_0.win)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
        	self.GetWin(),
        	baseband_freq=freq,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=fft_size,
        	fft_rate=15,
        	average=True,
        	avg_alpha=0.03,
        	title="Spectrum",
        	peak_hold=False,
        	win=window.rectangular,
        )
        self.Add(self.wxgui_fftsink2_0.win)
        self.rtlsdr_source_1 = osmosdr.source( args="numchan=" + str(1) + " " + "" )
        self.rtlsdr_source_1.set_sample_rate(samp_rate)
        self.rtlsdr_source_1.set_center_freq(freq, 0)
        self.rtlsdr_source_1.set_freq_corr(0, 0)
        self.rtlsdr_source_1.set_dc_offset_mode(0, 0)
        self.rtlsdr_source_1.set_iq_balance_mode(0, 0)
        self.rtlsdr_source_1.set_gain_mode(False, 0)
        self.rtlsdr_source_1.set_gain(20, 0)
        self.rtlsdr_source_1.set_if_gain(10, 0)
        self.rtlsdr_source_1.set_bb_gain(5, 0)
        self.rtlsdr_source_1.set_antenna("", 0)
        self.rtlsdr_source_1.set_bandwidth(1, 0)
          
        self.notebook = self.notebook = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "spectrum")
        self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "output")
        self.Add(self.notebook)
        self.fft_vxx_0 = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), True, 1)
        self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_float*1, fft_size)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_threshold_ff_0 = blocks.threshold_ff(-100, threshold, threshold)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_size)
        self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, 1, 0)
        self.blocks_divide_xx_0 = blocks.divide_ff(1)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(fft_size)
        self.analog_const_source_x_0 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, fft_size*fft_size)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_const_source_x_0, 0), (self.blocks_divide_xx_0, 1))    
        self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_vector_to_stream_0, 0))    
        self.connect((self.blocks_divide_xx_0, 0), (self.blocks_nlog10_ff_0, 0))    
        self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_threshold_ff_0, 0))    
        self.connect((self.blocks_nlog10_ff_0, 0), (self.wxgui_numbersink2_0, 0))    
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))    
        self.connect((self.blocks_threshold_ff_0, 0), (self.wxgui_numbersink2_1, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.blocks_stream_to_vector_0, 0))    
        self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_divide_xx_0, 0))    
        self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0))    
        self.connect((self.rtlsdr_source_1, 0), (self.blocks_throttle_0, 0))    
        self.connect((self.rtlsdr_source_1, 0), (self.wxgui_fftsink2_0, 0))    
    def __init__(self):
        gr.top_block.__init__(self, "Msod Sslsensor N210")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Msod Sslsensor N210")
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        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)

        self.settings = Qt.QSettings("GNU Radio", "MSOD_SSLSensor_N210")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 12.5e6
        self.fft_size = fft_size = 625
        self.num_ch = num_ch = 56
        self.mywindow = mywindow = window.blackmanharris(fft_size)
        self.hz_per_bin = hz_per_bin = samp_rate / fft_size
        self.bandwidth = bandwidth = 10.08e6
        self.window_power = window_power = sum(map(lambda x: x*x, mywindow))
        self.meas_interval = meas_interval = 1e-3
        self.impedance = impedance = 50.0
        self.channel_bw = channel_bw = hz_per_bin * round(bandwidth / num_ch / hz_per_bin)
        self.device3 = variable_uhd_device3_0 = ettus.device3(uhd.device_addr_t( ",".join(('type=x300, addr=usrp02', "")) ))
        self.rx_gain = rx_gain = 0
        self.meas_period = meas_period = max(1, int(round(meas_interval * samp_rate / fft_size)))
        self.dest_host = dest_host = "129.6.142.103"
        self.center_freq = center_freq = 724e6
        self.Vsq2W_dB = Vsq2W_dB = -10.0 * math.log10(fft_size * int(window_power) * impedance)
        self.ActualBW = ActualBW = channel_bw * num_ch

        ##################################################
        # Blocks
        ##################################################
        self._samp_rate_options = (12.5e6, 15.36e6, 7.68e6, 3.84e6, 1.92e6, )
        self._samp_rate_labels = ('12.5e6', '15.36e6', '7.68e6', '3.84e6', '1.92e6', )
        self._samp_rate_group_box = Qt.QGroupBox('samp_rate')
        self._samp_rate_box = Qt.QVBoxLayout()
        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)
            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)
        self._samp_rate_button_group = variable_chooser_button_group()
        self._samp_rate_group_box.setLayout(self._samp_rate_box)
        for i, label in enumerate(self._samp_rate_labels):
        	radio_button = Qt.QRadioButton(label)
        	self._samp_rate_box.addWidget(radio_button)
        	self._samp_rate_button_group.addButton(radio_button, i)
        self._samp_rate_callback = lambda i: Qt.QMetaObject.invokeMethod(self._samp_rate_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._samp_rate_options.index(i)))
        self._samp_rate_callback(self.samp_rate)
        self._samp_rate_button_group.buttonClicked[int].connect(
        	lambda i: self.set_samp_rate(self._samp_rate_options[i]))
        self.top_layout.addWidget(self._samp_rate_group_box)
        self._rx_gain_range = Range(0, 31.5, 0.5, 0, 200)
        self._rx_gain_win = RangeWidget(self._rx_gain_range, self.set_rx_gain, 'rx_gain', "counter_slider", float)
        self.top_layout.addWidget(self._rx_gain_win)
        self._num_ch_options = (56, 50, 25, 15, 8, )
        self._num_ch_labels = ('56', '50', '25', '15', '8', )
        self._num_ch_group_box = Qt.QGroupBox('num_ch')
        self._num_ch_box = Qt.QVBoxLayout()
        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)
            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)
        self._num_ch_button_group = variable_chooser_button_group()
        self._num_ch_group_box.setLayout(self._num_ch_box)
        for i, label in enumerate(self._num_ch_labels):
        	radio_button = Qt.QRadioButton(label)
        	self._num_ch_box.addWidget(radio_button)
        	self._num_ch_button_group.addButton(radio_button, i)
        self._num_ch_callback = lambda i: Qt.QMetaObject.invokeMethod(self._num_ch_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._num_ch_options.index(i)))
        self._num_ch_callback(self.num_ch)
        self._num_ch_button_group.buttonClicked[int].connect(
        	lambda i: self.set_num_ch(self._num_ch_options[i]))
        self.top_layout.addWidget(self._num_ch_group_box)
        self._fft_size_options = (625, 1024, 512, 256, 128, )
        self._fft_size_labels = ('625', '1024', '512', '256', '128', )
        self._fft_size_tool_bar = Qt.QToolBar(self)
        self._fft_size_tool_bar.addWidget(Qt.QLabel('fft_size'+": "))
        self._fft_size_combo_box = Qt.QComboBox()
        self._fft_size_tool_bar.addWidget(self._fft_size_combo_box)
        for label in self._fft_size_labels: self._fft_size_combo_box.addItem(label)
        self._fft_size_callback = lambda i: Qt.QMetaObject.invokeMethod(self._fft_size_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._fft_size_options.index(i)))
        self._fft_size_callback(self.fft_size)
        self._fft_size_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_fft_size(self._fft_size_options[i]))
        self.top_layout.addWidget(self._fft_size_tool_bar)
        self._center_freq_options = (709.01e6, 782e6, 724e6, )
        self._center_freq_labels = ('AT&T', 'Verizon', 'ChannelEmulator', )
        self._center_freq_tool_bar = Qt.QToolBar(self)
        self._center_freq_tool_bar.addWidget(Qt.QLabel('center_freq'+": "))
        self._center_freq_combo_box = Qt.QComboBox()
        self._center_freq_tool_bar.addWidget(self._center_freq_combo_box)
        for label in self._center_freq_labels: self._center_freq_combo_box.addItem(label)
        self._center_freq_callback = lambda i: Qt.QMetaObject.invokeMethod(self._center_freq_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._center_freq_options.index(i)))
        self._center_freq_callback(self.center_freq)
        self._center_freq_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_center_freq(self._center_freq_options[i]))
        self.top_layout.addWidget(self._center_freq_tool_bar)
        self._bandwidth_options = (10.08e6, 9e6, 4.5e6, 2.7e6, 1.08e6, )
        self._bandwidth_labels = ('10.08e6', '9e6', '4.5e6', '2.7e6', '1.08e6', )
        self._bandwidth_tool_bar = Qt.QToolBar(self)
        self._bandwidth_tool_bar.addWidget(Qt.QLabel('bandwidth'+": "))
        self._bandwidth_combo_box = Qt.QComboBox()
        self._bandwidth_tool_bar.addWidget(self._bandwidth_combo_box)
        for label in self._bandwidth_labels: self._bandwidth_combo_box.addItem(label)
        self._bandwidth_callback = lambda i: Qt.QMetaObject.invokeMethod(self._bandwidth_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._bandwidth_options.index(i)))
        self._bandwidth_callback(self.bandwidth)
        self._bandwidth_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_bandwidth(self._bandwidth_options[i]))
        self.top_layout.addWidget(self._bandwidth_tool_bar)
        self.uhd_rfnoc_streamer_radio_0 = ettus.rfnoc_radio(
            self.device3,
            uhd.stream_args( # Tx Stream Args
                cpu_format="fc32",
                otw_format="sc16",
                args="", # empty
            ),
            uhd.stream_args( # Rx Stream Args
                cpu_format="fc32",
                otw_format="sc16",
        	args='',
            ),
            1, -1
        )
        self.uhd_rfnoc_streamer_radio_0.set_rate(samp_rate)
        for i in xrange(1):
            self.uhd_rfnoc_streamer_radio_0.set_rx_freq(center_freq, i)
            self.uhd_rfnoc_streamer_radio_0.set_rx_gain(rx_gain, i)
            self.uhd_rfnoc_streamer_radio_0.set_rx_antenna("RX2", i)
            self.uhd_rfnoc_streamer_radio_0.set_rx_dc_offset(True, i)
        self.spectrum_latency_jsonfile_sink_0 = spectrum_latency.jsonfile_sink(num_ch, "/home/nae/Spectrum-Sensors/N210/Capture.N210/10-25-2016", "/raid/nae/gnuradio/src/gr-spectrum_latency/examples/utils/sensor.loc", "/raid/nae/gnuradio/src/gr-spectrum_latency/examples/utils/sensor.sys", "F37258", "12345", center_freq, bandwidth, meas_interval, 0, samp_rate, False)
        self.spectrum_latency_bin_statistics_0 = spectrum_latency.bin_statistics(num_ch, meas_period)
        self.spectrum_latency_bin_aggregator_0 = spectrum_latency.bin_aggregator(fft_size, num_ch, samp_rate, fft_size, center_freq, ActualBW, channel_bw, [0] * fft_size)
        self.fft_vxx_0 = fft.fft_vcc(fft_size, True, (mywindow), True, 1)
        self._dest_host_options = ("pwct1.ctl.nist.gov", "129.6.142.103", "129.6.142.181", "pwct5.ctl.nist.gov", )
        self._dest_host_labels = ('pwct1', 'NEO_VM', 'pwct5Desktop', 'Pwct5', )
        self._dest_host_tool_bar = Qt.QToolBar(self)
        self._dest_host_tool_bar.addWidget(Qt.QLabel(dest_host+": "))
        self._dest_host_combo_box = Qt.QComboBox()
        self._dest_host_tool_bar.addWidget(self._dest_host_combo_box)
        for label in self._dest_host_labels: self._dest_host_combo_box.addItem(label)
        self._dest_host_callback = lambda i: Qt.QMetaObject.invokeMethod(self._dest_host_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._dest_host_options.index(i)))
        self._dest_host_callback(self.dest_host)
        self._dest_host_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_dest_host(self._dest_host_options[i]))
        self.top_layout.addWidget(self._dest_host_tool_bar)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_size)
        self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, num_ch, 30.0 + Vsq2W_dB)
        self.blocks_float_to_char_0 = blocks.float_to_char(num_ch, 1.0)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(fft_size)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.spectrum_latency_bin_aggregator_0, 0))    
        self.connect((self.blocks_float_to_char_0, 0), (self.spectrum_latency_jsonfile_sink_0, 0))    
        self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_float_to_char_0, 0))    
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))    
        self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0))    
        self.connect((self.spectrum_latency_bin_aggregator_0, 0), (self.spectrum_latency_bin_statistics_0, 0))    
        self.connect((self.spectrum_latency_bin_statistics_0, 0), (self.blocks_nlog10_ff_0, 0))    
        self.connect((self.uhd_rfnoc_streamer_radio_0, 0), (self.blocks_stream_to_vector_0, 0))    
    def __init__(self):
        gr.top_block.__init__(self, "SIMONES_Occupation")
        
        ##################################################
        # Variables
        ##################################################
        self.fft_size = fft_size = 1024
        self.samp_rate = samp_rate = 20e6
        self.fft_window = fft_window = window.blackmanharris(fft_size)
        self.power = power = sum(x*x for x in fft_window)
        self.center_freq = center_freq = 98e6
        self.bandwidth = bandwidth = samp_rate
        self.stop_freq = stop_freq = center_freq+(bandwidth/2)
        self.start_freq = start_freq = center_freq-(bandwidth/2)
        self.simon_port = simon_port = 65123
        self.simon_ip = simon_ip = '127.0.0.1'
        self.server_port = server_port = 65234
        self.server_ip = server_ip = '127.0.0.1'
        self.n = n = max(1, int(samp_rate/fft_size/15L))
        self.k = k = -20*math.log10(fft_size)-10*math.log10(power/fft_size)-20*math.log10(2.0/2)
        self.device = device = 'bladerf,fpga=/home/i2t/Software/source/bladeRF/pre-built/hostedx115.rbf,xb200=auto'
        self.canalization = canalization = 1e6

        ##################################################
        # Blocks
        ##################################################
        self.xmlrpc_server_0 = SimpleXMLRPCServer.SimpleXMLRPCServer((simon_ip, simon_port), allow_none=True)
        self.xmlrpc_server_0.register_instance(self)
        threading.Thread(target=self.xmlrpc_server_0.serve_forever).start()
        self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff(1.0, fft_size)
        self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + device )
        self.osmosdr_source_0.set_sample_rate(samp_rate)
        self.osmosdr_source_0.set_center_freq(center_freq, 0)
        self.osmosdr_source_0.set_freq_corr(0, 0)
        self.osmosdr_source_0.set_dc_offset_mode(0, 0)
        self.osmosdr_source_0.set_iq_balance_mode(0, 0)
        self.osmosdr_source_0.set_gain_mode(False, 0)
        self.osmosdr_source_0.set_gain(10, 0)
        self.osmosdr_source_0.set_if_gain(20, 0)
        self.osmosdr_source_0.set_bb_gain(20, 0)
        self.osmosdr_source_0.set_antenna("", 0)
        self.osmosdr_source_0.set_bandwidth(bandwidth, 0)
          
        self.fft_vxx_0 = fft.fft_vcc(fft_size, True, (fft_window), True, 1)
        self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_float*1, fft_size)
        self.blocks_udp_sink_0 = blocks.udp_sink(gr.sizeof_float*1, server_ip, server_port, 1472, True)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_size)
        self.blocks_nlog10_ff_0 = blocks.nlog10_ff(20, fft_size, k)
        self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n(gr.sizeof_gr_complex*fft_size, n)
        self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1024)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_keep_one_in_n_0, 0), (self.fft_vxx_0, 0))
        self.connect((self.blocks_stream_to_vector_0, 0), (self.blocks_keep_one_in_n_0, 0))
        self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.blocks_stream_to_vector_0, 0))
        self.connect((self.osmosdr_source_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.blocks_nlog10_ff_0, 0), (self.blocks_vector_to_stream_0, 0))
        self.connect((self.blocks_complex_to_mag_0, 0), (self.single_pole_iir_filter_xx_0, 0))
        self.connect((self.single_pole_iir_filter_xx_0, 0), (self.blocks_nlog10_ff_0, 0))
        self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_udp_sink_0, 0))
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Pager 6Ch Decode")
        _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 = 2000000
        self.xlate_decimation = xlate_decimation = 40
        self.hunter_freq_5 = hunter_freq_5 = 0
        self.hunter_freq_4 = hunter_freq_4 = 0
        self.hunter_freq_3 = hunter_freq_3 = 0
        self.hunter_freq_2 = hunter_freq_2 = 0
        self.hunter_freq_1 = hunter_freq_1 = 0
        self.hunter_freq_0 = hunter_freq_0 = 0
        self.gain = gain = 10
        self.frequency = frequency = 929000000
        self.filter_width = filter_width = 5120
        self.fft_taps = fft_taps = filter.firdes.low_pass_2(1, samp_rate, 2000, 1000, 0.1)
        self.fft_n_elements = fft_n_elements = 2048

        ##################################################
        # Blocks
        ##################################################
        _hunter_freq_5_sizer = wx.BoxSizer(wx.VERTICAL)
        self._hunter_freq_5_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_hunter_freq_5_sizer,
        	value=self.hunter_freq_5,
        	callback=self.set_hunter_freq_5,
        	label='hunter_freq_5',
        	converter=forms.int_converter(),
        	proportion=0,
        )
        self._hunter_freq_5_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_hunter_freq_5_sizer,
        	value=self.hunter_freq_5,
        	callback=self.set_hunter_freq_5,
        	minimum=-1000000,
        	maximum=1000000,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=int,
        	proportion=1,
        )
        self.Add(_hunter_freq_5_sizer)
        _hunter_freq_4_sizer = wx.BoxSizer(wx.VERTICAL)
        self._hunter_freq_4_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_hunter_freq_4_sizer,
        	value=self.hunter_freq_4,
        	callback=self.set_hunter_freq_4,
        	label='hunter_freq_4',
        	converter=forms.int_converter(),
        	proportion=0,
        )
        self._hunter_freq_4_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_hunter_freq_4_sizer,
        	value=self.hunter_freq_4,
        	callback=self.set_hunter_freq_4,
        	minimum=-1000000,
        	maximum=1000000,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=int,
        	proportion=1,
        )
        self.Add(_hunter_freq_4_sizer)
        _hunter_freq_3_sizer = wx.BoxSizer(wx.VERTICAL)
        self._hunter_freq_3_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_hunter_freq_3_sizer,
        	value=self.hunter_freq_3,
        	callback=self.set_hunter_freq_3,
        	label='hunter_freq_3',
        	converter=forms.int_converter(),
        	proportion=0,
        )
        self._hunter_freq_3_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_hunter_freq_3_sizer,
        	value=self.hunter_freq_3,
        	callback=self.set_hunter_freq_3,
        	minimum=-1000000,
        	maximum=1000000,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=int,
        	proportion=1,
        )
        self.Add(_hunter_freq_3_sizer)
        _hunter_freq_2_sizer = wx.BoxSizer(wx.VERTICAL)
        self._hunter_freq_2_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_hunter_freq_2_sizer,
        	value=self.hunter_freq_2,
        	callback=self.set_hunter_freq_2,
        	label='hunter_freq_2',
        	converter=forms.int_converter(),
        	proportion=0,
        )
        self._hunter_freq_2_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_hunter_freq_2_sizer,
        	value=self.hunter_freq_2,
        	callback=self.set_hunter_freq_2,
        	minimum=-1000000,
        	maximum=1000000,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=int,
        	proportion=1,
        )
        self.Add(_hunter_freq_2_sizer)
        _hunter_freq_1_sizer = wx.BoxSizer(wx.VERTICAL)
        self._hunter_freq_1_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_hunter_freq_1_sizer,
        	value=self.hunter_freq_1,
        	callback=self.set_hunter_freq_1,
        	label='hunter_freq_1',
        	converter=forms.int_converter(),
        	proportion=0,
        )
        self._hunter_freq_1_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_hunter_freq_1_sizer,
        	value=self.hunter_freq_1,
        	callback=self.set_hunter_freq_1,
        	minimum=-1000000,
        	maximum=1000000,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=int,
        	proportion=1,
        )
        self.Add(_hunter_freq_1_sizer)
        _hunter_freq_0_sizer = wx.BoxSizer(wx.VERTICAL)
        self._hunter_freq_0_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_hunter_freq_0_sizer,
        	value=self.hunter_freq_0,
        	callback=self.set_hunter_freq_0,
        	label='hunter_freq_0',
        	converter=forms.int_converter(),
        	proportion=0,
        )
        self._hunter_freq_0_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_hunter_freq_0_sizer,
        	value=self.hunter_freq_0,
        	callback=self.set_hunter_freq_0,
        	minimum=-1000000,
        	maximum=1000000,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=int,
        	proportion=1,
        )
        self.Add(_hunter_freq_0_sizer)
        _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='Frequency',
        	converter=forms.int_converter(),
        	proportion=0,
        )
        self._frequency_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_frequency_sizer,
        	value=self.frequency,
        	callback=self.set_frequency,
        	minimum=80000000,
        	maximum=1100000000,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=int,
        	proportion=1,
        )
        self.Add(_frequency_sizer)
        self.zeromq_push_sink_0_0 = zeromq.push_sink(gr.sizeof_float, fft_n_elements, 'tcp://127.0.0.1:9000', 100, False, -1)
        self.xmlrpc_server_0 = SimpleXMLRPCServer.SimpleXMLRPCServer(('localhost', 8080), allow_none=True)
        self.xmlrpc_server_0.register_instance(self)
        self.xmlrpc_server_0_thread = threading.Thread(target=self.xmlrpc_server_0.serve_forever)
        self.xmlrpc_server_0_thread.daemon = True
        self.xmlrpc_server_0_thread.start()
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
        	self.GetWin(),
        	baseband_freq=frequency,
        	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='master_plot',
        	peak_hold=False,
        )
        self.Add(self.wxgui_fftsink2_0.win)
        self.rtlsdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + '' )
        self.rtlsdr_source_0.set_sample_rate(samp_rate)
        self.rtlsdr_source_0.set_center_freq(frequency, 0)
        self.rtlsdr_source_0.set_freq_corr(0, 0)
        self.rtlsdr_source_0.set_dc_offset_mode(0, 0)
        self.rtlsdr_source_0.set_iq_balance_mode(0, 0)
        self.rtlsdr_source_0.set_gain_mode(False, 0)
        self.rtlsdr_source_0.set_gain(10, 0)
        self.rtlsdr_source_0.set_if_gain(20, 0)
        self.rtlsdr_source_0.set_bb_gain(20, 0)
        self.rtlsdr_source_0.set_antenna('', 0)
        self.rtlsdr_source_0.set_bandwidth(0, 0)
          
        _gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._gain_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_gain_sizer,
        	value=self.gain,
        	callback=self.set_gain,
        	label='gain',
        	converter=forms.int_converter(),
        	proportion=0,
        )
        self._gain_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_gain_sizer,
        	value=self.gain,
        	callback=self.set_gain,
        	minimum=0,
        	maximum=50,
        	num_steps=50,
        	style=wx.SL_HORIZONTAL,
        	cast=int,
        	proportion=1,
        )
        self.Add(_gain_sizer)
        self.freq_xlating_fft_filter_ccc_0_0_3 = filter.freq_xlating_fft_filter_ccc(xlate_decimation, (fft_taps), frequency + hunter_freq_5, samp_rate)
        self.freq_xlating_fft_filter_ccc_0_0_3.set_nthreads(1)
        self.freq_xlating_fft_filter_ccc_0_0_3.declare_sample_delay(0)
        self.freq_xlating_fft_filter_ccc_0_0_2 = filter.freq_xlating_fft_filter_ccc(xlate_decimation, (fft_taps), frequency + hunter_freq_4, samp_rate)
        self.freq_xlating_fft_filter_ccc_0_0_2.set_nthreads(1)
        self.freq_xlating_fft_filter_ccc_0_0_2.declare_sample_delay(0)
        self.freq_xlating_fft_filter_ccc_0_0_1 = filter.freq_xlating_fft_filter_ccc(xlate_decimation, (fft_taps), frequency + hunter_freq_3, samp_rate)
        self.freq_xlating_fft_filter_ccc_0_0_1.set_nthreads(1)
        self.freq_xlating_fft_filter_ccc_0_0_1.declare_sample_delay(0)
        self.freq_xlating_fft_filter_ccc_0_0_0 = filter.freq_xlating_fft_filter_ccc(xlate_decimation, (fft_taps), frequency + hunter_freq_2, samp_rate)
        self.freq_xlating_fft_filter_ccc_0_0_0.set_nthreads(1)
        self.freq_xlating_fft_filter_ccc_0_0_0.declare_sample_delay(0)
        self.freq_xlating_fft_filter_ccc_0_0 = filter.freq_xlating_fft_filter_ccc(xlate_decimation, (fft_taps), frequency + hunter_freq_1, samp_rate)
        self.freq_xlating_fft_filter_ccc_0_0.set_nthreads(1)
        self.freq_xlating_fft_filter_ccc_0_0.declare_sample_delay(0)
        self.freq_xlating_fft_filter_ccc_0 = filter.freq_xlating_fft_filter_ccc(xlate_decimation, (fft_taps), frequency + hunter_freq_0, samp_rate)
        self.freq_xlating_fft_filter_ccc_0.set_nthreads(1)
        self.freq_xlating_fft_filter_ccc_0.declare_sample_delay(0)
        _filter_width_sizer = wx.BoxSizer(wx.VERTICAL)
        self._filter_width_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_filter_width_sizer,
        	value=self.filter_width,
        	callback=self.set_filter_width,
        	label='filter_width',
        	converter=forms.int_converter(),
        	proportion=0,
        )
        self._filter_width_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_filter_width_sizer,
        	value=self.filter_width,
        	callback=self.set_filter_width,
        	minimum=2048,
        	maximum=40960,
        	num_steps=100,
        	style=wx.SL_HORIZONTAL,
        	cast=int,
        	proportion=1,
        )
        self.Add(_filter_width_sizer)
        self.fft_vxx_0 = fft.fft_vcc(fft_n_elements, True, (window.blackmanharris(fft_n_elements)), True, 1)
        self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_gr_complex*1, fft_n_elements)
        self.blocks_stream_to_vector_1 = blocks.stream_to_vector(gr.sizeof_float*1, fft_n_elements)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_n_elements)
        self.blocks_null_sink_0_0_3 = blocks.null_sink(gr.sizeof_gr_complex*1)
        self.blocks_null_sink_0_0_2 = blocks.null_sink(gr.sizeof_gr_complex*1)
        self.blocks_null_sink_0_0_1 = blocks.null_sink(gr.sizeof_gr_complex*1)
        self.blocks_null_sink_0_0_0 = blocks.null_sink(gr.sizeof_gr_complex*1)
        self.blocks_null_sink_0_0 = blocks.null_sink(gr.sizeof_gr_complex*1)
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex*1)
        self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_complex_to_mag_0, 0), (self.blocks_stream_to_vector_1, 0))    
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))    
        self.connect((self.blocks_stream_to_vector_1, 0), (self.zeromq_push_sink_0_0, 0))    
        self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_complex_to_mag_0, 0))    
        self.connect((self.fft_vxx_0, 0), (self.blocks_vector_to_stream_0, 0))    
        self.connect((self.freq_xlating_fft_filter_ccc_0, 0), (self.blocks_null_sink_0, 0))    
        self.connect((self.freq_xlating_fft_filter_ccc_0_0, 0), (self.blocks_null_sink_0_0, 0))    
        self.connect((self.freq_xlating_fft_filter_ccc_0_0_0, 0), (self.blocks_null_sink_0_0_0, 0))    
        self.connect((self.freq_xlating_fft_filter_ccc_0_0_1, 0), (self.blocks_null_sink_0_0_1, 0))    
        self.connect((self.freq_xlating_fft_filter_ccc_0_0_2, 0), (self.blocks_null_sink_0_0_2, 0))    
        self.connect((self.freq_xlating_fft_filter_ccc_0_0_3, 0), (self.blocks_null_sink_0_0_3, 0))    
        self.connect((self.rtlsdr_source_0, 0), (self.blocks_stream_to_vector_0, 0))    
        self.connect((self.rtlsdr_source_0, 0), (self.freq_xlating_fft_filter_ccc_0, 0))    
        self.connect((self.rtlsdr_source_0, 0), (self.freq_xlating_fft_filter_ccc_0_0, 0))    
        self.connect((self.rtlsdr_source_0, 0), (self.freq_xlating_fft_filter_ccc_0_0_0, 0))    
        self.connect((self.rtlsdr_source_0, 0), (self.freq_xlating_fft_filter_ccc_0_0_1, 0))    
        self.connect((self.rtlsdr_source_0, 0), (self.freq_xlating_fft_filter_ccc_0_0_2, 0))    
        self.connect((self.rtlsdr_source_0, 0), (self.freq_xlating_fft_filter_ccc_0_0_3, 0))    
        self.connect((self.rtlsdr_source_0, 0), (self.wxgui_fftsink2_0, 0))    
Example #31
0
    def __init__(self,
                 ask_samp_rate=4E6,
                 num_demod=4,
                 type_demod=0,
                 hw_args="uhd",
                 freq_correction=0,
                 record=True,
                 play=True,
                 audio_bps=8):

        # Call the initialization method from the parent class
        gr.top_block.__init__(self, "Receiver")

        # Default values
        self.center_freq = 144E6
        self.gain_db = 0
        self.if_gain_db = 16
        self.bb_gain_db = 16
        self.squelch_db = -60
        self.volume_db = 0
        audio_rate = 8000

        # Setup the USRP source, or use the USRP sim
        self.src = osmosdr.source(args="numchan=" + str(1) + " " + hw_args)
        self.src.set_sample_rate(ask_samp_rate)
        self.src.set_gain(self.gain_db)
        self.src.set_if_gain(self.if_gain_db)
        self.src.set_bb_gain(self.bb_gain_db)
        self.src.set_center_freq(self.center_freq)
        self.src.set_freq_corr(freq_correction)

        # Get the sample rate and center frequency from the hardware
        self.samp_rate = self.src.get_sample_rate()
        self.center_freq = self.src.get_center_freq()

        # Set the I/Q bandwidth to 80 % of sample rate
        self.src.set_bandwidth(0.8 * self.samp_rate)

        # NBFM channel is about 10 KHz wide
        # Want  about 3 FFT bins to span a channel
        # Use length FFT so 4 Msps / 1024 = 3906.25 Hz/bin
        # This also means 3906.25 vectors/second
        # Using below formula keeps FFT size a power of two
        # Also keeps bin size constant for power of two sampling rates
        # Use of 256 sets 3906.25 Hz/bin; increase to reduce bin size
        samp_ratio = self.samp_rate / 1E6
        fft_length = 256 * int(pow(2, np.ceil(np.log(samp_ratio) / np.log(2))))

        # -----------Flow for FFT--------------

        # Convert USRP steam to vector
        stream_to_vector = blocks.stream_to_vector(gr.sizeof_gr_complex * 1,
                                                   fft_length)

        # Want about 1000 vector/sec
        amount = int(round(self.samp_rate / fft_length / 1000))
        keep_one_in_n = blocks.keep_one_in_n(gr.sizeof_gr_complex * fft_length,
                                             amount)

        # Take FFT
        fft_vcc = fft.fft_vcc(fft_length, True,
                              window.blackmanharris(fft_length), True, 1)

        # Compute the power
        complex_to_mag_squared = blocks.complex_to_mag_squared(fft_length)

        # Video average and decimate from 1000 vector/sec to 10 vector/sec
        integrate_ff = blocks.integrate_ff(100, fft_length)

        # Probe vector
        self.probe_signal_vf = blocks.probe_signal_vf(fft_length)

        # Connect the blocks
        self.connect(self.src, stream_to_vector, keep_one_in_n, fft_vcc,
                     complex_to_mag_squared, integrate_ff,
                     self.probe_signal_vf)

        # -----------Flow for Demod--------------

        # Create N parallel demodulators as a list of objects
        # Default to NBFM demod
        self.demodulators = []
        for idx in range(num_demod):
            if type_demod == 1:
                self.demodulators.append(
                    TunerDemodAM(self.samp_rate, audio_rate, record,
                                 audio_bps))
            else:
                self.demodulators.append(
                    TunerDemodNBFM(self.samp_rate, audio_rate, record,
                                   audio_bps))

        if play:
            # Create an adder
            add_ff = blocks.add_ff(1)

            # Connect the demodulators between the source and adder
            for idx, demodulator in enumerate(self.demodulators):
                self.connect(self.src, demodulator, (add_ff, idx))

            # Audio sink
            audio_sink = audio.sink(audio_rate)

            # Connect the summed outputs to the audio sink
            self.connect(add_ff, audio_sink)
        else:
            # Just connect each demodulator to the receiver source
            for demodulator in self.demodulators:
                self.connect(self.src, demodulator)