def __init__(self, decim=32, sync_check=False, satellite='METEOR-M-1', baseband_file=os.environ['HOME'] + '/METEOR-M-1.dat', frames_file=os.environ['HOME'] + '/METEOR-M-1.hrpt'):
		gr.top_block.__init__(self, "Meteor M N1 HRPT Baseband To Frames")

		##################################################
		# Parameters
		##################################################
		self.decim = decim
		self.sync_check = sync_check
		self.satellite = satellite
		self.baseband_file = baseband_file
		self.frames_file = frames_file

		##################################################
		# Variables
		##################################################
		self.sym_rate = sym_rate = 600*1109
		self.sample_rate = sample_rate = 64e6/decim
		self.sps = sps = sample_rate/sym_rate
		self.config_filename = config_filename = os.environ['HOME']+'/.gnuradio/mn1_hrpt.conf'
		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("satname", 'pll_alpha')
		except: saved_pll_alpha = 0.01
		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("satname", 'clock_alpha')
		except: saved_clock_alpha = 0.01
		self.saved_clock_alpha = saved_clock_alpha
		self.max_clock_offset = max_clock_offset = 100e-6
		self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/sample_rate
		self.hs = hs = int(sps/2.0)

		##################################################
		# Blocks
		##################################################
		self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)
		self.frame_sink = gr.file_sink(gr.sizeof_short*1, frames_file)
		self.frame_sink.set_unbuffered(False)
		self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(sps/2.0, saved_clock_alpha**2/4.0, 0.5, saved_clock_alpha, max_clock_offset)
		self.gr_file_source_0 = gr.file_source(gr.sizeof_short*1, baseband_file, False)
		self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex()
		self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0/hs, 4000)
		self.pll = noaa.hrpt_pll_cf(saved_pll_alpha, saved_pll_alpha**2/4.0, max_carrier_offset)
		self.poesweather_mn1_hrpt_deframer_0 = poesweather.mn1_hrpt_deframer(sync_check)
		self.throttle = gr.throttle(gr.sizeof_short*1, sample_rate*10)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_binary_slicer_fb_0, 0))
		self.connect((self.gr_file_source_0, 0), (self.throttle, 0))
		self.connect((self.throttle, 0), (self.gr_interleaved_short_to_complex_0, 0))
		self.connect((self.gr_interleaved_short_to_complex_0, 0), (self.agc, 0))
		self.connect((self.agc, 0), (self.pll, 0))
		self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.gr_binary_slicer_fb_0, 0), (self.poesweather_mn1_hrpt_deframer_0, 0))
		self.connect((self.poesweather_mn1_hrpt_deframer_0, 0), (self.frame_sink, 0))
Пример #2
0
    def __init__(self, fs, svn, alpha, fd_range, dump_bins=False):
        gr.hier_block2.__init__(self,
            "acquisition",
            gr.io_signature(1,1, gr.sizeof_gr_complex),
            gr.io_signature(3,3, gr.sizeof_float))

        fft_size = int( 1e-3*fs)
        doppler_range = self.get_doppler_range(fd_range)

        agc = gr.agc_cc( 1.0/fs, 1.0, 1.0, 1.0)
        s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
        fft = gr.fft_vcc(fft_size, True, [])

        argmax = gr.argmax_fs(fft_size)
        max = gr.max_ff(fft_size)

        self.connect( self, s2v, fft)
        self.connect( (argmax, 0),
                gr.short_to_float(),
                (self, 0))
        self.connect( (argmax,1),
                gr.short_to_float(),
                gr.add_const_ff(-fd_range),
                gr.multiply_const_ff(1e3),
                (self,1))
        self.connect( max, (self, 2))

        # Connect the individual channels to the input and the output.
        self.correlators = [ single_channel_correlator( fs, fd, svn, alpha, dump_bins) for fd in doppler_range ]

        for (correlator, i) in zip( self.correlators, range(len(self.correlators))):
            self.connect( fft, correlator )
            self.connect( correlator, (argmax, i) )
            self.connect( correlator, (max, i) )
Пример #3
0
    def __init__(self, fs, svn, alpha, fd_range, dump_bins=False):
        gr.hier_block2.__init__(self, "acquisition",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(3, 3, gr.sizeof_float))

        fft_size = int(1e-3 * fs)
        doppler_range = self.get_doppler_range(fd_range)

        agc = gr.agc_cc(1.0 / fs, 1.0, 1.0, 1.0)
        s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
        fft = gr.fft_vcc(fft_size, True, [])

        argmax = gr.argmax_fs(fft_size)
        max = gr.max_ff(fft_size)

        self.connect(self, s2v, fft)
        self.connect((argmax, 0), gr.short_to_float(), (self, 0))
        self.connect((argmax, 1), gr.short_to_float(),
                     gr.add_const_ff(-fd_range), gr.multiply_const_ff(1e3),
                     (self, 1))
        self.connect(max, (self, 2))

        # Connect the individual channels to the input and the output.
        self.correlators = [
            single_channel_correlator(fs, fd, svn, alpha, dump_bins)
            for fd in doppler_range
        ]

        for (correlator, i) in zip(self.correlators,
                                   range(len(self.correlators))):
            self.connect(fft, correlator)
            self.connect(correlator, (argmax, i))
            self.connect(correlator, (max, i))
Пример #4
0
    def __init__(self, options):
        gr.hier_block2.__init__(self, "transmit_path",
                                gr.io_signature(0, 0, 0),
                                gr.io_signature(0, 0, 0))
        #Set up usrp block
        self.u = usrp.source_c()
        adc_rate = self.u.adc_rate()  # 64 MS/s
        usrp_decim = 16
        gain = 65
        self.u.set_decim_rate(usrp_decim)
        usrp_rate = adc_rate / usrp_decim  #  320 kS/s
        print usrp_rate
        #subdev_spec = usrp.pick_subdev(self.u)
        subdev_spec = (0, 0)
        mux_value = usrp.determine_rx_mux_value(self.u, subdev_spec)
        self.u.set_mux(mux_value)
        self.subdev = usrp.selected_subdev(self.u, subdev_spec)
        self.subdev.set_gain(gain)
        self.subdev.set_auto_tr(False)
        self.subdev.set_enable(True)

        if not (self.set_freq(915e6)):
            print "Failed to set initial frequency"

        #set up the rest of the path
        deci = 1

        self.agc = gr.agc_cc(rate=1e-7,
                             reference=1.0,
                             gain=0.001,
                             max_gain=0.5)

        matchtaps = [complex(-1, -1)] * 8 + [complex(
            1, 1)] * 8 + [complex(-1, -1)] * 8 + [complex(1, 1)] * 8
        #matchtaps = [complex(-1,-1)] * 8 + [complex(1,1)] * 8
        self.matchfilter = gr.fir_filter_ccc(1, matchtaps)

        reverse = [complex(1, 1)] * (8 / deci) + [complex(
            -1, -1)] * (8 / deci) + [complex(
                1, 1)] * (8 / deci) + [complex(-1, -1)] * (8 / deci)
        #pretaps = matchtaps * 3 + reverse * 4 + matchtaps * 4 + reverse * 8 + matchtaps * 6 + matchtaps * 62
        pretaps = matchtaps * 2 + reverse * 2 + matchtaps * 2 + reverse * 4 + matchtaps * 3 + matchtaps * 31
        #pretaps =  matchtaps * 3 + reverse * 8 + matchtaps * 6 + matchtaps * 64
        self.preamble_filter = gr.fir_filter_ccc(1, pretaps)

        self.c_f = gr.complex_to_real()
        self.c_f2 = gr.complex_to_real()

        self.lock = howto.lock_time(32, 5, 32)

        self.pd = howto.find_pre_ff(55, 200)

        self.dec = symbols_decoder()

        self.vect = gr.vector_sink_f()

        #self.connect(self.u, self.agc, self.matchfilter, self.c_f, (self.lock, 0),  self.dec, self.vect)
        #self.connect(self.agc, self.preamble_filter, self.c_f2, self.pd, (self.lock, 1))
        self.connect(self.u, self.agc, self.matchfilter, self.c_f, self.vect)
Пример #5
0
  def __init__(self, options): 
    gr.hier_block2.__init__(self, "transmit_path", 
                             gr.io_signature(0, 0, 0), 
                             gr.io_signature(0, 0, 0))
    #Set up usrp block
    self.u = usrp.source_c()
    adc_rate = self.u.adc_rate()                # 64 MS/s
    usrp_decim = 16
    gain = 65
    self.u.set_decim_rate(usrp_decim)
    usrp_rate = adc_rate / usrp_decim           #  320 kS/s
    print usrp_rate
    #subdev_spec = usrp.pick_subdev(self.u)
    subdev_spec = (0,0)
    mux_value = usrp.determine_rx_mux_value(self.u, subdev_spec)
    self.u.set_mux(mux_value)
    self.subdev = usrp.selected_subdev(self.u, subdev_spec)
    self.subdev.set_gain(gain)
    self.subdev.set_auto_tr(False)
    self.subdev.set_enable(True)

    if not(self.set_freq(915e6)):	
      print "Failed to set initial frequency"

    #set up the rest of the path
    deci = 1

    self.agc = gr.agc_cc( rate = 1e-7, reference = 1.0, gain = 0.001, max_gain = 0.5)

    matchtaps = [complex(-1,-1)] * 8 + [complex(1,1)] * 8 + [complex(-1,-1)]* 8 + [complex(1,1)]* 8
    #matchtaps = [complex(-1,-1)] * 8 + [complex(1,1)] * 8 
    self.matchfilter = gr.fir_filter_ccc(1, matchtaps)

    reverse = [complex(1,1)] * (8 / deci) + [complex(-1,-1)] * (8 / deci) + [complex(1,1)]* (8 / deci) + [complex(-1,-1)]* (8 / deci)
    #pretaps = matchtaps * 3 + reverse * 4 + matchtaps * 4 + reverse * 8 + matchtaps * 6 + matchtaps * 62
    pretaps = matchtaps * 2 + reverse * 2 + matchtaps * 2 + reverse * 4 + matchtaps * 3 + matchtaps * 31
    #pretaps =  matchtaps * 3 + reverse * 8 + matchtaps * 6 + matchtaps * 64
    self.preamble_filter = gr.fir_filter_ccc(1, pretaps)

    self.c_f = gr.complex_to_real()
    self.c_f2 = gr.complex_to_real()

    self.lock = howto.lock_time(32, 5, 32)

    self.pd = howto.find_pre_ff(55, 200)

    self.dec = symbols_decoder()

    self.vect = gr.vector_sink_f()
    
    #self.connect(self.u, self.agc, self.matchfilter, self.c_f, (self.lock, 0),  self.dec, self.vect)
    #self.connect(self.agc, self.preamble_filter, self.c_f2, self.pd, (self.lock, 1))
    self.connect(self.u, self.agc, self.matchfilter, self.c_f, self.vect)
Пример #6
0
    def __init__(self):
        gr.hier_block2.__init__(self,
                                "proto_transceiver",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))
#file sinks for debugging
        self.agc_out = gr.file_sink(itemsize = gr.sizeof_gr_complex,
                                    filename = "agc.dat")
#########################
#uplink blocks

        q_encoder = gr.msg_queue(100)
        self.tx_encoder = rfidbts.pie_encoder(samples_per_delimiter = 8, 
                                              samples_per_tari = 16,
                                              samples_per_pw = 8,
                                              samples_per_trcal = 53,
                                              samples_per_data1 = 32)
        self.tx_encoder.set_encoder_queue(q_encoder)
        rfidbts.cvar.rfid_mac.set_encoder_queue(q_encoder)
####################################
#downlink blocks
        q_blocker = gr.msg_queue(100)
        frame_size_rn16 = int((32 + 32 + 12) * 8 + int(75*0.4*1.024))
        self.TX_blocker = rfidbts.receive_gate(threshold = 0.15,     #bit above the noise floor
                                               off_max = 15)         #should not be in the off state for more than 13 us
        self.TX_blocker.set_gate_queue(q_blocker)
        rfidbts.cvar.rfid_mac.set_gate_queue(q_blocker)
        self.blocker = gr.dc_blocker_cc(D = 5, 
                                        long_form = True)
        self.agc = gr.agc_cc(rate = 5e-1, 
                             reference = 0.707, 
                             gain = 100.0,
                             max_gain = 1000.0)
        self.search = preamble_search(frame_size_rn16)
        self.half_symbols = symbol_mapper()
#        self.decoder = binary_diff_decoder()
        self.decoder = rfidbts.orthogonal_decode()
        self.framer = rfidbts.packetizer()
#frame the rn16 and send to message queue
#####################################
#connect uplink
        self.connect(self.tx_encoder, self)
#####################################
#connect downlink
        self.connect(self,
                     self.TX_blocker,
                     self.blocker,
                     self.agc,
                     self.search,
                     self.half_symbols,
                     self.decoder,
                     self.framer)
        self.connect(self.agc, self.agc_out)
    def __init__(self, principal_gui, options):
    
        gr.hier_block2.__init__(self, "bpsk_demod",
                gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
                gr.io_signature(1, 1, gr.sizeof_gr_complex))       # Output signature
        
        #Enter the parameters of modulation         
        self._samples_per_symbol = options.samples_per_symbol
        
        self.verbose = options.verbose

        self._gray_code =_def_gray_code
        
        if self._samples_per_symbol < 2:
            raise TypeError, "samples_per_symbol must be >= 2, is %r" % (self._samples_per_symbol,)

        arity = pow(2,self.bits_per_symbol())

        # Automatic gain control
        
        #self.agc = gr.agc2_cc(0.6e-1, 1e-3, 1, 1, 100)
        self.agc = gr.agc_cc(1e-5, 1.0,1.0,1.0)
        #self.agc = gr.feedforward_agc_cc(16, 2.0)

        # RRC data filter
        ntaps = 11 * self._samples_per_symbol
        self.rrc_taps = gr.firdes.root_raised_cosine(
            1.0,                      # gain
            self._samples_per_symbol, # sampling rate
            1.0,                      # symbol rate
            0.35,                      # excess bandwidth (roll-off factor)
            ntaps)
        self.rrc_filter=gr.interp_fir_filter_ccf(1, self.rrc_taps)        
                
        self._costas = digital.costas_loop_cc(6.28/100.0, 2)
        self.gr_null_sink = gr.null_sink(gr.sizeof_float*1)
        self.connect((self._costas, 1), (self.gr_null_sink, 0))
        
        self._mm = digital.clock_recovery_mm_cc(self._samples_per_symbol,       # Initial samples/symbol
                                           1e-06,  # Second order gain
                                           0.5,          # Initial symbol phase
                                           0.001,     # First order gain
                                           0.0001) # Maximum timing offset
        
        if self.verbose:
            self._print_verbage()
        
        # Do differential decoding based on phase change of symbols
        #self.diffdec = gr.diff_phasor_cc()
 
        # Connect and Initialize base class
        self.connect(self, self.agc, self.rrc_filter, (self._costas,0), self._mm, self)
Пример #8
0
	def __init__(self, input_filename="usrp.dat", output_filename="frames.dat", decim=32, pll_alpha=0.01, clock_alpha=0.01):
		gr.top_block.__init__(self, "Hrpt Demod")

		##################################################
		# Parameters
		##################################################
		self.input_filename = input_filename
		self.output_filename = output_filename
		self.decim = decim
		self.pll_alpha = pll_alpha
		self.clock_alpha = clock_alpha

		##################################################
		# Variables
		##################################################
		self.sym_rate = sym_rate = 600*1109
		self.sample_rate = sample_rate = 4e6
		self.sps = sps = sample_rate/sym_rate
		self.max_clock_offset = max_clock_offset = 100e-6
		self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/sample_rate
		self.hs = hs = int(sps/2.0)

		##################################################
		# Blocks
		##################################################
		self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset)
		self.noaa_hrpt_deframer_0 = noaa.hrpt_deframer()
		self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0/hs, 4000)
		self.gr_file_sink_0 = gr.file_sink(gr.sizeof_short*1, output_filename)
		self.gr_file_sink_0.set_unbuffered(False)
		self.file_source = gr.file_source(gr.sizeof_short*1, input_filename, False)
		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.decoder = noaa.hrpt_decoder(True,False)
		self.cs2cf = gr.interleaved_short_to_complex()
		self.agc = gr.agc_cc(1e-5, 1.0, 1.0/32768.0, 1.0)

		##################################################
		# Connections
		##################################################
		self.connect((self.file_source, 0), (self.cs2cf, 0))
		self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.cs2cf, 0), (self.agc, 0))
		self.connect((self.agc, 0), (self.pll, 0))
		self.connect((self.noaa_hrpt_deframer_0, 0), (self.gr_file_sink_0, 0))
		self.connect((self.noaa_hrpt_deframer_0, 0), (self.decoder, 0))
		self.connect((self.gr_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.digital_binary_slicer_fb_0, 0), (self.noaa_hrpt_deframer_0, 0))
Пример #9
0
    def __init__(self):
        gr.hier_block2.__init__(self, "proto_transceiver",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))
        #file sinks for debugging
        self.agc_out = gr.file_sink(itemsize=gr.sizeof_gr_complex,
                                    filename="agc.dat")
        #########################
        #uplink blocks

        q_encoder = gr.msg_queue(100)
        self.tx_encoder = rfidbts.pie_encoder(samples_per_delimiter=8,
                                              samples_per_tari=16,
                                              samples_per_pw=8,
                                              samples_per_trcal=53,
                                              samples_per_data1=32)
        self.tx_encoder.set_encoder_queue(q_encoder)
        rfidbts.cvar.rfid_mac.set_encoder_queue(q_encoder)
        ####################################
        #downlink blocks
        q_blocker = gr.msg_queue(100)
        frame_size_rn16 = int((32 + 32 + 12) * 8 + int(75 * 0.4 * 1.024))
        self.TX_blocker = rfidbts.receive_gate(
            threshold=0.15,  #bit above the noise floor
            off_max=15)  #should not be in the off state for more than 13 us
        self.TX_blocker.set_gate_queue(q_blocker)
        rfidbts.cvar.rfid_mac.set_gate_queue(q_blocker)
        self.blocker = gr.dc_blocker_cc(D=5, long_form=True)
        self.agc = gr.agc_cc(rate=5e-1,
                             reference=0.707,
                             gain=100.0,
                             max_gain=1000.0)
        self.search = preamble_search(frame_size_rn16)
        self.half_symbols = symbol_mapper()
        #        self.decoder = binary_diff_decoder()
        self.decoder = rfidbts.orthogonal_decode()
        self.framer = rfidbts.packetizer()
        #frame the rn16 and send to message queue
        #####################################
        #connect uplink
        self.connect(self.tx_encoder, self)
        #####################################
        #connect downlink
        self.connect(self, self.TX_blocker, self.blocker, self.agc,
                     self.search, self.half_symbols, self.decoder, self.framer)
        self.connect(self.agc, self.agc_out)
Пример #10
0
    def __init__(self, options):
	gr.top_block.__init__(self)
	self.options = options

	(dev_rate, channel_rate, audio_rate,
	 channel_pass, channel_stop, demod) = demod_params[options.modulation]

        DEV = uhd_src(options.args,             # UHD device address
                      options.spec,             # device subdev spec
                      options.antenna,          # device antenna
                      dev_rate,         	# device sample rate
                      options.gain, 	    	# Receiver gain
                      options.calibration)      # Frequency offset
	DEV.tune(options.frequency)

	if_rate = DEV.rate()
        channel_decim = int(if_rate // channel_rate)
	audio_decim = int(channel_rate // audio_rate)

	CHAN_taps = optfir.low_pass(1.0,          # Filter gain
                                    if_rate, 	  # Sample rate
                                    channel_pass, # One sided modulation bandwidth
                                    channel_stop, # One sided channel bandwidth
                                    0.1, 	  # Passband ripple
                                    60) 	  # Stopband attenuation

	CHAN = gr.freq_xlating_fir_filter_ccf(channel_decim, # Decimation rate
	                                      CHAN_taps,     # Filter taps
					      0.0, 	     # Offset frequency
					      if_rate)	     # Sample rate

	RFSQL = gr.pwr_squelch_cc(options.rf_squelch,    # Power threshold
	                          125.0/channel_rate, 	 # Time constant
				  int(channel_rate/20),  # 50ms rise/fall
				  False)		 # Zero, not gate output

	AGC = gr.agc_cc(1.0/channel_rate,  # Time constant
			1.0,     	   # Reference power 
			1.0,               # Initial gain
			1.0)		   # Maximum gain

	DEMOD = demod(channel_rate, audio_decim)

	# From RF to audio
        #self.connect(DEV, CHAN, RFSQL, AGC, DEMOD)
        self.connect(DEV, CHAN, DEMOD)

	# Optionally add CTCSS and RSAMP if needed
	tail = DEMOD
	if options.ctcss != None and options.ctcss > 60.0:
	    CTCSS = gr.ctcss_squelch_ff(audio_rate,    # Sample rate
				        options.ctcss) # Squelch tone
	    self.connect(DEMOD, CTCSS)
	    tail = CTCSS

	if options.output_rate != audio_rate:
	    out_lcm = gru.lcm(audio_rate, options.output_rate)
	    out_interp = int(out_lcm // audio_rate)
	    out_decim = int(out_lcm // options.output_rate)
	    RSAMP = blks2.rational_resampler_fff(out_interp, out_decim)
	    self.connect(tail, RSAMP)
	    tail = RSAMP 

	# Send to audio output device
        AUDIO = audio.sink(int(options.output_rate),
                           options.audio_output)
	self.connect(tail, AUDIO)

        # Direct asynchronous notifications to callback function
        if self.options.show_async_msg:
            self.async_msgq = gr.msg_queue(0)
            self.async_src = uhd.amsg_source("", self.async_msgq)
            self.async_rcv = gru.msgq_runner(self.async_msgq, self.async_callback)
Пример #11
0
	def __init__(self, devid="type=b100", rdsfile="rds_fifo", gain=35.0, freq=101.1e6, xmlport=13777, arate=int(48e3), mute=-15.0, ftune=0, ant="J1", subdev="A:0", ahw="pulse", deemph=75.0e-6, prenames='["UWRF","89.3","950","WEVR"]', prefreqs="[88.715e6,89.3e6,950.735e6,106.317e6]", volume=1.0):
		grc_wxgui.top_block_gui.__init__(self, title="Simple FM (Stereo) Receiver")
		_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Parameters
		##################################################
		self.devid = devid
		self.rdsfile = rdsfile
		self.gain = gain
		self.freq = freq
		self.xmlport = xmlport
		self.arate = arate
		self.mute = mute
		self.ftune = ftune
		self.ant = ant
		self.subdev = subdev
		self.ahw = ahw
		self.deemph = deemph
		self.prenames = prenames
		self.prefreqs = prefreqs
		self.volume = volume

		##################################################
		# Variables
		##################################################
		self.pthresh = pthresh = 350
		self.preselect = preselect = eval(prefreqs)[0]
		self.pilot_level = pilot_level = 0
		self.ifreq = ifreq = freq
		self.stpilotdet = stpilotdet = True if (pilot_level > pthresh) else False
		self.stereo = stereo = True
		self.rf_pwr_lvl = rf_pwr_lvl = 0
		self.cur_freq = cur_freq = simple_fm_helper.freq_select(ifreq,preselect)
		self.vol = vol = volume
		self.variable_static_text_0 = variable_static_text_0 = 10.0*math.log(rf_pwr_lvl+1.0e-11)/math.log(10)
		self.tone_med = tone_med = 5
		self.tone_low = tone_low = 5
		self.tone_high = tone_high = 5
		self.stereo_0 = stereo_0 = stpilotdet
		self.st_enabled = st_enabled = 1 if (stereo == True and pilot_level > pthresh) else 0
		self.squelch_probe = squelch_probe = 0
		self.sq_thresh = sq_thresh = mute
		self.samp_rate = samp_rate = 250e3
		self.rtext_0 = rtext_0 = cur_freq
		self.record = record = False
		self.rdsrate = rdsrate = 25e3
		self.osmo_taps = osmo_taps = firdes.low_pass(1.0,1.00e6,95e3,20e3,firdes.WIN_HAMMING,6.76)
		self.mod_reset = mod_reset = 0
		self.igain = igain = gain
		self.fine = fine = ftune
		self.farate = farate = arate
		self.dm = dm = deemph
		self.discrim_dc = discrim_dc = 0
		self.capture_file = capture_file = "capture.wav"
		self.asrate = asrate = 125e3

		##################################################
		# Blocks
		##################################################
		_sq_thresh_sizer = wx.BoxSizer(wx.VERTICAL)
		self._sq_thresh_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_sq_thresh_sizer,
			value=self.sq_thresh,
			callback=self.set_sq_thresh,
			label="Mute Level",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._sq_thresh_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_sq_thresh_sizer,
			value=self.sq_thresh,
			callback=self.set_sq_thresh,
			minimum=-30.0,
			maximum=-5.0,
			num_steps=40,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_sq_thresh_sizer, 1, 5, 1, 1)
		self.input_power = gr.probe_avg_mag_sqrd_c(sq_thresh, 1.0/(samp_rate/10))
		self.dc_level = gr.probe_signal_f()
		_vol_sizer = wx.BoxSizer(wx.VERTICAL)
		self._vol_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_vol_sizer,
			value=self.vol,
			callback=self.set_vol,
			label="Volume",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._vol_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_vol_sizer,
			value=self.vol,
			callback=self.set_vol,
			minimum=0,
			maximum=11,
			num_steps=110,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_vol_sizer, 0, 3, 1, 1)
		_tone_med_sizer = wx.BoxSizer(wx.VERTICAL)
		self._tone_med_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_tone_med_sizer,
			value=self.tone_med,
			callback=self.set_tone_med,
			label="1Khz-4Khz",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._tone_med_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_tone_med_sizer,
			value=self.tone_med,
			callback=self.set_tone_med,
			minimum=0,
			maximum=10,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_tone_med_sizer, 1, 3, 1, 1)
		_tone_low_sizer = wx.BoxSizer(wx.VERTICAL)
		self._tone_low_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_tone_low_sizer,
			value=self.tone_low,
			callback=self.set_tone_low,
			label="0-1Khz",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._tone_low_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_tone_low_sizer,
			value=self.tone_low,
			callback=self.set_tone_low,
			minimum=0,
			maximum=10,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_tone_low_sizer, 1, 2, 1, 1)
		_tone_high_sizer = wx.BoxSizer(wx.VERTICAL)
		self._tone_high_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_tone_high_sizer,
			value=self.tone_high,
			callback=self.set_tone_high,
			label="4Khz-15Khz",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._tone_high_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_tone_high_sizer,
			value=self.tone_high,
			callback=self.set_tone_high,
			minimum=0,
			maximum=10,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_tone_high_sizer, 1, 4, 1, 1)
		def _squelch_probe_probe():
			while True:
				val = self.input_power.unmuted()
				try: self.set_squelch_probe(val)
				except AttributeError, e: pass
				time.sleep(1.0/(10))
		_squelch_probe_thread = threading.Thread(target=_squelch_probe_probe)
		_squelch_probe_thread.daemon = True
		_squelch_probe_thread.start()
		self._record_check_box = forms.check_box(
			parent=self.GetWin(),
			value=self.record,
			callback=self.set_record,
			label="Record Audio",
			true=True,
			false=False,
		)
		self.GridAdd(self._record_check_box, 2, 2, 1, 1)
		self.pilot_probe = gr.probe_signal_f()
		_fine_sizer = wx.BoxSizer(wx.VERTICAL)
		self._fine_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_fine_sizer,
			value=self.fine,
			callback=self.set_fine,
			label="Fine Tuning",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._fine_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_fine_sizer,
			value=self.fine,
			callback=self.set_fine,
			minimum=-50.0e3,
			maximum=50.e03,
			num_steps=400,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_fine_sizer, 1, 0, 1, 1)
		def _discrim_dc_probe():
			while True:
				val = self.dc_level.level()
				try: self.set_discrim_dc(val)
				except AttributeError, e: pass
				time.sleep(1.0/(2.5))
		_discrim_dc_thread = threading.Thread(target=_discrim_dc_probe)
		_discrim_dc_thread.daemon = True
		_discrim_dc_thread.start()
		self._capture_file_text_box = forms.text_box(
			parent=self.GetWin(),
			value=self.capture_file,
			callback=self.set_capture_file,
			label="Record Filename",
			converter=forms.str_converter(),
		)
		self.GridAdd(self._capture_file_text_box, 2, 0, 1, 2)
		self.Main = self.Main = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.Main.AddPage(grc_wxgui.Panel(self.Main), "L/R")
		self.Main.AddPage(grc_wxgui.Panel(self.Main), "FM Demod Spectrum")
		self.Add(self.Main)
		self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c(
			self.GetWin(),
			baseband_freq=0,
			dynamic_range=100,
			ref_level=0,
			ref_scale=2.0,
			sample_rate=samp_rate,
			fft_size=512,
			fft_rate=15,
			average=False,
			avg_alpha=None,
			title="Waterfall Plot",
		)
		self.Add(self.wxgui_waterfallsink2_0.win)
		self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
			self.Main.GetPage(0).GetWin(),
			title="Audio Channels (L and R)",
			sample_rate=farate,
			v_scale=0,
			v_offset=0,
			t_scale=0,
			ac_couple=False,
			xy_mode=False,
			num_inputs=2,
			trig_mode=gr.gr_TRIG_MODE_AUTO,
			y_axis_label="Rel. Audio Level",
		)
		self.Main.GetPage(0).Add(self.wxgui_scopesink2_0.win)
		self.wxgui_fftsink2_0 = fftsink2.fft_sink_f(
			self.Main.GetPage(1).GetWin(),
			baseband_freq=0,
			y_per_div=10,
			y_divs=10,
			ref_level=0,
			ref_scale=2.0,
			sample_rate=asrate,
			fft_size=1024,
			fft_rate=6,
			average=True,
			avg_alpha=0.1,
			title="FM Demod Spectrum",
			peak_hold=False,
		)
		self.Main.GetPage(1).Add(self.wxgui_fftsink2_0.win)
		self._variable_static_text_0_static_text = forms.static_text(
			parent=self.GetWin(),
			value=self.variable_static_text_0,
			callback=self.set_variable_static_text_0,
			label="RF Power ",
			converter=forms.float_converter(formatter=lambda x: "%4.1f" % x),
		)
		self.GridAdd(self._variable_static_text_0_static_text, 0, 2, 1, 1)
		self._stereo_0_check_box = forms.check_box(
			parent=self.GetWin(),
			value=self.stereo_0,
			callback=self.set_stereo_0,
			label="Stereo Detect",
			true=True,
			false=False,
		)
		self.GridAdd(self._stereo_0_check_box, 2, 5, 1, 1)
		self._stereo_check_box = forms.check_box(
			parent=self.GetWin(),
			value=self.stereo,
			callback=self.set_stereo,
			label="Stereo",
			true=True,
			false=False,
		)
		self.GridAdd(self._stereo_check_box, 2, 4, 1, 1)
		self.rtl2832_source_0 = baz.rtl_source_c(defer_creation=True)
		self.rtl2832_source_0.set_verbose(True)
		self.rtl2832_source_0.set_vid(0x0)
		self.rtl2832_source_0.set_pid(0x0)
		self.rtl2832_source_0.set_tuner_name("")
		self.rtl2832_source_0.set_default_timeout(0)
		self.rtl2832_source_0.set_use_buffer(True)
		self.rtl2832_source_0.set_fir_coefficients(([]))
		
		
		
		
		
		if self.rtl2832_source_0.create() == False: raise Exception("Failed to create RTL2832 Source: rtl2832_source_0")
		
		
		self.rtl2832_source_0.set_sample_rate(1.0e6)
		
		self.rtl2832_source_0.set_frequency(cur_freq+200e3)
		
		
		self.rtl2832_source_0.set_auto_gain_mode(False)
		self.rtl2832_source_0.set_relative_gain(True)
		self.rtl2832_source_0.set_gain(gain)
		  
		self._rtext_0_static_text = forms.static_text(
			parent=self.GetWin(),
			value=self.rtext_0,
			callback=self.set_rtext_0,
			label="CURRENT FREQUENCY>>",
			converter=forms.float_converter(),
		)
		self.GridAdd(self._rtext_0_static_text, 0, 1, 1, 1)
		def _rf_pwr_lvl_probe():
			while True:
				val = self.input_power.level()
				try: self.set_rf_pwr_lvl(val)
				except AttributeError, e: pass
				time.sleep(1.0/(2))
		_rf_pwr_lvl_thread = threading.Thread(target=_rf_pwr_lvl_probe)
		_rf_pwr_lvl_thread.daemon = True
		_rf_pwr_lvl_thread.start()
		self._preselect_chooser = forms.radio_buttons(
			parent=self.GetWin(),
			value=self.preselect,
			callback=self.set_preselect,
			label='preselect',
			choices=eval(prefreqs),
			labels=eval(prenames),
			style=wx.RA_HORIZONTAL,
		)
		self.GridAdd(self._preselect_chooser, 0, 4, 1, 1)
		def _pilot_level_probe():
			while True:
				val = self.pilot_probe.level()
				try: self.set_pilot_level(val)
				except AttributeError, e: pass
				time.sleep(1.0/(5))
		_pilot_level_thread = threading.Thread(target=_pilot_level_probe)
		_pilot_level_thread.daemon = True
		_pilot_level_thread.start()
		self.low_pass_filter_3 = gr.fir_filter_fff(1, firdes.low_pass(
			3, asrate/500, 10, 3, firdes.WIN_HAMMING, 6.76))
		self.low_pass_filter_2 = gr.fir_filter_fff(10, firdes.low_pass(
			3, asrate/50, 100, 30, firdes.WIN_HAMMING, 6.76))
		self.low_pass_filter_1 = gr.fir_filter_fff(10, firdes.low_pass(
			3, asrate/5, 1e3, 200, firdes.WIN_HAMMING, 6.76))
		self.low_pass_filter_0 = gr.fir_filter_fff(5, firdes.low_pass(
			3, asrate, 10e3, 2e3, firdes.WIN_HAMMING, 6.76))
		_igain_sizer = wx.BoxSizer(wx.VERTICAL)
		self._igain_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_igain_sizer,
			value=self.igain,
			callback=self.set_igain,
			label="RF Gain",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._igain_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_igain_sizer,
			value=self.igain,
			callback=self.set_igain,
			minimum=0,
			maximum=50,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_igain_sizer, 1, 1, 1, 1)
		_ifreq_sizer = wx.BoxSizer(wx.VERTICAL)
		self._ifreq_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_ifreq_sizer,
			value=self.ifreq,
			callback=self.set_ifreq,
			label="Center Frequency",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._ifreq_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_ifreq_sizer,
			value=self.ifreq,
			callback=self.set_ifreq,
			minimum=88.1e6,
			maximum=108.1e6,
			num_steps=200,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_ifreq_sizer, 0, 0, 1, 1)
		self.gr_wavfile_sink_0 = gr.wavfile_sink("/dev/null" if record == False else capture_file, 2, int(farate), 16)
		self.gr_sub_xx_0 = gr.sub_ff(1)
		self.gr_single_pole_iir_filter_xx_1 = gr.single_pole_iir_filter_ff(2.5/(asrate/500), 1)
		self.gr_single_pole_iir_filter_xx_0 = gr.single_pole_iir_filter_ff(1.0/(asrate/3), 1)
		self.gr_multiply_xx_1 = gr.multiply_vff(1)
		self.gr_multiply_xx_0_0 = gr.multiply_vff(1)
		self.gr_multiply_xx_0 = gr.multiply_vff(1)
		self.gr_multiply_const_vxx_3 = gr.multiply_const_vff((3.16e3 if st_enabled else 0, ))
		self.gr_multiply_const_vxx_2 = gr.multiply_const_vff((1.0 if st_enabled else 1.414, ))
		self.gr_multiply_const_vxx_1_0 = gr.multiply_const_vff((0 if st_enabled else 1, ))
		self.gr_multiply_const_vxx_1 = gr.multiply_const_vff((0 if squelch_probe == 0 else 1.0, ))
		self.gr_multiply_const_vxx_0_0 = gr.multiply_const_vff((vol*1.5*10.0, ))
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((vol*1.5*10.0 if st_enabled else 0, ))
		self.gr_keep_one_in_n_0 = gr.keep_one_in_n(gr.sizeof_float*1, int(asrate/3))
		self.gr_freq_xlating_fir_filter_xxx_0 = gr.freq_xlating_fir_filter_ccc(4, (osmo_taps), 200e3+fine+(-12e3*discrim_dc), 1.0e6)
		self.gr_fractional_interpolator_xx_0_0 = gr.fractional_interpolator_ff(0, asrate/farate)
		self.gr_fractional_interpolator_xx_0 = gr.fractional_interpolator_ff(0, asrate/farate)
		self.gr_fft_filter_xxx_1_0_0 = gr.fft_filter_fff(1, (firdes.band_pass(tone_high/10.0,asrate,3.5e3,15.0e3,5.0e3,firdes.WIN_HAMMING)), 1)
		self.gr_fft_filter_xxx_1_0 = gr.fft_filter_fff(1, (firdes.band_pass(tone_med/10.0,asrate,1.0e3,4.0e3,2.0e3,firdes.WIN_HAMMING)), 1)
		self.gr_fft_filter_xxx_1 = gr.fft_filter_fff(1, (firdes.low_pass(tone_low/10.0,asrate,1.2e3,500,firdes.WIN_HAMMING)), 1)
		self.gr_fft_filter_xxx_0_0_0 = gr.fft_filter_fff(1, (firdes.band_pass(tone_high/10.0,asrate,3.5e3,13.5e3,3.5e3,firdes.WIN_HAMMING)), 1)
		self.gr_fft_filter_xxx_0_0 = gr.fft_filter_fff(1, (firdes.band_pass(tone_med/10.0,asrate,1.0e3,4.0e3,2.0e3,firdes.WIN_HAMMING)), 1)
		self.gr_fft_filter_xxx_0 = gr.fft_filter_fff(1, (firdes.low_pass(tone_low/10.0,asrate,1.2e3,500,firdes.WIN_HAMMING)), 1)
		self.gr_divide_xx_0 = gr.divide_ff(1)
		self.gr_agc_xx_1 = gr.agc_cc(1e-2, 0.35, 1.0, 5000)
		self.gr_add_xx_2_0 = gr.add_vff(1)
		self.gr_add_xx_2 = gr.add_vff(1)
		self.gr_add_xx_1 = gr.add_vff(1)
		self.gr_add_xx_0 = gr.add_vff(1)
		self.gr_add_const_vxx_0 = gr.add_const_vff((1.0e-7, ))
		self._dm_chooser = forms.radio_buttons(
			parent=self.GetWin(),
			value=self.dm,
			callback=self.set_dm,
			label="FM Deemphasis",
			choices=[75.0e-6, 50.0e-6],
			labels=["NA", "EU"],
			style=wx.RA_HORIZONTAL,
		)
		self.GridAdd(self._dm_chooser, 0, 5, 1, 1)
		self.blks2_wfm_rcv_0 = blks2.wfm_rcv(
			quad_rate=samp_rate,
			audio_decimation=2,
		)
		self.blks2_fm_deemph_0_0 = blks2.fm_deemph(fs=farate, tau=deemph)
		self.blks2_fm_deemph_0 = blks2.fm_deemph(fs=farate, tau=deemph)
		self.band_pass_filter_2_0 = gr.fir_filter_fff(1, firdes.band_pass(
			20, asrate, 17.5e3, 17.9e3, 250, firdes.WIN_HAMMING, 6.76))
		self.band_pass_filter_2 = gr.fir_filter_fff(1, firdes.band_pass(
			10, asrate, 18.8e3, 19.2e3, 350, firdes.WIN_HAMMING, 6.76))
		self.band_pass_filter_0_0 = gr.fir_filter_fff(1, firdes.band_pass(
			1, asrate, 38e3-(15e3), 38e3+(15e3), 4.0e3, firdes.WIN_HAMMING, 6.76))
		self.audio_sink_0 = audio.sink(int(farate), "" if ahw == "Default" else ahw, True)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_add_xx_1, 0), (self.gr_fractional_interpolator_xx_0, 0))
		self.connect((self.gr_sub_xx_0, 0), (self.gr_fractional_interpolator_xx_0_0, 0))
		self.connect((self.band_pass_filter_0_0, 0), (self.gr_multiply_xx_1, 0))
		self.connect((self.gr_multiply_const_vxx_1_0, 0), (self.gr_add_xx_0, 0))
		self.connect((self.band_pass_filter_2_0, 0), (self.gr_multiply_xx_0, 0))
		self.connect((self.band_pass_filter_2_0, 0), (self.gr_multiply_xx_0, 1))
		self.connect((self.gr_multiply_xx_0_0, 0), (self.gr_divide_xx_0, 0))
		self.connect((self.gr_divide_xx_0, 0), (self.gr_single_pole_iir_filter_xx_0, 0))
		self.connect((self.gr_multiply_xx_0, 0), (self.gr_add_const_vxx_0, 0))
		self.connect((self.gr_add_const_vxx_0, 0), (self.gr_divide_xx_0, 1))
		self.connect((self.gr_single_pole_iir_filter_xx_0, 0), (self.gr_keep_one_in_n_0, 0))
		self.connect((self.gr_keep_one_in_n_0, 0), (self.pilot_probe, 0))
		self.connect((self.band_pass_filter_2, 0), (self.gr_multiply_xx_1, 2))
		self.connect((self.band_pass_filter_2, 0), (self.gr_multiply_xx_0_0, 0))
		self.connect((self.gr_multiply_const_vxx_2, 0), (self.gr_add_xx_1, 0))
		self.connect((self.gr_multiply_const_vxx_2, 0), (self.gr_sub_xx_0, 0))
		self.connect((self.gr_multiply_const_vxx_3, 0), (self.gr_sub_xx_0, 1))
		self.connect((self.gr_multiply_const_vxx_3, 0), (self.gr_add_xx_1, 1))
		self.connect((self.gr_fractional_interpolator_xx_0, 0), (self.gr_multiply_const_vxx_0_0, 0))
		self.connect((self.gr_fractional_interpolator_xx_0_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.band_pass_filter_2, 0), (self.gr_multiply_xx_1, 1))
		self.connect((self.gr_multiply_xx_1, 0), (self.gr_fft_filter_xxx_0, 0))
		self.connect((self.gr_fft_filter_xxx_1, 0), (self.gr_add_xx_2, 0))
		self.connect((self.gr_fft_filter_xxx_1_0, 0), (self.gr_add_xx_2, 1))
		self.connect((self.gr_fft_filter_xxx_1_0_0, 0), (self.gr_add_xx_2, 2))
		self.connect((self.gr_add_xx_2, 0), (self.gr_multiply_const_vxx_2, 0))
		self.connect((self.gr_add_xx_2_0, 0), (self.gr_multiply_const_vxx_3, 0))
		self.connect((self.gr_fft_filter_xxx_0, 0), (self.gr_add_xx_2_0, 0))
		self.connect((self.gr_fft_filter_xxx_0_0, 0), (self.gr_add_xx_2_0, 1))
		self.connect((self.gr_multiply_xx_1, 0), (self.gr_fft_filter_xxx_0_0, 0))
		self.connect((self.gr_fft_filter_xxx_0_0_0, 0), (self.gr_add_xx_2_0, 2))
		self.connect((self.gr_multiply_xx_1, 0), (self.gr_fft_filter_xxx_0_0_0, 0))
		self.connect((self.blks2_fm_deemph_0, 0), (self.gr_multiply_const_vxx_1_0, 0))
		self.connect((self.blks2_fm_deemph_0, 0), (self.gr_wavfile_sink_0, 0))
		self.connect((self.gr_multiply_const_vxx_1, 0), (self.gr_fft_filter_xxx_1, 0))
		self.connect((self.gr_multiply_const_vxx_1, 0), (self.gr_fft_filter_xxx_1_0, 0))
		self.connect((self.gr_multiply_const_vxx_1, 0), (self.gr_fft_filter_xxx_1_0_0, 0))
		self.connect((self.gr_multiply_const_vxx_1, 0), (self.wxgui_fftsink2_0, 0))
		self.connect((self.gr_multiply_const_vxx_0_0, 0), (self.blks2_fm_deemph_0, 0))
		self.connect((self.gr_add_xx_0, 0), (self.audio_sink_0, 1))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.blks2_fm_deemph_0_0, 0))
		self.connect((self.blks2_fm_deemph_0_0, 0), (self.gr_add_xx_0, 1))
		self.connect((self.band_pass_filter_2, 0), (self.gr_multiply_xx_0_0, 1))
		self.connect((self.gr_multiply_const_vxx_1, 0), (self.band_pass_filter_2, 0))
		self.connect((self.blks2_fm_deemph_0, 0), (self.audio_sink_0, 0))
		self.connect((self.gr_multiply_const_vxx_1, 0), (self.band_pass_filter_2_0, 0))
		self.connect((self.gr_multiply_const_vxx_1, 0), (self.band_pass_filter_0_0, 0))
		self.connect((self.gr_add_xx_0, 0), (self.gr_wavfile_sink_0, 1))
		self.connect((self.blks2_fm_deemph_0, 0), (self.wxgui_scopesink2_0, 0))
		self.connect((self.gr_add_xx_0, 0), (self.wxgui_scopesink2_0, 1))
		self.connect((self.blks2_wfm_rcv_0, 0), (self.gr_multiply_const_vxx_1, 0))
		self.connect((self.gr_agc_xx_1, 0), (self.blks2_wfm_rcv_0, 0))
		self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.gr_agc_xx_1, 0))
		self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.input_power, 0))
		self.connect((self.blks2_wfm_rcv_0, 0), (self.low_pass_filter_0, 0))
		self.connect((self.low_pass_filter_0, 0), (self.low_pass_filter_1, 0))
		self.connect((self.low_pass_filter_1, 0), (self.low_pass_filter_2, 0))
		self.connect((self.low_pass_filter_2, 0), (self.low_pass_filter_3, 0))
		self.connect((self.gr_single_pole_iir_filter_xx_1, 0), (self.dc_level, 0))
		self.connect((self.low_pass_filter_3, 0), (self.gr_single_pole_iir_filter_xx_1, 0))
		self.connect((self.rtl2832_source_0, 0), (self.gr_freq_xlating_fir_filter_xxx_0, 0))
		self.connect((self.gr_freq_xlating_fir_filter_xxx_0, 0), (self.wxgui_waterfallsink2_0, 0))
