def __init__(self, bandwidth=2e6, bb_gain=20, channels=1024, dev_args='', duration=60, frequency=1420e6, if_gain=20, obs_file='observation.dat', rf_gain=30, t_sample=1): gr.top_block.__init__(self, "Run Observation") ################################################## # Parameters ################################################## self.bandwidth = bandwidth self.bb_gain = bb_gain self.channels = channels self.dev_args = dev_args self.duration = duration self.frequency = frequency self.if_gain = if_gain self.obs_file = obs_file self.rf_gain = rf_gain self.t_sample = t_sample ################################################## # Variables ################################################## self.sinc_sample_locations = sinc_sample_locations = np.arange(-np.pi*4/2.0, np.pi*4/2.0, np.pi/channels) self.sinc = sinc = np.sinc(sinc_sample_locations/np.pi) self.custom_window = custom_window = sinc*np.hamming(4*channels) ################################################## # Blocks ################################################## self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + dev_args ) self.osmosdr_source_0.set_sample_rate(bandwidth) self.osmosdr_source_0.set_center_freq(frequency, 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(rf_gain, 0) self.osmosdr_source_0.set_if_gain(if_gain, 0) self.osmosdr_source_0.set_bb_gain(bb_gain, 0) self.osmosdr_source_0.set_antenna('', 0) self.osmosdr_source_0.set_bandwidth(0, 0) self.fft_vxx_0 = fft.fft_vcc(channels, True, (window.blackmanharris(channels)), True, 1) self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, channels) self.blocks_integrate_xx_0 = blocks.integrate_ff(int(t_sample*bandwidth/channels), channels) self.blocks_head_0 = blocks.head(gr.sizeof_gr_complex*1, int(duration*bandwidth)) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_float*channels, obs_file, True) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(channels) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_head_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_file_sink_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.osmosdr_source_0, 0), (self.blocks_head_0, 0))
def test_002_ff(self): src_data = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] dst_data = [6.0, 15.0] src = blocks.vector_source_f(src_data) itg = blocks.integrate_ff(3) dst = blocks.vector_sink_f() self.tb.connect(src, itg, dst) self.tb.run() self.assertFloatTuplesAlmostEqual(dst_data, dst.data(), 6)
def __init__(self): gr.hier_block2.__init__( self, "Bit Error Rate", gr.io_signaturev(2, 2, [gr.sizeof_char * 1, gr.sizeof_char * 1]), gr.io_signature(1, 1, gr.sizeof_float * 1), ) ################################################## # Variables ################################################## self._msgLength_config = ConfigParser.ConfigParser() self._msgLength_config.read("./configs/sdrConfig.txt") try: msgLength = self._msgLength_config.getint("main", "key") except: msgLength = 10000 self.msgLength = msgLength self._bits_per_byte_config = ConfigParser.ConfigParser() self._bits_per_byte_config.read("./configs/sdrConfig.txt") try: bits_per_byte = self._bits_per_byte_config.getint("main", "key") except: bits_per_byte = 8 self.bits_per_byte = bits_per_byte intdecim = 100000 if msgLength < intdecim: intdecim = msgLength ################################################## # Blocks ################################################## self.blocks_xor_xx_0 = blocks.xor_bb() self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(bits_per_byte) self.blocks_uchar_to_float_0 = blocks.uchar_to_float() self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff( (1.0 / msgLength, )) self.blocks_integrate_xx_0 = blocks.integrate_ff(intdecim) ################################################## # Connections ################################################## self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self, 1), (self.blocks_xor_xx_0, 1)) self.connect((self, 0), (self.blocks_xor_xx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self, 0)) self.connect((self.blocks_xor_xx_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_uchar_to_float_0, 0)) self.connect((self.blocks_uchar_to_float_0, 0), (self.blocks_integrate_xx_0, 0))
def __init__(self): gr.hier_block2.__init__(self, "BitErrors", gr.io_signature(1, 1, gr.sizeof_char), gr.io_signature(1, 1, gr.sizeof_int)) intdump_decim = min(int(N_BITS / 10), 100000) self.connect(self, blocks.skiphead(gr.sizeof_char, SKIP), blocks.not_bb(), blocks.and_const_bb(1), blocks.uchar_to_float(), blocks.integrate_ff(intdump_decim), blocks.multiply_const_ff(1.0 / intdump_decim), self)
def __init__(self, c_freq=1420000000, nbin=1000, nchan=1024, obs_time=60, samp_rate=2400000): gr.top_block.__init__(self, "Top Block") ################################################## # Parameters ################################################## self.c_freq = c_freq self.nbin = nbin self.nchan = nchan self.obs_time = obs_time self.samp_rate = samp_rate ################################################## # Variables ################################################## self.gain = gain = 10000 ################################################## # Blocks ################################################## self.fft_vxx_0 = fft.fft_vcc(nchan, True, (window.blackmanharris(nchan)), True, 1) self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, nchan) self.blocks_integrate_xx_0 = blocks.integrate_ff(nbin, nchan) self.blocks_head_0 = blocks.head(gr.sizeof_gr_complex*1, int(obs_time*samp_rate)) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_float*nchan, '/home/pictor/Desktop/pictortelescope/observation.dat', True) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(nchan) self.RTL820T = osmosdr.source( args="numchan=" + str(1) + " " + '' ) self.RTL820T.set_sample_rate(samp_rate) self.RTL820T.set_center_freq(c_freq, 0) self.RTL820T.set_freq_corr(0, 0) self.RTL820T.set_dc_offset_mode(0, 0) self.RTL820T.set_iq_balance_mode(0, 0) self.RTL820T.set_gain_mode(False, 0) self.RTL820T.set_gain(30, 0) self.RTL820T.set_if_gain(30, 0) self.RTL820T.set_bb_gain(30, 0) self.RTL820T.set_antenna('', 0) self.RTL820T.set_bandwidth(0, 0) ################################################## # Connections ################################################## self.connect((self.RTL820T, 0), (self.blocks_head_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_head_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_file_sink_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))
def __init__(self, bits_per_byte): gr.hier_block2.__init__(self, "BitErrors", gr.io_signature(2, 2, gr.sizeof_char), gr.io_signature(1, 1, gr.sizeof_int)) # Bit comparison comp = blocks.xor_bb() intdump_decim = 100000 if N_BITS < intdump_decim: intdump_decim = int(N_BITS) self.connect(self, comp, blocks.unpack_k_bits_bb(bits_per_byte), blocks.uchar_to_float(), blocks.integrate_ff(intdump_decim), blocks.multiply_const_ff(1.0 / N_BITS), self) self.connect((self, 1), (comp, 1))
def __init__(self): gr.hier_block2.__init__( self, "Bit Error Rate", gr.io_signaturev(2, 2, [gr.sizeof_char*1, gr.sizeof_char*1]), gr.io_signature(1, 1, gr.sizeof_float*1), ) ################################################## # Variables ################################################## self._msgLength_config = ConfigParser.ConfigParser() self._msgLength_config.read("./configs/sdrConfig.txt") try: msgLength = self._msgLength_config.getint("main", "key") except: msgLength = 10000 self.msgLength = msgLength self._bits_per_byte_config = ConfigParser.ConfigParser() self._bits_per_byte_config.read("./configs/sdrConfig.txt") try: bits_per_byte = self._bits_per_byte_config.getint("main", "key") except: bits_per_byte = 8 self.bits_per_byte = bits_per_byte intdecim = 100000 if msgLength < intdecim: intdecim = msgLength ################################################## # Blocks ################################################## self.blocks_xor_xx_0 = blocks.xor_bb() self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(bits_per_byte) self.blocks_uchar_to_float_0 = blocks.uchar_to_float() self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((1.0/msgLength, )) self.blocks_integrate_xx_0 = blocks.integrate_ff(intdecim) ################################################## # Connections ################################################## self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self, 1), (self.blocks_xor_xx_0, 1)) self.connect((self, 0), (self.blocks_xor_xx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self, 0)) self.connect((self.blocks_xor_xx_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_uchar_to_float_0, 0)) self.connect((self.blocks_uchar_to_float_0, 0), (self.blocks_integrate_xx_0, 0))
def test_001_t (self): expected_result = (250.0, 250.0) rng = c4fm.bernoulli_source_b(0.25, 0) head = blocks.head(gr.sizeof_char, 2000) convert = blocks.uchar_to_float() integrate = blocks.integrate_ff(1000) dst = blocks.vector_sink_f() self.tb.connect(rng, head) self.tb.connect(head, convert) self.tb.connect(convert, integrate) self.tb.connect(integrate, dst) self.tb.run () # check data # The result is a random variable of mean 0.25*1000 = 250 # This test is statistical: there is a small probablity that it will fail self.assertLess(dst.data()[0], 350.0) self.assertGreater(dst.data()[0], 150.0) self.assertLess(dst.data()[1], 350.0) self.assertGreater(dst.data()[1], 150.0)
def __init__(self, samp_rate, decimation, signal_taps, max_overlap=0.25, threshold=4., fft_size=2048, center_freq=0): gr.hier_block2.__init__( self, "Channel Detector", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(0, 0, 0), ) ################################################## # Parameters ################################################## self.samp_rate = samp_rate self.decimation = decimation self.fft_size = fft_size self.center_freq = center_freq self.signals_detected_handler = None ################################################## # Blocks ################################################## self.fft = fft.fft_vcc(fft_size, True, (fft.window.blackmanharris(fft_size)), True, 1) self.stream_to_vect = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_size) self.log10 = blocks.nlog10_ff(10, fft_size, -10*math.log10(decimation)) self.integrate = blocks.integrate_ff(decimation, fft_size) self.complex_to_mag_squared = blocks.complex_to_mag_squared(fft_size) self.sig_det = signal_detector_base(samp_rate, fft_size, signal_taps, threshold, max_overlap, center_freq=center_freq) ################################################## # Connections ################################################## self.connect((self, 0), (self.stream_to_vect, 0)) self.connect((self.stream_to_vect, 0), (self.fft, 0)) self.connect((self.fft, 0), (self.complex_to_mag_squared, 0)) self.connect((self.complex_to_mag_squared, 0), (self.integrate, 0)) self.connect((self.integrate, 0), (self.log10, 0)) self.connect((self.log10, 0), (self.sig_det, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 44100 ################################################## # Blocks ################################################## self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_f( self.GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate/4, fft_size=2048, fft_rate=15, average=False, avg_alpha=None, title='Waterfall Plot', ) self.Add(self.wxgui_waterfallsink2_0.win) self.blocks_wavfile_source_0 = blocks.wavfile_source('/home/sdr/Dropbox/Work/Documents/2020/FYS-2006/book/code/signal_processing/010_audio_compression/compressed_signal.wav', True) self.blocks_integrate_xx_0 = blocks.integrate_ff(4, 1) self.audio_sink_0 = audio.sink(samp_rate, '', True) ################################################## # Connections ################################################## self.connect((self.blocks_integrate_xx_0, 0), (self.wxgui_waterfallsink2_0, 0)) self.connect((self.blocks_wavfile_source_0, 0), (self.audio_sink_0, 0)) self.connect((self.blocks_wavfile_source_0, 0), (self.blocks_integrate_xx_0, 0))
def __init__(self, fast_integration=0.0005, freq=1.4205e9, samp_rate=25e6, vec_length=256): gr.top_block.__init__(self, "Headless Usrp Filterbank") ################################################## # Parameters ################################################## self.fast_integration = fast_integration self.freq = freq self.samp_rate = samp_rate self.vec_length = vec_length ################################################## # Variables ################################################## self.integration_time = integration_time = 10 ################################################## # Blocks ################################################## self.uhd_usrp_source_1 = uhd.usrp_source( ",".join(("", "")), uhd.stream_args( cpu_format="fc32", otw_format="sc8", args='', channels=list(range(0, 1)), ), ) self.uhd_usrp_source_1.set_samp_rate(samp_rate) self.uhd_usrp_source_1.set_time_now(uhd.time_spec(time.time()), uhd.ALL_MBOARDS) self.uhd_usrp_source_1.set_center_freq(freq, 0) self.uhd_usrp_source_1.set_antenna('TX/RX', 0) self.uhd_usrp_source_1.set_gain(35, 0) self.uhd_usrp_source_1.set_auto_dc_offset(True, 0) self.uhd_usrp_source_1.set_auto_iq_balance(True, 0) self.uhd_usrp_source_1.set_min_output_buffer(8192) self.uhd_usrp_source_1.set_max_output_buffer(16384) self.fft_vxx_0 = fft.fft_vcc(vec_length, True, window.rectangular(vec_length), True, 4) self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, vec_length) self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc( vec_length) self.blocks_integrate_xx_0_0 = blocks.integrate_ff( int(fast_integration * samp_rate / vec_length), vec_length) self.blocks_file_sink_0 = blocks.file_sink( gr.sizeof_float * vec_length, 'test.bin', False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_complex_to_real_0_0 = blocks.complex_to_real(vec_length) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_real_0_0, 0), (self.blocks_integrate_xx_0_0, 0)) self.connect((self.blocks_integrate_xx_0_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.blocks_complex_to_real_0_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_multiply_conjugate_cc_0, 1)) self.connect((self.fft_vxx_0, 0), (self.blocks_multiply_conjugate_cc_0, 0)) self.connect((self.uhd_usrp_source_1, 0), (self.blocks_stream_to_vector_0, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Vor Receive Realtime Clean") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.morse_vol = morse_vol = 10 self.samp_rate = samp_rate = 32000 self.rtl_gain = rtl_gain = 42 self.rtl_freq = rtl_freq = 115.5e6+64 self.morse_gain = morse_gain = pow(10,morse_vol/10) self.morse_amp_level = morse_amp_level = 0 ################################################## # Blocks ################################################## self.wxgui_scopesink2_1_0_0 = scopesink2.scope_sink_f( self.GetWin(), title='Morse', sample_rate=samp_rate/(1600), v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=wxgui.TRIG_MODE_STRIPCHART, y_axis_label='Amp', ) self.Add(self.wxgui_scopesink2_1_0_0.win) self.wxgui_scopesink2_0 = scopesink2.scope_sink_f( self.GetWin(), title='Scope Plot', sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0.02, ac_couple=False, xy_mode=False, num_inputs=2, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label='Counts', ) self.Add(self.wxgui_scopesink2_0.win) self.wxgui_numbersink2_1 = numbersink2.number_sink_f( self.GetWin(), unit='Units', minval=0, maxval=360, factor=1.0, decimal_places=10, ref_level=0, sample_rate=1, number_rate=15, average=False, avg_alpha=None, label='Number Plot', peak_hold=False, show_gauge=False, ) self.Add(self.wxgui_numbersink2_1.win) _morse_vol_sizer = wx.BoxSizer(wx.VERTICAL) self._morse_vol_text_box = forms.text_box( parent=self.GetWin(), sizer=_morse_vol_sizer, value=self.morse_vol, callback=self.set_morse_vol, label='Morse Volume (dB):', converter=forms.float_converter(), proportion=0, ) self._morse_vol_slider = forms.slider( parent=self.GetWin(), sizer=_morse_vol_sizer, value=self.morse_vol, callback=self.set_morse_vol, minimum=-25, maximum=25, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_morse_vol_sizer) def _morse_amp_level_probe(): while True: val = self.morse_amp.level() try: self.set_morse_amp_level(val) except AttributeError: pass time.sleep(1.0 / (25)) _morse_amp_level_thread = threading.Thread(target=_morse_amp_level_probe) _morse_amp_level_thread.daemon = True _morse_amp_level_thread.start() self.low_pass_filter_0_1_0 = filter.fir_filter_fff(1, firdes.low_pass( 1, samp_rate, 1000, 500, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0_1 = filter.fir_filter_ccf(1, firdes.low_pass( 1, samp_rate, 1000, 500, firdes.WIN_HAMMING, 6.76)) self.iio_modulo_const_ff_0 = iio.modulo_const_ff(360, 1) self.goertzel_fc_0_0 = fft.goertzel_fc(samp_rate, 3200, 30) self.goertzel_fc_0 = fft.goertzel_fc(samp_rate, 3200, 30) self.fir_filter_xxx_0_0 = filter.fir_filter_fff(1, (filter.optfir.low_pass(1, samp_rate, 100, 200, 0.1, 60))) self.fir_filter_xxx_0_0.declare_sample_delay(0) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vff((-180/pi, )) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((morse_gain, )) self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1) self.blocks_integrate_xx_1 = blocks.integrate_ff(1600, 1) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_file_source_0_0_0 = blocks.file_source(gr.sizeof_gr_complex*1, '/tmp/vor_simulation.cfile', False) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) self.blocks_add_const_vxx_1 = blocks.add_const_vff((360, )) self.band_pass_filter_0 = filter.fir_filter_fcc(1, firdes.complex_band_pass( 1, samp_rate, 1010, 1030, 100, firdes.WIN_HAMMING, 6.76)) self.audio_sink_0_0 = audio.sink(samp_rate, '', True) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, -9960, 1, 0) self.analog_fm_demod_cf_0 = analog.fm_demod_cf( channel_rate=samp_rate, audio_decim=1, deviation=1000, audio_pass=100, audio_stop=200, gain=1.0, tau=75e-6, ) self.analog_am_demod_cf_0 = analog.am_demod_cf( channel_rate=samp_rate, audio_decim=1, audio_pass=12000, audio_stop=13000, ) ################################################## # Connections ################################################## self.connect((self.analog_am_demod_cf_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.analog_am_demod_cf_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.analog_am_demod_cf_0, 0), (self.low_pass_filter_0_1_0, 0)) self.connect((self.analog_fm_demod_cf_0, 0), (self.goertzel_fc_0_0, 0)) self.connect((self.analog_fm_demod_cf_0, 0), (self.wxgui_scopesink2_0, 1)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.band_pass_filter_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.blocks_add_const_vxx_1, 0), (self.iio_modulo_const_ff_0, 0)) self.connect((self.blocks_complex_to_arg_0, 0), (self.blocks_multiply_const_vxx_1, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_integrate_xx_1, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_file_source_0_0_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_integrate_xx_1, 0), (self.wxgui_scopesink2_1_0_0, 0)) self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.blocks_complex_to_arg_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_add_const_vxx_1, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_0_1, 0)) self.connect((self.blocks_throttle_0, 0), (self.analog_am_demod_cf_0, 0)) self.connect((self.fir_filter_xxx_0_0, 0), (self.goertzel_fc_0, 0)) self.connect((self.fir_filter_xxx_0_0, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.goertzel_fc_0, 0), (self.blocks_multiply_conjugate_cc_0, 0)) self.connect((self.goertzel_fc_0_0, 0), (self.blocks_multiply_conjugate_cc_0, 1)) self.connect((self.iio_modulo_const_ff_0, 0), (self.wxgui_numbersink2_1, 0)) self.connect((self.low_pass_filter_0_1, 0), (self.analog_fm_demod_cf_0, 0)) self.connect((self.low_pass_filter_0_1_0, 0), (self.fir_filter_xxx_0_0, 0))
def __init__(self): gr.top_block.__init__(self, "Ham2Mon Receiver Flow Example") Qt.QWidget.__init__(self) self.setWindowTitle("Ham2Mon 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", "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))
def __init__(self, c_freq=1420000000, nbin=1000, nchan=1024, obs_time=60, samp_rate=2400000): gr.top_block.__init__(self, "Top Block") ################################################## # Parameters ################################################## self.c_freq = c_freq self.nbin = nbin self.nchan = nchan self.obs_time = obs_time self.samp_rate = samp_rate ################################################## # Variables ################################################## self.sinc_sample_locations = sinc_sample_locations = np.arange( -np.pi * 4 / 2.0, np.pi * 4 / 2.0, np.pi / nchan) self.sinc = sinc = np.sinc(sinc_sample_locations / np.pi) self.custom_window = custom_window = sinc * np.hamming(4 * nchan) ################################################## # Blocks ################################################## self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + 'rtl=0') self.osmosdr_source_0.set_sample_rate(samp_rate) self.osmosdr_source_0.set_center_freq(c_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(rtlgain, 0) self.osmosdr_source_0.set_if_gain(rtlgain, 0) self.osmosdr_source_0.set_bb_gain(rtlgain, 0) self.osmosdr_source_0.set_antenna('', 0) self.osmosdr_source_0.set_bandwidth(0, 0) self.fft_vxx_0 = fft.fft_vcc(nchan, True, (window.blackmanharris(nchan)), True, 1) self.blocks_stream_to_vector_0_2 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, nchan) self.blocks_stream_to_vector_0_1 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, nchan) self.blocks_stream_to_vector_0_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, nchan) self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, nchan) self.blocks_multiply_const_vxx_0_0_0_0 = blocks.multiply_const_vcc( (custom_window[0:nchan])) self.blocks_multiply_const_vxx_0_0_0 = blocks.multiply_const_vcc( (custom_window[nchan:2 * nchan])) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vcc( (custom_window[2 * nchan:3 * nchan])) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc( (custom_window[-nchan:])) self.blocks_integrate_xx_0 = blocks.integrate_ff(nbin, nchan) self.blocks_head_0 = blocks.head(gr.sizeof_gr_complex * 1, int(obs_time * samp_rate)) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_float * nchan, 'observation.dat', True) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_delay_0_1 = blocks.delay(gr.sizeof_gr_complex * 1, nchan) self.blocks_delay_0_0 = blocks.delay(gr.sizeof_gr_complex * 1, nchan * 2) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1, nchan * 3) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared( nchan) self.blocks_add_xx_0 = blocks.add_vcc(nchan) ################################################## # Connections ################################################## self.connect((self.blocks_add_xx_0, 0), (self.fft_vxx_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_stream_to_vector_0_2, 0)) self.connect((self.blocks_delay_0_0, 0), (self.blocks_stream_to_vector_0_0, 0)) self.connect((self.blocks_delay_0_1, 0), (self.blocks_stream_to_vector_0_1, 0)) self.connect((self.blocks_head_0, 0), (self.blocks_delay_0, 0)) self.connect((self.blocks_head_0, 0), (self.blocks_delay_0_0, 0)) self.connect((self.blocks_head_0, 0), (self.blocks_delay_0_1, 0)) self.connect((self.blocks_head_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_multiply_const_vxx_0_0_0, 0), (self.blocks_add_xx_0, 2)) self.connect((self.blocks_multiply_const_vxx_0_0_0_0, 0), (self.blocks_add_xx_0, 3)) self.connect((self.blocks_stream_to_vector_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_stream_to_vector_0_0, 0), (self.blocks_multiply_const_vxx_0_0_0, 0)) self.connect((self.blocks_stream_to_vector_0_1, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.blocks_stream_to_vector_0_2, 0), (self.blocks_multiply_const_vxx_0_0_0_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.blocks_head_0, 0))
def __init__(self): gr.top_block.__init__(self) options = get_options() self.ifreq = options.frequency self.rfgain = options.gain self.src = osmosdr.source(options.args) self.src.set_center_freq(self.ifreq) self.src.set_sample_rate(int(options.sample_rate)) if self.rfgain is None: self.src.set_gain_mode(1) self.iagc = 1 self.rfgain = 0 else: self.iagc = 0 self.src.set_gain_mode(0) self.src.set_gain(self.rfgain) # may differ from the requested rate sample_rate = self.src.get_sample_rate() sys.stderr.write("sample rate: %d\n" % (sample_rate)) bitrate = 8000 first_decim=125 out_sample_rate=sample_rate/first_decim sys.stderr.write("output sample rate: %d\n" % (out_sample_rate)) sps=out_sample_rate/bitrate sys.stderr.write("samples per symbol: %d\n" % (sps)) self.offset = options.offset sys.stderr.write("offset is: %dHz\n" % self.offset) taps = filter.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.2, filter.firdes.WIN_HANN) self.tuner = filter.freq_xlating_fir_filter_ccf(first_decim, taps, self.offset, sample_rate) self.demod = digital.gmsk_demod(samples_per_symbol=sps) self.output = blocks.file_sink(gr.sizeof_char, options.output_file) self.connect((self.src, 0), (self.tuner, 0)) self.connect((self.tuner, 0), (self.demod, 0)) self.connect((self.demod, 0), (self.output, 0)) self.fm_demod = analog.fm_demod_cf(sample_rate/first_decim, 1, 5000, 3000, 4000) self.integrate = blocks.integrate_ff(32000) self.probe = blocks.probe_signal_f() self.connect((self.tuner, 0), (self.fm_demod,0)) self.connect((self.fm_demod, 0), (self.integrate,0)) self.connect((self.integrate, 0), (self.probe, 0)) def _variable_function_probe_0_probe(): while True: freq = self.tuner.center_freq() freq2 = freq + 0.2*self.probe.level() print "Autotune: fix=%f old=%i new=%i"%(self.probe.level(), self.ifreq+freq, self.ifreq+freq2) self.tuner.set_center_freq(freq2) time.sleep(5.0) _variable_function_probe_0_thread = threading.Thread(target=_variable_function_probe_0_probe) _variable_function_probe_0_thread.daemon = True _variable_function_probe_0_thread.start()
def __init__(self): gr.top_block.__init__(self, "Spectrometer") Qt.QWidget.__init__(self) self.setWindowTitle("Spectrometer") 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", "spectrometer") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.vec_length = vec_length = 4096 self.sinc_sample_locations = sinc_sample_locations = np.arange( -np.pi * 4 / 2.0, np.pi * 4 / 2.0, np.pi / vec_length) self.timenow = timenow = datetime.now().strftime("%Y-%m-%d_%H.%M.%S") self.sinc = sinc = np.sinc(sinc_sample_locations / np.pi) self.prefix = prefix = "/home/dspradio/grc_data/" self.samp_rate = samp_rate = 10e6 self.recfile = recfile = prefix + timenow + ".h5" self.integration_time = integration_time = 2 self.freq = freq = 1.419e9 self.display_integration = display_integration = 0.5 self.custom_window = custom_window = sinc * np.hamming(4 * vec_length) ################################################## # Blocks ################################################## self.radio_astro_hdf5_sink_0 = radio_astro.hdf5_sink( vec_length, recfile, 'AZ: 180, EL: 30', freq - samp_rate / 2, samp_rate / vec_length, 'testing az el etc') self.qtgui_vector_sink_f_0 = qtgui.vector_sink_f( vec_length, freq - samp_rate / 2, samp_rate / vec_length, "Frequency", "PSD", "Spectrum", 1 # Number of inputs ) self.qtgui_vector_sink_f_0.set_update_time(0.10) self.qtgui_vector_sink_f_0.set_y_axis(0, 3000) self.qtgui_vector_sink_f_0.enable_autoscale(True) self.qtgui_vector_sink_f_0.enable_grid(True) self.qtgui_vector_sink_f_0.set_x_axis_units("Hz") self.qtgui_vector_sink_f_0.set_y_axis_units("arb") self.qtgui_vector_sink_f_0.set_ref_level(0) 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_vector_sink_f_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_vector_sink_f_0.set_line_label(i, labels[i]) self.qtgui_vector_sink_f_0.set_line_width(i, widths[i]) self.qtgui_vector_sink_f_0.set_line_color(i, colors[i]) self.qtgui_vector_sink_f_0.set_line_alpha(i, alphas[i]) self._qtgui_vector_sink_f_0_win = sip.wrapinstance( self.qtgui_vector_sink_f_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_vector_sink_f_0_win) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( vec_length, #size samp_rate, #samp_rate "", #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(-1, 1) self.qtgui_time_sink_x_0.set_y_label('Amplitude', "") 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(True) self.qtgui_time_sink_x_0.enable_grid(False) self.qtgui_time_sink_x_0.enable_axis_labels(False) self.qtgui_time_sink_x_0.enable_control_panel(True) 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_layout.addWidget(self._qtgui_time_sink_x_0_win) self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + 'airspy=0,bias=0,pack=0') self.osmosdr_source_0.set_sample_rate(samp_rate) self.osmosdr_source_0.set_center_freq(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(20, 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(0, 0) self.fft_vxx_0 = fft.fft_vcc(vec_length, True, (window.rectangular(vec_length)), True, 1) self.blocks_vector_to_stream_0 = blocks.vector_to_stream( gr.sizeof_float * 1, vec_length) self.blocks_stream_to_vector_0_2 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, vec_length) self.blocks_stream_to_vector_0_1 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, vec_length) self.blocks_stream_to_vector_0_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, vec_length) self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, vec_length) self.blocks_nlog10_ff_0_0 = blocks.nlog10_ff(10, vec_length, 0) self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, 1, 0) self.blocks_multiply_const_vxx_0_2 = blocks.multiply_const_vcc( (custom_window[-vec_length:])) self.blocks_multiply_const_vxx_0_1 = blocks.multiply_const_vcc( (custom_window[2 * vec_length:3 * vec_length])) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vcc( (custom_window[vec_length:2 * vec_length])) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc( (custom_window[0:vec_length])) self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc( vec_length) self.blocks_message_debug_0 = blocks.message_debug() self.blocks_integrate_xx_0_0 = blocks.integrate_ff( int(display_integration * samp_rate / vec_length), vec_length) self.blocks_integrate_xx_0 = blocks.integrate_ff( int((integration_time) * samp_rate / vec_length) / int(display_integration * samp_rate / vec_length), vec_length) self.blocks_delay_0_0_0_0 = blocks.delay(gr.sizeof_gr_complex * 1, 3 * vec_length) self.blocks_delay_0_0_0 = blocks.delay(gr.sizeof_gr_complex * 1, 2 * vec_length) self.blocks_delay_0_0 = blocks.delay(gr.sizeof_gr_complex * 1, vec_length) self.blocks_complex_to_real_0_0 = blocks.complex_to_real(vec_length) self.blocks_add_xx_0 = blocks.add_vcc(vec_length) ################################################## # Connections ################################################## self.msg_connect((self.qtgui_vector_sink_f_0, 'xval'), (self.blocks_message_debug_0, 'print')) self.connect((self.blocks_add_xx_0, 0), (self.fft_vxx_0, 0)) self.connect((self.blocks_complex_to_real_0_0, 0), (self.blocks_integrate_xx_0_0, 0)) self.connect((self.blocks_delay_0_0, 0), (self.blocks_stream_to_vector_0_0, 0)) self.connect((self.blocks_delay_0_0_0, 0), (self.blocks_stream_to_vector_0_2, 0)) self.connect((self.blocks_delay_0_0_0_0, 0), (self.blocks_stream_to_vector_0_1, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_vector_to_stream_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.radio_astro_hdf5_sink_0, 0)) self.connect((self.blocks_integrate_xx_0_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_integrate_xx_0_0, 0), (self.blocks_nlog10_ff_0_0, 0)) self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.blocks_complex_to_real_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_xx_0, 3)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.blocks_add_xx_0, 2)) self.connect((self.blocks_multiply_const_vxx_0_1, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_multiply_const_vxx_0_2, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_nlog10_ff_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blocks_nlog10_ff_0_0, 0), (self.qtgui_vector_sink_f_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.blocks_multiply_const_vxx_0_2, 0)) self.connect((self.blocks_stream_to_vector_0_0, 0), (self.blocks_multiply_const_vxx_0_1, 0)) self.connect((self.blocks_stream_to_vector_0_1, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_stream_to_vector_0_2, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_nlog10_ff_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_multiply_conjugate_cc_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_multiply_conjugate_cc_0, 1)) self.connect((self.osmosdr_source_0, 0), (self.blocks_delay_0_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.blocks_delay_0_0_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.blocks_delay_0_0_0_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.blocks_stream_to_vector_0, 0))
def __init__( self, EbN0=0, esprit_decimation=128, fc=436e6, mx=4, my=4, n=1, phi=50, rs_decimation=8, theta=30, ): gr.top_block.__init__(self, "BER Simulation") ################################################## # Parameters ################################################## self.EbN0 = EbN0 self.esprit_decimation = esprit_decimation self.fc = fc self.mx = mx self.my = my self.n = n self.phi = phi self.rs_decimation = rs_decimation self.theta = theta ################################################## # Variables ################################################## self.sps = sps = 5 self.N_BITS = N_BITS = 1e5 self.samp_rate = samp_rate = 32000 self.noise_voltage = noise_voltage = 1.0 / math.sqrt( 1 / float(sps) * 10**(float(EbN0) / 10)) self.intdump_decim = intdump_decim = min(int(N_BITS / 10), 100000) self.const = const = digital.constellation_bpsk().base() self.alpha = alpha = 0.35 self.SKIP = SKIP = 1000 self.RAND_SEED = RAND_SEED = 42 ################################################## # Blocks ################################################## self.lilacsat1_ber_bpsk_0 = lilacsat1_ber_bpsk( bfo=12000, callsign="", ip="::", latitude=0, longitude=0, port=7355, recstart="", ) self.digital_scrambler_bb_0 = digital.scrambler_bb(0x21, 0x0, 16) self.digital_diff_encoder_bb_0 = digital.diff_encoder_bb(2) self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(2) self.digital_descrambler_bb_0 = digital.descrambler_bb(0x21, 0x00, 16) self.digital_constellation_modulator_0 = digital.generic_mod( constellation=const, differential=False, samples_per_symbol=sps, pre_diff_code=True, excess_bw=alpha, verbose=False, log=False, ) self.channels_channel_model_0 = channels.channel_model( noise_voltage=noise_voltage, frequency_offset=0.0, epsilon=1.0, taps=( 0, 0, (1 + 1j) / numpy.sqrt(2), ), noise_seed=RAND_SEED, block_tags=False, ) self.blocks_vector_to_stream_0 = blocks.vector_to_stream( gr.sizeof_gr_complex * 1, mx * my) self.blocks_vector_source_x_0 = blocks.vector_source_b([1], True, 1, []) self.blocks_vector_sink_x_0_0_0 = blocks.vector_sink_f(1, 1024) self.blocks_vector_sink_x_0_0 = blocks.vector_sink_f(1, 1024) self.blocks_vector_sink_x_0 = blocks.vector_sink_f(1, 1024) self.blocks_uchar_to_float_0 = blocks.uchar_to_float() self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, mx * my) self.blocks_skiphead_0 = blocks.skiphead(gr.sizeof_char * 1, SKIP) self.blocks_pack_k_bits_bb_0 = blocks.pack_k_bits_bb(8) self.blocks_not_xx_0 = blocks.not_bb() self.blocks_multiply_const_vxx_1 = blocks.multiply_const_cc(0.1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff( 1.0 / intdump_decim) self.blocks_integrate_xx_0 = blocks.integrate_ff(intdump_decim, 1) self.blocks_head_0 = blocks.head(gr.sizeof_char * 1, int(N_BITS)) self.blocks_and_const_xx_0 = blocks.and_const_bb(1) self.beamforming_randomsampler_py_cc_0_0 = beamforming.randomsampler_py_cc( mx * my, rs_decimation) self.beamforming_phasedarray_py_cc_0 = beamforming.phasedarray_py_cc( mx, my, theta, phi, fc, 0) self.beamforming_doaesprit_py_cf_0 = beamforming.doaesprit_py_cf( 128, mx, my, fc, n) self.beamforming_beamformer_py_cc_0 = beamforming.beamformer_py_cc( mx, my, fc, 0, 0, 8 * 128) ################################################## # Connections ################################################## self.connect( (self.beamforming_beamformer_py_cc_0, 0), (self.blocks_multiply_const_vxx_1, 0), ) self.connect( (self.beamforming_doaesprit_py_cf_0, 0), (self.beamforming_beamformer_py_cc_0, 1), ) self.connect( (self.beamforming_doaesprit_py_cf_0, 1), (self.beamforming_beamformer_py_cc_0, 2), ) self.connect((self.beamforming_doaesprit_py_cf_0, 0), (self.blocks_vector_sink_x_0_0, 0)) self.connect( (self.beamforming_doaesprit_py_cf_0, 1), (self.blocks_vector_sink_x_0_0_0, 0), ) self.connect( (self.beamforming_phasedarray_py_cc_0, 0), (self.blocks_vector_to_stream_0, 0), ) self.connect( (self.beamforming_randomsampler_py_cc_0_0, 0), (self.beamforming_doaesprit_py_cf_0, 0), ) self.connect((self.blocks_and_const_xx_0, 0), (self.blocks_uchar_to_float_0, 0)) self.connect((self.blocks_head_0, 0), (self.digital_scrambler_bb_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_vector_sink_x_0, 0)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.lilacsat1_ber_bpsk_0, 0)) self.connect((self.blocks_not_xx_0, 0), (self.blocks_and_const_xx_0, 0)) self.connect( (self.blocks_pack_k_bits_bb_0, 0), (self.digital_constellation_modulator_0, 0), ) self.connect((self.blocks_skiphead_0, 0), (self.blocks_not_xx_0, 0)) self.connect( (self.blocks_stream_to_vector_0, 0), (self.beamforming_beamformer_py_cc_0, 0), ) self.connect( (self.blocks_stream_to_vector_0, 0), (self.beamforming_randomsampler_py_cc_0_0, 0), ) self.connect((self.blocks_uchar_to_float_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_head_0, 0)) self.connect((self.blocks_vector_to_stream_0, 0), (self.channels_channel_model_0, 0)) self.connect((self.channels_channel_model_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect( (self.digital_constellation_modulator_0, 0), (self.beamforming_phasedarray_py_cc_0, 0), ) self.connect((self.digital_descrambler_bb_0, 0), (self.blocks_skiphead_0, 0)) self.connect((self.digital_diff_decoder_bb_0, 0), (self.digital_descrambler_bb_0, 0)) self.connect((self.digital_diff_encoder_bb_0, 0), (self.blocks_pack_k_bits_bb_0, 0)) self.connect((self.digital_scrambler_bb_0, 0), (self.digital_diff_encoder_bb_0, 0)) self.connect((self.lilacsat1_ber_bpsk_0, 0), (self.digital_diff_decoder_bb_0, 0))
def __init__(self, directory="/mnt/buf0", gaindB=35, samp_rate=30.72e6, src_name='unknown_source', lo_freq=-1): gr.top_block.__init__(self, "Polarimetric Interferometry") self.directory = directory self.src_name = src_name self.samp_rate = samp_rate self.lo_freq = lo_freq self.nfft = nfft = 256 nthreads = 1 fc = 512e6 output_rate = 0.1 parallel_ffts = 2 self.decim = decim = int(output_rate * samp_rate / nfft) interleave_block = decim self.nchans = nchans = 4 self.npairs = npairs = nchans * (nchans - 1) // 2 self.uhd_usrp_source_0 = uhd.usrp_source( ",".join(("addr0=10.11.1.50, addr1=10.11.1.52", "")), uhd.stream_args( cpu_format="sc16", otw_format="sc16", args='', channels=list(range(nchans)), ), ) for mb in range(2): self.uhd_usrp_source_0.set_time_source('external', mb) self.uhd_usrp_source_0.set_clock_source('external', mb) for chan in range(nchans): self.uhd_usrp_source_0.set_center_freq(fc, chan) self.uhd_usrp_source_0.set_gain(gaindB, chan) self.uhd_usrp_source_0.set_antenna('RX2', chan) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_time_unknown_pps(uhd.time_spec()) self.uhd_usrp_source_0.set_time_next_pps( uhd.time_spec(int(time.time()) + 1)) self.uhd_usrp_source_0.set_lo_export_enabled(True, "lo1", 0) self.uhd_usrp_source_0.set_rx_lo_dist(True, "LO_OUT_0") self.uhd_usrp_source_0.set_rx_lo_dist(True, "LO_OUT_1") for chan in range(nchans): self.uhd_usrp_source_0.set_lo_source("external", "lo1", chan) time.sleep(1) self.deinterleaves = [ blocks.deinterleave(gr.sizeof_short * 2, nfft * interleave_block) for _ in range(nchans) ] self.ishort_to_complexs = [[ blocks.interleaved_short_to_complex(True, False) for _ in range(parallel_ffts) ] for _ in range(nchans)] self.stream_to_vectors = [[ blocks.stream_to_vector(gr.sizeof_gr_complex, nfft) for _ in range(parallel_ffts) ] for _ in range(nchans)] self.ffts = [[ fft.fft_vcc(nfft, True, window.rectangular(nfft), True, nthreads) for _ in range(parallel_ffts) ] for _ in range(nchans)] self.powers = [[ blocks.complex_to_mag_squared(nfft) for _ in range(parallel_ffts) ] for _ in range(nchans)] self.power_avgs = [[ blocks.integrate_ff(decim, nfft) for _ in range(parallel_ffts) ] for _ in range(nchans)] self.interleave_powers = [ blocks.interleave(gr.sizeof_float * nfft, interleave_block // decim) for _ in range(nchans) ] self.crossprods = [[ blocks.multiply_conjugate_cc(nfft) for _ in range(parallel_ffts) ] for _ in range(npairs)] self.crossprods_avgs = [[ blocks.integrate_cc(decim, nfft) for _ in range(parallel_ffts) ] for _ in range(npairs)] self.interleave_crossprods = [ blocks.interleave(gr.sizeof_gr_complex * nfft, interleave_block // decim) for _ in range(npairs) ] for chan in range(nchans): self.connect((self.uhd_usrp_source_0, chan), self.deinterleaves[chan]) for j in range(parallel_ffts): self.connect((self.deinterleaves[chan], j), self.ishort_to_complexs[chan][j], self.stream_to_vectors[chan][j], self.ffts[chan][j], self.powers[chan][j], self.power_avgs[chan][j], (self.interleave_powers[chan], j)) pairs = [(j, k) for j in range(nchans) for k in range(j + 1, nchans)] for j, p in enumerate(pairs): for k in range(parallel_ffts): for t in range(2): self.connect(self.ffts[p[t]][k], (self.crossprods[j][k], t)) self.connect(self.crossprods[j][k], self.crossprods_avgs[j][k], (self.interleave_crossprods[j], k))
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 = 16000 ################################################## # Blocks ################################################## self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 1024, #size samp_rate, #samp_rate "", #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(-1, 1) self.qtgui_time_sink_x_0.set_y_label("Amplitude", "") 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_layout.addWidget(self._qtgui_time_sink_x_0_win) self.qtgui_number_sink_1 = qtgui.number_sink( gr.sizeof_float, 0, qtgui.NUM_GRAPH_HORIZ, 1 ) self.qtgui_number_sink_1.set_update_time(0.10) self.qtgui_number_sink_1.set_title("after float") labels = ["", "", "", "", "", "", "", "", "", ""] units = ["", "", "", "", "", "", "", "", "", ""] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_1.set_min(i, -1) self.qtgui_number_sink_1.set_max(i, 1) self.qtgui_number_sink_1.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_1.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_1.set_label(i, labels[i]) self.qtgui_number_sink_1.set_unit(i, units[i]) self.qtgui_number_sink_1.set_factor(i, factor[i]) self.qtgui_number_sink_1.enable_autoscale(False) self._qtgui_number_sink_1_win = sip.wrapinstance(self.qtgui_number_sink_1.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_number_sink_1_win) self.qtgui_number_sink_0 = qtgui.number_sink( gr.sizeof_char, 0, qtgui.NUM_GRAPH_HORIZ, 1 ) self.qtgui_number_sink_0.set_update_time(0.10) self.qtgui_number_sink_0.set_title("") labels = ["", "", "", "", "", "", "", "", "", ""] units = ["", "", "", "", "", "", "", "", "", ""] colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0.set_min(i, -1) self.qtgui_number_sink_0.set_max(i, 1) self.qtgui_number_sink_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0.set_label(i, labels[i]) self.qtgui_number_sink_0.set_unit(i, units[i]) self.qtgui_number_sink_0.set_factor(i, factor[i]) self.qtgui_number_sink_0.enable_autoscale(False) self._qtgui_number_sink_0_win = sip.wrapinstance(self.qtgui_number_sink_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_number_sink_0_win) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_f( 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 float == 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_layout.addWidget(self._qtgui_freq_sink_x_0_win) self.blocks_unpacked_to_packed_xx_1 = blocks.unpacked_to_packed_bb(8, gr.GR_MSB_FIRST) self.blocks_short_to_float_0 = blocks.short_to_float(1, 1) self.blocks_rms_xx_0_0 = blocks.rms_ff(1) self.blocks_rms_xx_0 = blocks.rms_ff(1) self.blocks_null_sink_1 = blocks.null_sink(gr.sizeof_short*1) self.blocks_multiply_xx_0_2 = blocks.multiply_vff(1) self.blocks_multiply_xx_0_1 = blocks.multiply_vff(1) self.blocks_multiply_xx_0_0 = blocks.multiply_vff(1) self.blocks_multiply_xx_0 = blocks.multiply_vff(1) self.blocks_integrate_xx_1 = blocks.integrate_ff(samp_rate/80, 1) self.blocks_integrate_xx_0_1 = blocks.integrate_ff(samp_rate/80, 1) self.blocks_integrate_xx_0_0 = blocks.integrate_ff(samp_rate/80, 1) self.blocks_integrate_xx_0 = blocks.integrate_ff(samp_rate/80, 1) self.blocks_float_to_uchar_0 = blocks.float_to_uchar() self.blocks_file_sink_0_0 = blocks.file_sink(gr.sizeof_char*1, "/home/sidekiq/SDR_output", False) self.blocks_file_sink_0_0.set_unbuffered(True) self.blocks_argmax_xx_0 = blocks.argmax_fs(1) self.blocks_add_xx_0_0 = blocks.add_vff(1) self.blocks_add_xx_0 = blocks.add_vff(1) self.blocks_abs_xx_0_2 = blocks.abs_ff(1) self.blocks_abs_xx_0_1 = blocks.abs_ff(1) self.blocks_abs_xx_0_0 = blocks.abs_ff(1) self.blocks_abs_xx_0 = blocks.abs_ff(1) self.blks2_packet_decoder_0 = grc_blks2.packet_demod_b(grc_blks2.packet_decoder( access_code="11111111", threshold=-1, callback=lambda ok, payload: self.blks2_packet_decoder_0.recv_pkt(ok, payload), ), ) self.audio_source_0 = audio.source(16000, "", True) self.analog_sig_source_x_1 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 1330, 1, 0) self.analog_sig_source_x_0_1 = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, 1330, 1, 0) self.analog_sig_source_x_0_0 = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, 2720, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 2720, 1, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0_2, 0)) self.connect((self.analog_sig_source_x_0_1, 0), (self.blocks_multiply_xx_0_1, 0)) self.connect((self.analog_sig_source_x_1, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.audio_source_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.audio_source_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.audio_source_0, 0), (self.blocks_multiply_xx_0_1, 1)) self.connect((self.audio_source_0, 0), (self.blocks_multiply_xx_0_2, 1)) self.connect((self.audio_source_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.audio_source_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blks2_packet_decoder_0, 0), (self.blocks_unpacked_to_packed_xx_1, 0)) self.connect((self.blocks_abs_xx_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_abs_xx_0_0, 0), (self.blocks_add_xx_0_0, 0)) self.connect((self.blocks_abs_xx_0_1, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_abs_xx_0_2, 0), (self.blocks_add_xx_0_0, 1)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_rms_xx_0, 0)) self.connect((self.blocks_add_xx_0_0, 0), (self.blocks_rms_xx_0_0, 0)) self.connect((self.blocks_argmax_xx_0, 0), (self.blocks_null_sink_1, 0)) self.connect((self.blocks_argmax_xx_0, 1), (self.blocks_short_to_float_0, 0)) self.connect((self.blocks_float_to_uchar_0, 0), (self.blks2_packet_decoder_0, 0)) self.connect((self.blocks_float_to_uchar_0, 0), (self.qtgui_number_sink_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_abs_xx_0_2, 0)) self.connect((self.blocks_integrate_xx_0_0, 0), (self.blocks_abs_xx_0, 0)) self.connect((self.blocks_integrate_xx_0_1, 0), (self.blocks_abs_xx_0_0, 0)) self.connect((self.blocks_integrate_xx_1, 0), (self.blocks_abs_xx_0_1, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_integrate_xx_1, 0)) self.connect((self.blocks_multiply_xx_0_1, 0), (self.blocks_integrate_xx_0_1, 0)) self.connect((self.blocks_multiply_xx_0_2, 0), (self.blocks_integrate_xx_0_0, 0)) self.connect((self.blocks_rms_xx_0, 0), (self.blocks_argmax_xx_0, 1)) self.connect((self.blocks_rms_xx_0_0, 0), (self.blocks_argmax_xx_0, 0)) self.connect((self.blocks_short_to_float_0, 0), (self.blocks_float_to_uchar_0, 0)) self.connect((self.blocks_short_to_float_0, 0), (self.qtgui_number_sink_1, 0)) self.connect((self.blocks_unpacked_to_packed_xx_1, 0), (self.blocks_file_sink_0_0, 0))
def __init__(self): gr.top_block.__init__(self, "Pulsar Channelizer") Qt.QWidget.__init__(self) self.setWindowTitle("Pulsar Channelizer") qtgui.util.check_set_qss() 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", "PulsChan") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.scale = scale = float(sys.argv[7]) self.samp_rate = samp_rate = float(sys.argv[2]) self.filename = filename = sys.argv[8] self.fft_size = fft_size = int(sys.argv[5]) self.decimation = decimation = int(sys.argv[6]) self.RFGain = RFGain = float(sys.argv[4]) self.IFGain = IFGain = 12 self.n_buffer = n_buffer = 26000 self.Freq = Freq = float(sys.argv[3]) self.ACQ_TIME = ACQ_TIME = int(sys.argv[1]) print(len(sys.argv)) print(ACQ_TIME) print(samp_rate) print(Freq) print(RFGain) print(fft_size) print(decimation) print(scale) print(filename) ################################################## # Blocks ################################################## self.qtgui_vector_sink_f_0 = qtgui.vector_sink_f( fft_size / decimation, 0, 1, "CH", "POWER", "", 1 # Number of inputs ) self.qtgui_vector_sink_f_0.set_update_time(0.2) self.qtgui_vector_sink_f_0.set_y_axis(0, 32767) self.qtgui_vector_sink_f_0.enable_autoscale(False) self.qtgui_vector_sink_f_0.enable_grid(True) self.qtgui_vector_sink_f_0.set_x_axis_units("") self.qtgui_vector_sink_f_0.set_y_axis_units("") self.qtgui_vector_sink_f_0.set_ref_level(0) 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_vector_sink_f_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_vector_sink_f_0.set_line_label(i, labels[i]) self.qtgui_vector_sink_f_0.set_line_width(i, widths[i]) self.qtgui_vector_sink_f_0.set_line_color(i, colors[i]) self.qtgui_vector_sink_f_0.set_line_alpha(i, alphas[i]) self._qtgui_vector_sink_f_0_win = sip.wrapinstance( self.qtgui_vector_sink_f_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_vector_sink_f_0_win) self.qtgui_const_sink_x_0 = qtgui.const_sink_c( fft_size, #size "", #name 1 #number of inputs ) self.qtgui_const_sink_x_0.set_update_time(0.20) self.qtgui_const_sink_x_0.set_y_axis(-1, 1) self.qtgui_const_sink_x_0.set_x_axis(-1, 1) self.qtgui_const_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0.enable_autoscale(False) self.qtgui_const_sink_x_0.enable_grid(False) self.qtgui_const_sink_x_0.enable_axis_labels(True) if not True: self.qtgui_const_sink_x_0.disable_legend() labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "red", "red", "red", "red", "red", "red", "red", "red" ] styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] 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_const_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_win = sip.wrapinstance( self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_const_sink_x_0_win) self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + '') self.osmosdr_source_0.set_clock_source('internal', 0) self.osmosdr_source_0.set_sample_rate(samp_rate) self.osmosdr_source_0.set_center_freq(Freq * 1e6, 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(RFGain, 0) self.osmosdr_source_0.set_if_gain(IFGain, 0) self.osmosdr_source_0.set_bb_gain(0, 0) self.osmosdr_source_0.set_antenna('', 0) self.osmosdr_source_0.set_bandwidth(0, 0) self.osmosdr_source_0.set_min_output_buffer(n_buffer) self.fft_vxx_0 = fft.fft_vcc(fft_size, True, (window.rectangular(fft_size)), True, 1) self.fft_vxx_0.set_min_output_buffer(n_buffer) self.blocks_vector_to_stream_0 = blocks.vector_to_stream( gr.sizeof_gr_complex * 1, fft_size) self.blocks_vector_to_stream_0.set_min_output_buffer(n_buffer) self.blocks_stream_to_vector_0_0 = blocks.stream_to_vector( gr.sizeof_float * 1, fft_size / decimation) self.blocks_stream_to_vector_0_0.set_min_output_buffer(n_buffer) self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, fft_size) self.blocks_stream_to_vector_0.set_min_output_buffer(n_buffer) self.blocks_short_to_float_0 = blocks.short_to_float(1, 1) self.blocks_short_to_float_0.set_min_output_buffer(n_buffer) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff( (1000 / decimation, )) self.blocks_short_to_float_0.set_min_output_buffer(n_buffer) self.blocks_integrate_xx_0 = blocks.integrate_ff(decimation, 1) self.blocks_integrate_xx_0.set_min_output_buffer(n_buffer) self.blocks_float_to_short_0 = blocks.float_to_short(1, scale) self.blocks_float_to_short_0.set_min_output_buffer(n_buffer) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_short * 1, filename, False) self.blocks_file_sink_0.set_min_output_buffer(n_buffer) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1) self.blocks_complex_to_mag_0.set_min_output_buffer(n_buffer) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_mag_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_float_to_short_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_float_to_short_0, 0), (self.blocks_short_to_float_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_float_to_short_0, 0)) self.connect((self.blocks_short_to_float_0, 0), (self.blocks_stream_to_vector_0_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) self.connect((self.blocks_stream_to_vector_0_0, 0), (self.qtgui_vector_sink_f_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.osmosdr_source_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.qtgui_const_sink_x_0, 0)) self.start(10000000) import threading threading.Timer(ACQ_TIME, self.kill_process).start()
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 = 15e6 self.integration_bandwidth = integration_bandwidth = 2.5e3 self.if_bandwidth_2 = if_bandwidth_2 = .75e6 self.dec_rate_1 = dec_rate_1 = 5 self.samp_rate_2 = samp_rate_2 = samp_rate / dec_rate_1 self.num_channels = num_channels = int(if_bandwidth_2 / integration_bandwidth) self.samp_rate_3 = samp_rate_3 = samp_rate_2 / num_channels self.integration_time = integration_time = .5 self.variable_function_probe = variable_function_probe = 0 self.output_samp_rate = output_samp_rate = 1.0 / integration_time self.integration_dec_rate = integration_dec_rate = int( integration_time * samp_rate_3 / 2) self.if_bandwidth_0 = if_bandwidth_0 = 4.5e6 self.gain = gain = 60 self.freq = freq = 1.4204e9 self.channel_map = channel_map = range( int(num_channels / 2.0 + 1.0), num_channels, 1) + range( 0, int(num_channels / 2.0 + 1.0), 1) ################################################## # Blocks ################################################## self.probe_signal = blocks.probe_signal_vf(num_channels) self._gain_range = Range(0, 70, 1, 60, 200) self._gain_win = RangeWidget(self._gain_range, self.set_gain, "gain", "counter_slider", int) self.top_layout.addWidget(self._gain_win) def _variable_function_probe_probe(): while True: val = self.probe_signal.level() try: self.set_variable_function_probe(val) except AttributeError: pass pytime.sleep(1.0 / (10)) _variable_function_probe_thread = threading.Thread( target=_variable_function_probe_probe) _variable_function_probe_thread.daemon = True _variable_function_probe_thread.start() self.pfb_channelizer_ccf_0 = pfb.channelizer_ccf( num_channels, (firdes.low_pass(1, samp_rate_2, integration_bandwidth, 250, firdes.WIN_HAMMING)), 1.0, 0) self.pfb_channelizer_ccf_0.set_channel_map((channel_map)) self.pfb_channelizer_ccf_0.declare_sample_delay(0) self.low_pass_filter_1 = filter.fir_filter_ccf( dec_rate_1, firdes.low_pass(10, samp_rate, if_bandwidth_2, 1e5, firdes.WIN_HAMMING, 6.76)) self.limesdr_source_2 = limesdr.source('0009072C02873717', 2, 1, 0, 0, '', freq - 800e3, samp_rate, 0, 1, 15e6, 0, 10e6, 3, 2, 2, 1, if_bandwidth_0, 1, 5e6, 1, if_bandwidth_0, 0, 0, gain, 30, 0, 0, 0, 0) self.blocks_streams_to_vector_0 = blocks.streams_to_vector( gr.sizeof_gr_complex * 1, num_channels) self.blocks_multiply_xx_1 = blocks.multiply_vcc(1) self.blocks_integrate_xx_0_0 = blocks.integrate_ff( integration_dec_rate, num_channels) self.blocks_file_sink_0 = blocks.file_sink( gr.sizeof_gr_complex * 1, '/home/w1xm-admin/Documents/DSP/data_out/recieve_block_sink', False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_copy_0_0 = blocks.copy(gr.sizeof_gr_complex * 1) self.blocks_copy_0_0.set_enabled(False) self.blocks_copy_0 = blocks.copy(gr.sizeof_gr_complex * 1) self.blocks_copy_0.set_enabled(True) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared( num_channels) self.analog_sig_source_x_0 = analog.sig_source_c( samp_rate, analog.GR_SIN_WAVE, -800e3, 1, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_1, 1)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_integrate_xx_0_0, 0)) self.connect((self.blocks_copy_0, 0), (self.blocks_multiply_xx_1, 0)) self.connect((self.blocks_copy_0_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_integrate_xx_0_0, 0), (self.probe_signal, 0)) self.connect((self.blocks_multiply_xx_1, 0), (self.low_pass_filter_1, 0)) self.connect((self.blocks_streams_to_vector_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.limesdr_source_2, 0), (self.blocks_copy_0, 0)) self.connect((self.limesdr_source_2, 0), (self.blocks_copy_0_0, 0)) self.connect((self.low_pass_filter_1, 0), (self.pfb_channelizer_ccf_0, 0)) for i in range(num_channels): self.connect((self.pfb_channelizer_ccf_0, i), (self.blocks_streams_to_vector_0, i))
def __init__(self): # Call the initialization method from the parent class gr.top_block.__init__(self) # Setup the parser for command line arguments parser = OptionParser(option_class=eng_option) parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="print settings to stdout") parser.add_option("-f", "--frequency", type="eng_float", dest="rx_freq", default=98.9E6, help="RX frequency in Hz") parser.add_option("-a", "--args", type="string", dest="uhd_args", default='type=b200', help="USRP device args") parser.add_option("-c", "--cal", type="eng_float", dest="rssi_cal_offset_dB", default=-50, help="RSSI calibration offset in dB") parser.add_option("-g", "--gain", type="eng_float", dest="src_gain_dB", default=50, help="USRP gain in dB") parser.add_option("-V", "--volume", type="eng_float", dest="volume_dB", default=30, help="Audio volume in dB") parser.add_option("-s", "--soundrate", type="eng_float", dest="snd_card_rate", default=48000, help="Sound card rate in Hz") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit, 1 # Define constants uhd_args = options.uhd_args self.rx_freq = options.rx_freq lo_offset_freq = 125E3 src_samp_rate = 500000 src_gain_dB = options.src_gain_dB rssi_cal_offset_dB = -50 volume_dB = options.volume_dB snd_card_rate = options.snd_card_rate # Print some info to stdout for verbose option if options.verbose: print 'USRP args string "%s" ' % uhd_args print 'RX frequency = %f MHz' % (self.rx_freq / 1E6) print 'Source sample rate = %i Hz' % src_samp_rate print 'USRP gain = %i dB' % src_gain_dB print 'RSSI cal offset= %i dB' % rssi_cal_offset_dB print 'Audio volume = %i dB' % volume_dB print 'Sound card rate = %i Hz' % snd_card_rate # Setup the USRP source self.src = uhd.usrp_source(uhd_args, uhd.io_type_t.COMPLEX_FLOAT32, 1) self.src.set_samp_rate(src_samp_rate) self.src.set_center_freq(self.rx_freq - lo_offset_freq, 0) self.src.set_gain(src_gain_dB, 0) # Generate taps for frequency translating FIR filter filter_taps = filter.firdes.low_pass(gain=1.0, sampling_freq=src_samp_rate, cutoff_freq=100E3, transition_width=25E3, window=filter.firdes.WIN_HAMMING) # Frequency translating FIR filter fxlate = filter.freq_xlating_fir_filter_ccc( decimation=2, taps=filter_taps, center_freq=lo_offset_freq, sampling_freq=src_samp_rate) # Wideband FM demodulator wbfm = analog.fm_demod_cf(channel_rate=src_samp_rate / 2, audio_decim=5, deviation=75000, audio_pass=15000, audio_stop=16000, gain=1.0, tau=75E-6) # Rational resampler resamp = filter.rational_resampler_fff(interpolation=snd_card_rate, decimation=src_samp_rate / 10) # Multiply for voulme control volume = blocks.multiply_const_ff(10**(volume_dB / 20) - 1) # Sound card sink sndcard = audio.sink(snd_card_rate, '', True) # Connect the blocks for audio monitoring self.connect(self.src, fxlate, wbfm, resamp, volume, sndcard) # Calculate power for RSSI c2magsqr = blocks.complex_to_mag_squared(1) # Integrate for mean power and decimate down to 1 Hz integrator = blocks.integrate_ff(decim=src_samp_rate / 2) # Take 10*Log10 and offset for calibrated power and src gain logten = blocks.nlog10_ff(10, 1, rssi_cal_offset_dB - src_gain_dB) # Probe the RSSI signal self.rssi = blocks.probe_signal_f() # Connect the blocks for the RSSI self.connect(fxlate, c2magsqr, integrator, logten, self.rssi)
def __init__(self, bins=4096, display_integration=2, freq=150e6, gain=20, minutes=10, samp_rate=50e6): gr.top_block.__init__(self, "B210 2") ################################################## # Parameters ################################################## self.bins = bins self.display_integration = display_integration self.freq = freq self.gain = gain self.minutes = minutes self.samp_rate = samp_rate ################################################## # Variables ################################################## self.timenow = timenow = datetime.now().strftime("%Y%m%d_%H%M%S") self.prefix = prefix = "/home/ggancio/obs/gnur/" self.raw = raw = prefix + timenow + "_" + str(bins) + "_" + str( samp_rate / 1e6) + "_" + str(freq / 1e6) + "_raw.dat" ################################################## # Blocks ################################################## self.uhd_usrp_source_0 = uhd.usrp_source( ",".join(("", '')), uhd.stream_args( cpu_format="sc16", otw_format='sc8', channels=range(1), ), ) self.uhd_usrp_source_0.set_clock_source('external', 0) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_time_now(uhd.time_spec(time.time()), uhd.ALL_MBOARDS) self.uhd_usrp_source_0.set_center_freq(freq, 0) self.uhd_usrp_source_0.set_gain(gain, 0) self.uhd_usrp_source_0.set_bandwidth(samp_rate, 0) self.fft_vxx_0 = fft.fft_vcc(bins, True, (window.blackmanharris(bins)), True, 1) self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, bins) self.blocks_nlog10_ff_0_0 = blocks.nlog10_ff(10, bins, 0) self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc( bins) self.blocks_interleaved_short_to_complex_0 = blocks.interleaved_short_to_complex( True, False) self.blocks_integrate_xx_0 = blocks.integrate_ff( int(display_integration * samp_rate / bins), bins) self.blocks_head_0 = blocks.head(gr.sizeof_gr_complex * 1, int(minutes * 60 * (samp_rate))) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_float * bins, raw, False) self.blocks_file_sink_0.set_unbuffered(True) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared( bins) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_head_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_nlog10_ff_0_0, 0)) self.connect((self.blocks_interleaved_short_to_complex_0, 0), (self.blocks_head_0, 0)) self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.blocks_nlog10_ff_0_0, 0), (self.blocks_file_sink_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_multiply_conjugate_cc_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_multiply_conjugate_cc_0, 1)) self.connect((self.uhd_usrp_source_0, 0), (self.blocks_interleaved_short_to_complex_0, 0))
def __init__(self): gr.top_block.__init__(self) options = get_options() self.ifreq = options.frequency self.rfgain = options.gain self.src = osmosdr.source(options.args) self.src.set_center_freq(self.ifreq) self.src.set_sample_rate(int(options.sample_rate)) if self.rfgain is None: self.src.set_gain_mode(1) self.iagc = 1 self.rfgain = 0 else: self.iagc = 0 self.src.set_gain_mode(0) self.src.set_gain(self.rfgain) # may differ from the requested rate sample_rate = self.src.get_sample_rate() sys.stderr.write("sample rate: %d\n" % (sample_rate)) bitrate = 8000 first_decim = 125 out_sample_rate = sample_rate / first_decim sys.stderr.write("output sample rate: %d\n" % (out_sample_rate)) sps = out_sample_rate / bitrate sys.stderr.write("samples per symbol: %d\n" % (sps)) self.offset = options.offset sys.stderr.write("offset is: %dHz\n" % self.offset) taps = filter.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.2, filter.firdes.WIN_HANN) self.tuner = filter.freq_xlating_fir_filter_ccf( first_decim, taps, self.offset, sample_rate) self.demod = digital.gmsk_demod(samples_per_symbol=sps) self.output = blocks.file_sink(gr.sizeof_char, options.output_file) self.connect((self.src, 0), (self.tuner, 0)) self.connect((self.tuner, 0), (self.demod, 0)) self.connect((self.demod, 0), (self.output, 0)) self.fm_demod = analog.fm_demod_cf(sample_rate / first_decim, 1, 5000, 3000, 4000) self.integrate = blocks.integrate_ff(32000) self.probe = blocks.probe_signal_f() self.connect((self.tuner, 0), (self.fm_demod, 0)) self.connect((self.fm_demod, 0), (self.integrate, 0)) self.connect((self.integrate, 0), (self.probe, 0)) def _variable_function_probe_0_probe(): while True: freq = self.tuner.center_freq() freq2 = freq + 0.2 * self.probe.level() print "Autotune: fix=%f old=%i new=%i" % ( self.probe.level(), self.ifreq + freq, self.ifreq + freq2) self.tuner.set_center_freq(freq2) time.sleep(5.0) _variable_function_probe_0_thread = threading.Thread( target=_variable_function_probe_0_probe) _variable_function_probe_0_thread.daemon = True _variable_function_probe_0_thread.start()
def __init__(self): gr.top_block.__init__(self, "A1 Add Pol") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 50e6 self.display_integration = display_integration = 1 self.bins = bins = 4096 ################################################## # Blocks ################################################## self.uhd_usrp_source_0_0 = uhd.usrp_source( ",".join(("", "serial=314F813")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0_0.set_clock_source('external', 0) self.uhd_usrp_source_0_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0_0.set_time_now(uhd.time_spec(time.time()), uhd.ALL_MBOARDS) self.uhd_usrp_source_0_0.set_center_freq(155e6, 0) self.uhd_usrp_source_0_0.set_gain(20, 0) self.uhd_usrp_source_0_0.set_bandwidth(samp_rate, 0) self.uhd_usrp_source_0 = uhd.usrp_source( ",".join(("", '')), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_clock_source('external', 0) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_time_now(uhd.time_spec(time.time()), uhd.ALL_MBOARDS) self.uhd_usrp_source_0.set_center_freq(155e6, 0) self.uhd_usrp_source_0.set_gain(20, 0) self.uhd_usrp_source_0.set_bandwidth(samp_rate, 0) self.fft_vxx_0_1 = fft.fft_vcc(bins, True, (window.blackmanharris(bins)), True, 1) self.fft_vxx_0 = fft.fft_vcc(bins, True, (window.blackmanharris(bins)), True, 1) self.blocks_vector_to_stream_0 = blocks.vector_to_stream( gr.sizeof_float * 1, bins) self.blocks_udp_sink_0 = blocks.udp_sink(gr.sizeof_float * 1, '163.10.43.84', 7124, 1024, True) self.blocks_stream_to_vector_0_1 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, bins) self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, bins) self.blocks_repeat_0_0_0_0 = blocks.repeat(gr.sizeof_float * bins, 10) self.blocks_repeat_0_0_0 = blocks.repeat(gr.sizeof_float * bins, 10) self.blocks_integrate_xx_0_1 = blocks.integrate_ff( int(display_integration * samp_rate / bins), bins) self.blocks_integrate_xx_0 = blocks.integrate_ff( int(display_integration * samp_rate / bins), bins) self.blocks_complex_to_mag_squared_0_1 = blocks.complex_to_mag_squared( bins) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared( bins) self.blocks_add_xx_0 = blocks.add_vff(bins) ################################################## # Connections ################################################## self.connect((self.blocks_add_xx_0, 0), (self.blocks_vector_to_stream_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0_1, 0), (self.blocks_integrate_xx_0_1, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_repeat_0_0_0, 0)) self.connect((self.blocks_integrate_xx_0_1, 0), (self.blocks_repeat_0_0_0_0, 0)) self.connect((self.blocks_repeat_0_0_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_repeat_0_0_0_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) self.connect((self.blocks_stream_to_vector_0_1, 0), (self.fft_vxx_0_1, 0)) self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_udp_sink_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.fft_vxx_0_1, 0), (self.blocks_complex_to_mag_squared_0_1, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.uhd_usrp_source_0_0, 0), (self.blocks_stream_to_vector_0_1, 0))
def __init__(self): gr.top_block.__init__(self, "vor_record_sigmf") Qt.QWidget.__init__(self) self.setWindowTitle("vor_record_sigmf") qtgui.util.check_set_qss() 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", "vor_playback_sigmf") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.throttle_rate = throttle_rate = 1 self.samp_rate = samp_rate = 250e3 self.fine = fine = 0 self.decim = decim = 5 self.audio_gain_30hz = audio_gain_30hz = 1 self.alpha = alpha = .02 ################################################## # Blocks ################################################## self._throttle_rate_tool_bar = Qt.QToolBar(self) self._throttle_rate_tool_bar.addWidget( Qt.QLabel("throttle_rate" + ": ")) self._throttle_rate_line_edit = Qt.QLineEdit(str(self.throttle_rate)) self._throttle_rate_tool_bar.addWidget(self._throttle_rate_line_edit) self._throttle_rate_line_edit.returnPressed.connect( lambda: self.set_throttle_rate( eng_notation.str_to_num( str(self._throttle_rate_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._throttle_rate_tool_bar, 0, 6, 1, 2) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(6, 8): self.top_grid_layout.setColumnStretch(c, 1) self._samp_rate_tool_bar = Qt.QToolBar(self) self._samp_rate_tool_bar.addWidget(Qt.QLabel("samp_rate" + ": ")) self._samp_rate_line_edit = Qt.QLineEdit(str(self.samp_rate)) self._samp_rate_tool_bar.addWidget(self._samp_rate_line_edit) self._samp_rate_line_edit.returnPressed.connect( lambda: self.set_samp_rate( eng_notation.str_to_num( str(self._samp_rate_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._samp_rate_tool_bar, 0, 4, 1, 2) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 6): self.top_grid_layout.setColumnStretch(c, 1) self._fine_tool_bar = Qt.QToolBar(self) self._fine_tool_bar.addWidget(Qt.QLabel('Fine [Hz]' + ": ")) self._fine_line_edit = Qt.QLineEdit(str(self.fine)) self._fine_tool_bar.addWidget(self._fine_line_edit) self._fine_line_edit.returnPressed.connect(lambda: self.set_fine( eng_notation.str_to_num(str(self._fine_line_edit.text().toAscii())) )) self.top_grid_layout.addWidget(self._fine_tool_bar, 1, 4, 1, 2) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 6): self.top_grid_layout.setColumnStretch(c, 1) self.sigmf_source_0 = gr_sigmf.source( '/captures/20191216/VOR_2019-12-16T18:51:17Z.sigmf-data', "cf32" + ("_le" if sys.byteorder == "little" else "_be"), False) self.rational_resampler_xxx_2 = filter.rational_resampler_fff( interpolation=66, decimation=1, taps=None, fractional_bw=None, ) self.rational_resampler_xxx_1 = filter.rational_resampler_fff( interpolation=66, decimation=1, taps=None, fractional_bw=None, ) self.rational_resampler_xxx_0_0_0 = filter.rational_resampler_ccc( interpolation=24, decimation=25, taps=None, fractional_bw=None, ) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=1, decimation=decim, taps=None, fractional_bw=None, ) self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate / decim, #bw "", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_0.set_update_time(0.010) self.qtgui_waterfall_sink_x_0.enable_grid(False) self.qtgui_waterfall_sink_x_0.enable_axis_labels(True) if not True: self.qtgui_waterfall_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_waterfall_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] colors = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] 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_waterfall_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_0.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_0.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_0.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_0.set_intensity_range(-140, 10) self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance( self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_0_win, 4, 0, 4, 4) for r in range(4, 8): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 4): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_time_sink_x_0_0 = qtgui.time_sink_f( 1024, #size samp_rate / decim / 25 * 24, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_0_0.set_update_time(0.0010) self.qtgui_time_sink_x_0_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0_0.enable_tags(-1, True) self.qtgui_time_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_NORM, qtgui.TRIG_SLOPE_POS, 0, 0, 0, "") self.qtgui_time_sink_x_0_0.enable_autoscale(False) self.qtgui_time_sink_x_0_0.enable_grid(True) self.qtgui_time_sink_x_0_0.enable_axis_labels(True) self.qtgui_time_sink_x_0_0.enable_control_panel(False) self.qtgui_time_sink_x_0_0.enable_stem_plot(False) if not True: self.qtgui_time_sink_x_0_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_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_0_win, 6, 4, 2, 4) for r in range(6, 8): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 8): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 8192, #size samp_rate / decim / 25 * 24, #samp_rate "30 Hz Variable", #name 2 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.0010) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0.enable_tags(-1, True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_NORM, qtgui.TRIG_SLOPE_POS, 0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(False) self.qtgui_time_sink_x_0.enable_grid(True) self.qtgui_time_sink_x_0.enable_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(False) self.qtgui_time_sink_x_0.enable_stem_plot(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(2): 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, 4, 4, 2, 4) for r in range(4, 6): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 8): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_freq_sink_x_1 = qtgui.freq_sink_f( 4096, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate / decim / 25 * 24, #bw "", #name 1 #number of inputs ) self.qtgui_freq_sink_x_1.set_update_time(0.10) self.qtgui_freq_sink_x_1.set_y_axis(-140, 10) self.qtgui_freq_sink_x_1.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_1.enable_autoscale(False) self.qtgui_freq_sink_x_1.enable_grid(False) self.qtgui_freq_sink_x_1.set_fft_average(1.0) self.qtgui_freq_sink_x_1.enable_axis_labels(True) self.qtgui_freq_sink_x_1.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_1.disable_legend() if "float" == "float" or "float" == "msg_float": self.qtgui_freq_sink_x_1.set_plot_pos_half(not False) 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_1.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_1.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_1.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_1.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_1.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_1_win = sip.wrapinstance( self.qtgui_freq_sink_x_1.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_1_win, 0, 0, 4, 4) for r in range(0, 4): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 4): self.top_grid_layout.setColumnStretch(c, 1) self.low_pass_filter_0_0 = filter.fir_filter_fff( 1, firdes.low_pass(10, samp_rate / decim / 25 * 24, 1e3, 500, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0 = filter.fir_filter_fff( 1, firdes.low_pass(1, 48e3, 1, 1, firdes.WIN_HAMMING, 6.76)) self.dc_blocker_xx_0_0 = filter.dc_blocker_ff(1024, True) self.dc_blocker_xx_0 = filter.dc_blocker_ff(1024, True) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate * throttle_rate, True) self.blocks_multiply_xx_3 = blocks.multiply_vff(1) self.blocks_multiply_xx_2 = blocks.multiply_vff(1) self.blocks_multiply_xx_1 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_integrate_xx_2 = blocks.integrate_ff(66, 1) self.blocks_integrate_xx_0 = blocks.integrate_ff(66, 1) self.blocks_float_to_complex_2 = blocks.float_to_complex(1) self.blocks_float_to_complex_1 = blocks.float_to_complex(1) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_divide_xx_0_0 = blocks.divide_ff(1) self.blocks_divide_xx_0 = blocks.divide_ff(1) self.blocks_delay_1 = blocks.delay(gr.sizeof_float * 1, 0) self.blocks_delay_0 = blocks.delay(gr.sizeof_float * 1, 0) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) self.band_pass_filter_0_0 = filter.fir_filter_fff( 1, firdes.band_pass(1, samp_rate / decim / 25 * 24, 25, 35, 5, firdes.WIN_HAMMING, 6.76)) self.band_pass_filter_0 = filter.fir_filter_fff( 1, firdes.band_pass(1, samp_rate / decim / 25 * 24, 25, 35, 5, firdes.WIN_HAMMING, 6.76)) self._audio_gain_30hz_tool_bar = Qt.QToolBar(self) self._audio_gain_30hz_tool_bar.addWidget(Qt.QLabel('vol30' + ": ")) self._audio_gain_30hz_line_edit = Qt.QLineEdit( str(self.audio_gain_30hz)) self._audio_gain_30hz_tool_bar.addWidget( self._audio_gain_30hz_line_edit) self._audio_gain_30hz_line_edit.returnPressed.connect( lambda: self.set_audio_gain_30hz( eng_notation.str_to_num( str(self._audio_gain_30hz_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._audio_gain_30hz_tool_bar, 1, 7, 1, 1) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(7, 8): self.top_grid_layout.setColumnStretch(c, 1) self.analog_sig_source_x_1 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, 9960, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, -1 * fine, 1, 0) self.analog_pll_carriertracking_cc_0 = analog.pll_carriertracking_cc( math.pi / 200, math.pi / 10, -math.pi / 10) self.analog_fm_demod_cf_0 = analog.fm_demod_cf( channel_rate=samp_rate / decim / 25 * 24, audio_decim=1, deviation=1e3, audio_pass=100, audio_stop=200, gain=1.0, tau=75e-6, ) self.analog_const_source_x_0 = analog.sig_source_f( 0, analog.GR_CONST_WAVE, 0, 0, 0) self.analog_am_demod_cf_0 = analog.am_demod_cf( channel_rate=48e3, audio_decim=1, audio_pass=12000, audio_stop=13000, ) self.analog_agc2_xx_0 = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0.set_max_gain(65536) self._alpha_tool_bar = Qt.QToolBar(self) self._alpha_tool_bar.addWidget(Qt.QLabel('alpha' + ": ")) self._alpha_line_edit = Qt.QLineEdit(str(self.alpha)) self._alpha_tool_bar.addWidget(self._alpha_line_edit) self._alpha_line_edit.returnPressed.connect(lambda: self.set_alpha( eng_notation.str_to_num(str(self._alpha_line_edit.text().toAscii()) ))) self.top_grid_layout.addWidget(self._alpha_tool_bar, 1, 6, 1, 1) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(6, 7): self.top_grid_layout.setColumnStretch(c, 1) ################################################## # Connections ################################################## self.connect((self.analog_agc2_xx_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.analog_am_demod_cf_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.analog_am_demod_cf_0, 0), (self.low_pass_filter_0_0, 0)) self.connect((self.analog_am_demod_cf_0, 0), (self.qtgui_freq_sink_x_1, 0)) self.connect((self.analog_const_source_x_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.analog_fm_demod_cf_0, 0), (self.band_pass_filter_0_0, 0)) self.connect((self.analog_pll_carriertracking_cc_0, 0), (self.rational_resampler_xxx_0_0_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.analog_sig_source_x_1, 0), (self.blocks_multiply_xx_1, 1)) self.connect((self.band_pass_filter_0, 0), (self.dc_blocker_xx_0, 0)) self.connect((self.band_pass_filter_0_0, 0), (self.dc_blocker_xx_0_0, 0)) self.connect((self.blocks_complex_to_arg_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_divide_xx_0, 1)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_divide_xx_0_0, 1)) self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_xx_3, 0)) self.connect((self.blocks_delay_1, 0), (self.blocks_multiply_xx_2, 1)) self.connect((self.blocks_divide_xx_0, 0), (self.blocks_float_to_complex_2, 0)) self.connect((self.blocks_divide_xx_0_0, 0), (self.blocks_float_to_complex_2, 1)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_multiply_xx_1, 0)) self.connect((self.blocks_float_to_complex_1, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.blocks_float_to_complex_2, 0), (self.blocks_complex_to_arg_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.rational_resampler_xxx_1, 0)) self.connect((self.blocks_integrate_xx_2, 0), (self.rational_resampler_xxx_2, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.analog_agc2_xx_0, 0)) self.connect((self.blocks_multiply_xx_1, 0), (self.analog_fm_demod_cf_0, 0)) self.connect((self.blocks_multiply_xx_2, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_multiply_xx_3, 0), (self.blocks_integrate_xx_2, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.dc_blocker_xx_0, 0), (self.blocks_delay_0, 0)) self.connect((self.dc_blocker_xx_0, 0), (self.blocks_multiply_xx_2, 0)) self.connect((self.dc_blocker_xx_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.dc_blocker_xx_0_0, 0), (self.blocks_delay_1, 0)) self.connect((self.dc_blocker_xx_0_0, 0), (self.blocks_multiply_xx_3, 1)) self.connect((self.dc_blocker_xx_0_0, 0), (self.qtgui_time_sink_x_0, 1)) self.connect((self.low_pass_filter_0, 0), (self.qtgui_time_sink_x_0_0, 0)) self.connect((self.low_pass_filter_0_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.analog_pll_carriertracking_cc_0, 0)) self.connect((self.rational_resampler_xxx_0_0_0, 0), (self.analog_am_demod_cf_0, 0)) self.connect((self.rational_resampler_xxx_0_0_0, 0), (self.qtgui_waterfall_sink_x_0, 0)) self.connect((self.rational_resampler_xxx_1, 0), (self.blocks_divide_xx_0, 0)) self.connect((self.rational_resampler_xxx_1, 0), (self.blocks_float_to_complex_1, 0)) self.connect((self.rational_resampler_xxx_2, 0), (self.blocks_divide_xx_0_0, 0)) self.connect((self.rational_resampler_xxx_2, 0), (self.blocks_float_to_complex_1, 1)) self.connect((self.sigmf_source_0, 0), (self.blocks_throttle_0, 0))
def __init__( self, parent, baseband_freq=0, ref_scale=2.0, y_per_div=10, y_divs=8, ref_level=50, sample_rate=1, fft_size=512, fft_rate=fft_window.DEFAULT_FRAME_RATE, average=False, avg_alpha=None, title='', size=fft_window.DEFAULT_WIN_SIZE, peak_hold=False, win=None, use_persistence=False, persist_alpha=None, **kwargs #do not end with a comma ): #ensure avg alpha if avg_alpha is None: avg_alpha = 2.0/fft_rate #ensure analog alpha if persist_alpha is None: actual_fft_rate=float(sample_rate/fft_size)/float(max(1,int(float((sample_rate/fft_size)/fft_rate)))) #print "requested_fft_rate ",fft_rate #print "actual_fft_rate ",actual_fft_rate analog_cutoff_freq=0.5 # Hertz #calculate alpha from wanted cutoff freq persist_alpha = 1.0 - math.exp(-2.0*math.pi*analog_cutoff_freq/actual_fft_rate) #init gr.hier_block2.__init__( self, "fft_sink", gr.io_signature(1, 1, self._item_size), gr.io_signature(0, 0, 0), ) self.integrating = integrating = 0 #blocks self.fft = self._fft_chain( sample_rate=sample_rate, fft_size=fft_size, frame_rate=fft_rate, ref_scale=ref_scale, avg_alpha=avg_alpha, average=average, win=win, ) msgq = gr.msg_queue(2) sink = blocks.message_sink(gr.sizeof_float*fft_size, msgq, True) # For graphical display only self._log=self.fft.get_log() # For saving data (integration) int_filename="integration_data2.txt" self.vect2str= blocks.vector_to_stream(gr.sizeof_float*1, fft_size) self.integrate = blocks.integrate_ff(fft_size, 1) self.file_sink_int= blocks.file_sink(gr.sizeof_float*1, int_filename, False) #controls data streaming #self.integrating=1 #if the valve is open (1) or closed (0). Open valve stops data #self._valve = grc_blks2.valve(item_size=gr.sizeof_float*1, open=bool(self.integrating)) # self.selec = grc_blks2.selector( #item_size=gr.sizeof_float*1, # num_inputs=2, # num_outputs=2, # input_index=integrating, # output_index=integrating, #) #just for not leave ports disconnected #self.null_source = blocks.null_source(gr.sizeof_float*1) #self.null_sink = blocks.null_sink(gr.sizeof_float*1) #controller self.controller = pubsub() self.controller.subscribe(AVERAGE_KEY, self.fft.set_average) self.controller.publish(AVERAGE_KEY, self.fft.average) self.controller.subscribe(AVG_ALPHA_KEY, self.fft.set_avg_alpha) self.controller.publish(AVG_ALPHA_KEY, self.fft.avg_alpha) self.controller.subscribe(SAMPLE_RATE_KEY, self.fft.set_sample_rate) self.controller.publish(SAMPLE_RATE_KEY, self.fft.sample_rate) #start input watcher common.input_watcher(msgq, self.controller, MSG_KEY) #create window self.win = fft_window.fft_window( parent=parent, controller=self.controller, size=size, title=title, real=self._real, fft_size=fft_size, baseband_freq=baseband_freq, sample_rate_key=SAMPLE_RATE_KEY, y_per_div=y_per_div, y_divs=y_divs, ref_level=ref_level, average_key=AVERAGE_KEY, avg_alpha_key=AVG_ALPHA_KEY, peak_hold=peak_hold, msg_key=MSG_KEY, use_persistence=use_persistence, persist_alpha=persist_alpha, ) common.register_access_methods(self, self.win) setattr(self.win, 'set_baseband_freq', getattr(self, 'set_baseband_freq')) #BACKWARDS setattr(self.win, 'set_peak_hold', getattr(self, 'set_peak_hold')) #BACKWARDS #connect self.wxgui_connect(self,self.fft, self._log, sink)# GUI #Save data #self.connect(self.null_source,(self.selec,0))#selector is in ports 0 by default #self.connect((self.selec,0),self.null_sink) #self.connect(self.fft, self.vect2str, self.integrate, (self.selec,1)) #port 1 os select is to save data #self.connect((self.selec,1), self.file_sink_int)#SAVE DATA self.connect(self.fft, self.vect2str, self.integrate, self.file_sink_int)
def __init__(self, fc=629e6, gaindB=23, samp_rate=12.5e6): gr.top_block.__init__(self, "Usrp 2Chrx Save") ################################################## # Parameters ################################################## self.fc = fc self.gaindB = gaindB self.samp_rate = samp_rate ################################################## # Variables ################################################## self.chans = chans = 4096 ################################################## # Blocks ################################################## self.zeromq_pub_sink_0 = zeromq.pub_sink(gr.sizeof_float, chans, 'tcp://*:50001', 100, False, -1) self.uhd_usrp_source = uhd.usrp_source( ",".join(("addr=10.11.2.61", "master_clock_rate=250e6")), uhd.stream_args( cpu_format="fc32", otw_format="sc16", args='', channels=list(range(0,2)), ), ) self.uhd_usrp_source.set_subdev_spec('A:0 B:0', 0) self.uhd_usrp_source.set_time_source('external', 0) self.uhd_usrp_source.set_clock_source('external', 0) self.uhd_usrp_source.set_center_freq(fc, 0) self.uhd_usrp_source.set_gain(gaindB, 0) self.uhd_usrp_source.set_antenna('TX/RX', 0) self.uhd_usrp_source.set_center_freq(fc, 1) self.uhd_usrp_source.set_gain(gaindB, 1) self.uhd_usrp_source.set_antenna('TX/RX', 1) self.uhd_usrp_source.set_samp_rate(samp_rate) self.uhd_usrp_source.set_time_unknown_pps(uhd.time_spec()) self.fft_vxx_0_0 = fft.fft_vcc(chans, True, window.blackmanharris(chans), True, 1) self.fft_vxx_0 = fft.fft_vcc(chans, True, window.blackmanharris(chans), True, 1) self.blocks_stream_to_vector_0_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, chans) self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, chans) self.blocks_interleave_0 = blocks.interleave(gr.sizeof_float*chans, 1) self.blocks_integrate_xx_0_0 = blocks.integrate_ff(1000, chans) self.blocks_integrate_xx_0 = blocks.integrate_ff(1000, chans) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex*1, 'test.cfile', False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_complex_to_mag_squared_0_0 = blocks.complex_to_mag_squared(chans) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(chans) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0_0, 0), (self.blocks_integrate_xx_0_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_interleave_0, 0)) self.connect((self.blocks_integrate_xx_0_0, 0), (self.blocks_interleave_0, 1)) self.connect((self.blocks_interleave_0, 0), (self.zeromq_pub_sink_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0_0, 0)) self.connect((self.blocks_stream_to_vector_0_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.fft_vxx_0_0, 0), (self.blocks_complex_to_mag_squared_0_0, 0)) self.connect((self.uhd_usrp_source, 0), (self.blocks_file_sink_0, 0)) self.connect((self.uhd_usrp_source, 1), (self.blocks_stream_to_vector_0, 0)) self.connect((self.uhd_usrp_source, 0), (self.blocks_stream_to_vector_0_0, 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))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Vor Receive Realtime Clean") ################################################## # Variables ################################################## self.morse_vol = morse_vol = 10 self.samp_rate = samp_rate = 32000 self.rtl_gain = rtl_gain = 42 self.rtl_freq = rtl_freq = 112500e3 self.morse_gain = morse_gain = pow(10, morse_vol / 10) self.morse_amp_level = morse_amp_level = 0 self.PI = PI = 3.14159 ################################################## # Blocks ################################################## self.wxgui_scopesink2_1_0_0 = scopesink2.scope_sink_f( self.GetWin(), title='Morse', sample_rate=samp_rate / (1600), v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=wxgui.TRIG_MODE_STRIPCHART, y_axis_label='Amp', ) self.Add(self.wxgui_scopesink2_1_0_0.win) self.rtlsdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + '') self.rtlsdr_source_0.set_sample_rate(samp_rate * 64) self.rtlsdr_source_0.set_center_freq(rtl_freq, 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(rtl_gain, 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.pfb_decimator_ccf_0 = pfb.decimator_ccf( 64, (firdes.low_pass(1, samp_rate * 64, 16e3, 200e3)), 0, 100, True, True) self.pfb_decimator_ccf_0.declare_sample_delay(0) _morse_vol_sizer = wx.BoxSizer(wx.VERTICAL) self._morse_vol_text_box = forms.text_box( parent=self.GetWin(), sizer=_morse_vol_sizer, value=self.morse_vol, callback=self.set_morse_vol, label='Morse Volume (dB):', converter=forms.float_converter(), proportion=0, ) self._morse_vol_slider = forms.slider( parent=self.GetWin(), sizer=_morse_vol_sizer, value=self.morse_vol, callback=self.set_morse_vol, minimum=-25, maximum=25, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_morse_vol_sizer) def _morse_amp_level_probe(): while True: val = self.morse_amp.level() try: self.set_morse_amp_level(val) except AttributeError: pass time.sleep(1.0 / (25)) _morse_amp_level_thread = threading.Thread( target=_morse_amp_level_probe) _morse_amp_level_thread.daemon = True _morse_amp_level_thread.start() self.hilbert_fc_0 = filter.hilbert_fc(64, firdes.WIN_HAMMING, 6.76) self.goertzel_fc_0_0 = fft.goertzel_fc(samp_rate, 3200, 30) self.goertzel_fc_0 = fft.goertzel_fc(samp_rate, 3200, 30) self.freq_xlating_fft_filter_ccc_0 = filter.freq_xlating_fft_filter_ccc( 1, (firdes.low_pass(1, samp_rate, 480 * 2, 500 * 2)), 9960, samp_rate) self.freq_xlating_fft_filter_ccc_0.set_nthreads(1) self.freq_xlating_fft_filter_ccc_0.declare_sample_delay(0) self.blocks_tcp_server_sink_0 = blocks.tcp_server_sink( gr.sizeof_gr_complex * 1, '0.0.0.0', 20000, True) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff( (morse_gain, )) self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1) self.blocks_integrate_xx_1 = blocks.integrate_ff(1600, 1) self.blocks_integrate_xx_0 = blocks.integrate_cc(8, 1) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1) self.band_pass_filter_0 = filter.fir_filter_fcc( 1, firdes.complex_band_pass(1, samp_rate, 1010, 1030, 100, firdes.WIN_HAMMING, 6.76)) self.audio_sink_0_0 = audio.sink(samp_rate, '', True) self.analog_wfm_rcv_0 = analog.wfm_rcv( quad_rate=samp_rate, audio_decimation=1, ) self.analog_agc3_xx_0 = analog.agc3_cc(1e-3, 1e-4, 1.0, 1.0, 1) self.analog_agc3_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.analog_agc3_xx_0, 0), (self.blocks_complex_to_mag_0, 0)) self.connect((self.analog_wfm_rcv_0, 0), (self.goertzel_fc_0_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.blocks_complex_to_mag_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.blocks_complex_to_mag_0, 0), (self.goertzel_fc_0, 0)) self.connect((self.blocks_complex_to_mag_0, 0), (self.hilbert_fc_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_integrate_xx_1, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_tcp_server_sink_0, 0)) self.connect((self.blocks_integrate_xx_1, 0), (self.wxgui_scopesink2_1_0_0, 0)) self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0_0, 0)) self.connect((self.freq_xlating_fft_filter_ccc_0, 0), (self.analog_wfm_rcv_0, 0)) self.connect((self.goertzel_fc_0, 0), (self.blocks_multiply_conjugate_cc_0, 0)) self.connect((self.goertzel_fc_0_0, 0), (self.blocks_multiply_conjugate_cc_0, 1)) self.connect((self.hilbert_fc_0, 0), (self.freq_xlating_fft_filter_ccc_0, 0)) self.connect((self.pfb_decimator_ccf_0, 0), (self.analog_agc3_xx_0, 0)) self.connect((self.rtlsdr_source_0, 0), (self.pfb_decimator_ccf_0, 0))
def __init__(self): gr.top_block.__init__(self, "Top Block") Qt.QWidget.__init__(self) self.setWindowTitle("Top Block") qtgui.util.check_set_qss() 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") try: if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"): self.restoreGeometry(self.settings.value("geometry").toByteArray()) else: self.restoreGeometry(self.settings.value("geometry")) except: pass ################################################## # Variables ################################################## self.vec_length = vec_length = 65536 self.sinc_sample_locations = sinc_sample_locations = np.arange(-np.pi*4/2.0, np.pi*4/2.0, np.pi/vec_length) self.timenow = timenow = datetime.now().strftime("%Y-%m-%d_%H.%M.%S") self.sinc = sinc = np.sinc(sinc_sample_locations/np.pi) self.prefix = prefix = "/Users/kbandura/grc_data/" self.samp_rate = samp_rate = 2.4e6 self.recfile = recfile = prefix + timenow + ".h5" self.integration_time = integration_time = 2 self.freq = freq = 1420.5e6 self.display_integration = display_integration = 0.5 self.custom_window = custom_window = sinc*np.hamming(4*vec_length) ################################################## # Blocks ################################################## self.radio_astro_hdf5_sink_1 = radio_astro.hdf5_sink(vec_length, recfile, 'testing', freq - samp_rate/2, samp_rate/vec_length, 'testing') self.qtgui_vector_sink_f_0 = qtgui.vector_sink_f( vec_length, freq - samp_rate/2, samp_rate/vec_length, "Frequency", "PSD", "Spectrum", 1 # Number of inputs ) self.qtgui_vector_sink_f_0.set_update_time(0.10) self.qtgui_vector_sink_f_0.set_y_axis(0, 3000) self.qtgui_vector_sink_f_0.enable_autoscale(True) self.qtgui_vector_sink_f_0.enable_grid(True) self.qtgui_vector_sink_f_0.set_x_axis_units("Hz") self.qtgui_vector_sink_f_0.set_y_axis_units("arb") self.qtgui_vector_sink_f_0.set_ref_level(0) 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_vector_sink_f_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_vector_sink_f_0.set_line_label(i, labels[i]) self.qtgui_vector_sink_f_0.set_line_width(i, widths[i]) self.qtgui_vector_sink_f_0.set_line_color(i, colors[i]) self.qtgui_vector_sink_f_0.set_line_alpha(i, alphas[i]) self._qtgui_vector_sink_f_0_win = sip.wrapinstance(self.qtgui_vector_sink_f_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_vector_sink_f_0_win) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( vec_length, #size samp_rate, #samp_rate "", #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(-1, 1) self.qtgui_time_sink_x_0.set_y_label('Amplitude', "") 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(True) self.qtgui_time_sink_x_0.enable_grid(False) self.qtgui_time_sink_x_0.enable_axis_labels(False) self.qtgui_time_sink_x_0.enable_control_panel(True) 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_layout.addWidget(self._qtgui_time_sink_x_0_win) self.fft_vxx_0 = fft.fft_vcc(vec_length, True, (window.rectangular(vec_length)), True, 1) self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_float*1, vec_length) self.blocks_stream_to_vector_0_2 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, vec_length) self.blocks_stream_to_vector_0_1 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, vec_length) self.blocks_stream_to_vector_0_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, vec_length) self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, vec_length) self.blocks_nlog10_ff_0_0 = blocks.nlog10_ff(10, vec_length, 0) self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, 1, 0) self.blocks_multiply_const_vxx_0_2 = blocks.multiply_const_vcc((custom_window[-vec_length:])) self.blocks_multiply_const_vxx_0_1 = blocks.multiply_const_vcc((custom_window[2*vec_length:3*vec_length])) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vcc((custom_window[vec_length:2*vec_length])) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((custom_window[0:vec_length])) self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(vec_length) self.blocks_integrate_xx_0_0 = blocks.integrate_ff(int(display_integration*samp_rate/vec_length), vec_length) self.blocks_integrate_xx_0 = blocks.integrate_ff(int((integration_time)*samp_rate/vec_length)/int(display_integration*samp_rate/vec_length), vec_length) self.blocks_delay_0_0_0_0 = blocks.delay(gr.sizeof_gr_complex*1, 3*vec_length) self.blocks_delay_0_0_0 = blocks.delay(gr.sizeof_gr_complex*1, 2*vec_length) self.blocks_delay_0_0 = blocks.delay(gr.sizeof_gr_complex*1, vec_length) self.blocks_complex_to_real_0_0 = blocks.complex_to_real(vec_length) self.blocks_add_xx_0 = blocks.add_vcc(vec_length) self.analog_fastnoise_source_x_0 = analog.fastnoise_source_c(analog.GR_GAUSSIAN, 1, 0, 8192) ################################################## # Connections ################################################## self.connect((self.analog_fastnoise_source_x_0, 0), (self.blocks_delay_0_0, 0)) self.connect((self.analog_fastnoise_source_x_0, 0), (self.blocks_delay_0_0_0, 0)) self.connect((self.analog_fastnoise_source_x_0, 0), (self.blocks_delay_0_0_0_0, 0)) self.connect((self.analog_fastnoise_source_x_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.fft_vxx_0, 0)) self.connect((self.blocks_complex_to_real_0_0, 0), (self.blocks_integrate_xx_0_0, 0)) self.connect((self.blocks_delay_0_0, 0), (self.blocks_stream_to_vector_0_0, 0)) self.connect((self.blocks_delay_0_0_0, 0), (self.blocks_stream_to_vector_0_2, 0)) self.connect((self.blocks_delay_0_0_0_0, 0), (self.blocks_stream_to_vector_0_1, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_vector_to_stream_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.radio_astro_hdf5_sink_1, 0)) self.connect((self.blocks_integrate_xx_0_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_integrate_xx_0_0, 0), (self.blocks_nlog10_ff_0_0, 0)) self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.blocks_complex_to_real_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_xx_0, 3)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.blocks_add_xx_0, 2)) self.connect((self.blocks_multiply_const_vxx_0_1, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_multiply_const_vxx_0_2, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_nlog10_ff_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blocks_nlog10_ff_0_0, 0), (self.qtgui_vector_sink_f_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.blocks_multiply_const_vxx_0_2, 0)) self.connect((self.blocks_stream_to_vector_0_0, 0), (self.blocks_multiply_const_vxx_0_1, 0)) self.connect((self.blocks_stream_to_vector_0_1, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_stream_to_vector_0_2, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_nlog10_ff_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_multiply_conjugate_cc_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_multiply_conjugate_cc_0, 1))
def __init__(self, decimation_factor=4, fast_integration=0.0005, freq=1.4205e9, giant_prefix="/home/dspradio/giantPulses/", prefix="/data/", samp_rate=2.5e6, vec_length=1024): gr.top_block.__init__(self, "Headless Usrp Giantpulse") ################################################## # Parameters ################################################## self.decimation_factor = decimation_factor self.fast_integration = fast_integration self.freq = freq self.giant_prefix = giant_prefix self.prefix = prefix self.samp_rate = samp_rate self.vec_length = vec_length ################################################## # Variables ################################################## self.sinc_sample_locations = sinc_sample_locations = np.arange( -np.pi * 4 / 2.0, np.pi * 4 / 2.0, np.pi / vec_length) self.timenow = timenow = datetime.utcnow().strftime( "%Y-%m-%d_%H.%M.%S") self.sinc = sinc = np.sinc(sinc_sample_locations / np.pi) self.timeUTC = timeUTC = datetime.utcnow() self.recfile = recfile = prefix + timenow + "_Drift.h5" self.integration_time = integration_time = 10 self.giantout_bin = giantout_bin = giant_prefix + timenow + ".bin" self.custom_window = custom_window = sinc * np.hamming(4 * vec_length) ################################################## # Blocks ################################################## self.uhd_usrp_source_1 = uhd.usrp_source( ",".join(("", "")), uhd.stream_args( cpu_format="fc32", args='', channels=list(range(0, 1)), ), ) self.uhd_usrp_source_1.set_center_freq(freq, 0) self.uhd_usrp_source_1.set_gain(35, 0) self.uhd_usrp_source_1.set_antenna('TX/RX', 0) self.uhd_usrp_source_1.set_samp_rate(samp_rate) self.uhd_usrp_source_1.set_time_now(uhd.time_spec(time.time()), uhd.ALL_MBOARDS) self.radio_astro_hdf5_sink_1 = radio_astro.hdf5_sink( float, 1, vec_length, "True", recfile, 'A180E55', freq - samp_rate / 2, samp_rate / vec_length, 'amber:39.659,-79.872. horn3b, lna V3 mod, thin, 5.2/5.2cm probe, 20,12,10' ) self.fft_vxx_0 = fft.fft_vcc(vec_length, True, window.rectangular(vec_length), True, 1) self.blocks_vector_to_stream_0 = blocks.vector_to_stream( gr.sizeof_float * 1, vec_length) self.blocks_stream_to_vector_1 = blocks.stream_to_vector( gr.sizeof_float * 1, vec_length // decimation_factor) self.blocks_stream_to_vector_0_2 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, vec_length) self.blocks_stream_to_vector_0_1 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, vec_length) self.blocks_stream_to_vector_0_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, vec_length) self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, vec_length) self.blocks_multiply_const_vxx_0_2 = blocks.multiply_const_vcc( custom_window[-vec_length:]) self.blocks_multiply_const_vxx_0_1 = blocks.multiply_const_vcc( custom_window[2 * vec_length:3 * vec_length]) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vcc( custom_window[vec_length:2 * vec_length]) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc( custom_window[0:vec_length]) self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc( vec_length) self.blocks_integrate_xx_1 = blocks.integrate_ff(decimation_factor, 1) self.blocks_integrate_xx_0_0 = blocks.integrate_ff( int(fast_integration * samp_rate / vec_length), vec_length) self.blocks_integrate_xx_0 = blocks.integrate_ff( int((integration_time) * samp_rate / vec_length) // int(fast_integration * samp_rate / vec_length), vec_length) self.blocks_file_sink_0 = blocks.file_sink( gr.sizeof_float * vec_length // decimation_factor, giantout_bin, False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_delay_0_0_0_0 = blocks.delay(gr.sizeof_gr_complex * 1, 3 * vec_length) self.blocks_delay_0_0_0 = blocks.delay(gr.sizeof_gr_complex * 1, 2 * vec_length) self.blocks_delay_0_0 = blocks.delay(gr.sizeof_gr_complex * 1, vec_length) self.blocks_complex_to_real_0_0 = blocks.complex_to_real(vec_length) self.blocks_add_xx_0 = blocks.add_vcc(vec_length) ################################################## # Connections ################################################## self.connect((self.blocks_add_xx_0, 0), (self.fft_vxx_0, 0)) self.connect((self.blocks_complex_to_real_0_0, 0), (self.blocks_integrate_xx_0_0, 0)) self.connect((self.blocks_delay_0_0, 0), (self.blocks_stream_to_vector_0_0, 0)) self.connect((self.blocks_delay_0_0_0, 0), (self.blocks_stream_to_vector_0_2, 0)) self.connect((self.blocks_delay_0_0_0_0, 0), (self.blocks_stream_to_vector_0_1, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.radio_astro_hdf5_sink_1, 0)) self.connect((self.blocks_integrate_xx_0_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_integrate_xx_0_0, 0), (self.blocks_vector_to_stream_0, 0)) self.connect((self.blocks_integrate_xx_1, 0), (self.blocks_stream_to_vector_1, 0)) self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.blocks_complex_to_real_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_xx_0, 3)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.blocks_add_xx_0, 2)) self.connect((self.blocks_multiply_const_vxx_0_1, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_multiply_const_vxx_0_2, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.blocks_multiply_const_vxx_0_2, 0)) self.connect((self.blocks_stream_to_vector_0_0, 0), (self.blocks_multiply_const_vxx_0_1, 0)) self.connect((self.blocks_stream_to_vector_0_1, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_stream_to_vector_0_2, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.blocks_stream_to_vector_1, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_integrate_xx_1, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_multiply_conjugate_cc_0, 1)) self.connect((self.fft_vxx_0, 0), (self.blocks_multiply_conjugate_cc_0, 0)) self.connect((self.uhd_usrp_source_1, 0), (self.blocks_delay_0_0, 0)) self.connect((self.uhd_usrp_source_1, 0), (self.blocks_delay_0_0_0, 0)) self.connect((self.uhd_usrp_source_1, 0), (self.blocks_delay_0_0_0_0, 0)) self.connect((self.uhd_usrp_source_1, 0), (self.blocks_stream_to_vector_0, 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)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.sliderFc = sliderFc = 20000 self.sliderBeta = sliderBeta = 1 self.samp_rate = samp_rate = 200000 ################################################## # Blocks ################################################## _sliderFc_sizer = wx.BoxSizer(wx.VERTICAL) self._sliderFc_text_box = forms.text_box( parent=self.GetWin(), sizer=_sliderFc_sizer, value=self.sliderFc, callback=self.set_sliderFc, label='sliderFc', converter=forms.float_converter(), proportion=0, ) self._sliderFc_slider = forms.slider( parent=self.GetWin(), sizer=_sliderFc_sizer, value=self.sliderFc, callback=self.set_sliderFc, minimum=0, maximum=100000, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_sliderFc_sizer) self.wxgui_scopesink2_0 = scopesink2.scope_sink_f( self.GetWin(), title="Scope Plot", sample_rate=samp_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=gr.gr_TRIG_MODE_AUTO, y_axis_label="Counts", ) self.Add(self.wxgui_scopesink2_0.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_f( self.GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.Add(self.wxgui_fftsink2_0.win) _sliderBeta_sizer = wx.BoxSizer(wx.VERTICAL) self._sliderBeta_text_box = forms.text_box( parent=self.GetWin(), sizer=_sliderBeta_sizer, value=self.sliderBeta, callback=self.set_sliderBeta, label='sliderBeta', converter=forms.float_converter(), proportion=0, ) self._sliderBeta_slider = forms.slider( parent=self.GetWin(), sizer=_sliderBeta_sizer, value=self.sliderBeta, callback=self.set_sliderBeta, minimum=0, maximum=100, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_sliderBeta_sizer) self.blocks_transcendental_0_0 = blocks.transcendental("sin", "float") self.blocks_transcendental_0 = blocks.transcendental("cos", "float") self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate) self.blocks_sub_xx_0 = blocks.sub_ff(1) self.blocks_multiply_xx_0_0 = blocks.multiply_vff(1) self.blocks_multiply_xx_0 = blocks.multiply_vff(1) self.blocks_integrate_xx_0 = blocks.integrate_ff(1) self.analog_sig_source_x_0_0_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, sliderFc, 1, 0) self.analog_sig_source_x_0_0 = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, sliderFc, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, 1000, 1, 0) self.Beta = blocks.multiply_const_vff((sliderBeta, )) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.Beta, 0)) self.connect((self.Beta, 0), (self.blocks_transcendental_0, 0)) self.connect((self.Beta, 0), (self.blocks_transcendental_0_0, 0)) self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_transcendental_0_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.analog_sig_source_x_0_0_0, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.blocks_transcendental_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_sub_xx_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_sub_xx_0, 1)) self.connect((self.blocks_sub_xx_0, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.blocks_sub_xx_0, 0), (self.wxgui_fftsink2_0, 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.offset_tune_freq = offset_tune_freq = -10E3 self.band_freq = band_freq = 7.055E6 self.usrp_clk_rate = usrp_clk_rate = 200E6 self.usrp_ask_freq = usrp_ask_freq = band_freq+offset_tune_freq self.usrp_DDC_freq = usrp_DDC_freq = np.round(usrp_ask_freq/usrp_clk_rate* 2**32)/2**32 * usrp_clk_rate self.fine_tuner_freq = fine_tuner_freq = 0 self.coarse_tuner_freq = coarse_tuner_freq = 0 self.samp_rate = samp_rate = 250000 self.lo_freq = lo_freq = usrp_DDC_freq + coarse_tuner_freq + fine_tuner_freq - offset_tune_freq self.record_check_box = record_check_box = False self.file_name_string = file_name_string = str(int(time.mktime(time.gmtime())))+"UTC_"+'{:.6f}'.format(lo_freq)+"Hz"+"_"+str(int(samp_rate/100))+"sps"+".raw" self.variable_function_probe_0 = variable_function_probe_0 = 0 self.file_name = file_name = file_name_string if record_check_box==True else "/dev/null" self.volume = volume = 5.0 self.rx_power_label = rx_power_label = '{:.1f}'.format(variable_function_probe_0) self.lo_freq_label = lo_freq_label = '{:.6f}'.format(lo_freq) self.gain_offset_dB = gain_offset_dB = 18.86 self.filter_taps = filter_taps = firdes.low_pass(1.0,2.5,0.1,0.02,firdes.WIN_HAMMING) self.filename_label = filename_label = file_name self.cw_filter_bw = cw_filter_bw = 1000 self.RX_power_offset_dB = RX_power_offset_dB = -35.2 ################################################## # Blocks ################################################## self._volume_layout = Qt.QVBoxLayout() self._volume_knob = Qwt.QwtKnob() self._volume_knob.setRange(0, 10.0, 1.0) self._volume_knob.setValue(self.volume) self._volume_knob.valueChanged.connect(self.set_volume) self._volume_layout.addWidget(self._volume_knob) self._volume_label = Qt.QLabel("Volume") self._volume_label.setAlignment(Qt.Qt.AlignTop | Qt.Qt.AlignHCenter) self._volume_layout.addWidget(self._volume_label) self.top_grid_layout.addLayout(self._volume_layout, 5,6,1,1) self._cw_filter_bw_options = (100, 500, 1000, ) self._cw_filter_bw_labels = ("100 Hz", "500 Hz", "1 kHz", ) self._cw_filter_bw_tool_bar = Qt.QToolBar(self) self._cw_filter_bw_tool_bar.addWidget(Qt.QLabel("CW Filter BW"+": ")) self._cw_filter_bw_combo_box = Qt.QComboBox() self._cw_filter_bw_tool_bar.addWidget(self._cw_filter_bw_combo_box) for label in self._cw_filter_bw_labels: self._cw_filter_bw_combo_box.addItem(label) self._cw_filter_bw_callback = lambda i: Qt.QMetaObject.invokeMethod(self._cw_filter_bw_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._cw_filter_bw_options.index(i))) self._cw_filter_bw_callback(self.cw_filter_bw) self._cw_filter_bw_combo_box.currentIndexChanged.connect( lambda i: self.set_cw_filter_bw(self._cw_filter_bw_options[i])) self.top_grid_layout.addWidget(self._cw_filter_bw_tool_bar, 5,5,1,1) self.blocks_probe_signal_x_0 = blocks.probe_signal_f() def _variable_function_probe_0_probe(): while True: val = self.blocks_probe_signal_x_0.level() try: self.set_variable_function_probe_0(val) except AttributeError: pass time.sleep(1.0 / (5)) _variable_function_probe_0_thread = threading.Thread(target=_variable_function_probe_0_probe) _variable_function_probe_0_thread.daemon = True _variable_function_probe_0_thread.start() self.uhd_usrp_source_0 = uhd.usrp_source( ",".join(("", "addr=192.168.40.2")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_subdev_spec("B:A", 0) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(usrp_ask_freq, 0) self.uhd_usrp_source_0.set_gain(6, 0) self._rx_power_label_tool_bar = Qt.QToolBar(self) if None: self._rx_power_label_formatter = None else: self._rx_power_label_formatter = lambda x: x self._rx_power_label_tool_bar.addWidget(Qt.QLabel("RX Power (dBm)"+": ")) self._rx_power_label_label = Qt.QLabel(str(self._rx_power_label_formatter(self.rx_power_label))) self._rx_power_label_tool_bar.addWidget(self._rx_power_label_label) self.top_grid_layout.addWidget(self._rx_power_label_tool_bar, 4,7,1,1) _record_check_box_check_box = Qt.QCheckBox("Record") self._record_check_box_choices = {True: True, False: False} self._record_check_box_choices_inv = dict((v,k) for k,v in self._record_check_box_choices.iteritems()) self._record_check_box_callback = lambda i: Qt.QMetaObject.invokeMethod(_record_check_box_check_box, "setChecked", Qt.Q_ARG("bool", self._record_check_box_choices_inv[i])) self._record_check_box_callback(self.record_check_box) _record_check_box_check_box.stateChanged.connect(lambda i: self.set_record_check_box(self._record_check_box_choices[bool(i)])) self.top_grid_layout.addWidget(_record_check_box_check_box, 6,5,1,1) self.rational_resampler_xxx_0 = filter.rational_resampler_fff( interpolation=48000, decimation=2500, taps=None, fractional_bw=None, ) self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c( 4096, #size firdes.WIN_BLACKMAN_hARRIS, #wintype usrp_DDC_freq, #fc samp_rate, #bw "Band Waterfall", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_0.set_update_time(0.10) self.qtgui_waterfall_sink_x_0.enable_grid(False) if complex == type(float()): self.qtgui_waterfall_sink_x_0.set_plot_pos_half(not True) labels = ["", "", "", "", "", "", "", "", "", ""] colors = [5, 0, 0, 0, 0, 0, 0, 0, 0, 0] 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_waterfall_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_0.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_0.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_0.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_0.set_intensity_range(-100, -70) self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance(self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_0_win, 4,0,3,5) self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype lo_freq, #fc samp_rate/100, #bw str(samp_rate/100) + " Hz Channel Spectrum", #name 2 #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(-120, -70) 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(True) self.qtgui_freq_sink_x_0_0.set_fft_average(1.0) 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(2): 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, 0,5,3,5) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 4096, #size firdes.WIN_BLACKMAN_hARRIS, #wintype usrp_DDC_freq, #fc samp_rate, #bw "Band 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(-110, -60) 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(True) self.qtgui_freq_sink_x_0.set_fft_average(0.2) 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,5) self.low_pass_filter_0_0 = filter.fir_filter_ccf(1, firdes.low_pass( 1, samp_rate/100, 0.9*cw_filter_bw, 0.1*cw_filter_bw, firdes.WIN_BLACKMAN, 6.76)) self.low_pass_filter_0 = filter.fir_filter_ccf(1, firdes.low_pass( 10**(gain_offset_dB/20), samp_rate, 100E3, 20E3, firdes.WIN_HAMMING, 6.76)) self._lo_freq_label_tool_bar = Qt.QToolBar(self) if None: self._lo_freq_label_formatter = None else: self._lo_freq_label_formatter = lambda x: x self._lo_freq_label_tool_bar.addWidget(Qt.QLabel("LO Freq (Hz)"+": ")) self._lo_freq_label_label = Qt.QLabel(str(self._lo_freq_label_formatter(self.lo_freq_label))) self._lo_freq_label_tool_bar.addWidget(self._lo_freq_label_label) self.top_grid_layout.addWidget(self._lo_freq_label_tool_bar, 4,6,1,1) self.hilbert_fc_0_0 = filter.hilbert_fc(65, firdes.WIN_HAMMING, 6.76) self.hilbert_fc_0 = filter.hilbert_fc(65, firdes.WIN_HAMMING, 6.76) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(10, (filter_taps), lo_freq - usrp_DDC_freq, samp_rate) self.fir_filter_xxx_0_0_0 = filter.fir_filter_ccc(10, (filter_taps)) self.fir_filter_xxx_0_0_0.declare_sample_delay(0) self._fine_tuner_freq_layout = Qt.QVBoxLayout() self._fine_tuner_freq_tool_bar = Qt.QToolBar(self) self._fine_tuner_freq_layout.addWidget(self._fine_tuner_freq_tool_bar) self._fine_tuner_freq_tool_bar.addWidget(Qt.QLabel("Fine Tuner (Hz)"+": ")) class qwt_counter_pyslot(Qwt.QwtCounter): def __init__(self, parent=None): Qwt.QwtCounter.__init__(self, parent) @pyqtSlot('double') def setValue(self, value): super(Qwt.QwtCounter, self).setValue(value) self._fine_tuner_freq_counter = qwt_counter_pyslot() self._fine_tuner_freq_counter.setRange(-500, 500, 1) self._fine_tuner_freq_counter.setNumButtons(2) self._fine_tuner_freq_counter.setValue(self.fine_tuner_freq) self._fine_tuner_freq_tool_bar.addWidget(self._fine_tuner_freq_counter) self._fine_tuner_freq_counter.valueChanged.connect(self.set_fine_tuner_freq) self._fine_tuner_freq_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._fine_tuner_freq_slider.setRange(-500, 500, 1) self._fine_tuner_freq_slider.setValue(self.fine_tuner_freq) self._fine_tuner_freq_slider.setMinimumWidth(200) self._fine_tuner_freq_slider.valueChanged.connect(self.set_fine_tuner_freq) self._fine_tuner_freq_layout.addWidget(self._fine_tuner_freq_slider) self.top_grid_layout.addLayout(self._fine_tuner_freq_layout, 3,5,1,5) self._filename_label_tool_bar = Qt.QToolBar(self) if None: self._filename_label_formatter = None else: self._filename_label_formatter = lambda x: x self._filename_label_tool_bar.addWidget(Qt.QLabel("File Name"+": ")) self._filename_label_label = Qt.QLabel(str(self._filename_label_formatter(self.filename_label))) self._filename_label_tool_bar.addWidget(self._filename_label_label) self.top_grid_layout.addWidget(self._filename_label_tool_bar, 6,6,1,3) self._coarse_tuner_freq_layout = Qt.QVBoxLayout() self._coarse_tuner_freq_tool_bar = Qt.QToolBar(self) self._coarse_tuner_freq_layout.addWidget(self._coarse_tuner_freq_tool_bar) self._coarse_tuner_freq_tool_bar.addWidget(Qt.QLabel("Coarse Tuner (Hz)"+": ")) class qwt_counter_pyslot(Qwt.QwtCounter): def __init__(self, parent=None): Qwt.QwtCounter.__init__(self, parent) @pyqtSlot('double') def setValue(self, value): super(Qwt.QwtCounter, self).setValue(value) self._coarse_tuner_freq_counter = qwt_counter_pyslot() self._coarse_tuner_freq_counter.setRange(-samp_rate/2, samp_rate/2, 100) self._coarse_tuner_freq_counter.setNumButtons(2) self._coarse_tuner_freq_counter.setValue(self.coarse_tuner_freq) self._coarse_tuner_freq_tool_bar.addWidget(self._coarse_tuner_freq_counter) self._coarse_tuner_freq_counter.valueChanged.connect(self.set_coarse_tuner_freq) self._coarse_tuner_freq_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._coarse_tuner_freq_slider.setRange(-samp_rate/2, samp_rate/2, 100) self._coarse_tuner_freq_slider.setValue(self.coarse_tuner_freq) self._coarse_tuner_freq_slider.setMinimumWidth(50) self._coarse_tuner_freq_slider.valueChanged.connect(self.set_coarse_tuner_freq) self._coarse_tuner_freq_layout.addWidget(self._coarse_tuner_freq_slider) self.top_grid_layout.addLayout(self._coarse_tuner_freq_layout, 3,0,1,5) self.blocks_null_sink_1_0_0 = blocks.null_sink(gr.sizeof_float*1) self.blocks_null_sink_1_0 = blocks.null_sink(gr.sizeof_float*1) self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, 1, RX_power_offset_dB) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_integrate_xx_0 = blocks.integrate_ff(500) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex*1, file_name, False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.blocks_complex_to_float_1_0 = blocks.complex_to_float(1) self.blocks_complex_to_float_0_0 = blocks.complex_to_float(1) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.blocks_add_xx_0 = blocks.add_vff(1) self._band_freq_options = [1.84E6, 3.598E6, 7.055E6, 2.5E6, 5.0E6, 10.0E6] self._band_freq_labels = ["160m", "80m", "40m", "2.5 MHz", "5 MHz", "10 MHz"] self._band_freq_tool_bar = Qt.QToolBar(self) self._band_freq_tool_bar.addWidget(Qt.QLabel("Band"+": ")) self._band_freq_combo_box = Qt.QComboBox() self._band_freq_tool_bar.addWidget(self._band_freq_combo_box) for label in self._band_freq_labels: self._band_freq_combo_box.addItem(label) self._band_freq_callback = lambda i: Qt.QMetaObject.invokeMethod(self._band_freq_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._band_freq_options.index(i))) self._band_freq_callback(self.band_freq) self._band_freq_combo_box.currentIndexChanged.connect( lambda i: self.set_band_freq(self._band_freq_options[i])) self.top_grid_layout.addWidget(self._band_freq_tool_bar, 4,5,1,1) self.audio_sink_0 = audio.sink(48000, "", True) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate/100, analog.GR_COS_WAVE, 600, 1, 0) self.analog_agc3_xx_0 = analog.agc3_cc(1e-1, 1e-4, volume/100, 1, 1) self.analog_agc3_xx_0.set_max_gain(2**16) ################################################## # Connections ################################################## self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.fir_filter_xxx_0_0_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.fir_filter_xxx_0_0_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.fir_filter_xxx_0_0_0, 0), (self.low_pass_filter_0_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.low_pass_filter_0_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.low_pass_filter_0_0, 0), (self.blocks_complex_to_mag_squared_0, 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_nlog10_ff_0, 0), (self.blocks_probe_signal_x_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.qtgui_waterfall_sink_x_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.analog_agc3_xx_0, 0)) self.connect((self.analog_agc3_xx_0, 0), (self.blocks_complex_to_float_1_0, 0)) self.connect((self.fir_filter_xxx_0_0_0, 0), (self.qtgui_freq_sink_x_0_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_complex_to_float_0_0, 1), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_complex_to_float_0_0, 0), (self.blocks_null_sink_1_0_0, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_null_sink_1_0, 0)) self.connect((self.blocks_complex_to_float_1_0, 1), (self.hilbert_fc_0, 0)) self.connect((self.hilbert_fc_0, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.blocks_complex_to_float_1_0, 0), (self.hilbert_fc_0_0, 0)) self.connect((self.hilbert_fc_0_0, 0), (self.blocks_complex_to_float_0_0, 0)) self.connect((self.low_pass_filter_0_0, 0), (self.qtgui_freq_sink_x_0_0, 1))
def __init__(self): gr.top_block.__init__(self) options = get_options() bitrate = 8000 channel_bw = options.channel_bandwidth chan0_freq = 358400000 self.rfgain = options.gain self.channels = [ int(ch) for ch in options.channels.split(',') if ch ] self.ch_freqs = [ ch * channel_bw + chan0_freq for ch in self.channels ] self.ch_freqs.extend( [ int(f) for f in options.channels_by_freq.split(',') if f ]) while len(self.channels) < len(self.ch_freqs): self.channels.append(-1) if options.frequency is None: self.ifreq = (max(self.ch_freqs) + min(self.ch_freqs)) / 2 else: self.ifreq = options.frequency self.src = osmosdr.source(options.args) self.src.set_center_freq(self.ifreq) self.src.set_sample_rate(options.sample_rate) self.src.set_freq_corr(options.ppm, 0) if self.rfgain is None: self.src.set_gain_mode(True, 0) self.iagc = 1 self.rfgain = 0 else: self.iagc = 0 self.src.set_gain_mode(False) self.src.set_gain(self.rfgain) self.src.set_if_gain(37) # may differ from the requested rate sample_rate = int(self.src.get_sample_rate()) sys.stderr.write("sample rate: %d\n" % (sample_rate)) first_decim = int(options.sample_rate / bitrate / 2) sys.stderr.write("decim: %d\n" % (first_decim)) out_sample_rate=sample_rate/first_decim sys.stderr.write("output sample rate: %d\n" % (out_sample_rate)) sps=out_sample_rate/bitrate sys.stderr.write("samples per symbol: %d\n" % (sps)) self.tuners = [] self.afc_probes = [] if len(self.channels) != 1: if options.output_file: if options.output_file.find('%%') == -1: raise ValueError('Output name template missing "%%".') elif options.output_pipe: if options.output_pipe.find('%%') == -1: raise ValueError('Output name template missing "%%".') else: raise ValueError('WTF') for ch in range(0,len(self.channels)): bw = (9200 + options.afc_ppm_threshold)/2 taps = filter.firdes.low_pass(1.0, sample_rate, bw, bw*options.transition_width, filter.firdes.WIN_HANN) offset = self.ch_freqs[ch] - self.ifreq sys.stderr.write("channel[%d]: %d frequency=%d, offset=%d Hz\n" % (ch, self.channels[ch], self.ch_freqs[ch], offset)) tuner = filter.freq_xlating_fir_filter_ccc(first_decim, taps, offset, sample_rate) self.tuners.append(tuner) demod = digital.gmsk_demod(samples_per_symbol=sps) fname = self.channels[ch] if fname == -1: fname = self.ch_freqs[ch] if options.output_pipe is None: file = options.output_file.replace('%%', str(fname)) output = blocks.file_sink(gr.sizeof_char, file) else: cmd = options.output_pipe.replace('%%', str(fname)) pipe = subprocess.Popen(cmd, stdin=subprocess.PIPE, shell=True) fd = pipe.stdin.fileno() output = blocks.file_descriptor_sink(gr.sizeof_char, fd) self.connect((self.src, 0), (tuner, 0)) self.connect((tuner, 0), (demod, 0)) self.connect((demod, 0), (output, 0)) afc_decimation = 32000 afc_demod = analog.quadrature_demod_cf(sample_rate/first_decim/(2*math.pi*afc_decimation)) integrate = blocks.integrate_ff(afc_decimation) afc_probe = blocks.probe_signal_f() self.afc_probes.append(afc_probe) self.connect((tuner, 0), (afc_demod,0)) self.connect((afc_demod, 0), (integrate,0)) self.connect((integrate, 0), (afc_probe, 0)) def _variable_function_probe_0_probe(): while True: time.sleep(options.afc_period) for ch in range(0,len(self.channels)): err = self.afc_probes[ch].level() if abs(err) < options.afc_ppm_threshold: continue freq = self.tuners[ch].center_freq() + err * options.afc_gain self.tuners[ch].set_center_freq(freq) if self.channels[ch] == -1: sys.stderr.write("Freq %d freq err: %5.0f\tfreq: %f\n" % (self.ch_freqs[ch], err, freq)) else: sys.stderr.write("Chan %d freq err: %5.0f\tfreq: %f\n" % (self.channels[ch], err, freq)) sys.stderr.write("\n") _variable_function_probe_0_thread = threading.Thread(target=_variable_function_probe_0_probe) _variable_function_probe_0_thread.daemon = True _variable_function_probe_0_thread.start()
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 = 15e6 self.if_bandwidth_1 = if_bandwidth_1 = 2e6 self.sdr_gain = sdr_gain = 60 self.integration_bandwidth = integration_bandwidth = 5e3 self.if_filter_decimation_rate = if_filter_decimation_rate = int(samp_rate/(1.1*if_bandwidth_1)) self.sdr_power_offset = sdr_power_offset = 1.0 self.sdr_gain_lin = sdr_gain_lin = 10**(sdr_gain/20) self.num_channels = num_channels = int((samp_rate/if_filter_decimation_rate)/integration_bandwidth) self.lna_gain_measured = lna_gain_measured = 33.33 self.integration_time = integration_time = 10 self.if_samp_rate = if_samp_rate = samp_rate/if_filter_decimation_rate self.cable_loss = cable_loss = 0.25 self.variable_function_probe = variable_function_probe = 0 self.sdr_frequency = sdr_frequency = 1420.406e6 self.output_vector_bandwidth = output_vector_bandwidth = samp_rate/if_filter_decimation_rate self.offset_frequency = offset_frequency = if_bandwidth_1/2+1e5 self.integration_scale_factor = integration_scale_factor = np.full((num_channels),float(1.0/(integration_time*integration_bandwidth*50)),dtype=float) self.integration_dec_rate = integration_dec_rate = int(integration_time*if_samp_rate/num_channels) self.if_filter_gain = if_filter_gain = 1/(lna_gain_measured*cable_loss*sdr_gain_lin*sdr_power_offset) self.if_bandwidth_0 = if_bandwidth_0 = 5.5e6 self.channel_skirt = channel_skirt = integration_bandwidth/100 self.channel_map = channel_map = range(int(num_channels/2.0+1.0),num_channels,1)+range(0,int(num_channels/2.0+1.0),1) self.antenna_gain_estimated = antenna_gain_estimated = 173 ################################################## # Blocks ################################################## self.probe_signal = blocks.probe_signal_vf(num_channels) def _variable_function_probe_probe(): while True: val = self.probe_signal.level() try: self.set_variable_function_probe(val) except AttributeError: pass time.sleep(1.0 / (10)) _variable_function_probe_thread = threading.Thread(target=_variable_function_probe_probe) _variable_function_probe_thread.daemon = True _variable_function_probe_thread.start() self.pfb_channelizer_ccf_0 = pfb.channelizer_ccf( num_channels, (firdes.low_pass(1, if_samp_rate, (integration_bandwidth/2-channel_skirt), channel_skirt, firdes.WIN_HAMMING)), 1.0, 0) self.pfb_channelizer_ccf_0.set_channel_map((channel_map)) self.pfb_channelizer_ccf_0.declare_sample_delay(0) self.low_pass_filter_1 = filter.fir_filter_ccf(if_filter_decimation_rate, firdes.low_pass( if_filter_gain, samp_rate, if_bandwidth_1/2, 1e5, firdes.WIN_HAMMING, 6.76)) self.limesdr_source_2 = limesdr.source('0009060B00471B22', 2, 1, 0, 0, '', sdr_frequency-offset_frequency, samp_rate, 0, 1, 15e6, 0, 10e6, 3, 2, 2, 1, if_bandwidth_0, 1, 5e6, 1, if_bandwidth_0, 0, 0, sdr_gain, 30, 0, 0, 0, 0) self.blocks_streams_to_vector_0 = blocks.streams_to_vector(gr.sizeof_gr_complex*1, num_channels) self.blocks_multiply_xx_1 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((integration_scale_factor)) self.blocks_integrate_xx_0_0 = blocks.integrate_ff(integration_dec_rate, num_channels) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex*1, '/home/w1xm-admin/Documents/DSP/data_out/recieve_block_sink', False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_copy_0_0 = blocks.copy(gr.sizeof_gr_complex*1) self.blocks_copy_0_0.set_enabled(False) self.blocks_copy_0 = blocks.copy(gr.sizeof_gr_complex*1) self.blocks_copy_0.set_enabled(True) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(num_channels) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_SIN_WAVE, -offset_frequency, 1, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_1, 1)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_integrate_xx_0_0, 0)) self.connect((self.blocks_copy_0, 0), (self.blocks_multiply_xx_1, 0)) self.connect((self.blocks_copy_0_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_integrate_xx_0_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.probe_signal, 0)) self.connect((self.blocks_multiply_xx_1, 0), (self.low_pass_filter_1, 0)) self.connect((self.blocks_streams_to_vector_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.limesdr_source_2, 0), (self.blocks_copy_0, 0)) self.connect((self.limesdr_source_2, 0), (self.blocks_copy_0_0, 0)) self.connect((self.low_pass_filter_1, 0), (self.pfb_channelizer_ccf_0, 0)) for i in range(num_channels): self.connect((self.pfb_channelizer_ccf_0, i), (self.blocks_streams_to_vector_0, i))
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 = 16000 self.repeat = repeat = samp_rate/80 ################################################## # Blocks ################################################## self.qtgui_time_sink_x_0_0 = qtgui.time_sink_f( 1024, #size samp_rate, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_0_0.set_update_time(0.10) self.qtgui_time_sink_x_0_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0_0.set_y_label("Amplitude", "") self.qtgui_time_sink_x_0_0.enable_tags(-1, True) self.qtgui_time_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0_0.enable_autoscale(True) self.qtgui_time_sink_x_0_0.enable_grid(False) 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_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_time_sink_x_0_0_win) self.blocks_unpacked_to_packed_xx_1 = blocks.unpacked_to_packed_bb(8, gr.GR_MSB_FIRST) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(8) self.blocks_uchar_to_float_0_0_0 = blocks.uchar_to_float() self.blocks_uchar_to_float_0 = blocks.uchar_to_float() self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char*1, samp_rate,True) self.blocks_short_to_float_0 = blocks.short_to_float(1, 1) self.blocks_short_to_char_0 = blocks.short_to_char(1) self.blocks_rms_xx_0_0 = blocks.rms_ff(1) self.blocks_rms_xx_0 = blocks.rms_ff(1) self.blocks_repeat_0 = blocks.repeat(gr.sizeof_char*1, repeat) self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb(1, 8, "", False, gr.GR_MSB_FIRST) self.blocks_null_sink_1 = blocks.null_sink(gr.sizeof_short*1) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_float*1) self.blocks_multiply_xx_0_2 = blocks.multiply_vff(1) self.blocks_multiply_xx_0_1 = blocks.multiply_vff(1) self.blocks_multiply_xx_0_0 = blocks.multiply_vff(1) self.blocks_multiply_xx_0 = blocks.multiply_vff(1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vss((256, )) self.blocks_integrate_xx_1 = blocks.integrate_ff(repeat) self.blocks_integrate_xx_0_1 = blocks.integrate_ff(repeat) self.blocks_integrate_xx_0_0 = blocks.integrate_ff(repeat) self.blocks_integrate_xx_0 = blocks.integrate_ff(repeat) self.blocks_float_to_uchar_0 = blocks.float_to_uchar() self.blocks_file_source_0 = blocks.file_source(gr.sizeof_short*1, "/home/sidekiq/Documents/Documentation_SDR/sdr.in", True) self.blocks_file_sink_0_0 = blocks.file_sink(gr.sizeof_char*1, "/home/sidekiq/Documents/Documentation_SDR/text_output", False) self.blocks_file_sink_0_0.set_unbuffered(True) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.blocks_argmax_xx_0 = blocks.argmax_fs(1) self.blocks_add_xx_0_0 = blocks.add_vff(1) self.blocks_add_xx_0 = blocks.add_vff(1) self.blocks_add_const_vxx_0 = blocks.add_const_vff((1, )) self.blocks_abs_xx_0_2 = blocks.abs_ff(1) self.blocks_abs_xx_0_1 = blocks.abs_ff(1) self.blocks_abs_xx_0_0 = blocks.abs_ff(1) self.blocks_abs_xx_0 = blocks.abs_ff(1) self.blks2_packet_encoder_0 = grc_blks2.packet_mod_b(grc_blks2.packet_encoder( samples_per_symbol=1, bits_per_symbol=1, preamble="11111000", access_code="11111111", pad_for_usrp=False, ), payload_length=1, ) self.blks2_packet_decoder_0 = grc_blks2.packet_demod_b(grc_blks2.packet_decoder( access_code="", threshold=-1, callback=lambda ok, payload: self.blks2_packet_decoder_0.recv_pkt(ok, payload), ), ) self.audio_sink_1 = audio.sink(16000, "", True) self.analog_sig_source_x_1 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 1330, 1, 0) self.analog_sig_source_x_0_1 = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, 1330, 1, 0) self.analog_sig_source_x_0_0 = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, 2720, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_COS_WAVE, 2720, 1, 0) self.analog_frequency_modulator_fc_0 = analog.frequency_modulator_fc(100) ################################################## # Connections ################################################## self.connect((self.analog_frequency_modulator_fc_0, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0_2, 0)) self.connect((self.analog_sig_source_x_0_1, 0), (self.blocks_multiply_xx_0_1, 0)) self.connect((self.analog_sig_source_x_1, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blks2_packet_decoder_0, 0), (self.blocks_unpacked_to_packed_xx_1, 0)) self.connect((self.blks2_packet_encoder_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.blocks_abs_xx_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_abs_xx_0_0, 0), (self.blocks_add_xx_0_0, 0)) self.connect((self.blocks_abs_xx_0_1, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_abs_xx_0_2, 0), (self.blocks_add_xx_0_0, 1)) self.connect((self.blocks_add_const_vxx_0, 0), (self.analog_frequency_modulator_fc_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_rms_xx_0, 0)) self.connect((self.blocks_add_xx_0_0, 0), (self.blocks_rms_xx_0_0, 0)) self.connect((self.blocks_argmax_xx_0, 0), (self.blocks_null_sink_1, 0)) self.connect((self.blocks_argmax_xx_0, 1), (self.blocks_short_to_float_0, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.audio_sink_1, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_multiply_xx_0_1, 1)) self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_multiply_xx_0_2, 1)) self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_null_sink_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_float_to_uchar_0, 0), (self.blks2_packet_decoder_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_abs_xx_0_2, 0)) self.connect((self.blocks_integrate_xx_0_0, 0), (self.blocks_abs_xx_0, 0)) self.connect((self.blocks_integrate_xx_0_1, 0), (self.blocks_abs_xx_0_0, 0)) self.connect((self.blocks_integrate_xx_1, 0), (self.blocks_abs_xx_0_1, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_short_to_char_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_integrate_xx_1, 0)) self.connect((self.blocks_multiply_xx_0_1, 0), (self.blocks_integrate_xx_0_1, 0)) self.connect((self.blocks_multiply_xx_0_2, 0), (self.blocks_integrate_xx_0_0, 0)) self.connect((self.blocks_repack_bits_bb_0, 0), (self.blks2_packet_encoder_0, 0)) self.connect((self.blocks_repack_bits_bb_0, 0), (self.blocks_uchar_to_float_0_0_0, 0)) self.connect((self.blocks_repeat_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_rms_xx_0, 0), (self.blocks_argmax_xx_0, 1)) self.connect((self.blocks_rms_xx_0_0, 0), (self.blocks_argmax_xx_0, 0)) self.connect((self.blocks_short_to_char_0, 0), (self.blocks_repack_bits_bb_0, 0)) self.connect((self.blocks_short_to_float_0, 0), (self.blocks_float_to_uchar_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_uchar_to_float_0, 0)) self.connect((self.blocks_uchar_to_float_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_uchar_to_float_0_0_0, 0), (self.qtgui_time_sink_x_0_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_repeat_0, 0)) self.connect((self.blocks_unpacked_to_packed_xx_1, 0), (self.blocks_file_sink_0_0, 0))
def __init__(self, ask_samp_rate=4E6, num_demod=4, hw_args="uhd", 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) # 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 self.demodulators = [] for idx in range(num_demod): self.demodulators.append( TunerDemod(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)
def __init__(self): gr.top_block.__init__(self) bitrate = 8000 channel_bw = 12500 chan0_freq = 358400000 options = get_options() self.rfgain = options.gain self.channels = [ int(ch) for ch in options.channels.split(',') if ch ] self.ch_freqs = [ ch * channel_bw + chan0_freq for ch in self.channels ] self.ch_freqs.extend( [ int(f) for f in options.channels_by_freq.split(',') if f ]) while len(self.channels) < len(self.ch_freqs): self.channels.append(-1) if options.frequency is None: self.ifreq = (max(self.ch_freqs) + min(self.ch_freqs)) / 2 / channel_bw * channel_bw else: self.ifreq = options.frequency ch0 = (self.ifreq - chan0_freq ) / channel_bw n = options.sample_rate / channel_bw s = options.sample_rate / bitrate / 2 c = '' for ch in range(0,len(self.channels)): c = c + '%i,'%((self.channels[ch] - ch0)%n) c=c[:-1] self.src = osmosdr.source(options.args) self.src.set_center_freq(self.ifreq) self.src.set_sample_rate(options.sample_rate) self.src.set_freq_corr(options.ppm, 0) fcl_args = ['./fcl', '-n', '%i'%n, '-s', '%i'%s, '-t', '2', '-c', '%s'%c, '-f', './fir.py %i 7900 2000 rcos'%options.sample_rate, '-o', '/dev/stdout'] sys.stderr.write(string.join(fcl_args)) self.fcl = subprocess.Popen(fcl_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE) self.fcl_in = blocks.file_descriptor_sink(gr.sizeof_gr_complex*1, self.fcl.stdin.fileno()) self.fcl_out = blocks.file_descriptor_source(gr.sizeof_gr_complex*1, self.fcl.stdout.fileno(), False) self.deinterleave = blocks.deinterleave(gr.sizeof_gr_complex*1, 1) self.connect((self.src, 0), (self.fcl_in, 0)) self.connect((self.fcl_out, 0), (self.deinterleave, 0)) if self.rfgain is None: self.src.set_gain_mode(True, 0) self.iagc = 1 self.rfgain = 0 else: self.iagc = 0 self.src.set_gain_mode(False) self.src.set_gain(-9.7) self.src.set_gain(self.rfgain) self.src.set_if_gain(37) # may differ from the requested rate sample_rate = int(self.src.get_sample_rate()) sys.stderr.write("sample rate: %d\n" % (sample_rate)) first_decim = int(options.sample_rate / bitrate / 2) sys.stderr.write("decim: %d\n" % (first_decim)) out_sample_rate=sample_rate/first_decim sys.stderr.write("output sample rate: %d\n" % (out_sample_rate)) sps=out_sample_rate/bitrate sys.stderr.write("samples per symbol: %d\n" % (sps)) self.tuners = [] self.afc_probes = [] if len(self.channels) != 1: if options.output_file: if options.output_file.find('%%') == -1: raise ValueError('Output name template missing "%%".') elif options.output_pipe: if options.output_pipe.find('%%') == -1: raise ValueError('Output name template missing "%%".') else: raise ValueError('WTF') for ch in range(0,len(self.channels)): bw = (9200 + options.afc_ppm_threshold)/2 taps = filter.firdes.low_pass(1.0,out_sample_rate, bw, bw*options.transition_width, filter.firdes.WIN_HANN) # offset = self.ch_freqs[ch] - self.ifreq offset = 0 sys.stderr.write("channel[%d]: %d frequency=%d, offset=%d Hz\n" % (ch, self.channels[ch], self.ch_freqs[ch], offset)) tuner = filter.freq_xlating_fir_filter_ccc(1, taps, offset, out_sample_rate) self.tuners.append(tuner) demod = digital.gmsk_demod(samples_per_symbol=sps) fname = self.channels[ch] if fname == -1: fname = self.ch_freqs[ch] if options.output_pipe is None: file = options.output_file.replace('%%', str(fname)) output = blocks.file_sink(gr.sizeof_char, file) else: cmd = options.output_pipe.replace('%%', str(fname)) pipe = subprocess.Popen(cmd, stdin=subprocess.PIPE, shell=True) fd = pipe.stdin.fileno() output = blocks.file_descriptor_sink(gr.sizeof_char, fd) self.connect((self.deinterleave, ch), (tuner, 0)) self.connect((tuner, 0), (demod, 0)) self.connect((demod, 0), (output, 0)) afc_decimation = 32000 afc_demod = analog.quadrature_demod_cf(sample_rate/first_decim/(2*math.pi*afc_decimation)) integrate = blocks.integrate_ff(afc_decimation) afc_probe = blocks.probe_signal_f() self.afc_probes.append(afc_probe) self.connect((tuner, 0), (afc_demod,0)) self.connect((afc_demod, 0), (integrate,0)) self.connect((integrate, 0), (afc_probe, 0)) def _variable_function_probe_0_probe(): while True: time.sleep(options.afc_period) for ch in range(0,len(self.channels)): err = self.afc_probes[ch].level() if abs(err) < options.afc_ppm_threshold: continue freq = self.tuners[ch].center_freq() + err * options.afc_gain self.tuners[ch].set_center_freq(freq) if self.channels[ch] == -1: sys.stderr.write("Freq %d freq err: %5.0f\tfreq: %f\n" % (self.ch_freqs[ch], err, freq)) else: sys.stderr.write("Chan %d freq err: %5.0f\tfreq: %f\n" % (self.channels[ch], err, freq)) sys.stderr.write("\n") _variable_function_probe_0_thread = threading.Thread(target=_variable_function_probe_0_probe) _variable_function_probe_0_thread.daemon = True _variable_function_probe_0_thread.start()