def __init__(self): gr.top_block.__init__(self, "METEOR-M2 receiver") ################################################## # Variables ################################################## self.symb_rate = symb_rate = 72e3 self.samp_rate = samp_rate = 960e3 self.decimation = decimation = 4 self.samp_per_sym = samp_per_sym = samp_rate/decimation/symb_rate self.clock_alpha = clock_alpha = 30e-3 self.bitstream_name = bitstream_name = os.getcwd() + "/Data/meteor_LRPT_" + datetime.now().strftime("%d%m%Y_%H%M") + ".s" self.Tuning_offset = Tuning_offset = 300e3 self.LO_freq = LO_freq = 137.903e6 self.BPF_width = BPF_width = 140e3 ################################################## # Blocks ################################################## self.rtlsdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + '' ) self.rtlsdr_source_0.set_sample_rate(samp_rate) self.rtlsdr_source_0.set_center_freq(LO_freq-Tuning_offset, 0) self.rtlsdr_source_0.set_freq_corr(0, 0) self.rtlsdr_source_0.set_dc_offset_mode(2, 0) self.rtlsdr_source_0.set_iq_balance_mode(2, 0) self.rtlsdr_source_0.set_gain_mode(False, 0) self.rtlsdr_source_0.set_gain(42, 0) self.rtlsdr_source_0.set_if_gain(20, 0) self.rtlsdr_source_0.set_bb_gain(10, 0) self.rtlsdr_source_0.set_antenna('', 0) self.rtlsdr_source_0.set_bandwidth(0, 0) self.root_raised_cosine_filter_0 = filter.fir_filter_ccf(1, firdes.root_raised_cosine( 1, samp_rate/decimation, symb_rate, 0.3, 361)) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(decimation, (firdes.low_pass(1,samp_rate,BPF_width/2,20e3)), Tuning_offset, samp_rate) (self.freq_xlating_fir_filter_xxx_0).set_processor_affinity([0]) self.digital_costas_loop_cc_0 = digital.costas_loop_cc(1e-3, 4) (self.digital_costas_loop_cc_0).set_processor_affinity([1]) self.digital_constellation_soft_decoder_cf_1 = digital.constellation_soft_decoder_cf(digital.constellation_calcdist(([-1-1j, -1+1j, 1+1j, 1-1j]), ([0, 1, 3, 2]), 4, 1).base()) self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_cc(samp_per_sym*(1+0.0), clock_alpha**2/4.0, 0.5, clock_alpha, 0.005) (self.digital_clock_recovery_mm_xx_0).set_processor_affinity([2]) self.blocks_float_to_char_0 = blocks.float_to_char(1, 127) self.blocks_file_sink_0_0 = blocks.file_sink(gr.sizeof_char*1, bitstream_name, False) self.blocks_file_sink_0_0.set_unbuffered(False) self.analog_rail_ff_0 = analog.rail_ff(-1, 1) self.analog_agc_xx_0 = analog.agc_cc(1000e-4, 0.5, 1.0) self.analog_agc_xx_0.set_max_gain(4000) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0, 0), (self.root_raised_cosine_filter_0, 0)) self.connect((self.analog_rail_ff_0, 0), (self.blocks_float_to_char_0, 0)) self.connect((self.blocks_float_to_char_0, 0), (self.blocks_file_sink_0_0, 0)) self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.digital_constellation_soft_decoder_cf_1, 0)) self.connect((self.digital_constellation_soft_decoder_cf_1, 0), (self.analog_rail_ff_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.digital_clock_recovery_mm_xx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.root_raised_cosine_filter_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.rtlsdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
def test_001_sets(self): agc = analog.agc_cc(1e-3, 1, 1) agc.set_rate(1) agc.set_reference(1.1) agc.set_gain(1.1) agc.set_max_gain(100) self.assertAlmostEqual(agc.rate(), 1) self.assertAlmostEqual(agc.reference(), 1.1) self.assertAlmostEqual(agc.gain(), 1.1) self.assertAlmostEqual(agc.max_gain(), 100)
def __init__(self): gr.top_block.__init__(self, "Meteor QPSK LRPT") # get some variables in place for inputs # # Arguments: # 1. Full path and name of stream file (including file extension) # 2. Gain to be used # 3. Frequency offset (PPM) # 4. SDR Device ID from settings.yml (for RTL-SDR source block) # 5. Bias-T (0/1 for RTL-SDR) stream_name = sys.argv[1] gain = float(sys.argv[2]) freq_offset = int(sys.argv[3]) sdr_dev_id = sys.argv[4] bias_t_string = sys.argv[5] bias_t = "1" if not bias_t_string: bias_t = "0" ################################################## # Variables ################################################## self.samp_rate_airspy = samp_rate_airspy = 1250000 self.decim = decim = 8 self.symb_rate = symb_rate = 72000 self.samp_rate = samp_rate = samp_rate_airspy / decim self.sps = sps = (samp_rate * 1.0) / (symb_rate * 1.0) self.pll_alpha = pll_alpha = 0.006 self.freq = freq = 137100000 self.clock_alpha = clock_alpha = 0.002 self.bitstream_name = bitstream_name = stream_name ############################################################################################################################################## # Blocks -- *** NOTE HOW THE VARIABLES ARE CARRIED IN FROM settings.yml - this has to be re-done every time you export the .py from gnuradio ############################################################################################################################################### self.rtlsdr_source_0 = osmosdr.source(args='numchan=' + str(1) + ' ' + 'rtl=' + str(sdr_dev_id) + ',bias=' + bias_t + '') self.rtlsdr_source_0.set_sample_rate(samp_rate_airspy) self.rtlsdr_source_0.set_center_freq(freq, 0) self.rtlsdr_source_0.set_freq_corr(freq_offset, 0) self.rtlsdr_source_0.set_dc_offset_mode(0, 0) self.rtlsdr_source_0.set_iq_balance_mode(0, 0) # determine if gain is specified or if auto-gain should be used if (gain == 0): self.rtlsdr_source_0.set_gain_mode(True, 0) else: self.rtlsdr_source_0.set_gain_mode(False, 0) self.rtlsdr_source_0.set_gain(gain, 0) self.rtlsdr_source_0.set_if_gain(0, 0) self.rtlsdr_source_0.set_bb_gain(0, 0) self.rtlsdr_source_0.set_antenna('', 0) self.rtlsdr_source_0.set_bandwidth(1500000, 0) self.root_raised_cosine_filter_0 = filter.fir_filter_ccf( 1, firdes.root_raised_cosine(1, samp_rate, symb_rate, 0.6, 361)) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=1, decimation=decim, taps=None, fractional_bw=None, ) self.digital_costas_loop_cc_0 = digital.costas_loop_cc( pll_alpha, 4, False) self.digital_constellation_soft_decoder_cf_1 = digital.constellation_soft_decoder_cf( digital.constellation_calcdist( ([-1 - 1j, -1 + 1j, 1 + 1j, 1 - 1j]), ([0, 1, 3, 2]), 4, 1).base()) self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_cc( sps, clock_alpha**2 / 4.0, 0.5, clock_alpha, 0.005) self.blocks_float_to_char_0 = blocks.float_to_char(1, 127) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char * 1, bitstream_name, False) self.blocks_file_sink_0.set_unbuffered(False) self.analog_rail_ff_0 = analog.rail_ff(-1, 1) self.analog_agc_xx_0 = analog.agc_cc(1000e-4, 0.5, 1.0) self.analog_agc_xx_0.set_max_gain(4000) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0, 0), (self.root_raised_cosine_filter_0, 0)) self.connect((self.analog_rail_ff_0, 0), (self.blocks_float_to_char_0, 0)) self.connect((self.blocks_float_to_char_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.digital_constellation_soft_decoder_cf_1, 0)) self.connect((self.digital_constellation_soft_decoder_cf_1, 0), (self.analog_rail_ff_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.digital_clock_recovery_mm_xx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.root_raised_cosine_filter_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.rtlsdr_source_0, 0), (self.rational_resampler_xxx_0, 0))
def __init__(self): gr.top_block.__init__(self, "Downlink for EM") Qt.QWidget.__init__(self) self.setWindowTitle("Downlink for EM") 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", "downlink_em") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.block_len_enc = block_len_enc = 1024 / 8 * 2 self.variable_constellation_0 = variable_constellation_0 = digital.constellation_calcdist( ([-1, 1]), ([0, 1]), 4, 1).base() self.samp_rate = samp_rate = 250000 self.payload = payload = block_len_enc + 4 self.oversample = oversample = 5 self.frequency_offset_correction = frequency_offset_correction = 89e2 ################################################## # Blocks ################################################## self._frequency_offset_correction_range = Range( -120000, 120000, 100, 89e2, 200) self._frequency_offset_correction_win = RangeWidget( self._frequency_offset_correction_range, self.set_frequency_offset_correction, 'Frequency Correction', "counter_slider", float) self.top_grid_layout.addWidget(self._frequency_offset_correction_win, 0, 0, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self.rational_resampler_xxx_1 = filter.rational_resampler_ccc( interpolation=1, decimation=5, taps=None, fractional_bw=None, ) self.qtgui_sink_x_0_0_1 = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 145.79e6, #fc samp_rate * 4, #bw "Vor Sync", #name True, #plotfreq True, #plotwaterfall True, #plottime True, #plotconst ) self.qtgui_sink_x_0_0_1.set_update_time(1.0 / 10) self._qtgui_sink_x_0_0_1_win = sip.wrapinstance( self.qtgui_sink_x_0_0_1.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_sink_x_0_0_1_win, 1, 0, 1, 1) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_sink_x_0_0_1.enable_rf_freq(False) self.qtgui_sink_x_0_0_0_0 = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate / 5, #bw "Vor Sync", #name True, #plotfreq True, #plotwaterfall True, #plottime True, #plotconst ) self.qtgui_sink_x_0_0_0_0.set_update_time(1.0 / 10) self._qtgui_sink_x_0_0_0_0_win = sip.wrapinstance( self.qtgui_sink_x_0_0_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_sink_x_0_0_0_0_win, 2, 0, 1, 1) for r in range(2, 3): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_sink_x_0_0_0_0.enable_rf_freq(False) self.qtgui_sink_x_0_0_0 = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate / 5, #bw "Vor Sync", #name True, #plotfreq True, #plotwaterfall True, #plottime True, #plotconst ) self.qtgui_sink_x_0_0_0.set_update_time(1.0 / 10) self._qtgui_sink_x_0_0_0_win = sip.wrapinstance( self.qtgui_sink_x_0_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_sink_x_0_0_0_win, 3, 0, 1, 1) for r in range(3, 4): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_sink_x_0_0_0.enable_rf_freq(False) self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + '') self.osmosdr_source_0.set_sample_rate(samp_rate * oversample) self.osmosdr_source_0.set_center_freq(145.85e6, 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(True, 0) self.osmosdr_source_0.set_gain(30 * 1, 0) self.osmosdr_source_0.set_if_gain(30 * 1, 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.digital_mpsk_receiver_cc_0_0 = digital.mpsk_receiver_cc( 2, 0, 31.41e-3, -0.01, 0.01, 0.25, 0.05, samp_rate / 5 / 12.5e3, 0.01, 0.005) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb( variable_constellation_0) self.ccsds_softbits_msg_to_bytes_b_0 = ccsds.softbits_msg_to_bytes_b() self.ccsds_send_nanolink_0 = ccsds.send_nanolink( "https://move2radio.lrt.mw.tum.de") self.ccsds_randomiser_softbits_0 = ccsds.randomiser_softbits( 0x95, 0xFF) self.ccsds_mpsk_ambiguity_resolver_f_0 = ccsds.mpsk_ambiguity_resolver_f( 2, '49E0DCC7', 32, 1, 0.8, block_len_enc, 0) self.ccsds_ldpc_decoder_0 = ccsds.ldpc_decoder( '/tmp/AR4JA_r12_k1024n.a', ccsds.LDPC_SYS_FRONT, ccsds.LDPC_PUNCT_BACK, 512, tuple(([]))) self.ccsds_blob_msg_sink_b_0 = ccsds.blob_msg_sink_b(256 / 2) self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_char_to_float_0 = blocks.char_to_float(1, 0.5) self.blocks_add_const_vxx_0 = blocks.add_const_vff((-1, )) self.band_pass_filter_0 = filter.fir_filter_ccc( oversample, firdes.complex_band_pass(1, samp_rate * oversample, 40e3, 60e3, 6e3, firdes.WIN_HAMMING, 6.76)) self.analog_sig_source_x_0_0 = analog.sig_source_c( samp_rate * oversample, analog.GR_COS_WAVE, frequency_offset_correction, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, -50000, 1, 0) self.analog_agc_xx_0 = analog.agc_cc(1e-4, 0.5, 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.msg_connect((self.ccsds_blob_msg_sink_b_0, 'out'), (self.ccsds_send_nanolink_0, 'in')) self.msg_connect((self.ccsds_ldpc_decoder_0, 'out'), (self.ccsds_softbits_msg_to_bytes_b_0, 'in')) self.msg_connect((self.ccsds_mpsk_ambiguity_resolver_f_0, 'out'), (self.ccsds_randomiser_softbits_0, 'in')) self.msg_connect((self.ccsds_randomiser_softbits_0, 'out'), (self.ccsds_ldpc_decoder_0, 'in')) self.connect((self.analog_agc_xx_0, 0), (self.qtgui_sink_x_0_0_0_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.rational_resampler_xxx_1, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.band_pass_filter_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.ccsds_mpsk_ambiguity_resolver_f_0, 0)) self.connect((self.blocks_char_to_float_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.qtgui_sink_x_0_0_1, 0)) self.connect((self.ccsds_softbits_msg_to_bytes_b_0, 0), (self.ccsds_blob_msg_sink_b_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.digital_mpsk_receiver_cc_0_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.digital_mpsk_receiver_cc_0_0, 0), (self.qtgui_sink_x_0_0_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.rational_resampler_xxx_1, 0), (self.digital_mpsk_receiver_cc_0_0, 0))
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) usage="%prog: [options] [input_filename]. \n If you don't specify an input filename the usrp will be used as source\n " \ "Make sure your input capture file containes interleaved shorts not complex floats" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate") parser.add_option("-f", "--freq", type="eng_float", default=519.25e6, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-c", "--contrast", type="eng_float", default=1.0, help="set contrast (default is 1.0)") parser.add_option("-b", "--brightness", type="eng_float", default=0.0, help="set brightness (default is 0)") parser.add_option("-p", "--pal", action="store_true", default=False, help="PAL video format (this is the default)") parser.add_option("-n", "--ntsc", action="store_true", default=False, help="NTSC video format") parser.add_option( "-o", "--out-filename", type="string", default="sdl", help= "For example out_raw_uchar.gray. If you don't specify an output filename you will get a video_sink_sdl realtime output window. You then need to have gr-video-sdl installed)" ) parser.add_option("-r", "--repeat", action="store_false", default=True, help="repeat file in a loop") parser.add_option("", "--freq-min", type="eng_float", default=50.25e6, help="Set a minimum frequency [default=%default]") parser.add_option("", "--freq-max", type="eng_float", default=900.25e6, help="Set a maximum frequency [default=%default]") (options, args) = parser.parse_args() if not ((len(args) == 1) or (len(args) == 0)): parser.print_help() sys.exit(1) if len(args) == 1: filename = args[0] else: filename = None self.frame = frame self.panel = panel self.contrast = options.contrast self.brightness = options.brightness self.state = "FREQ" self.freq = 0 self.tv_freq_min = options.freq_min self.tv_freq_max = options.freq_max # build graph self.u = None if not (options.out_filename == "sdl"): options.repeat = False usrp_rate = options.samp_rate if not ((filename is None) or (filename == "usrp")): # file is data source self.filesource = blocks.file_source(gr.sizeof_short, filename, options.repeat) self.istoc = blocks.interleaved_short_to_complex() self.connect(self.filesource, self.istoc) self.src = self.istoc options.gain = 0.0 self.gain = 0.0 else: # use a UHD device self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if (options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if (options.antenna): self.u.set_antenna(options.antenna, 0) self.u.set_samp_rate(usrp_rate) dev_rate = self.u.get_samp_rate() if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start() + g.stop()) / 2.0 self.src = self.u self.gain = options.gain f2uc = blocks.float_to_uchar() # sdl window as final sink if not (options.pal or options.ntsc): options.pal = True #set default to PAL if options.pal: lines_per_frame = 625.0 frames_per_sec = 25.0 show_width = 768 elif options.ntsc: lines_per_frame = 525.0 frames_per_sec = 29.97002997 show_width = 640 width = int(usrp_rate / (lines_per_frame * frames_per_sec)) height = int(lines_per_frame) if (options.out_filename == "sdl"): #Here comes the tv screen, you have to build and install #gr-video-sdl for this (subproject of gnuradio, only in cvs #for now) try: video_sink = video_sdl.sink_uc(frames_per_sec, width, height, 0, show_width, height) except: print "gr-video-sdl is not installed" print "realtime \"sdl\" video output window is not available" raise SystemExit, 1 self.dst = video_sink else: print "You can use the imagemagick display tool to show the resulting imagesequence" print "use the following line to show the demodulated TV-signal:" print "display -depth 8 -size " +str(width)+ "x" + str(height) \ + " gray:" + options.out_filename print "(Use the spacebar to advance to next frames)" options.repeat = False file_sink = blocks.file_sink(gr.sizeof_char, options.out_filename) self.dst = file_sink self.agc = analog.agc_cc(1e-7, 1.0, 1.0) #1e-7 self.am_demod = blocks.complex_to_mag() self.set_blacklevel = blocks.add_const_ff(0.0) self.invert_and_scale = blocks.multiply_const_ff( 0.0) #-self.contrast *128.0*255.0/(200.0) # now wire it all together #sample_rate=options.width*options.height*options.framerate process_type = 'do_no_sync' if process_type == 'do_no_sync': self.connect(self.src, self.agc, self.am_demod, self.invert_and_scale, self.set_blacklevel, f2uc, self.dst) elif process_type == 'do_tv_sync_adv': #defaults: gr.tv_sync_adv (double sampling_freq, unsigned #int tv_format,bool output_active_video_only=false, bool #do_invert=false, double wanted_black_level=0.0, double #wanted_white_level=255.0, double avg_alpha=0.1, double #initial_gain=1.0, double initial_offset=0.0,bool #debug=false) #note, this block is not yet in cvs self.tv_sync_adv = gr.tv_sync_adv(usrp_rate, 0, False, False, 0.0, 255.0, 0.01, 1.0, 0.0, False) self.connect(self.src, self.am_demod, self.invert_and_scale, self.tv_sync_adv, s2f, f2uc, self.dst) elif process_type == 'do_nullsink': #self.connect (self.src, self.am_demod,self.invert_and_scale,f2uc,video_sink) c2r = blocks.complex_to_real() nullsink = blocks.null_sink(gr.sizeof_float) self.connect(self.src, c2r, nullsink) #video_sink) elif process_type == 'do_tv_sync_corr': frame_size = width * height #int(usrp_rate/25.0) nframes = 10 # 32 search_window = 20 * nframes debug = False video_alpha = 0.3 #0.1 corr_alpha = 0.3 #Note: this block is not yet in cvs tv_corr = gr.tv_correlator_ff(frame_size, nframes, search_window, video_alpha, corr_alpha, debug) shift = blocks.add_const_ff(-0.7) self.connect(self.src, self.agc, self.am_demod, tv_corr, self.invert_and_scale, self.set_blacklevel, f2uc, self.dst) else: # process_type=='do_test_image': src_vertical_bars = analog.sig_source_f(usrp_rate, analog.GR_SIN_WAVE, 10.0 * usrp_rate / 320, 255, 128) self.connect(src_vertical_bars, f2uc, self.dst) self._build_gui(vbox, usrp_rate, usrp_rate, usrp_rate) frange = self.u.get_freq_range() if (frange.start() > self.tv_freq_max or frange.stop() < self.tv_freq_min): sys.stderr.write( "Radio does not support required frequency range.\n") sys.exit(1) if (options.freq < self.tv_freq_min or options.freq > self.tv_freq_max): sys.stderr.write( "Requested frequency is outside of required frequency range.\n" ) sys.exit(1) # set initial values self.set_gain(options.gain) self.set_contrast(self.contrast) self.set_brightness(options.brightness) if not (self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def __init__(self,frame,panel,vbox,argv): stdgui2.std_top_block.__init__ (self,frame,panel,vbox,argv) usage="%prog: [options] [input_filename]. \n If you don't specify an input filename the usrp will be used as source\n " \ "Make sure your input capture file contains interleaved shorts not complex floats" parser=OptionParser(option_class=eng_option, usage=usage) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate") parser.add_option("-f", "--freq", type="eng_float", default=519.25e6, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-c", "--contrast", type="eng_float", default=1.0, help="set contrast (default is 1.0)") parser.add_option("-b", "--brightness", type="eng_float", default=0.0, help="set brightness (default is 0)") parser.add_option("-p", "--pal", action="store_true", default=False, help="PAL video format (this is the default)") parser.add_option("-n", "--ntsc", action="store_true", default=False, help="NTSC video format") parser.add_option("-o", "--out-filename", type="string", default="sdl", help="For example out_raw_uchar.gray. If you don't specify an output filename you will get a video_sink_sdl realtime output window. You then need to have gr-video-sdl installed)") parser.add_option("-r", "--repeat", action="store_false", default=True, help="repeat file in a loop") parser.add_option("", "--freq-min", type="eng_float", default=50.25e6, help="Set a minimum frequency [default=%default]") parser.add_option("", "--freq-max", type="eng_float", default=900.25e6, help="Set a maximum frequency [default=%default]") (options, args) = parser.parse_args() if not ((len(args) == 1) or (len(args) == 0)): parser.print_help() sys.exit(1) if len(args) == 1: filename = args[0] else: filename = None self.frame = frame self.panel = panel self.contrast = options.contrast self.brightness = options.brightness self.state = "FREQ" self.freq = 0 self.tv_freq_min = options.freq_min self.tv_freq_max = options.freq_max # build graph self.u=None if not (options.out_filename=="sdl"): options.repeat=False usrp_rate = options.samp_rate if not ((filename is None) or (filename=="usrp")): # file is data source self.filesource = blocks.file_source(gr.sizeof_short,filename,options.repeat) self.istoc = blocks.interleaved_short_to_complex() self.connect(self.filesource,self.istoc) self.src=self.istoc options.gain=0.0 self.gain=0.0 else: # use a UHD device self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if(options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if(options.antenna): self.u.set_antenna(options.antenna, 0) self.u.set_samp_rate(usrp_rate) dev_rate = self.u.get_samp_rate() if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start()+g.stop())/2.0 self.src=self.u self.gain = options.gain f2uc = blocks.float_to_uchar() # sdl window as final sink if not (options.pal or options.ntsc): options.pal=True #set default to PAL if options.pal: lines_per_frame=625.0 frames_per_sec=25.0 show_width=768 elif options.ntsc: lines_per_frame=525.0 frames_per_sec=29.97002997 show_width=640 width=int(usrp_rate/(lines_per_frame*frames_per_sec)) height=int(lines_per_frame) if (options.out_filename=="sdl"): #Here comes the tv screen, you have to build and install #gr-video-sdl for this (subproject of gnuradio, only in cvs #for now) try: video_sink = video_sdl.sink_uc ( frames_per_sec, width, height, 0, show_width, height) except: print "gr-video-sdl is not installed" print "realtime \"sdl\" video output window is not available" raise SystemExit, 1 self.dst=video_sink else: print "You can use the imagemagick display tool to show the resulting imagesequence" print "use the following line to show the demodulated TV-signal:" print "display -depth 8 -size " +str(width)+ "x" + str(height) \ + " gray:" + options.out_filename print "(Use the spacebar to advance to next frames)" options.repeat=False file_sink = blocks.file_sink(gr.sizeof_char, options.out_filename) self.dst =file_sink self.agc = analog.agc_cc(1e-7,1.0,1.0) #1e-7 self.am_demod = blocks.complex_to_mag () self.set_blacklevel = blocks.add_const_ff(0.0) self.invert_and_scale = blocks.multiply_const_ff (0.0) #-self.contrast *128.0*255.0/(200.0) # now wire it all together #sample_rate=options.width*options.height*options.framerate process_type='do_no_sync' if process_type=='do_no_sync': self.connect (self.src, self.agc,self.am_demod, self.invert_and_scale, self.set_blacklevel, f2uc,self.dst) elif process_type=='do_tv_sync_adv': #defaults: gr.tv_sync_adv (double sampling_freq, unsigned #int tv_format,bool output_active_video_only=false, bool #do_invert=false, double wanted_black_level=0.0, double #wanted_white_level=255.0, double avg_alpha=0.1, double #initial_gain=1.0, double initial_offset=0.0,bool #debug=false) #note, this block is not yet in cvs self.tv_sync_adv=gr.tv_sync_adv(usrp_rate, 0, False, False, 0.0, 255.0, 0.01, 1.0, 0.0, False) self.connect (self.src, self.am_demod, self.invert_and_scale, self.tv_sync_adv, s2f, f2uc, self.dst) elif process_type=='do_nullsink': #self.connect (self.src, self.am_demod,self.invert_and_scale,f2uc,video_sink) c2r=blocks.complex_to_real() nullsink=blocks.null_sink(gr.sizeof_float) self.connect (self.src, c2r,nullsink) #video_sink) elif process_type=='do_tv_sync_corr': frame_size=width*height #int(usrp_rate/25.0) nframes=10# 32 search_window=20*nframes debug=False video_alpha=0.3 #0.1 corr_alpha=0.3 #Note: this block is not yet in cvs tv_corr=gr.tv_correlator_ff(frame_size,nframes, search_window, video_alpha, corr_alpha,debug) shift = blocks.add_const_ff(-0.7) self.connect (self.src, self.agc, self.am_demod, tv_corr, self.invert_and_scale, self.set_blacklevel, f2uc, self.dst) else: # process_type=='do_test_image': src_vertical_bars = analog.sig_source_f(usrp_rate, analog.GR_SIN_WAVE, 10.0 *usrp_rate/320, 255,128) self.connect(src_vertical_bars, f2uc, self.dst) self._build_gui(vbox, usrp_rate, usrp_rate, usrp_rate) frange = self.u.get_freq_range() if(frange.start() > self.tv_freq_max or frange.stop() < self.tv_freq_min): sys.stderr.write("Radio does not support required frequency range.\n") sys.exit(1) if(options.freq < self.tv_freq_min or options.freq > self.tv_freq_max): sys.stderr.write("Requested frequency is outside of required frequency range.\n") sys.exit(1) # set initial values self.set_gain(options.gain) self.set_contrast(self.contrast) self.set_brightness(options.brightness) if not(self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def __init__(self): gr.top_block.__init__(self) usage=("%prog: [options] output_filename.\nSpecial output_filename" + \ "\"sdl\" will use video_sink_sdl as realtime output window. " + \ "You then need to have gr-video-sdl installed.\n" +\ "Make sure your input capture file containes interleaved " + \ "shorts not complex floats") parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate") parser.add_option("-c", "--contrast", type="eng_float", default=1.0, help="set contrast (default is 1.0)") parser.add_option("-b", "--brightness", type="eng_float", default=0.0, help="set brightness (default is 0)") parser.add_option("-i", "--in-filename", type="string", default=None, help="Use input file as source. samples must be " + \ "interleaved shorts \n Use usrp_rx_file.py or " + \ "usrp_rx_cfile.py --output-shorts.\n Special " + \ "name \"usrp\" results in realtime capturing " + \ "and processing using usrp.\n" + \ "You then probably need a decimation factor of 64 or higher.") parser.add_option( "-f", "--freq", type="eng_float", default=519.25e6, help= "set frequency to FREQ.\nNote that the frequency of the video carrier is not at the middle of the TV channel", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-p", "--pal", action="store_true", default=False, help="PAL video format (this is the default)") parser.add_option("-n", "--ntsc", action="store_true", default=False, help="NTSC video format") parser.add_option("-r", "--repeat", action="store_false", default=True, help="repeat in_file in a loop") parser.add_option("-N", "--nframes", type="eng_float", default=None, help="number of frames to collect [default=+inf]") parser.add_option("", "--freq-min", type="eng_float", default=50.25e6, help="Set a minimum frequency [default=%default]") parser.add_option("", "--freq-max", type="eng_float", default=900.25e6, help="Set a maximum frequency [default=%default]") (options, args) = parser.parse_args() if not (len(args) == 1): parser.print_help() sys.stderr.write('You must specify the output. FILENAME or sdl \n') sys.exit(1) filename = args[0] self.tv_freq_min = options.freq_min self.tv_freq_max = options.freq_max if options.in_filename is None: parser.print_help() sys.stderr.write( 'You must specify the input -i FILENAME or -i usrp\n') raise SystemExit, 1 if not (filename == "sdl"): options.repeat = False input_rate = options.samp_rate print "video sample rate %s" % (eng_notation.num_to_str(input_rate)) if not (options.in_filename == "usrp"): # file is data source, capture with usr_rx_csfile.py self.filesource = blocks.file_source(gr.sizeof_short, options.in_filename, options.repeat) self.istoc = blocks.interleaved_short_to_complex() self.connect(self.filesource, self.istoc) self.src = self.istoc else: if options.freq is None: parser.print_help() sys.stderr.write( 'You must specify the frequency with -f FREQ\n') raise SystemExit, 1 # build the graph self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if (options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if (options.antenna): self.u.set_antenna(options.antenna, 0) self.u.set_samp_rate(input_rate) dev_rate = self.u.get_samp_rate() self.src = self.u if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start() + g.stop()) / 2.0 self.u.set_gain(options.gain) r = self.u.set_center_freq(options.freq) if not r: sys.stderr.write('Failed to set frequency\n') raise SystemExit, 1 self.agc = analog.agc_cc(1e-7, 1.0, 1.0) #1e-7 self.am_demod = blocks.complex_to_mag() self.set_blacklevel = blocks.add_const_ff(options.brightness + 255.0) self.invert_and_scale = blocks.multiply_const_ff( -options.contrast * 128.0 * 255.0 / (200.0)) self.f2uc = blocks.float_to_uchar() # sdl window as final sink if not (options.pal or options.ntsc): options.pal = True #set default to PAL if options.pal: lines_per_frame = 625.0 frames_per_sec = 25.0 show_width = 768 elif options.ntsc: lines_per_frame = 525.0 frames_per_sec = 29.97002997 show_width = 640 width = int(input_rate / (lines_per_frame * frames_per_sec)) height = int(lines_per_frame) if filename == "sdl": #Here comes the tv screen, you have to build and install #gr-video-sdl for this (subproject of gnuradio) try: video_sink = video_sdl.sink_uc(frames_per_sec, width, height, 0, show_width, height) except: print "gr-video-sdl is not installed" print "realtime \"sdl\" video output window is not available" raise SystemExit, 1 self.dst = video_sink else: print "You can use the imagemagick display tool to show the resulting imagesequence" print "use the following line to show the demodulated TV-signal:" print "display -depth 8 -size " + str(width) + "x" + str( height) + " gray:" + filename print "(Use the spacebar to advance to next frames)" file_sink = blocks.file_sink(gr.sizeof_char, filename) self.dst = file_sink if options.nframes is None: self.connect(self.src, self.agc) else: self.head = blocks.head(gr.sizeof_gr_complex, int(options.nframes * width * height)) self.connect(self.src, self.head, self.agc) self.connect(self.agc, self.am_demod, self.invert_and_scale, self.set_blacklevel, self.f2uc, self.dst)
def __init__(self): gr.top_block.__init__(self, "ELEKTRO-L2/L3 TLM Demodulator") Qt.QWidget.__init__(self) self.setWindowTitle("ELEKTRO-L2/L3 TLM Demodulator") 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", "elektro_tlm") 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.file_rate = file_rate = 1024000 self.sym_rate = sym_rate = 5000.0 self.samp_rate = samp_rate = file_rate / 4 self.sps = sps = samp_rate / sym_rate self.offset = offset = 0 ################################################## # Blocks ################################################## self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=1, decimation=4, taps=None, fractional_bw=None) self.qtgui_time_raster_sink_x_0 = qtgui.time_raster_sink_b( samp_rate, 100, 1792, [], [], "", 1) self.qtgui_time_raster_sink_x_0.set_update_time(0.10) self.qtgui_time_raster_sink_x_0.set_intensity_range(-1, 1) self.qtgui_time_raster_sink_x_0.enable_grid(False) self.qtgui_time_raster_sink_x_0.enable_axis_labels(False) labels = ['', '', '', '', '', '', '', '', '', ''] colors = [2, 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 range(1): if len(labels[i]) == 0: self.qtgui_time_raster_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_raster_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_raster_sink_x_0.set_color_map(i, colors[i]) self.qtgui_time_raster_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_raster_sink_x_0_win = sip.wrapinstance( self.qtgui_time_raster_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_raster_sink_x_0_win, 3, 0, 1, 2) for r in range(3, 4): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 2): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c( 2048, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name 1) self.qtgui_freq_sink_x_0_0.set_update_time(0.01) self.qtgui_freq_sink_x_0_0.set_y_axis(-65, -15) self.qtgui_freq_sink_x_0_0.set_y_label('Relative Gain', 'dB') 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(0.1) self.qtgui_freq_sink_x_0_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0_0.enable_control_panel(False) self.qtgui_freq_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", "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 range(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, 0, 0, 1, 2) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 2): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 2048, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name 1) self.qtgui_freq_sink_x_0.set_update_time(0.01) self.qtgui_freq_sink_x_0.set_y_axis(-65, 0) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') 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.05) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) self.qtgui_freq_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", "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 range(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, 1, 0, 1, 1) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_const_sink_x_0 = qtgui.const_sink_c( 256, #size "", #name 1 #number of inputs ) self.qtgui_const_sink_x_0.set_update_time(0.01) self.qtgui_const_sink_x_0.set_y_axis(-0.5, 0.5) self.qtgui_const_sink_x_0.set_x_axis(-0.5, 0.5) 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(True) self.qtgui_const_sink_x_0.enable_axis_labels(False) 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 range(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_grid_layout.addWidget(self._qtgui_const_sink_x_0_win, 1, 1, 1, 1) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self.low_pass_filter_0_0 = filter.fir_filter_ccf( 1, firdes.low_pass(1, samp_rate, 4.5e3, 1e3, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0 = filter.fir_filter_ccf( 1, firdes.low_pass(1, samp_rate, 10e3, 1e3, firdes.WIN_HAMMING, 6.76)) self.freq_xlating_fft_filter_ccc_0 = filter.freq_xlating_fft_filter_ccc( 1, firdes.low_pass(1, samp_rate, samp_rate / (2 * 1), 1000), offset, samp_rate) self.freq_xlating_fft_filter_ccc_0.set_nthreads(1) self.freq_xlating_fft_filter_ccc_0.declare_sample_delay(0) self.digital_costas_loop_cc_0 = digital.costas_loop_cc(3e-3, 2, False) self.digital_clock_recovery_mm_xx_1 = digital.clock_recovery_mm_cc( sps * (1 + 0.0), 0.625e-3, 0.5, 0.175, 0.005) self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb() self.dc_blocker_xx_0 = filter.dc_blocker_cc(32, True) self.blocks_wavfile_source_0 = blocks.wavfile_source('', True) self.blocks_udp_sink_0 = blocks.udp_sink(gr.sizeof_gr_complex * 28, '127.0.0.1', 52001, 1472, True) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1, file_rate, True) self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_char * 1, 224) self.blocks_pack_k_bits_bb_0 = blocks.pack_k_bits_bb(8) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_moving_average_xx_0 = blocks.moving_average_cc( 2, 0.5, 4000, 1) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) self.analog_sig_source_x_0 = analog.sig_source_c( samp_rate, analog.GR_SIN_WAVE, -5000, 1, 0, 0) self.analog_agc_xx_0_0_0 = analog.agc_cc(10e-3, 500e-3, 0.5) self.analog_agc_xx_0_0_0.set_max_gain(4e3) self.analog_agc_xx_0_0 = analog.agc_cc(10e-3, 500e-3, 0.5) self.analog_agc_xx_0_0.set_max_gain(4e3) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.analog_agc_xx_0_0_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_complex_to_real_0, 0), (self.digital_binary_slicer_fb_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_moving_average_xx_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_0_0, 0)) self.connect((self.blocks_pack_k_bits_bb_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.blocks_udp_sink_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.analog_agc_xx_0_0, 0)) self.connect((self.blocks_wavfile_source_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_wavfile_source_0, 1), (self.blocks_float_to_complex_0, 1)) self.connect((self.dc_blocker_xx_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.digital_binary_slicer_fb_0, 0), (self.blocks_pack_k_bits_bb_0, 0)) self.connect((self.digital_binary_slicer_fb_0, 0), (self.qtgui_time_raster_sink_x_0, 0)) self.connect((self.digital_clock_recovery_mm_xx_1, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.digital_clock_recovery_mm_xx_1, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.digital_clock_recovery_mm_xx_1, 0)) self.connect((self.freq_xlating_fft_filter_ccc_0, 0), (self.analog_agc_xx_0_0_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.dc_blocker_xx_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, 0), (self.blocks_moving_average_xx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.freq_xlating_fft_filter_ccc_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.qtgui_freq_sink_x_0_0, 0))
def __init__(self): gr.top_block.__init__(self, "Analyzing interference") Qt.QWidget.__init__(self) self.setWindowTitle("Analyzing interference") 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", "comb") 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.xlate_bandwidth = xlate_bandwidth = 12000 self.tuning_freq = tuning_freq = 3330000 self.samp_rate_2 = samp_rate_2 = 6000000 / 64 self.samp_rate = samp_rate = 6000000 self.freq_offset = freq_offset = 3318730 ################################################## # Blocks ################################################## self._tuning_freq_range = Range(0, 6000000, 100, 3330000, 200) self._tuning_freq_win = RangeWidget(self._tuning_freq_range, self.set_tuning_freq, 'tuning_freq', "counter_slider", float) self.top_grid_layout.addWidget(self._tuning_freq_win) self.qtgui_waterfall_sink_x_1 = qtgui.waterfall_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 2681270, #fc samp_rate, #bw "", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_1.set_update_time(0.10) self.qtgui_waterfall_sink_x_1.enable_grid(False) self.qtgui_waterfall_sink_x_1.enable_axis_labels(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 range(1): if len(labels[i]) == 0: self.qtgui_waterfall_sink_x_1.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_1.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_1.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_1.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_1.set_intensity_range(-140, 10) self._qtgui_waterfall_sink_x_1_win = sip.wrapinstance( self.qtgui_waterfall_sink_x_1.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_1_win) self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate_2, #bw "", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_0.set_update_time(0.001) self.qtgui_waterfall_sink_x_0.enable_grid(False) self.qtgui_waterfall_sink_x_0.enable_axis_labels(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 range(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) self.qtgui_time_sink_x_0 = qtgui.time_sink_c( 1024, #size samp_rate_2, #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(True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_NORM, qtgui.TRIG_SLOPE_POS, 0.5, 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_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(True) self.qtgui_time_sink_x_0.enable_stem_plot(False) labels = [ 'Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5', 'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10' ] 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] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] for i in range(2): if len(labels[i]) == 0: if (i % 2 == 0): self.qtgui_time_sink_x_0.set_line_label( i, "Re{{Data {0}}}".format(i / 2)) else: self.qtgui_time_sink_x_0.set_line_label( i, "Im{{Data {0}}}".format(i / 2)) 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) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc( 64, firdes.low_pass(1, samp_rate, xlate_bandwidth, 3000), tuning_freq + freq_offset, samp_rate) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(.3) self.blocks_file_source_0 = blocks.file_source( gr.sizeof_gr_complex * 1, '/home/mg/Documents/signals/SDRuno_20200912_190336Z_2681kHz.cf32', True, 0, 0) self.blocks_file_source_0.set_begin_tag(pmt.PMT_NIL) self.audio_sink_0 = audio.sink(48000, '', True) self.analog_am_demod_cf_0 = analog.am_demod_cf( channel_rate=samp_rate_2, audio_decim=2, audio_pass=5000, audio_stop=5500, ) self.analog_agc_xx_0 = analog.agc_cc(6.25e-4, 1.0, 1.0) self.analog_agc_xx_0.set_max_gain(128) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0, 0), (self.analog_am_demod_cf_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.qtgui_waterfall_sink_x_0, 0)) self.connect((self.analog_am_demod_cf_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.qtgui_waterfall_sink_x_1, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.analog_agc_xx_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") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.volume = volume = 1 self.samp_rate = samp_rate = 2.88e6 self.freq = freq = 126.42e6 ################################################## # Blocks ################################################## self._volume_range = Range(0, 3, 10e-3, 1, 200) self._volume_win = RangeWidget(self._volume_range, self.set_volume, "volume", "counter_slider", float) self.top_layout.addWidget(self._volume_win) self._freq_range = Range(125.530e6, 126.7e6, 10e3, 126.42e6, 200) self._freq_win = RangeWidget(self._freq_range, self.set_freq, "freq", "counter_slider", float) self.top_layout.addWidget(self._freq_win) self.rtlsdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + '' ) self.rtlsdr_source_0.set_sample_rate(samp_rate) self.rtlsdr_source_0.set_center_freq(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(10, 0) self.rtlsdr_source_0.set_if_gain(20, 0) self.rtlsdr_source_0.set_bb_gain(20, 0) self.rtlsdr_source_0.set_antenna('', 0) self.rtlsdr_source_0.set_bandwidth(0, 0) self.qtgui_sink_x_0 = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate/60, #bw "", #name True, #plotfreq True, #plotwaterfall True, #plottime True, #plotconst ) self.qtgui_sink_x_0.set_update_time(1.0/10) self._qtgui_sink_x_0_win = sip.wrapinstance(self.qtgui_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_sink_x_0_win) self.qtgui_sink_x_0.enable_rf_freq(False) self.low_pass_filter_0 = filter.fir_filter_ccf(60, firdes.low_pass( 1, samp_rate, 5e3, 1e3, firdes.WIN_HAMMING, 6.76)) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((volume, )) self.audio_sink_0 = audio.sink(48000, '', True) self.analog_am_demod_cf_0 = analog.am_demod_cf( channel_rate=48e3, audio_decim=1, audio_pass=5000, audio_stop=5500, ) self.analog_agc_xx_0 = analog.agc_cc(1e-2, 1.0, 1.0) self.analog_agc_xx_0.set_max_gain(1e3) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0, 0), (self.analog_am_demod_cf_0, 0)) self.connect((self.analog_am_demod_cf_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.rtlsdr_source_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.rtlsdr_source_0, 0), (self.qtgui_sink_x_0, 0))
def __init__(self): gr.top_block.__init__(self, "Lab 3") Qt.QWidget.__init__(self) self.setWindowTitle("Lab 3") 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", "lab3") 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.freqc = freqc = 900 self.zeta = zeta = 0.707 self.std_dev = std_dev = 0.01 self.sps = sps = 8 self.samp_rate = samp_rate = 1000 self.nat_freq = nat_freq = 10000 self.lw = lw = 2 self.gain_ = gain_ = 0.5 self.freqc_ = freqc_ = freqc self.fps = fps = 30 self.fo = fo = 0 self.const_qpsk = const_qpsk = digital.constellation_calcdist(digital.psk_4()[0], digital.psk_4()[1], 4, 1).base() self.const_bpsk = const_bpsk = digital.constellation_calcdist(digital.psk_2()[0], digital.psk_2()[1], 2, 1).base() self.bw = bw = 1 self.buff_size = buff_size = 32768 self.bSignal = bSignal = 0 self.bSelectPLL = bSelectPLL = 0 self.axis = axis = 2 ################################################## # Blocks ################################################## self._zeta_range = Range(0, 4, 0.001, 0.707, 200) self._zeta_win = RangeWidget(self._zeta_range, self.set_zeta, 'Damping Factor (Zeta)', "counter_slider", float) self.top_grid_layout.addWidget(self._zeta_win, 13, 0, 1, 1) for r in range(13, 14): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self.tab0 = Qt.QTabWidget() self.tab0_widget_0 = Qt.QWidget() self.tab0_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab0_widget_0) self.tab0_grid_layout_0 = Qt.QGridLayout() self.tab0_layout_0.addLayout(self.tab0_grid_layout_0) self.tab0.addTab(self.tab0_widget_0, 'Loop Filter Output') self.tab0_widget_1 = Qt.QWidget() self.tab0_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab0_widget_1) self.tab0_grid_layout_1 = Qt.QGridLayout() self.tab0_layout_1.addLayout(self.tab0_grid_layout_1) self.tab0.addTab(self.tab0_widget_1, 'Spectrum') self.top_grid_layout.addWidget(self.tab0, 0, 0, 10, 2) for r in range(0, 10): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 2): self.top_grid_layout.setColumnStretch(c, 1) self._std_dev_range = Range(0, 0.1, 0.001, 0.01, 200) self._std_dev_win = RangeWidget(self._std_dev_range, self.set_std_dev, 'Noise Std. Dev', "counter_slider", float) self.top_grid_layout.addWidget(self._std_dev_win, 11, 0, 1, 1) for r in range(11, 12): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self._nat_freq_range = Range(0, 100e3, 1, 10000, 200) self._nat_freq_win = RangeWidget(self._nat_freq_range, self.set_nat_freq, 'Natural Freq (Hz)', "counter_slider", float) self.top_grid_layout.addWidget(self._nat_freq_win, 13, 1, 1, 1) for r in range(13, 14): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self._gain__range = Range(0.1, 1, 0.01, 0.5, 200) self._gain__win = RangeWidget(self._gain__range, self.set_gain_, 'Gain (Amp)', "counter_slider", float) self.top_grid_layout.addWidget(self._gain__win, 10, 1, 1, 1) for r in range(10, 11): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self._freqc__range = Range(70, 6000, .01, freqc, 200) self._freqc__win = RangeWidget(self._freqc__range, self.set_freqc_, 'Carrier (MHz)', "counter_slider", float) self.top_grid_layout.addWidget(self._freqc__win, 10, 0, 1, 1) for r in range(10, 11): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self._fo_range = Range(0, 100e3, 100, 0, 200) self._fo_win = RangeWidget(self._fo_range, self.set_fo, 'Frequency Offset (Hz)', "counter_slider", float) self.top_grid_layout.addWidget(self._fo_win, 11, 1, 1, 1) for r in range(11, 12): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) # Create the options list self._bSignal_options = (0, 1, 2, ) # Create the labels list self._bSignal_labels = ('Tone', 'BPSK', 'QPSK', ) # Create the combo box # Create the radio buttons self._bSignal_group_box = Qt.QGroupBox('Signal Select' + ": ") self._bSignal_box = Qt.QHBoxLayout() class variable_chooser_button_group(Qt.QButtonGroup): def __init__(self, parent=None): Qt.QButtonGroup.__init__(self, parent) @pyqtSlot(int) def updateButtonChecked(self, button_id): self.button(button_id).setChecked(True) self._bSignal_button_group = variable_chooser_button_group() self._bSignal_group_box.setLayout(self._bSignal_box) for i, _label in enumerate(self._bSignal_labels): radio_button = Qt.QRadioButton(_label) self._bSignal_box.addWidget(radio_button) self._bSignal_button_group.addButton(radio_button, i) self._bSignal_callback = lambda i: Qt.QMetaObject.invokeMethod(self._bSignal_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._bSignal_options.index(i))) self._bSignal_callback(self.bSignal) self._bSignal_button_group.buttonClicked[int].connect( lambda i: self.set_bSignal(self._bSignal_options[i])) self.top_grid_layout.addWidget(self._bSignal_group_box, 12, 0, 1, 1) for r in range(12, 13): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) # Create the options list self._bSelectPLL_options = (0, 1, 2, 3, ) # Create the labels list self._bSelectPLL_labels = ('Standard', 'Costas', 'Costas w/ HL', 'QPSK Costas', ) # Create the combo box # Create the radio buttons self._bSelectPLL_group_box = Qt.QGroupBox('PLL Order' + ": ") self._bSelectPLL_box = Qt.QHBoxLayout() class variable_chooser_button_group(Qt.QButtonGroup): def __init__(self, parent=None): Qt.QButtonGroup.__init__(self, parent) @pyqtSlot(int) def updateButtonChecked(self, button_id): self.button(button_id).setChecked(True) self._bSelectPLL_button_group = variable_chooser_button_group() self._bSelectPLL_group_box.setLayout(self._bSelectPLL_box) for i, _label in enumerate(self._bSelectPLL_labels): radio_button = Qt.QRadioButton(_label) self._bSelectPLL_box.addWidget(radio_button) self._bSelectPLL_button_group.addButton(radio_button, i) self._bSelectPLL_callback = lambda i: Qt.QMetaObject.invokeMethod(self._bSelectPLL_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._bSelectPLL_options.index(i))) self._bSelectPLL_callback(self.bSelectPLL) self._bSelectPLL_button_group.buttonClicked[int].connect( lambda i: self.set_bSelectPLL(self._bSelectPLL_options[i])) self.top_grid_layout.addWidget(self._bSelectPLL_group_box, 12, 1, 1, 1) for r in range(12, 13): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self.wes_costas_cc_0 = wes.costas_cc(nat_freq / (samp_rate*1000), zeta, bSelectPLL) self.qtgui_time_sink_x_0_0 = qtgui.time_sink_c( 4096, #size samp_rate*1000, #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(-10000, 10000) self.qtgui_time_sink_x_0_0.set_y_label('Frequency (Hz)', "") self.qtgui_time_sink_x_0_0.enable_tags(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(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(True) self.qtgui_time_sink_x_0_0.enable_stem_plot(False) labels = ['Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5', 'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10'] 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] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] for i in range(2): if len(labels[i]) == 0: if (i % 2 == 0): self.qtgui_time_sink_x_0_0.set_line_label(i, "Re{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_0_0.set_line_label(i, "Im{{Data {0}}}".format(i/2)) 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.tab0_grid_layout_0.addWidget(self._qtgui_time_sink_x_0_0_win, 5, 0, 5, 1) for r in range(5, 10): self.tab0_grid_layout_0.setRowStretch(r, 1) for c in range(0, 1): self.tab0_grid_layout_0.setColumnStretch(c, 1) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate*1e3, #bw "", #name 1 ) self.qtgui_freq_sink_x_0.set_update_time(1/fps) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') 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(1.0) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) labels = ['In-Phase', 'Quadrature', '', '', '', '', '', '', '', ''] 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 range(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.tab0_grid_layout_1.addWidget(self._qtgui_freq_sink_x_0_win, 5, 0, 5, 1) for r in range(5, 10): self.tab0_grid_layout_1.setRowStretch(r, 1) for c in range(0, 1): self.tab0_grid_layout_1.setColumnStretch(c, 1) self.qtgui_freq_sink_x_0.set_processor_affinity([0]) self.interp_fir_filter_xxx_1_0_0 = filter.interp_fir_filter_ccc(sps, (1,1,1,1,1,1,1,1)) self.interp_fir_filter_xxx_1_0_0.declare_sample_delay(0) self.interp_fir_filter_xxx_1_0 = filter.interp_fir_filter_ccc(sps, (1,1,1,1,1,1,1,1)) self.interp_fir_filter_xxx_1_0.declare_sample_delay(0) self.iio_pluto_source_0 = iio.pluto_source(epy_module_0.RX, int(freqc_*1e6), int(samp_rate*1000), 20000000, buff_size, True, True, True, 'manual', 32, '', True) self.iio_pluto_sink_0 = iio.pluto_sink(epy_module_0.TX, int(freqc_*1e6), int(samp_rate*1000), 20000000, buff_size, False, 10.0, '', True) self.digital_chunks_to_symbols_xx_1_0 = digital.chunks_to_symbols_bc(const_qpsk.points(), 1) self.digital_chunks_to_symbols_xx_1 = digital.chunks_to_symbols_bc(const_bpsk.points(), 1) self.blocks_tag_gate_0 = blocks.tag_gate(gr.sizeof_gr_complex * 1, False) self.blocks_tag_gate_0.set_single_key("") self.blocks_selector_0_0 = blocks.selector(gr.sizeof_gr_complex*1,bSignal,0) self.blocks_selector_0_0.set_enabled(True) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex*1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_2 = blocks.multiply_const_cc(1/6.28*samp_rate*1000) self.blocks_multiply_const_vxx_1 = blocks.multiply_const_cc(0) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_cc(gain_ ) self.blocks_add_xx_0 = blocks.add_vcc(1) self.blocks_add_const_vxx_0 = blocks.add_const_cc(1) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate*1000, analog.GR_COS_WAVE, fo, 1, 0, 0) self.analog_random_source_x_0_0 = blocks.vector_source_b(list(map(int, numpy.random.randint(0, 4, 8192))), True) self.analog_random_source_x_0 = blocks.vector_source_b(list(map(int, numpy.random.randint(0, 2, 8192))), True) self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, std_dev, 0) self.analog_agc_xx_0 = analog.agc_cc(1e-4, 1.0, 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.wes_costas_cc_0, 0)) self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.analog_random_source_x_0, 0), (self.digital_chunks_to_symbols_xx_1, 0)) self.connect((self.analog_random_source_x_0_0, 0), (self.digital_chunks_to_symbols_xx_1_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_selector_0_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_2, 0), (self.qtgui_time_sink_x_0_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.iio_pluto_sink_0, 0)) self.connect((self.blocks_selector_0_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_tag_gate_0, 0), (self.blocks_multiply_const_vxx_2, 0)) self.connect((self.digital_chunks_to_symbols_xx_1, 0), (self.interp_fir_filter_xxx_1_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_1_0, 0), (self.interp_fir_filter_xxx_1_0_0, 0)) self.connect((self.iio_pluto_source_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.interp_fir_filter_xxx_1_0, 0), (self.blocks_multiply_const_vxx_1, 0)) self.connect((self.interp_fir_filter_xxx_1_0, 0), (self.blocks_selector_0_0, 1)) self.connect((self.interp_fir_filter_xxx_1_0_0, 0), (self.blocks_selector_0_0, 2)) self.connect((self.wes_costas_cc_0, 0), (self.blocks_null_sink_0, 0)) self.connect((self.wes_costas_cc_0, 1), (self.blocks_tag_gate_0, 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.variable_slider_1 = variable_slider_1 = 1000 self.variable_slider_0 = variable_slider_0 = 0.5 self.samp_rate = samp_rate = 48000 ################################################## # Blocks ################################################## _variable_slider_1_sizer = wx.BoxSizer(wx.VERTICAL) self._variable_slider_1_text_box = forms.text_box( parent=self.GetWin(), sizer=_variable_slider_1_sizer, value=self.variable_slider_1, callback=self.set_variable_slider_1, label='tone frequency', converter=forms.float_converter(), proportion=0, ) self._variable_slider_1_slider = forms.slider( parent=self.GetWin(), sizer=_variable_slider_1_sizer, value=self.variable_slider_1, callback=self.set_variable_slider_1, minimum=500, maximum=2000, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_variable_slider_1_sizer) _variable_slider_0_sizer = wx.BoxSizer(wx.VERTICAL) self._variable_slider_0_text_box = forms.text_box( parent=self.GetWin(), sizer=_variable_slider_0_sizer, value=self.variable_slider_0, callback=self.set_variable_slider_0, label='Microphone Audio level', converter=forms.float_converter(), proportion=0, ) self._variable_slider_0_slider = forms.slider( parent=self.GetWin(), sizer=_variable_slider_0_sizer, value=self.variable_slider_0, callback=self.set_variable_slider_0, minimum=0, maximum=0.5, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_variable_slider_0_sizer) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc( 1, ([1]), -10000, samp_rate) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blks2_tcp_sink_0 = grc_blks2.tcp_sink( itemsize=gr.sizeof_gr_complex * 1, addr='raspberrypi.local', port=8011, server=False, ) self.band_pass_filter_0 = filter.fir_filter_ccc( 1, firdes.complex_band_pass(1, samp_rate, 300, 3000, 100, firdes.WIN_HAMMING, 6.76)) self.audio_source_0 = audio.source(samp_rate, '', True) self.analog_const_source_x_0 = analog.sig_source_f( 0, analog.GR_CONST_WAVE, 0, 0, 0) self.analog_agc_xx_0 = analog.agc_cc(1e-4, 1.0, 1.0) self.analog_agc_xx_0.set_max_gain(65535) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.analog_const_source_x_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.audio_source_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.blks2_tcp_sink_0, 0))
def __init__(self, freq=1698e6, rate=2e6, frames_file=os.environ['HOME'] + '/data/noaa/frames/NOAA-XX.hrpt', rtlsdr="rtl=0", ifgain=20, satellite='NOAA-XX', sync_check=False, rfgain=40): grc_wxgui.top_block_gui.__init__(self, title="Enhanced NOAA HRPT Receiver using USB DVB-T Dongles") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.freq = freq self.rate = rate self.frames_file = frames_file self.rtlsdr = rtlsdr self.ifgain = ifgain self.satellite = satellite self.sync_check = sync_check self.rfgain = rfgain ################################################## # Variables ################################################## self.sym_rate = sym_rate = 600*1109 self.samp_rate = samp_rate = rate self.config_filename = config_filename = os.environ['HOME']+'/.gnuradio/rtlsdr_noaa_hrpt.conf' self.sps = sps = samp_rate/sym_rate self._saved_pll_alpha_config = ConfigParser.ConfigParser() self._saved_pll_alpha_config.read(config_filename) try: saved_pll_alpha = self._saved_pll_alpha_config.getfloat(satellite, 'pll_alpha') except: saved_pll_alpha = 0.005 self.saved_pll_alpha = saved_pll_alpha self._saved_clock_alpha_config = ConfigParser.ConfigParser() self._saved_clock_alpha_config.read(config_filename) try: saved_clock_alpha = self._saved_clock_alpha_config.getfloat(satellite, 'clock_alpha') except: saved_clock_alpha = 0.001 self.saved_clock_alpha = saved_clock_alpha self.sync_check_cb = sync_check_cb = sync_check self._saved_rf_gain_config = ConfigParser.ConfigParser() self._saved_rf_gain_config.read(config_filename) try: saved_rf_gain = self._saved_rf_gain_config.getfloat(satellite, 'rf-gain') except: saved_rf_gain = rfgain self.saved_rf_gain = saved_rf_gain self._saved_if_gain_config = ConfigParser.ConfigParser() self._saved_if_gain_config.read(config_filename) try: saved_if_gain = self._saved_if_gain_config.getfloat(satellite, 'if-gain') except: saved_if_gain = ifgain self.saved_if_gain = saved_if_gain self.satellite_text = satellite_text = satellite self.sample_rate_text = sample_rate_text = samp_rate self.rf_gain_slider = rf_gain_slider = rfgain self.rate_tb = rate_tb = rate self.pll_alpha = pll_alpha = saved_pll_alpha self.max_clock_offset = max_clock_offset = 0.1 self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/samp_rate self.if_gain_slider = if_gain_slider = ifgain self.hs = hs = int(sps/2.0) self.freq_tb = freq_tb = freq self.frames_outfile_text = frames_outfile_text = frames_file self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime()) self.clock_alpha = clock_alpha = saved_clock_alpha ################################################## # Blocks ################################################## _rf_gain_slider_sizer = wx.BoxSizer(wx.VERTICAL) self._rf_gain_slider_text_box = forms.text_box( parent=self.GetWin(), sizer=_rf_gain_slider_sizer, value=self.rf_gain_slider, callback=self.set_rf_gain_slider, label="RF Gain", converter=forms.int_converter(), proportion=0, ) self._rf_gain_slider_slider = forms.slider( parent=self.GetWin(), sizer=_rf_gain_slider_sizer, value=self.rf_gain_slider, callback=self.set_rf_gain_slider, minimum=0, maximum=100, num_steps=100, style=wx.SL_HORIZONTAL, cast=int, proportion=1, ) self.GridAdd(_rf_gain_slider_sizer, 2, 0, 1, 1) _if_gain_slider_sizer = wx.BoxSizer(wx.VERTICAL) self._if_gain_slider_text_box = forms.text_box( parent=self.GetWin(), sizer=_if_gain_slider_sizer, value=self.if_gain_slider, callback=self.set_if_gain_slider, label="IF Gain", converter=forms.int_converter(), proportion=0, ) self._if_gain_slider_slider = forms.slider( parent=self.GetWin(), sizer=_if_gain_slider_sizer, value=self.if_gain_slider, callback=self.set_if_gain_slider, minimum=0, maximum=100, num_steps=100, style=wx.SL_HORIZONTAL, cast=int, proportion=1, ) self.GridAdd(_if_gain_slider_sizer, 2, 1, 1, 1) self.displays = self.displays = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.displays.AddPage(grc_wxgui.Panel(self.displays), "RX NOAA HRPT") self.displays.AddPage(grc_wxgui.Panel(self.displays), "Information") self.Add(self.displays) _clock_alpha_sizer = wx.BoxSizer(wx.VERTICAL) self._clock_alpha_text_box = forms.text_box( parent=self.GetWin(), sizer=_clock_alpha_sizer, value=self.clock_alpha, callback=self.set_clock_alpha, label="Clock alpha", converter=forms.float_converter(), proportion=0, ) self._clock_alpha_slider = forms.slider( parent=self.GetWin(), sizer=_clock_alpha_sizer, value=self.clock_alpha, callback=self.set_clock_alpha, minimum=0.001, maximum=0.1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_clock_alpha_sizer, 2, 3, 1, 1) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.displays.GetPage(0).GetWin(), baseband_freq=0, y_per_div=5, y_divs=10, ref_level=-30, ref_scale=2.0, sample_rate=samp_rate, fft_size=512, fft_rate=5, average=True, avg_alpha=0.4, title="NOAA HRPT FFT Spectrum", peak_hold=False, ) self.displays.GetPage(0).Add(self.wxgui_fftsink2_0.win) self._sync_check_cb_check_box = forms.check_box( parent=self.GetWin(), value=self.sync_check_cb, callback=self.set_sync_check_cb, label="Continuous sync check", true=True, false=False, ) self.GridAdd(self._sync_check_cb_check_box, 1, 2, 1, 1) self._satellite_text_static_text = forms.static_text( parent=self.GetWin(), value=self.satellite_text, callback=self.set_satellite_text, label="Satellite", converter=forms.str_converter(), ) self.GridAdd(self._satellite_text_static_text, 0, 1, 1, 1) self._sample_rate_text_static_text = forms.static_text( parent=self.displays.GetPage(1).GetWin(), value=self.sample_rate_text, callback=self.set_sample_rate_text, label="Sample rate", converter=forms.float_converter(), ) self.displays.GetPage(1).GridAdd(self._sample_rate_text_static_text, 3, 0, 1, 1) self._rate_tb_text_box = forms.text_box( parent=self.GetWin(), value=self.rate_tb, callback=self.set_rate_tb, label="Sample rate", converter=forms.float_converter(), ) self.GridAdd(self._rate_tb_text_box, 1, 0, 1, 1) self.poesweather_noaa_hrpt_deframer_0 = poesweather.noaa_hrpt_deframer(False) _pll_alpha_sizer = wx.BoxSizer(wx.VERTICAL) self._pll_alpha_text_box = forms.text_box( parent=self.GetWin(), sizer=_pll_alpha_sizer, value=self.pll_alpha, callback=self.set_pll_alpha, label="PLL Alpha", converter=forms.float_converter(), proportion=0, ) self._pll_alpha_slider = forms.slider( parent=self.GetWin(), sizer=_pll_alpha_sizer, value=self.pll_alpha, callback=self.set_pll_alpha, minimum=0.005, maximum=0.5, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_pll_alpha_sizer, 2, 2, 1, 1) self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset) self.osmosdr_source_c_0 = osmosdr.source_c( args="nchan=" + str(1) + " " + rtlsdr ) self.osmosdr_source_c_0.set_sample_rate(samp_rate) self.osmosdr_source_c_0.set_center_freq(freq, 0) self.osmosdr_source_c_0.set_freq_corr(0, 0) self.osmosdr_source_c_0.set_iq_balance_mode(0, 0) self.osmosdr_source_c_0.set_gain_mode(0, 0) self.osmosdr_source_c_0.set_gain(rf_gain_slider, 0) self.osmosdr_source_c_0.set_if_gain(if_gain_slider, 0) self._freq_tb_text_box = forms.text_box( parent=self.GetWin(), value=self.freq_tb, callback=self.set_freq_tb, label="Frequency", converter=forms.float_converter(), ) self.GridAdd(self._freq_tb_text_box, 1, 1, 1, 1) self._frames_outfile_text_static_text = forms.static_text( parent=self.displays.GetPage(1).GetWin(), value=self.frames_outfile_text, callback=self.set_frames_outfile_text, label="Frames filename", converter=forms.str_converter(), ) self.displays.GetPage(1).GridAdd(self._frames_outfile_text_static_text, 4, 0, 1, 1) self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_ff(sps/2.0, clock_alpha**2/4.0, 0.5, clock_alpha, max_clock_offset) self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb() self._datetime_text_static_text = forms.static_text( parent=self.displays.GetPage(1).GetWin(), value=self.datetime_text, callback=self.set_datetime_text, label="Acquisition start", converter=forms.str_converter(), ) self.displays.GetPage(1).GridAdd(self._datetime_text_static_text, 2, 0, 1, 1) self.blocks_moving_average_xx_0 = blocks.moving_average_ff(hs, 1.0/hs, 4000) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_short*1, frames_file) self.blocks_file_sink_0.set_unbuffered(False) self.analog_agc_xx_0 = analog.agc_cc(1e-5, 1.0, 1.0/32768.0, 1.0) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0, 0), (self.pll, 0)) self.connect((self.pll, 0), (self.blocks_moving_average_xx_0, 0)) self.connect((self.blocks_moving_average_xx_0, 0), (self.digital_clock_recovery_mm_xx_0, 0)) self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.digital_binary_slicer_fb_0, 0)) self.connect((self.poesweather_noaa_hrpt_deframer_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.digital_binary_slicer_fb_0, 0), (self.poesweather_noaa_hrpt_deframer_0, 0)) self.connect((self.osmosdr_source_c_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.osmosdr_source_c_0, 0), (self.analog_agc_xx_0, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="AM Receiver") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 64e6 / 256 self.offset_fine = offset_fine = 0 self.offset_coarse = offset_coarse = 0 self.freq = freq = 15000000 self.LO = LO = 0 self.xlate_filter_taps = xlate_filter_taps = firdes.low_pass( 1, samp_rate, 125000, 25000, firdes.WIN_HAMMING, 6.76 ) self.width = width = 10000 self.trans = trans = 1500 self.rx_freq = rx_freq = LO + freq + (offset_coarse + offset_fine) self.rf_gain = rf_gain = 10 self.lo_freq = lo_freq = LO self.display_selector = display_selector = 0 self.af_gain = af_gain = 0.200 ################################################## # Blocks ################################################## _width_sizer = wx.BoxSizer(wx.VERTICAL) self._width_text_box = forms.text_box( parent=self.GetWin(), sizer=_width_sizer, value=self.width, callback=self.set_width, label="Filter", converter=forms.float_converter(), proportion=0, ) self._width_slider = forms.slider( parent=self.GetWin(), sizer=_width_sizer, value=self.width, callback=self.set_width, minimum=2000, maximum=40000, num_steps=760, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_width_sizer, 7, 0, 1, 1) _trans_sizer = wx.BoxSizer(wx.VERTICAL) self._trans_text_box = forms.text_box( parent=self.GetWin(), sizer=_trans_sizer, value=self.trans, callback=self.set_trans, label="Trans", converter=forms.float_converter(), proportion=0, ) self._trans_slider = forms.slider( parent=self.GetWin(), sizer=_trans_sizer, value=self.trans, callback=self.set_trans, minimum=500, maximum=5000, num_steps=900, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_trans_sizer, 8, 0, 1, 1) self._rx_freq_static_text = forms.static_text( parent=self.GetWin(), value=self.rx_freq, callback=self.set_rx_freq, label="Receive", converter=forms.float_converter(), ) self.GridAdd(self._rx_freq_static_text, 5, 3, 1, 1) _rf_gain_sizer = wx.BoxSizer(wx.VERTICAL) self._rf_gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_rf_gain_sizer, value=self.rf_gain, callback=self.set_rf_gain, label="RF", converter=forms.float_converter(), proportion=0, ) self._rf_gain_slider = forms.slider( parent=self.GetWin(), sizer=_rf_gain_sizer, value=self.rf_gain, callback=self.set_rf_gain, minimum=0, maximum=50, num_steps=50, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_rf_gain_sizer, 7, 1, 1, 1) self._display_selector_chooser = forms.drop_down( parent=self.GetWin(), value=self.display_selector, callback=self.set_display_selector, label="Spectrum", choices=[0, 1], labels=["Baseband", "USRP"], ) self.GridAdd(self._display_selector_chooser, 5, 0, 1, 1) _af_gain_sizer = wx.BoxSizer(wx.VERTICAL) self._af_gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_af_gain_sizer, value=self.af_gain, callback=self.set_af_gain, label="VOL", converter=forms.float_converter(), proportion=0, ) self._af_gain_slider = forms.slider( parent=self.GetWin(), sizer=_af_gain_sizer, value=self.af_gain, callback=self.set_af_gain, minimum=0, maximum=1, num_steps=500, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_af_gain_sizer, 8, 1, 1, 1) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=8, decimation=45, taps=(5,), fractional_bw=None ) self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + "") self.osmosdr_source_0.set_sample_rate(samp_rate) self.osmosdr_source_0.set_center_freq(rx_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(2, 0) self.osmosdr_source_0.set_gain_mode(True, 0) self.osmosdr_source_0.set_gain(rf_gain, 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) _offset_fine_sizer = wx.BoxSizer(wx.VERTICAL) self._offset_fine_text_box = forms.text_box( parent=self.GetWin(), sizer=_offset_fine_sizer, value=self.offset_fine, callback=self.set_offset_fine, label="Fine tune", converter=forms.float_converter(), proportion=0, ) self._offset_fine_slider = forms.slider( parent=self.GetWin(), sizer=_offset_fine_sizer, value=self.offset_fine, callback=self.set_offset_fine, minimum=-1000, maximum=1000, num_steps=400, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_offset_fine_sizer, 6, 0, 1, 2) _offset_coarse_sizer = wx.BoxSizer(wx.VERTICAL) self._offset_coarse_text_box = forms.text_box( parent=self.GetWin(), sizer=_offset_coarse_sizer, value=self.offset_coarse, callback=self.set_offset_coarse, label="Coarse tune", converter=forms.float_converter(), proportion=0, ) self._offset_coarse_slider = forms.slider( parent=self.GetWin(), sizer=_offset_coarse_sizer, value=self.offset_coarse, callback=self.set_offset_coarse, minimum=-250000, maximum=250000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_offset_coarse_sizer, 6, 2, 1, 2) self._lo_freq_static_text = forms.static_text( parent=self.GetWin(), value=self.lo_freq, callback=self.set_lo_freq, label="LO", converter=forms.float_converter(), ) self.GridAdd(self._lo_freq_static_text, 5, 2, 1, 1) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(1, (xlate_filter_taps), 0, samp_rate) self._freq_text_box = forms.text_box( parent=self.GetWin(), value=self.freq, callback=self.set_freq, label="USRP", converter=forms.float_converter(), ) self.GridAdd(self._freq_text_box, 5, 1, 1, 1) self.fftsink = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=rx_freq * display_selector, y_per_div=10, y_divs=10, ref_level=0, ref_scale=13490.0, sample_rate=samp_rate, fft_size=512, fft_rate=15, average=True, avg_alpha=0.5, title="", peak_hold=False, size=(800, 300), ) self.GridAdd(self.fftsink.win, 0, 0, 5, 4) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((af_gain,)) self.band_pass_filter_0 = filter.fir_filter_ccf( 1, firdes.band_pass(1, samp_rate, width / 4, width / 2, trans, firdes.WIN_HAMMING, 6.76) ) self.audio_sink_0 = audio.sink(44100, "", True) self.analog_am_demod_cf_0 = analog.am_demod_cf( channel_rate=44100, audio_decim=1, audio_pass=5000, audio_stop=10000 ) self.analog_agc_xx_0 = analog.agc_cc(1e-4, 1.0, 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.analog_am_demod_cf_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.analog_am_demod_cf_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.fftsink, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.analog_agc_xx_0, 0))
def __init__(self): gr.top_block.__init__(self, "Lab 2") Qt.QWidget.__init__(self) self.setWindowTitle("Lab 2") 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", "lab2") 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.sps = sps = 8 self.roll_off = roll_off = 0.5 self.freqc = freqc = 900 self.std_dev = std_dev = 0.05 self.samp_rate = samp_rate = 1024 self.rrc_filter = rrc_filter = firdes.root_raised_cosine(4, sps, 1, roll_off, 32*sps+1) self.phase = phase = 0 self.lw = lw = 2 self.gain_ = gain_ = 0.5 self.freqc_ = freqc_ = freqc self.fps = fps = 30 self.const = const = digital.constellation_calcdist(digital.psk_2()[0], digital.psk_2()[1], 2, 1).base() self.bw = bw = 1 self.buff_size = buff_size = 32768 self.bNoise = bNoise = 0 self.bFilter = bFilter = 0 self.axis = axis = 2 self.N = N = 0 ################################################## # Blocks ################################################## self.tab0 = Qt.QTabWidget() self.tab0_widget_0 = Qt.QWidget() self.tab0_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab0_widget_0) self.tab0_grid_layout_0 = Qt.QGridLayout() self.tab0_layout_0.addLayout(self.tab0_grid_layout_0) self.tab0.addTab(self.tab0_widget_0, 'Spectrum/Constellation') self.tab0_widget_1 = Qt.QWidget() self.tab0_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab0_widget_1) self.tab0_grid_layout_1 = Qt.QGridLayout() self.tab0_layout_1.addLayout(self.tab0_grid_layout_1) self.tab0.addTab(self.tab0_widget_1, 'Eye Diagram') self.top_grid_layout.addWidget(self.tab0, 0, 0, 10, 2) for r in range(0, 10): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 2): self.top_grid_layout.setColumnStretch(c, 1) self._std_dev_range = Range(0, 1, 0.01, 0.05, 200) self._std_dev_win = RangeWidget(self._std_dev_range, self.set_std_dev, 'Noise Std. Dev', "counter_slider", float) self.top_grid_layout.addWidget(self._std_dev_win, 11, 0, 1, 1) for r in range(11, 12): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self._phase_range = Range(-180*2, 180*2, 0.1, 0, 200) self._phase_win = RangeWidget(self._phase_range, self.set_phase, 'Phase Offset (Degrees)', "counter_slider", float) self.top_grid_layout.addWidget(self._phase_win, 11, 1, 1, 1) for r in range(11, 12): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self._gain__range = Range(0.1, 1, 0.01, 0.5, 200) self._gain__win = RangeWidget(self._gain__range, self.set_gain_, 'Gain (Amp)', "counter_slider", float) self.top_grid_layout.addWidget(self._gain__win, 10, 1, 1, 1) for r in range(10, 11): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self._freqc__range = Range(70, 6000, .01, freqc, 200) self._freqc__win = RangeWidget(self._freqc__range, self.set_freqc_, 'Carrier (MHz)', "counter_slider", float) self.top_grid_layout.addWidget(self._freqc__win, 10, 0, 1, 1) for r in range(10, 11): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) # Create the options list self._bNoise_options = (0, 1, ) # Create the labels list self._bNoise_labels = ('Noise Only', 'Signal + Noise', ) # Create the combo box # Create the radio buttons self._bNoise_group_box = Qt.QGroupBox('Waveform Select' + ": ") self._bNoise_box = Qt.QHBoxLayout() class variable_chooser_button_group(Qt.QButtonGroup): def __init__(self, parent=None): Qt.QButtonGroup.__init__(self, parent) @pyqtSlot(int) def updateButtonChecked(self, button_id): self.button(button_id).setChecked(True) self._bNoise_button_group = variable_chooser_button_group() self._bNoise_group_box.setLayout(self._bNoise_box) for i, _label in enumerate(self._bNoise_labels): radio_button = Qt.QRadioButton(_label) self._bNoise_box.addWidget(radio_button) self._bNoise_button_group.addButton(radio_button, i) self._bNoise_callback = lambda i: Qt.QMetaObject.invokeMethod(self._bNoise_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._bNoise_options.index(i))) self._bNoise_callback(self.bNoise) self._bNoise_button_group.buttonClicked[int].connect( lambda i: self.set_bNoise(self._bNoise_options[i])) self.top_grid_layout.addWidget(self._bNoise_group_box, 12, 1, 1, 1) for r in range(12, 13): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) # Create the options list self._bFilter_options = (0, 1, ) # Create the labels list self._bFilter_labels = ('Rectangular', 'Raised Cosine', ) # Create the combo box # Create the radio buttons self._bFilter_group_box = Qt.QGroupBox('Pulse Shaping Select' + ": ") self._bFilter_box = Qt.QHBoxLayout() class variable_chooser_button_group(Qt.QButtonGroup): def __init__(self, parent=None): Qt.QButtonGroup.__init__(self, parent) @pyqtSlot(int) def updateButtonChecked(self, button_id): self.button(button_id).setChecked(True) self._bFilter_button_group = variable_chooser_button_group() self._bFilter_group_box.setLayout(self._bFilter_box) for i, _label in enumerate(self._bFilter_labels): radio_button = Qt.QRadioButton(_label) self._bFilter_box.addWidget(radio_button) self._bFilter_button_group.addButton(radio_button, i) self._bFilter_callback = lambda i: Qt.QMetaObject.invokeMethod(self._bFilter_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._bFilter_options.index(i))) self._bFilter_callback(self.bFilter) self._bFilter_button_group.buttonClicked[int].connect( lambda i: self.set_bFilter(self._bFilter_options[i])) self.top_grid_layout.addWidget(self._bFilter_group_box, 12, 0, 1, 1) for r in range(12, 13): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self._N_range = Range(0, 7, 1, 0, 200) self._N_win = RangeWidget(self._N_range, self.set_N, 'Nth Sample', "counter_slider", float) self.top_grid_layout.addWidget(self._N_win, 13, 1, 1, 1) for r in range(13, 14): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self._roll_off_range = Range(0.01, 0.99, 0.01, 0.5, 200) self._roll_off_win = RangeWidget(self._roll_off_range, self.set_roll_off, 'Beta (Roll-Off-Factor)', "counter_slider", float) self.top_grid_layout.addWidget(self._roll_off_win, 13, 0, 1, 1) for r in range(13, 14): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 2*sps, #size 1, #samp_rate "", #name 10 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(1/fps) self.qtgui_time_sink_x_0.set_y_axis(-2, 2) self.qtgui_time_sink_x_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0.enable_tags(True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "buffer_start") 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(True) self.qtgui_time_sink_x_0.enable_stem_plot(False) labels = ['Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5', 'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10'] widths = [lw, lw, lw, lw, lw, lw, lw, lw, lw, lw] colors = ['blue', 'red', 'yellow', '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] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] for i in range(10): 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.tab0_grid_layout_1.addWidget(self._qtgui_time_sink_x_0_win, 0, 0, 5, 1) for r in range(0, 5): self.tab0_grid_layout_1.setRowStretch(r, 1) for c in range(0, 1): self.tab0_grid_layout_1.setColumnStretch(c, 1) self.qtgui_histogram_sink_x_0 = qtgui.histogram_sink_f( int(1e5), 400, -axis, axis, "", 1 ) self.qtgui_histogram_sink_x_0.set_update_time(1/fps) self.qtgui_histogram_sink_x_0.enable_autoscale(True) self.qtgui_histogram_sink_x_0.enable_accumulate(False) self.qtgui_histogram_sink_x_0.enable_grid(True) self.qtgui_histogram_sink_x_0.enable_axis_labels(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"] 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 range(1): if len(labels[i]) == 0: self.qtgui_histogram_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_histogram_sink_x_0.set_line_label(i, labels[i]) self.qtgui_histogram_sink_x_0.set_line_width(i, widths[i]) self.qtgui_histogram_sink_x_0.set_line_color(i, colors[i]) self.qtgui_histogram_sink_x_0.set_line_style(i, styles[i]) self.qtgui_histogram_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_histogram_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_histogram_sink_x_0_win = sip.wrapinstance(self.qtgui_histogram_sink_x_0.pyqwidget(), Qt.QWidget) self.tab0_grid_layout_0.addWidget(self._qtgui_histogram_sink_x_0_win, 5, 1, 5, 1) for r in range(5, 10): self.tab0_grid_layout_0.setRowStretch(r, 1) for c in range(1, 2): self.tab0_grid_layout_0.setColumnStretch(c, 1) self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate*1e3, #bw "", #name 1 ) self.qtgui_freq_sink_x_0_0.set_update_time(1/fps) self.qtgui_freq_sink_x_0_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0_0.set_y_label('Relative Gain', 'dB') 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(0.05) self.qtgui_freq_sink_x_0_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0_0.enable_control_panel(False) labels = ['Magnitude', '', '', '', '', '', '', '', '', ''] 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 range(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.tab0_grid_layout_0.addWidget(self._qtgui_freq_sink_x_0_0_win, 0, 0, 5, 1) for r in range(0, 5): self.tab0_grid_layout_0.setRowStretch(r, 1) for c in range(0, 1): self.tab0_grid_layout_0.setColumnStretch(c, 1) self.qtgui_freq_sink_x_0_0.set_processor_affinity([0]) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_f( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate*1e3, #bw "", #name 2 ) self.qtgui_freq_sink_x_0.set_update_time(1/fps) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') 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.05) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ['In-Phase', 'Quadrature', '', '', '', '', '', '', '', ''] 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 range(2): 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.tab0_grid_layout_0.addWidget(self._qtgui_freq_sink_x_0_win, 5, 0, 5, 1) for r in range(5, 10): self.tab0_grid_layout_0.setRowStretch(r, 1) for c in range(0, 1): self.tab0_grid_layout_0.setColumnStretch(c, 1) self.qtgui_freq_sink_x_0.set_processor_affinity([0]) self.qtgui_const_sink_x_0 = qtgui.const_sink_c( 1024, #size "", #name 2 #number of inputs ) self.qtgui_const_sink_x_0.set_update_time(1/fps) self.qtgui_const_sink_x_0.set_y_axis(-axis, axis) self.qtgui_const_sink_x_0.set_x_axis(-axis, axis) 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(True) self.qtgui_const_sink_x_0.enable_axis_labels(True) 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, 1, 0, 0, 0, 0, 0, 0, 0, 0] markers = [0, -1, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in range(2): 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.tab0_grid_layout_0.addWidget(self._qtgui_const_sink_x_0_win, 0, 1, 5, 1) for r in range(0, 5): self.tab0_grid_layout_0.setRowStretch(r, 1) for c in range(1, 2): self.tab0_grid_layout_0.setColumnStretch(c, 1) self.qtgui_const_sink_x_0.set_processor_affinity([0]) self.interp_fir_filter_xxx_1_0 = filter.interp_fir_filter_ccc(sps, (1,1,1,1,1,1,1,1)) self.interp_fir_filter_xxx_1_0.declare_sample_delay(0) self.interp_fir_filter_xxx_1 = filter.interp_fir_filter_ccc(sps, rrc_filter) self.interp_fir_filter_xxx_1.declare_sample_delay(0) self.interp_fir_filter_xxx_0 = filter.interp_fir_filter_ccc(1, rrc_filter) self.interp_fir_filter_xxx_0.declare_sample_delay(0) self.iio_pluto_source_0 = iio.pluto_source('', int(freqc_*1e6), int(samp_rate*1000), 20000000, buff_size, True, True, True, 'manual', 32, '', True) self.iio_pluto_sink_0 = iio.pluto_sink('', int(freqc_*1e6), int(samp_rate*1000), 20000000, buff_size, False, 10.0, '', True) self.digital_chunks_to_symbols_xx_1 = digital.chunks_to_symbols_bc(const.points(), 1) self.blocks_tag_gate_0 = blocks.tag_gate(gr.sizeof_gr_complex * 1, False) self.blocks_tag_gate_0.set_single_key("") self.blocks_selector_0_0 = blocks.selector(gr.sizeof_gr_complex*1,bFilter,0) self.blocks_selector_0_0.set_enabled(True) self.blocks_selector_0 = blocks.selector(gr.sizeof_gr_complex*1,N,0) self.blocks_selector_0.set_enabled(True) self.blocks_multiply_const_vxx_1 = blocks.multiply_const_cc(np.exp(1j*2*pi*phase/360)) self.blocks_multiply_const_vxx_0_0_0 = blocks.multiply_const_cc(2) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_cc(bNoise) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_cc(gain_ ) self.blocks_delay_0_2 = blocks.delay(gr.sizeof_float*1, -N+1024) self.blocks_delay_0_1 = blocks.delay(gr.sizeof_float*1, sps) self.blocks_delay_0_0_1 = blocks.delay(gr.sizeof_float*1, sps) self.blocks_delay_0_0_0_1_0 = blocks.delay(gr.sizeof_float*1, sps) self.blocks_delay_0_0_0_1 = blocks.delay(gr.sizeof_float*1, sps) self.blocks_delay_0_0_0_0_0 = blocks.delay(gr.sizeof_float*1, sps) self.blocks_delay_0_0_0_0 = blocks.delay(gr.sizeof_float*1, sps) self.blocks_delay_0_0_0 = blocks.delay(gr.sizeof_float*1, sps) self.blocks_delay_0_0 = blocks.delay(gr.sizeof_float*1, sps) self.blocks_delay_0 = blocks.delay(gr.sizeof_float*1, sps) self.blocks_deinterleave_0 = blocks.deinterleave(gr.sizeof_gr_complex*1, 1) self.blocks_complex_to_real_0_0 = blocks.complex_to_real(1) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) self.blocks_complex_to_imag_0 = blocks.complex_to_imag(1) self.blocks_add_xx_0 = blocks.add_vcc(1) self.analog_random_source_x_0 = blocks.vector_source_b(list(map(int, numpy.random.randint(0, 2, 8192))), True) self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, std_dev, 0) self.analog_agc_xx_0 = analog.agc_cc(1e-4, 1.0, 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0, 0), (self.blocks_deinterleave_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.blocks_tag_gate_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.qtgui_freq_sink_x_0_0, 0)) self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.analog_random_source_x_0, 0), (self.digital_chunks_to_symbols_xx_1, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_complex_to_imag_0, 0), (self.qtgui_freq_sink_x_0, 1)) self.connect((self.blocks_complex_to_real_0, 0), (self.blocks_delay_0_2, 0)) self.connect((self.blocks_complex_to_real_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.blocks_complex_to_real_0_0, 0), (self.qtgui_histogram_sink_x_0, 0)) self.connect((self.blocks_deinterleave_0, 7), (self.blocks_selector_0, 7)) self.connect((self.blocks_deinterleave_0, 4), (self.blocks_selector_0, 4)) self.connect((self.blocks_deinterleave_0, 3), (self.blocks_selector_0, 3)) self.connect((self.blocks_deinterleave_0, 6), (self.blocks_selector_0, 6)) self.connect((self.blocks_deinterleave_0, 5), (self.blocks_selector_0, 5)) self.connect((self.blocks_deinterleave_0, 0), (self.blocks_selector_0, 0)) self.connect((self.blocks_deinterleave_0, 1), (self.blocks_selector_0, 1)) self.connect((self.blocks_deinterleave_0, 2), (self.blocks_selector_0, 2)) self.connect((self.blocks_delay_0, 0), (self.blocks_delay_0_0, 0)) self.connect((self.blocks_delay_0, 0), (self.qtgui_time_sink_x_0, 1)) self.connect((self.blocks_delay_0_0, 0), (self.blocks_delay_0_0_0, 0)) self.connect((self.blocks_delay_0_0, 0), (self.qtgui_time_sink_x_0, 2)) self.connect((self.blocks_delay_0_0_0, 0), (self.blocks_delay_0_0_0_0, 0)) self.connect((self.blocks_delay_0_0_0, 0), (self.qtgui_time_sink_x_0, 3)) self.connect((self.blocks_delay_0_0_0_0, 0), (self.blocks_delay_0_1, 0)) self.connect((self.blocks_delay_0_0_0_0, 0), (self.qtgui_time_sink_x_0, 4)) self.connect((self.blocks_delay_0_0_0_0_0, 0), (self.blocks_delay_0_0_0_1_0, 0)) self.connect((self.blocks_delay_0_0_0_0_0, 0), (self.qtgui_time_sink_x_0, 8)) self.connect((self.blocks_delay_0_0_0_1, 0), (self.blocks_delay_0_0_0_0_0, 0)) self.connect((self.blocks_delay_0_0_0_1, 0), (self.qtgui_time_sink_x_0, 7)) self.connect((self.blocks_delay_0_0_0_1_0, 0), (self.qtgui_time_sink_x_0, 9)) self.connect((self.blocks_delay_0_0_1, 0), (self.blocks_delay_0_0_0_1, 0)) self.connect((self.blocks_delay_0_0_1, 0), (self.qtgui_time_sink_x_0, 6)) self.connect((self.blocks_delay_0_1, 0), (self.blocks_delay_0_0_1, 0)) self.connect((self.blocks_delay_0_1, 0), (self.qtgui_time_sink_x_0, 5)) self.connect((self.blocks_delay_0_2, 0), (self.blocks_delay_0, 0)) self.connect((self.blocks_delay_0_2, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.iio_pluto_sink_0, 0)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0_0_0, 0), (self.blocks_selector_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.analog_agc_xx_0, 0)) self.connect((self.blocks_selector_0, 0), (self.blocks_complex_to_real_0_0, 0)) self.connect((self.blocks_selector_0, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.blocks_selector_0, 0), (self.qtgui_const_sink_x_0, 1)) self.connect((self.blocks_selector_0_0, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.blocks_tag_gate_0, 0), (self.blocks_complex_to_imag_0, 0)) self.connect((self.blocks_tag_gate_0, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_1, 0), (self.interp_fir_filter_xxx_1, 0)) self.connect((self.digital_chunks_to_symbols_xx_1, 0), (self.interp_fir_filter_xxx_1_0, 0)) self.connect((self.iio_pluto_source_0, 0), (self.blocks_multiply_const_vxx_1, 0)) self.connect((self.interp_fir_filter_xxx_0, 0), (self.blocks_selector_0_0, 1)) self.connect((self.interp_fir_filter_xxx_1, 0), (self.interp_fir_filter_xxx_0, 0)) self.connect((self.interp_fir_filter_xxx_1_0, 0), (self.blocks_multiply_const_vxx_0_0_0, 0))
def __init__(self, rxPort=52002, txPort=52001): grc_wxgui.top_block_gui.__init__(self, title="Top Block") ################################################## # Parameters ################################################## self.rxPort = rxPort self.txPort = txPort ################################################## # Variables ################################################## self.localOscillator = localOscillator = 14070000 self.threshold = threshold = -200 self.samp_rate = samp_rate = 48000 self.rxPhase = rxPhase = .84 self.rxMagnitude = rxMagnitude = 0.854 self.freqFine = freqFine = 0 self.freq = freq = localOscillator self.bandwidth = bandwidth = 50 ################################################## # Blocks ################################################## _threshold_sizer = wx.BoxSizer(wx.VERTICAL) self._threshold_text_box = forms.text_box( parent=self.GetWin(), sizer=_threshold_sizer, value=self.threshold, callback=self.set_threshold, label="threshold", converter=forms.float_converter(), proportion=0, ) self._threshold_slider = forms.slider( parent=self.GetWin(), sizer=_threshold_sizer, value=self.threshold, callback=self.set_threshold, minimum=-500, maximum=500, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_threshold_sizer) self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "tuning") self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "scope") self.Add(self.notebook_0) _freqFine_sizer = wx.BoxSizer(wx.VERTICAL) self._freqFine_text_box = forms.text_box( parent=self.GetWin(), sizer=_freqFine_sizer, value=self.freqFine, callback=self.set_freqFine, label="Tuning", converter=forms.float_converter(), proportion=0, ) self._freqFine_slider = forms.slider( parent=self.GetWin(), sizer=_freqFine_sizer, value=self.freqFine, callback=self.set_freqFine, minimum=-500, maximum=500, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_freqFine_sizer) _freq_sizer = wx.BoxSizer(wx.VERTICAL) self._freq_text_box = forms.text_box( parent=self.GetWin(), sizer=_freq_sizer, value=self.freq, callback=self.set_freq, label="Frequency", converter=forms.float_converter(), proportion=0, ) self._freq_slider = forms.slider( parent=self.GetWin(), sizer=_freq_sizer, value=self.freq, callback=self.set_freq, minimum=localOscillator-samp_rate, maximum=localOscillator+samp_rate, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_freq_sizer) _bandwidth_sizer = wx.BoxSizer(wx.VERTICAL) self._bandwidth_text_box = forms.text_box( parent=self.GetWin(), sizer=_bandwidth_sizer, value=self.bandwidth, callback=self.set_bandwidth, label="Signal Bandwidth", converter=forms.float_converter(), proportion=0, ) self._bandwidth_slider = forms.slider( parent=self.GetWin(), sizer=_bandwidth_sizer, value=self.bandwidth, callback=self.set_bandwidth, minimum=30, maximum=5000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_bandwidth_sizer) self.wxgui_waterfallsink2_0_0_0 = waterfallsink2.waterfall_sink_c( self.notebook_0.GetPage(1).GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=125*8, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", ) self.notebook_0.GetPage(1).Add(self.wxgui_waterfallsink2_0_0_0.win) self.wxgui_waterfallsink2_0_0 = waterfallsink2.waterfall_sink_c( self.notebook_0.GetPage(0).GetWin(), baseband_freq=0, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=125*8, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", ) self.notebook_0.GetPage(0).Add(self.wxgui_waterfallsink2_0_0.win) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.notebook_0.GetPage(0).GetWin(), baseband_freq=localOscillator, dynamic_range=100, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", ) self.notebook_0.GetPage(0).Add(self.wxgui_waterfallsink2_0.win) self.low_pass_filter_0_1 = filter.fir_filter_ccf(samp_rate/125/8, firdes.low_pass( 1, samp_rate, 500, 500, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0_0 = filter.interp_fir_filter_ccf(1, firdes.low_pass( 1, samp_rate, 30, 30, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0 = filter.fir_filter_ccf(samp_rate/125/8, firdes.low_pass( 1, samp_rate, bandwidth, bandwidth, firdes.WIN_HAMMING, 6.76)) self.digital_mpsk_receiver_cc_0 = digital.mpsk_receiver_cc(2, 0, cmath.pi/100.0, -0.5, 0.5, 0.25, 0.01, 125*8/31.25, 0.001, 0.001) self.blocks_transcendental_1 = blocks.transcendental("sin", "float") self.blocks_transcendental_0 = blocks.transcendental("cos", "float") self.blocks_throttle_0_1 = blocks.throttle(gr.sizeof_float*1, samp_rate) self.blocks_throttle_0_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char*1, 31.25) self.blocks_threshold_ff_0 = blocks.threshold_ff(1e-12, 1e-12, 0) self.blocks_repeat_0 = blocks.repeat(gr.sizeof_float*1, int(samp_rate/31.25)) self.blocks_null_source_1 = blocks.null_source(gr.sizeof_float*1) self.blocks_null_source_0_0 = blocks.null_source(gr.sizeof_float*1) self.blocks_null_source_0 = blocks.null_source(gr.sizeof_float*1) self.blocks_multiply_xx_0_2 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_1 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_2 = blocks.multiply_const_vff((rxMagnitude, )) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((2, )) self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1) self.blocks_float_to_complex_1_0 = blocks.float_to_complex(1) self.blocks_float_to_complex_1 = blocks.float_to_complex(1) self.blocks_float_to_complex_0_1 = blocks.float_to_complex(1) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_float_to_char_0 = blocks.float_to_char(1, 1) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex*1, 1) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.blocks_char_to_float_0 = blocks.char_to_float(1, 1) self.blocks_add_xx_0 = blocks.add_vcc(1) self.blocks_add_const_vxx_0 = blocks.add_const_vff((-1, )) self.blks2_tcp_source_0 = grc_blks2.tcp_source( itemsize=gr.sizeof_char*1, addr="127.0.0.1", port=txPort, server=False, ) self.blks2_tcp_sink_0 = grc_blks2.tcp_sink( itemsize=gr.sizeof_char*1, addr="127.0.0.1", port=rxPort, server=False, ) self.audio_source_0 = audio.source(samp_rate, "", True) self.audio_sink_0 = audio.sink(samp_rate, "", True) self.analog_simple_squelch_cc_0 = analog.simple_squelch_cc(threshold, 1) self.analog_sig_source_x_1 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, -freqFine, 1, 0) self.analog_sig_source_x_0_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, freq+freqFine-localOscillator, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_SIN_WAVE, -(freq-localOscillator), 1, 0) self.analog_const_source_x_0 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, rxPhase*3.14159/180.0) self.analog_agc_xx_0 = analog.agc_cc(1e-4, 1.0, 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.blks2_tcp_source_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.blocks_char_to_float_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.low_pass_filter_0_0, 0)) self.connect((self.blocks_throttle_0_1, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.low_pass_filter_0_0, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.blocks_float_to_complex_0_1, 0), (self.blocks_multiply_xx_0_1, 1)) self.connect((self.analog_const_source_x_0, 0), (self.blocks_transcendental_1, 0)) self.connect((self.analog_const_source_x_0, 0), (self.blocks_transcendental_0, 0)) self.connect((self.blocks_transcendental_0, 0), (self.blocks_float_to_complex_0_1, 0)) self.connect((self.blocks_transcendental_1, 0), (self.blocks_float_to_complex_0_1, 1)) self.connect((self.blocks_null_source_0, 0), (self.blocks_float_to_complex_1, 0)) self.connect((self.audio_source_0, 0), (self.blocks_multiply_const_vxx_2, 0)) self.connect((self.blocks_multiply_const_vxx_2, 0), (self.blocks_float_to_complex_1, 1)) self.connect((self.blocks_float_to_complex_1, 0), (self.blocks_multiply_xx_0_1, 0)) self.connect((self.blocks_null_source_0_0, 0), (self.blocks_float_to_complex_1_0, 1)) self.connect((self.audio_source_0, 1), (self.blocks_float_to_complex_1_0, 0)) self.connect((self.blocks_float_to_complex_1_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_multiply_xx_0_1, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_throttle_0_0, 0)) self.connect((self.blocks_null_source_1, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_throttle_0_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_float_to_char_0, 0), (self.blks2_tcp_sink_0, 0)) self.connect((self.blocks_complex_to_real_0, 0), (self.blocks_threshold_ff_0, 0)) self.connect((self.blocks_threshold_ff_0, 0), (self.blocks_float_to_char_0, 0)) self.connect((self.analog_simple_squelch_cc_0, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.analog_simple_squelch_cc_0, 0)) self.connect((self.digital_mpsk_receiver_cc_0, 0), (self.blocks_multiply_conjugate_cc_0, 1)) self.connect((self.digital_mpsk_receiver_cc_0, 0), (self.blocks_delay_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_conjugate_cc_0, 0)) self.connect((self.blocks_repeat_0, 0), (self.blocks_throttle_0_1, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_repeat_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_multiply_xx_0_2, 0)) self.connect((self.analog_sig_source_x_1, 0), (self.blocks_multiply_xx_0_2, 1)) self.connect((self.blocks_multiply_xx_0_2, 0), (self.low_pass_filter_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_0_1, 0)) self.connect((self.low_pass_filter_0_1, 0), (self.wxgui_waterfallsink2_0_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.digital_mpsk_receiver_cc_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.wxgui_waterfallsink2_0_0_0, 0)) self.connect((self.blocks_complex_to_float_0, 0), (self.audio_sink_0, 1)) self.connect((self.blocks_complex_to_float_0, 1), (self.audio_sink_0, 0)) self.connect((self.blocks_throttle_0_0, 0), (self.wxgui_waterfallsink2_0, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Meteor QPSK LRPT") _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_airspy = samp_rate_airspy = 192000 self.decim = decim = 1 self.symb_rate = symb_rate = 72000 self.samp_rate = samp_rate = samp_rate_airspy/decim self.sps = sps = (samp_rate*1.0)/(symb_rate*1.0) self.rfgain = rfgain = 9 self.pll_alpha = pll_alpha = 0.015 self.ifgain = ifgain = 10 self.freq = freq = 137900000 self.clock_alpha = clock_alpha = 0.001 self.bitstream_name = bitstream_name = "/tmp/meteor_LRPT_" + datetime.now().strftime("%d%m%Y_%H%M") + ".s" ################################################## # Blocks ################################################## self.nb_0 = self.nb_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.nb_0.AddPage(grc_wxgui.Panel(self.nb_0), "SDR FFT") self.nb_0.AddPage(grc_wxgui.Panel(self.nb_0), "QPSK Constellation") self.Add(self.nb_0) _pll_alpha_sizer = wx.BoxSizer(wx.VERTICAL) self._pll_alpha_text_box = forms.text_box( parent=self.nb_0.GetPage(1).GetWin(), sizer=_pll_alpha_sizer, value=self.pll_alpha, callback=self.set_pll_alpha, label="PLL Alpha", converter=forms.float_converter(), proportion=0, ) self._pll_alpha_slider = forms.slider( parent=self.nb_0.GetPage(1).GetWin(), sizer=_pll_alpha_sizer, value=self.pll_alpha, callback=self.set_pll_alpha, minimum=0.001, maximum=0.1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.nb_0.GetPage(1).Add(_pll_alpha_sizer) _clock_alpha_sizer = wx.BoxSizer(wx.VERTICAL) self._clock_alpha_text_box = forms.text_box( parent=self.nb_0.GetPage(1).GetWin(), sizer=_clock_alpha_sizer, value=self.clock_alpha, callback=self.set_clock_alpha, label="Clock Alpha", converter=forms.float_converter(), proportion=0, ) self._clock_alpha_slider = forms.slider( parent=self.nb_0.GetPage(1).GetWin(), sizer=_clock_alpha_sizer, value=self.clock_alpha, callback=self.set_clock_alpha, minimum=0.001, maximum=0.01, num_steps=10, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.nb_0.GetPage(1).Add(_clock_alpha_sizer) self.wxgui_scopesink2_0 = scopesink2.scope_sink_c( self.nb_0.GetPage(1).GetWin(), title="Scope Plot", sample_rate=symb_rate, v_scale=0.5, v_offset=0, t_scale=0.5, ac_couple=False, xy_mode=True, num_inputs=1, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label="Counts", ) self.nb_0.GetPage(1).Add(self.wxgui_scopesink2_0.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.nb_0.GetPage(0).GetWin(), baseband_freq=freq, y_per_div=5, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=768, fft_rate=25, average=True, avg_alpha=0.1, title="Filtered Spectrum", peak_hold=False, ) self.nb_0.GetPage(0).Add(self.wxgui_fftsink2_0.win) self.root_raised_cosine_filter_0 = filter.fir_filter_ccf(1, firdes.root_raised_cosine( 1, samp_rate, symb_rate, 0.6, 361)) _rfgain_sizer = wx.BoxSizer(wx.VERTICAL) self._rfgain_text_box = forms.text_box( parent=self.GetWin(), sizer=_rfgain_sizer, value=self.rfgain, callback=self.set_rfgain, label="RF Gain", converter=forms.float_converter(), proportion=0, ) self._rfgain_slider = forms.slider( parent=self.GetWin(), sizer=_rfgain_sizer, value=self.rfgain, callback=self.set_rfgain, minimum=1, maximum=15, num_steps=14, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_rfgain_sizer) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=1, decimation=decim, taps=None, fractional_bw=None, ) _ifgain_sizer = wx.BoxSizer(wx.VERTICAL) self._ifgain_text_box = forms.text_box( parent=self.GetWin(), sizer=_ifgain_sizer, value=self.ifgain, callback=self.set_ifgain, label="IF Gain", converter=forms.float_converter(), proportion=0, ) self._ifgain_slider = forms.slider( parent=self.GetWin(), sizer=_ifgain_sizer, value=self.ifgain, callback=self.set_ifgain, minimum=1, maximum=15, num_steps=14, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_ifgain_sizer) self.fcdproplus_fcdproplus_0 = fcdproplus.fcdproplus("0",1) self.fcdproplus_fcdproplus_0.set_lna(1) self.fcdproplus_fcdproplus_0.set_mixer_gain(0) self.fcdproplus_fcdproplus_0.set_if_gain(30) self.fcdproplus_fcdproplus_0.set_freq_corr(0) self.fcdproplus_fcdproplus_0.set_freq(137900000) self.digital_costas_loop_cc_0 = digital.costas_loop_cc(pll_alpha, 4) self.digital_constellation_soft_decoder_cf_1 = digital.constellation_soft_decoder_cf(digital.constellation_calcdist(([-1-1j, -1+1j, 1+1j, 1-1j]), ([0, 1, 3, 2]), 4, 1).base()) self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_cc(sps, clock_alpha**2/4.0, 0.5, clock_alpha, 0.005) self.blocks_float_to_char_0 = blocks.float_to_char(1, 127) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, bitstream_name, False) self.blocks_file_sink_0.set_unbuffered(False) self.analog_rail_ff_0 = analog.rail_ff(-1, 1) self.analog_agc_xx_0 = analog.agc_cc(1000e-4, 0.5, 1.0) self.analog_agc_xx_0.set_max_gain(4000) ################################################## # Connections ################################################## self.connect((self.digital_costas_loop_cc_0, 0), (self.digital_clock_recovery_mm_xx_0, 0)) self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.digital_constellation_soft_decoder_cf_1, 0)) self.connect((self.digital_constellation_soft_decoder_cf_1, 0), (self.analog_rail_ff_0, 0)) self.connect((self.root_raised_cosine_filter_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.root_raised_cosine_filter_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.blocks_float_to_char_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.analog_rail_ff_0, 0), (self.blocks_float_to_char_0, 0)) self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.fcdproplus_fcdproplus_0, 0), (self.rational_resampler_xxx_0, 0))
def __init__(self): gr.top_block.__init__(self, "Meteor QPSK LRPT") ################################################## # Variables ################################################## self.freq = freq = 137900000 self.symb_rate = symb_rate = 72000 self.samp_rate = samp_rate = 128000 self.doppler_freq = doppler_freq = freq self.sps = sps = (samp_rate * 1.0) / (symb_rate * 1.0) self.samp_rate_rtlsdr = samp_rate_rtlsdr = 1536000 self.pll_alpha = pll_alpha = float(sys.argv[2]) self.doppler_shift = doppler_shift = doppler_freq - freq self.decim = decim = 8 self.clock_alpha = clock_alpha = .001 self.bitstream_name = bitstream_name = sys.argv[1] + '.s' ################################################## # Blocks ################################################## self.root_raised_cosine_filter_0 = filter.fir_filter_ccf( 1, firdes.root_raised_cosine(1, samp_rate, symb_rate, 0.6, 361)) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=1, decimation=int(samp_rate_rtlsdr / samp_rate), taps=None, fractional_bw=None, ) self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + '') self.osmosdr_source_0.set_sample_rate(samp_rate_rtlsdr) 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(2, 0) self.osmosdr_source_0.set_iq_balance_mode(0, 0) self.osmosdr_source_0.set_gain_mode(True, 0) self.osmosdr_source_0.set_gain(44, 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.gpredict_doppler_0 = gpredict.doppler(self.set_doppler_freq, "localhost", 4532, True) self.digital_costas_loop_cc_0 = digital.costas_loop_cc( pll_alpha, 4, False) self.digital_constellation_soft_decoder_cf_1 = digital.constellation_soft_decoder_cf( digital.constellation_calcdist( ([-1 - 1j, -1 + 1j, 1 + 1j, 1 - 1j]), ([0, 1, 3, 2]), 4, 1).base()) self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_cc( sps, clock_alpha**2 / 4.0, 0.5, clock_alpha, 0.005) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_float_to_char_0 = blocks.float_to_char(1, 127) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char * 1, bitstream_name, False) self.blocks_file_sink_0.set_unbuffered(False) self.analog_sig_source_x_1 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, doppler_shift, 1, 0) self.analog_rail_ff_0 = analog.rail_ff(-1, 1) self.analog_agc_xx_0 = analog.agc_cc(1000e-4, 0.5, 1.0) self.analog_agc_xx_0.set_max_gain(4000) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0, 0), (self.root_raised_cosine_filter_0, 0)) self.connect((self.analog_rail_ff_0, 0), (self.blocks_float_to_char_0, 0)) self.connect((self.analog_sig_source_x_1, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_float_to_char_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.digital_constellation_soft_decoder_cf_1, 0)) self.connect((self.digital_constellation_soft_decoder_cf_1, 0), (self.analog_rail_ff_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.digital_clock_recovery_mm_xx_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.root_raised_cosine_filter_0, 0), (self.digital_costas_loop_cc_0, 0))
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv) parser=OptionParser(option_class=eng_option) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate (bandwidth) [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=1008.0e3, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-I", "--use-if-freq", action="store_true", default=False, help="use intermediate freq (compensates DC problems in quadrature boards)" ) parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is maximum)") parser.add_option("-V", "--volume", type="eng_float", default=None, help="set volume (default is midpoint)") parser.add_option("-O", "--audio-output", type="string", default="default", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.frame = frame self.panel = panel self.use_IF=options.use_if_freq if self.use_IF: self.IF_freq=64000.0 else: self.IF_freq=0.0 self.vol = 0 self.state = "FREQ" self.freq = 0 # build graph self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if(options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if(options.antenna): self.u.set_antenna(options.antenna, 0) usrp_rate = 256e3 demod_rate = 64e3 audio_rate = 32e3 chanfilt_decim = int(usrp_rate // demod_rate) audio_decim = int(demod_rate // audio_rate) self.u.set_samp_rate(usrp_rate) dev_rate = self.u.get_samp_rate() # Resample signal to exactly self.usrp_rate # FIXME: make one of the follow-on filters an arb resampler rrate = usrp_rate / dev_rate self.resamp = filter.pfb.arb_resampler_ccf(rrate) chan_filt_coeffs = filter.firdes.low_pass_2(1, # gain usrp_rate, # sampling rate 8e3, # passband cutoff 4e3, # transition bw 60) # stopband attenuation if self.use_IF: # Turn If to baseband and filter. self.chan_filt = filter.freq_xlating_fir_filter_ccf(chanfilt_decim, chan_filt_coeffs, self.IF_freq, usrp_rate) else: self.chan_filt = filter.fir_filter_ccf(chanfilt_decim, chan_filt_coeffs) self.agc = analog.agc_cc(0.1, 1, 1, 100000) self.am_demod = blocks.complex_to_mag() self.volume_control = blocks.multiply_const_ff(self.vol) audio_filt_coeffs = filter.firdes.low_pass_2(1, # gain demod_rate, # sampling rate 8e3, # passband cutoff 2e3, # transition bw 60) # stopband attenuation self.audio_filt = filter.fir_filter_fff(audio_decim, audio_filt_coeffs) # sound card as final sink self.audio_sink = audio.sink(int (audio_rate), options.audio_output, False) # ok_to_block # now wire it all together self.connect (self.u, self.resamp, self.chan_filt, self.agc, self.am_demod, self.audio_filt, self.volume_control, self.audio_sink) self._build_gui(vbox, usrp_rate, demod_rate, audio_rate) if options.gain is None: g = self.u.get_gain_range() # if no gain was specified, use the mid gain options.gain = (g.start() + g.stop())/2.0 if options.volume is None: v = self.volume_range() options.volume = float(v[0]*3+v[1])/4.0 if abs(options.freq) < 1e3: options.freq *= 1e3 # set initial values self.set_gain(options.gain) self.set_vol(options.volume) if not(self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def agc(N): op = analog.agc_cc() tb = helper(N/10, op, gr.sizeof_gr_complex, gr.sizeof_gr_complex, 1, 1) return tb
def __init__(self): gr.top_block.__init__(self) usage=("%prog: [options] output_filename.\nSpecial output_filename" + \ "\"sdl\" will use video_sink_sdl as realtime output window. " + \ "You then need to have gr-video-sdl installed.\n" +\ "Make sure your input capture file containes interleaved " + \ "shorts not complex floats") parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate") parser.add_option("-c", "--contrast", type="eng_float", default=1.0, help="set contrast (default is 1.0)") parser.add_option("-b", "--brightness", type="eng_float", default=0.0, help="set brightness (default is 0)") parser.add_option("-i", "--in-filename", type="string", default=None, help="Use input file as source. samples must be " + \ "interleaved shorts \n Use usrp_rx_file.py or " + \ "usrp_rx_cfile.py --output-shorts.\n Special " + \ "name \"usrp\" results in realtime capturing " + \ "and processing using usrp.\n" + \ "You then probably need a decimation factor of 64 or higher.") parser.add_option("-f", "--freq", type="eng_float", default=519.25e6, help="set frequency to FREQ.\nNote that the frequency of the video carrier is not at the middle of the TV channel", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-p", "--pal", action="store_true", default=False, help="PAL video format (this is the default)") parser.add_option("-n", "--ntsc", action="store_true", default=False, help="NTSC video format") parser.add_option("-r", "--repeat", action="store_false", default=True, help="repeat in_file in a loop") parser.add_option("-N", "--nframes", type="eng_float", default=None, help="number of frames to collect [default=+inf]") parser.add_option("", "--freq-min", type="eng_float", default=50.25e6, help="Set a minimum frequency [default=%default]") parser.add_option("", "--freq-max", type="eng_float", default=900.25e6, help="Set a maximum frequency [default=%default]") (options, args) = parser.parse_args () if not (len(args) == 1): parser.print_help() sys.stderr.write('You must specify the output. FILENAME or sdl \n'); sys.exit(1) filename = args[0] self.tv_freq_min = options.freq_min self.tv_freq_max = options.freq_max if options.in_filename is None: parser.print_help() sys.stderr.write('You must specify the input -i FILENAME or -i usrp\n'); raise SystemExit, 1 if not (filename=="sdl"): options.repeat=False input_rate = options.samp_rate print "video sample rate %s" % (eng_notation.num_to_str(input_rate)) if not (options.in_filename=="usrp"): # file is data source, capture with usr_rx_csfile.py self.filesource = blocks.file_source(gr.sizeof_short, options.in_filename, options.repeat) self.istoc = blocks.interleaved_short_to_complex() self.connect(self.filesource,self.istoc) self.src=self.istoc else: if options.freq is None: parser.print_help() sys.stderr.write('You must specify the frequency with -f FREQ\n'); raise SystemExit, 1 # build the graph self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if(options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if(options.antenna): self.u.set_antenna(options.antenna, 0) self.u.set_samp_rate(input_rate) dev_rate = self.u.get_samp_rate() self.src=self.u if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start()+g.stop())/2.0 self.u.set_gain(options.gain) r = self.u.set_center_freq(options.freq) if not r: sys.stderr.write('Failed to set frequency\n') raise SystemExit, 1 self.agc = analog.agc_cc(1e-7,1.0,1.0) #1e-7 self.am_demod = blocks.complex_to_mag () self.set_blacklevel = blocks.add_const_ff(options.brightness +255.0) self.invert_and_scale = blocks.multiply_const_ff(-options.contrast *128.0*255.0/(200.0)) self.f2uc = blocks.float_to_uchar() # sdl window as final sink if not (options.pal or options.ntsc): options.pal=True #set default to PAL if options.pal: lines_per_frame=625.0 frames_per_sec=25.0 show_width=768 elif options.ntsc: lines_per_frame=525.0 frames_per_sec=29.97002997 show_width=640 width=int(input_rate/(lines_per_frame*frames_per_sec)) height=int(lines_per_frame) if filename=="sdl": #Here comes the tv screen, you have to build and install #gr-video-sdl for this (subproject of gnuradio) try: video_sink = video_sdl.sink_uc(frames_per_sec, width, height, 0, show_width,height) except: print "gr-video-sdl is not installed" print "realtime \"sdl\" video output window is not available" raise SystemExit, 1 self.dst=video_sink else: print "You can use the imagemagick display tool to show the resulting imagesequence" print "use the following line to show the demodulated TV-signal:" print "display -depth 8 -size " +str(width)+ "x" + str(height) + " gray:" +filename print "(Use the spacebar to advance to next frames)" file_sink = blocks.file_sink(gr.sizeof_char, filename) self.dst =file_sink if options.nframes is None: self.connect(self.src, self.agc) else: self.head = blocks.head(gr.sizeof_gr_complex, int(options.nframes*width*height)) self.connect(self.src, self.head, self.agc) self.connect (self.agc, self.am_demod, self.invert_and_scale, self.set_blacklevel, self.f2uc, self.dst)
def __init__(self): gr.top_block.__init__( self, "Downlink from TVAC (This should run all the time)") ################################################## # Variables ################################################## self.block_len_enc = block_len_enc = 1024 / 8 * 2 self.variable_constellation_0 = variable_constellation_0 = digital.constellation_calcdist( ([-1, 1]), ([0, 1]), 4, 1).base() self.samp_rate_factor = samp_rate_factor = 5 self.samp_rate = samp_rate = 250000 self.rgain = rgain = 0 self.payload = payload = block_len_enc + 4 self.freq_offset = freq_offset = 0 ################################################## # Blocks ################################################## self.rational_resampler_xxx_1 = filter.rational_resampler_ccc( interpolation=1, decimation=5, taps=None, fractional_bw=None, ) self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + 'rtl_tcp=10.0.0.51:1234') self.osmosdr_source_0.set_sample_rate(samp_rate * samp_rate_factor) self.osmosdr_source_0.set_center_freq(145.95, 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(rgain, 0) self.osmosdr_source_0.set_if_gain(0, 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.fir_filter_xxx_0 = filter.fir_filter_ccc(samp_rate_factor, (1, )) self.fir_filter_xxx_0.declare_sample_delay(0) self.digital_mpsk_receiver_cc_0_0 = digital.mpsk_receiver_cc( 2, 0, cmath.pi / 100.0, -0.05, 0.05, 0.25, 0.05, 4, 4, 0.005) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb( variable_constellation_0) self.ccsds_softbits_msg_to_bytes_b_0 = ccsds.softbits_msg_to_bytes_b() self.ccsds_randomiser_softbits_0 = ccsds.randomiser_softbits( 0x95, 0xFF) self.ccsds_mpsk_ambiguity_resolver_f_0 = ccsds.mpsk_ambiguity_resolver_f( 2, '49E0DCC7', 32, 1, 0.8, block_len_enc, 0) self.ccsds_message_info_0 = ccsds.message_info( "Block received and sent to Nanolink: ", 10) self.ccsds_ldpc_decoder_0 = ccsds.ldpc_decoder( '/tmp/AR4JA_r12_k1024n.a', ccsds.LDPC_SYS_FRONT, ccsds.LDPC_PUNCT_BACK, 512, tuple(([]))) self.ccsds_blob_msg_sink_b_0 = ccsds.blob_msg_sink_b(256 / 2) self.blocks_udp_sink_0_1 = blocks.udp_sink(gr.sizeof_char * 1, '127.0.0.1', 5431, 256, True) self.blocks_udp_sink_0_0 = blocks.udp_sink(gr.sizeof_char * 1, '127.0.0.1', 5433, 1472, True) self.blocks_udp_sink_0 = blocks.udp_sink(gr.sizeof_gr_complex * 1, '127.0.0.1', 5435, 1472, True) self.blocks_null_sink_1 = blocks.null_sink(gr.sizeof_char * 1) self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_char_to_float_0 = blocks.char_to_float(1, 0.5) self.blocks_add_const_vxx_0 = blocks.add_const_vff((-1, )) self.band_pass_filter_0 = filter.fir_filter_ccc( 1, firdes.complex_band_pass(1, samp_rate * samp_rate_factor, 40e3, 60e3, 6e3, firdes.WIN_HAMMING, 6.76)) self.analog_sig_source_x_0_0 = analog.sig_source_c( samp_rate * samp_rate_factor, analog.GR_COS_WAVE, -freq_offset, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, -50000, 1, 0) self.analog_agc_xx_0 = analog.agc_cc(1e-4, 0.5, 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.msg_connect((self.ccsds_blob_msg_sink_b_0, 'out'), (self.ccsds_message_info_0, 'in')) self.msg_connect((self.ccsds_ldpc_decoder_0, 'out'), (self.ccsds_softbits_msg_to_bytes_b_0, 'in')) self.msg_connect((self.ccsds_mpsk_ambiguity_resolver_f_0, 'out'), (self.ccsds_randomiser_softbits_0, 'in')) self.msg_connect((self.ccsds_randomiser_softbits_0, 'out'), (self.ccsds_ldpc_decoder_0, 'in')) self.connect((self.analog_agc_xx_0, 0), (self.rational_resampler_xxx_1, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.fir_filter_xxx_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.ccsds_mpsk_ambiguity_resolver_f_0, 0)) self.connect((self.blocks_char_to_float_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.ccsds_softbits_msg_to_bytes_b_0, 0), (self.blocks_null_sink_1, 0)) self.connect((self.ccsds_softbits_msg_to_bytes_b_0, 0), (self.blocks_udp_sink_0_1, 0)) self.connect((self.ccsds_softbits_msg_to_bytes_b_0, 0), (self.ccsds_blob_msg_sink_b_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blocks_udp_sink_0_0, 0)) self.connect((self.digital_mpsk_receiver_cc_0_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.fir_filter_xxx_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.osmosdr_source_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.osmosdr_source_0, 0), (self.blocks_udp_sink_0, 0)) self.connect((self.rational_resampler_xxx_1, 0), (self.digital_mpsk_receiver_cc_0_0, 0))
def __init__(self): gr.top_block.__init__(self, "Lab 4") Qt.QWidget.__init__(self) self.setWindowTitle("Lab 4") 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", "lab4") 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.echo_gain_iir = echo_gain_iir = 0 self.delay_limit = delay_limit = 64 self.delay_iir = delay_iir = 1 self.sps = sps = 4 self.pn6 = pn6 = [1, 1, 1, 1, 1, 1, -1, 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, -1, 1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, -1, 1, 1, -1, -1, -1, -1, 1, -1, -1, -1 -1 -1] self.pn5 = pn5 = [1,-1,1,-1,1, 1, 1, -1, 1, 1, -1, -1, -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, -1, -1, -1, -1] self.iir_taps_2 = iir_taps_2 = np.concatenate( ([1], np.zeros(int(delay_iir-1)),[-echo_gain_iir],np.zeros(int(delay_limit-delay_iir))) ) self.h_filt = h_filt = [1,1,1,1] self.freqc = freqc = 900 self.samp_rate = samp_rate = 1000 self.pn6_up = pn6_up = sp.upfirdn( h_filt, pn6, sps ) self.pn5_up = pn5_up = sp.upfirdn( h_filt, pn5, sps ) self.phase_shift = phase_shift = 1 self.lw = lw = 2 self.iir_taps = iir_taps = iir_taps_2 self.gain_ = gain_ = 0.5 self.freqc_ = freqc_ = freqc self.fps = fps = 30 self.fo = fo = 800 self.equalize_on = equalize_on = 0 self.echo_gain = echo_gain = 0 self.delay = delay = 0 self.const_qpsk = const_qpsk = digital.constellation_calcdist(digital.psk_4()[0], digital.psk_4()[1], 4, 1).base() self.const_bpsk = const_bpsk = digital.constellation_calcdist(digital.psk_2()[0], digital.psk_2()[1], 2, 1).base() self.bw = bw = 1 self.buff_size = buff_size = 32768 self.axis = axis = 2 self.PLL_ON = PLL_ON = 0 ################################################## # Blocks ################################################## self.tab0 = Qt.QTabWidget() self.tab0_widget_0 = Qt.QWidget() self.tab0_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab0_widget_0) self.tab0_grid_layout_0 = Qt.QGridLayout() self.tab0_layout_0.addLayout(self.tab0_grid_layout_0) self.tab0.addTab(self.tab0_widget_0, 'Cross-Correlation') self.tab0_widget_1 = Qt.QWidget() self.tab0_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab0_widget_1) self.tab0_grid_layout_1 = Qt.QGridLayout() self.tab0_layout_1.addLayout(self.tab0_grid_layout_1) self.tab0.addTab(self.tab0_widget_1, 'Spectrum') self.top_grid_layout.addWidget(self.tab0, 0, 0, 10, 2) for r in range(0, 10): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 2): self.top_grid_layout.setColumnStretch(c, 1) _phase_shift_check_box = Qt.QCheckBox('PI Phase Shift') self._phase_shift_choices = {True: 1, False: 0} self._phase_shift_choices_inv = dict((v,k) for k,v in self._phase_shift_choices.items()) self._phase_shift_callback = lambda i: Qt.QMetaObject.invokeMethod(_phase_shift_check_box, "setChecked", Qt.Q_ARG("bool", self._phase_shift_choices_inv[i])) self._phase_shift_callback(self.phase_shift) _phase_shift_check_box.stateChanged.connect(lambda i: self.set_phase_shift(self._phase_shift_choices[bool(i)])) self.top_grid_layout.addWidget(_phase_shift_check_box, 12, 1, 1, 1) for r in range(12, 13): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self._gain__range = Range(0.1, 1, 0.01, 0.5, 200) self._gain__win = RangeWidget(self._gain__range, self.set_gain_, 'Gain (Amp)', "counter_slider", float) self.top_grid_layout.addWidget(self._gain__win, 10, 1, 1, 1) for r in range(10, 11): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self._freqc__range = Range(70, 6000, .01, freqc, 200) self._freqc__win = RangeWidget(self._freqc__range, self.set_freqc_, 'Carrier (MHz)', "counter_slider", float) self.top_grid_layout.addWidget(self._freqc__win, 10, 0, 1, 1) for r in range(10, 11): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self._fo_range = Range(-10000, 10000, 1, 800, 200) self._fo_win = RangeWidget(self._fo_range, self.set_fo, 'Frequency Offset (Hz)', "counter_slider", float) self.top_grid_layout.addWidget(self._fo_win, 12, 0, 1, 1) for r in range(12, 13): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) # Create the options list self._equalize_on_options = (0, 1, ) # Create the labels list self._equalize_on_labels = ('Equalizer Off', 'Equalizer On', ) # Create the combo box self._equalize_on_tool_bar = Qt.QToolBar(self) self._equalize_on_tool_bar.addWidget(Qt.QLabel('Equalizer Select' + ": ")) self._equalize_on_combo_box = Qt.QComboBox() self._equalize_on_tool_bar.addWidget(self._equalize_on_combo_box) for _label in self._equalize_on_labels: self._equalize_on_combo_box.addItem(_label) self._equalize_on_callback = lambda i: Qt.QMetaObject.invokeMethod(self._equalize_on_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._equalize_on_options.index(i))) self._equalize_on_callback(self.equalize_on) self._equalize_on_combo_box.currentIndexChanged.connect( lambda i: self.set_equalize_on(self._equalize_on_options[i])) # Create the radio buttons self.top_grid_layout.addWidget(self._equalize_on_tool_bar, 13, 0, 1, 1) for r in range(13, 14): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self._echo_gain_range = Range(0, 1, 0.01, 0, 200) self._echo_gain_win = RangeWidget(self._echo_gain_range, self.set_echo_gain, 'Echo Path Gain (A)', "counter_slider", float) self.top_grid_layout.addWidget(self._echo_gain_win, 11, 0, 1, 1) for r in range(11, 12): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self._delay_range = Range(0, delay_limit, 1, 0, 200) self._delay_win = RangeWidget(self._delay_range, self.set_delay, 'Delay (samples)', "counter_slider", float) self.top_grid_layout.addWidget(self._delay_win, 11, 1, 1, 1) for r in range(11, 12): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) # Create the options list self._PLL_ON_options = (0, 1, ) # Create the labels list self._PLL_ON_labels = ('PLL ON', 'PLL OFF', ) # Create the combo box self._PLL_ON_tool_bar = Qt.QToolBar(self) self._PLL_ON_tool_bar.addWidget(Qt.QLabel('PLL Select' + ": ")) self._PLL_ON_combo_box = Qt.QComboBox() self._PLL_ON_tool_bar.addWidget(self._PLL_ON_combo_box) for _label in self._PLL_ON_labels: self._PLL_ON_combo_box.addItem(_label) self._PLL_ON_callback = lambda i: Qt.QMetaObject.invokeMethod(self._PLL_ON_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._PLL_ON_options.index(i))) self._PLL_ON_callback(self.PLL_ON) self._PLL_ON_combo_box.currentIndexChanged.connect( lambda i: self.set_PLL_ON(self._PLL_ON_options[i])) # Create the radio buttons self.top_grid_layout.addWidget(self._PLL_ON_tool_bar, 13, 1, 1, 1) for r in range(13, 14): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_time_sink_x_0_0 = qtgui.time_sink_f( 4096, #size samp_rate*1000, #samp_rate "Cross Correlation", #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(-2, 2) self.qtgui_time_sink_x_0_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0_0.enable_tags(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(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(True) self.qtgui_time_sink_x_0_0.enable_stem_plot(False) labels = ['Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5', 'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10'] 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] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] for i in range(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.tab0_grid_layout_0.addWidget(self._qtgui_time_sink_x_0_0_win, 5, 0, 5, 1) for r in range(5, 10): self.tab0_grid_layout_0.setRowStretch(r, 1) for c in range(0, 1): self.tab0_grid_layout_0.setColumnStretch(c, 1) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 4096, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate*1e3, #bw "", #name 1 ) self.qtgui_freq_sink_x_0.set_update_time(1/fps) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') 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(1.0) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(True) labels = ['In-Phase', 'Quadrature', '', '', '', '', '', '', '', ''] 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 range(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.tab0_grid_layout_1.addWidget(self._qtgui_freq_sink_x_0_win, 5, 0, 5, 1) for r in range(5, 10): self.tab0_grid_layout_1.setRowStretch(r, 1) for c in range(0, 1): self.tab0_grid_layout_1.setColumnStretch(c, 1) self.qtgui_freq_sink_x_0.set_processor_affinity([0]) self.interp_fir_filter_xxx_1_0 = filter.interp_fir_filter_ccc(sps, (1,1,1,1)) self.interp_fir_filter_xxx_1_0.declare_sample_delay(0) self.iir_filter_xxx_0 = filter.iir_filter_ccz([(1)], iir_taps, True) self.iio_pluto_source_0 = iio.pluto_source(epy_module_0.RX, int(freqc_*1e6), int(samp_rate*1000), 20000000, buff_size, True, True, True, 'manual', 32, '', True) self.iio_pluto_sink_0 = iio.pluto_sink(epy_module_0.TX, int(freqc_*1e6), int(samp_rate*1000), 20000000, buff_size, False, 10.0, '', True) self._echo_gain_iir_range = Range(0, 1, 0.01, 0, 200) self._echo_gain_iir_win = RangeWidget(self._echo_gain_iir_range, self.set_echo_gain_iir, 'Equalizer Gain (A)', "counter_slider", float) self.top_grid_layout.addWidget(self._echo_gain_iir_win, 14, 0, 1, 1) for r in range(14, 15): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self.digital_glfsr_source_x_0 = digital.glfsr_source_b(6, True, 0, 1) self.digital_costas_loop_cc_0 = digital.costas_loop_cc(3.14/100, 2, False) self.digital_corr_est_cc_0 = digital.corr_est_cc(pn6_up, sps, 0, 0.7, digital.THRESHOLD_ABSOLUTE) self.digital_chunks_to_symbols_xx_1 = digital.chunks_to_symbols_bc(const_bpsk.points(), 1) self._delay_iir_range = Range(1, delay_limit, 1, 1, 200) self._delay_iir_win = RangeWidget(self._delay_iir_range, self.set_delay_iir, 'Equalizer Delay (samples)', "counter_slider", float) self.top_grid_layout.addWidget(self._delay_iir_win, 14, 1, 1, 1) for r in range(14, 15): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self.blocks_tag_gate_0_0_0 = blocks.tag_gate(gr.sizeof_gr_complex * 1, False) self.blocks_tag_gate_0_0_0.set_single_key("time_est") self.blocks_tag_gate_0_0 = blocks.tag_gate(gr.sizeof_gr_complex * 1, False) self.blocks_tag_gate_0_0.set_single_key("corr_est") self.blocks_tag_gate_0 = blocks.tag_gate(gr.sizeof_gr_complex * 1, False) self.blocks_tag_gate_0.set_single_key("amp_est") self.blocks_selector_0_0 = blocks.selector(gr.sizeof_gr_complex*1,equalize_on,0) self.blocks_selector_0_0.set_enabled(True) self.blocks_selector_0 = blocks.selector(gr.sizeof_gr_complex*1,PLL_ON,0) self.blocks_selector_0.set_enabled(True) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex*1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_2 = blocks.multiply_const_cc((1/63/sps)*np.exp(1j*pi*phase_shift)) self.blocks_multiply_const_vxx_1 = blocks.multiply_const_cc(echo_gain) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_cc(gain_ ) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex*1, delay) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) self.blocks_add_xx_0 = blocks.add_vcc(1) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate*1000, analog.GR_COS_WAVE, fo, 1, 0, 0) self.analog_agc_xx_0 = analog.agc_cc(1e-4, 1.0, 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0, 0), (self.blocks_selector_0, 1)) self.connect((self.analog_agc_xx_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_complex_to_real_0, 0), (self.qtgui_time_sink_x_0_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_const_vxx_1, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_multiply_const_vxx_2, 0), (self.blocks_tag_gate_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.iio_pluto_sink_0, 0)) self.connect((self.blocks_selector_0, 0), (self.blocks_selector_0_0, 0)) self.connect((self.blocks_selector_0, 0), (self.iir_filter_xxx_0, 0)) self.connect((self.blocks_selector_0_0, 0), (self.digital_corr_est_cc_0, 0)) self.connect((self.blocks_selector_0_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.blocks_tag_gate_0, 0), (self.blocks_tag_gate_0_0, 0)) self.connect((self.blocks_tag_gate_0_0, 0), (self.blocks_tag_gate_0_0_0, 0)) self.connect((self.blocks_tag_gate_0_0_0, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_1, 0), (self.interp_fir_filter_xxx_1_0, 0)) self.connect((self.digital_corr_est_cc_0, 1), (self.blocks_multiply_const_vxx_2, 0)) self.connect((self.digital_corr_est_cc_0, 0), (self.blocks_null_sink_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.blocks_selector_0, 0)) self.connect((self.digital_glfsr_source_x_0, 0), (self.digital_chunks_to_symbols_xx_1, 0)) self.connect((self.iio_pluto_source_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.iir_filter_xxx_0, 0), (self.blocks_selector_0_0, 1)) self.connect((self.interp_fir_filter_xxx_1_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.interp_fir_filter_xxx_1_0, 0), (self.blocks_delay_0, 0))
def __init__(self): gr.hier_block2.__init__( self, "PW-Sat2 Demodulator", gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(0, 0, 0), ) self.message_port_register_hier_out("frames") Qt.QWidget.__init__(self) self.top_layout = Qt.QVBoxLayout() self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.setLayout(self.top_layout) ################################################## # Variables ################################################## self.symb_rate = symb_rate = 1200 self.samp_per_sym = samp_per_sym = 10 self.samp_rate = samp_rate = symb_rate * samp_per_sym self.frequency_offset = frequency_offset = -20e3 self.decimation = decimation = 16 self.bpsk = bpsk = digital.constellation_calcdist(([-1, 1]), ([0, 1]), 2, 1).base() self.alpha = alpha = 0.5 ################################################## # Blocks ################################################## self._frequency_offset_range = Range(-40e3, 40e3, 10, -20e3, 200) self._frequency_offset_win = RangeWidget(self._frequency_offset_range, self.set_frequency_offset, 'Frequency Offset', "counter_slider", float) self.top_grid_layout.addWidget(self._frequency_offset_win) self._decimation_options = ( 16, 8, 4, 2, ) self._decimation_labels = ( '1200', '2400', '4800', '9600', ) self._decimation_tool_bar = Qt.QToolBar(self) self._decimation_tool_bar.addWidget(Qt.QLabel('Symbol Rate' + ": ")) self._decimation_combo_box = Qt.QComboBox() self._decimation_tool_bar.addWidget(self._decimation_combo_box) for label in self._decimation_labels: self._decimation_combo_box.addItem(label) self._decimation_callback = lambda i: Qt.QMetaObject.invokeMethod( self._decimation_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._decimation_options.index(i))) self._decimation_callback(self.decimation) self._decimation_combo_box.currentIndexChanged.connect( lambda i: self.set_decimation(self._decimation_options[i])) self.top_grid_layout.addWidget(self._decimation_tool_bar) self._alpha_range = Range(0, 1, 1e-3, 0.5, 200) self._alpha_win = RangeWidget(self._alpha_range, self.set_alpha, "alpha", "counter_slider", float) self.top_grid_layout.addWidget(self._alpha_win) self.satellites_nrzi_decode_0 = satellites.nrzi_decode() self.satellites_hdlc_deframer_0 = satellites.hdlc_deframer( check_fcs=True, max_length=10000) self.root_raised_cosine_filter_0_0 = filter.fir_filter_ccf( 1, firdes.root_raised_cosine(1, samp_rate, symb_rate, alpha, 300)) self.qtgui_waterfall_sink_x_1 = qtgui.waterfall_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc 192000, #bw "", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_1.set_update_time(0.10) self.qtgui_waterfall_sink_x_1.enable_grid(False) self.qtgui_waterfall_sink_x_1.enable_axis_labels(True) if not True: self.qtgui_waterfall_sink_x_1.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_waterfall_sink_x_1.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_1.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_1.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_1.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_1.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_1.set_intensity_range(-140, 10) self._qtgui_waterfall_sink_x_1_win = sip.wrapinstance( self.qtgui_waterfall_sink_x_1.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_1_win) self.qtgui_time_sink_x_0 = qtgui.time_sink_c( 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_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: if (i % 2 == 0): self.qtgui_time_sink_x_0.set_line_label( i, "Re{{Data {0}}}".format(i / 2)) else: self.qtgui_time_sink_x_0.set_line_label( i, "Im{{Data {0}}}".format(i / 2)) 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) self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc 192000, #bw "", #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(-140, 10) self.qtgui_freq_sink_x_0_0.set_y_label('Relative Gain', 'dB') 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_axis_labels(True) 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" == "float" or "complex" == "msg_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) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') 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_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win) self.qtgui_const_sink_x_0 = qtgui.const_sink_c( 128, #size "", #name 1 #number of inputs ) self.qtgui_const_sink_x_0.set_update_time(0.10) self.qtgui_const_sink_x_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0.set_x_axis(-2, 2) 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_grid_layout.addWidget(self._qtgui_const_sink_x_0_win) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc( 1, (firdes.low_pass(1, 192000, 40000, 1000)), frequency_offset, 192000) self.fractional_resampler_xx_0 = filter.fractional_resampler_cc( 0, decimation) self.digital_symbol_sync_xx_0 = digital.symbol_sync_cc( digital.TED_ZERO_CROSSING, samp_per_sym, 0.045, 1.0, 1, 0.1, 1, digital.constellation_bpsk().base(), digital.IR_MMSE_8TAP, 128, ([])) self.digital_descrambler_bb_0_1 = digital.descrambler_bb( 0x21, 0x00, 16) self.digital_costas_loop_cc_0 = digital.costas_loop_cc(0.1, 2, False) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb( bpsk) self.analog_agc_xx_0 = analog.agc_cc(1e-3, 1, 1.0) self.analog_agc_xx_0.set_max_gain(30) ################################################## # Connections ################################################## self.msg_connect((self.satellites_hdlc_deframer_0, 'out'), (self, 'frames')) self.connect((self.analog_agc_xx_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.digital_descrambler_bb_0_1, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.root_raised_cosine_filter_0_0, 0)) self.connect((self.digital_descrambler_bb_0_1, 0), (self.satellites_nrzi_decode_0, 0)) self.connect((self.digital_symbol_sync_xx_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.digital_symbol_sync_xx_0, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.fractional_resampler_xx_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.fractional_resampler_xx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.qtgui_freq_sink_x_0_0, 0)) self.connect((self, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self, 0), (self.qtgui_waterfall_sink_x_1, 0)) self.connect((self.root_raised_cosine_filter_0_0, 0), (self.digital_symbol_sync_xx_0, 0)) self.connect((self.root_raised_cosine_filter_0_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.satellites_nrzi_decode_0, 0), (self.satellites_hdlc_deframer_0, 0))
def __init__(self, satellite='NOAA-XX', gain=35, freq=1698e6, sync_check=False, side="A:0", rate=2e6, frames_file=os.environ['HOME'] + '/data/noaa/frames/NOAA-XX.hrpt', baseband_file=os.environ['HOME'] + '/data/noaa/baseband/NOAA-XX.dat'): grc_wxgui.top_block_gui.__init__(self, title="Enhanced NOAA HRPT Receiver") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Parameters ################################################## self.satellite = satellite self.gain = gain self.freq = freq self.sync_check = sync_check self.side = side self.rate = rate self.frames_file = frames_file self.baseband_file = baseband_file ################################################## # Variables ################################################## self.sym_rate = sym_rate = 600*1109 self.samp_rate = samp_rate = rate self.config_filename = config_filename = os.environ['HOME']+'/.gnuradio/noaa_hrpt.conf' self.sps = sps = samp_rate/sym_rate self._saved_pll_alpha_config = ConfigParser.ConfigParser() self._saved_pll_alpha_config.read(config_filename) try: saved_pll_alpha = self._saved_pll_alpha_config.getfloat(satellite, 'pll_alpha') except: saved_pll_alpha = 0.005 self.saved_pll_alpha = saved_pll_alpha self._saved_clock_alpha_config = ConfigParser.ConfigParser() self._saved_clock_alpha_config.read(config_filename) try: saved_clock_alpha = self._saved_clock_alpha_config.getfloat(satellite, 'clock_alpha') except: saved_clock_alpha = 0.001 self.saved_clock_alpha = saved_clock_alpha self.sync_check_txt = sync_check_txt = sync_check self.side_text = side_text = side self._saved_gain_config = ConfigParser.ConfigParser() self._saved_gain_config.read(config_filename) try: saved_gain = self._saved_gain_config.getfloat(satellite, 'gain') except: saved_gain = gain self.saved_gain = saved_gain self.satellite_text = satellite_text = satellite self.sample_rate_text = sample_rate_text = samp_rate self.rate_tb = rate_tb = rate self.pll_alpha = pll_alpha = saved_pll_alpha self.max_clock_offset = max_clock_offset = 0.1 self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/samp_rate self.hs = hs = int(sps/2.0) self.gain_slider = gain_slider = gain self.freq_tb = freq_tb = freq self.frames_outfile_text = frames_outfile_text = frames_file self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime()) self.clock_alpha = clock_alpha = saved_clock_alpha ################################################## # Blocks ################################################## _gain_slider_sizer = wx.BoxSizer(wx.VERTICAL) self._gain_slider_text_box = forms.text_box( parent=self.GetWin(), sizer=_gain_slider_sizer, value=self.gain_slider, callback=self.set_gain_slider, label="Gain", converter=forms.int_converter(), proportion=0, ) self._gain_slider_slider = forms.slider( parent=self.GetWin(), sizer=_gain_slider_sizer, value=self.gain_slider, callback=self.set_gain_slider, minimum=0, maximum=100, num_steps=100, style=wx.SL_HORIZONTAL, cast=int, proportion=1, ) self.GridAdd(_gain_slider_sizer, 2, 0, 1, 1) self.displays = self.displays = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.displays.AddPage(grc_wxgui.Panel(self.displays), "RX NOAA HRPT") self.displays.AddPage(grc_wxgui.Panel(self.displays), "Information") self.Add(self.displays) _clock_alpha_sizer = wx.BoxSizer(wx.VERTICAL) self._clock_alpha_text_box = forms.text_box( parent=self.GetWin(), sizer=_clock_alpha_sizer, value=self.clock_alpha, callback=self.set_clock_alpha, label="Clock alpha", converter=forms.float_converter(), proportion=0, ) self._clock_alpha_slider = forms.slider( parent=self.GetWin(), sizer=_clock_alpha_sizer, value=self.clock_alpha, callback=self.set_clock_alpha, minimum=0.001, maximum=0.1, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_clock_alpha_sizer, 2, 2, 1, 1) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.displays.GetPage(0).GetWin(), baseband_freq=0, y_per_div=5, y_divs=10, ref_level=-70, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=True, avg_alpha=0.4, title="NOAA HRPT FFT Spectrum", peak_hold=False, ) self.displays.GetPage(0).Add(self.wxgui_fftsink2_0.win) self.uhd_usrp_source_0 = uhd.usrp_source( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_subdev_spec(side, 0) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(freq, 0) self.uhd_usrp_source_0.set_gain(gain_slider, 0) self._sync_check_txt_static_text = forms.static_text( parent=self.GetWin(), value=self.sync_check_txt, callback=self.set_sync_check_txt, label="Continuous sync check", converter=forms.str_converter(), ) self.GridAdd(self._sync_check_txt_static_text, 0, 2, 1, 1) self._side_text_static_text = forms.static_text( parent=self.GetWin(), value=self.side_text, callback=self.set_side_text, label="USRP Side", converter=forms.str_converter(), ) self.GridAdd(self._side_text_static_text, 0, 0, 1, 1) self._satellite_text_static_text = forms.static_text( parent=self.GetWin(), value=self.satellite_text, callback=self.set_satellite_text, label="Satellite", converter=forms.str_converter(), ) self.GridAdd(self._satellite_text_static_text, 0, 1, 1, 1) self._sample_rate_text_static_text = forms.static_text( parent=self.displays.GetPage(1).GetWin(), value=self.sample_rate_text, callback=self.set_sample_rate_text, label="Sample rate", converter=forms.float_converter(), ) self.displays.GetPage(1).GridAdd(self._sample_rate_text_static_text, 3, 0, 1, 1) self._rate_tb_text_box = forms.text_box( parent=self.GetWin(), value=self.rate_tb, callback=self.set_rate_tb, label="Sample rate", converter=forms.float_converter(), ) self.GridAdd(self._rate_tb_text_box, 1, 0, 1, 1) self.poesweather_noaa_hrpt_deframer_0 = poesweather.noaa_hrpt_deframer(False) _pll_alpha_sizer = wx.BoxSizer(wx.VERTICAL) self._pll_alpha_text_box = forms.text_box( parent=self.GetWin(), sizer=_pll_alpha_sizer, value=self.pll_alpha, callback=self.set_pll_alpha, label="PLL Alpha", converter=forms.float_converter(), proportion=0, ) self._pll_alpha_slider = forms.slider( parent=self.GetWin(), sizer=_pll_alpha_sizer, value=self.pll_alpha, callback=self.set_pll_alpha, minimum=0.005, maximum=0.5, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_pll_alpha_sizer, 2, 1, 1, 1) self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset) self._freq_tb_text_box = forms.text_box( parent=self.GetWin(), value=self.freq_tb, callback=self.set_freq_tb, label="Frequency", converter=forms.float_converter(), ) self.GridAdd(self._freq_tb_text_box, 1, 1, 1, 1) self._frames_outfile_text_static_text = forms.static_text( parent=self.displays.GetPage(1).GetWin(), value=self.frames_outfile_text, callback=self.set_frames_outfile_text, label="Frames filename", converter=forms.str_converter(), ) self.displays.GetPage(1).GridAdd(self._frames_outfile_text_static_text, 4, 0, 1, 1) self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_ff(sps/2.0, clock_alpha**2/4.0, 0.5, clock_alpha, max_clock_offset) self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb() self._datetime_text_static_text = forms.static_text( parent=self.displays.GetPage(1).GetWin(), value=self.datetime_text, callback=self.set_datetime_text, label="Acquisition start", converter=forms.str_converter(), ) self.displays.GetPage(1).GridAdd(self._datetime_text_static_text, 2, 0, 1, 1) self.blocks_moving_average_xx_0 = blocks.moving_average_ff(hs, 1.0/hs, 4000) self.blocks_file_sink_1 = blocks.file_sink(gr.sizeof_short*1, baseband_file) self.blocks_file_sink_1.set_unbuffered(False) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_short*1, frames_file) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_complex_to_interleaved_short_0 = blocks.complex_to_interleaved_short() self.analog_agc_xx_0 = analog.agc_cc(1e-5, 1.0, 1.0/32768.0, 1.0) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0, 0), (self.pll, 0)) self.connect((self.pll, 0), (self.blocks_moving_average_xx_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.blocks_moving_average_xx_0, 0), (self.digital_clock_recovery_mm_xx_0, 0)) self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.digital_binary_slicer_fb_0, 0)) self.connect((self.poesweather_noaa_hrpt_deframer_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.digital_binary_slicer_fb_0, 0), (self.poesweather_noaa_hrpt_deframer_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.blocks_complex_to_interleaved_short_0, 0)) self.connect((self.blocks_complex_to_interleaved_short_0, 0), (self.blocks_file_sink_1, 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") if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"): self.restoreGeometry(self.settings.value("geometry").toByteArray()) else: self.restoreGeometry( self.settings.value("geometry", type=QtCore.QByteArray)) ################################################## # Variables ################################################## self.sps = sps = 4 self.nfilts = nfilts = 32 self.ntaps = ntaps = 11 * nfilts * sps self.excess_bw = excess_bw = 0.4 self.timing_bw = timing_bw = 2 * pi / 100 self.samp_rate_0 = samp_rate_0 = 20000 * sps self.rx_taps = rx_taps = firdes.root_raised_cosine( nfilts, nfilts, 1.0, excess_bw, ntaps) self.freq_bw = freq_bw = 2 * pi / 100 self.fll_ntaps = fll_ntaps = 55 self.f_fine = f_fine = 0 self.const_points = const_points = 4 ################################################## # Blocks ################################################## self._f_fine_range = Range(-2e6, 2e6, 1000, 0, 200) self._f_fine_win = RangeWidget(self._f_fine_range, self.set_f_fine, "f_fine", "counter_slider", float) self.top_layout.addWidget(self._f_fine_win) self.rtlsdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + '') self.rtlsdr_source_0.set_sample_rate(400e3 * sps) self.rtlsdr_source_0.set_center_freq(1.2e9 + f_fine, 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(30, 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.qtgui_sink_x_0 = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc 400e3, #bw "", #name True, #plotfreq True, #plotwaterfall True, #plottime True, #plotconst ) self.qtgui_sink_x_0.set_update_time(1.0 / 10) self._qtgui_sink_x_0_win = sip.wrapinstance( self.qtgui_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_sink_x_0_win) self.qtgui_sink_x_0.enable_rf_freq(False) self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf( sps, timing_bw, (rx_taps), nfilts, 0, 1.5, 1) self.digital_fll_band_edge_cc_0 = digital.fll_band_edge_cc( sps, excess_bw, fll_ntaps, freq_bw) self.digital_costas_loop_cc_0 = digital.costas_loop_cc( freq_bw, const_points * 2, False) self.digital_cma_equalizer_cc_0 = digital.cma_equalizer_cc( 4, 1, 0.0001, 1) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1, 400e3, True) self.analog_agc_xx_0 = analog.agc_cc(1e-4, 1.0, 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0, 0), (self.digital_fll_band_edge_cc_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.qtgui_sink_x_0, 0)) self.connect((self.digital_cma_equalizer_cc_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.digital_fll_band_edge_cc_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_cma_equalizer_cc_0, 0)) self.connect((self.rtlsdr_source_0, 0), (self.analog_agc_xx_0, 0))
def __init__(self): gr.top_block.__init__( self, "Downlink from TVAC (This should run all the time)") Qt.QWidget.__init__(self) self.setWindowTitle( "Downlink from TVAC (This should run all the time)") 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", "downlink") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.block_len_enc = block_len_enc = 1024 / 8 * 2 self.variable_constellation_0 = variable_constellation_0 = digital.constellation_calcdist( ([-1, 1]), ([0, 1]), 4, 1).base() self.samp_rate_factor = samp_rate_factor = 5 self.samp_rate = samp_rate = 250000 self.rgain = rgain = 0 self.payload = payload = block_len_enc + 4 self.freq_offset_flag = freq_offset_flag = 0 self.freq_offset = freq_offset = 0 ################################################## # Blocks ################################################## self._rgain_range = Range(0, 11, 1, 0, 200) self._rgain_win = RangeWidget(self._rgain_range, self.set_rgain, 'RX Gain', "counter_slider", float) self.top_layout.addWidget(self._rgain_win) self._freq_offset_range = Range(-400e3, 400e3, 1.5e3, 0, 200) self._freq_offset_win = RangeWidget(self._freq_offset_range, self.set_freq_offset, 'Frequency Offset', "counter_slider", float) self.top_layout.addWidget(self._freq_offset_win) self.rational_resampler_xxx_1 = filter.rational_resampler_ccc( interpolation=1, decimation=5, taps=None, fractional_bw=None, ) self.qtgui_sink_x_1 = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name False, #plotfreq False, #plotwaterfall False, #plottime True, #plotconst ) self.qtgui_sink_x_1.set_update_time(1.0 / 10) self._qtgui_sink_x_1_win = sip.wrapinstance( self.qtgui_sink_x_1.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_sink_x_1_win) self.qtgui_sink_x_1.enable_rf_freq(False) self.qtgui_sink_x_0_0_1 = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "Vor Sync", #name True, #plotfreq True, #plotwaterfall True, #plottime True, #plotconst ) self.qtgui_sink_x_0_0_1.set_update_time(1.0 / 10) self._qtgui_sink_x_0_0_1_win = sip.wrapinstance( self.qtgui_sink_x_0_0_1.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_sink_x_0_0_1_win) self.qtgui_sink_x_0_0_1.enable_rf_freq(False) self.qtgui_sink_x_0_0 = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate * samp_rate_factor, #bw "Vor Sync", #name True, #plotfreq True, #plotwaterfall True, #plottime True, #plotconst ) self.qtgui_sink_x_0_0.set_update_time(1.0 / 10) self._qtgui_sink_x_0_0_win = sip.wrapinstance( self.qtgui_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_sink_x_0_0_win) self.qtgui_sink_x_0_0.enable_rf_freq(False) self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + 'bladerf=1269166c0b71088680ad4ec53222be07,xb200=144M') self.osmosdr_source_0.set_sample_rate(samp_rate * samp_rate_factor) self.osmosdr_source_0.set_center_freq(145.95e6, 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(rgain, 0) self.osmosdr_source_0.set_if_gain(0, 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._freq_offset_flag_range = Range(0, 1, 1, 0, 200) self._freq_offset_flag_win = RangeWidget(self._freq_offset_flag_range, self.set_freq_offset_flag, 'Enable flatsat freq', "counter_slider", float) self.top_layout.addWidget(self._freq_offset_flag_win) self.fir_filter_xxx_0 = filter.fir_filter_ccc(samp_rate_factor, (1, )) self.fir_filter_xxx_0.declare_sample_delay(0) self.digital_mpsk_receiver_cc_0_0 = digital.mpsk_receiver_cc( 2, 0, cmath.pi / 100.0, -0.05, 0.05, 0.25, 0.05, 4, 4, 0.005) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb( variable_constellation_0) self.ccsds_softbits_msg_to_bytes_b_0 = ccsds.softbits_msg_to_bytes_b() self.ccsds_randomiser_softbits_0 = ccsds.randomiser_softbits( 0x95, 0xFF) self.ccsds_mpsk_ambiguity_resolver_f_0 = ccsds.mpsk_ambiguity_resolver_f( 2, '49E0DCC7', 32, 1, 0.8, block_len_enc, 0) self.ccsds_message_info_0 = ccsds.message_info(10) self.ccsds_ldpc_decoder_0 = ccsds.ldpc_decoder( '/tmp/AR4JA_r12_k1024n.a', ccsds.LDPC_SYS_FRONT, ccsds.LDPC_PUNCT_BACK, 512, tuple(([]))) self.ccsds_blob_msg_sink_b_0 = ccsds.blob_msg_sink_b(256 / 2) self.blocks_udp_sink_0_1 = blocks.udp_sink(gr.sizeof_char * 1, '127.0.0.1', 5431, 256, True) self.blocks_udp_sink_0_0 = blocks.udp_sink(gr.sizeof_char * 1, '127.0.0.1', 5433, 1472, True) self.blocks_udp_sink_0 = blocks.udp_sink(gr.sizeof_gr_complex * 1, '127.0.0.1', 5435, 1472, True) self.blocks_null_sink_1 = blocks.null_sink(gr.sizeof_char * 1) self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_char_to_float_0 = blocks.char_to_float(1, 0.5) self.blocks_add_const_vxx_0 = blocks.add_const_vff((-1, )) self.band_pass_filter_0 = filter.fir_filter_ccc( 1, firdes.complex_band_pass(1, samp_rate * samp_rate_factor, 40e3, 60e3, 6e3, firdes.WIN_HAMMING, 6.76)) self.analog_sig_source_x_0_0 = analog.sig_source_c( samp_rate * samp_rate_factor, analog.GR_COS_WAVE, -freq_offset, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, -50000, 1, 0) self.analog_agc_xx_0 = analog.agc_cc(1e-4, 0.5, 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.msg_connect((self.ccsds_blob_msg_sink_b_0, 'out'), (self.ccsds_message_info_0, 'in')) self.msg_connect((self.ccsds_ldpc_decoder_0, 'out'), (self.ccsds_softbits_msg_to_bytes_b_0, 'in')) self.msg_connect((self.ccsds_mpsk_ambiguity_resolver_f_0, 'out'), (self.ccsds_randomiser_softbits_0, 'in')) self.msg_connect((self.ccsds_randomiser_softbits_0, 'out'), (self.ccsds_ldpc_decoder_0, 'in')) self.connect((self.analog_agc_xx_0, 0), (self.rational_resampler_xxx_1, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.fir_filter_xxx_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.ccsds_mpsk_ambiguity_resolver_f_0, 0)) self.connect((self.blocks_char_to_float_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.qtgui_sink_x_0_0_1, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.ccsds_softbits_msg_to_bytes_b_0, 0), (self.blocks_null_sink_1, 0)) self.connect((self.ccsds_softbits_msg_to_bytes_b_0, 0), (self.blocks_udp_sink_0_1, 0)) self.connect((self.ccsds_softbits_msg_to_bytes_b_0, 0), (self.ccsds_blob_msg_sink_b_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blocks_udp_sink_0_0, 0)) self.connect((self.digital_mpsk_receiver_cc_0_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.digital_mpsk_receiver_cc_0_0, 0), (self.qtgui_sink_x_1, 0)) self.connect((self.fir_filter_xxx_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.osmosdr_source_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.osmosdr_source_0, 0), (self.blocks_udp_sink_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.qtgui_sink_x_0_0, 0)) self.connect((self.rational_resampler_xxx_1, 0), (self.digital_mpsk_receiver_cc_0_0, 0))
def __init__(self, constellation, frame_type, code_rate): gr.top_block.__init__(self, "Dvbs2 Tx") ################################################## # Parameters ################################################## # Header is 10 bytes try: frame_length = 1.0 * BBFRAME_LENGTH[frame_type][code_rate] - 80 except KeyError: raise UnknownFrameLength(frame_type, code_rate) # print("Base frame length: %s" % frame_length) frame_length /= 8 # print("Base frame length: %s" % frame_length) assert int( frame_length ) == 1.0 * frame_length, "Frame length {0} won't work because {0}/8 = {1}!".format( frame_length, frame_length / 8.0) frame_length = int(frame_length) self.frame_length = frame_length bits_per_input, bits_per_output = get_ratio(constellation) ################################################## # Variables ################################################## self.symbol_rate = symbol_rate = 5000000 self.taps = taps = 100 self.samp_rate = samp_rate = symbol_rate * 2 self.rolloff = rolloff = 0.2 self.noise = noise = 0 self.gain = gain = 1 self.center_freq = center_freq = 1280e6 ################################################## # Blocks ################################################## self.ldpc_encoder_input = blocks.file_sink(gr.sizeof_char * 1, 'ldpc_encoder_input.bin', False) self.ldpc_encoder_input.set_unbuffered(False) self.fir_filter_xxx_0_0 = filter.fir_filter_ccc( 1, (numpy.conj([ 0.00000 + 1.00000j, 0.00000 - 1.00000j, 0.00000 - 1.00000j, 0.00000 + 1.00000j, 0.00000 - 1.00000j, 0.00000 + 1.00000j, 0.00000 - 1.00000j, 0.00000 - 1.00000j, 0.00000 + 1.00000j, 0.00000 + 1.00000j, 0.00000 + 1.00000j, 0.00000 - 1.00000j, 0.00000 + 1.00000j, 0.00000 + 1.00000j, 0.00000 - 1.00000j, 0.00000 - 1.00000j, 0.00000 + 1.00000j, 0.00000 + 1.00000j, 0.00000 - 1.00000j, 0.00000 + 1.00000j, 0.00000 + 1.00000j, 0.00000 - 1.00000j, 0.00000 + 1.00000j, 0.00000 + 1.00000j, 0.00000 + 1.00000j, 0.00000 + 1.00000j, 0.00000 + 1.00000j, 0.00000 - 1.00000j, 0.00000 + 1.00000j, 0.00000 - 1.00000j, 0.00000 + 1.00000j, 0.00000 - 1.00000j ] + [ 0, ] * (89 - 32)))) self.fir_filter_xxx_0_0.declare_sample_delay(0) self.fir_filter_xxx_0 = filter.fir_filter_ccc(1, (numpy.conj([ 0, ] * (89 - 25) + [ 0.00000 - 1.00000j, 0.00000 - 1.00000j, 0.00000 + 1.00000j, 0.00000 - 1.00000j, 0.00000 + 1.00000j, 0.00000 + 1.00000j, 0.00000 - 1.00000j, 0.00000 + 1.00000j, 0.00000 + 1.00000j, 0.00000 - 1.00000j, 0.00000 - 1.00000j, 0.00000 + 1.00000j, 0.00000 - 1.00000j, 0.00000 - 1.00000j, 0.00000 - 1.00000j, 0.00000 + 1.00000j, 0.00000 - 1.00000j, 0.00000 - 1.00000j, 0.00000 - 1.00000j, 0.00000 - 1.00000j, 0.00000 + 1.00000j, 0.00000 + 1.00000j, 0.00000 + 1.00000j, 0.00000 + 1.00000j, 0.00000 + 0.00000j ]))) self.fir_filter_xxx_0.declare_sample_delay(0) self.fft_filter_xxx_0 = filter.fft_filter_ccc( 1, (firdes.root_raised_cosine(1.0, samp_rate, samp_rate / 2, rolloff, taps)), 1) self.fft_filter_xxx_0.declare_sample_delay(0) self.dtv_dvbs2_physical_cc_0 = dtv.dvbs2_physical_cc( frame_type, code_rate, dtv.MOD_BPSK, dtv.PILOTS_ON, 0) self.dtv_dvbs2_modulator_bc_0 = dtv.dvbs2_modulator_bc( frame_type, code_rate, dtv.MOD_BPSK, dtv.INTERPOLATION_OFF) self.dtv_dvbs2_interleaver_bb_0 = dtv.dvbs2_interleaver_bb( frame_type, code_rate, constellation) self.dtv_dvb_ldpc_bb_0 = dtv.dvb_ldpc_bb(dtv.STANDARD_DVBS2, frame_type, code_rate, dtv.MOD_OTHER) self.dtv_dvb_bch_bb_0 = dtv.dvb_bch_bb(dtv.STANDARD_DVBS2, frame_type, code_rate) self.dtv_dvb_bbscrambler_bb_0 = dtv.dvb_bbscrambler_bb( dtv.STANDARD_DVBS2, frame_type, code_rate) self.dtv_dvb_bbheader_bb_0 = dtv.dvb_bbheader_bb( dtv.STANDARD_DVBS2, frame_type, code_rate, dtv.RO_0_20, dtv.INPUTMODE_NORMAL, dtv.INBAND_OFF, 168, 4000000) self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf( 2, math.pi / 100.0, (firdes.root_raised_cosine( 2 * 32, 32, 1.0 / float(2), 0.35, 11 * 2 * 32)), 32, 16, 1.5, 1) self.digital_costas_loop_cc_0 = digital.costas_loop_cc( math.pi / 100.0, 4, False) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1, samp_rate / 10, True) self.blocks_sub_xx_0 = blocks.sub_cc(1) self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb( bits_per_input, bits_per_output, "", False, gr.GR_MSB_FIRST) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((gain, )) self.blocks_max_xx_0 = blocks.max_ff(1, 1) self.blocks_file_sink_1 = blocks.file_sink(gr.sizeof_float * 1, 'output.bin', False) self.blocks_file_sink_1.set_unbuffered(False) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1, 1) self.blocks_conjugate_cc_0 = blocks.conjugate_cc() self.blocks_complex_to_mag_0_0 = blocks.complex_to_mag(1) self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1) self.blocks_add_xx_2 = blocks.add_vcc(1) self.blocks_add_xx_0 = blocks.add_vcc(1) self.bit_interleaver_output_packed = blocks.file_sink( gr.sizeof_char * 1, 'bit_interleaver_output_packed.bin', False) self.bit_interleaver_output_packed.set_unbuffered(False) self.bit_interleaver_output = blocks.file_sink( gr.sizeof_char * 1, 'bit_interleaver_output.bin', False) self.bit_interleaver_output.set_unbuffered(False) self.bit_interleaver_input = blocks.file_sink( gr.sizeof_char * 1, 'bit_interleaver_input.bin', False) self.bit_interleaver_input.set_unbuffered(False) self.bch_encoder_input = blocks.file_sink(gr.sizeof_char * 1, 'bch_encoder_input.bin', False) self.bch_encoder_input.set_unbuffered(False) self.bb_scrambler_input_0 = blocks.file_sink(gr.sizeof_char * 1, 'bb_scrambler_input.bin', False) self.bb_scrambler_input_0.set_unbuffered(False) self.analog_random_source_x_0 = blocks.vector_source_b( map(int, numpy.random.randint(0, 255, frame_length)), False) self.analog_noise_source_x_1 = analog.noise_source_c( analog.GR_GAUSSIAN, noise, 0) self.analog_agc_xx_0 = analog.agc_cc(1e-4, 1.0, 1.0) self.analog_agc_xx_0.set_max_gain(8192) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.analog_noise_source_x_1, 0), (self.blocks_add_xx_2, 1)) self.connect((self.analog_random_source_x_0, 0), (self.dtv_dvb_bbheader_bb_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_complex_to_mag_0, 0)) self.connect((self.blocks_add_xx_2, 0), (self.analog_agc_xx_0, 0)) self.connect((self.blocks_complex_to_mag_0, 0), (self.blocks_max_xx_0, 1)) self.connect((self.blocks_complex_to_mag_0_0, 0), (self.blocks_max_xx_0, 0)) self.connect((self.blocks_conjugate_cc_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_max_xx_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.fft_filter_xxx_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.fir_filter_xxx_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.fir_filter_xxx_0_0, 0)) self.connect((self.blocks_repack_bits_bb_0, 0), (self.bit_interleaver_output_packed, 0)) self.connect((self.blocks_sub_xx_0, 0), (self.blocks_complex_to_mag_0_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_file_sink_1, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.blocks_conjugate_cc_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.blocks_delay_0, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.dtv_dvb_bbheader_bb_0, 0), (self.bb_scrambler_input_0, 0)) self.connect((self.dtv_dvb_bbheader_bb_0, 0), (self.dtv_dvb_bbscrambler_bb_0, 0)) self.connect((self.dtv_dvb_bbscrambler_bb_0, 0), (self.bch_encoder_input, 0)) self.connect((self.dtv_dvb_bbscrambler_bb_0, 0), (self.dtv_dvb_bch_bb_0, 0)) self.connect((self.dtv_dvb_bch_bb_0, 0), (self.dtv_dvb_ldpc_bb_0, 0)) self.connect((self.dtv_dvb_bch_bb_0, 0), (self.ldpc_encoder_input, 0)) self.connect((self.dtv_dvb_ldpc_bb_0, 0), (self.bit_interleaver_input, 0)) self.connect((self.dtv_dvb_ldpc_bb_0, 0), (self.dtv_dvbs2_interleaver_bb_0, 0)) self.connect((self.dtv_dvbs2_interleaver_bb_0, 0), (self.bit_interleaver_output, 0)) self.connect((self.dtv_dvbs2_interleaver_bb_0, 0), (self.blocks_repack_bits_bb_0, 0)) self.connect((self.dtv_dvbs2_interleaver_bb_0, 0), (self.dtv_dvbs2_modulator_bc_0, 0)) self.connect((self.dtv_dvbs2_modulator_bc_0, 0), (self.dtv_dvbs2_physical_cc_0, 0)) self.connect((self.dtv_dvbs2_physical_cc_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.fft_filter_xxx_0, 0), (self.blocks_add_xx_2, 0)) self.connect((self.fir_filter_xxx_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.fir_filter_xxx_0, 0), (self.blocks_sub_xx_0, 0)) self.connect((self.fir_filter_xxx_0_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.fir_filter_xxx_0_0, 0), (self.blocks_sub_xx_0, 1))
def __init__(self, corr_tag_delay=131): gr.top_block.__init__(self, "Lab3 BER") Qt.QWidget.__init__(self) self.setWindowTitle("Lab3 BER") 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", "lab3_ber") 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 ################################################## # Parameters ################################################## self.corr_tag_delay = corr_tag_delay ################################################## # Variables ################################################## self.rolloff = rolloff = 0.5 self.sps = sps = 4 self.snr_default = snr_default = 8.5 self.rolloff_ = rolloff_ = rolloff self.payload_len = payload_len = 31 self.num_tag_key = num_tag_key = "packet_num" self.nfilts_pfb = nfilts_pfb = 32 self.mark_delays = mark_delays = [0, 0, 34, 56, 87, 119] self.len_tag_key = len_tag_key = "packet_length" self.header_len = header_len = 32 self.cw_len = cw_len = 32 self.tag_s = tag_s = gr.tag_utils.python_to_tag( (0, pmt.intern(len_tag_key), pmt.from_long(payload_len), pmt.intern("vect_test_src"))) self.tag0 = tag0 = gr.tag_utils.python_to_tag( (0, pmt.intern(len_tag_key), pmt.from_long(cw_len), pmt.intern("vect_cw_src"))) self.sync_seq = sync_seq = [ 1, 1, -1, 1, -1, 1, 1, 1, -1, -1, 1, -1, -1, -1, 1, -1, -1, 1, 1, -1, 1, 1, -1, -1, -1, -1, 1, 1, -1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1, -1, 1, -1, 1, 1, -1, -1, -1, 1, 1, 1, 1, 1, 1 ] self.snr_db = snr_db = snr_default self.samp_rate = samp_rate = 1e3 self.rrc_filter = rrc_filter = firdes.root_raised_cosine( 4, sps, 1, rolloff_, 32 * sps + 1) self.reset_ber = reset_ber = 0 self.pn_order = pn_order = np.round(np.log2(payload_len + 1)) self.pn6_padded = pn6_padded = [ 1, 1, 1, 1, 1, 1, -1, 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, -1, 1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, -1, 1, 1, -1, -1, -1, -1, 1, -1, -1, -1 - 1 - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] self.pn6 = pn6 = [ 1, 1, 1, 1, 1, 1, -1, 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, -1, 1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, -1, 1, 1, -1, -1, -1, -1, 1, -1, -1, -1 - 1 - 1 ] self.pn5 = pn5 = [ 1, -1, 1, -1, 1, 1, 1, -1, 1, 1, -1, -1, -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, -1, -1, -1, -1 ] self.pi = pi = np.pi self.pfb_filter = pfb_filter = firdes.root_raised_cosine( nfilts_pfb, nfilts_pfb * sps, 1, rolloff_, nfilts_pfb * 11 * sps + 1) self.mark_delay = mark_delay = mark_delays[sps] self.header_formatter_0 = header_formatter_0 = digital.packet_header_default( header_len, len_tag_key, num_tag_key, 1) self.header_formatter = header_formatter = digital.packet_header_default( header_len, len_tag_key, num_tag_key, 1) self.fc = fc = 900e6 self.const = const = digital.constellation_calcdist( digital.psk_2()[0], digital.psk_2()[1], 2, 1).base() self.buffer_size = buffer_size = 32768 self.bFilter = bFilter = 1 self.agc_rate = agc_rate = 1e-4 ################################################## # Blocks ################################################## self._snr_db_range = Range(0, 20, 0.5, snr_default, 200) self._snr_db_win = RangeWidget(self._snr_db_range, self.set_snr_db, 'SNR (dB)', "counter_slider", float) self.top_grid_layout.addWidget(self._snr_db_win) self._rolloff__range = Range(0.01, 0.99, 0.01, rolloff, 200) self._rolloff__win = RangeWidget(self._rolloff__range, self.set_rolloff_, 'Beta (Excess BW)', "counter_slider", float) self.top_grid_layout.addWidget(self._rolloff__win) _reset_ber_push_button = Qt.QPushButton('Reset BER') _reset_ber_push_button = Qt.QPushButton('Reset BER') self._reset_ber_choices = {'Pressed': 1, 'Released': 0} _reset_ber_push_button.pressed.connect( lambda: self.set_reset_ber(self._reset_ber_choices['Pressed'])) _reset_ber_push_button.released.connect( lambda: self.set_reset_ber(self._reset_ber_choices['Released'])) self.top_grid_layout.addWidget(_reset_ber_push_button) # Create the options list self._bFilter_options = ( 1, 2, ) # Create the labels list self._bFilter_labels = ( 'Raised Cosine (Mis-Matched)', 'Root Raised Cosine (Matched)', ) # Create the combo box self._bFilter_tool_bar = Qt.QToolBar(self) self._bFilter_tool_bar.addWidget(Qt.QLabel('TX Filter Select' + ": ")) self._bFilter_combo_box = Qt.QComboBox() self._bFilter_tool_bar.addWidget(self._bFilter_combo_box) for _label in self._bFilter_labels: self._bFilter_combo_box.addItem(_label) self._bFilter_callback = lambda i: Qt.QMetaObject.invokeMethod( self._bFilter_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._bFilter_options.index(i))) self._bFilter_callback(self.bFilter) self._bFilter_combo_box.currentIndexChanged.connect( lambda i: self.set_bFilter(self._bFilter_options[i])) # Create the radio buttons self.top_grid_layout.addWidget(self._bFilter_tool_bar) self._agc_rate_range = Range(1e-4, 1e-3, 1e-4, 1e-4, 200) self._agc_rate_win = RangeWidget(self._agc_rate_range, self.set_agc_rate, 'AGC Decay Rate', "counter_slider", float) self.top_grid_layout.addWidget(self._agc_rate_win) self.wes_packet_tx_0 = wes_packet_tx( cw_len=cw_len, payload_len=payload_len, samp_rate=samp_rate, ) self.wes_ber_0 = wes.ber(1, reset_ber) self.qtgui_number_sink_0_0 = qtgui.number_sink(gr.sizeof_float, 0, qtgui.NUM_GRAPH_NONE, 1) self.qtgui_number_sink_0_0.set_update_time(0.10) self.qtgui_number_sink_0_0.set_title("# of Errors") 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 range(1): self.qtgui_number_sink_0_0.set_min(i, -1) self.qtgui_number_sink_0_0.set_max(i, 1) self.qtgui_number_sink_0_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0_0.set_label(i, labels[i]) self.qtgui_number_sink_0_0.set_unit(i, units[i]) self.qtgui_number_sink_0_0.set_factor(i, factor[i]) self.qtgui_number_sink_0_0.enable_autoscale(False) self._qtgui_number_sink_0_0_win = sip.wrapinstance( self.qtgui_number_sink_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_number_sink_0_0_win) self.qtgui_number_sink_0 = qtgui.number_sink(gr.sizeof_float, 0, qtgui.NUM_GRAPH_HORIZ, 1) self.qtgui_number_sink_0.set_update_time(0.10) self.qtgui_number_sink_0.set_title("BER") 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 range(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_grid_layout.addWidget(self._qtgui_number_sink_0_win) self.qtgui_const_sink_x_0 = qtgui.const_sink_c( 1024, #size "", #name 2 #number of inputs ) self.qtgui_const_sink_x_0.set_update_time(0.10) self.qtgui_const_sink_x_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0.set_x_axis(-2, 2) 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(True) self.qtgui_const_sink_x_0.enable_axis_labels(True) 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, 1, 0, 0, 0, 0, 0, 0, 0, 0] markers = [0, -1, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in range(2): 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_grid_layout.addWidget(self._qtgui_const_sink_x_0_win) self.pulse_shape_hier_0 = pulse_shape_hier( bFilter=bFilter, rect_taps=(1, 1, 1, 1), roll_off=rolloff_, sps=sps, ) self.iio_pluto_source_0 = iio.pluto_source('', int(fc), int(samp_rate * 1e3), 20000000, buffer_size, True, True, True, 'manual', 18, '', True) self.iio_pluto_sink_0 = iio.pluto_sink('', int(fc), int(samp_rate * 1e3), 20000000, buffer_size, False, 10.0, '', True) self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf( sps, 2 * pi / 200, pfb_filter, nfilts_pfb, int(nfilts_pfb / 2), 0.5, 1) self.digital_packet_headerparser_b_0_0 = digital.packet_headerparser_b( header_formatter.formatter()) self.digital_header_payload_demux_0 = digital.header_payload_demux( header_len, 1, 0, "packet_length", "corr_est", False, gr.sizeof_gr_complex, "rx_time", 1, (), 0) self.digital_glfsr_source_x_0 = digital.glfsr_source_b( int(pn_order), True, 0, 1) self.digital_diff_decoder_bb_0_0 = digital.diff_decoder_bb(2) self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(2) self.digital_costas_loop_cc_0 = digital.costas_loop_cc( 2 * pi / 200, 2, False) self.digital_corr_est_cc_0 = digital.corr_est_cc( pn6_padded, 1, 64, 0.7, digital.THRESHOLD_ABSOLUTE) self.digital_constellation_decoder_cb_0_0_0_0_0 = digital.constellation_decoder_cb( const) self.digital_constellation_decoder_cb_0_0_0_0 = digital.constellation_decoder_cb( const) self.blocks_add_xx_0 = blocks.add_vcc(1) self.analog_noise_source_x_0 = analog.noise_source_c( analog.GR_GAUSSIAN, np.sqrt(2) * np.sqrt(0.5 / np.power(10, snr_db / 10)), 0) self.analog_agc_xx_0 = analog.agc_cc(agc_rate, 1.0, 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.msg_connect( (self.digital_packet_headerparser_b_0_0, 'header_data'), (self.digital_header_payload_demux_0, 'header_data')) self.connect((self.analog_agc_xx_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.digital_constellation_decoder_cb_0_0_0_0_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.qtgui_const_sink_x_0, 1)) self.connect((self.digital_constellation_decoder_cb_0_0_0_0, 0), (self.digital_diff_decoder_bb_0, 0)) self.connect((self.digital_constellation_decoder_cb_0_0_0_0_0, 0), (self.digital_diff_decoder_bb_0_0, 0)) self.connect((self.digital_corr_est_cc_0, 0), (self.digital_header_payload_demux_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.digital_diff_decoder_bb_0, 0), (self.digital_packet_headerparser_b_0_0, 0)) self.connect((self.digital_diff_decoder_bb_0_0, 0), (self.wes_ber_0, 0)) self.connect((self.digital_glfsr_source_x_0, 0), (self.wes_ber_0, 1)) self.connect((self.digital_glfsr_source_x_0, 0), (self.wes_packet_tx_0, 0)) self.connect((self.digital_header_payload_demux_0, 1), (self.blocks_add_xx_0, 1)) self.connect((self.digital_header_payload_demux_0, 0), (self.digital_constellation_decoder_cb_0_0_0_0, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_corr_est_cc_0, 0)) self.connect((self.iio_pluto_source_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.pulse_shape_hier_0, 0), (self.iio_pluto_sink_0, 0)) self.connect((self.wes_ber_0, 0), (self.qtgui_number_sink_0, 0)) self.connect((self.wes_ber_0, 1), (self.qtgui_number_sink_0_0, 0)) self.connect((self.wes_packet_tx_0, 0), (self.pulse_shape_hier_0, 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 = 48000 self.seed = seed = 128 self.m_rate = m_rate = 0.8 self.if_rate = if_rate = samp_rate * 40 self.gauss = gauss = 0 self.fc = fc = 511e3 self.dpp = dpp = 100.0 ################################################## # Blocks ################################################## self.wxgui_fftsink2_0_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_0.win) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=if_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) self.rational_resampler_xxx_0_1 = filter.rational_resampler_fff( interpolation=3, decimation=1, taps=None, fractional_bw=None, ) self.rational_resampler_xxx_0_0 = filter.rational_resampler_fff( interpolation=40, decimation=1, taps=None, fractional_bw=None, ) self.low_pass_filter_0 = filter.interp_fir_filter_fff( 1, firdes.low_pass(1, samp_rate, 7500, 100, firdes.WIN_HAMMING, 6.76)) self.hilbert_fc_0 = filter.hilbert_fc(301, firdes.WIN_HAMMING, 6.76) self.channels_fading_model_0 = channels.fading_model( 8, dpp / if_rate, False, 2, 256) self.blocks_wavfile_source_0 = blocks.wavfile_source( '/media/akio/ssd1/fading_generator/5-263831-B-6.wav', True) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1, samp_rate, True) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_float * 1) self.blocks_multiply_xx_0 = blocks.multiply_vff(1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff( (m_rate, )) self.blocks_add_const_vxx_0 = blocks.add_const_vff((1, )) self.band_pass_filter_0 = filter.fir_filter_ccf( 1, firdes.band_pass(4, if_rate, fc - 8e3, fc + 8e3, 100, firdes.WIN_HAMMING, 6.76)) self.analog_sig_source_x_0_0 = analog.sig_source_f( if_rate, analog.GR_COS_WAVE, fc, 1, 0) self.analog_am_demod_cf_0 = analog.am_demod_cf( channel_rate=fc, audio_decim=40, audio_pass=7500, audio_stop=10e3, ) self.analog_agc_xx_0 = analog.agc_cc(1e-4, 1.0, 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0, 0), (self.analog_am_demod_cf_0, 0)) self.connect((self.analog_am_demod_cf_0, 0), (self.blocks_null_sink_0, 0)) self.connect((self.analog_am_demod_cf_0, 0), (self.wxgui_fftsink2_0_0, 0)) self.connect((self.analog_sig_source_x_0_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.band_pass_filter_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.rational_resampler_xxx_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.hilbert_fc_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_wavfile_source_0, 0), (self.rational_resampler_xxx_0_1, 0)) self.connect((self.channels_fading_model_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.hilbert_fc_0, 0), (self.channels_fading_model_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.rational_resampler_xxx_0_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.rational_resampler_xxx_0_1, 0), (self.low_pass_filter_0, 0))
def __init__(self): gr.top_block.__init__(self, "M2 Lrpt Doppler Corr") Qt.QWidget.__init__(self) self.setWindowTitle("M2 Lrpt Doppler Corr") 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", "m2_lrpt_doppler_corr") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.sps = sps = 4 self.nfilt = nfilt = 32 self.taps = taps = firdes.root_raised_cosine(nfilt,nfilt*sps,1.0,0.35,11*sps*nfilt) self.samp_rate = samp_rate = 300e3 self.cma = cma = -20 self.baudrate = baudrate = 72e3 ################################################## # Blocks ################################################## self._cma_range = Range(-40, -10, 1, -20, 200) self._cma_win = RangeWidget(self._cma_range, self.set_cma, "cma", "counter_slider", float) self.top_layout.addWidget(self._cma_win) self.root_raised_cosine_filter_0 = filter.fir_filter_ccf(1, firdes.root_raised_cosine( 1, sps*1.0, 1.0, 0.7, 32*sps)) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=int(baudrate*sps), decimation=int(samp_rate), taps=None, fractional_bw=None, ) self.qtgui_time_sink_x_0 = qtgui.time_sink_c( 4096, #size baudrate, #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(-2, 2) 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(True) self.qtgui_time_sink_x_0.enable_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(False) if not False: 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 = [0, 0, 1, 1, 1, 1, 1, 1, 1, 1] markers = [2, 2, -1, -1, -1, -1, -1, -1, -1, -1] alphas = [0.5, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(2*1): if len(labels[i]) == 0: if(i % 2 == 0): self.qtgui_time_sink_x_0.set_line_label(i, "Re{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_0.set_line_label(i, "Im{{Data {0}}}".format(i/2)) 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, 1,1,1,1) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 4096, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc baudrate*4, #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(-110, -20) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') 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.1) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) if not False: self.qtgui_freq_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue"] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 0,0,1,2) self.qtgui_const_sink_x_0 = qtgui.const_sink_c( 2048, #size "", #name 1 #number of inputs ) self.qtgui_const_sink_x_0.set_update_time(0.10) self.qtgui_const_sink_x_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0.set_x_axis(-2, 2) 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 False: 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 = [2, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [0.5, 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_grid_layout.addWidget(self._qtgui_const_sink_x_0_win, 1,0,1,1) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(1, (1, ), 7.5e3, samp_rate) self.digital_costas_loop_cc_0 = digital.costas_loop_cc(6.28/100, 4, False) self.digital_cma_equalizer_cc_0 = digital.cma_equalizer_cc(16, 1.0, pow(10.0,cma/10.0), 1) self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_cc(sps*(1+0.0), 0.25*0.002*0.002, 0.5, 0.002, 0.005) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True) self.blocks_file_source_0 = blocks.file_source(gr.sizeof_gr_complex*1, '/home/handiko/gqrx_20180406_133933_137892600_300000_fc.raw', True) self.analog_agc_xx_0 = analog.agc_cc(1e-4, 1.0, 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0, 0), (self.root_raised_cosine_filter_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.digital_cma_equalizer_cc_0, 0)) self.connect((self.digital_cma_equalizer_cc_0, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.root_raised_cosine_filter_0, 0), (self.digital_clock_recovery_mm_xx_0, 0))
def test_001(self): ''' Test the complex AGC loop (single rate input) ''' tb = self.tb expected_result = ( (100.000244140625 + 7.2191943445432116e-07j), (72.892257690429688 + 52.959323883056641j), (25.089065551757812 + 77.216217041015625j), (-22.611061096191406 + 69.589706420898438j), (-53.357715606689453 + 38.766635894775391j), (-59.458671569824219 + 3.4792964243024471e-07j), (-43.373462677001953 - 31.512666702270508j), (-14.94139289855957 - 45.984889984130859j), (13.478158950805664 - 41.48150634765625j), (31.838506698608398 - 23.132022857666016j), (35.519271850585938 - 3.1176801940091536e-07j), (25.942903518676758 + 18.848621368408203j), (8.9492912292480469 + 27.5430908203125j), (-8.0852642059326172 + 24.883890151977539j), (-19.131628036499023 + 13.899936676025391j), (-21.383295059204102 + 3.1281737733479531e-07j), (-15.650330543518066 - 11.370632171630859j), (-5.4110145568847656 - 16.65339469909668j), (4.9008159637451172 - 15.083160400390625j), (11.628337860107422 - 8.4484796524047852j), (13.036135673522949 - 2.288476110834381e-07j), (9.5726661682128906 + 6.954948902130127j), (3.3216962814331055 + 10.223132133483887j), (-3.0204284191131592 + 9.2959251403808594j), (-7.1977195739746094 + 5.2294478416442871j), (-8.1072216033935547 + 1.8976157889483147e-07j), (-5.9838657379150391 - 4.3475332260131836j), (-2.0879747867584229 - 6.4261269569396973j), (1.9100792407989502 - 5.8786196708679199j), (4.5814824104309082 - 3.3286411762237549j), (5.1967458724975586 - 1.3684227440080576e-07j), (3.8647139072418213 + 2.8078789710998535j), (1.3594740629196167 + 4.1840314865112305j), (-1.2544282674789429 + 3.8607344627380371j), (-3.0366206169128418 + 2.2062335014343262j), (-3.4781389236450195 + 1.1194014604143376e-07j), (-2.6133756637573242 - 1.8987287282943726j), (-0.9293016791343689 - 2.8600969314575195j), (0.86727333068847656 - 2.6691930294036865j), (2.1243946552276611 - 1.5434627532958984j), (2.4633183479309082 - 8.6486437567145913e-08j), (1.8744727373123169 + 1.3618841171264648j), (0.67528903484344482 + 2.0783262252807617j), (-0.63866174221038818 + 1.965599536895752j), (-1.5857341289520264 + 1.152103066444397j), (-1.8640764951705933 + 7.6355092915036948e-08j), (-1.4381576776504517 - 1.0448826551437378j), (-0.52529704570770264 - 1.6166983842849731j), (0.50366902351379395 - 1.5501341819763184j), (1.26766037940979 - 0.92100900411605835j)) sampling_freq = 100 src1 = analog.sig_source_c(sampling_freq, analog.GR_SIN_WAVE, sampling_freq * 0.10, 100.0) dst1 = blocks.vector_sink_c() head = blocks.head(gr.sizeof_gr_complex, int(5 * sampling_freq * 0.10)) agc = analog.agc_cc(1e-3, 1, 1) tb.connect(src1, head) tb.connect(head, agc) tb.connect(agc, dst1) tb.run() dst_data = dst1.data() self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 4)
def __init__(self): gr.top_block.__init__(self, "Psk31 Rx") Qt.QWidget.__init__(self) self.setWindowTitle("Psk31 Rx") 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", "psk31_rx") 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.center_freq = center_freq = 441800000 self.samp_rate = samp_rate = 960000 self.psk_offset = psk_offset = 1000 self.psk_center = psk_center = center_freq + 141000 self.int_rate = int_rate = 48000 self.gain = gain = 10 self.audio_rate = audio_rate = 8000 ################################################## # Blocks ################################################## self._psk_offset_range = Range(0, 3000, 10, 1000, 200) self._psk_offset_win = RangeWidget(self._psk_offset_range, self.set_psk_offset, 'PSK offset', "counter_slider", float) self.top_grid_layout.addWidget(self._psk_offset_win) self._psk_center_range = Range(center_freq + 110000, center_freq + 150000, 1000, center_freq + 141000, 200) self._psk_center_win = RangeWidget(self._psk_center_range, self.set_psk_center, 'Tuning', "counter_slider", float) self.top_grid_layout.addWidget(self._psk_center_win) self._gain_range = Range(0, 50, 0.4, 10, 200) self._gain_win = RangeWidget(self._gain_range, self.set_gain, 'RX gain', "counter_slider", float) self.top_grid_layout.addWidget(self._gain_win) self.qtgui_waterfall_sink_x_2 = qtgui.waterfall_sink_f( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate / 120, #bw "", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_2.set_update_time(0.10) self.qtgui_waterfall_sink_x_2.enable_grid(False) self.qtgui_waterfall_sink_x_2.enable_axis_labels(True) self.qtgui_waterfall_sink_x_2.set_plot_pos_half(not False) 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 range(1): if len(labels[i]) == 0: self.qtgui_waterfall_sink_x_2.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_2.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_2.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_2.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_2.set_intensity_range(-140, 10) self._qtgui_waterfall_sink_x_2_win = sip.wrapinstance(self.qtgui_waterfall_sink_x_2.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_2_win) self.qtgui_waterfall_sink_x_1 = qtgui.waterfall_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate / 20, #bw "", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_1.set_update_time(0.10) self.qtgui_waterfall_sink_x_1.enable_grid(False) self.qtgui_waterfall_sink_x_1.enable_axis_labels(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 range(1): if len(labels[i]) == 0: self.qtgui_waterfall_sink_x_1.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_1.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_1.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_1.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_1.set_intensity_range(-140, 10) self._qtgui_waterfall_sink_x_1_win = sip.wrapinstance(self.qtgui_waterfall_sink_x_1.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_1_win) self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype center_freq, #fc samp_rate, #bw "", #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) self.qtgui_waterfall_sink_x_0.enable_axis_labels(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 range(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) self.qtgui_time_sink_x_1 = qtgui.time_sink_c( 1024, #size samp_rate / 120, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_1.set_update_time(0.10) self.qtgui_time_sink_x_1.set_y_axis(-1, 1) self.qtgui_time_sink_x_1.set_y_label('Amplitude', "") self.qtgui_time_sink_x_1.enable_tags(True) self.qtgui_time_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_1.enable_autoscale(False) self.qtgui_time_sink_x_1.enable_grid(False) self.qtgui_time_sink_x_1.enable_axis_labels(True) self.qtgui_time_sink_x_1.enable_control_panel(False) self.qtgui_time_sink_x_1.enable_stem_plot(False) labels = ['Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5', 'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10'] 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] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] for i in range(2): if len(labels[i]) == 0: if (i % 2 == 0): self.qtgui_time_sink_x_1.set_line_label(i, "Re{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_1.set_line_label(i, "Im{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_1.set_line_label(i, labels[i]) self.qtgui_time_sink_x_1.set_line_width(i, widths[i]) self.qtgui_time_sink_x_1.set_line_color(i, colors[i]) self.qtgui_time_sink_x_1.set_line_style(i, styles[i]) self.qtgui_time_sink_x_1.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_1.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_1_win = sip.wrapinstance(self.qtgui_time_sink_x_1.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_sink_x_1_win) self.qtgui_time_sink_x_0 = qtgui.time_sink_c( 1024, #size samp_rate / 120 / 16 / 16, #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(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_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(False) self.qtgui_time_sink_x_0.enable_stem_plot(False) labels = ['Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5', 'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10'] 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] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] for i in range(2): if len(labels[i]) == 0: if (i % 2 == 0): self.qtgui_time_sink_x_0.set_line_label(i, "Re{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_0.set_line_label(i, "Im{{Data {0}}}".format(i/2)) 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) self.qtgui_number_sink_0 = qtgui.number_sink( gr.sizeof_float, 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 range(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_grid_layout.addWidget(self._qtgui_number_sink_0_win) self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + '' ) self.osmosdr_source_0.set_time_unknown_pps(osmosdr.time_spec_t()) 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_gain(gain, 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.ham_varicode_rx_0 = ham.varicode_rx() self.freq_xlating_fir_filter_xxx_1 = filter.freq_xlating_fir_filter_ccc(16, firdes.low_pass(10, audio_rate, 120, 40, firdes.WIN_HAMMING, 6.76), psk_offset, audio_rate) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(samp_rate // int_rate, firdes.low_pass(1, samp_rate, 12000, 12000, firdes.WIN_HAMMING, 6.76), round(psk_center - center_freq,-3), samp_rate) self.digital_diff_phasor_cc_0 = digital.diff_phasor_cc() self.digital_costas_loop_cc_0 = digital.costas_loop_cc(5 * math.pi /100.0, 2, False) self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_cc(16, 0.25*0.175*0.175, 0.5, 0.175, 0.005) self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb() self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, 'psk31.txt', False) self.blocks_file_sink_0.set_unbuffered(True) self.blocks_complex_to_real_1 = blocks.complex_to_real(1) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) self.band_pass_filter_0 = filter.fir_filter_ccc( int_rate // audio_rate, firdes.complex_band_pass( 1, int_rate, 200, 2800, 200, firdes.WIN_HAMMING, 6.76)) self.audio_sink_0 = audio.sink(audio_rate, 'plughw:0,0', True) self.analog_agc_xx_0 = analog.agc_cc(1e-3, 0.1, 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.freq_xlating_fir_filter_xxx_1, 0)) self.connect((self.band_pass_filter_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.blocks_complex_to_real_0, 0), (self.audio_sink_0, 0)) self.connect((self.blocks_complex_to_real_0, 0), (self.qtgui_waterfall_sink_x_2, 0)) self.connect((self.blocks_complex_to_real_1, 0), (self.digital_binary_slicer_fb_0, 0)) self.connect((self.digital_binary_slicer_fb_0, 0), (self.ham_varicode_rx_0, 0)) self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.digital_diff_phasor_cc_0, 0)) self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.digital_clock_recovery_mm_xx_0, 0)) self.connect((self.digital_costas_loop_cc_0, 1), (self.qtgui_number_sink_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.qtgui_time_sink_x_1, 0)) self.connect((self.digital_diff_phasor_cc_0, 0), (self.blocks_complex_to_real_1, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.qtgui_waterfall_sink_x_1, 0)) self.connect((self.freq_xlating_fir_filter_xxx_1, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.ham_varicode_rx_0, 0), (self.blocks_file_sink_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_waterfall_sink_x_0, 0))
def __init__(self): gr.top_block.__init__(self, "Stanley Rx") Qt.QWidget.__init__(self) self.setWindowTitle("Stanley Rx") 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", "stanley_rx") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.output_rate = output_rate = int(15e3) self.hackrf_rate = hackrf_rate = int(2e6) self.frequency = frequency = 433.858e6 self.dc_offset = dc_offset = 200e3 ################################################## # Blocks ################################################## self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=output_rate, decimation=hackrf_rate, taps=None, fractional_bw=None, ) self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_f( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc output_rate, #bw "", #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 not True: self.qtgui_waterfall_sink_x_0.disable_legend() if float == type(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_layout.addWidget(self._qtgui_waterfall_sink_x_0_win) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 1024, #size output_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.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + "") self.osmosdr_source_0.set_sample_rate(hackrf_rate) self.osmosdr_source_0.set_center_freq(frequency + dc_offset, 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(True, 0) self.osmosdr_source_0.set_gain(10, 0) self.osmosdr_source_0.set_if_gain(20, 0) self.osmosdr_source_0.set_bb_gain(20, 0) self.osmosdr_source_0.set_antenna("", 0) self.osmosdr_source_0.set_bandwidth(0, 0) self.freq_xlating_fft_filter_ccc_0 = filter.freq_xlating_fft_filter_ccc( 1, (1, ), 0 - dc_offset, hackrf_rate) self.freq_xlating_fft_filter_ccc_0.set_nthreads(1) self.freq_xlating_fft_filter_ccc_0.declare_sample_delay(0) self.blocks_wavfile_sink_0 = blocks.wavfile_sink( "/Users/adamcoddington/Desktop/output/1_offw.wav", 1, output_rate, 8) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.analog_agc_xx_0 = analog.agc_cc(1e-4, 1.0, 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_wavfile_sink_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.qtgui_waterfall_sink_x_0, 0)) self.connect((self.freq_xlating_fft_filter_ccc_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fft_filter_ccc_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.analog_agc_xx_0, 0))
def test_001(self): ''' Test the complex AGC loop (single rate input) ''' tb = self.tb expected_result = ( (100 + 0j), (72.89209747314453 + 52.9592170715332j), (25.089027404785156 + 77.2160873413086j), (-22.611034393310547 + 69.58960723876953j), (-53.35764694213867 + 38.766597747802734j), (-59.4586067199707 - 2.7399494229030097e-06j), (-43.3734245300293 - 31.51263999938965j), (-14.941386222839355 - 45.984867095947266j), (13.478157997131348 - 41.48149490356445j), (31.838510513305664 - 23.13202476501465j), (35.51927947998047 + 3.3255341804760974e-06j), (25.94291114807129 + 18.848634719848633j), (8.949296951293945 + 27.543113708496094j), (-8.085277557373047 + 24.883914947509766j), (-19.13165283203125 + 13.899954795837402j), (-21.383323669433594 - 2.987417019539862e-06j), (-15.65035343170166 - 11.370650291442871j), (-5.4110236167907715 - 16.653427124023438j), (4.900828838348389 - 15.083191871643066j), (11.62836742401123 - 8.448498725891113j), (13.036169052124023 + 2.4410530841123546e-06j), (9.572690963745117 + 6.954970359802246j), (3.3217051029205322 + 10.223164558410645j), (-3.0204410552978516 + 9.295955657958984j), (-7.197745323181152 + 5.229465007781982j), (-8.107251167297363 - 1.8916969111160142e-06j), (-5.983887195587158 - 4.347550392150879j), (-2.087981939315796 - 6.426152229309082j), (1.9100888967514038 - 5.87864351272583j), (4.581503391265869 - 3.3286550045013428j), (5.196768760681152 + 1.4596606661143596e-06j), (3.864729881286621 + 2.807892322540283j), (1.359479308128357 + 4.184051513671875j), (-1.2544355392456055 + 3.8607518672943115j), (-3.036635398864746 + 2.2062432765960693j), (-3.4781548976898193 - 1.137218077928992e-06j), (-2.613386869430542 - 1.8987380266189575j), (-0.9293051958084106 - 2.8601105213165283j), (0.8672783374786377 - 2.6692051887512207j), (2.1244049072265625 - 1.5434693098068237j), (2.463329315185547 + 9.225283861269418e-07j), (1.8744803667068481 + 1.3618910312652588j), (0.6752913594245911 + 2.078335762023926j), (-0.6386655569076538 + 1.9656078815460205j), (-1.5857415199279785 + 1.1521075963974j), (-1.864084243774414 - 7.840082503207668e-07j), (-1.438162922859192 - 1.0448874235153198j), (-0.5252984762191772 - 1.6167048215866089j), (0.5036717653274536 - 1.5501397848129272j), (1.2676655054092407 - 0.9210119843482971j)) sampling_freq = 100 src1 = analog.sig_source_c(sampling_freq, analog.GR_SIN_WAVE, sampling_freq * 0.10, 100.0) dst1 = blocks.vector_sink_c() head = blocks.head(gr.sizeof_gr_complex, int(5 * sampling_freq * 0.10)) agc = analog.agc_cc(1e-3, 1, 1) tb.connect(src1, head) tb.connect(head, agc) tb.connect(agc, dst1) tb.run() dst_data = dst1.data() self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 4)
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) parser = OptionParser(option_class=eng_option) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option( "-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate (bandwidth) [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=1008.0e3, help="set frequency to FREQ", metavar="FREQ") parser.add_option( "-I", "--use-if-freq", action="store_true", default=False, help= "use intermediate freq (compensates DC problems in quadrature boards)" ) parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is maximum)") parser.add_option("-V", "--volume", type="eng_float", default=None, help="set volume (default is midpoint)") parser.add_option( "-O", "--audio-output", type="string", default="default", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.frame = frame self.panel = panel self.use_IF = options.use_if_freq if self.use_IF: self.IF_freq = 64000.0 else: self.IF_freq = 0.0 self.vol = 0 self.state = "FREQ" self.freq = 0 # build graph self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if (options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if (options.antenna): self.u.set_antenna(options.antenna, 0) usrp_rate = 256e3 demod_rate = 64e3 audio_rate = 32e3 chanfilt_decim = int(usrp_rate // demod_rate) audio_decim = int(demod_rate // audio_rate) self.u.set_samp_rate(usrp_rate) dev_rate = self.u.get_samp_rate() # Resample signal to exactly self.usrp_rate # FIXME: make one of the follow-on filters an arb resampler rrate = usrp_rate / dev_rate self.resamp = filter.pfb.arb_resampler_ccf(rrate) chan_filt_coeffs = filter.firdes.low_pass_2( 1, # gain usrp_rate, # sampling rate 8e3, # passband cutoff 4e3, # transition bw 60) # stopband attenuation if self.use_IF: # Turn If to baseband and filter. self.chan_filt = filter.freq_xlating_fir_filter_ccf( chanfilt_decim, chan_filt_coeffs, self.IF_freq, usrp_rate) else: self.chan_filt = filter.fir_filter_ccf(chanfilt_decim, chan_filt_coeffs) self.agc = analog.agc_cc(0.1, 1, 1, 100000) self.am_demod = blocks.complex_to_mag() self.volume_control = blocks.multiply_const_ff(self.vol) audio_filt_coeffs = filter.firdes.low_pass_2( 1, # gain demod_rate, # sampling rate 8e3, # passband cutoff 2e3, # transition bw 60) # stopband attenuation self.audio_filt = filter.fir_filter_fff(audio_decim, audio_filt_coeffs) # sound card as final sink self.audio_sink = audio.sink(int(audio_rate), options.audio_output, False) # ok_to_block # now wire it all together self.connect(self.u, self.resamp, self.chan_filt, self.agc, self.am_demod, self.audio_filt, self.volume_control, self.audio_sink) self._build_gui(vbox, usrp_rate, demod_rate, audio_rate) if options.gain is None: g = self.u.get_gain_range() # if no gain was specified, use the mid gain options.gain = (g.start() + g.stop()) / 2.0 if options.volume is None: v = self.volume_range() options.volume = float(v[0] * 3 + v[1]) / 4.0 if abs(options.freq) < 1e3: options.freq *= 1e3 # set initial values self.set_gain(options.gain) self.set_vol(options.volume) if not (self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def __init__(self): gr.top_block.__init__(self, "Lab 1") Qt.QWidget.__init__(self) self.setWindowTitle("Lab 1") 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", "lab1") 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.freqc = freqc = 900 self.sps = sps = 8 self.samp_rate = samp_rate = 1000 self.phase = phase = 0 self.mod_M = mod_M = 0 self.gain_ = gain_ = 0.5 self.freqc_ = freqc_ = freqc self.fps = fps = 30 self.foffset = foffset = 0 self.bw = bw = 1 self.buff_size = buff_size = 32768 self.analog_gain = analog_gain = 32 ################################################## # Blocks ################################################## self.tab0 = Qt.QTabWidget() self.tab0_widget_0 = Qt.QWidget() self.tab0_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab0_widget_0) self.tab0_grid_layout_0 = Qt.QGridLayout() self.tab0_layout_0.addLayout(self.tab0_grid_layout_0) self.tab0.addTab(self.tab0_widget_0, 'Spectrum/Constellation') self.tab0_widget_1 = Qt.QWidget() self.tab0_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.tab0_widget_1) self.tab0_grid_layout_1 = Qt.QGridLayout() self.tab0_layout_1.addLayout(self.tab0_grid_layout_1) self.tab0.addTab(self.tab0_widget_1, 'Time-Series') self.top_grid_layout.addWidget(self.tab0, 0, 0, 10, 2) for r in range(0, 10): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 2): self.top_grid_layout.setColumnStretch(c, 1) self._phase_range = Range(-180*2, 180*2, 0.1, 0, 200) self._phase_win = RangeWidget(self._phase_range, self.set_phase, 'Phase Offset (Degrees)', "counter_slider", float) self.top_grid_layout.addWidget(self._phase_win, 11, 1, 1, 1) for r in range(11, 12): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) # Create the options list self._mod_M_options = (0, 1, ) # Create the labels list self._mod_M_labels = ('BPSK', 'QPSK', ) # Create the combo box # Create the radio buttons self._mod_M_group_box = Qt.QGroupBox('Modulation Select' + ": ") self._mod_M_box = Qt.QHBoxLayout() class variable_chooser_button_group(Qt.QButtonGroup): def __init__(self, parent=None): Qt.QButtonGroup.__init__(self, parent) @pyqtSlot(int) def updateButtonChecked(self, button_id): self.button(button_id).setChecked(True) self._mod_M_button_group = variable_chooser_button_group() self._mod_M_group_box.setLayout(self._mod_M_box) for i, _label in enumerate(self._mod_M_labels): radio_button = Qt.QRadioButton(_label) self._mod_M_box.addWidget(radio_button) self._mod_M_button_group.addButton(radio_button, i) self._mod_M_callback = lambda i: Qt.QMetaObject.invokeMethod(self._mod_M_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._mod_M_options.index(i))) self._mod_M_callback(self.mod_M) self._mod_M_button_group.buttonClicked[int].connect( lambda i: self.set_mod_M(self._mod_M_options[i])) self.top_grid_layout.addWidget(self._mod_M_group_box, 12, 1, 1, 1) for r in range(12, 13): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self._gain__range = Range(0.1, 1, 0.01, 0.5, 200) self._gain__win = RangeWidget(self._gain__range, self.set_gain_, 'Gain (Amp)', "counter_slider", float) self.top_grid_layout.addWidget(self._gain__win, 10, 1, 1, 1) for r in range(10, 11): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self._freqc__range = Range(70, 6000, .01, freqc, 200) self._freqc__win = RangeWidget(self._freqc__range, self.set_freqc_, 'Carrier (MHz)', "counter_slider", float) self.top_grid_layout.addWidget(self._freqc__win, 10, 0, 1, 1) for r in range(10, 11): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self._foffset_range = Range(-10, 10, 1, 0, 10) self._foffset_win = RangeWidget(self._foffset_range, self.set_foffset, 'Frequency Offset (Hz)', "counter_slider", float) self.top_grid_layout.addWidget(self._foffset_win, 12, 0, 1, 1) for r in range(12, 13): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self._analog_gain_range = Range(0, 64, 1, 32, 200) self._analog_gain_win = RangeWidget(self._analog_gain_range, self.set_analog_gain, 'Gain (Analog)', "counter_slider", float) self.top_grid_layout.addWidget(self._analog_gain_win, 11, 0, 1, 1) for r in range(11, 12): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_time_sink_x_0 = qtgui.time_sink_c( 131072, #size samp_rate*1000, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(1/fps) 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(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_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(True) self.qtgui_time_sink_x_0.enable_stem_plot(False) labels = ['Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5', 'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10'] 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] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] for i in range(2): if len(labels[i]) == 0: if (i % 2 == 0): self.qtgui_time_sink_x_0.set_line_label(i, "Re{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_0.set_line_label(i, "Im{{Data {0}}}".format(i/2)) 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.tab0_grid_layout_1.addWidget(self._qtgui_time_sink_x_0_win, 0, 0, 10, 2) for r in range(0, 10): self.tab0_grid_layout_1.setRowStretch(r, 1) for c in range(0, 2): self.tab0_grid_layout_1.setColumnStretch(c, 1) self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate*1e3, #bw "", #name 1 ) self.qtgui_freq_sink_x_0_0.set_update_time(1/fps) self.qtgui_freq_sink_x_0_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0_0.set_y_label('Relative Gain', 'dB') 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(0.1) self.qtgui_freq_sink_x_0_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0_0.enable_control_panel(False) labels = ['Magnitude', '', '', '', '', '', '', '', '', ''] 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 range(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.tab0_grid_layout_0.addWidget(self._qtgui_freq_sink_x_0_0_win, 0, 0, 5, 1) for r in range(0, 5): self.tab0_grid_layout_0.setRowStretch(r, 1) for c in range(0, 1): self.tab0_grid_layout_0.setColumnStretch(c, 1) self.qtgui_freq_sink_x_0_0.set_processor_affinity([0]) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_f( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate*1e3, #bw "", #name 2 ) self.qtgui_freq_sink_x_0.set_update_time(1/fps) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') 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(1.0) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ['In-Phase', 'Quadrature', '', '', '', '', '', '', '', ''] 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 range(2): 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.tab0_grid_layout_0.addWidget(self._qtgui_freq_sink_x_0_win, 5, 0, 5, 1) for r in range(5, 10): self.tab0_grid_layout_0.setRowStretch(r, 1) for c in range(0, 1): self.tab0_grid_layout_0.setColumnStretch(c, 1) self.qtgui_freq_sink_x_0.set_processor_affinity([0]) self.qtgui_const_sink_x_0 = qtgui.const_sink_c( 1024, #size "", #name 2 #number of inputs ) self.qtgui_const_sink_x_0.set_update_time(1/fps) self.qtgui_const_sink_x_0.set_y_axis(-3, 3) self.qtgui_const_sink_x_0.set_x_axis(-3, 3) 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(True) self.qtgui_const_sink_x_0.enable_axis_labels(True) 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, 1, 0, 0, 0, 0, 0, 0, 0, 0] markers = [0, -1, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in range(2): 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.tab0_grid_layout_0.addWidget(self._qtgui_const_sink_x_0_win, 0, 1, 10, 1) for r in range(0, 10): self.tab0_grid_layout_0.setRowStretch(r, 1) for c in range(1, 2): self.tab0_grid_layout_0.setColumnStretch(c, 1) self.qtgui_const_sink_x_0.set_processor_affinity([0]) self.iio_pluto_source_0 = iio.pluto_source('', int(freqc_*1e6), int(samp_rate*1000), 20000000, buff_size, True, True, True, 'manual', analog_gain, '', True) self.iio_pluto_sink_0 = iio.pluto_sink('', int(freqc_*1e6)+foffset, int(samp_rate*1000), 20000000, buff_size, False, 10.0, '', True) self.digital_psk_mod_0_0 = digital.psk.psk_mod( constellation_points=4, mod_code="gray", differential=True, samples_per_symbol=sps, excess_bw=1, verbose=False, log=False) self.blocks_multiply_const_vxx_1 = blocks.multiply_const_cc(np.exp(1j*2*pi*phase/360)) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_ff(mod_M) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_cc(gain_ * np.exp(1j * pi / 4)) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_complex_to_real_1 = blocks.complex_to_real(1) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) self.blocks_complex_to_imag_1 = blocks.complex_to_imag(1) self.blocks_complex_to_imag_0 = blocks.complex_to_imag(1) self.analog_random_source_x_0 = blocks.vector_source_b(list(map(int, numpy.random.randint(0, 4, 8192))), True) self.analog_agc_xx_0 = analog.agc_cc(1e-4, ( 1.0 + mod_M), 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0, 0), (self.blocks_complex_to_imag_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.qtgui_const_sink_x_0, 1)) self.connect((self.analog_agc_xx_0, 0), (self.qtgui_freq_sink_x_0_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.analog_random_source_x_0, 0), (self.digital_psk_mod_0_0, 0)) self.connect((self.blocks_complex_to_imag_0, 0), (self.qtgui_freq_sink_x_0, 1)) self.connect((self.blocks_complex_to_imag_1, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_complex_to_real_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.blocks_complex_to_real_1, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.iio_pluto_sink_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_complex_to_imag_1, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_complex_to_real_1, 0)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.analog_agc_xx_0, 0)) self.connect((self.digital_psk_mod_0_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.iio_pluto_source_0, 0), (self.blocks_multiply_const_vxx_1, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="AM Receiver") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 64e6 / 256 self.offset_fine = offset_fine = 0 self.offset_coarse = offset_coarse = 0 self.freq = freq = 15000000 self.LO = LO = 0 self.xlate_filter_taps = xlate_filter_taps = firdes.low_pass( 1, samp_rate, 125000, 25000, firdes.WIN_HAMMING, 6.76) self.width = width = 10000 self.trans = trans = 1500 self.rx_freq = rx_freq = LO + freq + (offset_coarse + offset_fine) self.rf_gain = rf_gain = 10 self.lo_freq = lo_freq = LO self.display_selector = display_selector = 0 self.af_gain = af_gain = 0.200 ################################################## # Blocks ################################################## _width_sizer = wx.BoxSizer(wx.VERTICAL) self._width_text_box = forms.text_box( parent=self.GetWin(), sizer=_width_sizer, value=self.width, callback=self.set_width, label="Filter", converter=forms.float_converter(), proportion=0, ) self._width_slider = forms.slider( parent=self.GetWin(), sizer=_width_sizer, value=self.width, callback=self.set_width, minimum=2000, maximum=40000, num_steps=760, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_width_sizer, 7, 0, 1, 1) _trans_sizer = wx.BoxSizer(wx.VERTICAL) self._trans_text_box = forms.text_box( parent=self.GetWin(), sizer=_trans_sizer, value=self.trans, callback=self.set_trans, label="Trans", converter=forms.float_converter(), proportion=0, ) self._trans_slider = forms.slider( parent=self.GetWin(), sizer=_trans_sizer, value=self.trans, callback=self.set_trans, minimum=500, maximum=5000, num_steps=900, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_trans_sizer, 8, 0, 1, 1) self._rx_freq_static_text = forms.static_text( parent=self.GetWin(), value=self.rx_freq, callback=self.set_rx_freq, label="Receive", converter=forms.float_converter(), ) self.GridAdd(self._rx_freq_static_text, 5, 3, 1, 1) _rf_gain_sizer = wx.BoxSizer(wx.VERTICAL) self._rf_gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_rf_gain_sizer, value=self.rf_gain, callback=self.set_rf_gain, label="RF", converter=forms.float_converter(), proportion=0, ) self._rf_gain_slider = forms.slider( parent=self.GetWin(), sizer=_rf_gain_sizer, value=self.rf_gain, callback=self.set_rf_gain, minimum=0, maximum=50, num_steps=50, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_rf_gain_sizer, 7, 1, 1, 1) self._display_selector_chooser = forms.drop_down( parent=self.GetWin(), value=self.display_selector, callback=self.set_display_selector, label="Spectrum", choices=[0, 1], labels=['Baseband', 'USRP'], ) self.GridAdd(self._display_selector_chooser, 5, 0, 1, 1) _af_gain_sizer = wx.BoxSizer(wx.VERTICAL) self._af_gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_af_gain_sizer, value=self.af_gain, callback=self.set_af_gain, label="VOL", converter=forms.float_converter(), proportion=0, ) self._af_gain_slider = forms.slider( parent=self.GetWin(), sizer=_af_gain_sizer, value=self.af_gain, callback=self.set_af_gain, minimum=0, maximum=1, num_steps=500, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_af_gain_sizer, 8, 1, 1, 1) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=8, decimation=45, taps=(5, ), fractional_bw=None, ) self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + "") self.osmosdr_source_0.set_sample_rate(samp_rate) self.osmosdr_source_0.set_center_freq(rx_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(2, 0) self.osmosdr_source_0.set_gain_mode(True, 0) self.osmosdr_source_0.set_gain(rf_gain, 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) _offset_fine_sizer = wx.BoxSizer(wx.VERTICAL) self._offset_fine_text_box = forms.text_box( parent=self.GetWin(), sizer=_offset_fine_sizer, value=self.offset_fine, callback=self.set_offset_fine, label="Fine tune", converter=forms.float_converter(), proportion=0, ) self._offset_fine_slider = forms.slider( parent=self.GetWin(), sizer=_offset_fine_sizer, value=self.offset_fine, callback=self.set_offset_fine, minimum=-1000, maximum=1000, num_steps=400, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_offset_fine_sizer, 6, 0, 1, 2) _offset_coarse_sizer = wx.BoxSizer(wx.VERTICAL) self._offset_coarse_text_box = forms.text_box( parent=self.GetWin(), sizer=_offset_coarse_sizer, value=self.offset_coarse, callback=self.set_offset_coarse, label="Coarse tune", converter=forms.float_converter(), proportion=0, ) self._offset_coarse_slider = forms.slider( parent=self.GetWin(), sizer=_offset_coarse_sizer, value=self.offset_coarse, callback=self.set_offset_coarse, minimum=-250000, maximum=250000, num_steps=1000, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_offset_coarse_sizer, 6, 2, 1, 2) self._lo_freq_static_text = forms.static_text( parent=self.GetWin(), value=self.lo_freq, callback=self.set_lo_freq, label="LO", converter=forms.float_converter(), ) self.GridAdd(self._lo_freq_static_text, 5, 2, 1, 1) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc( 1, (xlate_filter_taps), 0, samp_rate) self._freq_text_box = forms.text_box( parent=self.GetWin(), value=self.freq, callback=self.set_freq, label="USRP", converter=forms.float_converter(), ) self.GridAdd(self._freq_text_box, 5, 1, 1, 1) self.fftsink = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=rx_freq * display_selector, y_per_div=10, y_divs=10, ref_level=0, ref_scale=13490.0, sample_rate=samp_rate, fft_size=512, fft_rate=15, average=True, avg_alpha=0.5, title="", peak_hold=False, size=(800, 300), ) self.GridAdd(self.fftsink.win, 0, 0, 5, 4) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff( (af_gain, )) self.band_pass_filter_0 = filter.fir_filter_ccf( 1, firdes.band_pass(1, samp_rate, width / 4, width / 2, trans, firdes.WIN_HAMMING, 6.76)) self.audio_sink_0 = audio.sink(44100, "", True) self.analog_am_demod_cf_0 = analog.am_demod_cf( channel_rate=44100, audio_decim=1, audio_pass=5000, audio_stop=10000, ) self.analog_agc_xx_0 = analog.agc_cc(1e-4, 1.0, 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.analog_am_demod_cf_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.analog_am_demod_cf_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.fftsink, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.analog_agc_xx_0, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Psk31 Rx") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.center_freq = center_freq = 441000000 self.samp_rate = samp_rate = 960000 self.psk_offset = psk_offset = 1000 self.psk_center = psk_center = center_freq + 141000 self.int_rate = int_rate = 48000 self.gain = gain = 30 self.corr = corr = 0 self.audio_rate = audio_rate = 8000 ################################################## # Message Queues ################################################## blocks_message_sink_0_msgq_out = wxgui_termsink_0_msgq_in = gr.msg_queue(2) ################################################## # Blocks ################################################## _psk_offset_sizer = wx.BoxSizer(wx.VERTICAL) self._psk_offset_text_box = forms.text_box( parent=self.GetWin(), sizer=_psk_offset_sizer, value=self.psk_offset, callback=self.set_psk_offset, label="PSK offset", converter=forms.float_converter(), proportion=0, ) self._psk_offset_slider = forms.slider( parent=self.GetWin(), sizer=_psk_offset_sizer, value=self.psk_offset, callback=self.set_psk_offset, minimum=0, maximum=3000, num_steps=300, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_psk_offset_sizer, 1, 0, 1, 2) _psk_center_sizer = wx.BoxSizer(wx.VERTICAL) self._psk_center_text_box = forms.text_box( parent=self.GetWin(), sizer=_psk_center_sizer, value=self.psk_center, callback=self.set_psk_center, label="Tuning", converter=forms.float_converter(), proportion=0, ) self._psk_center_slider = forms.slider( parent=self.GetWin(), sizer=_psk_center_sizer, value=self.psk_center, callback=self.set_psk_center, minimum=center_freq + 110000, maximum=center_freq + 150000, num_steps=40, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_psk_center_sizer, 0, 0, 1, 2) self.nb = self.nb = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.nb.AddPage(grc_wxgui.Panel(self.nb), "960 kHz") self.nb.AddPage(grc_wxgui.Panel(self.nb), "48 kHz") self.nb.AddPage(grc_wxgui.Panel(self.nb), "4 kHz") self.nb.AddPage(grc_wxgui.Panel(self.nb), "I/Q scope") self.nb.AddPage(grc_wxgui.Panel(self.nb), "Constellation") self.GridAdd(self.nb, 3, 0, 1, 2) _gain_sizer = wx.BoxSizer(wx.VERTICAL) self._gain_text_box = forms.text_box( parent=self.GetWin(), sizer=_gain_sizer, value=self.gain, callback=self.set_gain, label='gain', converter=forms.float_converter(), proportion=0, ) self._gain_slider = forms.slider( parent=self.GetWin(), sizer=_gain_sizer, value=self.gain, callback=self.set_gain, minimum=0, maximum=49.6, num_steps=124, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_gain_sizer, 2, 0, 1, 1) _corr_sizer = wx.BoxSizer(wx.VERTICAL) self._corr_text_box = forms.text_box( parent=self.GetWin(), sizer=_corr_sizer, value=self.corr, callback=self.set_corr, label='corr', converter=forms.float_converter(), proportion=0, ) self._corr_slider = forms.slider( parent=self.GetWin(), sizer=_corr_sizer, value=self.corr, callback=self.set_corr, minimum=-150, maximum=150, num_steps=300, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.GridAdd(_corr_sizer, 2, 1, 1, 1) self.wxgui_waterfallsink2_2 = waterfallsink2.waterfall_sink_f( self.nb.GetPage(2).GetWin(), baseband_freq=0, dynamic_range=30, ref_level=-40, ref_scale=2.0, sample_rate=audio_rate, fft_size=512, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", win=window.blackmanharris, size=((800,400)), ) self.nb.GetPage(2).Add(self.wxgui_waterfallsink2_2.win) def wxgui_waterfallsink2_2_callback(x, y): self.set_psk_offset(x) self.wxgui_waterfallsink2_2.set_callback(wxgui_waterfallsink2_2_callback) self.wxgui_waterfallsink2_1 = waterfallsink2.waterfall_sink_c( self.nb.GetPage(1).GetWin(), baseband_freq=psk_center, dynamic_range=30, ref_level=-30, ref_scale=2.0, sample_rate=int_rate, fft_size=2048, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", size=((800,400)), ) self.nb.GetPage(1).Add(self.wxgui_waterfallsink2_1.win) self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c( self.nb.GetPage(0).GetWin(), baseband_freq=center_freq, dynamic_range=30, ref_level=-20, ref_scale=2.0, sample_rate=samp_rate, fft_size=2048, fft_rate=15, average=False, avg_alpha=None, title="Waterfall Plot", size=((800,400)), ) self.nb.GetPage(0).Add(self.wxgui_waterfallsink2_0.win) def wxgui_waterfallsink2_0_callback(x, y): self.set_psk_center(x) self.wxgui_waterfallsink2_0.set_callback(wxgui_waterfallsink2_0_callback) self.wxgui_termsink_0 = termsink.termsink( parent=self.GetWin(), size=(500,100), msgq=wxgui_termsink_0_msgq_in, ) self.Add(self.wxgui_termsink_0) self.wxgui_scopesink2_1 = scopesink2.scope_sink_c( self.nb.GetPage(4).GetWin(), title="Scope Plot", sample_rate=31.25, v_scale=0.4, v_offset=0, t_scale=0, ac_couple=False, xy_mode=True, num_inputs=1, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label="Counts", ) self.nb.GetPage(4).Add(self.wxgui_scopesink2_1.win) self.wxgui_scopesink2_0 = scopesink2.scope_sink_c( self.nb.GetPage(3).GetWin(), title="Scope Plot", sample_rate=500, v_scale=0.4, v_offset=0, t_scale=0, ac_couple=False, xy_mode=True, num_inputs=1, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label="Counts", ) self.nb.GetPage(3).Add(self.wxgui_scopesink2_0.win) self.wxgui_numbersink2_0 = numbersink2.number_sink_f( self.GetWin(), unit="Hz", minval=-500 / math.pi, maxval=500 / math.pi, factor=500 / math.pi, decimal_places=1, ref_level=0, sample_rate=500, number_rate=15, average=False, avg_alpha=None, label="Carrier tracking offset", peak_hold=False, show_gauge=True, ) self.Add(self.wxgui_numbersink2_0.win) self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" ) 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(corr, 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(0, 0) self.osmosdr_source_0.set_gain(gain, 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.ham_varicode_rx_0 = ham.varicode_rx() self.freq_xlating_fir_filter_xxx_1 = filter.freq_xlating_fir_filter_ccc(16, (firdes.low_pass(10, audio_rate, 120, 40, firdes.WIN_HAMMING, 6.76)), psk_offset, audio_rate) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(samp_rate / int_rate, (firdes.low_pass(1, samp_rate, 12000, 12000, firdes.WIN_HAMMING, 6.76)), round(psk_center - center_freq,-3), samp_rate) self.digital_diff_phasor_cc_0 = digital.diff_phasor_cc() self.digital_costas_loop_cc_0 = digital.costas_loop_cc(5 * math.pi /100.0, 2) self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_cc(16, 0.25*0.175*0.175, 0.5, 0.175, 0.005) self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb() self.blocks_message_sink_0 = blocks.message_sink(gr.sizeof_char*1, blocks_message_sink_0_msgq_out, True) self.blocks_complex_to_real_1 = blocks.complex_to_real(1) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) self.band_pass_filter_0 = filter.fir_filter_ccc(int_rate / audio_rate, firdes.complex_band_pass( 1, int_rate, 200, 2800, 200, firdes.WIN_HAMMING, 6.76)) self.audio_sink_0 = audio.sink(audio_rate, "plughw:0,0", True) self.analog_agc_xx_0 = analog.agc_cc(1e-3, 0.1, 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.wxgui_waterfallsink2_1, 0)) self.connect((self.osmosdr_source_0, 0), (self.wxgui_waterfallsink2_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.blocks_complex_to_real_0, 0), (self.wxgui_waterfallsink2_2, 0)) self.connect((self.digital_costas_loop_cc_0, 1), (self.wxgui_numbersink2_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_1, 0), (self.digital_costas_loop_cc_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.wxgui_scopesink2_0, 0)) self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.digital_diff_phasor_cc_0, 0)) self.connect((self.digital_costas_loop_cc_0, 0), (self.digital_clock_recovery_mm_xx_0, 0)) self.connect((self.ham_varicode_rx_0, 0), (self.blocks_message_sink_0, 0)) self.connect((self.digital_binary_slicer_fb_0, 0), (self.ham_varicode_rx_0, 0)) self.connect((self.blocks_complex_to_real_1, 0), (self.digital_binary_slicer_fb_0, 0)) self.connect((self.digital_diff_phasor_cc_0, 0), (self.blocks_complex_to_real_1, 0)) self.connect((self.blocks_complex_to_real_0, 0), (self.audio_sink_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.analog_agc_xx_0, 0), (self.freq_xlating_fir_filter_xxx_1, 0)) self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.wxgui_scopesink2_1, 0))
def test_001(self): ''' Test the complex AGC loop (single rate input) ''' tb = self.tb expected_result = ( (100.000244140625+7.2191943445432116e-07j), (72.892257690429688+52.959323883056641j), (25.089065551757812+77.216217041015625j), (-22.611061096191406+69.589706420898438j), (-53.357715606689453+38.766635894775391j), (-59.458671569824219+3.4792964243024471e-07j), (-43.373462677001953-31.512666702270508j), (-14.94139289855957-45.984889984130859j), (13.478158950805664-41.48150634765625j), (31.838506698608398-23.132022857666016j), (35.519271850585938-3.1176801940091536e-07j), (25.942903518676758+18.848621368408203j), (8.9492912292480469+27.5430908203125j), (-8.0852642059326172+24.883890151977539j), (-19.131628036499023+13.899936676025391j), (-21.383295059204102+3.1281737733479531e-07j), (-15.650330543518066-11.370632171630859j), (-5.4110145568847656-16.65339469909668j), (4.9008159637451172-15.083160400390625j), (11.628337860107422-8.4484796524047852j), (13.036135673522949-2.288476110834381e-07j), (9.5726661682128906+6.954948902130127j), (3.3216962814331055+10.223132133483887j), (-3.0204284191131592+9.2959251403808594j), (-7.1977195739746094+5.2294478416442871j), (-8.1072216033935547+1.8976157889483147e-07j), (-5.9838657379150391-4.3475332260131836j), (-2.0879747867584229-6.4261269569396973j), (1.9100792407989502-5.8786196708679199j), (4.5814824104309082-3.3286411762237549j), (5.1967458724975586-1.3684227440080576e-07j), (3.8647139072418213+2.8078789710998535j), (1.3594740629196167+4.1840314865112305j), (-1.2544282674789429+3.8607344627380371j), (-3.0366206169128418+2.2062335014343262j), (-3.4781389236450195+1.1194014604143376e-07j), (-2.6133756637573242-1.8987287282943726j), (-0.9293016791343689-2.8600969314575195j), (0.86727333068847656-2.6691930294036865j), (2.1243946552276611-1.5434627532958984j), (2.4633183479309082-8.6486437567145913e-08j), (1.8744727373123169+1.3618841171264648j), (0.67528903484344482+2.0783262252807617j), (-0.63866174221038818+1.965599536895752j), (-1.5857341289520264+1.152103066444397j), (-1.8640764951705933+7.6355092915036948e-08j), (-1.4381576776504517-1.0448826551437378j), (-0.52529704570770264-1.6166983842849731j), (0.50366902351379395-1.5501341819763184j), (1.26766037940979-0.92100900411605835j)) sampling_freq = 100 src1 = analog.sig_source_c(sampling_freq, analog.GR_SIN_WAVE, sampling_freq * 0.10, 100.0) dst1 = blocks.vector_sink_c() head = blocks.head(gr.sizeof_gr_complex, int (5*sampling_freq * 0.10)) agc = analog.agc_cc(1e-3, 1, 1) tb.connect(src1, head) tb.connect(head, agc) tb.connect(agc, dst1) tb.run() dst_data = dst1.data() self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 4)
def __init__(self, argv): gr.top_block.__init__(self) parser=OptionParser(option_class=eng_option) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--dev", type="string", default=0, help="Device (rtl=0 or something") parser.add_option("-f", "--freqset", type="string", default="", help="Frequency set key=freq,key=freq,... in kHz") parser.add_option("-m", "--mode", type="string", default="fm", help="Mode (am or fm)") parser.add_option("-g", "--gain", type="eng_float", default=30.0, help="set gain in dB (default is maximum)") parser.add_option("-V", "--volume", type="eng_float", default=1.0, help="set volume (default is midpoint)") parser.add_option("-i", "--icecast", type="string", default="", help="Icecast host:port") parser.add_option("-p", "--icepw", type="string", default="127.0.0.1:8000", help="Icecast source password") parser.add_option("-O", "--audio-output", type="string", default="", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) if options.volume is None: options.volume = 0.8 self.vol = options.volume self.freqs = self.parse_freqset(options.freqset) self.freq_corr = 0 self.rf_gain = options.gain # around 20 self.if_gain = 7 self.bb_gain = 10.0 self.bandwidth = 2400000 self.channel_bw = 10000 freq_min = min(self.freqs.values()) freq_max = max(self.freqs.values()) print "Frequencies:" for k in self.freqs: print " %s: %.3f MHz" % (k, self.freqs[k]/1000000.0) required_bw = freq_max - freq_min print "Required bandwidth: %.3f MHz" % (required_bw/1000000.0) if required_bw > self.bandwidth: print "Required bandwidth %.3f MHz larger than maximum BW %.3f MHz" % (required_bw/1000000, self.bandwidth/100000) return None # offset center frequency so that it's not on a monitored frequency self.center_freq = freq_min + (required_bw/2) for f in self.freqs.values(): if abs(f - self.center_freq) < self.channel_bw: self.center_freq += self.channel_bw print "Center frequency: %.3f MHz" % self.center_freq print "" # build graph arg_s = options.dev #"rtl=%d" % options.dev u = self.u = osmosdr.source(args=arg_s) u.set_center_freq(self.center_freq, 0) u.set_freq_corr(self.freq_corr, 0) u.set_dc_offset_mode(0, 0) # 0-2: Off-Manual-Automatic u.set_iq_balance_mode(0, 0) # 0-2: Off-Manual-Automatic u.set_gain_mode(False, 0) # 0-1: Manual, Automatic u.set_gain(self.rf_gain, 0) u.set_if_gain(self.if_gain, 0) u.set_bb_gain(self.bb_gain, 0) u.set_antenna("all", 0) u.set_sample_rate(1024e3*2) u.set_bandwidth(self.bandwidth, 0) dev_rate = self.u.get_sample_rate() demod_rate = 64e3 audio_rate = 32e3 chanfilt_decim = int(dev_rate // demod_rate) audio_decim = int(demod_rate // audio_rate) print "Device rate %d, bandwidth %.3f MHz" % (dev_rate, self.bandwidth / 1000000.0) print "Demod rate %d, audio rate %d" % (demod_rate, audio_rate) if options.mode == 'am': chan_filt_coeffs = filter.firdes.low_pass_2(1, # gain dev_rate, # sampling rate 8e3, # passband cutoff 2e3, # transition bw 60) # stopband attenuation else: print "FM filter" chan_filt_coeffs = filter.firdes.low_pass_2(1, # gain dev_rate, # sampling rate 16e3, # passband cutoff 3e3, # transition bw 60) # stopband attenuation audio_filt_coeffs = filter.firdes.low_pass_2(1, # gain demod_rate, # sampling rate 7e3, # passband cutoff 2e3, # transition bw 60) # stopband attenuation demodulators = [] for k in self.freqs: f = self.freqs[k] print "Setting up %s: %.3f MHz" % (k, f / 1000000.0) if_freq = f - self.center_freq chan_filt = filter.freq_xlating_fir_filter_ccf(chanfilt_decim, chan_filt_coeffs, if_freq, dev_rate) agc = analog.agc_cc(0.1, 1, 1) if options.mode == 'am': demod = blocks.complex_to_mag() squelch = analog.standard_squelch(dev_rate/10) sq_range = squelch.squelch_range() sq = (sq_range[0] + sq_range[1])/2 sq = 0.7 print "Squelch: range %.1f ... %.1f, using %.2f" % (sq_range[0], sq_range[1], sq) squelch.set_threshold(sq) audio_filt = filter.fir_filter_fff(audio_decim, audio_filt_coeffs) self.connect(chan_filt, agc, demod, squelch, audio_filt) last_block = audio_filt else: print "FM demod" demod = analog.demod_20k0f3e_cf(demod_rate, audio_decim) squelch = analog.pwr_squelch_cc(-50.0, # Power threshold 125.0/demod_rate, # Time constant int(demod_rate/20), # 50ms rise/fall False) # Zero, not gate output self.connect(chan_filt, squelch, agc, demod) last_block = demod demodulators.append([chan_filt, last_block]) if options.icecast: # set up a file sink fname = self.setup_upstream_pipe(k, options) float_to_int = blocks.float_to_short(scale=7500.0) file_sink = blocks.file_sink(gr.sizeof_short, fname, append=True) self.connect(last_block, float_to_int, file_sink) self.adder = None if options.audio_output != "": self.volume_control = blocks.multiply_const_ff(self.vol) self.adder = blocks.add_ff(1) # sound card as final sink self.audio_sink = audio.sink(int (audio_rate), options.audio_output, False) # ok_to_block # now wire it all together ch = 0 for d in demodulators: self.connect(self.u, d[0]) if self.adder: self.connect(d[1], (self.adder, ch)) ch += 1 if self.adder: self.connect(self.adder, self.volume_control, self.audio_sink) if options.gain is None: g = self.u.get_gain_range() # if no gain was specified, use the mid gain options.gain = (g.start() + g.stop())/2.0