Пример #12
0
    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 = gr.file_source(gr.sizeof_short,
                                           options.in_filename,
                                           options.repeat)
          self.istoc = gr.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 = gr.agc_cc(1e-7,1.0,1.0) #1e-7
        self.am_demod = gr.complex_to_mag ()
        self.set_blacklevel = gr.add_const_ff(options.brightness +255.0)
        self.invert_and_scale = gr.multiply_const_ff (-options.contrast *128.0*255.0/(200.0))
        self.f2uc = gr.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, 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:" +filename
          print "(Use the spacebar to advance to next frames)"
          file_sink=gr.file_sink(gr.sizeof_char, filename)
          self.dst =file_sink

        if options.nframes is None:
            self.connect(self.src, self.agc)
        else:
            self.head = gr.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)
Пример #13
0
	def __init__(self, gain=25, clock_alpha=0.005, pll_alpha=0.005, deframer_sync_check=True, deframer_insync_frames=2, deframer_outsync_frames=5, viterbi_sync_threshold=0.1, viterbi_sync_check=True, viterbi_insync_frames=5, viterbi_outsync_frames=20, satellite='MeteorMN1', decim=400, freq=137.1e6, frames_file=os.environ['HOME'] + '/meteor_lrpt_frames.cadu', baseband_file=os.environ['HOME'] + '/meteor_lrpt_baseband.dat', symb_rate=72e3):
		grc_wxgui.top_block_gui.__init__(self, title="USRP2 MN1 LRPT Receiver")

		##################################################
		# Parameters
		##################################################
		self.gain = gain
		self.clock_alpha = clock_alpha
		self.pll_alpha = pll_alpha
		self.deframer_sync_check = deframer_sync_check
		self.deframer_insync_frames = deframer_insync_frames
		self.deframer_outsync_frames = deframer_outsync_frames
		self.viterbi_sync_threshold = viterbi_sync_threshold
		self.viterbi_sync_check = viterbi_sync_check
		self.viterbi_insync_frames = viterbi_insync_frames
		self.viterbi_outsync_frames = viterbi_outsync_frames
		self.satellite = satellite
		self.decim = decim
		self.freq = freq
		self.frames_file = frames_file
		self.baseband_file = baseband_file
		self.symb_rate = symb_rate

		##################################################
		# Variables
		##################################################
		self.decim_tb = decim_tb = decim
		self.symb_rate_tb = symb_rate_tb = symb_rate
		self.samp_rate = samp_rate = 100e6/decim_tb
		self.viterbi_sync_threshold_text = viterbi_sync_threshold_text = viterbi_sync_threshold
		self.viterbi_sync_after_text = viterbi_sync_after_text = viterbi_insync_frames
		self.viterbi_outofsync_after_text = viterbi_outofsync_after_text = viterbi_outsync_frames
		self.viterbi_node_sync_text = viterbi_node_sync_text = viterbi_sync_check
		self.sps = sps = samp_rate/symb_rate_tb
		self.satellite_text = satellite_text = satellite
		self.samp_rate_st = samp_rate_st = samp_rate
		self.pll_alpha_sl = pll_alpha_sl = 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.gain_tb = gain_tb = gain
		self.freq_tb = freq_tb = freq
		self.frames_file_text_inf = frames_file_text_inf = frames_file
		self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
		self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
		self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
		self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime())
		self.clock_alpha_sl = clock_alpha_sl = clock_alpha
		self.baseband_file_text_inf = baseband_file_text_inf = baseband_file

		##################################################
		# Notebooks
		##################################################
		self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "USRP Receiver")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "PLL demodulator and Clock sync")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Viterbi decoder")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
		self.Add(self.rx_ntb)

		##################################################
		# Controls
		##################################################
		self._decim_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.decim_tb,
			callback=self.set_decim_tb,
			label="Decimation",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
		self._symb_rate_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			value=self.symb_rate_tb,
			callback=self.set_symb_rate_tb,
			label="Symbol rate",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
		self._viterbi_sync_threshold_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_sync_threshold_text,
			callback=self.set_viterbi_sync_threshold_text,
			label="Viterbi node sync threshold [BER]",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_sync_threshold_text_static_text, 3, 0, 1, 1)
		self._viterbi_sync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_sync_after_text,
			callback=self.set_viterbi_sync_after_text,
			label="Valid frames for Viterbi decoder sync",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_sync_after_text_static_text, 4, 0, 1, 1)
		self._viterbi_outofsync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_outofsync_after_text,
			callback=self.set_viterbi_outofsync_after_text,
			label="Invalid frames for Viterbi decoder out of sync",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_outofsync_after_text_static_text, 5, 0, 1, 1)
		self._viterbi_node_sync_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_node_sync_text,
			callback=self.set_viterbi_node_sync_text,
			label="Viterbi node sync enable",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_node_sync_text_static_text, 2, 0, 1, 1)
		self._satellite_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.satellite_text,
			callback=self.set_satellite_text,
			label="Sat ",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0, 1, 1)
		self._samp_rate_st_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.samp_rate_st,
			callback=self.set_samp_rate_st,
			label="Sample rate",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1, 1)
		_pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._pll_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			label="PLL Alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._pll_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
		self._gain_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.gain_tb,
			callback=self.set_gain_tb,
			label="RX gain [dB]",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._gain_tb_text_box, 1, 2, 1, 1)
		self._freq_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.freq_tb,
			callback=self.set_freq_tb,
			label="Frequency",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._freq_tb_text_box, 1, 1, 1, 1)
		self._frames_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(4).GetWin(),
			value=self.frames_file_text_inf,
			callback=self.set_frames_file_text_inf,
			label="Frames filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(4).GridAdd(self._frames_file_text_inf_static_text, 3, 0, 1, 1)
		self._deframer_sync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_sync_after_text,
			callback=self.set_deframer_sync_after_text,
			label="Deframe sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
		self._deframer_nosync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_nosync_after_text,
			callback=self.set_deframer_nosync_after_text,
			label="Deframer out of sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
		self._deframer_check_sync_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_check_sync_text,
			callback=self.set_deframer_check_sync_text,
			label="Deframer check sync enable",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
		self._datetime_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(4).GetWin(),
			value=self.datetime_text,
			callback=self.set_datetime_text,
			label="Local time of aquisition start",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(4).GridAdd(self._datetime_text_static_text, 1, 0, 1, 1)
		_clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._clock_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			label="Clock alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._clock_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
		self._baseband_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(4).GetWin(),
			value=self.baseband_file_text_inf,
			callback=self.set_baseband_file_text_inf,
			label="Baseband filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(4).Add(self._baseband_file_text_inf_static_text)

		##################################################
		# Blocks
		##################################################
		self.gr_agc_xx_0 = gr.agc_cc(10e-6, 1, 1.0/32767.0, 1.0)
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(sps, clock_alpha_sl*clock_alpha_sl/4.0, 0.5, clock_alpha_sl, 0.05)
		self.gr_costas_loop_cc_0 = gr.costas_loop_cc(pll_alpha_sl, pll_alpha_sl*pll_alpha_sl/4.0, 0.07, -0.07, 4)
		self.gr_file_sink_0_1 = gr.file_sink(gr.sizeof_short*2, baseband_file)
		self.gr_float_to_complex_0 = gr.float_to_complex(1)
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((1, ))
		self.gr_null_sink_0 = gr.null_sink(gr.sizeof_gr_complex*1)
		self.gr_short_to_float_0 = gr.short_to_float()
		self.gr_short_to_float_0_0 = gr.short_to_float()
		self.gr_vector_to_streams_0 = gr.vector_to_streams(gr.sizeof_short*1, 2)
		self.root_raised_cosine_filter_0 = gr.fir_filter_ccf(1, firdes.root_raised_cosine(
			1, samp_rate, symb_rate, 0.25, int(11*samp_rate/symb_rate)))
		self.usrp2_source_xxxx2_0 = usrp2.source_16sc()
		self.usrp2_source_xxxx2_0.set_decim(decim_tb)
		self.usrp2_source_xxxx2_0.set_center_freq(freq_tb)
		self.usrp2_source_xxxx2_0.set_gain(gain_tb)
		self.wxgui_fftsink1 = fftsink2.fft_sink_c(
			self.rx_ntb.GetPage(0).GetWin(),
			baseband_freq=freq,
			y_per_div=5,
			y_divs=10,
			ref_level=15,
			ref_scale=2.0,
			sample_rate=samp_rate,
			fft_size=1024,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="Not filtered spectrum",
			peak_hold=False,
		)
		self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
		self.wxgui_fftsink2 = fftsink2.fft_sink_c(
			self.rx_ntb.GetPage(0).GetWin(),
			baseband_freq=0,
			y_per_div=5,
			y_divs=10,
			ref_level=15,
			ref_scale=2.0,
			sample_rate=samp_rate,
			fft_size=1024,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="RRC filtered spectrum",
			peak_hold=False,
		)
		self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink2.win)
		self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
			self.rx_ntb.GetPage(1).GetWin(),
			title="QPSK constellation diagram",
			sample_rate=symb_rate,
			v_scale=0.4,
			v_offset=0,
			t_scale=1/samp_rate,
			ac_couple=False,
			xy_mode=True,
			num_inputs=1,
		)
		self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_float_to_complex_0, 0), (self.wxgui_fftsink1, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_null_sink_0, 0))
		self.connect((self.root_raised_cosine_filter_0, 0), (self.wxgui_fftsink2, 0))
		self.connect((self.gr_short_to_float_0, 0), (self.gr_float_to_complex_0, 0))
		self.connect((self.gr_short_to_float_0_0, 0), (self.gr_float_to_complex_0, 1))
		self.connect((self.usrp2_source_xxxx2_0, 0), (self.gr_file_sink_0_1, 0))
		self.connect((self.usrp2_source_xxxx2_0, 0), (self.gr_vector_to_streams_0, 0))
		self.connect((self.gr_vector_to_streams_0, 1), (self.gr_short_to_float_0_0, 0))
		self.connect((self.gr_vector_to_streams_0, 0), (self.gr_short_to_float_0, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.root_raised_cosine_filter_0, 0))
		self.connect((self.gr_float_to_complex_0, 0), (self.gr_agc_xx_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.gr_costas_loop_cc_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.root_raised_cosine_filter_0, 0), (self.gr_costas_loop_cc_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.wxgui_scopesink2_1, 0))
    def __init__(
            self,
            deframer_insync_frames=2,
            viterbi_insync_frames=5,
            deframer_outsync_frames=5,
            viterbi_outsync_frames=20,
            viterbi_sync_check=True,
            viterbi_sync_threshold=0.1,
            deframer_sync_check=True,
            pll_alpha=0.005,
            freq=1691.02e6,
            gain=23,
            side="A",
            decim=25,
            symb_rate=(3500e3 / 3 + 3500e3) / 2,
            frames_file=os.environ['HOME'] + '/MetOp-AHRPT_cadu_frames.cadu',
            clock_alpha=0.05,
            baseband_file='/home/martin/GNURadioData/USRPSamples/AHRPT_MetOp-A_20100306_0758UTC_U2_d25.sam',
            satellite='MetOp'):
        grc_wxgui.top_block_gui.__init__(
            self, title="MetOp AHRPT Receiver from baseband file")

        ##################################################
        # Parameters
        ##################################################
        self.deframer_insync_frames = deframer_insync_frames
        self.viterbi_insync_frames = viterbi_insync_frames
        self.deframer_outsync_frames = deframer_outsync_frames
        self.viterbi_outsync_frames = viterbi_outsync_frames
        self.viterbi_sync_check = viterbi_sync_check
        self.viterbi_sync_threshold = viterbi_sync_threshold
        self.deframer_sync_check = deframer_sync_check
        self.pll_alpha = pll_alpha
        self.freq = freq
        self.gain = gain
        self.side = side
        self.decim = decim
        self.symb_rate = symb_rate
        self.frames_file = frames_file
        self.clock_alpha = clock_alpha
        self.baseband_file = baseband_file
        self.satellite = satellite

        ##################################################
        # Variables
        ##################################################
        self.decim_tb = decim_tb = decim
        self.symb_rate_tb = symb_rate_tb = symb_rate
        self.samp_rate = samp_rate = 100e6 / decim_tb
        self.viterbi_sync_threshold_text = viterbi_sync_threshold_text = viterbi_sync_threshold
        self.viterbi_sync_after_text = viterbi_sync_after_text = viterbi_insync_frames
        self.viterbi_outofsync_after_text = viterbi_outofsync_after_text = viterbi_outsync_frames
        self.viterbi_node_sync_text = viterbi_node_sync_text = viterbi_sync_check
        self.sps = sps = samp_rate / symb_rate_tb
        self.satellite_text = satellite_text = satellite
        self.samp_rate_st = samp_rate_st = samp_rate
        self.pll_alpha_sl = pll_alpha_sl = pll_alpha
        self.gain_tb = gain_tb = gain
        self.freq_tb = freq_tb = freq
        self.frames_file_text_inf = frames_file_text_inf = frames_file
        self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
        self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
        self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
        self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S",
                                                      localtime())
        self.clock_alpha_sl = clock_alpha_sl = clock_alpha
        self.baseband_file_text_inf = baseband_file_text_inf = 'no output file'

        ##################################################
        # Notebooks
        ##################################################
        self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "USRP Receiver")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb),
                            "PLL demodulator and Clock sync")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Viterbi decoder")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
        self.Add(self.rx_ntb)

        ##################################################
        # Controls
        ##################################################
        self._decim_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.decim_tb,
            callback=self.set_decim_tb,
            label="Decimation",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
        self._symb_rate_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            value=self.symb_rate_tb,
            callback=self.set_symb_rate_tb,
            label="Symbol rate",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
        self._viterbi_sync_threshold_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_sync_threshold_text,
            callback=self.set_viterbi_sync_threshold_text,
            label="Viterbi node sync threshold [BER]",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_sync_threshold_text_static_text, 3, 0, 1, 1)
        self._viterbi_sync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_sync_after_text,
            callback=self.set_viterbi_sync_after_text,
            label="Valid frames for Viterbi decoder sync",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_sync_after_text_static_text, 4, 0, 1, 1)
        self._viterbi_outofsync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_outofsync_after_text,
            callback=self.set_viterbi_outofsync_after_text,
            label="Invalid frames for Viterbi decoder out of sync",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_outofsync_after_text_static_text, 5, 0, 1, 1)
        self._viterbi_node_sync_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_node_sync_text,
            callback=self.set_viterbi_node_sync_text,
            label="Viterbi node sync enable",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_node_sync_text_static_text, 2, 0, 1, 1)
        self._satellite_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.satellite_text,
            callback=self.set_satellite_text,
            label="Sat ",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0,
                                       1, 1)
        self._samp_rate_st_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.samp_rate_st,
            callback=self.set_samp_rate_st,
            label="Sample rate",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1,
                                       1)
        _pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._pll_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            label="PLL Alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._pll_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
        self._gain_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.gain_tb,
            callback=self.set_gain_tb,
            label="RX gain [dB]",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._gain_tb_text_box, 1, 2, 1, 1)
        self._freq_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.freq_tb,
            callback=self.set_freq_tb,
            label="Frequency",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._freq_tb_text_box, 1, 1, 1, 1)
        self._frames_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.frames_file_text_inf,
            callback=self.set_frames_file_text_inf,
            label="Frames filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(self._frames_file_text_inf_static_text,
                                       3, 0, 1, 1)
        self._deframer_sync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_sync_after_text,
            callback=self.set_deframer_sync_after_text,
            label="Deframe sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
        self._deframer_nosync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_nosync_after_text,
            callback=self.set_deframer_nosync_after_text,
            label="Deframer out of sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
        self._deframer_check_sync_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_check_sync_text,
            callback=self.set_deframer_check_sync_text,
            label="Deframer check sync enable",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
        self._datetime_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.datetime_text,
            callback=self.set_datetime_text,
            label="Local time of aquisition start",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(self._datetime_text_static_text, 1, 0,
                                       1, 1)
        _clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._clock_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            label="Clock alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._clock_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
        self._baseband_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.baseband_file_text_inf,
            callback=self.set_baseband_file_text_inf,
            label="Baseband filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(
            self._baseband_file_text_inf_static_text, 4, 0, 1, 1)

        ##################################################
        # Blocks
        ##################################################
        self.cs2cf = gr.interleaved_short_to_complex()
        self.gr_agc_xx_0 = gr.agc_cc(10e-6, 1, 1.0 / 32767.0, 1.0)
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(
            sps, clock_alpha_sl * clock_alpha_sl / 4.0, 0.5, clock_alpha_sl,
            0.05)
        self.gr_costas_loop_cc_0 = gr.costas_loop_cc(
            pll_alpha_sl, pll_alpha_sl * pll_alpha_sl / 4.0, 0.07, -0.07, 4)
        self.gr_file_source_0 = gr.file_source(gr.sizeof_short * 1,
                                               baseband_file, True)
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((1, ))
        self.gr_null_sink_0 = gr.null_sink(gr.sizeof_gr_complex * 1)
        self.gr_throttle_0 = gr.throttle(gr.sizeof_short * 1, samp_rate * 2)
        self.wxgui_fftsink1 = fftsink2.fft_sink_c(
            self.rx_ntb.GetPage(0).GetWin(),
            baseband_freq=freq,
            y_per_div=5,
            y_divs=10,
            ref_level=-15,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="Not filtered spectrum",
            peak_hold=False,
        )
        self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
        self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
            self.rx_ntb.GetPage(1).GetWin(),
            title="QPSK constellation diagram",
            sample_rate=symb_rate,
            v_scale=0.4,
            v_offset=0,
            t_scale=1 / samp_rate,
            ac_couple=False,
            xy_mode=True,
            num_inputs=1,
        )
        self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.gr_costas_loop_cc_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.gr_agc_xx_0, 0), (self.gr_costas_loop_cc_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.cs2cf, 0))
        self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0))
        self.connect((self.cs2cf, 0), (self.gr_agc_xx_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.wxgui_scopesink2_1, 0))
        self.connect((self.gr_agc_xx_0, 0), (self.wxgui_fftsink1, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.gr_null_sink_0, 0))
Пример #15
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 = gr.file_source(gr.sizeof_short,filename,options.repeat)
          self.istoc = gr.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=gr.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=gr.file_sink(gr.sizeof_char, options.out_filename)
          self.dst =file_sink

        self.agc=gr.agc_cc(1e-7,1.0,1.0) #1e-7
        self.am_demod = gr.complex_to_mag ()
        self.set_blacklevel=gr.add_const_ff(0.0)
        self.invert_and_scale = gr.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=gr.complex_to_real()
          nullsink=gr.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=gr.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 = gr.sig_source_f (usrp_rate, gr.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")
Пример #16
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="USRP HRPT Receiver")

        ##################################################
        # Variables
        ##################################################
        self.config_filename = config_filename = "usrp_rx_hrpt.cfg"
        self._decim_config = ConfigParser.ConfigParser()
        self._decim_config.read(config_filename)
        try:
            decim = self._decim_config.getfloat("usrp", "decim")
        except:
            decim = 16
        self.decim = decim
        self.sym_rate = sym_rate = 600 * 1109
        self.sample_rate = sample_rate = 64e6 / decim
        self.sps = sps = sample_rate / sym_rate
        self._side_config = ConfigParser.ConfigParser()
        self._side_config.read(config_filename)
        try:
            side = self._side_config.get("usrp", "side")
        except:
            side = "A"
        self.side = side
        self._saved_sync_alpha_config = ConfigParser.ConfigParser()
        self._saved_sync_alpha_config.read(config_filename)
        try:
            saved_sync_alpha = self._saved_sync_alpha_config.getfloat("demod", "sync_alpha")
        except:
            saved_sync_alpha = 0.05
        self.saved_sync_alpha = saved_sync_alpha
        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("demod", "pll_alpha")
        except:
            saved_pll_alpha = 0.05
        self.saved_pll_alpha = saved_pll_alpha
        self._saved_gain_config = ConfigParser.ConfigParser()
        self._saved_gain_config.read(config_filename)
        try:
            saved_gain = self._saved_gain_config.getfloat("usrp", "gain")
        except:
            saved_gain = 35
        self.saved_gain = saved_gain
        self._saved_freq_config = ConfigParser.ConfigParser()
        self._saved_freq_config.read(config_filename)
        try:
            saved_freq = self._saved_freq_config.getfloat("usrp", "freq")
        except:
            saved_freq = 1698e6
        self.saved_freq = saved_freq
        self.hs = hs = int(sps / 2.0)
        self.sync_alpha = sync_alpha = saved_sync_alpha
        self.side_text = side_text = side
        self.pll_alpha = pll_alpha = saved_pll_alpha
        self._output_filename_config = ConfigParser.ConfigParser()
        self._output_filename_config.read(config_filename)
        try:
            output_filename = self._output_filename_config.get("output", "filename")
        except:
            output_filename = "frames.dat"
        self.output_filename = output_filename
        self.mf_taps = mf_taps = [-0.5 / hs] * hs + [0.5 / hs] * hs
        self.max_sync_offset = max_sync_offset = 0.01
        self.max_carrier_offset = max_carrier_offset = 2 * math.pi * 100e3 / sample_rate
        self.gain = gain = saved_gain
        self.freq = freq = saved_freq
        self.decim_text = decim_text = decim

        ##################################################
        # Notebooks
        ##################################################
        self.displays = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "RX")
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "Demod")
        self.GridAdd(self.displays, 2, 0, 1, 4)

        ##################################################
        # Controls
        ##################################################
        _sync_alpha_sizer = wx.BoxSizer(wx.VERTICAL)
        self._sync_alpha_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_sync_alpha_sizer,
            value=self.sync_alpha,
            callback=self.set_sync_alpha,
            label="SYNC Alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._sync_alpha_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_sync_alpha_sizer,
            value=self.sync_alpha,
            callback=self.set_sync_alpha,
            minimum=0.0,
            maximum=0.5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_sync_alpha_sizer, 0, 3, 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, 1, 0, 1, 1)
        _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.0,
            maximum=0.5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_pll_alpha_sizer, 0, 2, 1, 1)
        _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="RX 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=100,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_gain_sizer, 0, 1, 1, 1)
        self._freq_text_box = forms.text_box(
            parent=self.GetWin(),
            value=self.freq,
            callback=self.set_freq,
            label="Frequency",
            converter=forms.float_converter(),
        )
        self.GridAdd(self._freq_text_box, 0, 0, 1, 1)
        self._decim_text_static_text = forms.static_text(
            parent=self.GetWin(),
            value=self.decim_text,
            callback=self.set_decim_text,
            label="Decimation",
            converter=forms.float_converter(),
        )
        self.GridAdd(self._decim_text_static_text, 1, 1, 1, 1)

        ##################################################
        # Blocks
        ##################################################
        self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)
        self.decoder = noaa.hrpt_decoder()
        self.deframer = noaa.hrpt_deframer()
        self.frame_sink = gr.file_sink(gr.sizeof_short * 1, output_filename)
        self.gr_fir_filter_xxx_0 = gr.fir_filter_ccc(1, (mf_taps))
        self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha ** 2 / 4.0, max_carrier_offset)
        self.pll_scope = scopesink2.scope_sink_f(
            self.displays.GetPage(1).GetWin(),
            title="Demod Waveform",
            sample_rate=sample_rate,
            v_scale=0.5,
            t_scale=20.0 / sample_rate,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
        )
        self.displays.GetPage(1).GridAdd(self.pll_scope.win, 0, 0, 1, 1)
        self.rx_fft = fftsink2.fft_sink_c(
            self.displays.GetPage(0).GetWin(),
            baseband_freq=freq,
            y_per_div=5,
            y_divs=8,
            ref_level=-5,
            ref_scale=2.0,
            sample_rate=sample_rate,
            fft_size=1024,
            fft_rate=15,
            average=True,
            avg_alpha=0.1,
            title="RX Spectrum",
            peak_hold=False,
        )
        self.displays.GetPage(0).GridAdd(self.rx_fft.win, 0, 0, 1, 1)
        self.rx_scope = scopesink2.scope_sink_c(
            self.displays.GetPage(0).GetWin(),
            title="RX Waveform",
            sample_rate=sample_rate,
            v_scale=0,
            t_scale=20.0 / sample_rate,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
        )
        self.displays.GetPage(0).GridAdd(self.rx_scope.win, 1, 0, 1, 1)
        self.sync = noaa.hrpt_sync_fb(sync_alpha, sync_alpha ** 2 / 4.0, sps, max_sync_offset)
        self.usrp_source = grc_usrp.simple_source_c(which=0, side=side, rx_ant="RXA")
        self.usrp_source.set_decim_rate(decim)
        self.usrp_source.set_frequency(freq, verbose=True)
        self.usrp_source.set_gain(gain)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.deframer, 0), (self.frame_sink, 0))
        self.connect((self.sync, 0), (self.deframer, 0))
        self.connect((self.pll, 0), (self.sync, 0))
        self.connect((self.pll, 0), (self.pll_scope, 0))
        self.connect((self.agc, 0), (self.rx_scope, 0))
        self.connect((self.agc, 0), (self.rx_fft, 0))
        self.connect((self.deframer, 0), (self.decoder, 0))
        self.connect((self.agc, 0), (self.gr_fir_filter_xxx_0, 0))
        self.connect((self.gr_fir_filter_xxx_0, 0), (self.pll, 0))
        self.connect((self.usrp_source, 0), (self.agc, 0))
Пример #17
0
	def __init__(self):
		gr.top_block.__init__(self, "USRP HRPT Receiver")

		##################################################
		# Variables
		##################################################
		self.sym_rate = sym_rate = 600*1109
		self.sample_rate = sample_rate = 4e6
		self.sps = sps = sample_rate/sym_rate
		self.config_filename = config_filename = os.environ['HOME']+'/.gnuradio/config.conf'
		self._pll_alpha_config = ConfigParser.ConfigParser()
		self._pll_alpha_config.read(config_filename)
		try: pll_alpha = self._pll_alpha_config.getfloat('usrp_rx_hrpt', 'pll_alpha')
		except: pll_alpha = 0.01
		self.pll_alpha = pll_alpha
		self._output_filename_config = ConfigParser.ConfigParser()
		self._output_filename_config.read(config_filename)
		try: output_filename = self._output_filename_config.get('usrp_rx_hrpt', 'filename')
		except: output_filename = 'frames.hrpt'
		self.output_filename = output_filename
		self.max_clock_offset = max_clock_offset = 100e-6
		self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/sample_rate
		self.hs = hs = int(sps/2.0)
		self._gain_config = ConfigParser.ConfigParser()
		self._gain_config.read(config_filename)
		try: gain = self._gain_config.getfloat('usrp_rx_hrpt', 'gain')
		except: gain = 35
		self.gain = gain
		self._freq_config = ConfigParser.ConfigParser()
		self._freq_config.read(config_filename)
		try: freq = self._freq_config.getfloat('usrp_rx_hrpt', 'freq')
		except: freq = 1698e6
		self.freq = freq
		self._clock_alpha_config = ConfigParser.ConfigParser()
		self._clock_alpha_config.read(config_filename)
		try: clock_alpha = self._clock_alpha_config.getfloat('usrp_rx_hrpt', 'clock_alpha')
		except: clock_alpha = 0.01
		self.clock_alpha = clock_alpha

		##################################################
		# Blocks
		##################################################
		self.throttle = gr.throttle(gr.sizeof_short*1, 2*sample_rate)
		self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset)
		self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0/hs, 4000)
		self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex()
		self.gr_file_source_0 = gr.file_source(gr.sizeof_short*1, "input_filename", False)
		self.frame_sink = gr.file_sink(gr.sizeof_short*1, output_filename)
		self.frame_sink.set_unbuffered(False)
		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.deframer = noaa.hrpt_deframer()
		self.decoder = noaa.hrpt_decoder(True,True)
		self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_moving_average_xx_0, 0), (self.digital_clock_recovery_mm_xx_0, 0))
		self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.agc, 0), (self.pll, 0))
		self.connect((self.deframer, 0), (self.decoder, 0))
		self.connect((self.deframer, 0), (self.frame_sink, 0))
		self.connect((self.gr_interleaved_short_to_complex_0, 0), (self.agc, 0))
		self.connect((self.throttle, 0), (self.gr_interleaved_short_to_complex_0, 0))
		self.connect((self.gr_file_source_0, 0), (self.throttle, 0))
		self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.digital_binary_slicer_fb_0, 0))
		self.connect((self.digital_binary_slicer_fb_0, 0), (self.deframer, 0))
    def __init__(self,
                 frames_file=os.environ['HOME'] + '/NOAA-XX.hrpt',
                 decim=32,
                 satellite='NOAA-XX',
                 baseband_file=os.environ['HOME'] + '/NOAA-XX.dat',
                 sync_check=False):
        grc_wxgui.top_block_gui.__init__(self,
                                         title="NOAA HRPT Baseband To Frames")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Parameters
        ##################################################
        self.frames_file = frames_file
        self.decim = decim
        self.satellite = satellite
        self.baseband_file = baseband_file
        self.sync_check = sync_check

        ##################################################
        # Variables
        ##################################################
        self.sym_rate = sym_rate = 600 * 1109
        self.sample_rate = sample_rate = 64e6 / decim
        self.config_filename = config_filename = os.environ[
            'HOME'] + '/.gnuradio/noaa_hrpt.conf'
        self.sps = sps = sample_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(
                "satname", 'pll_alpha')
        except:
            saved_pll_alpha = 0.01
        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(
                "satname", 'clock_alpha')
        except:
            saved_clock_alpha = 0.01
        self.saved_clock_alpha = saved_clock_alpha
        self.sync_check_txt = sync_check_txt = sync_check
        self.satname_txt = satname_txt = satellite
        self.pll_alpha = pll_alpha = saved_pll_alpha
        self.max_clock_offset = max_clock_offset = 100e-6
        self.max_carrier_offset = max_carrier_offset = 2 * math.pi * 100e3 / sample_rate
        self.hs = hs = int(sps / 2.0)
        self.frames_file_txt = frames_file_txt = frames_file
        self.decim_txt = decim_txt = decim
        self.clock_alpha = clock_alpha = saved_clock_alpha
        self.baseband_file_txt = baseband_file_txt = baseband_file

        ##################################################
        # Notebooks
        ##################################################
        self.displays = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.displays.AddPage(grc_wxgui.Panel(self.displays),
                              "NOAA HRPT Spectrum")
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "Information")
        self.Add(self.displays)

        ##################################################
        # Controls
        ##################################################
        self._sync_check_txt_static_text = forms.static_text(
            parent=self.GetWin(),
            value=self.sync_check_txt,
            callback=self.set_sync_check_txt,
            label="Sync check",
            converter=forms.int_converter(),
        )
        self.GridAdd(self._sync_check_txt_static_text, 0, 3, 1, 1)
        self._satname_txt_static_text = forms.static_text(
            parent=self.GetWin(),
            value=self.satname_txt,
            callback=self.set_satname_txt,
            label="Satellite",
            converter=forms.str_converter(),
        )
        self.GridAdd(self._satname_txt_static_text, 0, 0, 1, 1)
        _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.0,
            maximum=0.5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_pll_alpha_sizer, 1, 0, 1, 1)
        self._frames_file_txt_static_text = forms.static_text(
            parent=self.displays.GetPage(1).GetWin(),
            value=self.frames_file_txt,
            callback=self.set_frames_file_txt,
            label="Frames output filename",
            converter=forms.str_converter(),
        )
        self.displays.GetPage(1).GridAdd(self._frames_file_txt_static_text, 2,
                                         0, 1, 1)
        self._decim_txt_static_text = forms.static_text(
            parent=self.GetWin(),
            value=self.decim_txt,
            callback=self.set_decim_txt,
            label="Decimation",
            converter=forms.str_converter(),
        )
        self.GridAdd(self._decim_txt_static_text, 0, 1, 1, 1)
        _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.0,
            maximum=0.5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_clock_alpha_sizer, 1, 1, 1, 1)
        self._baseband_file_txt_static_text = forms.static_text(
            parent=self.displays.GetPage(1).GetWin(),
            value=self.baseband_file_txt,
            callback=self.set_baseband_file_txt,
            label="Baseband filename",
            converter=forms.str_converter(),
        )
        self.displays.GetPage(1).GridAdd(self._baseband_file_txt_static_text,
                                         1, 0, 1, 1)

        ##################################################
        # Blocks
        ##################################################
        self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)
        self.decoder = noaa.hrpt_decoder(True, False)
        self.frame_sink = gr.file_sink(gr.sizeof_short * 1,
                                       "/home/jerry/NOAA-XX.hrpt")
        self.frame_sink.set_unbuffered(False)
        self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(
            sps / 2.0, clock_alpha**2 / 4.0, 0.5, clock_alpha,
            max_clock_offset)
        self.gr_file_source_0 = gr.file_source(
            gr.sizeof_short * 1,
            "/home/jerry/hrpt/baseband/NOAA-18/2011-01-07T132821-NOAA-18.dat",
            False)
        self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex(
        )
        self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0 / hs, 4000)
        self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2 / 4.0,
                                    max_carrier_offset)
        self.poesweather_noaa_hrpt_deframer_0 = poesweather.noaa_hrpt_deframer(
            sync_check)
        self.rx_fft = fftsink2.fft_sink_c(
            self.displays.GetPage(0).GetWin(),
            baseband_freq=0,
            y_per_div=5,
            y_divs=10,
            ref_level=45,
            ref_scale=2.0,
            sample_rate=sample_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="NOAA HRPT Spectrum",
            peak_hold=False,
        )
        self.displays.GetPage(0).Add(self.rx_fft.win)
        self.throttle = gr.throttle(gr.sizeof_short * 1, sample_rate * 10)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_interleaved_short_to_complex_0, 0),
                     (self.agc, 0))
        self.connect((self.throttle, 0),
                     (self.gr_interleaved_short_to_complex_0, 0))
        self.connect((self.gr_file_source_0, 0), (self.throttle, 0))
        self.connect((self.agc, 0), (self.rx_fft, 0))
        self.connect((self.poesweather_noaa_hrpt_deframer_0, 0),
                     (self.frame_sink, 0))
        self.connect((self.poesweather_noaa_hrpt_deframer_0, 0),
                     (self.decoder, 0))
        self.connect((self.gr_binary_slicer_fb_0, 0),
                     (self.poesweather_noaa_hrpt_deframer_0, 0))
        self.connect((self.agc, 0), (self.pll, 0))
        self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
        self.connect((self.gr_moving_average_xx_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_binary_slicer_fb_0, 0))
Пример #19
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="USRP LRIT Receiver")

		##################################################
		# Variables
		##################################################
		self.config_filename = config_filename = "usrp_rx_lrit.cfg"
		self._saved_decim_config = ConfigParser.ConfigParser()
		self._saved_decim_config.read(config_filename)
		try: saved_decim = self._saved_decim_config.getint("main", "decim")
		except: saved_decim = 160
		self.saved_decim = saved_decim
		self.decim = decim = saved_decim
		self.symbol_rate = symbol_rate = 293e3
		self._saved_gain_mu_config = ConfigParser.ConfigParser()
		self._saved_gain_mu_config.read(config_filename)
		try: saved_gain_mu = self._saved_gain_mu_config.getfloat("main", "gain_mu")
		except: saved_gain_mu = 0.005
		self.saved_gain_mu = saved_gain_mu
		self._saved_gain_config = ConfigParser.ConfigParser()
		self._saved_gain_config.read(config_filename)
		try: saved_gain = self._saved_gain_config.getfloat("main", "gain")
		except: saved_gain = 33
		self.saved_gain = saved_gain
		self._saved_freq_config = ConfigParser.ConfigParser()
		self._saved_freq_config.read(config_filename)
		try: saved_freq = self._saved_freq_config.getfloat("main", "freq")
		except: saved_freq = 137e6
		self.saved_freq = saved_freq
		self._saved_costas_alpha_config = ConfigParser.ConfigParser()
		self._saved_costas_alpha_config.read(config_filename)
		try: saved_costas_alpha = self._saved_costas_alpha_config.getfloat("main", "costas_alpha")
		except: saved_costas_alpha = 0.005
		self.saved_costas_alpha = saved_costas_alpha
		self.samp_rate = samp_rate = 64e6/decim
		self.sps = sps = samp_rate/symbol_rate
		self.gain_mu = gain_mu = saved_gain_mu
		self.gain = gain = saved_gain
		self.freq = freq = saved_freq
		self.costas_alpha = costas_alpha = saved_costas_alpha

		##################################################
		# Notebooks
		##################################################
		self.displays = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.displays.AddPage(grc_wxgui.Panel(self.displays), "USRP RX")
		self.displays.AddPage(grc_wxgui.Panel(self.displays), "Costas Output")
		self.GridAdd(self.displays, 2, 0, 1, 3)

		##################################################
		# Controls
		##################################################
		self._decim_text_box = forms.text_box(
			parent=self.GetWin(),
			value=self.decim,
			callback=self.set_decim,
			label="Decim",
			converter=forms.int_converter(),
		)
		self.GridAdd(self._decim_text_box, 0, 0, 1, 1)
		_gain_mu_sizer = wx.BoxSizer(wx.VERTICAL)
		self._gain_mu_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_gain_mu_sizer,
			value=self.gain_mu,
			callback=self.set_gain_mu,
			label="Gain Mu",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._gain_mu_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_gain_mu_sizer,
			value=self.gain_mu,
			callback=self.set_gain_mu,
			minimum=0,
			maximum=0.5,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_gain_mu_sizer, 1, 1, 1, 1)
		_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=115,
			num_steps=115,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_gain_sizer, 0, 1, 1, 1)
		_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=135e6,
			maximum=139e6,
			num_steps=400,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_freq_sizer, 0, 2, 1, 1)
		_costas_alpha_sizer = wx.BoxSizer(wx.VERTICAL)
		self._costas_alpha_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_costas_alpha_sizer,
			value=self.costas_alpha,
			callback=self.set_costas_alpha,
			label="Costas Alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._costas_alpha_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_costas_alpha_sizer,
			value=self.costas_alpha,
			callback=self.set_costas_alpha,
			minimum=0,
			maximum=0.5,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_costas_alpha_sizer, 1, 0, 1, 1)

		##################################################
		# Blocks
		##################################################
		self.gr_add_const_vxx_0 = gr.add_const_vff((48.0, ))
		self.gr_agc_xx_0 = gr.agc_cc(1e-6, 1.0, 1.0/32767.0, 1.0)
		self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
		self.gr_char_to_float_0 = gr.char_to_float()
		self.gr_complex_to_real_0 = gr.complex_to_real(1)
		self.gr_file_sink_0 = gr.file_sink(gr.sizeof_char*1, "bits.dat")
		self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1, "lrit.dat", False)
		self.gr_float_to_char_0 = gr.float_to_char()
		self.gr_mpsk_receiver_cc_0 = gr.mpsk_receiver_cc(2, 0, costas_alpha, costas_alpha*costas_alpha/4.0, -0.05, 0.05, 0.5, gain_mu, sps, gain_mu*gain_mu/4.0, 0.05)
		self.gr_probe_mpsk_snr_c_0 = grc_blks2.probe_mpsk_snr_c(
			type='snr',
			alpha=0.0001,
			probe_rate=10,
		)
		self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate)
		self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
			self.displays.GetPage(0).GetWin(),
			baseband_freq=freq,
			y_per_div=10,
			y_divs=10,
			ref_level=50,
			sample_rate=samp_rate,
			fft_size=1024,
			fft_rate=30,
			average=False,
			avg_alpha=None,
			title="Spectrum",
			peak_hold=False,
		)
		self.displays.GetPage(0).GridAdd(self.wxgui_fftsink2_0.win, 0, 0, 1, 1)
		self.wxgui_numbersink2_0 = numbersink2.number_sink_f(
			self.displays.GetPage(1).GetWin(),
			unit="dB",
			minval=0,
			maxval=30,
			factor=1.0,
			decimal_places=1,
			ref_level=0,
			sample_rate=10,
			number_rate=10,
			average=False,
			avg_alpha=None,
			label="SNR",
			peak_hold=False,
			show_gauge=True,
		)
		self.displays.GetPage(1).GridAdd(self.wxgui_numbersink2_0.win, 2, 0, 1, 1)
		self.wxgui_scopesink2_0 = scopesink2.scope_sink_c(
			self.displays.GetPage(0).GetWin(),
			title="Waveform",
			sample_rate=samp_rate,
			v_scale=0.5,
			t_scale=20.0/samp_rate,
			ac_couple=False,
			xy_mode=True,
			num_inputs=1,
		)
		self.displays.GetPage(0).GridAdd(self.wxgui_scopesink2_0.win, 1, 0, 1, 1)
		self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
			self.displays.GetPage(1).GetWin(),
			title="Scope Plot",
			sample_rate=samp_rate,
			v_scale=0.4,
			t_scale=20.0/samp_rate,
			ac_couple=False,
			xy_mode=True,
			num_inputs=1,
		)
		self.displays.GetPage(1).GridAdd(self.wxgui_scopesink2_1.win, 0, 0, 1, 1)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_agc_xx_0, 0), (self.wxgui_scopesink2_0, 0))
		self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.gr_throttle_0, 0), (self.gr_agc_xx_0, 0))
		self.connect((self.gr_probe_mpsk_snr_c_0, 0), (self.wxgui_numbersink2_0, 0))
		self.connect((self.gr_mpsk_receiver_cc_0, 0), (self.gr_probe_mpsk_snr_c_0, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.gr_mpsk_receiver_cc_0, 0))
		self.connect((self.gr_mpsk_receiver_cc_0, 0), (self.wxgui_scopesink2_1, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.wxgui_fftsink2_0, 0))
		self.connect((self.gr_mpsk_receiver_cc_0, 0), (self.gr_complex_to_real_0, 0))
		self.connect((self.gr_complex_to_real_0, 0), (self.gr_binary_slicer_fb_0, 0))
		self.connect((self.gr_binary_slicer_fb_0, 0), (self.gr_char_to_float_0, 0))
		self.connect((self.gr_char_to_float_0, 0), (self.gr_add_const_vxx_0, 0))
		self.connect((self.gr_add_const_vxx_0, 0), (self.gr_float_to_char_0, 0))
		self.connect((self.gr_float_to_char_0, 0), (self.gr_file_sink_0, 0))
	def __init__(self, satellite='NOAAxx', decim=50, baseband_file="/home/martin/GNURadioData/hrpt/baseband/HRPT_NOAA19_2010-09-10_12-35-34_UTC_U2_d50.sam", frames_file=os.environ['HOME'] + '/noaa_hrpt_frames.hmf', deframer_outsync_frames=5, deframer_insync_frames=2, clock_alpha=0.005, gain_mu=0.005, pll_alpha=0.005, pll_beta=0.00001, deframer_sync_check=True, symb_rate=600*1109):
		grc_wxgui.top_block_gui.__init__(self, title="NOAA HRPT Receiver from baseband file")
		_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.decim = decim
		self.baseband_file = baseband_file
		self.frames_file = frames_file
		self.deframer_outsync_frames = deframer_outsync_frames
		self.deframer_insync_frames = deframer_insync_frames
		self.clock_alpha = clock_alpha
		self.gain_mu = gain_mu
		self.pll_alpha = pll_alpha
		self.pll_beta = pll_beta
		self.deframer_sync_check = deframer_sync_check
		self.symb_rate = symb_rate

		##################################################
		# Variables
		##################################################
		self.decim_tb = decim_tb = decim
		self.symb_rate_tb = symb_rate_tb = symb_rate
		self.samp_rate = samp_rate = 100e6/decim_tb
		self.sps = sps = samp_rate/symb_rate_tb
		self.satellite_text = satellite_text = satellite
		self.samp_rate_st = samp_rate_st = samp_rate
		self.pll_beta_sl = pll_beta_sl = pll_beta
		self.pll_alpha_sl = pll_alpha_sl = 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_mu_sl = gain_mu_sl = gain_mu
		self.frames_file_text_inf = frames_file_text_inf = frames_file
		self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
		self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
		self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
		self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime())
		self.clock_alpha_sl = clock_alpha_sl = clock_alpha
		self.baseband_file_text_inf = baseband_file_text_inf = baseband_file

		##################################################
		# Notebooks
		##################################################
		self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Input baseband")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "PLL demodulator and Clock sync")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
		self.Add(self.rx_ntb)

		##################################################
		# Controls
		##################################################
		self._decim_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.decim_tb,
			callback=self.set_decim_tb,
			label="Decimation",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
		self._symb_rate_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			value=self.symb_rate_tb,
			callback=self.set_symb_rate_tb,
			label="Symbol rate",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
		self._satellite_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.satellite_text,
			callback=self.set_satellite_text,
			label="Sat ",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0, 1, 1)
		self._samp_rate_st_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.samp_rate_st,
			callback=self.set_samp_rate_st,
			label="Sample rate",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1, 1)
		_pll_beta_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._pll_beta_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_beta_sl_sizer,
			value=self.pll_beta_sl,
			callback=self.set_pll_beta_sl,
			label="PLL Beta",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._pll_beta_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_beta_sl_sizer,
			value=self.pll_beta_sl,
			callback=self.set_pll_beta_sl,
			minimum=0.000001,
			maximum=0.001,
			num_steps=1000,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_pll_beta_sl_sizer, 2, 0, 1, 1)
		_pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._pll_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			label="PLL Alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._pll_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
		_gain_mu_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._gain_mu_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_gain_mu_sl_sizer,
			value=self.gain_mu_sl,
			callback=self.set_gain_mu_sl,
			label="Gain MU",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._gain_mu_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_gain_mu_sl_sizer,
			value=self.gain_mu_sl,
			callback=self.set_gain_mu_sl,
			minimum=0.0001,
			maximum=0.01,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_gain_mu_sl_sizer, 1, 2, 1, 1)
		self._frames_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.frames_file_text_inf,
			callback=self.set_frames_file_text_inf,
			label="Frames filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._frames_file_text_inf_static_text, 3, 0, 1, 1)
		self._deframer_sync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.deframer_sync_after_text,
			callback=self.set_deframer_sync_after_text,
			label="Deframe sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
		self._deframer_nosync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.deframer_nosync_after_text,
			callback=self.set_deframer_nosync_after_text,
			label="Deframer out of sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
		self._deframer_check_sync_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.deframer_check_sync_text,
			callback=self.set_deframer_check_sync_text,
			label="Deframer check sync enable",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
		self._datetime_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.datetime_text,
			callback=self.set_datetime_text,
			label="Local time of aquisition start",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._datetime_text_static_text, 1, 0, 1, 1)
		_clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._clock_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			label="Clock alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._clock_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
		self._baseband_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.baseband_file_text_inf,
			callback=self.set_baseband_file_text_inf,
			label="Baseband filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._baseband_file_text_inf_static_text, 4, 0, 1, 1)

		##################################################
		# Blocks
		##################################################
		self.cs2cf = gr.interleaved_short_to_complex()
		self.gr_agc_xx_0_0 = gr.agc_cc(10e-6, 1, 1.0/32767.0, 1.0)
		self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(sps/2.0, clock_alpha**2/4.0, 0.5, gain_mu_sl, max_clock_offset)
		self.gr_complex_to_real_0 = gr.complex_to_real(1)
		self.gr_costas_loop_cc_0 = gr.costas_loop_cc(pll_alpha_sl, pll_beta_sl, 0.07, -0.07, 2)
		self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_short*1, frames_file)
		self.gr_file_sink_0_0.set_unbuffered(False)
		self.gr_file_source_0 = gr.file_source(gr.sizeof_short*1, baseband_file, False)
		self.gr_moving_average_xx_0 = gr.moving_average_cc(hs, 1.0/hs, 4000)
		self.gr_throttle_0 = gr.throttle(gr.sizeof_short*1, samp_rate*2)
		self.noaa_hrpt_decoder_0 = noaa.hrpt_decoder(True,False)
		self.poesweather_univ_hrpt_deframer_0 = poesweather.univ_hrpt_deframer(deframer_sync_check, 11090, deframer_insync_frames, deframer_outsync_frames)
		self.wxgui_fftsink1 = fftsink2.fft_sink_c(
			self.rx_ntb.GetPage(0).GetWin(),
			baseband_freq=0,
			y_per_div=5,
			y_divs=10,
			ref_level=50,
			ref_scale=2.0,
			sample_rate=samp_rate,
			fft_size=1024,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="Not filtered spectrum",
			peak_hold=False,
		)
		self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
		self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
			self.rx_ntb.GetPage(1).GetWin(),
			title="PSK constellation diagram",
			sample_rate=symb_rate,
			v_scale=0.4,
			v_offset=0,
			t_scale=1/samp_rate,
			ac_couple=False,
			xy_mode=True,
			num_inputs=1,
			trig_mode=gr.gr_TRIG_MODE_AUTO,
		)
		self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.gr_throttle_0, 0), (self.cs2cf, 0))
		self.connect((self.cs2cf, 0), (self.gr_agc_xx_0_0, 0))
		self.connect((self.cs2cf, 0), (self.wxgui_fftsink1, 0))
		self.connect((self.gr_complex_to_real_0, 0), (self.gr_binary_slicer_fb_0, 0))
		self.connect((self.poesweather_univ_hrpt_deframer_0, 0), (self.gr_file_sink_0_0, 0))
		self.connect((self.gr_binary_slicer_fb_0, 0), (self.poesweather_univ_hrpt_deframer_0, 0))
		self.connect((self.poesweather_univ_hrpt_deframer_0, 0), (self.noaa_hrpt_decoder_0, 0))
		self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.gr_agc_xx_0_0, 0), (self.gr_costas_loop_cc_0, 0))
		self.connect((self.gr_costas_loop_cc_0, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_complex_to_real_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.wxgui_scopesink2_1, 0))
Пример #21
0
    def __init__(self):
        gr.top_block.__init__(self, "Usrp Rx Hrpt Nogui")

        ##################################################
        # Variables
        ##################################################
        self.config_filename = config_filename = os.environ[
            'HOME'] + '/.gnuradio/config.conf'
        self._decim_config = ConfigParser.ConfigParser()
        self._decim_config.read(config_filename)
        try:
            decim = self._decim_config.getfloat('usrp_rx_hrpt', 'decim')
        except:
            decim = 32
        self.decim = decim
        self.sym_rate = sym_rate = 600 * 1109
        self.sample_rate = sample_rate = 64e6 / decim
        self.sps = sps = sample_rate / sym_rate
        self._side_config = ConfigParser.ConfigParser()
        self._side_config.read(config_filename)
        try:
            side = self._side_config.get('usrp_rx_hrpt', 'side')
        except:
            side = 'A'
        self.side = side
        self._pll_alpha_config = ConfigParser.ConfigParser()
        self._pll_alpha_config.read(config_filename)
        try:
            pll_alpha = self._pll_alpha_config.getfloat(
                'usrp_rx_hrpt', 'pll_alpha')
        except:
            pll_alpha = 0.01
        self.pll_alpha = pll_alpha
        self._output_filename_config = ConfigParser.ConfigParser()
        self._output_filename_config.read(config_filename)
        try:
            output_filename = self._output_filename_config.get(
                'usrp_rx_hrpt', 'filename')
        except:
            output_filename = 'frames.hrpt'
        self.output_filename = output_filename
        self.max_clock_offset = max_clock_offset = 100e-6
        self.max_carrier_offset = max_carrier_offset = 2 * math.pi * 100e3 / sample_rate
        self.hs = hs = int(sps / 2.0)
        self._gain_config = ConfigParser.ConfigParser()
        self._gain_config.read(config_filename)
        try:
            gain = self._gain_config.getfloat('usrp_rx_hrpt', 'gain')
        except:
            gain = 35
        self.gain = gain
        self._freq_config = ConfigParser.ConfigParser()
        self._freq_config.read(config_filename)
        try:
            freq = self._freq_config.getfloat('usrp_rx_hrpt', 'freq')
        except:
            freq = 1698e6
        self.freq = freq
        self._clock_alpha_config = ConfigParser.ConfigParser()
        self._clock_alpha_config.read(config_filename)
        try:
            clock_alpha = self._clock_alpha_config.getfloat(
                'usrp_rx_hrpt', 'clock_alpha')
        except:
            clock_alpha = 0.01
        self.clock_alpha = clock_alpha

        ##################################################
        # Blocks
        ##################################################
        self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)
        self.decoder = noaa.hrpt_decoder(True, True)
        self.deframer = noaa.hrpt_deframer()
        self.frame_sink = gr.file_sink(gr.sizeof_short * 1, output_filename)
        self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(
            sps / 2.0, clock_alpha**2 / 4.0, 0.5, clock_alpha,
            max_clock_offset)
        self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0 / hs, 4000)
        self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2 / 4.0,
                                    max_carrier_offset)
        self.usrp_source = grc_usrp.simple_source_c(which=0,
                                                    side=side,
                                                    rx_ant="RXA")
        self.usrp_source.set_decim_rate(decim)
        self.usrp_source.set_frequency(freq, verbose=True)
        self.usrp_source.set_gain(gain)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.usrp_source, 0), (self.agc, 0))
        self.connect((self.agc, 0), (self.pll, 0))
        self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
        self.connect((self.gr_moving_average_xx_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_binary_slicer_fb_0, 0))
        self.connect((self.deframer, 0), (self.frame_sink, 0))
        self.connect((self.deframer, 0), (self.decoder, 0))
        self.connect((self.gr_binary_slicer_fb_0, 0), (self.deframer, 0))
Пример #22
0
	def __init__(self):
		gr.top_block.__init__(self, "Usrp Rx Hrpt Nogui")

		##################################################
		# Variables
		##################################################
		self.config_filename = config_filename = os.environ['HOME']+'/.gnuradio/config.conf'
		self._decim_config = ConfigParser.ConfigParser()
		self._decim_config.read(config_filename)
		try: decim = self._decim_config.getfloat('usrp_rx_hrpt', 'decim')
		except: decim = 32
		self.decim = decim
		self.sym_rate = sym_rate = 600*1109
		self.sample_rate = sample_rate = 64e6/decim
		self.sps = sps = sample_rate/sym_rate
		self._side_config = ConfigParser.ConfigParser()
		self._side_config.read(config_filename)
		try: side = self._side_config.get('usrp_rx_hrpt', 'side')
		except: side = 'A'
		self.side = side
		self._pll_alpha_config = ConfigParser.ConfigParser()
		self._pll_alpha_config.read(config_filename)
		try: pll_alpha = self._pll_alpha_config.getfloat('usrp_rx_hrpt', 'pll_alpha')
		except: pll_alpha = 0.01
		self.pll_alpha = pll_alpha
		self._output_filename_config = ConfigParser.ConfigParser()
		self._output_filename_config.read(config_filename)
		try: output_filename = self._output_filename_config.get('usrp_rx_hrpt', 'filename')
		except: output_filename = 'frames.hrpt'
		self.output_filename = output_filename
		self.max_clock_offset = max_clock_offset = 100e-6
		self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/sample_rate
		self.hs = hs = int(sps/2.0)
		self._gain_config = ConfigParser.ConfigParser()
		self._gain_config.read(config_filename)
		try: gain = self._gain_config.getfloat('usrp_rx_hrpt', 'gain')
		except: gain = 35
		self.gain = gain
		self._freq_config = ConfigParser.ConfigParser()
		self._freq_config.read(config_filename)
		try: freq = self._freq_config.getfloat('usrp_rx_hrpt', 'freq')
		except: freq = 1698e6
		self.freq = freq
		self._clock_alpha_config = ConfigParser.ConfigParser()
		self._clock_alpha_config.read(config_filename)
		try: clock_alpha = self._clock_alpha_config.getfloat('usrp_rx_hrpt', 'clock_alpha')
		except: clock_alpha = 0.01
		self.clock_alpha = clock_alpha

		##################################################
		# Blocks
		##################################################
		self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)
		self.decoder = noaa.hrpt_decoder(True,True)
		self.deframer = noaa.hrpt_deframer()
		self.frame_sink = gr.file_sink(gr.sizeof_short*1, output_filename)
		self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(sps/2.0, clock_alpha**2/4.0, 0.5, clock_alpha, max_clock_offset)
		self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0/hs, 4000)
		self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset)
		self.usrp_source = grc_usrp.simple_source_c(which=0, side=side, rx_ant="RXA")
		self.usrp_source.set_decim_rate(decim)
		self.usrp_source.set_frequency(freq, verbose=True)
		self.usrp_source.set_gain(gain)

		##################################################
		# Connections
		##################################################
		self.connect((self.usrp_source, 0), (self.agc, 0))
		self.connect((self.agc, 0), (self.pll, 0))
		self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_binary_slicer_fb_0, 0))
		self.connect((self.deframer, 0), (self.frame_sink, 0))
		self.connect((self.deframer, 0), (self.decoder, 0))
		self.connect((self.gr_binary_slicer_fb_0, 0), (self.deframer, 0))
	def __init__(self, deframer_insync_frames=2, deframer_sync_check=True, viterbi_insync_frames=5, deframer_outsync_frames=5, viterbi_outsync_frames=20, viterbi_sync_check=True, viterbi_sync_threshold=0.1, satellite='GOES-LRIT', freq=1691.02e6, gain=23, decim=108, side="A", pll_alpha=0.005, symb_rate=293883, clock_alpha=0.005):
		grc_wxgui.top_block_gui.__init__(self, title="USRP LRIT Receiver - check signal quality")

		##################################################
		# Parameters
		##################################################
		self.deframer_insync_frames = deframer_insync_frames
		self.deframer_sync_check = deframer_sync_check
		self.viterbi_insync_frames = viterbi_insync_frames
		self.deframer_outsync_frames = deframer_outsync_frames
		self.viterbi_outsync_frames = viterbi_outsync_frames
		self.viterbi_sync_check = viterbi_sync_check
		self.viterbi_sync_threshold = viterbi_sync_threshold
		self.satellite = satellite
		self.freq = freq
		self.gain = gain
		self.decim = decim
		self.side = side
		self.pll_alpha = pll_alpha
		self.symb_rate = symb_rate
		self.clock_alpha = clock_alpha

		##################################################
		# Variables
		##################################################
		self.decim_tb = decim_tb = decim
		self.symb_rate_tb = symb_rate_tb = symb_rate
		self.samp_rate = samp_rate = 64e6/decim_tb
		self.viterbi_sync_threshold_text = viterbi_sync_threshold_text = viterbi_sync_threshold
		self.viterbi_sync_after_text = viterbi_sync_after_text = viterbi_insync_frames
		self.viterbi_outofsync_after_text = viterbi_outofsync_after_text = viterbi_outsync_frames
		self.viterbi_node_sync_text = viterbi_node_sync_text = viterbi_sync_check
		self.sps = sps = samp_rate/symb_rate_tb
		self.satellite_text = satellite_text = satellite
		self.samp_rate_st = samp_rate_st = samp_rate
		self.pll_alpha_sl = pll_alpha_sl = pll_alpha
		self.gain_tb = gain_tb = gain
		self.freq_tb = freq_tb = freq
		self.frames_file_text_inf = frames_file_text_inf = 'no output file'
		self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
		self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
		self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
		self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime())
		self.clock_alpha_sl = clock_alpha_sl = clock_alpha
		self.baseband_file_text_inf = baseband_file_text_inf = 'no output file'

		##################################################
		# Notebooks
		##################################################
		self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "USRP Receiver")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "PLL demodulator and Clock sync")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Viterbi decoder")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
		self.Add(self.rx_ntb)

		##################################################
		# Controls
		##################################################
		self._decim_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.decim_tb,
			callback=self.set_decim_tb,
			label="Decimation",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
		self._symb_rate_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			value=self.symb_rate_tb,
			callback=self.set_symb_rate_tb,
			label="Symbol rate",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
		self._viterbi_sync_threshold_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_sync_threshold_text,
			callback=self.set_viterbi_sync_threshold_text,
			label="Viterbi node sync threshold [BER]",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_sync_threshold_text_static_text, 3, 0, 1, 1)
		self._viterbi_sync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_sync_after_text,
			callback=self.set_viterbi_sync_after_text,
			label="Valid frames for Viterbi decoder sync",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_sync_after_text_static_text, 4, 0, 1, 1)
		self._viterbi_outofsync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_outofsync_after_text,
			callback=self.set_viterbi_outofsync_after_text,
			label="Invalid frames for Viterbi decoder out of sync",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_outofsync_after_text_static_text, 5, 0, 1, 1)
		self._viterbi_node_sync_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_node_sync_text,
			callback=self.set_viterbi_node_sync_text,
			label="Viterbi node sync enable",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_node_sync_text_static_text, 2, 0, 1, 1)
		self._satellite_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.satellite_text,
			callback=self.set_satellite_text,
			label="Sat ",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0, 1, 1)
		self._samp_rate_st_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.samp_rate_st,
			callback=self.set_samp_rate_st,
			label="Sample rate",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1, 1)
		_pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._pll_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			label="PLL Alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._pll_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
		self._gain_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.gain_tb,
			callback=self.set_gain_tb,
			label="RX gain [dB]",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._gain_tb_text_box, 1, 2, 1, 1)
		self._freq_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.freq_tb,
			callback=self.set_freq_tb,
			label="Frequency",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._freq_tb_text_box, 1, 1, 1, 1)
		self._frames_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(4).GetWin(),
			value=self.frames_file_text_inf,
			callback=self.set_frames_file_text_inf,
			label="Frames filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(4).GridAdd(self._frames_file_text_inf_static_text, 3, 0, 1, 1)
		self._deframer_sync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_sync_after_text,
			callback=self.set_deframer_sync_after_text,
			label="Deframe sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
		self._deframer_nosync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_nosync_after_text,
			callback=self.set_deframer_nosync_after_text,
			label="Deframer out of sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
		self._deframer_check_sync_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_check_sync_text,
			callback=self.set_deframer_check_sync_text,
			label="Deframer check sync enable",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
		self._datetime_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(4).GetWin(),
			value=self.datetime_text,
			callback=self.set_datetime_text,
			label="Local time of aquisition start",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(4).GridAdd(self._datetime_text_static_text, 1, 0, 1, 1)
		_clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._clock_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			label="Clock alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._clock_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
		self._baseband_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(4).GetWin(),
			value=self.baseband_file_text_inf,
			callback=self.set_baseband_file_text_inf,
			label="Baseband filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(4).GridAdd(self._baseband_file_text_inf_static_text, 4, 0, 1, 1)

		##################################################
		# Blocks
		##################################################
		self.fec_decode_viterbi_bpsk_fb_0 = fec.decode_viterbi_bpsk_fb(viterbi_sync_check, viterbi_sync_threshold, viterbi_insync_frames, viterbi_outsync_frames, viterbi_outsync_frames*3)
		self.gr_agc_xx_0 = gr.agc_cc(10e-6, 1, 1.0/32767.0, 1.0)
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(sps, clock_alpha_sl*clock_alpha_sl/4.0, 0.5, clock_alpha_sl, 0.05)
		self.gr_complex_to_real_0 = gr.complex_to_real(1)
		self.gr_costas_loop_cc_0 = gr.costas_loop_cc(pll_alpha_sl, pll_alpha_sl*pll_alpha_sl/4.0, 0.07, -0.07, 2)
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((1, ))
		self.gr_null_sink_0 = gr.null_sink(gr.sizeof_char*1)
		self.gr_packed_to_unpacked_xx_0 = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
		self.poesweather_metop_cadu_deframer_0 = poesweather.metop_cadu_deframer(True, 1024, deframer_insync_frames, deframer_outsync_frames)
		self.root_raised_cosine_filter_0 = gr.fir_filter_ccf(1, firdes.root_raised_cosine(
			1, samp_rate, symb_rate, 0.25, int(11*samp_rate/symb_rate)))
		self.usrp_simple_source = grc_usrp.simple_source_c(which=0, side=side, rx_ant="RXA")
		self.usrp_simple_source.set_decim_rate(decim_tb)
		self.usrp_simple_source.set_frequency(freq_tb, verbose=True)
		self.usrp_simple_source.set_gain(gain_tb)
		self.wxgui_fftsink1 = fftsink2.fft_sink_c(
			self.rx_ntb.GetPage(0).GetWin(),
			baseband_freq=freq,
			y_per_div=2,
			y_divs=10,
			ref_level=12,
			ref_scale=2.0,
			sample_rate=samp_rate,
			fft_size=1024,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="Not filtered spectrum",
			peak_hold=False,
		)
		self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
		self.wxgui_fftsink2 = fftsink2.fft_sink_c(
			self.rx_ntb.GetPage(0).GetWin(),
			baseband_freq=0,
			y_per_div=2,
			y_divs=10,
			ref_level=12,
			ref_scale=2.0,
			sample_rate=samp_rate,
			fft_size=1024,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="RRC filtered spectrum",
			peak_hold=False,
		)
		self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink2.win)
		self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
			self.rx_ntb.GetPage(1).GetWin(),
			title="BPSK constellation diagram",
			sample_rate=symb_rate,
			v_scale=0.4,
			v_offset=0,
			t_scale=1/samp_rate,
			ac_couple=False,
			xy_mode=True,
			num_inputs=1,
		)
		self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win)

		##################################################
		# Connections
		##################################################
		self.connect((self.usrp_simple_source, 0), (self.gr_agc_xx_0, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.root_raised_cosine_filter_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_complex_to_real_0, 0))
		self.connect((self.fec_decode_viterbi_bpsk_fb_0, 0), (self.gr_packed_to_unpacked_xx_0, 0))
		self.connect((self.gr_packed_to_unpacked_xx_0, 0), (self.poesweather_metop_cadu_deframer_0, 0))
		self.connect((self.gr_complex_to_real_0, 0), (self.fec_decode_viterbi_bpsk_fb_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.gr_costas_loop_cc_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.root_raised_cosine_filter_0, 0), (self.gr_costas_loop_cc_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.wxgui_scopesink2_1, 0))
		self.connect((self.root_raised_cosine_filter_0, 0), (self.wxgui_fftsink2, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.wxgui_fftsink1, 0))
		self.connect((self.poesweather_metop_cadu_deframer_0, 0), (self.gr_null_sink_0, 0))
Пример #24
0
    def __init__(self, decim=160):
        grc_wxgui.top_block_gui.__init__(
            self, title="LRIT Receiver (from capture file)")

        ##################################################
        # Parameters
        ##################################################
        self.decim = decim

        ##################################################
        # Variables
        ##################################################
        self.config_filename = config_filename = os.environ[
            'HOME'] + '/.gnuradio/config.conf'
        self.symbol_rate = symbol_rate = 293e3
        self._saved_gain_mu_config = ConfigParser.ConfigParser()
        self._saved_gain_mu_config.read(config_filename)
        try:
            saved_gain_mu = self._saved_gain_mu_config.getfloat(
                'usrp_rx_lrit', 'gain_mu')
        except:
            saved_gain_mu = 0.2
        self.saved_gain_mu = saved_gain_mu
        self._saved_costas_alpha_config = ConfigParser.ConfigParser()
        self._saved_costas_alpha_config.read(config_filename)
        try:
            saved_costas_alpha = self._saved_costas_alpha_config.getfloat(
                'usrp_rx_lrit', 'costas_alpha')
        except:
            saved_costas_alpha = 0.2
        self.saved_costas_alpha = saved_costas_alpha
        self.sample_rate = sample_rate = 64e6 / decim
        self.sps = sps = sample_rate / symbol_rate
        self.gain_mu = gain_mu = saved_gain_mu
        self.costas_alpha = costas_alpha = saved_costas_alpha

        ##################################################
        # Notebooks
        ##################################################
        self.displays = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "USRP RX")
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "RRC Filter")
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "PLL")
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "MM")
        self.GridAdd(self.displays, 1, 0, 1, 2)

        ##################################################
        # Controls
        ##################################################
        _gain_mu_sizer = wx.BoxSizer(wx.VERTICAL)
        self._gain_mu_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_gain_mu_sizer,
            value=self.gain_mu,
            callback=self.set_gain_mu,
            label="Gain Mu",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._gain_mu_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_gain_mu_sizer,
            value=self.gain_mu,
            callback=self.set_gain_mu,
            minimum=0,
            maximum=0.5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_gain_mu_sizer, 0, 1, 1, 1)
        _costas_alpha_sizer = wx.BoxSizer(wx.VERTICAL)
        self._costas_alpha_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_costas_alpha_sizer,
            value=self.costas_alpha,
            callback=self.set_costas_alpha,
            label="Costas Alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._costas_alpha_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_costas_alpha_sizer,
            value=self.costas_alpha,
            callback=self.set_costas_alpha,
            minimum=0,
            maximum=0.5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_costas_alpha_sizer, 0, 0, 1, 1)

        ##################################################
        # Blocks
        ##################################################
        self.costas = gr.costas_loop_cc(costas_alpha, (costas_alpha**2) / 4.0,
                                        50e-6 * sps, -50e-6 * sps, 2)
        self.costas_spectrum = fftsink2.fft_sink_c(
            self.displays.GetPage(2).GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=-15,
            ref_scale=2.0,
            sample_rate=sample_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=None,
            title="PLL Spectrum",
            peak_hold=False,
            win=window.hanning,
        )
        self.displays.GetPage(2).GridAdd(self.costas_spectrum.win, 0, 0, 1, 1)
        self.costas_spectrum_0 = fftsink2.fft_sink_c(
            self.displays.GetPage(3).GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=-15,
            ref_scale=2.0,
            sample_rate=symbol_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=None,
            title="Bit Sync Spectrum",
            peak_hold=False,
            win=window.hanning,
        )
        self.displays.GetPage(3).GridAdd(self.costas_spectrum_0.win, 0, 0, 1,
                                         1)
        self.costas_waveform = scopesink2.scope_sink_c(
            self.displays.GetPage(2).GetWin(),
            title="PLL Waveform",
            sample_rate=sample_rate,
            v_scale=0.5,
            v_offset=0,
            t_scale=20.0 / sample_rate,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
        )
        self.displays.GetPage(2).GridAdd(self.costas_waveform.win, 1, 0, 1, 1)
        self.gr_agc_xx_0 = gr.agc_cc(1e-6, 1.0, 1.0 / 32767.0, 1.0)
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(
            sps, (gain_mu**2) / 4.0, 0.5, gain_mu, 50e-6)
        self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex * 1,
                                               "lrit.dat", False)
        self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex * 1, sample_rate)
        self.mm_waveform = scopesink2.scope_sink_c(
            self.displays.GetPage(3).GetWin(),
            title="Constellation",
            sample_rate=symbol_rate,
            v_scale=0.5,
            v_offset=0,
            t_scale=20.0 / symbol_rate,
            ac_couple=False,
            xy_mode=True,
            num_inputs=1,
        )
        self.displays.GetPage(3).GridAdd(self.mm_waveform.win, 1, 0, 1, 1)
        self.rrc = gr.fir_filter_ccf(
            1,
            firdes.root_raised_cosine(1, sample_rate, symbol_rate, 0.25,
                                      int(11 * sample_rate / symbol_rate)))
        self.rrc_spectrum = fftsink2.fft_sink_c(
            self.displays.GetPage(1).GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=-15,
            ref_scale=2.0,
            sample_rate=sample_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=None,
            title="RRC Spectrum",
            peak_hold=False,
            win=window.hanning,
        )
        self.displays.GetPage(1).GridAdd(self.rrc_spectrum.win, 0, 0, 1, 1)
        self.rx_spectrum = fftsink2.fft_sink_c(
            self.displays.GetPage(0).GetWin(),
            baseband_freq=0,
            y_per_div=5,
            y_divs=10,
            ref_level=50,
            ref_scale=2.0,
            sample_rate=sample_rate,
            fft_size=1024,
            fft_rate=15,
            average=True,
            avg_alpha=None,
            title="Baseband Spectrum",
            peak_hold=False,
        )
        self.displays.GetPage(0).GridAdd(self.rx_spectrum.win, 0, 0, 1, 1)
        self.rx_waveform = scopesink2.scope_sink_c(
            self.displays.GetPage(0).GetWin(),
            title="Baseband Waveform",
            sample_rate=sample_rate,
            v_scale=0,
            v_offset=0,
            t_scale=20.0 / sample_rate,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
        )
        self.displays.GetPage(0).GridAdd(self.rx_waveform.win, 1, 0, 1, 1)
        self.rx_waveform_0 = scopesink2.scope_sink_c(
            self.displays.GetPage(1).GetWin(),
            title="RRC Waveform",
            sample_rate=sample_rate,
            v_scale=0.5,
            v_offset=0,
            t_scale=20.0 / sample_rate,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
        )
        self.displays.GetPage(1).GridAdd(self.rx_waveform_0.win, 1, 0, 1, 1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.rrc, 0), (self.rx_waveform_0, 0))
        self.connect((self.rrc, 0), (self.rrc_spectrum, 0))
        self.connect((self.gr_agc_xx_0, 0), (self.rrc, 0))
        self.connect((self.gr_throttle_0, 0), (self.rx_waveform, 0))
        self.connect((self.gr_throttle_0, 0), (self.rx_spectrum, 0))
        self.connect((self.gr_throttle_0, 0), (self.gr_agc_xx_0, 0))
        self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0))
        self.connect((self.rrc, 0), (self.costas, 0))
        self.connect((self.costas, 0), (self.costas_spectrum, 0))
        self.connect((self.costas, 0), (self.costas_waveform, 0))
        self.connect((self.costas, 0), (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.costas_spectrum_0, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.mm_waveform, 0))
Пример #25
0
    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 = gr.file_source(gr.sizeof_short,
                                             options.in_filename,
                                             options.repeat)
            self.istoc = gr.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 = gr.agc_cc(1e-7, 1.0, 1.0)  #1e-7
        self.am_demod = gr.complex_to_mag()
        self.set_blacklevel = gr.add_const_ff(options.brightness + 255.0)
        self.invert_and_scale = gr.multiply_const_ff(-options.contrast *
                                                     128.0 * 255.0 / (200.0))
        self.f2uc = gr.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, 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:" + filename
            print "(Use the spacebar to advance to next frames)"
            file_sink = gr.file_sink(gr.sizeof_char, filename)
            self.dst = file_sink

        if options.nframes is None:
            self.connect(self.src, self.agc)
        else:
            self.head = gr.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)
Пример #26
0
    def __init__(self, options):
        
        gr.hier_block2.__init__(self, "bpsk_demodulator",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
                                gr.io_signature(0, 0, 0))                    # Output signature
        
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        
        self._samples_per_symbol = options.samples_per_symbol
        
        # Number of bits per symbol
        self._bits_per_symbol = 1
        # Create AGC to scale input to unity
        self._agc = gr.agc_cc(1e-5, 1.0, 1.0, 1.0)
        # Create RRC with specified excess bandwidth
        taps = gr.firdes.root_raised_cosine(1.0,       # Gain
                        self._samples_per_symbol,      # Sampling rate
                        1.0,                           # Symbol rate
                        0.35,                          # Roll-off factor
                        11*self._samples_per_symbol)                  # Number of taps
        
        self._rrc = gr.fir_filter_ccf(1, taps)
        
        # Create a Costas loop frequency/phase recovery block
        self._costas = digital.costas_loop_cc(6.28/100.0, 2)
        self.gr_null_sink_f1 = gr.null_sink(gr.sizeof_float*1)
        
        
        # Create a M&M bit synchronization retiming block        
        self._mm = digital.clock_recovery_mm_cc(self._samples_per_symbol,       # Initial samples/symbol
                                           1e-06,  # Second order gain
                                           0.5,          # Initial symbol phase
                                           0.001,     # First order gain
                                           0.0001) # Maximum timing offset
        
        # Add an SNR probe on the demodulated constellation
        #self._snr_probe = gr.probe_mpsk_snr_c(10.0/symbol_rate)
        self._symbol_rate = options.data_rate / self._bits_per_symbol
        #self._snr_probe = digital.mpsk_snr_est_cc(0, 10000, 0.001) # 0 at the first mean Simple
        
        self._snr_probe = digital.probe_mpsk_snr_est_c(digital.SNR_EST_M2M4, alpha=10.0/self._symbol_rate)
        #self._snr_probe = digital.mpsk_snr_est_cc(digital.SNR_EST_SIMPLE, alpha=10.0/self._symbol_rate)
    
  
        # Slice the resulting constellation into bits.
        # Get inphase channel and make decision about 0
        self._c2r = gr.complex_to_real()
        self._slicer = digital.binary_slicer_fb() 
        
        # Descramble BERT sequence.  A channel error will create 3 incorrect bits
        self._descrambler = gr.descrambler_bb(0x8A, 0x7F, 31) # CCSDS 7-bit descrambler

        # Measure BER by the density of 0s in the stream
        # self._ber = gr.probe_density_b(1.0/symbol_rate)
        self._ber = grc_blks2.error_rate(type='BER', 
                                         win_size=1000,
                                         bits_per_symbol=1)
        
        #self.create_number_sink(self._samples_per_symbol)
        self.gr_null_sink_f2 = gr.null_sink(gr.sizeof_float*1)
        
        #Create a vector source reference to calculate BER
        self._vector_source_ref = gr.vector_source_b(([1,]), True, 1)
        
        #create a comparator 
        self.comparator = howto.compare_vector_cci((1, 1, 1, 1 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1), (0,0, 1, 1, 0,0), 5, 0, True)
        
        
        #Connection of blocks
        #"""""""""""""""""""""""""""""""""-->_snr_probe-->gr_null_sink_cc
        # agc --> _rrc --> costas --> _mm --> _c2r  -->  _slicer  -->   _descrambler --> _ber --> gr_null_sink_f2
        #"""""""""""""""""""""""""--> gr_null_sink_f1 ""           _vector_source_ref-->
        
#        
#        self.connect(self, self._agc, self._rrc, self._costas, self._mm, 
#                     self._c2r, self._slicer, self._descrambler, self.comparator, (self._ber, 1))
#        
                
        self.connect(self, self._agc, self._rrc, self._costas, self._mm, 
                     self._c2r, self._slicer, self._descrambler, (self._ber, 1))
        
        
        self.connect((self._costas, 1), (self.gr_null_sink_f1, 0))
        self.connect(self._mm, self._snr_probe)
        
        self.connect(self._vector_source_ref, (self._ber,0)) 
        self.connect(self._ber, self.gr_null_sink_f2)
	def __init__(self, sync_check=False, decim=32, freq=1698e6, gain=35, side="A", frames_file=os.environ['HOME'] + '/NOAA-XX.hrpt', satellite='NOAA-XX'):
		gr.top_block.__init__(self, "USRP NOAA HRPT Receiver")

		##################################################
		# Parameters
		##################################################
		self.sync_check = sync_check
		self.decim = decim
		self.freq = freq
		self.gain = gain
		self.side = side
		self.frames_file = frames_file
		self.satellite = satellite

		##################################################
		# Variables
		##################################################
		self.sym_rate = sym_rate = 600*1109
		self.samp_rate = samp_rate = 64e6/decim
		self.sps = sps = samp_rate/sym_rate
		self.config_filename = config_filename = os.environ['HOME']+'/.gnuradio/noaa_hrpt.conf'
		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("satname", 'pll_alpha')
		except: saved_pll_alpha = 0.005
		self.saved_pll_alpha = saved_pll_alpha
		self._saved_gain_config = ConfigParser.ConfigParser()
		self._saved_gain_config.read(config_filename)
		try: saved_gain = self._saved_gain_config.getfloat("satname", 'gain')
		except: saved_gain = gain
		self.saved_gain = saved_gain
		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("satname", 'clock_alpha')
		except: saved_clock_alpha = 0.001
		self.saved_clock_alpha = saved_clock_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)

		##################################################
		# Blocks
		##################################################
		self.agc = gr.agc_cc(1e-5, 1.0, 1.0/32768.0, 1.0)
		self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(sps/2.0, saved_clock_alpha**2/4.0, 0.5, saved_clock_alpha, max_clock_offset)
		self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_short*1, frames_file)
		self.gr_file_sink_0_0.set_unbuffered(False)
		self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex()
		self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0/hs, 4000)
		self.noaa_hrpt_decoder_0 = noaa.hrpt_decoder(True,False)
		self.pll = noaa.hrpt_pll_cf(saved_pll_alpha, saved_pll_alpha**2/4.0, max_carrier_offset)
		self.poesweather_noaa_hrpt_deframer_0 = poesweather.noaa_hrpt_deframer(sync_check)
		self.usrp_simple_source_x_0 = grc_usrp.simple_source_s(which=0, side=side, rx_ant="RXA")
		self.usrp_simple_source_x_0.set_decim_rate(decim)
		self.usrp_simple_source_x_0.set_frequency(freq, verbose=True)
		self.usrp_simple_source_x_0.set_gain(gain)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_interleaved_short_to_complex_0, 0), (self.agc, 0))
		self.connect((self.usrp_simple_source_x_0, 0), (self.gr_interleaved_short_to_complex_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_binary_slicer_fb_0, 0))
		self.connect((self.agc, 0), (self.pll, 0))
		self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.poesweather_noaa_hrpt_deframer_0, 0), (self.gr_file_sink_0_0, 0))
		self.connect((self.poesweather_noaa_hrpt_deframer_0, 0), (self.noaa_hrpt_decoder_0, 0))
		self.connect((self.gr_binary_slicer_fb_0, 0), (self.poesweather_noaa_hrpt_deframer_0, 0))
Пример #28
0
    def __init__(self, options):
        gr.top_block.__init__(self)
        self.options = options

        (dev_rate, channel_rate, audio_rate, channel_pass, channel_stop,
         demod) = demod_params[options.modulation]

        DEV = uhd_src(
            options.args,  # UHD device address
            options.spec,  # device subdev spec
            options.antenna,  # device antenna
            dev_rate,  # device sample rate
            options.gain,  # Receiver gain
            options.calibration)  # Frequency offset
        DEV.tune(options.frequency)

        if_rate = DEV.rate()
        channel_decim = int(if_rate // channel_rate)
        audio_decim = int(channel_rate // audio_rate)

        CHAN_taps = optfir.low_pass(
            1.0,  # Filter gain
            if_rate,  # Sample rate
            channel_pass,  # One sided modulation bandwidth
            channel_stop,  # One sided channel bandwidth
            0.1,  # Passband ripple
            60)  # Stopband attenuation

        CHAN = gr.freq_xlating_fir_filter_ccf(
            channel_decim,  # Decimation rate
            CHAN_taps,  # Filter taps
            0.0,  # Offset frequency
            if_rate)  # Sample rate

        RFSQL = gr.pwr_squelch_cc(
            options.rf_squelch,  # Power threshold
            125.0 / channel_rate,  # Time constant
            int(channel_rate / 20),  # 50ms rise/fall
            False)  # Zero, not gate output

        AGC = gr.agc_cc(
            1.0 / channel_rate,  # Time constant
            1.0,  # Reference power 
            1.0,  # Initial gain
            1.0)  # Maximum gain

        DEMOD = demod(channel_rate, audio_decim)

        # From RF to audio
        #self.connect(DEV, CHAN, RFSQL, AGC, DEMOD)
        self.connect(DEV, CHAN, DEMOD)

        # Optionally add CTCSS and RSAMP if needed
        tail = DEMOD
        if options.ctcss != None and options.ctcss > 60.0:
            CTCSS = gr.ctcss_squelch_ff(
                audio_rate,  # Sample rate
                options.ctcss)  # Squelch tone
            self.connect(DEMOD, CTCSS)
            tail = CTCSS

        if options.output_rate != audio_rate:
            out_lcm = gru.lcm(audio_rate, options.output_rate)
            out_interp = int(out_lcm // audio_rate)
            out_decim = int(out_lcm // options.output_rate)
            RSAMP = blks2.rational_resampler_fff(out_interp, out_decim)
            self.connect(tail, RSAMP)
            tail = RSAMP

        # Send to audio output device
        AUDIO = audio.sink(int(options.output_rate), options.audio_output)
        self.connect(tail, AUDIO)
Пример #29
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage="%prog: [options] output_filename. \n Special 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("-R",
                          "--rx-subdev-spec",
                          type="subdev",
                          default=(0, 0),
                          help="select USRP Rx side A or B (default=A)")
        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(
            "-d",
            "--decim",
            type="int",
            default=8,
            help="set fgpa decimation rate to DECIM [default=%default]")
        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=None,
            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("-8",
                          "--width-8",
                          action="store_true",
                          default=False,
                          help="Enable 8-bit samples across USB")
        parser.add_option("-N",
                          "--nframes",
                          type="eng_float",
                          default=None,
                          help="number of frames to collect [default=+inf]")
        parser.add_option("--no-hb",
                          action="store_true",
                          default=False,
                          help="don't use halfband filter in usrp")
        (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]

        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

        if not (options.in_filename == "usrp"):
            self.filesource = gr.file_source(
                gr.sizeof_short, options.in_filename, options.repeat
            )  # file is data source, capture with usr_rx_csfile.py
            self.istoc = gr.interleaved_short_to_complex()
            self.connect(self.filesource, self.istoc)
            self.adc_rate = 64e6
            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
            if abs(options.freq) < 1e6:
                options.freq *= 1e6
            if options.no_hb or (options.decim < 8):
                self.fpga_filename = "std_4rx_0tx.rbf"  #contains 4 Rx paths without halfbands and 0 tx paths
            else:
                self.fpga_filename = "std_2rxhb_2tx.rbf"  # contains 2 Rx paths with halfband filters and 2 tx paths (the default)

            # build the graph
            self.u = usrp.source_c(decim_rate=options.decim,
                                   fpga_filename=self.fpga_filename)
            self.src = self.u
            if options.width_8:
                sample_width = 8
                sample_shift = 8
                format = self.u.make_format(sample_width, sample_shift)
                r = self.u.set_format(format)
            self.adc_rate = self.u.adc_freq()
            if options.rx_subdev_spec is None:
                options.rx_subdev_spec = usrp.pick_rx_subdevice(self.u)
            self.u.set_mux(
                usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))
            # determine the daughterboard subdevice we're using
            self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
            print "Using RX d'board %s" % (self.subdev.side_and_name(), )

            if options.gain is None:
                # if no gain was specified, use the mid-point in dB
                g = self.subdev.gain_range()
                options.gain = float(g[0] + g[1]) / 2
            self.subdev.set_gain(options.gain)

            r = self.u.tune(0, self.subdev, options.freq)
            if not r:
                sys.stderr.write('Failed to set frequency\n')
                raise SystemExit, 1

        input_rate = self.adc_rate / options.decim
        print "video sample rate %s" % (eng_notation.num_to_str(input_rate))

        self.agc = gr.agc_cc(1e-7, 1.0, 1.0)  #1e-7
        self.am_demod = gr.complex_to_mag()
        self.set_blacklevel = gr.add_const_ff(options.brightness + 255.0)
        self.invert_and_scale = gr.multiply_const_ff(-options.contrast *
                                                     128.0 * 255.0 / (200.0))
        self.f2uc = gr.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, 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:" + filename
            print "(Use the spacebar to advance to next frames)"
            file_sink = gr.file_sink(gr.sizeof_char, filename)
            self.dst = file_sink

        if options.nframes is None:
            self.connect(self.src, self.agc)
        else:
            self.head = gr.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, frames_file=os.environ['HOME'] + '/NOAA-XX.hrpt', decim=32, satellite='NOAA-XX', baseband_file=os.environ['HOME'] + '/NOAA-XX.dat', sync_check=False):
		grc_wxgui.top_block_gui.__init__(self, title="NOAA HRPT Baseband To Frames")
		_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Parameters
		##################################################
		self.frames_file = frames_file
		self.decim = decim
		self.satellite = satellite
		self.baseband_file = baseband_file
		self.sync_check = sync_check

		##################################################
		# Variables
		##################################################
		self.sym_rate = sym_rate = 600*1109
		self.sample_rate = sample_rate = 64e6/decim
		self.config_filename = config_filename = os.environ['HOME']+'/.gnuradio/noaa_hrpt.conf'
		self.sps = sps = sample_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("satname", 'pll_alpha')
		except: saved_pll_alpha = 0.01
		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("satname", 'clock_alpha')
		except: saved_clock_alpha = 0.01
		self.saved_clock_alpha = saved_clock_alpha
		self.sync_check_txt = sync_check_txt = sync_check
		self.satname_txt = satname_txt = satellite
		self.pll_alpha = pll_alpha = saved_pll_alpha
		self.max_clock_offset = max_clock_offset = 100e-6
		self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/sample_rate
		self.hs = hs = int(sps/2.0)
		self.frames_file_txt = frames_file_txt = frames_file
		self.decim_txt = decim_txt = decim
		self.clock_alpha = clock_alpha = saved_clock_alpha
		self.baseband_file_txt = baseband_file_txt = baseband_file

		##################################################
		# Notebooks
		##################################################
		self.displays = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.displays.AddPage(grc_wxgui.Panel(self.displays), "NOAA HRPT Spectrum")
		self.displays.AddPage(grc_wxgui.Panel(self.displays), "Information")
		self.Add(self.displays)

		##################################################
		# Controls
		##################################################
		self._sync_check_txt_static_text = forms.static_text(
			parent=self.GetWin(),
			value=self.sync_check_txt,
			callback=self.set_sync_check_txt,
			label="Sync check",
			converter=forms.int_converter(),
		)
		self.GridAdd(self._sync_check_txt_static_text, 0, 3, 1, 1)
		self._satname_txt_static_text = forms.static_text(
			parent=self.GetWin(),
			value=self.satname_txt,
			callback=self.set_satname_txt,
			label="Satellite",
			converter=forms.str_converter(),
		)
		self.GridAdd(self._satname_txt_static_text, 0, 0, 1, 1)
		_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.0,
			maximum=0.5,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_pll_alpha_sizer, 1, 0, 1, 1)
		self._frames_file_txt_static_text = forms.static_text(
			parent=self.displays.GetPage(1).GetWin(),
			value=self.frames_file_txt,
			callback=self.set_frames_file_txt,
			label="Frames output filename",
			converter=forms.str_converter(),
		)
		self.displays.GetPage(1).GridAdd(self._frames_file_txt_static_text, 2, 0, 1, 1)
		self._decim_txt_static_text = forms.static_text(
			parent=self.GetWin(),
			value=self.decim_txt,
			callback=self.set_decim_txt,
			label="Decimation",
			converter=forms.str_converter(),
		)
		self.GridAdd(self._decim_txt_static_text, 0, 1, 1, 1)
		_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.0,
			maximum=0.5,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_clock_alpha_sizer, 1, 1, 1, 1)
		self._baseband_file_txt_static_text = forms.static_text(
			parent=self.displays.GetPage(1).GetWin(),
			value=self.baseband_file_txt,
			callback=self.set_baseband_file_txt,
			label="Baseband filename",
			converter=forms.str_converter(),
		)
		self.displays.GetPage(1).GridAdd(self._baseband_file_txt_static_text, 1, 0, 1, 1)

		##################################################
		# Blocks
		##################################################
		self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)
		self.decoder = noaa.hrpt_decoder(True,False)
		self.frame_sink = gr.file_sink(gr.sizeof_short*1, "/home/jerry/NOAA-XX.hrpt")
		self.frame_sink.set_unbuffered(False)
		self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(sps/2.0, clock_alpha**2/4.0, 0.5, clock_alpha, max_clock_offset)
		self.gr_file_source_0 = gr.file_source(gr.sizeof_short*1, "/home/jerry/hrpt/baseband/NOAA-18/2011-01-07T132821-NOAA-18.dat", False)
		self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex()
		self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0/hs, 4000)
		self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset)
		self.poesweather_noaa_hrpt_deframer_0 = poesweather.noaa_hrpt_deframer(sync_check)
		self.rx_fft = fftsink2.fft_sink_c(
			self.displays.GetPage(0).GetWin(),
			baseband_freq=0,
			y_per_div=5,
			y_divs=10,
			ref_level=45,
			ref_scale=2.0,
			sample_rate=sample_rate,
			fft_size=1024,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="NOAA HRPT Spectrum",
			peak_hold=False,
		)
		self.displays.GetPage(0).Add(self.rx_fft.win)
		self.throttle = gr.throttle(gr.sizeof_short*1, sample_rate*10)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_interleaved_short_to_complex_0, 0), (self.agc, 0))
		self.connect((self.throttle, 0), (self.gr_interleaved_short_to_complex_0, 0))
		self.connect((self.gr_file_source_0, 0), (self.throttle, 0))
		self.connect((self.agc, 0), (self.rx_fft, 0))
		self.connect((self.poesweather_noaa_hrpt_deframer_0, 0), (self.frame_sink, 0))
		self.connect((self.poesweather_noaa_hrpt_deframer_0, 0), (self.decoder, 0))
		self.connect((self.gr_binary_slicer_fb_0, 0), (self.poesweather_noaa_hrpt_deframer_0, 0))
		self.connect((self.agc, 0), (self.pll, 0))
		self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_binary_slicer_fb_0, 0))
Пример #31
0
    def __init__(self, input_filename="usrp.dat", decim=32):
        grc_wxgui.top_block_gui.__init__(self, title="USRP HRPT Receiver")

        ##################################################
        # Parameters
        ##################################################
        self.input_filename = input_filename
        self.decim = decim

        ##################################################
        # Variables
        ##################################################
        self.sym_rate = sym_rate = 600 * 1109
        self.sample_rate = sample_rate = 64e6 / decim
        self.config_filename = config_filename = os.environ[
            'HOME'] + '/.gnuradio/config.conf'
        self.sps = sps = sample_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(
                'usrp_rx_hrpt', 'pll_alpha')
        except:
            saved_pll_alpha = 0.01
        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(
                'usrp_rx_hrpt', 'clock_alpha')
        except:
            saved_clock_alpha = 0.01
        self.saved_clock_alpha = saved_clock_alpha
        self.pll_alpha = pll_alpha = saved_pll_alpha
        self._output_filename_config = ConfigParser.ConfigParser()
        self._output_filename_config.read(config_filename)
        try:
            output_filename = self._output_filename_config.get(
                'usrp_rx_hrpt', 'filename')
        except:
            output_filename = 'frames.hrpt'
        self.output_filename = output_filename
        self.max_clock_offset = max_clock_offset = 100e-6
        self.max_carrier_offset = max_carrier_offset = 2 * math.pi * 100e3 / sample_rate
        self.hs = hs = int(sps / 2.0)
        self.clock_alpha = clock_alpha = saved_clock_alpha

        ##################################################
        # Notebooks
        ##################################################
        self.displays = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "Spectrum")
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "Demod")
        self.GridAdd(self.displays, 1, 0, 1, 2)

        ##################################################
        # Controls
        ##################################################
        _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.0,
            maximum=0.5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_pll_alpha_sizer, 0, 0, 1, 1)
        _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.0,
            maximum=0.5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_clock_alpha_sizer, 0, 1, 1, 1)

        ##################################################
        # Blocks
        ##################################################
        self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)
        self.decoder = noaa.hrpt_decoder(True, False)
        self.deframer = noaa.hrpt_deframer()
        self.demod_scope = scopesink2.scope_sink_f(
            self.displays.GetPage(1).GetWin(),
            title="Post-Demod",
            sample_rate=sym_rate * 2.0,
            v_scale=0.5,
            v_offset=0,
            t_scale=10.0 / sym_rate,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
        )
        self.displays.GetPage(1).GridAdd(self.demod_scope.win, 0, 0, 1, 1)
        self.frame_sink = gr.file_sink(gr.sizeof_short * 1, output_filename)
        self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(
            sps / 2.0, clock_alpha**2 / 4.0, 0.5, clock_alpha,
            max_clock_offset)
        self.gr_file_source_0 = gr.file_source(gr.sizeof_short * 1,
                                               input_filename, False)
        self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex(
        )
        self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0 / hs, 4000)
        self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2 / 4.0,
                                    max_carrier_offset)
        self.rx_fft = fftsink2.fft_sink_c(
            self.displays.GetPage(0).GetWin(),
            baseband_freq=0,
            y_per_div=5,
            y_divs=8,
            ref_level=-5,
            ref_scale=2.0,
            sample_rate=sample_rate,
            fft_size=1024,
            fft_rate=15,
            average=True,
            avg_alpha=0.1,
            title="RX Spectrum",
            peak_hold=False,
            size=(640, 360),
        )
        self.displays.GetPage(0).GridAdd(self.rx_fft.win, 0, 0, 1, 1)
        self.throttle = gr.throttle(gr.sizeof_short * 1, 2 * sample_rate)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_binary_slicer_fb_0, 0))
        self.connect((self.deframer, 0), (self.frame_sink, 0))
        self.connect((self.deframer, 0), (self.decoder, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.demod_scope, 0))
        self.connect((self.gr_moving_average_xx_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
        self.connect((self.agc, 0), (self.pll, 0))
        self.connect((self.agc, 0), (self.rx_fft, 0))
        self.connect((self.gr_interleaved_short_to_complex_0, 0),
                     (self.agc, 0))
        self.connect((self.throttle, 0),
                     (self.gr_interleaved_short_to_complex_0, 0))
        self.connect((self.gr_file_source_0, 0), (self.throttle, 0))
        self.connect((self.gr_binary_slicer_fb_0, 0), (self.deframer, 0))
Пример #32
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="USRP HRPT Receiver")

        ##################################################
        # Variables
        ##################################################
        self.sym_rate = sym_rate = 600 * 1109
        self.sample_rate = sample_rate = 4e6
        self.config_filename = config_filename = os.environ[
            'HOME'] + '/.gnuradio/config.conf'
        self.sps = sps = sample_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(
                'usrp_rx_hrpt', 'pll_alpha')
        except:
            saved_pll_alpha = 0.01
        self.saved_pll_alpha = saved_pll_alpha
        self._saved_gain_config = ConfigParser.ConfigParser()
        self._saved_gain_config.read(config_filename)
        try:
            saved_gain = self._saved_gain_config.getfloat(
                'usrp_rx_hrpt', 'gain')
        except:
            saved_gain = 35
        self.saved_gain = saved_gain
        self._saved_freq_config = ConfigParser.ConfigParser()
        self._saved_freq_config.read(config_filename)
        try:
            saved_freq = self._saved_freq_config.getfloat(
                'usrp_rx_hrpt', 'freq')
        except:
            saved_freq = 1698e6
        self.saved_freq = saved_freq
        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(
                'usrp_rx_hrpt', 'clock_alpha')
        except:
            saved_clock_alpha = 0.01
        self.saved_clock_alpha = saved_clock_alpha
        self._addr_config = ConfigParser.ConfigParser()
        self._addr_config.read(config_filename)
        try:
            addr = self._addr_config.get('usrp_rx_hrpt', 'addr')
        except:
            addr = ""
        self.addr = addr
        self.rate_text = rate_text = sample_rate
        self.pll_alpha = pll_alpha = saved_pll_alpha
        self._output_filename_config = ConfigParser.ConfigParser()
        self._output_filename_config.read(config_filename)
        try:
            output_filename = self._output_filename_config.get(
                'usrp_rx_hrpt', 'filename')
        except:
            output_filename = 'frames.hrpt'
        self.output_filename = output_filename
        self.max_clock_offset = max_clock_offset = 100e-6
        self.max_carrier_offset = max_carrier_offset = 2 * math.pi * 100e3 / sample_rate
        self.hs = hs = int(sps / 2.0)
        self.gain = gain = saved_gain
        self.freq = freq = saved_freq
        self.clock_alpha = clock_alpha = saved_clock_alpha
        self.addr_text = addr_text = addr

        ##################################################
        # Blocks
        ##################################################
        self._freq_text_box = forms.text_box(
            parent=self.GetWin(),
            value=self.freq,
            callback=self.set_freq,
            label="Frequency",
            converter=forms.float_converter(),
        )
        self.GridAdd(self._freq_text_box, 0, 0, 1, 1)
        self.displays = self.displays = wx.Notebook(self.GetWin(),
                                                    style=wx.NB_TOP)
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "Spectrum")
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "Demod")
        self.GridAdd(self.displays, 2, 0, 1, 4)
        _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.0,
            maximum=0.5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_clock_alpha_sizer, 0, 3, 1, 1)
        self.uhd_usrp_source_0 = uhd.usrp_source(
            device_addr=addr,
            io_type=uhd.io_type.COMPLEX_FLOAT32,
            num_channels=1,
        )
        self.uhd_usrp_source_0.set_samp_rate(sample_rate)
        self.uhd_usrp_source_0.set_center_freq(freq, 0)
        self.uhd_usrp_source_0.set_gain(0, 0)
        self.rx_fft = fftsink2.fft_sink_c(
            self.displays.GetPage(0).GetWin(),
            baseband_freq=freq,
            y_per_div=5,
            y_divs=8,
            ref_level=-5,
            ref_scale=2.0,
            sample_rate=sample_rate,
            fft_size=1024,
            fft_rate=15,
            average=True,
            avg_alpha=0.1,
            title="RX Spectrum",
            peak_hold=False,
            size=(640, 360),
        )
        self.displays.GetPage(0).GridAdd(self.rx_fft.win, 0, 0, 1, 1)
        self._rate_text_static_text = forms.static_text(
            parent=self.GetWin(),
            value=self.rate_text,
            callback=self.set_rate_text,
            label="Baseband Rate",
            converter=forms.float_converter(),
        )
        self.GridAdd(self._rate_text_static_text, 1, 1, 1, 1)
        _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.0,
            maximum=0.5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_pll_alpha_sizer, 0, 2, 1, 1)
        self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2 / 4.0,
                                    max_carrier_offset)
        self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0 / hs, 4000)
        _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="RX 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=100,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_gain_sizer, 0, 1, 1, 1)
        self.frame_sink = gr.file_sink(gr.sizeof_short * 1, output_filename)
        self.frame_sink.set_unbuffered(False)
        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.demod_scope = scopesink2.scope_sink_f(
            self.displays.GetPage(1).GetWin(),
            title="Post-Demod",
            sample_rate=sym_rate * 2.0,
            v_scale=0.5,
            v_offset=0,
            t_scale=10.0 / sym_rate,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
            trig_mode=gr.gr_TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.displays.GetPage(1).GridAdd(self.demod_scope.win, 0, 0, 1, 1)
        self.deframer = noaa.hrpt_deframer()
        self.decoder = noaa.hrpt_decoder(True, True)
        self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)
        self._addr_text_static_text = forms.static_text(
            parent=self.GetWin(),
            value=self.addr_text,
            callback=self.set_addr_text,
            label="USRP Addr",
            converter=forms.str_converter(),
        )
        self.GridAdd(self._addr_text_static_text, 1, 0, 1, 1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.deframer, 0), (self.frame_sink, 0))
        self.connect((self.deframer, 0), (self.decoder, 0))
        self.connect((self.agc, 0), (self.pll, 0))
        self.connect((self.agc, 0), (self.rx_fft, 0))
        self.connect((self.uhd_usrp_source_0, 0), (self.agc, 0))
        self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
        self.connect((self.gr_moving_average_xx_0, 0), (self.demod_scope, 0))
        self.connect((self.gr_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.digital_binary_slicer_fb_0, 0), (self.deframer, 0))
Пример #33
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="USRP LRIT Receiver")

        ##################################################
        # Variables
        ##################################################
        self.config_filename = config_filename = os.environ[
            'HOME'] + '/.gnuradio/config.conf'
        self._saved_decim_config = ConfigParser.ConfigParser()
        self._saved_decim_config.read(config_filename)
        try:
            saved_decim = self._saved_decim_config.getint(
                'usrp_rx_lrit', 'decim')
        except:
            saved_decim = 160
        self.saved_decim = saved_decim
        self.decim = decim = saved_decim
        self.symbol_rate = symbol_rate = 293e3
        self._saved_offset_config = ConfigParser.ConfigParser()
        self._saved_offset_config.read(config_filename)
        try:
            saved_offset = self._saved_offset_config.getfloat(
                'usrp_rx_lrit', 'offset')
        except:
            saved_offset = 0
        self.saved_offset = saved_offset
        self._saved_gain_mu_config = ConfigParser.ConfigParser()
        self._saved_gain_mu_config.read(config_filename)
        try:
            saved_gain_mu = self._saved_gain_mu_config.getfloat(
                'usrp_rx_lrit', 'gain_mu')
        except:
            saved_gain_mu = 0.005
        self.saved_gain_mu = saved_gain_mu
        self._saved_gain_config = ConfigParser.ConfigParser()
        self._saved_gain_config.read(config_filename)
        try:
            saved_gain = self._saved_gain_config.getfloat(
                'usrp_rx_lrit', 'gain')
        except:
            saved_gain = 33
        self.saved_gain = saved_gain
        self._saved_freq_config = ConfigParser.ConfigParser()
        self._saved_freq_config.read(config_filename)
        try:
            saved_freq = self._saved_freq_config.getfloat(
                'usrp_rx_lrit', 'freq')
        except:
            saved_freq = 1691e6
        self.saved_freq = saved_freq
        self._saved_costas_alpha_config = ConfigParser.ConfigParser()
        self._saved_costas_alpha_config.read(config_filename)
        try:
            saved_costas_alpha = self._saved_costas_alpha_config.getfloat(
                'usrp_rx_lrit', 'costas_alpha')
        except:
            saved_costas_alpha = 0.005
        self.saved_costas_alpha = saved_costas_alpha
        self.sample_rate = sample_rate = 64e6 / decim
        self.sps = sps = sample_rate / symbol_rate
        self._side_config = ConfigParser.ConfigParser()
        self._side_config.read(config_filename)
        try:
            side = self._side_config.get('usrp_rx_lrit', 'side')
        except:
            side = 'A'
        self.side = side
        self.offset = offset = saved_offset
        self.gain_mu = gain_mu = saved_gain_mu
        self.gain = gain = saved_gain
        self.freq = freq = saved_freq
        self.costas_alpha = costas_alpha = saved_costas_alpha

        ##################################################
        # Notebooks
        ##################################################
        self.displays = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "USRP RX")
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "RRC")
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "PLL")
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "Const")
        self.GridAdd(self.displays, 2, 0, 1, 3)

        ##################################################
        # Controls
        ##################################################
        self._decim_text_box = forms.text_box(
            parent=self.GetWin(),
            value=self.decim,
            callback=self.set_decim,
            label="Decim",
            converter=forms.int_converter(),
        )
        self.GridAdd(self._decim_text_box, 0, 2, 1, 1)
        _offset_sizer = wx.BoxSizer(wx.VERTICAL)
        self._offset_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_offset_sizer,
            value=self.offset,
            callback=self.set_offset,
            label="Offset",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._offset_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_offset_sizer,
            value=self.offset,
            callback=self.set_offset,
            minimum=-50e3,
            maximum=50e3,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_offset_sizer, 0, 1, 1, 1)
        _gain_mu_sizer = wx.BoxSizer(wx.VERTICAL)
        self._gain_mu_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_gain_mu_sizer,
            value=self.gain_mu,
            callback=self.set_gain_mu,
            label="Gain Mu",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._gain_mu_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_gain_mu_sizer,
            value=self.gain_mu,
            callback=self.set_gain_mu,
            minimum=0,
            maximum=0.5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_gain_mu_sizer, 1, 2, 1, 1)
        _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=115,
            num_steps=115,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_gain_sizer, 1, 0, 1, 1)
        self._freq_text_box = forms.text_box(
            parent=self.GetWin(),
            value=self.freq,
            callback=self.set_freq,
            label="Frequency",
            converter=forms.float_converter(),
        )
        self.GridAdd(self._freq_text_box, 0, 0, 1, 1)
        _costas_alpha_sizer = wx.BoxSizer(wx.VERTICAL)
        self._costas_alpha_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_costas_alpha_sizer,
            value=self.costas_alpha,
            callback=self.set_costas_alpha,
            label="Costas Alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._costas_alpha_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_costas_alpha_sizer,
            value=self.costas_alpha,
            callback=self.set_costas_alpha,
            minimum=0,
            maximum=0.5,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.GridAdd(_costas_alpha_sizer, 1, 1, 1, 1)

        ##################################################
        # Blocks
        ##################################################
        self.costas = gr.costas_loop_cc(costas_alpha,
                                        (costas_alpha**2.0) / 4.0, 50e-6 * sps,
                                        -50e-6 * sps, 2)
        self.costas_spectrum = fftsink2.fft_sink_c(
            self.displays.GetPage(2).GetWin(),
            baseband_freq=freq + offset,
            y_per_div=10,
            y_divs=10,
            ref_level=-15,
            ref_scale=2.0,
            sample_rate=sample_rate,
            fft_size=1024,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title="PLL Spectrum",
            peak_hold=False,
        )
        self.displays.GetPage(2).GridAdd(self.costas_spectrum.win, 0, 0, 1, 1)
        self.costas_waveform = scopesink2.scope_sink_c(
            self.displays.GetPage(2).GetWin(),
            title="PLL Waveform",
            sample_rate=sample_rate,
            v_scale=0.5,
            v_offset=0,
            t_scale=20.0 / sample_rate,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
        )
        self.displays.GetPage(2).GridAdd(self.costas_waveform.win, 1, 0, 1, 1)
        self.gr_agc_xx_0 = gr.agc_cc(1e-6, 1.0, 1.0 / 32767.0, 1.0)
        self.mm_const = scopesink2.scope_sink_c(
            self.displays.GetPage(3).GetWin(),
            title="Constellation",
            sample_rate=symbol_rate,
            v_scale=0.5,
            v_offset=0,
            t_scale=20.0 / symbol_rate,
            ac_couple=False,
            xy_mode=True,
            num_inputs=1,
        )
        self.displays.GetPage(3).GridAdd(self.mm_const.win, 1, 0, 1, 1)
        self.mm_spectrum = fftsink2.fft_sink_c(
            self.displays.GetPage(3).GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=-15,
            ref_scale=2.0,
            sample_rate=symbol_rate,
            fft_size=1024,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title="Bit Sync Spectrum",
            peak_hold=False,
        )
        self.displays.GetPage(3).GridAdd(self.mm_spectrum.win, 0, 0, 1, 1)
        self.mm_sync = gr.clock_recovery_mm_cc(sps, (gain_mu**2) / 4.0, 0.5,
                                               gain_mu, 50e-6 * sps)
        self.root_raised_cosine_filter_0 = gr.fir_filter_ccf(
            1,
            firdes.root_raised_cosine(1, sample_rate, symbol_rate, 0.25,
                                      int(11 * sample_rate / symbol_rate)))
        self.rrc_spectrum = fftsink2.fft_sink_c(
            self.displays.GetPage(1).GetWin(),
            baseband_freq=freq + offset,
            y_per_div=10,
            y_divs=10,
            ref_level=-15,
            ref_scale=2.0,
            sample_rate=sample_rate,
            fft_size=1024,
            fft_rate=15,
            average=False,
            avg_alpha=None,
            title="RRC Spectrum",
            peak_hold=False,
        )
        self.displays.GetPage(1).GridAdd(self.rrc_spectrum.win, 0, 0, 1, 1)
        self.rrc_waveform = scopesink2.scope_sink_c(
            self.displays.GetPage(1).GetWin(),
            title="RRC Waveform",
            sample_rate=sample_rate,
            v_scale=0.5,
            v_offset=0,
            t_scale=20.0 / sample_rate,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
        )
        self.displays.GetPage(1).GridAdd(self.rrc_waveform.win, 1, 0, 1, 1)
        self.rx_spectrum = fftsink2.fft_sink_c(
            self.displays.GetPage(0).GetWin(),
            baseband_freq=freq,
            y_per_div=10,
            y_divs=10,
            ref_level=50,
            ref_scale=2.0,
            sample_rate=sample_rate,
            fft_size=1024,
            fft_rate=30,
            average=False,
            avg_alpha=None,
            title="RX Spectrum",
            peak_hold=False,
        )
        self.displays.GetPage(0).GridAdd(self.rx_spectrum.win, 0, 0, 1, 1)
        self.rx_waveform = scopesink2.scope_sink_c(
            self.displays.GetPage(0).GetWin(),
            title="RX Waveform",
            sample_rate=sample_rate,
            v_scale=0,
            v_offset=0,
            t_scale=20.0 / sample_rate,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
        )
        self.displays.GetPage(0).GridAdd(self.rx_waveform.win, 1, 0, 1, 1)
        self.usrp_simple_source_x_0 = grc_usrp.simple_source_c(which=0,
                                                               side=side,
                                                               rx_ant="RXA")
        self.usrp_simple_source_x_0.set_decim_rate(decim)
        self.usrp_simple_source_x_0.set_frequency(freq + offset, verbose=True)
        self.usrp_simple_source_x_0.set_gain(gain)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_agc_xx_0, 0),
                     (self.root_raised_cosine_filter_0, 0))
        self.connect((self.usrp_simple_source_x_0, 0), (self.gr_agc_xx_0, 0))
        self.connect((self.usrp_simple_source_x_0, 0), (self.rx_spectrum, 0))
        self.connect((self.usrp_simple_source_x_0, 0), (self.rx_waveform, 0))
        self.connect((self.root_raised_cosine_filter_0, 0),
                     (self.rrc_waveform, 0))
        self.connect((self.root_raised_cosine_filter_0, 0),
                     (self.rrc_spectrum, 0))
        self.connect((self.root_raised_cosine_filter_0, 0), (self.costas, 0))
        self.connect((self.costas, 0), (self.costas_spectrum, 0))
        self.connect((self.costas, 0), (self.costas_waveform, 0))
        self.connect((self.costas, 0), (self.mm_sync, 0))
        self.connect((self.mm_sync, 0), (self.mm_spectrum, 0))
        self.connect((self.mm_sync, 0), (self.mm_const, 0))
Пример #34
0
    def __init__(self, options):
	gr.top_block.__init__(self)
	self.options = options

	(usrp_decim, channel_decim, audio_decim, 
	 channel_pass, channel_stop, demod) = demod_params[options.modulation]

        USRP = usrp_src(options.rx_subdev_spec, # Daugherboard spec
	                usrp_decim,     	# IF decimation ratio
			options.gain, 	    	# Receiver gain
			options.calibration)    # Frequency offset
	USRP.tune(options.frequency)

	if_rate = USRP.rate()
        channel_rate = if_rate // channel_decim
	audio_rate = channel_rate // audio_decim

	CHAN_taps = optfir.low_pass(1.0,         # Filter gain
				   if_rate, 	 # Sample rate
				   channel_pass, # One sided modulation bandwidth
	                           channel_stop, # One sided channel bandwidth
				   0.1, 	 # Passband ripple
				   60) 		 # Stopband attenuation

	CHAN = gr.freq_xlating_fir_filter_ccf(channel_decim, # Decimation rate
	                                      CHAN_taps,     # Filter taps
					      0.0, 	     # Offset frequency
					      if_rate)	     # Sample rate

	RFSQL = gr.pwr_squelch_cc(options.rf_squelch,    # Power threshold
	                          125.0/channel_rate, 	 # Time constant
				  channel_rate/20,       # 50ms rise/fall
				  False)		 # Zero, not gate output

	AGC = gr.agc_cc(1.0/channel_rate,  # Time constant
			1.0,     	   # Reference power 
			1.0,               # Initial gain
			1.0)		   # Maximum gain

	DEMOD = demod(channel_rate, audio_decim)

	# From RF to audio
        self.connect(USRP, CHAN, RFSQL, AGC, DEMOD)

	# Optionally add CTCSS and RSAMP if needed
	tail = DEMOD
	if options.ctcss != None and options.ctcss > 60.0:
	    CTCSS = gr.ctcss_squelch_ff(audio_rate,    # Sample rate
				        options.ctcss) # Squelch tone
	    self.connect(DEMOD, CTCSS)
	    tail = CTCSS

	if options.output_rate != audio_rate:
	    out_lcm = gru.lcm(audio_rate, options.output_rate)
	    out_interp = int(out_lcm // audio_rate)
	    out_decim = int(out_lcm // options.output_rate)
	    RSAMP = blks2.rational_resampler_fff(out_interp, out_decim)
	    self.connect(tail, RSAMP)
	    tail = RSAMP 

	# Send to default audio output
        AUDIO = audio.sink(options.output_rate, "")
	self.connect(tail, AUDIO)
Пример #35
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 = blks2.pfb_arb_resampler_ccf(rrate)

        chan_filt_coeffs = gr.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 = gr.freq_xlating_fir_filter_ccf (chanfilt_decim,
                                                           chan_filt_coeffs,
                                                           self.IF_freq,
                                                           usrp_rate)
        else:
          self.chan_filt = gr.fir_filter_ccf (chanfilt_decim, chan_filt_coeffs)

        self.agc = gr.agc_cc(0.1, 1, 1, 100000)
        self.am_demod = gr.complex_to_mag()
        self.volume_control = gr.multiply_const_ff(self.vol)

        audio_filt_coeffs = gr.firdes.low_pass_2 (1,          # gain
                                                  demod_rate, # sampling rate
                                                  8e3,        # passband cutoff
                                                  2e3,        # transition bw
                                                  60)         # stopband attenuation
        self.audio_filt=gr.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")
Пример #36
0
    def __init__(self, parent, ID, title):
        wxFrame.__init__(self, parent, ID, title,
                wxDefaultPosition)

        self.pga = 0
        self.pgaMin = -20
        self.pgaMax = 0
        self.pgaStep = 0.25

# Parsing options
        parser = OptionParser(option_class=eng_option,
                usage="usage: %prog [options] filename1" \
                " [-f frequency2 filename2 [...]]")
        parser.add_option("-a", "--agc", action="store_true",
                help="enable agc")
        parser.add_option("-c", "--clockrate", type="eng_float", default=128e6,
                help="set USRP clock rate (128e6)")
        parser.add_option("--copy", action="store_true",
                help="enable real to imag data copy when in real mode")
        parser.add_option("-e", "--encoding", type="choice", choices=["s", "f"],
                default="f", help="choose data encoding: [s]igned or [f]loat.")
        parser.add_option("-f", "--frequency", type="eng_float",
                action="callback", callback=appendFrequency,
                help="set output frequency (222.064e6)")
        parser.add_option("-g", "--gain", type="float",
                help="set output pga gain")
        parser.add_option("-l", "--list", action="callback", callback=listUsrp,
                help="list USRPs and daugtherboards")
        parser.add_option("-m", "--mode", type="eng_float", default=2,
                help="mode: 1: real, 2: complex (2)")
        parser.add_option("-o", "--osc", action="store_true",
                help="enable oscilloscope")
        parser.add_option("-r", "--samplingrate", type="eng_float",
                default=3.2e6,
                help="set input sampling rate (3200000)")
        parser.add_option("-s", "--spectrum", action="store_true",
                help="enable spectrum analyzer")
#        parser.add_option("-t", "--tx", type="choice", choices=["A", "B"],
#                default="A", help="choose USRP tx A|B output (A)")
        parser.add_option("-u", "--usrp", action="store_true",
                help="enable USRP output")

        (options, args) = parser.parse_args()
        if len(args) == 0 :
            options.filename = [ "/dev/stdin" ]
        else :
            options.filename = args
# Setting default frequency
        if options.frequency is None :
            options.frequency = [ 222.064e6 ]
        if len(options.filename) != len(options.frequency) :
            parser.error("Nb input file != nb frequency!")

# Status bar
#        self.CreateStatusBar(3, 0)
#        msg = "PGA: %.2f dB" % (self.pga * self.pgaStep)
#        self.SetStatusText(msg, 1)
#        msg = "Freq: %.3f mHz" % (options.frequency[0] / 1000000.0)
#        self.SetStatusText(msg, 2)

# Menu bar
        menu = wxMenu()
        menu.Append(ID_ABOUT, "&About",
                "More information about this program")
        menu.AppendSeparator()
        menu.Append(ID_EXIT, "E&xit", "Terminate the program")
        menuBar = wxMenuBar()
        menuBar.Append(menu, "&File")
        self.SetMenuBar(menuBar)
        

# Main windows
        mainSizer = wxFlexGridSizer(0, 1)
        sliderSizer = wxFlexGridSizer(0, 2)
        buttonSizer = wxBoxSizer(wxHORIZONTAL)

        if options.usrp :
            # TX d'board 0
            gainLabel = wxStaticText(self, -1, "PGA 0")
            gainSlider = wxSlider(self, ID_GAIN_SLIDER0, self.pga,
                    self.pgaMin / self.pgaStep, self.pgaMax / self.pgaStep,
                    style = wxSL_HORIZONTAL | wxSL_AUTOTICKS)
            gainSlider.SetSize((400, -1))
            sliderSizer.Add(gainLabel, 0,
                    wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0)
            sliderSizer.Add(gainSlider, 0,
                    wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0)

            freqLabel = wxStaticText(self, -1, "Frequency 0")
            freqSlider = wxSlider(self, ID_FREQ_SLIDER0,
                    options.frequency[0] / 16000, 0, 20e3,
                    style = wxSL_HORIZONTAL | wxSL_AUTOTICKS)
            freqSlider.SetSize((400, -1))
            sliderSizer.Add(freqLabel, 0,
                    wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0)
            sliderSizer.Add(freqSlider, 0,
                    wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0)

            if len(options.frequency) > 1 :
                # TX d'board 1
                gainLabel = wxStaticText(self, -1, "PGA 1")
                gainSlider = wxSlider(self, ID_GAIN_SLIDER1, self.pga,
                        self.pgaMin / self.pgaStep, self.pgaMax / self.pgaStep,
                        style = wxSL_HORIZONTAL | wxSL_AUTOTICKS)
                gainSlider.SetSize((400, -1))
                sliderSizer.Add(gainLabel, 0,
                        wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0)
                sliderSizer.Add(gainSlider, 0,
                        wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0)

                freqLabel = wxStaticText(self, -1, "Frequency 1")
                freqSlider = wxSlider(self, ID_FREQ_SLIDER1,
                        options.frequency[1] / 16000, 0, 20e3,
                        style = wxSL_HORIZONTAL | wxSL_AUTOTICKS)
                freqSlider.SetSize((400, -1))
                sliderSizer.Add(freqLabel, 0,
                        wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0)
                sliderSizer.Add(freqSlider, 0,
                        wxALIGN_CENTER_VERTICAL | wxFIXED_MINSIZE, 0)

            mainSizer.Add(sliderSizer, 1, wxEXPAND, 0)

        start = wxButton(self, ID_START, "Start")
        stop = wxButton(self, ID_STOP, "Stop")
        buttonSizer.Add(start, 1, wxALIGN_CENTER, 0)
        buttonSizer.Add(stop, 1, wxALIGN_CENTER, 0)
        mainSizer.Add(buttonSizer, 1, wxEXPAND, 0)
    
# GnuRadio
        self.fg = gr.flow_graph()
        if options.mode == 1 :
            print "Source: real"
            if (options.encoding == "s") :
                print "Source encoding: short"
                src = gr.file_source(gr.sizeof_short, options.filename[0], 1)
                if (options.copy) :
                    print "Imag: copy"
                    imag = src
                else :
                    print "Imag: null"
                    imag = gr.null_source(gr.sizeof_short)
                interleaver = gr.interleave(gr.sizeof_short)
                self.fg.connect(src, (interleaver, 0))
                self.fg.connect(imag, (interleaver, 1))
                tail = interleaver
            elif (options.encoding == "f") :
                print "Source encoding: float"
                src = gr.file_source(gr.sizeof_gr_complex,
                    options.filename[0], 1)
                tail = src
        elif (options.mode == 2) :
            print "Source: complex"
            if len(options.frequency) == 1 :
                if (options.encoding == "s") :
                    print "Source encoding: short"
                    src = gr.file_source(gr.sizeof_short,
                            options.filename[0], 1)
                elif (options.encoding == "f") :
                    print "Source encoding: float"
                    src = gr.file_source(gr.sizeof_gr_complex,
                            options.filename[0], 1)
                else :
                    parser.error("Invalid encoding type for complex data!")
                tail = src
                    
            elif (len(options.frequency) == 2) :
                src0 = gr.file_source(gr.sizeof_gr_complex,
                        options.filename[0], 1)
                src1 = gr.file_source(gr.sizeof_gr_complex,
                        options.filename[1], 1)
                interleaver = gr.interleave(gr.sizeof_gr_complex)
                self.fg.connect(src0, (interleaver, 0))
                self.fg.connect(src1, (interleaver, 1))
                tail = interleaver
            else :
                parser.error(
                        "Invalid number of source (> 2) with complex input!")
        else :
            parser.error("Invalid mode!")

# Interpolation
        dac_freq = options.clockrate
        interp = int(dac_freq / options.samplingrate)
        if interp == 0 :
            parser.error("Invalid sampling rate!")
        if options.mode == 2 :
            print "Input sampling rate: %s complex samples/s" % \
                num_to_str(options.samplingrate)
        else :
            print "Input sampling rate: %s samples/s" % \
                num_to_str(options.samplingrate)
        print "Interpolation rate: int(%s / %s) = %sx" % \
            (num_to_str(dac_freq), num_to_str(options.samplingrate), interp)
        if interp > 512 :
            factor = gcd(dac_freq / 512, options.samplingrate)
            num = int((dac_freq / 512) / factor)
            den = int(options.samplingrate / factor)
            print "Resampling by %i / %i" % (num, den)
            resampler = blks.rational_resampler_ccc(self.fg, num, den)
            self.fg.connect(tail, resampler)
            tail = resampler
            interp = 512
            options.samplingrate = dac_freq / 512

# AGC
        if options.agc :
            agc = gr.agc_cc()
            self.fg.connect(tail, agc)
            tail = agc
            
# USRP
        if options.usrp :
            nchan = len(options.frequency)
            if len(options.frequency) == 1 :
                if options.mode == 1 :
                    mux = 0x00000098
                elif options.mode == 2 :
                    mux = 0x00000098
                else :
                    parser.error("Unsupported mode for USRP mux!")
            elif len(options.frequency) == 2 :
                if options.mode == 1 :
                    mux = 0x0000ba98
                elif options.mode == 2 :
                    mux = 0x0000ba98
                else :
                    parser.error("Unsupported mode for USRP mux!")
            else :
                parser.error("Invalid number of frequency [0..2]!")
#            if options.tx == "A" :
#                mux = 0x00000098
#            else :
#                mux = 0x00009800
            print "Nb channels: ", nchan
            print "Mux: 0x%x" % mux
            if options.encoding == 's' :
                dst = usrp.sink_s(0, interp, nchan, mux)
            elif options.encoding == 'f' :
                dst = usrp.sink_c(0, interp, nchan, mux)
            else :
                parser.error("Unsupported data encoding for USRP!")
            
            dst.set_verbose(1)

            for i in range(len(options.frequency)) :
                if options.gain is None :
                    print "Setting gain to %f" % dst.pga_max()
                    dst.set_pga(i << 1, dst.pga_max())
                else :
                    print "Setting gain to %f" % options.gain
                    dst.set_pga(i << 1, options.gain)

                tune = false
                for dboard in dst.db:
                    if (dboard[0].dbid() != -1):
                        device = dboard[0]
                        print "Tuning TX d'board %s to %sHz" % \
                                (device.side_and_name(),
                                num_to_str(options.frequency[i]))
                        device.lo_offset = 38e6
                        (min, max, offset) = device.freq_range()
                        print " Frequency"
                        print "  Min:    %sHz" % num_to_str(min)
                        print "  Max:    %sHz" % num_to_str(max)
                        print "  Offset: %sHz" % num_to_str(offset)
#device.set_gain(device.gain_range()[1])
                        device.set_enable(True)
                        tune = \
                            dst.tune(device._which, device,
                                    options.frequency[i] * 128e6 / dac_freq)
                        if tune:
                            print "  Baseband frequency: %sHz" % \
                                num_to_str(tune.baseband_freq)
                            print "  DXC frequency: %sHz" % \
                                num_to_str(tune.dxc_freq)
                            print "  Residual Freqency: %sHz" % \
                                num_to_str(tune.residual_freq)
                            print "  Inverted: ", \
                                tune.inverted
                            mux = usrp.determine_tx_mux_value(dst,
                                    (device._which, 0))
                            dst.set_mux(mux)
                            break
                        else:
                            print "  Failed!"
                if not tune:
                    print "  Failed!"
                    raise SystemExit

# int nunderruns ()

            print "USRP"
            print " Rx halfband: ", dst.has_rx_halfband()
            print " Tx halfband: ", dst.has_tx_halfband()
            print " Nb DDC: ", dst.nddc()
            print " Nb DUC: ", dst.nduc()
#dst._write_9862(0, 14, 224)
            
            print " DAC frequency: %s samples/s" % num_to_str(dst.dac_freq())
            print " Fpga decimation rate: %s -> %s samples/s" % \
                (num_to_str(dst.interp_rate()),
                 num_to_str(dac_freq / dst.interp_rate()))
            print " Nb channels:",
            if hasattr(dst, "nchannels()") :
                print dst.nchannels()
            else:
                print "N/A"
            print " Mux:",
            if hasattr(dst, "mux()") :
                print "0x%x" % dst.mux()
            else :
                print "N/A"
            print " FPGA master clock frequency:",
            if hasattr(dst, "fpga_master_clock_freq()") :
                print "%sHz" % num_to_str(dst.fpga_master_clock_freq())
            else :
                print "N/A"
            print " Converter rate:",
            if hasattr(dst, "converter_rate()") :
                print "%s" % num_to_str(dst.converter_rate())
            else :
                print "N/A"
            print " DAC rate:",
            if hasattr(dst, "dac_rate()") :
                print "%s sample/s" % num_to_str(dst.dac_rate())
            else :
                print "N/A"
            print " Interp rate: %sx" % num_to_str(dst.interp_rate())
            print " DUC frequency 0: %sHz" % num_to_str(dst.tx_freq(0))
            print " DUC frequency 1: %sHz" % num_to_str(dst.tx_freq(1))
            print " Programmable Gain Amplifier 0: %s dB" % \
                num_to_str(dst.pga(0))
            print " Programmable Gain Amplifier 1: %s dB" % \
                num_to_str(dst.pga(2))

        else :
            dst = gr.null_sink(gr.sizeof_gr_complex)
            
# AGC
        if options.agc :
            agc = gr.agc_cc()
            self.fg.connect(tail, agc)
            tail = agc
            
        self.fg.connect(tail, dst)

# oscilloscope
        if options.osc :
            oscPanel = wxPanel(self, -1)
            if (options.encoding == "s") :
                converter = gr.interleaved_short_to_complex()
                self.fg.connect(tail, converter)
                signal = converter
            elif (options.encoding == "f") :
                signal = tail
            else :
                parser.error("Unsupported data encoding for oscilloscope!")

#block = scope_sink_f(fg, parent, title=label, sample_rate=input_rate)
#return (block, block.win)

            oscWin = scopesink.scope_sink_c(self.fg, oscPanel, "Signal",
                    options.samplingrate)
            self.fg.connect(signal, oscWin)
            mainSizer.Add(oscPanel, 1, wxEXPAND)

# spectrometer
        if options.spectrum :
            ymin = 0
            ymax = 160
            fftPanel = wxPanel(self, -1)
            if (options.encoding == "s") :
                converter = gr.interleaved_short_to_complex()
                self.fg.connect(tail, converter)
                signal = converter
            elif (options.encoding == "f") :
                signal = tail
            else :
                parser.error("Unsupported data encoding for oscilloscope!")

            fftWin = fftsink.fft_sink_c(self.fg, fftPanel,
                    title="Spectrum",
                    fft_size=2048,
                    sample_rate=options.samplingrate,
                    y_per_div=(ymax - ymin) / 8,
                    ref_level=ymax,
                    fft_rate=50,
                    average=True
                    )
            self.fg.connect(signal, fftWin)
            mainSizer.Add(fftPanel, 1, wxEXPAND)

# Events
        EVT_MENU(self, ID_ABOUT, self.OnAbout)
        EVT_MENU(self, ID_EXIT,  self.TimeToQuit)
        EVT_SLIDER(self, ID_GAIN_SLIDER0, self.slideEvent)
        EVT_SLIDER(self, ID_FREQ_SLIDER0, self.slideEvent)
        EVT_SLIDER(self, ID_GAIN_SLIDER1, self.slideEvent)
        EVT_SLIDER(self, ID_FREQ_SLIDER1, self.slideEvent)
        EVT_BUTTON(self, ID_START, self.onClick)
        EVT_BUTTON(self, ID_STOP, self.onClick)

#Layout sizers
        self.SetSizer(mainSizer)
        self.SetAutoLayout(1)
        mainSizer.Fit(self)

        self.fg.start()
Пример #37
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="USRP HRPT Receiver")

		##################################################
		# Variables
		##################################################
		self.config_filename = config_filename = 'usrp_rx_hrpt.cfg'
		self._decim_config = ConfigParser.ConfigParser()
		self._decim_config.read(config_filename)
		try: decim = self._decim_config.getfloat('usrp', 'decim')
		except: decim = 16
		self.decim = decim
		self.sym_rate = sym_rate = 600*1109
		self.sample_rate = sample_rate = 64e6/decim
		self.sps = sps = sample_rate/sym_rate
		self._side_config = ConfigParser.ConfigParser()
		self._side_config.read(config_filename)
		try: side = self._side_config.get('usrp', 'side')
		except: side = 'A'
		self.side = side
		self._saved_sync_alpha_config = ConfigParser.ConfigParser()
		self._saved_sync_alpha_config.read(config_filename)
		try: saved_sync_alpha = self._saved_sync_alpha_config.getfloat('demod', 'sync_alpha')
		except: saved_sync_alpha = 0.05
		self.saved_sync_alpha = saved_sync_alpha
		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('demod', 'pll_alpha')
		except: saved_pll_alpha = 0.05
		self.saved_pll_alpha = saved_pll_alpha
		self._saved_gain_config = ConfigParser.ConfigParser()
		self._saved_gain_config.read(config_filename)
		try: saved_gain = self._saved_gain_config.getfloat('usrp', 'gain')
		except: saved_gain = 35
		self.saved_gain = saved_gain
		self._saved_freq_config = ConfigParser.ConfigParser()
		self._saved_freq_config.read(config_filename)
		try: saved_freq = self._saved_freq_config.getfloat('usrp', 'freq')
		except: saved_freq = 1698e6
		self.saved_freq = saved_freq
		self.hs = hs = int(sps/2.0)
		self.sync_alpha = sync_alpha = saved_sync_alpha
		self.side_text = side_text = side
		self.pll_alpha = pll_alpha = saved_pll_alpha
		self._output_filename_config = ConfigParser.ConfigParser()
		self._output_filename_config.read(config_filename)
		try: output_filename = self._output_filename_config.get('output', 'filename')
		except: output_filename = 'frames.dat'
		self.output_filename = output_filename
		self.mf_taps = mf_taps = [-0.5/hs,]*hs+[0.5/hs,]*hs
		self.max_sync_offset = max_sync_offset = 0.01
		self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/sample_rate
		self.gain = gain = saved_gain
		self.freq = freq = saved_freq
		self.decim_text = decim_text = decim

		##################################################
		# Controls
		##################################################
		_sync_alpha_sizer = wx.BoxSizer(wx.VERTICAL)
		self._sync_alpha_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_sync_alpha_sizer,
			value=self.sync_alpha,
			callback=self.set_sync_alpha,
			label="SYNC Alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._sync_alpha_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_sync_alpha_sizer,
			value=self.sync_alpha,
			callback=self.set_sync_alpha,
			minimum=0.0,
			maximum=0.5,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_sync_alpha_sizer, 0, 3, 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, 1, 0, 1, 1)
		_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.0,
			maximum=0.5,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_pll_alpha_sizer, 0, 2, 1, 1)
		_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="RX 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=100,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_gain_sizer, 0, 1, 1, 1)
		self._freq_text_box = forms.text_box(
			parent=self.GetWin(),
			value=self.freq,
			callback=self.set_freq,
			label="Frequency",
			converter=forms.float_converter(),
		)
		self.GridAdd(self._freq_text_box, 0, 0, 1, 1)
		self._decim_text_static_text = forms.static_text(
			parent=self.GetWin(),
			value=self.decim_text,
			callback=self.set_decim_text,
			label="Decimation",
			converter=forms.float_converter(),
		)
		self.GridAdd(self._decim_text_static_text, 1, 1, 1, 1)

		##################################################
		# Blocks
		##################################################
		self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)
		self.decoder = noaa.hrpt_decoder()
		self.deframer = noaa.hrpt_deframer()
		self.frame_sink = gr.file_sink(gr.sizeof_short*1, output_filename)
		self.gr_fir_filter_xxx_0 = gr.fir_filter_ccc(1, (mf_taps))
		self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset)
		self.pll_scope = scopesink2.scope_sink_f(
			self.GetWin(),
			title="Demod Waveform",
			sample_rate=sample_rate,
			v_scale=0.5,
			t_scale=20.0/sample_rate,
			ac_couple=False,
			xy_mode=False,
			num_inputs=1,
		)
		self.GridAdd(self.pll_scope.win, 2, 0, 1, 4)
		self.sync = noaa.hrpt_sync_fb(sync_alpha, sync_alpha**2/4.0, sps, max_sync_offset)
		self.usrp_source = grc_usrp.simple_source_c(which=0, side=side, rx_ant="RXA")
		self.usrp_source.set_decim_rate(decim)
		self.usrp_source.set_frequency(freq, verbose=True)
		self.usrp_source.set_gain(gain)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_fir_filter_xxx_0, 0), (self.pll, 0))
		self.connect((self.agc, 0), (self.gr_fir_filter_xxx_0, 0))
		self.connect((self.usrp_source, 0), (self.agc, 0))
		self.connect((self.deframer, 0), (self.decoder, 0))
		self.connect((self.pll, 0), (self.pll_scope, 0))
		self.connect((self.pll, 0), (self.sync, 0))
		self.connect((self.sync, 0), (self.deframer, 0))
		self.connect((self.deframer, 0), (self.frame_sink, 0))
    def __init__(self):
        gr.top_block.__init__(self, "USRP HRPT Receiver")

        ##################################################
        # Variables
        ##################################################
        self.sym_rate = sym_rate = 600 * 1109
        self.sample_rate = sample_rate = 4e6
        self.sps = sps = sample_rate / sym_rate
        self.config_filename = config_filename = os.environ[
            'HOME'] + '/.gnuradio/config.conf'
        self._pll_alpha_config = ConfigParser.ConfigParser()
        self._pll_alpha_config.read(config_filename)
        try:
            pll_alpha = self._pll_alpha_config.getfloat(
                'usrp_rx_hrpt', 'pll_alpha')
        except:
            pll_alpha = 0.01
        self.pll_alpha = pll_alpha
        self._output_filename_config = ConfigParser.ConfigParser()
        self._output_filename_config.read(config_filename)
        try:
            output_filename = self._output_filename_config.get(
                'usrp_rx_hrpt', 'filename')
        except:
            output_filename = 'frames.hrpt'
        self.output_filename = output_filename
        self.max_clock_offset = max_clock_offset = 100e-6
        self.max_carrier_offset = max_carrier_offset = 2 * math.pi * 100e3 / sample_rate
        self.hs = hs = int(sps / 2.0)
        self._gain_config = ConfigParser.ConfigParser()
        self._gain_config.read(config_filename)
        try:
            gain = self._gain_config.getfloat('usrp_rx_hrpt', 'gain')
        except:
            gain = 35
        self.gain = gain
        self._freq_config = ConfigParser.ConfigParser()
        self._freq_config.read(config_filename)
        try:
            freq = self._freq_config.getfloat('usrp_rx_hrpt', 'freq')
        except:
            freq = 1698e6
        self.freq = freq
        self._clock_alpha_config = ConfigParser.ConfigParser()
        self._clock_alpha_config.read(config_filename)
        try:
            clock_alpha = self._clock_alpha_config.getfloat(
                'usrp_rx_hrpt', 'clock_alpha')
        except:
            clock_alpha = 0.01
        self.clock_alpha = clock_alpha
        self._addr_config = ConfigParser.ConfigParser()
        self._addr_config.read(config_filename)
        try:
            addr = self._addr_config.get('usrp_rx_hrpt', 'addr')
        except:
            addr = ""
        self.addr = addr

        ##################################################
        # Blocks
        ##################################################
        self.uhd_usrp_source_0 = uhd.usrp_source(
            device_addr=addr,
            io_type=uhd.io_type.COMPLEX_FLOAT32,
            num_channels=1,
        )
        self.uhd_usrp_source_0.set_samp_rate(sample_rate)
        self.uhd_usrp_source_0.set_center_freq(freq, 0)
        self.uhd_usrp_source_0.set_gain(0, 0)
        self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2 / 4.0,
                                    max_carrier_offset)
        self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0 / hs, 4000)
        self.frame_sink = gr.file_sink(gr.sizeof_short * 1, output_filename)
        self.frame_sink.set_unbuffered(False)
        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.deframer = noaa.hrpt_deframer()
        self.decoder = noaa.hrpt_decoder(True, True)
        self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_moving_average_xx_0, 0),
                     (self.digital_clock_recovery_mm_xx_0, 0))
        self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
        self.connect((self.uhd_usrp_source_0, 0), (self.agc, 0))
        self.connect((self.agc, 0), (self.pll, 0))
        self.connect((self.digital_binary_slicer_fb_0, 0), (self.deframer, 0))
        self.connect((self.digital_clock_recovery_mm_xx_0, 0),
                     (self.digital_binary_slicer_fb_0, 0))
        self.connect((self.deframer, 0), (self.decoder, 0))
        self.connect((self.deframer, 0), (self.frame_sink, 0))
Пример #39
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 = gr.sig_source_c(sampling_freq, gr.GR_SIN_WAVE,
                               sampling_freq * 0.10, 100.0)
        dst1 = gr.vector_sink_c()
        head = gr.head(gr.sizeof_gr_complex, int(5 * sampling_freq * 0.10))

        agc = gr.agc_cc(1e-3, 1, 1, 1000)

        tb.connect(src1, head)
        tb.connect(head, agc)
        tb.connect(agc, dst1)

        if test_output == True:
            tb.connect(agc,
                       gr.file_sink(gr.sizeof_gr_complex, "test_agc_cc.dat"))

        tb.run()
        dst_data = dst1.data()
        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 4)
    def __init__(self,
                 decim=32,
                 freq=1698e6,
                 gain=35,
                 side="A",
                 frames_file=os.environ['HOME'] + '/NOAA-XX.hrpt',
                 baseband_file=os.environ['HOME'] + '/NOAA-XX.dat',
                 satellite='NOAA-XX',
                 sync_check=False):
        gr.top_block.__init__(self, "USRP NOAA HRPT Receiver")

        ##################################################
        # Parameters
        ##################################################
        self.decim = decim
        self.freq = freq
        self.gain = gain
        self.side = side
        self.frames_file = frames_file
        self.baseband_file = baseband_file
        self.satellite = satellite
        self.sync_check = sync_check

        ##################################################
        # Variables
        ##################################################
        self.sym_rate = sym_rate = 600 * 1109
        self.samp_rate = samp_rate = 64e6 / decim
        self.sps = sps = samp_rate / sym_rate
        self.config_filename = config_filename = os.environ[
            'HOME'] + '/.gnuradio/noaa_hrpt.conf'
        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(
                "satname", 'pll_alpha')
        except:
            saved_pll_alpha = 0.005
        self.saved_pll_alpha = saved_pll_alpha
        self._saved_gain_config = ConfigParser.ConfigParser()
        self._saved_gain_config.read(config_filename)
        try:
            saved_gain = self._saved_gain_config.getfloat("satname", 'gain')
        except:
            saved_gain = gain
        self.saved_gain = saved_gain
        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(
                "satname", 'clock_alpha')
        except:
            saved_clock_alpha = 0.001
        self.saved_clock_alpha = saved_clock_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)

        ##################################################
        # Blocks
        ##################################################
        self.agc = gr.agc_cc(1e-5, 1.0, 1.0 / 32768.0, 1.0)
        self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(
            sps / 2.0, saved_clock_alpha**2 / 4.0, 0.5, saved_clock_alpha,
            max_clock_offset)
        self.gr_file_sink_0 = gr.file_sink(gr.sizeof_short * 1, baseband_file)
        self.gr_file_sink_0.set_unbuffered(False)
        self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_short * 1, frames_file)
        self.gr_file_sink_0_0.set_unbuffered(False)
        self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex(
        )
        self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0 / hs, 4000)
        self.noaa_hrpt_decoder_0 = noaa.hrpt_decoder(True, False)
        self.pll = noaa.hrpt_pll_cf(saved_pll_alpha, saved_pll_alpha**2 / 4.0,
                                    max_carrier_offset)
        self.poesweather_noaa_hrpt_deframer_0 = poesweather.noaa_hrpt_deframer(
            sync_check)
        self.usrp_simple_source_x_0 = grc_usrp.simple_source_s(which=0,
                                                               side=side,
                                                               rx_ant="RXA")
        self.usrp_simple_source_x_0.set_decim_rate(decim)
        self.usrp_simple_source_x_0.set_frequency(freq, verbose=True)
        self.usrp_simple_source_x_0.set_gain(gain)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_binary_slicer_fb_0, 0))
        self.connect((self.agc, 0), (self.pll, 0))
        self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
        self.connect((self.gr_moving_average_xx_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.poesweather_noaa_hrpt_deframer_0, 0),
                     (self.gr_file_sink_0_0, 0))
        self.connect((self.poesweather_noaa_hrpt_deframer_0, 0),
                     (self.noaa_hrpt_decoder_0, 0))
        self.connect((self.gr_binary_slicer_fb_0, 0),
                     (self.poesweather_noaa_hrpt_deframer_0, 0))
        self.connect((self.usrp_simple_source_x_0, 0),
                     (self.gr_file_sink_0, 0))
        self.connect((self.gr_interleaved_short_to_complex_0, 0),
                     (self.agc, 0))
        self.connect((self.usrp_simple_source_x_0, 0),
                     (self.gr_interleaved_short_to_complex_0, 0))
Пример #41
0
    def __init__(
            self,
            satellite='NOAAxx',
            decim=50,
            baseband_file="/home/martin/GNURadioData/hrpt/baseband/HRPT_NOAA19_2010-09-10_12-35-34_UTC_U2_d50.sam",
            frames_file=os.environ['HOME'] + '/noaa_hrpt_frames.hmf',
            deframer_outsync_frames=5,
            deframer_insync_frames=2,
            clock_alpha=0.005,
            gain_mu=0.005,
            pll_alpha=0.005,
            pll_beta=0.00001,
            deframer_sync_check=True,
            symb_rate=600 * 1109):
        grc_wxgui.top_block_gui.__init__(
            self, title="NOAA HRPT Receiver from baseband file")
        _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.decim = decim
        self.baseband_file = baseband_file
        self.frames_file = frames_file
        self.deframer_outsync_frames = deframer_outsync_frames
        self.deframer_insync_frames = deframer_insync_frames
        self.clock_alpha = clock_alpha
        self.gain_mu = gain_mu
        self.pll_alpha = pll_alpha
        self.pll_beta = pll_beta
        self.deframer_sync_check = deframer_sync_check
        self.symb_rate = symb_rate

        ##################################################
        # Variables
        ##################################################
        self.decim_tb = decim_tb = decim
        self.symb_rate_tb = symb_rate_tb = symb_rate
        self.samp_rate = samp_rate = 100e6 / decim_tb
        self.sps = sps = samp_rate / symb_rate_tb
        self.satellite_text = satellite_text = satellite
        self.samp_rate_st = samp_rate_st = samp_rate
        self.pll_beta_sl = pll_beta_sl = pll_beta
        self.pll_alpha_sl = pll_alpha_sl = 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_mu_sl = gain_mu_sl = gain_mu
        self.frames_file_text_inf = frames_file_text_inf = frames_file
        self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
        self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
        self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
        self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S",
                                                      localtime())
        self.clock_alpha_sl = clock_alpha_sl = clock_alpha
        self.baseband_file_text_inf = baseband_file_text_inf = baseband_file

        ##################################################
        # Notebooks
        ##################################################
        self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Input baseband")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb),
                            "PLL demodulator and Clock sync")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
        self.Add(self.rx_ntb)

        ##################################################
        # Controls
        ##################################################
        self._decim_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.decim_tb,
            callback=self.set_decim_tb,
            label="Decimation",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
        self._symb_rate_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            value=self.symb_rate_tb,
            callback=self.set_symb_rate_tb,
            label="Symbol rate",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
        self._satellite_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.satellite_text,
            callback=self.set_satellite_text,
            label="Sat ",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0,
                                       1, 1)
        self._samp_rate_st_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.samp_rate_st,
            callback=self.set_samp_rate_st,
            label="Sample rate",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1,
                                       1)
        _pll_beta_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._pll_beta_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_beta_sl_sizer,
            value=self.pll_beta_sl,
            callback=self.set_pll_beta_sl,
            label="PLL Beta",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._pll_beta_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_beta_sl_sizer,
            value=self.pll_beta_sl,
            callback=self.set_pll_beta_sl,
            minimum=0.000001,
            maximum=0.001,
            num_steps=1000,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_pll_beta_sl_sizer, 2, 0, 1, 1)
        _pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._pll_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            label="PLL Alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._pll_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
        _gain_mu_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._gain_mu_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_gain_mu_sl_sizer,
            value=self.gain_mu_sl,
            callback=self.set_gain_mu_sl,
            label="Gain MU",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._gain_mu_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_gain_mu_sl_sizer,
            value=self.gain_mu_sl,
            callback=self.set_gain_mu_sl,
            minimum=0.0001,
            maximum=0.01,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_gain_mu_sl_sizer, 1, 2, 1, 1)
        self._frames_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.frames_file_text_inf,
            callback=self.set_frames_file_text_inf,
            label="Frames filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(self._frames_file_text_inf_static_text,
                                       3, 0, 1, 1)
        self._deframer_sync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.deframer_sync_after_text,
            callback=self.set_deframer_sync_after_text,
            label="Deframe sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
        self._deframer_nosync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.deframer_nosync_after_text,
            callback=self.set_deframer_nosync_after_text,
            label="Deframer out of sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
        self._deframer_check_sync_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.deframer_check_sync_text,
            callback=self.set_deframer_check_sync_text,
            label="Deframer check sync enable",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
        self._datetime_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.datetime_text,
            callback=self.set_datetime_text,
            label="Local time of aquisition start",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(self._datetime_text_static_text, 1, 0,
                                       1, 1)
        _clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._clock_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            label="Clock alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._clock_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
        self._baseband_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.baseband_file_text_inf,
            callback=self.set_baseband_file_text_inf,
            label="Baseband filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._baseband_file_text_inf_static_text, 4, 0, 1, 1)

        ##################################################
        # Blocks
        ##################################################
        self.cs2cf = gr.interleaved_short_to_complex()
        self.gr_agc_xx_0_0 = gr.agc_cc(10e-6, 1, 1.0 / 32767.0, 1.0)
        self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(
            sps / 2.0, clock_alpha**2 / 4.0, 0.5, gain_mu_sl, max_clock_offset)
        self.gr_complex_to_real_0 = gr.complex_to_real(1)
        self.gr_costas_loop_cc_0 = gr.costas_loop_cc(pll_alpha_sl, pll_beta_sl,
                                                     0.07, -0.07, 2)
        self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_short * 1, frames_file)
        self.gr_file_sink_0_0.set_unbuffered(False)
        self.gr_file_source_0 = gr.file_source(gr.sizeof_short * 1,
                                               baseband_file, False)
        self.gr_moving_average_xx_0 = gr.moving_average_cc(hs, 1.0 / hs, 4000)
        self.gr_throttle_0 = gr.throttle(gr.sizeof_short * 1, samp_rate * 2)
        self.noaa_hrpt_decoder_0 = noaa.hrpt_decoder(True, False)
        self.poesweather_univ_hrpt_deframer_0 = poesweather.univ_hrpt_deframer(
            deframer_sync_check, 11090, deframer_insync_frames,
            deframer_outsync_frames)
        self.wxgui_fftsink1 = fftsink2.fft_sink_c(
            self.rx_ntb.GetPage(0).GetWin(),
            baseband_freq=0,
            y_per_div=5,
            y_divs=10,
            ref_level=50,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="Not filtered spectrum",
            peak_hold=False,
        )
        self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
        self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
            self.rx_ntb.GetPage(1).GetWin(),
            title="PSK constellation diagram",
            sample_rate=symb_rate,
            v_scale=0.4,
            v_offset=0,
            t_scale=1 / samp_rate,
            ac_couple=False,
            xy_mode=True,
            num_inputs=1,
            trig_mode=gr.gr_TRIG_MODE_AUTO,
        )
        self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.cs2cf, 0))
        self.connect((self.cs2cf, 0), (self.gr_agc_xx_0_0, 0))
        self.connect((self.cs2cf, 0), (self.wxgui_fftsink1, 0))
        self.connect((self.gr_complex_to_real_0, 0),
                     (self.gr_binary_slicer_fb_0, 0))
        self.connect((self.poesweather_univ_hrpt_deframer_0, 0),
                     (self.gr_file_sink_0_0, 0))
        self.connect((self.gr_binary_slicer_fb_0, 0),
                     (self.poesweather_univ_hrpt_deframer_0, 0))
        self.connect((self.poesweather_univ_hrpt_deframer_0, 0),
                     (self.noaa_hrpt_decoder_0, 0))
        self.connect((self.gr_moving_average_xx_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.gr_agc_xx_0_0, 0), (self.gr_costas_loop_cc_0, 0))
        self.connect((self.gr_costas_loop_cc_0, 0),
                     (self.gr_moving_average_xx_0, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_complex_to_real_0, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.wxgui_scopesink2_1, 0))
Пример #42
0
	def __init__(self, decim=50, satellite='Meteor-M-N1', frames_file=os.environ['HOME'] + '/MN1_hrpt_frames.hmf', baseband_file="/home/martin/GNURadioData/hrpt/baseband/HRPT_Meteor-M-N1_2011-02-27_09-30-46_UTC_U2_d50.sam", symb_rate=600*1109, clock_alpha=0.050, pll_alpha=0.05, deframer_outsync_frames=100, deframer_insync_frames=3, deframer_sync_check=False):
		grc_wxgui.top_block_gui.__init__(self, title="Meteor M-N1 HRPT Receiver from baseband file")
		_icon_path = "/home/martin/.local/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Parameters
		##################################################
		self.decim = decim
		self.satellite = satellite
		self.frames_file = frames_file
		self.baseband_file = baseband_file
		self.symb_rate = symb_rate
		self.clock_alpha = clock_alpha
		self.pll_alpha = pll_alpha
		self.deframer_outsync_frames = deframer_outsync_frames
		self.deframer_insync_frames = deframer_insync_frames
		self.deframer_sync_check = deframer_sync_check

		##################################################
		# Variables
		##################################################
		self.decim_tb = decim_tb = decim
		self.symb_rate_tb = symb_rate_tb = symb_rate
		self.samp_rate = samp_rate = 100e6/decim_tb
		self.sps = sps = samp_rate/symb_rate_tb
		self.v = v = True
		self.satellite_text = satellite_text = satellite
		self.samp_rate_st = samp_rate_st = samp_rate
		self.pll_alpha_sl = pll_alpha_sl = 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.frames_file_text_inf = frames_file_text_inf = frames_file
		self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
		self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
		self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
		self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime())
		self.clock_alpha_sl = clock_alpha_sl = clock_alpha
		self.baseband_file_text_inf = baseband_file_text_inf = baseband_file

		##################################################
		# Blocks
		##################################################
		self.rx_ntb = self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Input baseband")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "PLL demodulator and Clock sync")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
		self.Add(self.rx_ntb)
		self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
			self.GetWin(),
			title="Scope Plot",
			sample_rate=samp_rate,
			v_scale=0,
			v_offset=0,
			t_scale=0,
			ac_couple=False,
			xy_mode=False,
			num_inputs=1,
			trig_mode=gr.gr_TRIG_MODE_AUTO,
			y_axis_label="Counts",
		)
		self.Add(self.wxgui_scopesink2_0.win)
		self.wxgui_fftsink1 = fftsink2.fft_sink_c(
			self.rx_ntb.GetPage(0).GetWin(),
			baseband_freq=0,
			y_per_div=5,
			y_divs=10,
			ref_level=50,
			ref_scale=2.0,
			sample_rate=samp_rate,
			fft_size=1024,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="Not filtered spectrum",
			peak_hold=False,
		)
		self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
		self._v_check_box = forms.check_box(
			parent=self.GetWin(),
			value=self.v,
			callback=self.set_v,
			label="Open",
			true=True,
			false=False,
		)
		self.Add(self._v_check_box)
		self._symb_rate_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			value=self.symb_rate_tb,
			callback=self.set_symb_rate_tb,
			label="Symbol rate",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
		self._satellite_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.satellite_text,
			callback=self.set_satellite_text,
			label="Sat ",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0, 1, 1)
		self._samp_rate_st_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.samp_rate_st,
			callback=self.set_samp_rate_st,
			label="Sample rate",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1, 1)
		self.poesweather_meteor_cadu_deframer_0 = poesweather.meteor_cadu_deframer(deframer_sync_check, 256, deframer_insync_frames, deframer_outsync_frames)
		_pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._pll_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			label="PLL Alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._pll_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
		self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset)
		self.gr_throttle_0 = gr.throttle(gr.sizeof_short*1, samp_rate*10)
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((-1, ))
		self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0/hs, 4000)
		self.gr_file_source_0_0 = gr.file_source(gr.sizeof_short*1, "/home/martin/hrpt/baseband/METEOR-M-1/2011/07/24/METEOR-M-1_2011-07-24T113448_U2d50.sam", False)
		self.gr_file_sink_0_0_0 = gr.file_sink(gr.sizeof_char*1, "frames.mn1")
		self.gr_file_sink_0_0_0.set_unbuffered(False)
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(sps/2.0, clock_alpha**2/4.0, 0.5, clock_alpha, max_clock_offset)
		self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
		self.gr_agc_xx_0_0 = gr.agc_cc(10e-6, 1, 1.0/32767.0, 1.0)
		self._frames_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.frames_file_text_inf,
			callback=self.set_frames_file_text_inf,
			label="Frames filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._frames_file_text_inf_static_text, 3, 0, 1, 1)
		self._deframer_sync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.deframer_sync_after_text,
			callback=self.set_deframer_sync_after_text,
			label="Deframe sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
		self._deframer_nosync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.deframer_nosync_after_text,
			callback=self.set_deframer_nosync_after_text,
			label="Deframer out of sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
		self._deframer_check_sync_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.deframer_check_sync_text,
			callback=self.set_deframer_check_sync_text,
			label="Deframer check sync enable",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
		self._decim_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.decim_tb,
			callback=self.set_decim_tb,
			label="Decimation",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
		self._datetime_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.datetime_text,
			callback=self.set_datetime_text,
			label="Local time of aquisition start",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._datetime_text_static_text, 1, 0, 1, 1)
		self.cs2cf = gr.interleaved_short_to_complex()
		_clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._clock_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			label="Clock alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._clock_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
		self._baseband_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.baseband_file_text_inf,
			callback=self.set_baseband_file_text_inf,
			label="Baseband filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._baseband_file_text_inf_static_text, 4, 0, 1, 1)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_throttle_0, 0), (self.cs2cf, 0))
		self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.cs2cf, 0), (self.gr_agc_xx_0_0, 0))
		self.connect((self.gr_agc_xx_0_0, 0), (self.pll, 0))
		self.connect((self.cs2cf, 0), (self.wxgui_fftsink1, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_binary_slicer_fb_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.poesweather_meteor_cadu_deframer_0, 0), (self.gr_file_sink_0_0_0, 0))
		self.connect((self.gr_binary_slicer_fb_0, 0), (self.poesweather_meteor_cadu_deframer_0, 0))
		self.connect((self.gr_file_source_0_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.wxgui_scopesink2_0, 0))
    def test_001(self):
        ''' Test the complex AGC loop (single rate input) '''
        fg = self.fg

        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 = gr.sig_source_c (sampling_freq, gr.GR_SIN_WAVE,
                                sampling_freq * 0.10, 100.0)
        dst1 = gr.vector_sink_c ()
        head = gr.head (gr.sizeof_gr_complex, int (5*sampling_freq * 0.10))

        agc = gr.agc_cc(1e-3, 1, 1, 1000)
        
        fg.connect (src1, head)
        fg.connect (head, agc)
        fg.connect (agc, dst1)

        if test_output == True:
            fg.connect (agc, gr.file_sink(gr.sizeof_gr_complex, "test_agc_cc.dat"))

        fg.run ()
        dst_data = dst1.data ()
        self.assertComplexTuplesAlmostEqual (expected_result, dst_data, 4)
Пример #44
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 = gr.file_source(gr.sizeof_short,filename,options.repeat)
          self.istoc = gr.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=gr.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=gr.file_sink(gr.sizeof_char, options.out_filename)
          self.dst =file_sink 

        self.agc=gr.agc_cc(1e-7,1.0,1.0) #1e-7
        self.am_demod = gr.complex_to_mag ()
        self.set_blacklevel=gr.add_const_ff(0.0)
        self.invert_and_scale = gr.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=gr.complex_to_real()
          nullsink=gr.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=gr.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 = gr.sig_source_f (usrp_rate, gr.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")
Пример #45
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="",
            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'))

        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 = blks2.pfb_arb_resampler_ccf(rrate)

        chan_filt_coeffs = gr.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 = gr.freq_xlating_fir_filter_ccf(
                chanfilt_decim, chan_filt_coeffs, self.IF_freq, usrp_rate)
        else:
            self.chan_filt = gr.fir_filter_ccf(chanfilt_decim,
                                               chan_filt_coeffs)

        self.agc = gr.agc_cc(0.1, 1, 1, 100000)
        self.am_demod = gr.complex_to_mag()
        self.volume_control = gr.multiply_const_ff(self.vol)

        audio_filt_coeffs = gr.firdes.low_pass_2(
            1,  # gain
            demod_rate,  # sampling rate
            8e3,  # passband cutoff
            2e3,  # transition bw
            60)  # stopband attenuation
        self.audio_filt = gr.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 True:
                # if no gain was specified, use the mid gain
                options.gain = (g.start() + g.stop()) / 2.0
                options.gain = g.stop()

        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")

        # 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)
Пример #46
0
	def __init__(self, side="A", gain=35, decim=32, sync_check=False, satellite='METEOR-M-1', frames_file=os.environ['HOME'] + '/METEOR-M-1.hrpt', freq=1700e6):
		grc_wxgui.top_block_gui.__init__(self, title="USRP 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.side = side
		self.gain = gain
		self.decim = decim
		self.sync_check = sync_check
		self.satellite = satellite
		self.frames_file = frames_file
		self.freq = freq

		##################################################
		# Variables
		##################################################
		self.sym_rate = sym_rate = 600*1109
		self.samp_rate = samp_rate = 64e6/decim
		self.config_filename = config_filename = os.environ['HOME']+'/.gnuradio/mn1_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("satname", '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("satname", '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("satname", '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.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.decim_tb = decim_tb = decim
		self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime())
		self.clock_alpha = clock_alpha = saved_clock_alpha

		##################################################
		# Notebooks
		##################################################
		self.displays = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.displays.AddPage(grc_wxgui.Panel(self.displays), "RX Meteor M N1 HRPT")
		self.displays.AddPage(grc_wxgui.Panel(self.displays), "Information")
		self.Add(self.displays)

		##################################################
		# Controls
		##################################################
		self._sync_check_txt_static_text = forms.static_text(
			parent=self.GetWin(),
			value=self.sync_check_txt,
			callback=self.set_sync_check_txt,
			label="Sync check",
			converter=forms.float_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)
		_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)
		_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._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._decim_tb_text_box = forms.text_box(
			parent=self.GetWin(),
			value=self.decim_tb,
			callback=self.set_decim_tb,
			label="Decimation",
			converter=forms.int_converter(),
		)
		self.GridAdd(self._decim_tb_text_box, 1, 0, 1, 1)
		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)
		_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)

		##################################################
		# Blocks
		##################################################
		self.agc = gr.agc_cc(1e-5, 1.0, 1.0/32768.0, 1.0)
		self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(sps/2.0, clock_alpha**2/4.0, 0.5, clock_alpha, max_clock_offset)
		self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_short*1, frames_file)
		self.gr_file_sink_0_0.set_unbuffered(False)
		self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex()
		self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0/hs, 4000)
		self.gr_rms_xx_0 = gr.rms_cf(0.2)
		self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset)
		self.poesweather_mn1_hrpt_deframer_0 = poesweather.mn1_hrpt_deframer(sync_check)
		self.usrp_simple_source_x_0 = grc_usrp.simple_source_s(which=0, side=side, rx_ant="RXA")
		self.usrp_simple_source_x_0.set_decim_rate(decim)
		self.usrp_simple_source_x_0.set_frequency(freq, verbose=True)
		self.usrp_simple_source_x_0.set_gain(gain)
		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=45,
			ref_scale=2.0,
			sample_rate=samp_rate,
			fft_size=1024,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="Meteor M N1 HRPT FFT Spectrum",
			peak_hold=False,
		)
		self.displays.GetPage(0).Add(self.wxgui_fftsink2_0.win)
		self.wxgui_numbersink2_0 = numbersink2.number_sink_f(
			self.GetWin(),
			unit="Units",
			minval=0,
			maxval=5000,
			factor=1.0,
			decimal_places=4,
			ref_level=0,
			sample_rate=samp_rate,
			number_rate=15,
			average=True,
			avg_alpha=0.07,
			label="S-Meter",
			peak_hold=False,
			show_gauge=True,
		)
		self.Add(self.wxgui_numbersink2_0.win)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_binary_slicer_fb_0, 0), (self.poesweather_mn1_hrpt_deframer_0, 0))
		self.connect((self.usrp_simple_source_x_0, 0), (self.gr_interleaved_short_to_complex_0, 0))
		self.connect((self.gr_interleaved_short_to_complex_0, 0), (self.agc, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_binary_slicer_fb_0, 0))
		self.connect((self.agc, 0), (self.pll, 0))
		self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.gr_interleaved_short_to_complex_0, 0), (self.wxgui_fftsink2_0, 0))
		self.connect((self.gr_interleaved_short_to_complex_0, 0), (self.gr_rms_xx_0, 0))
		self.connect((self.gr_rms_xx_0, 0), (self.wxgui_numbersink2_0, 0))
		self.connect((self.poesweather_mn1_hrpt_deframer_0, 0), (self.gr_file_sink_0_0, 0))
    def __init__(self,
                 pll_alpha=0.005,
                 satellite='NOAA18',
                 decim=50,
                 gain=25,
                 clock_alpha=0.005,
                 freq=1707e6,
                 deframer_sync_check=True,
                 deframer_insync_frames=2,
                 deframer_outsync_frames=5,
                 symb_rate=600 * 1109,
                 baseband_file=os.environ['HOME'] + '/noaa_hrpt_baseband.dat',
                 frames_file=os.environ['HOME'] + '/noaa_hrpt_frames.hmf'):
        grc_wxgui.top_block_gui.__init__(self,
                                         title="USRP2 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.pll_alpha = pll_alpha
        self.satellite = satellite
        self.decim = decim
        self.gain = gain
        self.clock_alpha = clock_alpha
        self.freq = freq
        self.deframer_sync_check = deframer_sync_check
        self.deframer_insync_frames = deframer_insync_frames
        self.deframer_outsync_frames = deframer_outsync_frames
        self.symb_rate = symb_rate
        self.baseband_file = baseband_file
        self.frames_file = frames_file

        ##################################################
        # Variables
        ##################################################
        self.decim_tb = decim_tb = decim
        self.symb_rate_tb = symb_rate_tb = symb_rate
        self.samp_rate = samp_rate = 100e6 / decim_tb
        self.sps = sps = samp_rate / symb_rate_tb
        self.satellite_text = satellite_text = satellite
        self.samp_rate_st = samp_rate_st = samp_rate
        self.pll_alpha_sl = pll_alpha_sl = 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_tb = gain_tb = gain
        self.freq_tb = freq_tb = freq
        self.frames_file_text_inf = frames_file_text_inf = frames_file
        self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
        self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
        self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
        self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S",
                                                      localtime())
        self.clock_alpha_sl = clock_alpha_sl = clock_alpha
        self.baseband_file_text_inf = baseband_file_text_inf = baseband_file

        ##################################################
        # Notebooks
        ##################################################
        self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "USRP Receiver")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb),
                            "PLL demodulator and Clock sync")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
        self.Add(self.rx_ntb)

        ##################################################
        # Controls
        ##################################################
        self._decim_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.decim_tb,
            callback=self.set_decim_tb,
            label="Decimation",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
        self._symb_rate_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            value=self.symb_rate_tb,
            callback=self.set_symb_rate_tb,
            label="Symbol rate",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
        self._satellite_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.satellite_text,
            callback=self.set_satellite_text,
            label="Sat ",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0,
                                       1, 1)
        self._samp_rate_st_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.samp_rate_st,
            callback=self.set_samp_rate_st,
            label="Sample rate",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1,
                                       1)
        _pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._pll_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            label="PLL Alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._pll_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
        self._gain_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.gain_tb,
            callback=self.set_gain_tb,
            label="RX gain [dB]",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._gain_tb_text_box, 1, 2, 1, 1)
        self._freq_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.freq_tb,
            callback=self.set_freq_tb,
            label="Frequency",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._freq_tb_text_box, 1, 1, 1, 1)
        self._frames_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.frames_file_text_inf,
            callback=self.set_frames_file_text_inf,
            label="Frames filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(self._frames_file_text_inf_static_text,
                                       3, 0, 1, 1)
        self._deframer_sync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.deframer_sync_after_text,
            callback=self.set_deframer_sync_after_text,
            label="Deframe sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
        self._deframer_nosync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.deframer_nosync_after_text,
            callback=self.set_deframer_nosync_after_text,
            label="Deframer out of sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
        self._deframer_check_sync_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.deframer_check_sync_text,
            callback=self.set_deframer_check_sync_text,
            label="Deframer check sync enable",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
        self._datetime_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.datetime_text,
            callback=self.set_datetime_text,
            label="Local time of aquisition start",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(self._datetime_text_static_text, 1, 0,
                                       1, 1)
        _clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._clock_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            label="Clock alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._clock_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
        self._baseband_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.baseband_file_text_inf,
            callback=self.set_baseband_file_text_inf,
            label="Baseband filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._baseband_file_text_inf_static_text, 4, 0, 1, 1)

        ##################################################
        # Blocks
        ##################################################
        self.gr_agc_xx_0 = gr.agc_cc(10e-6, 1, 1.0 / 32767.0, 1.0)
        self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(
            sps / 2.0, clock_alpha**2 / 4.0, 0.5, clock_alpha,
            max_clock_offset)
        self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_short * 1, frames_file)
        self.gr_file_sink_0_0.set_unbuffered(False)
        self.gr_file_sink_0_1 = gr.file_sink(gr.sizeof_short * 2,
                                             baseband_file)
        self.gr_file_sink_0_1.set_unbuffered(False)
        self.gr_float_to_complex_0 = gr.float_to_complex(1)
        self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0 / hs, 4000)
        self.gr_short_to_float_0 = gr.short_to_float()
        self.gr_short_to_float_0_0 = gr.short_to_float()
        self.gr_vector_to_streams_0 = gr.vector_to_streams(
            gr.sizeof_short * 1, 2)
        self.noaa_hrpt_decoder_0 = noaa.hrpt_decoder(True, False)
        self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2 / 4.0,
                                    max_carrier_offset)
        self.poesweather_univ_hrpt_deframer_0 = poesweather.univ_hrpt_deframer(
            deframer_sync_check, 11090, deframer_insync_frames,
            deframer_outsync_frames)
        self.usrp2_source_xxxx2_0 = usrp2.source_16sc()
        self.usrp2_source_xxxx2_0.set_decim(decim_tb)
        self.usrp2_source_xxxx2_0.set_center_freq(freq_tb)
        self.usrp2_source_xxxx2_0.set_gain(gain_tb)
        self.wxgui_fftsink1 = fftsink2.fft_sink_c(
            self.rx_ntb.GetPage(0).GetWin(),
            baseband_freq=freq,
            y_per_div=5,
            y_divs=10,
            ref_level=65,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="Not filtered spectrum",
            peak_hold=False,
        )
        self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_float_to_complex_0, 0), (self.wxgui_fftsink1, 0))
        self.connect((self.poesweather_univ_hrpt_deframer_0, 0),
                     (self.noaa_hrpt_decoder_0, 0))
        self.connect((self.gr_binary_slicer_fb_0, 0),
                     (self.poesweather_univ_hrpt_deframer_0, 0))
        self.connect((self.poesweather_univ_hrpt_deframer_0, 0),
                     (self.gr_file_sink_0_0, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_binary_slicer_fb_0, 0))
        self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
        self.connect((self.gr_moving_average_xx_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.gr_agc_xx_0, 0), (self.pll, 0))
        self.connect((self.gr_float_to_complex_0, 0), (self.gr_agc_xx_0, 0))
        self.connect((self.gr_vector_to_streams_0, 0),
                     (self.gr_short_to_float_0, 0))
        self.connect((self.gr_vector_to_streams_0, 1),
                     (self.gr_short_to_float_0_0, 0))
        self.connect((self.usrp2_source_xxxx2_0, 0),
                     (self.gr_vector_to_streams_0, 0))
        self.connect((self.usrp2_source_xxxx2_0, 0),
                     (self.gr_file_sink_0_1, 0))
        self.connect((self.gr_short_to_float_0_0, 0),
                     (self.gr_float_to_complex_0, 1))
        self.connect((self.gr_short_to_float_0, 0),
                     (self.gr_float_to_complex_0, 0))
Пример #48
0
	def __init__(self, deframer_insync_frames=2, deframer_outsync_frames=5, deframer_sync_check=True, pll_alpha=0.005, baseband_file='/home/martin/GNURadioData/USRPSamples/AHRPT_MetOp-A_20100306_0758UTC_U2_d25.sam', satellite='MetOp', viterbi_sync_threshold=0.1, viterbi_outsync_frames=20, viterbi_insync_frames=5, frames_file=os.environ['HOME'] + '/MetOp-cadu_frames.cadu', clock_alpha=0.05, symb_rate=(3500e3/3+3500e3)/2, symb_rate_0=3*3500/4, viterbi_sync_check=True, decim=24):
		grc_wxgui.top_block_gui.__init__(self, title="MetOp AHRPT Receiver from baseband file")
		_icon_path = "/home/martin/.local/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Parameters
		##################################################
		self.deframer_insync_frames = deframer_insync_frames
		self.deframer_outsync_frames = deframer_outsync_frames
		self.deframer_sync_check = deframer_sync_check
		self.pll_alpha = pll_alpha
		self.baseband_file = baseband_file
		self.satellite = satellite
		self.viterbi_sync_threshold = viterbi_sync_threshold
		self.viterbi_outsync_frames = viterbi_outsync_frames
		self.viterbi_insync_frames = viterbi_insync_frames
		self.frames_file = frames_file
		self.clock_alpha = clock_alpha
		self.symb_rate = symb_rate
		self.symb_rate_0 = symb_rate_0
		self.viterbi_sync_check = viterbi_sync_check
		self.decim = decim

		##################################################
		# Variables
		##################################################
		self.decim_tb = decim_tb = decim
		self.symb_rate_tb = symb_rate_tb = symb_rate
		self.samp_rate = samp_rate = 100e6/decim_tb
		self.viterbi_sync_threshold_text = viterbi_sync_threshold_text = viterbi_sync_threshold
		self.viterbi_sync_after_text = viterbi_sync_after_text = viterbi_insync_frames
		self.viterbi_outofsync_after_text = viterbi_outofsync_after_text = viterbi_outsync_frames
		self.viterbi_node_sync_text = viterbi_node_sync_text = viterbi_sync_check
		self.sps = sps = samp_rate/symb_rate_tb
		self.satellite_text = satellite_text = satellite
		self.samp_rate_st = samp_rate_st = samp_rate
		self.pll_alpha_sl = pll_alpha_sl = pll_alpha
		self.frames_file_text_inf = frames_file_text_inf = frames_file
		self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
		self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
		self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
		self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime())
		self.clock_alpha_sl = clock_alpha_sl = clock_alpha
		self.baseband_file_text_inf = baseband_file_text_inf = baseband_file

		##################################################
		# Blocks
		##################################################
		self.rx_ntb = self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Input")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "PLL demodulator and Clock sync")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Viterbi decoder")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
		self.Add(self.rx_ntb)
		_pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._pll_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			label="PLL Alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._pll_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
		_clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._clock_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			label="Clock alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._clock_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
		self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
			self.rx_ntb.GetPage(0).GetWin(),
			title="QPSK constellation diagram",
			sample_rate=symb_rate,
			v_scale=0.4,
			v_offset=0,
			t_scale=1/samp_rate,
			ac_couple=False,
			xy_mode=True,
			num_inputs=1,
			trig_mode=gr.gr_TRIG_MODE_AUTO,
			y_axis_label="Counts",
		)
		self.rx_ntb.GetPage(0).Add(self.wxgui_scopesink2_1.win)
		self.wxgui_fftsink1 = fftsink2.fft_sink_c(
			self.rx_ntb.GetPage(0).GetWin(),
			baseband_freq=0,
			y_per_div=5,
			y_divs=10,
			ref_level=-15,
			ref_scale=2.0,
			sample_rate=samp_rate,
			fft_size=1024,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="Not filtered spectrum",
			peak_hold=False,
		)
		self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
		self._viterbi_sync_threshold_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_sync_threshold_text,
			callback=self.set_viterbi_sync_threshold_text,
			label="Viterbi node sync threshold [BER]",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_sync_threshold_text_static_text, 3, 0, 1, 1)
		self._viterbi_sync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_sync_after_text,
			callback=self.set_viterbi_sync_after_text,
			label="Valid frames for Viterbi decoder sync",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_sync_after_text_static_text, 4, 0, 1, 1)
		self._viterbi_outofsync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_outofsync_after_text,
			callback=self.set_viterbi_outofsync_after_text,
			label="Invalid frames for Viterbi decoder out of sync",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_outofsync_after_text_static_text, 5, 0, 1, 1)
		self._viterbi_node_sync_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.viterbi_node_sync_text,
			callback=self.set_viterbi_node_sync_text,
			label="Viterbi node sync enable",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._viterbi_node_sync_text_static_text, 2, 0, 1, 1)
		self._symb_rate_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			value=self.symb_rate_tb,
			callback=self.set_symb_rate_tb,
			label="Symbol rate",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
		self._satellite_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.satellite_text,
			callback=self.set_satellite_text,
			label="Sat ",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0, 1, 1)
		self._samp_rate_st_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.samp_rate_st,
			callback=self.set_samp_rate_st,
			label="Sample rate",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1, 1)
		self.poesweather_metop_cadu_deframer_0 = poesweather.metop_cadu_deframer(False, 1024, 5, 25)
		self.gr_throttle_0 = gr.throttle(gr.sizeof_short*1, samp_rate*10)
		self.gr_packed_to_unpacked_xx_0 = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((0.6, ))
		self.gr_file_source_0_0_0_0 = gr.file_source(gr.sizeof_short*1, "/home/martin/hrpt/baseband/METOP-A/2011/07/24/METOP-A_2011-07-24_122614-U2d24.sam", False)
		self.gr_file_sink_0 = gr.file_sink(gr.sizeof_char*1, "/home/martin/MetOp-cadu_frames.cadu")
		self.gr_file_sink_0.set_unbuffered(False)
		self.gr_costas_loop_cc_0 = gr.costas_loop_cc(pll_alpha_sl, pll_alpha_sl*pll_alpha_sl/4.0, 0.07, -0.07, 4)
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(sps, clock_alpha_sl*clock_alpha_sl/4.0, 0.5, clock_alpha_sl, 0.05)
		self.gr_agc_xx_0 = gr.agc_cc(10e-6, 1, 1.0/32767.0, 1.0)
		self._frames_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(4).GetWin(),
			value=self.frames_file_text_inf,
			callback=self.set_frames_file_text_inf,
			label="Frames filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(4).GridAdd(self._frames_file_text_inf_static_text, 3, 0, 1, 1)
		self.fec_decode_viterbi_ahrpt_metop_cb_0 = fec.decode_viterbi_ahrpt_metop_cb(True, 0.2, 5, 50, 50)
		self._deframer_sync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_sync_after_text,
			callback=self.set_deframer_sync_after_text,
			label="Deframe sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
		self._deframer_nosync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_nosync_after_text,
			callback=self.set_deframer_nosync_after_text,
			label="Deframer out of sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
		self._deframer_check_sync_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.deframer_check_sync_text,
			callback=self.set_deframer_check_sync_text,
			label="Deframer check sync enable",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
		self._decim_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.decim_tb,
			callback=self.set_decim_tb,
			label="Decimation",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
		self._datetime_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(4).GetWin(),
			value=self.datetime_text,
			callback=self.set_datetime_text,
			label="Local time of aquisition start",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(4).GridAdd(self._datetime_text_static_text, 1, 0, 1, 1)
		self.cs2cf = gr.interleaved_short_to_complex()
		self._baseband_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.baseband_file_text_inf,
			callback=self.set_baseband_file_text_inf,
			label="Baseband filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(0).Add(self._baseband_file_text_inf_static_text)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_throttle_0, 0), (self.cs2cf, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.wxgui_fftsink1, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.wxgui_scopesink2_1, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.gr_costas_loop_cc_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.gr_costas_loop_cc_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.cs2cf, 0), (self.gr_agc_xx_0, 0))
		self.connect((self.gr_file_source_0_0_0_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.fec_decode_viterbi_ahrpt_metop_cb_0, 0))
		self.connect((self.fec_decode_viterbi_ahrpt_metop_cb_0, 0), (self.gr_packed_to_unpacked_xx_0, 0))
		self.connect((self.poesweather_metop_cadu_deframer_0, 0), (self.gr_file_sink_0, 0))
		self.connect((self.gr_packed_to_unpacked_xx_0, 0), (self.poesweather_metop_cadu_deframer_0, 0))
Пример #49
0
	def __init__(self, baseband_file=os.environ['HOME'] + '/NOAA-XX.dat', satellite='NOAA-XX', decim=32, frames_file=os.environ['HOME'] + '/NOAA-XX.hrpt', sync_check=False):
		gr.top_block.__init__(self, "NOAA HRPT Baseband To Frames")

		##################################################
		# Parameters
		##################################################
		self.baseband_file = baseband_file
		self.satellite = satellite
		self.decim = decim
		self.frames_file = frames_file
		self.sync_check = sync_check

		##################################################
		# Variables
		##################################################
		self.sym_rate = sym_rate = 600*1109
		self.sample_rate = sample_rate = 64e6/decim
		self.sps = sps = sample_rate/sym_rate
		self.config_filename = config_filename = os.environ['HOME']+'/.gnuradio/noaa_hrpt.conf'
		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("satname", 'pll_alpha')
		except: saved_pll_alpha = 0.01
		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("satname", 'clock_alpha')
		except: saved_clock_alpha = 0.01
		self.saved_clock_alpha = saved_clock_alpha
		self.max_clock_offset = max_clock_offset = 100e-6
		self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/sample_rate
		self.hs = hs = int(sps/2.0)

		##################################################
		# Blocks
		##################################################
		self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)
		self.decoder = noaa.hrpt_decoder(True,False)
		self.frame_sink = gr.file_sink(gr.sizeof_short*1, frames_file)
		self.frame_sink.set_unbuffered(False)
		self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(sps/2.0, saved_clock_alpha**2/4.0, 0.5, saved_clock_alpha, max_clock_offset)
		self.gr_file_source_0 = gr.file_source(gr.sizeof_short*1, baseband_file, False)
		self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex()
		self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0/hs, 4000)
		self.pll = noaa.hrpt_pll_cf(saved_pll_alpha, saved_pll_alpha**2/4.0, max_carrier_offset)
		self.poesweather_noaa_hrpt_deframer_0 = poesweather.noaa_hrpt_deframer(sync_check)
		self.throttle = gr.throttle(gr.sizeof_short*1, sample_rate*10)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_binary_slicer_fb_0, 0))
		self.connect((self.gr_binary_slicer_fb_0, 0), (self.poesweather_noaa_hrpt_deframer_0, 0))
		self.connect((self.poesweather_noaa_hrpt_deframer_0, 0), (self.decoder, 0))
		self.connect((self.poesweather_noaa_hrpt_deframer_0, 0), (self.frame_sink, 0))
		self.connect((self.gr_file_source_0, 0), (self.throttle, 0))
		self.connect((self.throttle, 0), (self.gr_interleaved_short_to_complex_0, 0))
		self.connect((self.gr_interleaved_short_to_complex_0, 0), (self.agc, 0))
		self.connect((self.agc, 0), (self.pll, 0))
		self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
	def __init__(self, pll_alpha=0.005, satellite='NOAA18', decim=50, gain=25, clock_alpha=0.005, freq=1707e6, deframer_sync_check=True, deframer_insync_frames=2, deframer_outsync_frames=5, symb_rate=600*1109, baseband_file=os.environ['HOME'] + '/noaa_hrpt_baseband.dat', frames_file=os.environ['HOME'] + '/noaa_hrpt_frames.hmf'):
		grc_wxgui.top_block_gui.__init__(self, title="USRP2 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.pll_alpha = pll_alpha
		self.satellite = satellite
		self.decim = decim
		self.gain = gain
		self.clock_alpha = clock_alpha
		self.freq = freq
		self.deframer_sync_check = deframer_sync_check
		self.deframer_insync_frames = deframer_insync_frames
		self.deframer_outsync_frames = deframer_outsync_frames
		self.symb_rate = symb_rate
		self.baseband_file = baseband_file
		self.frames_file = frames_file

		##################################################
		# Variables
		##################################################
		self.decim_tb = decim_tb = decim
		self.symb_rate_tb = symb_rate_tb = symb_rate
		self.samp_rate = samp_rate = 100e6/decim_tb
		self.sps = sps = samp_rate/symb_rate_tb
		self.satellite_text = satellite_text = satellite
		self.samp_rate_st = samp_rate_st = samp_rate
		self.pll_alpha_sl = pll_alpha_sl = 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_tb = gain_tb = gain
		self.freq_tb = freq_tb = freq
		self.frames_file_text_inf = frames_file_text_inf = frames_file
		self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
		self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
		self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
		self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S", localtime())
		self.clock_alpha_sl = clock_alpha_sl = clock_alpha
		self.baseband_file_text_inf = baseband_file_text_inf = baseband_file

		##################################################
		# Notebooks
		##################################################
		self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "USRP Receiver")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "PLL demodulator and Clock sync")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
		self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
		self.Add(self.rx_ntb)

		##################################################
		# Controls
		##################################################
		self._decim_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.decim_tb,
			callback=self.set_decim_tb,
			label="Decimation",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
		self._symb_rate_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			value=self.symb_rate_tb,
			callback=self.set_symb_rate_tb,
			label="Symbol rate",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
		self._satellite_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.satellite_text,
			callback=self.set_satellite_text,
			label="Sat ",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0, 1, 1)
		self._samp_rate_st_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.samp_rate_st,
			callback=self.set_samp_rate_st,
			label="Sample rate",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1, 1)
		_pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._pll_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			label="PLL Alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._pll_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_pll_alpha_sl_sizer,
			value=self.pll_alpha_sl,
			callback=self.set_pll_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
		self._gain_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.gain_tb,
			callback=self.set_gain_tb,
			label="RX gain [dB]",
			converter=forms.int_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._gain_tb_text_box, 1, 2, 1, 1)
		self._freq_tb_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(0).GetWin(),
			value=self.freq_tb,
			callback=self.set_freq_tb,
			label="Frequency",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(0).GridAdd(self._freq_tb_text_box, 1, 1, 1, 1)
		self._frames_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.frames_file_text_inf,
			callback=self.set_frames_file_text_inf,
			label="Frames filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._frames_file_text_inf_static_text, 3, 0, 1, 1)
		self._deframer_sync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.deframer_sync_after_text,
			callback=self.set_deframer_sync_after_text,
			label="Deframe sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
		self._deframer_nosync_after_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.deframer_nosync_after_text,
			callback=self.set_deframer_nosync_after_text,
			label="Deframer out of sync after",
			converter=forms.float_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
		self._deframer_check_sync_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(2).GetWin(),
			value=self.deframer_check_sync_text,
			callback=self.set_deframer_check_sync_text,
			label="Deframer check sync enable",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(2).GridAdd(self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
		self._datetime_text_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.datetime_text,
			callback=self.set_datetime_text,
			label="Local time of aquisition start",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._datetime_text_static_text, 1, 0, 1, 1)
		_clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
		self._clock_alpha_sl_text_box = forms.text_box(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			label="Clock alpha",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._clock_alpha_sl_slider = forms.slider(
			parent=self.rx_ntb.GetPage(1).GetWin(),
			sizer=_clock_alpha_sl_sizer,
			value=self.clock_alpha_sl,
			callback=self.set_clock_alpha_sl,
			minimum=0.001,
			maximum=0.1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
		self._baseband_file_text_inf_static_text = forms.static_text(
			parent=self.rx_ntb.GetPage(3).GetWin(),
			value=self.baseband_file_text_inf,
			callback=self.set_baseband_file_text_inf,
			label="Baseband filename",
			converter=forms.str_converter(),
		)
		self.rx_ntb.GetPage(3).GridAdd(self._baseband_file_text_inf_static_text, 4, 0, 1, 1)

		##################################################
		# Blocks
		##################################################
		self.gr_agc_xx_0 = gr.agc_cc(10e-6, 1, 1.0/32767.0, 1.0)
		self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(sps/2.0, clock_alpha**2/4.0, 0.5, clock_alpha, max_clock_offset)
		self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_short*1, frames_file)
		self.gr_file_sink_0_0.set_unbuffered(False)
		self.gr_file_sink_0_1 = gr.file_sink(gr.sizeof_short*2, baseband_file)
		self.gr_file_sink_0_1.set_unbuffered(False)
		self.gr_float_to_complex_0 = gr.float_to_complex(1)
		self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0/hs, 4000)
		self.gr_short_to_float_0 = gr.short_to_float()
		self.gr_short_to_float_0_0 = gr.short_to_float()
		self.gr_vector_to_streams_0 = gr.vector_to_streams(gr.sizeof_short*1, 2)
		self.noaa_hrpt_decoder_0 = noaa.hrpt_decoder(True,False)
		self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset)
		self.poesweather_univ_hrpt_deframer_0 = poesweather.univ_hrpt_deframer(deframer_sync_check, 11090, deframer_insync_frames, deframer_outsync_frames)
		self.usrp2_source_xxxx2_0 = usrp2.source_16sc()
		self.usrp2_source_xxxx2_0.set_decim(decim_tb)
		self.usrp2_source_xxxx2_0.set_center_freq(freq_tb)
		self.usrp2_source_xxxx2_0.set_gain(gain_tb)
		self.wxgui_fftsink1 = fftsink2.fft_sink_c(
			self.rx_ntb.GetPage(0).GetWin(),
			baseband_freq=freq,
			y_per_div=5,
			y_divs=10,
			ref_level=65,
			ref_scale=2.0,
			sample_rate=samp_rate,
			fft_size=1024,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="Not filtered spectrum",
			peak_hold=False,
		)
		self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_float_to_complex_0, 0), (self.wxgui_fftsink1, 0))
		self.connect((self.poesweather_univ_hrpt_deframer_0, 0), (self.noaa_hrpt_decoder_0, 0))
		self.connect((self.gr_binary_slicer_fb_0, 0), (self.poesweather_univ_hrpt_deframer_0, 0))
		self.connect((self.poesweather_univ_hrpt_deframer_0, 0), (self.gr_file_sink_0_0, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_binary_slicer_fb_0, 0))
		self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.gr_agc_xx_0, 0), (self.pll, 0))
		self.connect((self.gr_float_to_complex_0, 0), (self.gr_agc_xx_0, 0))
		self.connect((self.gr_vector_to_streams_0, 0), (self.gr_short_to_float_0, 0))
		self.connect((self.gr_vector_to_streams_0, 1), (self.gr_short_to_float_0_0, 0))
		self.connect((self.usrp2_source_xxxx2_0, 0), (self.gr_vector_to_streams_0, 0))
		self.connect((self.usrp2_source_xxxx2_0, 0), (self.gr_file_sink_0_1, 0))
		self.connect((self.gr_short_to_float_0_0, 0), (self.gr_float_to_complex_0, 1))
		self.connect((self.gr_short_to_float_0, 0), (self.gr_float_to_complex_0, 0))
Пример #51
0
    def __init__(self,
                 deframer_insync_frames=2,
                 viterbi_insync_frames=5,
                 deframer_outsync_frames=5,
                 viterbi_outsync_frames=20,
                 viterbi_sync_check=True,
                 viterbi_sync_threshold=0.1,
                 deframer_sync_check=True,
                 clock_alpha=0.005,
                 symb_rate=293883,
                 pll_alpha=0.005,
                 satellite='GOES-LRIT',
                 freq=1691.02e6,
                 gain=23,
                 decim=108,
                 side="A",
                 frames_file=os.environ['HOME'] +
                 '/GOES-LRIT_cadu_frames.cadu',
                 baseband_file=os.environ['HOME'] + '/GOES-LRIT_baseband.dat'):
        grc_wxgui.top_block_gui.__init__(
            self, title="LRIT Receiver from baseband file")

        ##################################################
        # Parameters
        ##################################################
        self.deframer_insync_frames = deframer_insync_frames
        self.viterbi_insync_frames = viterbi_insync_frames
        self.deframer_outsync_frames = deframer_outsync_frames
        self.viterbi_outsync_frames = viterbi_outsync_frames
        self.viterbi_sync_check = viterbi_sync_check
        self.viterbi_sync_threshold = viterbi_sync_threshold
        self.deframer_sync_check = deframer_sync_check
        self.clock_alpha = clock_alpha
        self.symb_rate = symb_rate
        self.pll_alpha = pll_alpha
        self.satellite = satellite
        self.freq = freq
        self.gain = gain
        self.decim = decim
        self.side = side
        self.frames_file = frames_file
        self.baseband_file = baseband_file

        ##################################################
        # Variables
        ##################################################
        self.decim_tb = decim_tb = decim
        self.symb_rate_tb = symb_rate_tb = symb_rate
        self.samp_rate = samp_rate = 64e6 / decim_tb
        self.viterbi_sync_threshold_text = viterbi_sync_threshold_text = viterbi_sync_threshold
        self.viterbi_sync_after_text = viterbi_sync_after_text = viterbi_insync_frames
        self.viterbi_outofsync_after_text = viterbi_outofsync_after_text = viterbi_outsync_frames
        self.viterbi_node_sync_text = viterbi_node_sync_text = viterbi_sync_check
        self.sps = sps = samp_rate / symb_rate_tb
        self.satellite_text = satellite_text = satellite
        self.samp_rate_st = samp_rate_st = samp_rate
        self.pll_alpha_sl = pll_alpha_sl = pll_alpha
        self.gain_tb = gain_tb = gain
        self.freq_tb = freq_tb = freq
        self.frames_file_text_inf = frames_file_text_inf = frames_file
        self.deframer_sync_after_text = deframer_sync_after_text = deframer_insync_frames
        self.deframer_nosync_after_text = deframer_nosync_after_text = deframer_outsync_frames
        self.deframer_check_sync_text = deframer_check_sync_text = deframer_sync_check
        self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S",
                                                      localtime())
        self.clock_alpha_sl = clock_alpha_sl = clock_alpha
        self.baseband_file_text_inf = baseband_file_text_inf = 'no output file'

        ##################################################
        # Notebooks
        ##################################################
        self.rx_ntb = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "USRP Receiver")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb),
                            "PLL demodulator and Clock sync")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Viterbi decoder")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Deframer")
        self.rx_ntb.AddPage(grc_wxgui.Panel(self.rx_ntb), "Output")
        self.Add(self.rx_ntb)

        ##################################################
        # Controls
        ##################################################
        self._decim_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.decim_tb,
            callback=self.set_decim_tb,
            label="Decimation",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._decim_tb_text_box, 1, 3, 1, 1)
        self._symb_rate_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            value=self.symb_rate_tb,
            callback=self.set_symb_rate_tb,
            label="Symbol rate",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(1).GridAdd(self._symb_rate_tb_text_box, 2, 1, 1, 1)
        self._viterbi_sync_threshold_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_sync_threshold_text,
            callback=self.set_viterbi_sync_threshold_text,
            label="Viterbi node sync threshold [BER]",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_sync_threshold_text_static_text, 3, 0, 1, 1)
        self._viterbi_sync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_sync_after_text,
            callback=self.set_viterbi_sync_after_text,
            label="Valid frames for Viterbi decoder sync",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_sync_after_text_static_text, 4, 0, 1, 1)
        self._viterbi_outofsync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_outofsync_after_text,
            callback=self.set_viterbi_outofsync_after_text,
            label="Invalid frames for Viterbi decoder out of sync",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_outofsync_after_text_static_text, 5, 0, 1, 1)
        self._viterbi_node_sync_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(2).GetWin(),
            value=self.viterbi_node_sync_text,
            callback=self.set_viterbi_node_sync_text,
            label="Viterbi node sync enable",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(2).GridAdd(
            self._viterbi_node_sync_text_static_text, 2, 0, 1, 1)
        self._satellite_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.satellite_text,
            callback=self.set_satellite_text,
            label="Sat ",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._satellite_text_static_text, 1, 0,
                                       1, 1)
        self._samp_rate_st_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.samp_rate_st,
            callback=self.set_samp_rate_st,
            label="Sample rate",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._samp_rate_st_static_text, 1, 4, 1,
                                       1)
        _pll_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._pll_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            label="PLL Alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._pll_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_pll_alpha_sl_sizer,
            value=self.pll_alpha_sl,
            callback=self.set_pll_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_pll_alpha_sl_sizer, 1, 0, 1, 1)
        self._gain_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.gain_tb,
            callback=self.set_gain_tb,
            label="RX gain [dB]",
            converter=forms.int_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._gain_tb_text_box, 1, 2, 1, 1)
        self._freq_tb_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(0).GetWin(),
            value=self.freq_tb,
            callback=self.set_freq_tb,
            label="Frequency",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(0).GridAdd(self._freq_tb_text_box, 1, 1, 1, 1)
        self._frames_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.frames_file_text_inf,
            callback=self.set_frames_file_text_inf,
            label="Frames filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(self._frames_file_text_inf_static_text,
                                       3, 0, 1, 1)
        self._deframer_sync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_sync_after_text,
            callback=self.set_deframer_sync_after_text,
            label="Deframe sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_sync_after_text_static_text, 3, 0, 1, 1)
        self._deframer_nosync_after_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_nosync_after_text,
            callback=self.set_deframer_nosync_after_text,
            label="Deframer out of sync after",
            converter=forms.float_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_nosync_after_text_static_text, 4, 0, 1, 1)
        self._deframer_check_sync_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(3).GetWin(),
            value=self.deframer_check_sync_text,
            callback=self.set_deframer_check_sync_text,
            label="Deframer check sync enable",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(3).GridAdd(
            self._deframer_check_sync_text_static_text, 2, 0, 1, 1)
        self._datetime_text_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.datetime_text,
            callback=self.set_datetime_text,
            label="Local time of aquisition start",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(self._datetime_text_static_text, 1, 0,
                                       1, 1)
        _clock_alpha_sl_sizer = wx.BoxSizer(wx.VERTICAL)
        self._clock_alpha_sl_text_box = forms.text_box(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            label="Clock alpha",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._clock_alpha_sl_slider = forms.slider(
            parent=self.rx_ntb.GetPage(1).GetWin(),
            sizer=_clock_alpha_sl_sizer,
            value=self.clock_alpha_sl,
            callback=self.set_clock_alpha_sl,
            minimum=0.001,
            maximum=0.1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.rx_ntb.GetPage(1).GridAdd(_clock_alpha_sl_sizer, 1, 1, 1, 1)
        self._baseband_file_text_inf_static_text = forms.static_text(
            parent=self.rx_ntb.GetPage(4).GetWin(),
            value=self.baseband_file_text_inf,
            callback=self.set_baseband_file_text_inf,
            label="Baseband filename",
            converter=forms.str_converter(),
        )
        self.rx_ntb.GetPage(4).GridAdd(
            self._baseband_file_text_inf_static_text, 4, 0, 1, 1)

        ##################################################
        # Blocks
        ##################################################
        self.fec_decode_viterbi_bpsk_fb_0 = fec.decode_viterbi_bpsk_fb(
            viterbi_sync_check, viterbi_sync_threshold, viterbi_insync_frames,
            viterbi_outsync_frames, viterbi_outsync_frames * 3)
        self.gr_agc_xx_0 = gr.agc_cc(10e-6, 1, 1.0 / 32767.0, 1.0)
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_cc(
            sps, clock_alpha_sl * clock_alpha_sl / 4.0, 0.5, clock_alpha_sl,
            0.05)
        self.gr_complex_to_real_0 = gr.complex_to_real(1)
        self.gr_costas_loop_cc_0 = gr.costas_loop_cc(
            pll_alpha_sl, pll_alpha_sl * pll_alpha_sl / 4.0, 0.07, -0.07, 2)
        self.gr_file_source_0 = gr.file_source(
            gr.sizeof_gr_complex * 1,
            "/home/martin/GNURadioData/lrit/goes_lrit_D108AD64MHz.sam", True)
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((1, ))
        self.gr_null_sink_0 = gr.null_sink(gr.sizeof_char * 1)
        self.gr_packed_to_unpacked_xx_0 = gr.packed_to_unpacked_bb(
            1, gr.GR_MSB_FIRST)
        self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex * 1, samp_rate)
        self.poesweather_metop_cadu_deframer_0 = poesweather.metop_cadu_deframer(
            True, 1024, deframer_insync_frames, deframer_outsync_frames)
        self.root_raised_cosine_filter_0 = gr.fir_filter_ccf(
            1,
            firdes.root_raised_cosine(1, samp_rate, symb_rate, 0.25,
                                      int(11 * samp_rate / symb_rate)))
        self.wxgui_fftsink1 = fftsink2.fft_sink_c(
            self.rx_ntb.GetPage(0).GetWin(),
            baseband_freq=freq,
            y_per_div=2,
            y_divs=10,
            ref_level=12,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="Not filtered spectrum",
            peak_hold=False,
        )
        self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink1.win)
        self.wxgui_fftsink2 = fftsink2.fft_sink_c(
            self.rx_ntb.GetPage(0).GetWin(),
            baseband_freq=0,
            y_per_div=2,
            y_divs=10,
            ref_level=12,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="RRC filtered spectrum",
            peak_hold=False,
        )
        self.rx_ntb.GetPage(0).Add(self.wxgui_fftsink2.win)
        self.wxgui_scopesink2_1 = scopesink2.scope_sink_c(
            self.rx_ntb.GetPage(1).GetWin(),
            title="BPSK constellation diagram",
            sample_rate=symb_rate,
            v_scale=0.4,
            v_offset=0,
            t_scale=1 / samp_rate,
            ac_couple=False,
            xy_mode=True,
            num_inputs=1,
        )
        self.rx_ntb.GetPage(1).Add(self.wxgui_scopesink2_1.win)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_agc_xx_0, 0),
                     (self.root_raised_cosine_filter_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.gr_complex_to_real_0, 0))
        self.connect((self.fec_decode_viterbi_bpsk_fb_0, 0),
                     (self.gr_packed_to_unpacked_xx_0, 0))
        self.connect((self.gr_packed_to_unpacked_xx_0, 0),
                     (self.poesweather_metop_cadu_deframer_0, 0))
        self.connect((self.gr_complex_to_real_0, 0),
                     (self.fec_decode_viterbi_bpsk_fb_0, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.gr_costas_loop_cc_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.root_raised_cosine_filter_0, 0),
                     (self.gr_costas_loop_cc_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.wxgui_scopesink2_1, 0))
        self.connect((self.root_raised_cosine_filter_0, 0),
                     (self.wxgui_fftsink2, 0))
        self.connect((self.gr_agc_xx_0, 0), (self.wxgui_fftsink1, 0))
        self.connect((self.poesweather_metop_cadu_deframer_0, 0),
                     (self.gr_null_sink_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.gr_agc_xx_0, 0))
        self.connect((self.gr_file_source_0, 0), (self.gr_throttle_0, 0))
Пример #52
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)
        parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
                          help="select USRP Rx side A or B (default=A)")
        parser.add_option("-d", "--decim", type="int", default=64,
                          help="set fgpa decimation rate to DECIM [default=%default]")
        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("-8", "--width-8", action="store_true", default=False,
                          help="Enable 8-bit samples across USB")
        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("-N", "--no-hb", action="store_true", default=False,
                          help="don't use halfband filter in usrp")

        (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

        # build graph

        self.u=None

        usrp_decim = options.decim # 32

        if not (options.out_filename=="sdl"):
          options.repeat=False

        if not ((filename is None) or (filename=="usrp")):
          self.filesource = gr.file_source(gr.sizeof_short,filename,options.repeat) # file is data source
          self.istoc = gr.interleaved_short_to_complex()
          self.connect(self.filesource,self.istoc)
          adc_rate=64e6
          self.src=self.istoc
          options.gain=0.0
          self.gain=0.0
        else:
          if options.no_hb or (options.decim<8):
            self.fpga_filename="std_4rx_0tx.rbf" #contains 4 Rx paths without halfbands and 0 tx paths
          else:
            self.fpga_filename="std_2rxhb_2tx.rbf" # contains 2 Rx paths with halfband filters and 2 tx paths (the default)
          self.u = usrp.source_c(0,fpga_filename=self.fpga_filename)                    # usrp is data source
          if options.width_8:
              sample_width = 8
              sample_shift = 8
              format = self.u.make_format(sample_width, sample_shift)
              r = self.u.set_format(format)
          adc_rate = self.u.adc_rate()                # 64 MS/s
          self.u.set_decim_rate(usrp_decim)
          if options.rx_subdev_spec is None:
            options.rx_subdev_spec = pick_subdevice(self.u)
          self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))
          self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
          print "Using RX d'board %s" % (self.subdev.side_and_name(),)
          if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.subdev.gain_range()
            options.gain = float(g[0]+g[1])/2
          self.src=self.u

        usrp_rate = adc_rate / usrp_decim           # 320 kS/s

        f2uc=gr.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=gr.file_sink(gr.sizeof_char, options.out_filename)
          self.dst =file_sink 

        self.agc=gr.agc_cc(1e-7,1.0,1.0) #1e-7
        self.am_demod = gr.complex_to_mag ()
        self.set_blacklevel=gr.add_const_ff(0.0)
        self.invert_and_scale = gr.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)
          self.tv_sync_adv=gr.tv_sync_adv(usrp_rate,0,False,False,0.0,255.0,0.01,1.0,0.0,False) #note, this block is not yet in cvs
          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=gr.complex_to_real()
          nullsink=gr.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
          tv_corr=gr.tv_correlator_ff(frame_size,nframes, search_window, video_alpha, corr_alpha,debug) #Note: this block is not yet in cvs
          shift=gr.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) #self.agc,
        else: # process_type=='do_test_image':
          src_vertical_bars = gr.sig_source_f (usrp_rate, gr.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)

   
        if abs(options.freq) < 1e6:
            options.freq *= 1e6

        # 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")
Пример #53
0
    def __init__(self,
                 if_rate,        # Incoming sample rate
                 symbol_rate,    # Original symbol rate
                 excess_bw,      # RRC excess bandwidth, typically 0.35-0.5
                 costas_alpha,   # Costas loop 1st order gain, typically 0.01-0.2
                 costas_beta,    # Costas loop 2nd order gain, typically alpha^2/4.0
                 costas_max,     # Costas loop max frequency offset in radians/sample
                 mm_gain_mu,     # M&M loop 1st order gain, typically 0.001-0.2
                 mm_gain_omega,  # M&M loop 2nd order gain, typically alpha^2/4.0
                 mm_omega_limit, # M&M loop max timing error
                 ):
        
        gr.hier_block2.__init__(self, "receive_path",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
                                gr.io_signature(0, 0, 0))                    # Output signature
        
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        
        self._if_rate = if_rate
        self._sps = int(self._if_rate/symbol_rate)
        print "IF sample rate:", n2s(self._if_rate)
        print "Symbol rate:", n2s(symbol_rate)
        print "Samples/symbol:", self._sps
        print "RRC bandwidth:", excess_bw
        
        # Create AGC to scale input to unity
        self._agc = gr.agc_cc(1e-5, 1.0, 1.0, 1.0)

	# Create RRC with specified excess bandwidth
	taps = gr.firdes.root_raised_cosine(1.0,          # Gain
					    self._sps,    # Sampling rate
					    1.0,          # Symbol rate
					    excess_bw,    # Roll-off factor
					    11*self._sps) # Number of taps

	self._rrc = gr.fir_filter_ccf(1, taps)
        
        # Create a Costas loop frequency/phase recovery block

        print "Costas alpha:", costas_alpha
        print "Costas beta:", costas_beta
        print "Costas max:", costas_max
        
        self._costas = gr.costas_loop_cc(costas_alpha,  # PLL first order gain
                                         costas_beta,   # PLL second order gain
                                         costas_max,    # Max frequency offset rad/sample
                                         -costas_max,   # Min frequency offset rad/sample
                                         2)             # BPSK

        # Create a M&M bit synchronization retiming block
        mm_mu = 0.5
        mm_omega = self._sps

        print "MM gain mu:", mm_gain_mu
        print "MM gain omega:", mm_gain_omega
        print "MM omega limit:", mm_omega_limit
        
        self._mm = gr.clock_recovery_mm_cc(mm_omega,       # Initial samples/symbol
                                           mm_gain_omega,  # Second order gain
                                           mm_mu,          # Initial symbol phase
                                           mm_gain_mu,     # First order gain
                                           mm_omega_limit) # Maximum timing offset

        # Add an SNR probe on the demodulated constellation
        self._snr_probe = gr.probe_mpsk_snr_c(10.0/symbol_rate)
        
#        #Null for recuperate the out of snr
#        self.gr_null_sink_0 = gr.null_sink(gr.sizeof_double)
#        
#        self.connect(self._snr_probe, (self.gr_null_sink_0,0))
        
        self.connect(self._mm, self._snr_probe)
        
        # Slice the resulting constellation into bits.
        # Get inphase channel and make decision about 0
        self._c2r = gr.complex_to_real()
        self._slicer = gr.binary_slicer_fb() 
        
        # Descramble BERT sequence.  A channel error will create 3 incorrect bits
        self._descrambler = gr.descrambler_bb(0x8A, 0x7F, 7) # CCSDS 7-bit descrambler

        # Measure BER by the density of 0s in the stream
        self._ber = gr.probe_density_b(1.0/symbol_rate)
        
#        #Null for recuperate the out of ber
#        self.gr_null_sink_1 = gr.null_sink(gr.sizeof_double)
#        
#        self.connect(self._ber, self.gr_null_sink_1)
        
        self.create_number_sink(self._sps)
        self.connect((self._snr_probe, 0), (self.wxgui_numbersink2_0, 0))
        self.connect((self._ber, 0), (self.wxgui_numbersink2_1, 0))

        self.connect(self, self._agc, self._rrc, self._costas, self._mm, 
                     self._c2r, self._slicer, self._descrambler, self._ber)
Пример #54
0
    def __init__(self,
                 if_rate,        # Incoming sample rate
                 symbol_rate,    # Original symbol rate
                 excess_bw,      # RRC excess bandwidth, typically 0.35-0.5
                 costas_alpha,   # Costas loop 1st order gain, typically 0.01-0.2
                 costas_beta,    # Costas loop 2nd order gain, typically alpha^2/4.0
                 costas_max,     # Costas loop max frequency offset in radians/sample
                 mm_gain_mu,     # M&M loop 1st order gain, typically 0.001-0.2
                 mm_gain_omega,  # M&M loop 2nd order gain, typically alpha^2/4.0
                 mm_omega_limit, # M&M loop max timing error
                 ):
        
        gr.hier_block2.__init__(self, "receive_path",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
                                gr.io_signature(0, 0, 0))                    # Output signature

        self._if_rate = if_rate
        self._sps = int(self._if_rate/symbol_rate)
        print "IF sample rate:", n2s(self._if_rate)
        print "Symbol rate:", n2s(symbol_rate)
        print "Samples/symbol:", self._sps
        print "RRC bandwidth:", excess_bw
        
        # Create AGC to scale input to unity
        self._agc = gr.agc_cc(1e-5, 1.0, 1.0, 1.0)

	# Create RRC with specified excess bandwidth
	taps = gr.firdes.root_raised_cosine(1.0,          # Gain
					    self._sps,    # Sampling rate
					    1.0,          # Symbol rate
					    excess_bw,    # Roll-off factor
					    11*self._sps) # Number of taps

	self._rrc = gr.fir_filter_ccf(1, taps)
        
        # Create a Costas loop frequency/phase recovery block

        print "Costas alpha:", costas_alpha
        print "Costas beta:", costas_beta
        print "Costas max:", costas_max
        
        self._costas = gr.costas_loop_cc(costas_alpha,  # PLL first order gain
                                         costas_beta,   # PLL second order gain
                                         costas_max,    # Max frequency offset rad/sample
                                         -costas_max,   # Min frequency offset rad/sample
                                         2)             # BPSK

        # Create a M&M bit synchronization retiming block
        mm_mu = 0.5
        mm_omega = self._sps

        print "MM gain mu:", mm_gain_mu
        print "MM gain omega:", mm_gain_omega
        print "MM omega limit:", mm_omega_limit
        
        self._mm = gr.clock_recovery_mm_cc(mm_omega,       # Initial samples/symbol
                                           mm_gain_omega,  # Second order gain
                                           mm_mu,          # Initial symbol phase
                                           mm_gain_mu,     # First order gain
                                           mm_omega_limit) # Maximum timing offset

        # Add an SNR probe on the demodulated constellation
        self._snr_probe = gr.probe_mpsk_snr_c(10.0/symbol_rate)
        self.connect(self._mm, self._snr_probe)
        
        # Slice the resulting constellation into bits.
        # Get inphase channel and make decision about 0
        self._c2r = gr.complex_to_real()
        self._slicer = gr.binary_slicer_fb() 
        
        # Descramble BERT sequence.  A channel error will create 3 incorrect bits
        self._descrambler = gr.descrambler_bb(0x8A, 0x7F, 7) # CCSDS 7-bit descrambler

        # Measure BER by the density of 0s in the stream
        self._ber = gr.probe_density_b(1.0/symbol_rate)

        self.connect(self, self._agc, self._rrc, self._costas, self._mm, 
                     self._c2r, self._slicer, self._descrambler, self._ber)
Пример #55
0
    def __init__(self,
                 side="A",
                 gain=35,
                 decim=32,
                 sync_check=False,
                 satellite='METEOR-M-1',
                 frames_file=os.environ['HOME'] + '/METEOR-M-1.hrpt',
                 freq=1700e6):
        grc_wxgui.top_block_gui.__init__(self, title="USRP 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.side = side
        self.gain = gain
        self.decim = decim
        self.sync_check = sync_check
        self.satellite = satellite
        self.frames_file = frames_file
        self.freq = freq

        ##################################################
        # Variables
        ##################################################
        self.sym_rate = sym_rate = 600 * 1109
        self.samp_rate = samp_rate = 64e6 / decim
        self.config_filename = config_filename = os.environ[
            'HOME'] + '/.gnuradio/mn1_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(
                "satname", '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(
                "satname", '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("satname", '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.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.decim_tb = decim_tb = decim
        self.datetime_text = datetime_text = strftime("%A, %B %d %Y %H:%M:%S",
                                                      localtime())
        self.clock_alpha = clock_alpha = saved_clock_alpha

        ##################################################
        # Notebooks
        ##################################################
        self.displays = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.displays.AddPage(grc_wxgui.Panel(self.displays),
                              "RX Meteor M N1 HRPT")
        self.displays.AddPage(grc_wxgui.Panel(self.displays), "Information")
        self.Add(self.displays)

        ##################################################
        # Controls
        ##################################################
        self._sync_check_txt_static_text = forms.static_text(
            parent=self.GetWin(),
            value=self.sync_check_txt,
            callback=self.set_sync_check_txt,
            label="Sync check",
            converter=forms.float_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)
        _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)
        _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._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._decim_tb_text_box = forms.text_box(
            parent=self.GetWin(),
            value=self.decim_tb,
            callback=self.set_decim_tb,
            label="Decimation",
            converter=forms.int_converter(),
        )
        self.GridAdd(self._decim_tb_text_box, 1, 0, 1, 1)
        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)
        _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)

        ##################################################
        # Blocks
        ##################################################
        self.agc = gr.agc_cc(1e-5, 1.0, 1.0 / 32768.0, 1.0)
        self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
        self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(
            sps / 2.0, clock_alpha**2 / 4.0, 0.5, clock_alpha,
            max_clock_offset)
        self.gr_file_sink_0_0 = gr.file_sink(gr.sizeof_short * 1, frames_file)
        self.gr_file_sink_0_0.set_unbuffered(False)
        self.gr_interleaved_short_to_complex_0 = gr.interleaved_short_to_complex(
        )
        self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0 / hs, 4000)
        self.gr_rms_xx_0 = gr.rms_cf(0.2)
        self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2 / 4.0,
                                    max_carrier_offset)
        self.poesweather_mn1_hrpt_deframer_0 = poesweather.mn1_hrpt_deframer(
            sync_check)
        self.usrp_simple_source_x_0 = grc_usrp.simple_source_s(which=0,
                                                               side=side,
                                                               rx_ant="RXA")
        self.usrp_simple_source_x_0.set_decim_rate(decim)
        self.usrp_simple_source_x_0.set_frequency(freq, verbose=True)
        self.usrp_simple_source_x_0.set_gain(gain)
        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=45,
            ref_scale=2.0,
            sample_rate=samp_rate,
            fft_size=1024,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="Meteor M N1 HRPT FFT Spectrum",
            peak_hold=False,
        )
        self.displays.GetPage(0).Add(self.wxgui_fftsink2_0.win)
        self.wxgui_numbersink2_0 = numbersink2.number_sink_f(
            self.GetWin(),
            unit="Units",
            minval=0,
            maxval=5000,
            factor=1.0,
            decimal_places=4,
            ref_level=0,
            sample_rate=samp_rate,
            number_rate=15,
            average=True,
            avg_alpha=0.07,
            label="S-Meter",
            peak_hold=False,
            show_gauge=True,
        )
        self.Add(self.wxgui_numbersink2_0.win)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_binary_slicer_fb_0, 0),
                     (self.poesweather_mn1_hrpt_deframer_0, 0))
        self.connect((self.usrp_simple_source_x_0, 0),
                     (self.gr_interleaved_short_to_complex_0, 0))
        self.connect((self.gr_interleaved_short_to_complex_0, 0),
                     (self.agc, 0))
        self.connect((self.gr_clock_recovery_mm_xx_0, 0),
                     (self.gr_binary_slicer_fb_0, 0))
        self.connect((self.agc, 0), (self.pll, 0))
        self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
        self.connect((self.gr_moving_average_xx_0, 0),
                     (self.gr_clock_recovery_mm_xx_0, 0))
        self.connect((self.gr_interleaved_short_to_complex_0, 0),
                     (self.wxgui_fftsink2_0, 0))
        self.connect((self.gr_interleaved_short_to_complex_0, 0),
                     (self.gr_rms_xx_0, 0))
        self.connect((self.gr_rms_xx_0, 0), (self.wxgui_numbersink2_0, 0))
        self.connect((self.poesweather_mn1_hrpt_deframer_0, 0),
                     (self.gr_file_sink_0_0, 0))
Пример #56
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="USRP HRPT Receiver")

		##################################################
		# Variables
		##################################################
		self.config_filename = config_filename = os.environ['HOME']+'/.gnuradio/config.conf'
		self._decim_config = ConfigParser.ConfigParser()
		self._decim_config.read(config_filename)
		try: decim = self._decim_config.getfloat('usrp_rx_hrpt', 'decim')
		except: decim = 32
		self.decim = decim
		self.sym_rate = sym_rate = 600*1109
		self.sample_rate = sample_rate = 64e6/decim
		self.sps = sps = sample_rate/sym_rate
		self._side_config = ConfigParser.ConfigParser()
		self._side_config.read(config_filename)
		try: side = self._side_config.get('usrp_rx_hrpt', 'side')
		except: side = 'A'
		self.side = side
		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('usrp_rx_hrpt', 'pll_alpha')
		except: saved_pll_alpha = 0.01
		self.saved_pll_alpha = saved_pll_alpha
		self._saved_gain_config = ConfigParser.ConfigParser()
		self._saved_gain_config.read(config_filename)
		try: saved_gain = self._saved_gain_config.getfloat('usrp_rx_hrpt', 'gain')
		except: saved_gain = 35
		self.saved_gain = saved_gain
		self._saved_freq_config = ConfigParser.ConfigParser()
		self._saved_freq_config.read(config_filename)
		try: saved_freq = self._saved_freq_config.getfloat('usrp_rx_hrpt', 'freq')
		except: saved_freq = 1698e6
		self.saved_freq = saved_freq
		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('usrp_rx_hrpt', 'clock_alpha')
		except: saved_clock_alpha = 0.01
		self.saved_clock_alpha = saved_clock_alpha
		self.side_text = side_text = side
		self.pll_alpha = pll_alpha = saved_pll_alpha
		self._output_filename_config = ConfigParser.ConfigParser()
		self._output_filename_config.read(config_filename)
		try: output_filename = self._output_filename_config.get('usrp_rx_hrpt', 'filename')
		except: output_filename = 'frames.hrpt'
		self.output_filename = output_filename
		self.max_clock_offset = max_clock_offset = 100e-6
		self.max_carrier_offset = max_carrier_offset = 2*math.pi*100e3/sample_rate
		self.hs = hs = int(sps/2.0)
		self.gain = gain = saved_gain
		self.freq = freq = saved_freq
		self.decim_text = decim_text = decim
		self.clock_alpha = clock_alpha = saved_clock_alpha

		##################################################
		# Notebooks
		##################################################
		self.displays = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.displays.AddPage(grc_wxgui.Panel(self.displays), "Spectrum")
		self.displays.AddPage(grc_wxgui.Panel(self.displays), "Demod")
		self.GridAdd(self.displays, 2, 0, 1, 4)

		##################################################
		# Controls
		##################################################
		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, 1, 0, 1, 1)
		_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.0,
			maximum=0.5,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_pll_alpha_sizer, 0, 2, 1, 1)
		_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="RX 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=100,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_gain_sizer, 0, 1, 1, 1)
		self._freq_text_box = forms.text_box(
			parent=self.GetWin(),
			value=self.freq,
			callback=self.set_freq,
			label="Frequency",
			converter=forms.float_converter(),
		)
		self.GridAdd(self._freq_text_box, 0, 0, 1, 1)
		self._decim_text_static_text = forms.static_text(
			parent=self.GetWin(),
			value=self.decim_text,
			callback=self.set_decim_text,
			label="Decimation",
			converter=forms.float_converter(),
		)
		self.GridAdd(self._decim_text_static_text, 1, 1, 1, 1)
		_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.0,
			maximum=0.5,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.GridAdd(_clock_alpha_sizer, 0, 3, 1, 1)

		##################################################
		# Blocks
		##################################################
		self.agc = gr.agc_cc(1e-6, 1.0, 1.0, 1.0)
		self.decoder = noaa.hrpt_decoder(True,True)
		self.deframer = noaa.hrpt_deframer()
		self.demod_scope = scopesink2.scope_sink_f(
			self.displays.GetPage(1).GetWin(),
			title="Post-Demod",
			sample_rate=sym_rate*2.0,
			v_scale=0.5,
			v_offset=0,
			t_scale=10.0/sym_rate,
			ac_couple=False,
			xy_mode=False,
			num_inputs=1,
		)
		self.displays.GetPage(1).GridAdd(self.demod_scope.win, 0, 0, 1, 1)
		self.frame_sink = gr.file_sink(gr.sizeof_short*1, output_filename)
		self.gr_binary_slicer_fb_0 = gr.binary_slicer_fb()
		self.gr_clock_recovery_mm_xx_0 = gr.clock_recovery_mm_ff(sps/2.0, clock_alpha**2/4.0, 0.5, clock_alpha, max_clock_offset)
		self.gr_moving_average_xx_0 = gr.moving_average_ff(hs, 1.0/hs, 4000)
		self.pll = noaa.hrpt_pll_cf(pll_alpha, pll_alpha**2/4.0, max_carrier_offset)
		self.rx_fft = fftsink2.fft_sink_c(
			self.displays.GetPage(0).GetWin(),
			baseband_freq=freq,
			y_per_div=5,
			y_divs=8,
			ref_level=-5,
			ref_scale=2.0,
			sample_rate=sample_rate,
			fft_size=1024,
			fft_rate=15,
			average=True,
			avg_alpha=0.1,
			title="RX Spectrum",
			peak_hold=False,
			size=(640, 360),
		)
		self.displays.GetPage(0).GridAdd(self.rx_fft.win, 0, 0, 1, 1)
		self.usrp_source = grc_usrp.simple_source_c(which=0, side=side, rx_ant="RXA")
		self.usrp_source.set_decim_rate(decim)
		self.usrp_source.set_frequency(freq, verbose=True)
		self.usrp_source.set_gain(gain)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.gr_binary_slicer_fb_0, 0))
		self.connect((self.deframer, 0), (self.frame_sink, 0))
		self.connect((self.deframer, 0), (self.decoder, 0))
		self.connect((self.gr_clock_recovery_mm_xx_0, 0), (self.demod_scope, 0))
		self.connect((self.gr_moving_average_xx_0, 0), (self.gr_clock_recovery_mm_xx_0, 0))
		self.connect((self.pll, 0), (self.gr_moving_average_xx_0, 0))
		self.connect((self.agc, 0), (self.pll, 0))
		self.connect((self.usrp_source, 0), (self.agc, 0))
		self.connect((self.agc, 0), (self.rx_fft, 0))
		self.connect((self.gr_binary_slicer_fb_0, 0), (self.deframer, 0))