def __init__(self, fg, parent,
                 y_per_div=10, ref_level=50, sample_rate=1,
                 title='', stripsize=4,
                 size=default_stripchartsink_size,xlabel="X", 
                 ylabel="Y", divbase=0.025,
                 parallel=False, scaling=1.0, autoscale=False):

        stripchart_sink_base.__init__(self, input_is_real=True,
                               y_per_div=y_per_div, ref_level=ref_level,
                               sample_rate=sample_rate,
                               stripsize=stripsize,
                               xlabel=xlabel, ylabel=ylabel, 
                               divbase=divbase, title=title,
                               parallel=parallel, 
                               scaling=scaling, autoscale=autoscale)
                               
        if (parallel == True):
            one = gr.keep_one_in_n (gr.sizeof_float*stripsize, 1)
            sink = gr.message_sink(gr.sizeof_float*stripsize, self.msgq, True)
        else:
            one = gr.keep_one_in_n (gr.sizeof_float, 1)
            sink = gr.message_sink(gr.sizeof_float, self.msgq, True)
        fg.connect (one, sink)

        gr.hier_block.__init__(self, fg, one, sink)

        self.win = stripchart_window(self, parent, size=size)
Ejemplo n.º 2
0
    def __init__(
        self,
        parent,
        y_per_div=10,
        ref_level=50,
        sample_rate=1,
        title="",
        stripsize=4,
        size=default_stripchartsink_size,
        xlabel="X",
        ylabel="Y",
        divbase=0.025,
        parallel=False,
        scaling=1.0,
        autoscale=False,
    ):

        if parallel == False:
            gr.hier_block2.__init__(
                self, "stripchart_sink_f", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(0, 0, 0)
            )
        else:
            gr.hier_block2.__init__(
                self, "stripchart_sink_f", gr.io_signature(1, 1, gr.sizeof_float * stripsize), gr.io_signature(0, 0, 0)
            )

        stripchart_sink_base.__init__(
            self,
            input_is_real=True,
            y_per_div=y_per_div,
            ref_level=ref_level,
            sample_rate=sample_rate,
            stripsize=stripsize,
            xlabel=xlabel,
            ylabel=ylabel,
            divbase=divbase,
            title=title,
            parallel=parallel,
            scaling=scaling,
            autoscale=autoscale,
        )

        if parallel == True:
            one = gr.keep_one_in_n(gr.sizeof_float * stripsize, 1)
            sink = gr.message_sink(gr.sizeof_float * stripsize, self.msgq, True)
        else:
            one = gr.keep_one_in_n(gr.sizeof_float, 1)
            sink = gr.message_sink(gr.sizeof_float, self.msgq, True)
        self.connect(self, one, sink)

        self.win = stripchart_window(self, parent, size=size)
    def __init__(self, fg, parent, unit='',base_value=0,minval=-100.0,maxval=100.0,factor=1.0,
                 decimal_places=10, ref_level=50, sample_rate=1, #number_size=512,
                 number_rate=default_number_rate, average=False, avg_alpha=None,
                 label='', size=default_numbersink_size, peak_hold=False):

        number_sink_base.__init__(self, unit=unit, input_is_real=True, base_value=base_value,
                               minval=minval,maxval=maxval,factor=factor,
                               decimal_places=decimal_places, ref_level=ref_level,
                               sample_rate=sample_rate, #number_size=number_size,
                               number_rate=number_rate,
                               average=average, avg_alpha=avg_alpha, label=label,
                               peak_hold=peak_hold)
         
        number_size=1                      
        #s2p = gr.stream_to_vector(gr.sizeof_float, number_size)
        one_in_n = gr.keep_one_in_n(gr.sizeof_float,
                                    max(1, int(sample_rate/number_rate)))

            
        #c2mag = gr.complex_to_mag(number_size)
        self.avg = gr.single_pole_iir_filter_ff(1.0, number_size)

        # FIXME  We need to add 3dB to all bins but the DC bin
        #log = gr.nlog10_ff(20, number_size,
        #                   -20*math.log10(number_size)-10*math.log10(power/number_size))
        sink = gr.message_sink(gr.sizeof_float , self.msgq, True)

        #fg.connect (s2p, one_in_n, fft, c2mag, self.avg, log, sink)
        fg.connect(self.avg,one_in_n,sink)
        gr.hier_block.__init__(self, fg, self.avg, sink)
        self.win = number_window(self, parent, size=size,label=label)
        self.set_average(self.average)
    def __init__(self, parent, unit='',base_value=0,minval=-100.0,maxval=100.0,factor=1.0,
                 decimal_places=10, ref_level=50, sample_rate=1, 
                 number_rate=default_number_rate, average=False, avg_alpha=None,
                 label='', size=default_numbersink_size, peak_hold=False):

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

        number_sink_base.__init__(self, unit=unit, input_is_real=True, base_value=base_value,
                               minval=minval,maxval=maxval,factor=factor,
                               decimal_places=decimal_places, ref_level=ref_level,
                               sample_rate=sample_rate, number_rate=number_rate,
                               average=average, avg_alpha=avg_alpha, label=label,
                               peak_hold=peak_hold)
         
        number_size=1                      
        one_in_n = gr.keep_one_in_n(gr.sizeof_float,
                                    max(1, int(sample_rate/number_rate)))
            
        self.avg = gr.single_pole_iir_filter_ff(1.0, number_size)
        sink = gr.message_sink(gr.sizeof_float , self.msgq, True)
        self.connect(self, self.avg, one_in_n, sink)

        self.win = number_window(self, parent, size=size,label=label)
        self.set_average(self.average)
	self.set_peak_hold(self.peak_hold)
Ejemplo n.º 5
0
    def __init__(self,subdev_spec=None,gain=None,length=1,alpha=1.0,msgq=None,loopback=False,verbose=False,debug=False):
	self._subdev_spec = subdev_spec
        self._gain = gain
        self._length = length
        self._alpha = alpha
        self._msgq = msgq
	self._loopback = loopback
	self._verbose = verbose
	self._debug = debug
		
        self._tb = gr.top_block()
        self._u = usrp.source_c(fpga_filename='usrp_sounder.rbf')
	if not self._loopback:
            if self._subdev_spec == None:
                self._subdev_spec = pick_subdevice(self._u)
            self._u.set_mux(usrp.determine_rx_mux_value(self._u, self._subdev_spec))
            self._subdev = usrp.selected_subdev(self._u, self._subdev_spec)
            if self._verbose:
	        print "Using", self._subdev.name(), "for sounder receiver."

        self.set_gain(self._gain)
        self._vblen = gr.sizeof_gr_complex*self._length
	if self._debug:
            print "Generating impulse vectors of length", self._length, "byte length", self._vblen
            
        self._s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self._length)
	if self._verbose:
	    print "Using smoothing alpha of", self._alpha
        self._lpf = gr.single_pole_iir_filter_cc(self._alpha, self._length)
        self._sink = gr.message_sink(self._vblen, self._msgq, True)
        self._tb.connect(self._u, self._s2v, self._lpf, self._sink)
Ejemplo n.º 6
0
    def __init__(
        self,
        parent,
        baseband_freq=0,
        y_per_div=10,
        ref_level=50,
        sample_rate=1,
        fac_size=512,
        fac_rate=default_fac_rate,
        average=False,
        avg_alpha=None,
        title="",
        size=default_facsink_size,
        peak_hold=False,
    ):

        fac_sink_base.__init__(
            self,
            input_is_real=False,
            baseband_freq=baseband_freq,
            y_per_div=y_per_div,
            ref_level=ref_level,
            sample_rate=sample_rate,
            fac_size=fac_size,
            fac_rate=fac_rate,
            average=average,
            avg_alpha=avg_alpha,
            title=title,
            peak_hold=peak_hold,
        )

        s2p = gr.stream_to_vector(gr.sizeof_gr_complex, self.fac_size)
        self.one_in_n = gr.keep_one_in_n(
            gr.sizeof_gr_complex * self.fac_size, max(1, int(self.sample_rate / self.fac_size / self.fac_rate))
        )

        # windowing removed ...

        fac = gr.fft_vcc(self.fac_size, True, ())
        c2mag = gr.complex_to_mag(fac_size)

        # Things go off into the weeds if we try for an inverse FFT so a forward FFT will have to do...
        fac_fac = gr.fft_vfc(self.fac_size, True, ())
        fac_c2mag = gr.complex_to_mag(fac_size)

        self.avg = gr.single_pole_iir_filter_ff(1.0, fac_size)

        log = gr.nlog10_ff(
            20, self.fac_size, -20 * math.log10(self.fac_size)
        )  #  - 20*math.log10(norm) ) # - self.avg[0] )
        sink = gr.message_sink(gr.sizeof_float * fac_size, self.msgq, True)

        self.connect(s2p, self.one_in_n, fac, c2mag, fac_fac, fac_c2mag, self.avg, log, sink)

        #        gr.hier_block2.__init__(self, fg, s2p, sink)

        self.win = fac_window(self, parent, size=size)
        self.set_average(self.average)

        self.wxgui_connect(self, s2p)
    def __init__(self, fg, parent, baseband_freq=0,
                 y_per_div=10, ref_level=50, sample_rate=1, fft_size=512,
                 fft_rate=default_fft_rate, average=False, avg_alpha=None,
                 title='', size=default_fftsink_size, peak_hold=False):

        fft_sink_base.__init__(self, input_is_real=True, baseband_freq=baseband_freq,
                               y_per_div=y_per_div, ref_level=ref_level,
                               sample_rate=sample_rate, fft_size=fft_size,
                               fft_rate=fft_rate,
                               average=average, avg_alpha=avg_alpha, title=title,
                               peak_hold=peak_hold)
                               
        s2p = gr.stream_to_vector(gr.sizeof_float, self.fft_size)
        self.one_in_n = gr.keep_one_in_n(gr.sizeof_float * self.fft_size,
                                         max(1, int(self.sample_rate/self.fft_size/self.fft_rate)))

        mywindow = window.blackmanharris(self.fft_size)
        fft = gr.fft_vfc(self.fft_size, True, mywindow)
        power = 0
        for tap in mywindow:
            power += tap*tap
            
        c2mag = gr.complex_to_mag(self.fft_size)
        self.avg = gr.single_pole_iir_filter_ff(1.0, self.fft_size)

        # FIXME  We need to add 3dB to all bins but the DC bin
        log = gr.nlog10_ff(20, self.fft_size,
                           -20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size))
        sink = gr.message_sink(gr.sizeof_float * self.fft_size, self.msgq, True)

        fg.connect (s2p, self.one_in_n, fft, c2mag, self.avg, log, sink)
        gr.hier_block.__init__(self, fg, s2p, sink)

        self.win = fft_window(self, parent, size=size)
        self.set_average(self.average)
Ejemplo n.º 8
0
    def __init__(self, parent, baseband_freq=0,
                 y_per_div=10, sc_y_per_div=0.5, sc_ref_level=40, ref_level=50, sample_rate=1, fft_size=512,
                 fft_rate=15, average=False, avg_alpha=None, title='',
                 size=default_ra_fftsink_size, peak_hold=False, ofunc=None,
                 xydfunc=None):
	gr.hier_block2.__init__(self, "ra_fft_sink_f",
				gr.io_signature(1, 1, gr.sizeof_float),
				gr.io_signature(0, 0, 0))
				
        ra_fft_sink_base.__init__(self, input_is_real=True, baseband_freq=baseband_freq,
                               y_per_div=y_per_div, sc_y_per_div=sc_y_per_div,
                               sc_ref_level=sc_ref_level, ref_level=ref_level,
                               sample_rate=sample_rate, fft_size=fft_size,
                               fft_rate=fft_rate,
                               average=average, avg_alpha=avg_alpha, title=title,
                               peak_hold=peak_hold, ofunc=ofunc, 
                               xydfunc=xydfunc)
                               
        self.binwidth = float(sample_rate/2.0)/float(fft_size)
        s2p = gr.serial_to_parallel(gr.sizeof_float, fft_size)
        one_in_n = gr.keep_one_in_n(gr.sizeof_float * fft_size,
                                    max(1, int(sample_rate/fft_size/fft_rate)))
        mywindow = window.blackmanharris(fft_size)
        fft = gr.fft_vfc(fft_size, True, mywindow)
        c2mag = gr.complex_to_mag(fft_size)
        self.avg = gr.single_pole_iir_filter_ff(1.0, fft_size)
        log = gr.nlog10_ff(20, fft_size, -20*math.log10(fft_size))
        sink = gr.message_sink(gr.sizeof_float * fft_size, self.msgq, True)

        self.connect (self, s2p, one_in_n, fft, c2mag, self.avg, log, sink)

        self.win = fft_window(self, parent, size=size)
        self.set_average(self.average)
Ejemplo n.º 9
0
    def __init__(self,
                 parent,
                 title='',
                 sample_rate=1,
                 size=default_scopesink_size,
                 frame_decim=default_frame_decim,
                 samples_per_symbol=10,
                 num_plots=100,
                 v_scale=default_v_scale,
                 t_scale=None,
                 num_inputs=1,
                 **kwargs):

        gr.hier_block2.__init__(
            self, "datascope_sink_f",
            gr.io_signature(num_inputs, num_inputs, gr.sizeof_float),
            gr.io_signature(0, 0, 0))

        msgq = gr.msg_queue(2)  # message queue that holds at most 2 messages
        self.st = gr.message_sink(gr.sizeof_float, msgq, dont_block=1)
        self.connect((self, 0), self.st)

        self.win = datascope_window(datascope_win_info(msgq, sample_rate,
                                                       frame_decim, v_scale,
                                                       t_scale, None, title),
                                    parent,
                                    samples_per_symbol=samples_per_symbol,
                                    num_plots=num_plots)
Ejemplo n.º 10
0
    def __init__(self, parent, baseband_freq=0,
                 y_per_div=10, ref_level=50, sample_rate=1, fft_size=512,
                 fft_rate=default_fft_rate, average=False, avg_alpha=None,
                 title='', size=default_fftsink_size, **kwargs):

        gr.hier_block2.__init__(self, "waterfall_sink_f",
                                gr.io_signature(1, 1, gr.sizeof_float),
                                gr.io_signature(0,0,0))

        waterfall_sink_base.__init__(self, input_is_real=True, baseband_freq=baseband_freq,
                               sample_rate=sample_rate, fft_size=fft_size,
                               fft_rate=fft_rate,
                               average=average, avg_alpha=avg_alpha, title=title)

        self.s2p = gr.serial_to_parallel(gr.sizeof_float, self.fft_size)
        self.one_in_n = gr.keep_one_in_n(gr.sizeof_float * self.fft_size,
                                         max(1, int(self.sample_rate/self.fft_size/self.fft_rate)))

        mywindow = window.blackmanharris(self.fft_size)
        self.fft = gr.fft_vfc(self.fft_size, True, mywindow)
        self.c2mag = gr.complex_to_mag(self.fft_size)
        self.avg = gr.single_pole_iir_filter_ff(1.0, self.fft_size)
        self.log = gr.nlog10_ff(20, self.fft_size, -20*math.log10(self.fft_size))
        self.sink = gr.message_sink(gr.sizeof_float * self.fft_size, self.msgq, True)
	self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2mag, self.avg, self.log, self.sink)

        self.win = waterfall_window(self, parent, size=size)
        self.set_average(self.average)
Ejemplo n.º 11
0
	def __init__(self, parent, title, vlen, decim,gsz):
		self._vlen = vlen
		self._parent = parent
		self._title = title
		print "Initing block: %s" % title

		self.plotQueue = Queue.Queue()
		self.win = matplotsink.matplotsink(parent,title, self.plotQueue,gsz)		

		self._item_size = self._size*self._vlen
		#init hier block
		gr.hier_block2.__init__(
			self, 'plot_sink',
			gr.io_signature(1, 1, self._item_size),
			gr.io_signature(0, 0, 0),
		)
		#create blocks		
		self._msgq = gr.msg_queue(2)
		message_sink = gr.message_sink(self._item_size, self._msgq, False)
		#connect
		self.connect(self, message_sink)
		#setup thread
		threading.Thread.__init__(self)
		self.setDaemon(True)
		self.start() 
Ejemplo n.º 12
0
    def __init__(self, parent, title, vlen, decim):
        self._vlen = vlen
        self._parent = parent
        self._title = title

        print "Initing block: %s" % title

        self.plotQueue = Queue.Queue()

        self.win = matplotsink.matplotsink(parent, title, self.plotQueue)

        self._item_size = self._size * self._vlen
        #init hier block
        gr.hier_block2.__init__(
            self,
            'plot_sink',
            gr.io_signature(1, 1, self._item_size),
            gr.io_signature(0, 0, 0),
        )
        #create blocks
        self._msgq = gr.msg_queue(2)
        message_sink = gr.message_sink(self._item_size, self._msgq, False)
        #connect
        self.connect(self, message_sink)
        #setup thread
        threading.Thread.__init__(self)
        self.setDaemon(True)
        self.start()
Ejemplo n.º 13
0
 def __init__(self, packet_source=None, payload_length=0):
     if not payload_length:  #get payload length
         payload_length = DEFAULT_PAYLOAD_LEN
     if payload_length % self._item_size_in != 0:  #verify that packet length is a multiple of the stream size
         raise ValueError, 'The payload length: "%d" is not a mutiple of the stream size: "%d".' % (
             payload_length, self._item_size_in)
     #initialize hier2
     gr.hier_block2.__init__(
         self,
         "ofdm_mod",
         gr.io_signature(1, 1, self._item_size_in),  # Input signature
         gr.io_signature(
             1, 1,
             packet_source._hb.output_signature().sizeof_stream_item(
                 0))  # Output signature
     )
     #create blocks
     msgq = gr.msg_queue(DEFAULT_MSGQ_LIMIT)
     msg_sink = gr.message_sink(self._item_size_in, msgq,
                                False)  #False -> blocking
     #connect
     self.connect(self, msg_sink)
     self.connect(packet_source, self)
     #start thread
     _packet_encoder_thread(msgq, payload_length, packet_source.send_pkt)
    def __init__(self,subdev_spec=None,gain=None,length=1,alpha=1.0,msgq=None,loopback=False,verbose=False,debug=False):
	self._subdev_spec = subdev_spec
        self._gain = gain
        self._length = length
        self._alpha = alpha
        self._msgq = msgq
	self._loopback = loopback
	self._verbose = verbose
	self._debug = debug
		
        self._fg = gr.flow_graph()
        self._u = usrp.source_c(fpga_filename='usrp_sounder.rbf')
	if not self._loopback:
            if self._subdev_spec == None:
                self._subdev_spec = pick_subdevice(self._u)
            self._u.set_mux(usrp.determine_rx_mux_value(self._u, self._subdev_spec))
            self._subdev = usrp.selected_subdev(self._u, self._subdev_spec)
            if self._verbose:
	        print "Using", self._subdev.name(), "for sounder receiver."

        self.set_gain(self._gain)
        self._vblen = gr.sizeof_gr_complex*self._length
	if self._debug:
            print "Generating impulse vectors of length", self._length, "byte length", self._vblen
            
        self._s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self._length)
	if self._verbose:
	    print "Using smoothing alpha of", self._alpha
        self._lpf = gr.single_pole_iir_filter_cc(self._alpha, self._length)
        self._sink = gr.message_sink(self._vblen, self._msgq, True)
        self._fg.connect(self._u, self._s2v, self._lpf, self._sink)
Ejemplo n.º 15
0
  def publish_rx_spectrum(self,fftlen):
    ## RX Spectrum

    fftlen = 256
    my_window = window.hamming(fftlen) #.blackmanharris(fftlen)
    rxs_sampler = vector_sampler(gr.sizeof_gr_complex,fftlen)
    rxs_trigger = gr.vector_source_b(concatenate([[1],[0]*199]),True)
    rxs_window = blocks.multiply_const_vcc(my_window)
    rxs_spectrum = gr.fft_vcc(fftlen,True,[],True)
    rxs_mag = gr.complex_to_mag(fftlen)
    rxs_avg = gr.single_pole_iir_filter_ff(0.01,fftlen)
    rxs_logdb = gr.nlog10_ff(20.0,fftlen,-20*log10(fftlen))
    rxs_decimate_rate = gr.keep_one_in_n(gr.sizeof_float*fftlen,1)
    msgq = gr.msg_queue(5)
    rxs_msg_sink = gr.message_sink(gr.sizeof_float*fftlen,msgq,True)
    self.connect(rxs_trigger,(rxs_sampler,1))
    t = self.u if self.filter is None else self.filter
    self.connect(t,rxs_sampler,rxs_window,
                 rxs_spectrum,rxs_mag,rxs_avg,rxs_logdb, rxs_decimate_rate,
                 rxs_msg_sink)
    self.servants.append(corba_data_buffer_servant("spectrum",fftlen,msgq))

    print "RXS trigger unique id", rxs_trigger.unique_id()
    
    print "Publishing RX baseband under id: spectrum"
    def __init__(self, fg, parent, baseband_freq=0,
                 ref_level=0, sample_rate=1, fft_size=512,
                 fft_rate=default_fft_rate, average=False, avg_alpha=None, 
                 title='', size=default_fftsink_size, report=None, span=40, ofunc=None, xydfunc=None):

        waterfall_sink_base.__init__(self, input_is_real=False,
                                     baseband_freq=baseband_freq,
                                     sample_rate=sample_rate,
                                     fft_size=fft_size,
                                     fft_rate=fft_rate,
                                     average=average, avg_alpha=avg_alpha,
                                     title=title)

        s2p = gr.serial_to_parallel(gr.sizeof_gr_complex, self.fft_size)
        self.one_in_n = gr.keep_one_in_n(gr.sizeof_gr_complex * self.fft_size,
                                         max(1, int(self.sample_rate/self.fft_size/self.fft_rate)))

        mywindow = window.blackmanharris(self.fft_size)
        fft = gr.fft_vcc(self.fft_size, True, mywindow)
        c2mag = gr.complex_to_mag(self.fft_size)
        self.avg = gr.single_pole_iir_filter_ff(1.0, self.fft_size)
        log = gr.nlog10_ff(20, self.fft_size, -20*math.log10(self.fft_size))
        sink = gr.message_sink(gr.sizeof_float * self.fft_size, self.msgq, True)

        self.block_list = (s2p, self.one_in_n, fft, c2mag, self.avg, log, sink)
        self.reconnect( fg )
        gr.hier_block.__init__(self, fg, s2p, sink)

        self.win = waterfall_window(self, parent, size=size, report=report,
                                    ref_level=ref_level, span=span, ofunc=ofunc, xydfunc=xydfunc)
        self.set_average(self.average)
Ejemplo n.º 17
0
    def __init__(self, parent, baseband_freq=0,
                 y_per_div=10, ref_level=50, sample_rate=1, fft_size=512,
                 fft_rate=default_fft_rate, average=False, avg_alpha=None,
                 title='', size=default_fftsink_size):

        gr.hier_block2.__init__(self, "waterfall_sink_f",
                                gr.io_signature(1, 1, gr.sizeof_float),
                                gr.io_signature(0,0,0))

        waterfall_sink_base.__init__(self, input_is_real=True, baseband_freq=baseband_freq,
                               sample_rate=sample_rate, fft_size=fft_size,
                               fft_rate=fft_rate,
                               average=average, avg_alpha=avg_alpha, title=title)
                               
        self.s2p = gr.serial_to_parallel(gr.sizeof_float, self.fft_size)
        self.one_in_n = gr.keep_one_in_n(gr.sizeof_float * self.fft_size,
                                         max(1, int(self.sample_rate/self.fft_size/self.fft_rate)))
        
        mywindow = window.blackmanharris(self.fft_size)
        self.fft = gr.fft_vfc(self.fft_size, True, mywindow)
        self.c2mag = gr.complex_to_mag(self.fft_size)
        self.avg = gr.single_pole_iir_filter_ff(1.0, self.fft_size)
        self.log = gr.nlog10_ff(20, self.fft_size, -20*math.log10(self.fft_size))
        self.sink = gr.message_sink(gr.sizeof_float * self.fft_size, self.msgq, True)
	self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2mag, self.avg, self.log, self.sink)

        self.win = waterfall_window(self, parent, size=size)
        self.set_average(self.average)
Ejemplo n.º 18
0
    def __init__(
        self,
        parent,
        baseband_freq=0,
        y_per_div=10,
        ref_level=50,
        sample_rate=1,
        fac_size=512,
        fac_rate=default_fac_rate,
        average=False,
        avg_alpha=None,
        title="",
        size=default_facsink_size,
        peak_hold=False,
    ):

        fac_sink_base.__init__(
            self,
            input_is_real=True,
            baseband_freq=baseband_freq,
            y_per_div=y_per_div,
            ref_level=ref_level,
            sample_rate=sample_rate,
            fac_size=fac_size,
            fac_rate=fac_rate,
            average=average,
            avg_alpha=avg_alpha,
            title=title,
            peak_hold=peak_hold,
        )

        s2p = gr.stream_to_vector(gr.sizeof_float, self.fac_size)
        self.one_in_n = gr.keep_one_in_n(
            gr.sizeof_float * self.fac_size, max(1, int(self.sample_rate / self.fac_size / self.fac_rate))
        )

        # windowing removed...

        fac = gr.fft_vfc(self.fac_size, True, ())

        c2mag = gr.complex_to_mag(self.fac_size)
        self.avg = gr.single_pole_iir_filter_ff(1.0, self.fac_size)

        fac_fac = gr.fft_vfc(self.fac_size, True, ())
        fac_c2mag = gr.complex_to_mag(fac_size)

        # FIXME  We need to add 3dB to all bins but the DC bin
        log = gr.nlog10_ff(20, self.fac_size, -20 * math.log10(self.fac_size))
        sink = gr.message_sink(gr.sizeof_float * self.fac_size, self.msgq, True)

        self.connect(s2p, self.one_in_n, fac, c2mag, fac_fac, fac_c2mag, self.avg, log, sink)

        #        gr.hier_block.__init__(self, fg, s2p, sink)

        self.win = fac_window(self, parent, size=size)
        self.set_average(self.average)

        self.wxgui_connect(self, s2p)
Ejemplo n.º 19
0
    def __init__(self,
                 parent,
                 baseband_freq=0,
                 y_per_div=10,
                 ref_level=50,
                 sample_rate=1,
                 fac_size=512,
                 fac_rate=default_fac_rate,
                 average=False,
                 avg_alpha=None,
                 title='',
                 size=default_facsink_size,
                 peak_hold=False):

        fac_sink_base.__init__(self,
                               input_is_real=False,
                               baseband_freq=baseband_freq,
                               y_per_div=y_per_div,
                               ref_level=ref_level,
                               sample_rate=sample_rate,
                               fac_size=fac_size,
                               fac_rate=fac_rate,
                               average=average,
                               avg_alpha=avg_alpha,
                               title=title,
                               peak_hold=peak_hold)

        s2p = gr.stream_to_vector(gr.sizeof_gr_complex, self.fac_size)
        self.one_in_n = gr.keep_one_in_n(
            gr.sizeof_gr_complex * self.fac_size,
            max(1, int(self.sample_rate / self.fac_size / self.fac_rate)))

        # windowing removed ...

        fac = gr.fft_vcc(self.fac_size, True, ())
        c2mag = gr.complex_to_mag(fac_size)

        # Things go off into the weeds if we try for an inverse FFT so a forward FFT will have to do...
        fac_fac = gr.fft_vfc(self.fac_size, True, ())
        fac_c2mag = gr.complex_to_mag(fac_size)

        self.avg = gr.single_pole_iir_filter_ff(1.0, fac_size)

        log = gr.nlog10_ff(20, self.fac_size, -20 * math.log10(
            self.fac_size))  #  - 20*math.log10(norm) ) # - self.avg[0] )
        sink = gr.message_sink(gr.sizeof_float * fac_size, self.msgq, True)

        self.connect(s2p, self.one_in_n, fac, c2mag, fac_fac, fac_c2mag,
                     self.avg, log, sink)

        #        gr.hier_block2.__init__(self, fg, s2p, sink)

        self.win = fac_window(self, parent, size=size)
        self.set_average(self.average)

        self.wxgui_connect(self, s2p)
Ejemplo n.º 20
0
    def __init__(self,
                 parent,
                 baseband_freq=0,
                 y_per_div=10,
                 ref_level=50,
                 sample_rate=1,
                 fac_size=512,
                 fac_rate=default_fac_rate,
                 average=False,
                 avg_alpha=None,
                 title='',
                 size=default_facsink_size,
                 peak_hold=False):

        fac_sink_base.__init__(self,
                               input_is_real=True,
                               baseband_freq=baseband_freq,
                               y_per_div=y_per_div,
                               ref_level=ref_level,
                               sample_rate=sample_rate,
                               fac_size=fac_size,
                               fac_rate=fac_rate,
                               average=average,
                               avg_alpha=avg_alpha,
                               title=title,
                               peak_hold=peak_hold)

        s2p = gr.stream_to_vector(gr.sizeof_float, self.fac_size)
        self.one_in_n = gr.keep_one_in_n(
            gr.sizeof_float * self.fac_size,
            max(1, int(self.sample_rate / self.fac_size / self.fac_rate)))

        # windowing removed...

        fac = gr.fft_vfc(self.fac_size, True, ())

        c2mag = gr.complex_to_mag(self.fac_size)
        self.avg = gr.single_pole_iir_filter_ff(1.0, self.fac_size)

        fac_fac = gr.fft_vfc(self.fac_size, True, ())
        fac_c2mag = gr.complex_to_mag(fac_size)

        # FIXME  We need to add 3dB to all bins but the DC bin
        log = gr.nlog10_ff(20, self.fac_size, -20 * math.log10(self.fac_size))
        sink = gr.message_sink(gr.sizeof_float * self.fac_size, self.msgq,
                               True)

        self.connect(s2p, self.one_in_n, fac, c2mag, fac_fac, fac_c2mag,
                     self.avg, log, sink)

        #        gr.hier_block.__init__(self, fg, s2p, sink)

        self.win = fac_window(self, parent, size=size)
        self.set_average(self.average)

        self.wxgui_connect(self, s2p)
Ejemplo n.º 21
0
    def __init__(self, options):
        gr.top_block.__init__(self)

        if options.freq is not None:
            u = usrp2.source(options)
        elif options.infile is not None:
            u = gr.file_source(gr.sizeof_gr_complex, options.infile)
        else:
            import sys
            sys.stderr.write("--freq or --infile must be specified\n")
            raise SystemExit

        self.scope = None

        if options.outfile is not None:
            rx = gr.file_sink(gr.sizeof_gr_complex, options.outfile)
        else:
            rx = qam_rxtx.RX(options)
            framebytes = rx.framebytes
            if options.rxdata is not None:
                if options.rxdata == '-':
                    self.connect(
                        rx,
                        gr.file_descriptor_sink(gr.sizeof_char * framebytes,
                                                1))
                else:
                    self.connect(
                        rx,
                        gr.file_sink(gr.sizeof_char * framebytes,
                                     options.rxdata))

            if options.berdata is not None:
                # select one of the ber modes
                ber = qam_rxtx.BER(framebytes, 100, mode=options.bermode)
                data = qam_rxtx.make_data(framebytes)
                self.connect(rx, (ber, 0))
                self.connect(data, (ber, 1))
                if options.berdata == '-':
                    # print it out
                    msgq = gr.msg_queue(16)
                    self.connect(ber,
                                 gr.message_sink(gr.sizeof_float, msgq, True))
                    self.watcher = ofdm_rxtx.queue_watcher(msgq)
                elif options.berdata == '.':
                    import scope
                    # scope it out
                    self.scope = scope.scope(self, ber, 'Frame BER')
                else:
                    self.connect(
                        ber, gr.file_sink(gr.sizeof_float, options.berdata))
            else:
                pass
                #self.connect(rx, gr.null_sink(symbol_size)) # XXX do we still need this?

        self.connect(u, rx)
Ejemplo n.º 22
0
    def __init__(
        self,
        baseband_freq=0,
        ref_scale=2.0,
        y_per_div=10,
        y_divs=8,
        ref_level=50,
        sample_rate=1,
        fft_size=512,
        fft_rate=20,
        average=False,
        avg_alpha=None,
        win=None,
        use_persistence=False,
        persist_alpha=None,
        **kwargs
    ):
        # ensure avg alpha
        if avg_alpha is None:
            avg_alpha = 2.0 / fft_rate

            # ensure analog alpha
        if persist_alpha is None:
            actual_fft_rate = float(sample_rate / fft_size) / float(
                max(1, int(float((sample_rate / fft_size) / fft_rate)))
            )
            # print "requested_fft_rate ",fft_rate
            # print "actual_fft_rate    ",actual_fft_rate
            analog_cutoff_freq = 0.5  # Hertz
            # calculate alpha from wanted cutoff freq
            persist_alpha = 1.0 - math.exp(-2.0 * math.pi * analog_cutoff_freq / actual_fft_rate)

            # init
        gr.hier_block2.__init__(
            self, "zmq_fft_sink", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(0, 0, 0)
        )

        # blocks
        fft_0 = fft.logpwrfft_c(
            sample_rate=sample_rate,
            fft_size=fft_size,
            frame_rate=fft_rate,
            ref_scale=ref_scale,
            avg_alpha=avg_alpha,
            average=average,
            win=win,
        )

        msgq = gr.msg_queue(2)
        sink = gr.message_sink(gr.sizeof_float * fft_size, msgq, True)
        input_watcher(msgq)

        # connect
        self.connect(self, fft_0, sink)
Ejemplo n.º 23
0
 def __init__(self, d_type, d_len, qt_box, d_type_numpy, samp_rate, center_f):
     gr.hier_block2.__init__(self, "plot_sink",
             gr.io_signature(1, 1, d_type * d_len),
             gr.io_signature(0, 0, 0))
     self.msgq = gr.msg_queue(1)
     self.snk = gr.message_sink(d_type * d_len, self.msgq, True)
     self.connect(self, self.snk)
     self.watcher = QueueWatcherThread(self.msgq, d_len, d_type_numpy, samp_rate, center_f)
     qt_box.connect(self.watcher,
                    Qt.SIGNAL("new_plot_data(PyQt_PyObject, PyQt_PyObject, PyQt_PyObject)"),
                    qt_box.plot_data)
Ejemplo n.º 24
0
    def __init__(self):
        gr.top_block.__init__(self, 'Message Blocks Test')

        # initialize the queues
        self.sink_queue = gr.msg_queue()
        self.source_queue = gr.msg_queue()

        # initialize the blocks
        self.msg_source = gr.message_source(gr.sizeof_char, self.source_queue)
        self.msg_sink = gr.message_sink(gr.sizeof_char, self.sink_queue, False)

        self.connect((self.msg_source, 0), (self.msg_sink, 0))
    def __init__(self):
        gr.top_block.__init__(self, 'Message Blocks Test')

        # initialize the queues
        self.sink_queue = gr.msg_queue()
        self.source_queue = gr.msg_queue()

        # initialize the blocks
        self.msg_source = gr.message_source(gr.sizeof_char, self.source_queue)
        self.msg_sink = gr.message_sink(gr.sizeof_char, self.sink_queue, False)

        self.connect((self.msg_source, 0), (self.msg_sink, 0))
Ejemplo n.º 26
0
    def __init__(self, audio_input_dev):
	gr.hier_block2.__init__(self, "audio_rx",
				gr.io_signature(0, 0, 0), # Input signature
				gr.io_signature(0, 0, 0)) # Output signature
        sample_rate = 44100
        src = audio.source(sample_rate, audio_input_dev)
        src_scale = gr.multiply_const_ff(32767)
        f2s = gr.float_to_short()
        voice_coder = gsm_full_rate.encode_sp()
        self.packets_from_encoder = gr.msg_queue()
        packet_sink = gr.message_sink(33, self.packets_from_encoder, False)
        self.connect(src, src_scale, f2s, voice_coder, packet_sink)
Ejemplo n.º 27
0
    def __init__(self, audio_input_dev):
	gr.hier_block2.__init__(self, "audio_rx",
				gr.io_signature(0, 0, 0), # Input signature
				gr.io_signature(0, 0, 0)) # Output signature
        sample_rate = 8000
        src = audio.source(sample_rate, audio_input_dev)
        src_scale = gr.multiply_const_ff(32767)
        f2s = gr.float_to_short()
        voice_coder = gsm_full_rate.encode_sp()
        self.packets_from_encoder = gr.msg_queue()
        packet_sink = gr.message_sink(33, self.packets_from_encoder, False)
        self.connect(src, src_scale, f2s, voice_coder, packet_sink)
Ejemplo n.º 28
0
    def __init__(self,
                 parent,
                 baseband_freq=0,
                 ref_level=0,
                 sample_rate=1,
                 fft_size=512,
                 fft_rate=default_fft_rate,
                 average=False,
                 avg_alpha=None,
                 title='',
                 size=default_fftsink_size,
                 report=None,
                 span=40,
                 ofunc=None,
                 xydfunc=None):

        gr.hier_block2.__init__(self, "waterfall_sink_c",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(0, 0, 0))

        waterfall_sink_base.__init__(self,
                                     input_is_real=False,
                                     baseband_freq=baseband_freq,
                                     sample_rate=sample_rate,
                                     fft_size=fft_size,
                                     fft_rate=fft_rate,
                                     average=average,
                                     avg_alpha=avg_alpha,
                                     title=title)

        s2p = gr.serial_to_parallel(gr.sizeof_gr_complex, self.fft_size)
        self.one_in_n = gr.keep_one_in_n(
            gr.sizeof_gr_complex * self.fft_size,
            max(1, int(self.sample_rate / self.fft_size / self.fft_rate)))

        mywindow = window.blackmanharris(self.fft_size)
        fft = gr.fft_vcc(self.fft_size, True, mywindow)
        c2mag = gr.complex_to_mag(self.fft_size)
        self.avg = gr.single_pole_iir_filter_ff(1.0, self.fft_size)
        log = gr.nlog10_ff(20, self.fft_size, -20 * math.log10(self.fft_size))
        sink = gr.message_sink(gr.sizeof_float * self.fft_size, self.msgq,
                               True)

        self.connect(self, s2p, self.one_in_n, fft, c2mag, self.avg, log, sink)
        self.win = waterfall_window(self,
                                    parent,
                                    size=size,
                                    report=report,
                                    ref_level=ref_level,
                                    span=span,
                                    ofunc=ofunc,
                                    xydfunc=xydfunc)
        self.set_average(self.average)
Ejemplo n.º 29
0
  def publish_spectrum(self,fftlen):
    spectrum = gr.fft_vcc(fftlen,True,[],True)
    mag = gr.complex_to_mag(fftlen)
    logdb = gr.nlog10_ff(20.0,fftlen,-20*log10(fftlen))
    decimate_rate = gr.keep_one_in_n(gr.sizeof_gr_complex*fftlen,10)

    msgq = gr.msg_queue(10)
    msg_sink = gr.message_sink(gr.sizeof_float*fftlen,msgq,True)

    self.connect(self.filter,gr.stream_to_vector(gr.sizeof_gr_complex,fftlen),
                 decimate_rate,spectrum,mag,logdb,msg_sink)

    self.servants.append(corba_data_buffer_servant("tx_spectrum",fftlen,msgq))
Ejemplo n.º 30
0
  def publish_ctf(self,unique_id):
    """
    corbaname: ofdm_ti.unique_id
    """

    config = self.config
    vlen = config.data_subcarriers

    msgq = gr.msg_queue(2)
    msg_sink = gr.message_sink(gr.sizeof_float*vlen,msgq,True)
    msg_sink_2 = gr.message_sink(gr.sizeof_float*vlen,msgq,True)

    ctf = self.filter_ctf()
    ctf_2 = self.filter_ctf_2()
    self.connect( ctf, msg_sink )
    self.connect( ctf_2, msg_sink_2 )

    self.servants.append(corba_data_buffer_servant(str(unique_id),vlen,msgq))
    self.servants.append(corba_data_buffer_servant(str(unique_id_2),vlen,msgq_2))

    print "Publishing CTF under id: %s" % (unique_id)
    print "Publishing CTF 2 under id: %s" % (unique_id_2)
Ejemplo n.º 31
0
	def __init__(
		self,
		parent,
		unit='%',
		minval=0,
		maxval=100,
		decimal_places=5,
		sample_rate=1,
		number_rate=DEFAULT_NUMBER_RATE,
		label='Bit Error Rate',
		size=DEFAULT_WIN_SIZE,
		show_gauge=True,
		**kwargs #catchall for backwards compatibility
	):
		gr.hier_block2.__init__(
			self,
			"number_sink",
			gr.io_signature(1, 1, self._item_size),
			gr.io_signature(0, 0, 0),
		)
		#blocks
		sd = blks2.stream_to_vector_decimator(
			item_size=self._item_size,
			sample_rate=sample_rate,
			vec_rate=number_rate,
			vec_len=1,
		)
		mult = gr.multiply_const_ff(100)
		add = gr.add_const_ff(1e-10)
		msgq = gr.msg_queue(2)
		sink = gr.message_sink(self._item_size, msgq, True)
		#connect
		self.connect(self, sd, mult, add, sink)
		#controller
		self.controller = pubsub()
		#start input watcher
		common.input_watcher(msgq, self.controller, MSG_KEY)
		#create window
		self.win = number_window(
			parent=parent,
			controller=self.controller,
			size=size,
			title=label,
			units=unit,
			real=self._real,
			minval=minval,
			maxval=maxval,
			decimal_places=decimal_places,
			show_gauge=show_gauge,
			msg_key=MSG_KEY,
			sample_rate_key=SAMPLE_RATE_KEY)
Ejemplo n.º 32
0
    def _setup_connections(self):
	if not self._length_set:
	    raise RuntimeError("Echo length not set.")
	self._setup_usrp()
        self._vblen = gr.sizeof_gr_complex*self._length
	self._s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self._length)
        self._sink = gr.message_sink(self._vblen, self._msgq, False)
        self.connect(self._u, self._s2v, self._sink)

        if self._verbose:
            print "Generating echo vectors of length", self._length, \
                  "(samples)", self._vblen, "(bytes)"

	self._connected = True
Ejemplo n.º 33
0
    def _setup_connections(self):
        if not self._length_set:
            raise RuntimeError("Echo length not set.")
        self._setup_usrp()
        self._vblen = gr.sizeof_gr_complex * self._length
        self._s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self._length)
        self._sink = gr.message_sink(self._vblen, self._msgq, False)
        self.connect(self._u, self._s2v, self._sink)

        if self._verbose:
            print "Generating echo vectors of length", self._length, \
                  "(samples)", self._vblen, "(bytes)"

        self._connected = True
Ejemplo n.º 34
0
 def __init__(
         self,
         parent,
         unit='%',
         minval=0,
         maxval=100,
         decimal_places=5,
         sample_rate=1,
         number_rate=DEFAULT_NUMBER_RATE,
         label='Bit Error Rate',
         size=DEFAULT_WIN_SIZE,
         show_gauge=True,
         **kwargs  #catchall for backwards compatibility
 ):
     gr.hier_block2.__init__(
         self,
         "number_sink",
         gr.io_signature(1, 1, self._item_size),
         gr.io_signature(0, 0, 0),
     )
     #blocks
     sd = blks2.stream_to_vector_decimator(
         item_size=self._item_size,
         sample_rate=sample_rate,
         vec_rate=number_rate,
         vec_len=1,
     )
     mult = gr.multiply_const_ff(100)
     add = gr.add_const_ff(1e-10)
     msgq = gr.msg_queue(2)
     sink = gr.message_sink(self._item_size, msgq, True)
     #connect
     self.connect(self, sd, mult, add, sink)
     #controller
     self.controller = pubsub()
     #start input watcher
     common.input_watcher(msgq, self.controller, MSG_KEY)
     #create window
     self.win = number_window(parent=parent,
                              controller=self.controller,
                              size=size,
                              title=label,
                              units=unit,
                              real=self._real,
                              minval=minval,
                              maxval=maxval,
                              decimal_places=decimal_places,
                              show_gauge=show_gauge,
                              msg_key=MSG_KEY,
                              sample_rate_key=SAMPLE_RATE_KEY)
Ejemplo n.º 35
0
  def publish_sinrsc(self,unique_id):
    """
    corbaname: ofdm_ti.unique_id
    """

    config = self.config
    vlen = config.subcarriers

    msgq = gr.msg_queue(2)
    msg_sink = gr.message_sink(gr.sizeof_float*vlen,msgq,True)

    sinrsc = self._sinr_measurement
    self.connect( sinrsc, msg_sink )

    self.servants.append(corba_data_buffer_servant(str(unique_id),vlen,msgq))
Ejemplo n.º 36
0
  def publish_tm_window(self,unique_id):
    """
    corbaname: ofdm_ti.unique_id
    """
    raise SystemError,"Bad guy! Obey the gnuradio hierarchy ..."

    config = self.config
    msgq = gr.msg_queue(10)
    msg_sink = gr.message_sink(gr.sizeof_float*config.fft_length,msgq,True)
    sampler = vector_sampler(gr.sizeof_float,config.fft_length)

    self.connect(self.receiver.timing_metric,(sampler,0))
    self.connect(self.receiver.time_sync,delay(gr.sizeof_char,config.fft_length/2-1),(sampler,1))
    self.connect(sampler,msg_sink)

    self.servants.append(corba_data_buffer_servant(str(unique_id),config.fft_length,msgq))
Ejemplo n.º 37
0
Archivo: qam_rx.py Proyecto: UpYou/ofdm
  def __init__(self, options):
    gr.top_block.__init__(self)

    if options.freq is not None:
      u = usrp2.source(options)
    elif options.infile is not None:
      u = gr.file_source(gr.sizeof_gr_complex, options.infile)
    else:
      import sys
      sys.stderr.write("--freq or --infile must be specified\n")
      raise SystemExit

    self.scope = None

    if options.outfile is not None:
      rx = gr.file_sink(gr.sizeof_gr_complex, options.outfile)
    else:
      rx = qam_rxtx.RX(options)
      framebytes = rx.framebytes
      if options.rxdata is not None:
        if options.rxdata == '-':
          self.connect(rx, gr.file_descriptor_sink(gr.sizeof_char * framebytes, 1))
        else:
          self.connect(rx, gr.file_sink(gr.sizeof_char * framebytes, options.rxdata))

      if options.berdata is not None:
        # select one of the ber modes
        ber = qam_rxtx.BER(framebytes, 100, mode=options.bermode)
        data = qam_rxtx.make_data(framebytes)
        self.connect(rx, (ber,0))
        self.connect(data, (ber,1))
        if options.berdata == '-':
          # print it out
          msgq = gr.msg_queue(16)
          self.connect(ber, gr.message_sink(gr.sizeof_float, msgq, True))
          self.watcher = ofdm_rxtx.queue_watcher(msgq)
        elif options.berdata == '.':
          import scope
          # scope it out
          self.scope = scope.scope(self, ber, 'Frame BER')
        else:
          self.connect(ber, gr.file_sink(gr.sizeof_float, options.berdata))
      else:
        pass
        #self.connect(rx, gr.null_sink(symbol_size)) # XXX do we still need this?

    self.connect(u, rx)
Ejemplo n.º 38
0
 def test_1(self):
     data = ('hello', 'you', 'there')
     tx_msgq = gr.msg_queue()
     rx_msgq = gr.msg_queue()
     for d in data:
         tx_msgq.insert_tail(gr.message_from_string(d))
     tb = gr.top_block()
     src = gr.message_source(gr.sizeof_char, tx_msgq, "packet_length")
     snk = gr.message_sink(gr.sizeof_char, rx_msgq, False, "packet_length")
     tb.connect(src, snk)
     tb.start()
     time.sleep(1)
     tb.stop()
     for d in data:
         msg = rx_msgq.delete_head()
         contents = msg.to_string()
         self.assertEqual(d, contents)
Ejemplo n.º 39
0
 def test_1 (self):
     data = ('hello', 'you', 'there')
     tx_msgq = gr.msg_queue ()
     rx_msgq = gr.msg_queue ()
     for d in data:
         tx_msgq.insert_tail(gr.message_from_string(d))
     tb = gr.top_block()
     src = gr.message_source(gr.sizeof_char, tx_msgq, "packet_length")
     snk = gr.message_sink(gr.sizeof_char, rx_msgq, False, "packet_length")
     tb.connect(src, snk)
     tb.start()
     time.sleep(1)
     tb.stop()
     for d in data:
         msg = rx_msgq.delete_head()
         contents = msg.to_string()
         self.assertEqual(d, contents)
Ejemplo n.º 40
0
  def publish_ctf(self,unique_id):
    """
    corbaname: ofdm_ti.unique_id
    """

    config = self.config
    vlen = config.data_subcarriers

    msgq = gr.msg_queue(2)
    msg_sink = gr.message_sink(gr.sizeof_float*vlen,msgq,True)

    ctf = self.filter_ctf()
    self.connect( ctf, msg_sink )

    self.servants.append(corba_data_buffer_servant(str(unique_id),vlen,msgq))

    print "Publishing CTF under id: %s" % (unique_id)
Ejemplo n.º 41
0
    def __init__(self, samp_rate, symbol_rate=31.25):

	super(psk31_receiver, self).__init__(
            "psk31_receiver",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),
            gr.io_signature(0, 0, 1))
        self.symbol_rate = symbol_rate
	self.costas = digital.costas_loop_cc(2*3.14/100, 4)
        self.clock_recovery = digital.clock_recovery_mm_cc(
            1.0*samp_rate/symbol_rate, 0.25 * 0.1*0.1, 0.05, 0.1, 0.001)
	self.receiver = digital.constellation_receiver_cb(
            digital.constellation_bpsk().base(), 2*3.14/100, -0.25, 0.25)
	self.diff = gr.diff_decoder_bb(2)
        self.decoder = ham.psk31_decode_bb(True)
        self.msgq_out = gr.msg_queue()
	self.snk = gr.message_sink(gr.sizeof_char, self.msgq_out, True)
        self.connect(self, self.costas, self.clock_recovery,
                     self.receiver, self.diff, self.decoder, self.snk)
Ejemplo n.º 42
0
	def __init__(
		self,
		parent,
		title='',
		sample_rate=1,
		size=(495,450),
		frame_rate=5,
		const_size=1024,
		mod='DBPSK'):
		#init
		gr.hier_block2.__init__(
			self,
			"const_sink",
			gr.io_signature(1, 1, gr.sizeof_gr_complex),
			gr.io_signature(0, 0, 0),
		)
		self.sd = blks2.stream_to_vector_decimator(
			item_size=gr.sizeof_gr_complex,
			sample_rate=sample_rate,
			vec_rate=frame_rate,
			vec_len=const_size,
		)
		self. agc = gr.agc2_cc(0.6e-1, 1e-3, 1, 1, 100)
		self.gain= gr.multiply_const_cc(utils.gain[mod])
		msgq = gr.msg_queue(2)
		sink = gr.message_sink(gr.sizeof_gr_complex*const_size, msgq, True)
		#connect
		self.connect(self, self.agc, self.gain, self.sd, sink)
		
		#controller
		def setter(p, k, x): p[k] = x
		
		self.controller = pubsub()
		#initial update
		common.input_watcher(msgq, self.controller, MSG_KEY)
		#create window
		self.win = const_window(
			parent=parent,
			controller=self.controller,
			size=size,
			title=title,
			msg_key=MSG_KEY
		)
		common.register_access_methods(self, self.win)
Ejemplo n.º 43
0
    def __init__(self, parent, baseband_freq=0, ref_scale=2.0,
                 y_per_div=10, y_divs=8, ref_level=50, sample_rate=1, fft_size=512,
                 fft_rate=default_fft_rate, average=False, avg_alpha=None,
                 title='', size=default_fftsink_size, peak_hold=False, use_persistence=False,persist_alpha=0.2, **kwargs):

        gr.hier_block2.__init__(self, "fft_sink_c",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(0,0,0))

        fft_sink_base.__init__(self, input_is_real=False, baseband_freq=baseband_freq,
                               y_per_div=y_per_div, y_divs=y_divs, ref_level=ref_level,
                               sample_rate=sample_rate, fft_size=fft_size,
                               fft_rate=fft_rate,
                               average=average, avg_alpha=avg_alpha, title=title,
                               peak_hold=peak_hold, use_persistence=use_persistence,persist_alpha=persist_alpha)

        self.s2p = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)
        self.one_in_n = gr.keep_one_in_n(gr.sizeof_gr_complex * self.fft_size,
                                         max(1, int(self.sample_rate/self.fft_size/self.fft_rate)))
        
        mywindow = window.blackmanharris(self.fft_size)
        self.fft = gr.fft_vcc(self.fft_size, True, mywindow)
        power = 0
        for tap in mywindow:
            power += tap*tap
            
        self.c2mag = gr.complex_to_mag(self.fft_size)
        self.avg = gr.single_pole_iir_filter_ff(1.0, self.fft_size)

        # FIXME  We need to add 3dB to all bins but the DC bin
        self.log = gr.nlog10_ff(20, self.fft_size,
                                -10*math.log10(self.fft_size)                # Adjust for number of bins
                                -10*math.log10(power/self.fft_size)        # Adjust for windowing loss
                                -20*math.log10(ref_scale/2))                # Adjust for reference scale
                                
        self.sink = gr.message_sink(gr.sizeof_float * self.fft_size, self.msgq, True)
        self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2mag, self.avg, self.log, self.sink)

        self.win = fft_window(self, parent, size=size)
        self.set_average(self.average)
        self.set_use_persistence(self.use_persistence)
        self.set_persist_alpha(self.persist_alpha)
        self.set_peak_hold(self.peak_hold)
Ejemplo n.º 44
0
    def __init__(self, options):

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


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

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

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

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

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

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

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

        self.sink = gr.message_sink(gr.sizeof_float * self.fft_size, self.msgq, True)
        self.connect(self, self.s2p, self.fft, self.c2mag, self.avg, self.log, self.sink)
Ejemplo n.º 45
0
    def __init__(self,
                 parent,
                 title='',
                 sample_rate=1,
                 size=(495, 450),
                 frame_rate=5,
                 const_size=1024,
                 mod='DBPSK'):
        #init
        gr.hier_block2.__init__(
            self,
            "const_sink",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),
            gr.io_signature(0, 0, 0),
        )
        self.sd = blks2.stream_to_vector_decimator(
            item_size=gr.sizeof_gr_complex,
            sample_rate=sample_rate,
            vec_rate=frame_rate,
            vec_len=const_size,
        )
        self.agc = gr.agc2_cc(0.6e-1, 1e-3, 1, 1, 100)
        self.gain = gr.multiply_const_cc(utils.gain[mod])
        msgq = gr.msg_queue(2)
        sink = gr.message_sink(gr.sizeof_gr_complex * const_size, msgq, True)
        #connect
        self.connect(self, self.agc, self.gain, self.sd, sink)

        #controller
        def setter(p, k, x):
            p[k] = x

        self.controller = pubsub()
        #initial update
        common.input_watcher(msgq, self.controller, MSG_KEY)
        #create window
        self.win = const_window(parent=parent,
                                controller=self.controller,
                                size=size,
                                title=title,
                                msg_key=MSG_KEY)
        common.register_access_methods(self, self.win)
	def __init__(self, packet_source=None, payload_length=0):
		if not payload_length: #get payload length
			payload_length = DEFAULT_PAYLOAD_LEN
		if payload_length%self._item_size_in != 0:	#verify that packet length is a multiple of the stream size
			raise ValueError, 'The payload length: "%d" is not a mutiple of the stream size: "%d".'%(payload_length, self._item_size_in)
		#initialize hier2
		gr.hier_block2.__init__(
			self,
			"ofdm_mod",
			gr.io_signature(1, 1, self._item_size_in), # Input signature
			gr.io_signature(1, 1, packet_source._hb.output_signature().sizeof_stream_item(0)) # Output signature
		)
		#create blocks
		msgq = gr.msg_queue(DEFAULT_MSGQ_LIMIT)
		msg_sink = gr.message_sink(self._item_size_in, msgq, False) #False -> blocking
		#connect
		self.connect(self, msg_sink)
		self.connect(packet_source, self)
		#start thread
		_packet_encoder_thread(msgq, payload_length, packet_source.send_pkt)
Ejemplo n.º 47
0
	def __init__(self, vlen, decim, callback):
		self._vlen = vlen
		self._callback = callback
		self._item_size = self._size*self._vlen
		#init hier block
		gr.hier_block2.__init__(
			self, 'variable_sink',
			gr.io_signature(1, 1, self._item_size),
			gr.io_signature(0, 0, 0),
		)
		#create blocks
		self._decimator = gr.keep_one_in_n(self._item_size, decim)
		self._msgq = gr.msg_queue(2)
		message_sink = gr.message_sink(self._item_size, self._msgq, False)
		#connect
		self.connect(self, self._decimator, message_sink)
		#setup thread
		threading.Thread.__init__(self)
		self.setDaemon(True)
		self.start() 
Ejemplo n.º 48
0
    def __init__(self,
                 type='BER',
                 win_size=default_win_size,
                 bits_per_symbol=2):
        """
		Error rate constructor.
		@param type a string 'BER' or 'SER'
		@param win_size the number of samples to calculate over
		@param bits_per_symbol the number of information bits per symbol (BER only)
		"""
        #init
        gr.hier_block2.__init__(
            self,
            'error_rate',
            gr.io_signature(2, 2, gr.sizeof_char),
            gr.io_signature(1, 1, gr.sizeof_float),
        )
        assert type in ('BER', 'SER')
        self._max_samples = win_size
        self._bits_per_symbol = bits_per_symbol
        #setup message queue
        msg_source = gr.message_source(gr.sizeof_float, 1)
        self._msgq_source = msg_source.msgq()
        msgq_sink = gr.msg_queue(2)
        msg_sink = gr.message_sink(gr.sizeof_char, msgq_sink,
                                   False)  #False -> blocking
        inter = gr.interleave(gr.sizeof_char)
        #start thread
        self._num_errs = 0
        self._err_index = 0
        self._num_samps = 0
        self._err_array = numpy.zeros(self._max_samples, numpy.int8)
        if type == 'BER':
            input_watcher(msgq_sink, self._handler_ber)
        elif type == 'SER':
            input_watcher(msgq_sink, self._handler_ser)
        #connect
        self.connect(msg_source, self)
        self.connect((self, 0), (inter, 0))
        self.connect((self, 1), (inter, 1))
        self.connect(inter, msg_sink)
Ejemplo n.º 49
0
    def __init__(self, vlen=1):
        """!
		Queue sink base contructor.
		@param vlen the vector length
		"""
        self._vlen = vlen
        #initialize hier2
        gr.hier_block2.__init__(
            self,
            "queue_sink",
            gr.io_signature(1, 1,
                            self._item_size * self._vlen),  # Input signature
            gr.io_signature(0, 0, 0)  # Output signature
        )
        #create message sink
        self._msgq = gr.msg_queue(4)
        message_sink = gr.message_sink(self._item_size * self._vlen,
                                       self._msgq, False)  #False -> blocking
        #connect
        self.connect(self, message_sink)

        self.arr = None
        self.idx = 0
Ejemplo n.º 50
0
	def __init__(
		self,
		parent,
		baseband_freq=0,
		ref_scale=2.0,
		y_per_div=10,
		y_divs=8,
		ref_level=50,
		sample_rate=1,
		pspectrum_len=512,
		specest_rate=specest_window.DEFAULT_FRAME_RATE,
		average=False,
		avg_alpha=None,
		title='',
		size=specest_window.DEFAULT_WIN_SIZE,
		peak_hold=False,
        use_persistence=False,
        persist_alpha=None,
        n = 1,
        m = 150,
        nsamples = 256,
        estimator = 'esprit',
		**kwargs #do not end with a comma
	):
		#ensure avg alpha
		if avg_alpha is None: avg_alpha = 2.0/specest_rate
                #ensure analog alpha
                if persist_alpha is None: 
                  actual_specest_rate=float(sample_rate/pspectrum_len)/float(max(1,int(float((sample_rate/pspectrum_len)/specest_rate))))
                  #print "requested_specest_rate ",specest_rate
                  #print "actual_specest_rate    ",actual_specest_rate
                  analog_cutoff_freq=0.5 # Hertz
                  #calculate alpha from wanted cutoff freq
                  persist_alpha = 1.0 - math.exp(-2.0*math.pi*analog_cutoff_freq/actual_specest_rate)
                  
		#init
		gr.hier_block2.__init__(
			self,
			"spectrum_sink",
			gr.io_signature(1, 1, self._item_size),
			gr.io_signature(0, 0, 0),
		)
		#blocks
		fft = self._specest_chain(
			sample_rate=sample_rate,
			pspectrum_len=pspectrum_len,
			frame_rate=specest_rate,
			ref_scale=ref_scale,
			avg_alpha=avg_alpha,
			average=average,
            n = n,
            m = m,
            nsamples = nsamples,
            estimator = estimator
		)
		msgq = gr.msg_queue(2)
		sink = gr.message_sink(gr.sizeof_float*pspectrum_len, msgq, True)

		#controller
		self.controller = pubsub()
		self.controller.subscribe(AVERAGE_KEY, fft.set_average)
		self.controller.publish(AVERAGE_KEY, fft.average)
		self.controller.subscribe(AVG_ALPHA_KEY, fft.set_avg_alpha)
		self.controller.publish(AVG_ALPHA_KEY, fft.avg_alpha)
		self.controller.subscribe(SAMPLE_RATE_KEY, fft.set_sample_rate)
		self.controller.publish(SAMPLE_RATE_KEY, fft.sample_rate)
		#start input watcher
		common.input_watcher(msgq, self.controller, MSG_KEY)
		#create window
		self.win = specest_window.specest_window(
			parent=parent,
			controller=self.controller,
			size=size,
			title=title,
			real=self._real,
			spectrum_len=pspectrum_len,
			baseband_freq=baseband_freq,
			sample_rate_key=SAMPLE_RATE_KEY,
			y_per_div=y_per_div,
			y_divs=y_divs,
			ref_level=ref_level,
			average_key=AVERAGE_KEY,
			avg_alpha_key=AVG_ALPHA_KEY,
			peak_hold=peak_hold,
			msg_key=MSG_KEY,
            use_persistence=use_persistence,
            persist_alpha=persist_alpha,
		)
		common.register_access_methods(self, self.win)
		setattr(self.win, 'set_baseband_freq', getattr(self, 'set_baseband_freq')) #BACKWARDS
		setattr(self.win, 'set_peak_hold', getattr(self, 'set_peak_hold')) #BACKWARDS
		#connect
		self.wxgui_connect(self, fft, sink)
Ejemplo n.º 51
0
    def __init__(
            self,
            sample_rate,
            ber_threshold=0,  # Above which to do search
            ber_smoothing=0,  # Alpha of BER smoother (0.01)
            ber_duration=0,  # Length before trying next combo
            ber_sample_decimation=1,
            settling_period=0,
            pre_lock_duration=0,
            #ber_sample_skip=0
            **kwargs):

        use_throttle = False
        base_duration = 1024
        if sample_rate > 0:
            use_throttle = True
            base_duration *= 4  # Has to be high enough for block-delay

        if ber_threshold == 0:
            ber_threshold = 512 * 4
        if ber_smoothing == 0:
            ber_smoothing = 0.01
        if ber_duration == 0:
            ber_duration = base_duration * 2  # 1000ms
        if settling_period == 0:
            settling_period = base_duration * 1  # 500ms
        if pre_lock_duration == 0:
            pre_lock_duration = base_duration * 2  #1000ms

        print "Creating Auto-FEC:"
        print "\tsample_rate:\t\t", sample_rate
        print "\tber_threshold:\t\t", ber_threshold
        print "\tber_smoothing:\t\t", ber_smoothing
        print "\tber_duration:\t\t", ber_duration
        print "\tber_sample_decimation:\t", ber_sample_decimation
        print "\tsettling_period:\t", settling_period
        print "\tpre_lock_duration:\t", pre_lock_duration
        print ""

        self.sample_rate = sample_rate
        self.ber_threshold = ber_threshold
        #self.ber_smoothing = ber_smoothing
        self.ber_duration = ber_duration
        self.settling_period = settling_period
        self.pre_lock_duration = pre_lock_duration
        #self.ber_sample_skip = ber_sample_skip

        self.data_lock = threading.Lock()

        gr.hier_block2.__init__(
            self,
            "auto_fec",
            gr.io_signature(
                1, 1,
                gr.sizeof_gr_complex),  # Post MPSK-receiver complex input
            gr.io_signature3(
                3, 3, gr.sizeof_char, gr.sizeof_float,
                gr.sizeof_float))  # Decoded packed bytes, BER metric, lock

        self.input_watcher = auto_fec_input_watcher(self)
        default_xform = self.input_watcher.xform_lock

        self.gr_conjugate_cc_0 = gr.conjugate_cc()
        self.connect((self, 0), (self.gr_conjugate_cc_0, 0))  # Input

        self.blks2_selector_0 = grc_blks2.selector(
            item_size=gr.sizeof_gr_complex * 1,
            num_inputs=2,
            num_outputs=1,
            input_index=default_xform.get_conjugation_index(),
            output_index=0,
        )
        self.connect((self.gr_conjugate_cc_0, 0), (self.blks2_selector_0, 0))
        self.connect((self, 0), (self.blks2_selector_0, 1))  # Input

        self.gr_multiply_const_vxx_3 = gr.multiply_const_vcc(
            (0.707 * (1 + 1j), ))
        self.connect((self.blks2_selector_0, 0),
                     (self.gr_multiply_const_vxx_3, 0))

        self.gr_multiply_const_vxx_2 = gr.multiply_const_vcc(
            (default_xform.get_rotation(), ))  # phase_mult
        self.connect((self.gr_multiply_const_vxx_3, 0),
                     (self.gr_multiply_const_vxx_2, 0))

        self.gr_complex_to_float_0_0 = gr.complex_to_float(1)
        self.connect((self.gr_multiply_const_vxx_2, 0),
                     (self.gr_complex_to_float_0_0, 0))

        self.gr_interleave_1 = gr.interleave(gr.sizeof_float * 1)
        self.connect((self.gr_complex_to_float_0_0, 1),
                     (self.gr_interleave_1, 1))
        self.connect((self.gr_complex_to_float_0_0, 0),
                     (self.gr_interleave_1, 0))

        self.gr_multiply_const_vxx_0 = gr.multiply_const_vff((1, ))  # invert
        self.connect((self.gr_interleave_1, 0),
                     (self.gr_multiply_const_vxx_0, 0))

        self.baz_delay_2 = baz.delay(
            gr.sizeof_float * 1,
            default_xform.get_puncture_delay())  # delay_puncture
        self.connect((self.gr_multiply_const_vxx_0, 0), (self.baz_delay_2, 0))

        self.depuncture_ff_0 = baz.depuncture_ff(
            (_puncture_matrices[self.input_watcher.puncture_matrix][1]
             ))  # puncture_matrix
        self.connect((self.baz_delay_2, 0), (self.depuncture_ff_0, 0))

        self.baz_delay_1 = baz.delay(
            gr.sizeof_float * 1,
            default_xform.get_viterbi_delay())  # delay_viterbi
        self.connect((self.depuncture_ff_0, 0), (self.baz_delay_1, 0))

        self.swap_ff_0 = baz.swap_ff(
            default_xform.get_viterbi_swap())  # swap_viterbi
        self.connect((self.baz_delay_1, 0), (self.swap_ff_0, 0))

        self.gr_decode_ccsds_27_fb_0 = gr.decode_ccsds_27_fb()

        if use_throttle:
            print "==> Using throttle at sample rate:", self.sample_rate
            self.gr_throttle_0 = gr.throttle(gr.sizeof_float, self.sample_rate)
            self.connect((self.swap_ff_0, 0), (self.gr_throttle_0, 0))
            self.connect((self.gr_throttle_0, 0),
                         (self.gr_decode_ccsds_27_fb_0, 0))
        else:
            self.connect((self.swap_ff_0, 0),
                         (self.gr_decode_ccsds_27_fb_0, 0))

        self.connect((self.gr_decode_ccsds_27_fb_0, 0),
                     (self, 0))  # Output bytes

        self.gr_add_const_vxx_1 = gr.add_const_vff((-4096, ))
        self.connect((self.gr_decode_ccsds_27_fb_0, 1),
                     (self.gr_add_const_vxx_1, 0))

        self.gr_multiply_const_vxx_1 = gr.multiply_const_vff((-1, ))
        self.connect((self.gr_add_const_vxx_1, 0),
                     (self.gr_multiply_const_vxx_1, 0))
        self.connect((self.gr_multiply_const_vxx_1, 0),
                     (self, 1))  # Output BER

        self.gr_single_pole_iir_filter_xx_0 = gr.single_pole_iir_filter_ff(
            ber_smoothing, 1)
        self.connect((self.gr_multiply_const_vxx_1, 0),
                     (self.gr_single_pole_iir_filter_xx_0, 0))

        self.gr_keep_one_in_n_0 = blocks.keep_one_in_n(gr.sizeof_float,
                                                       ber_sample_decimation)
        self.connect((self.gr_single_pole_iir_filter_xx_0, 0),
                     (self.gr_keep_one_in_n_0, 0))

        self.const_source_x_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0,
                                                0)  # Last param is const value
        if use_throttle:
            lock_throttle_rate = self.sample_rate // 16
            print "==> Using lock throttle rate:", lock_throttle_rate
            self.gr_throttle_1 = gr.throttle(gr.sizeof_float,
                                             lock_throttle_rate)
            self.connect((self.const_source_x_0, 0), (self.gr_throttle_1, 0))
            self.connect((self.gr_throttle_1, 0), (self, 2))
        else:
            self.connect((self.const_source_x_0, 0), (self, 2))

        self.msg_q = gr.msg_queue(
            2 * 256
        )  # message queue that holds at most 2 messages, increase to speed up process
        self.msg_sink = gr.message_sink(
            gr.sizeof_float, self.msg_q,
            dont_block=0)  # Block to speed up process
        self.connect((self.gr_keep_one_in_n_0, 0), self.msg_sink)

        self.input_watcher.start()
 def __init__(
         self,
         parent,
         baseband_freq=0,
         ref_level=50,
         sample_rate=1,
         fft_size=512,
         fft_rate=waterfall_window.DEFAULT_FRAME_RATE,
         average=False,
         avg_alpha=None,
         title='',
         size=waterfall_window.DEFAULT_WIN_SIZE,
         ref_scale=2.0,
         dynamic_range=80,
         num_lines=256,
         win=None,
         **kwargs  #do not end with a comma
 ):
     #ensure avg alpha
     if avg_alpha is None: avg_alpha = 2.0 / fft_rate
     #init
     gr.hier_block2.__init__(
         self,
         "waterfall_sink",
         gr.io_signature(1, 1, self._item_size),
         gr.io_signature(0, 0, 0),
     )
     #blocks
     fft = self._fft_chain(
         sample_rate=sample_rate,
         fft_size=fft_size,
         frame_rate=fft_rate,
         ref_scale=ref_scale,
         avg_alpha=avg_alpha,
         average=average,
         win=win,
     )
     msgq = gr.msg_queue(2)
     sink = gr.message_sink(gr.sizeof_float * fft_size, msgq, True)
     #controller
     self.controller = pubsub()
     self.controller.subscribe(AVERAGE_KEY, fft.set_average)
     self.controller.publish(AVERAGE_KEY, fft.average)
     self.controller.subscribe(AVG_ALPHA_KEY, fft.set_avg_alpha)
     self.controller.publish(AVG_ALPHA_KEY, fft.avg_alpha)
     self.controller.subscribe(SAMPLE_RATE_KEY, fft.set_sample_rate)
     self.controller.publish(SAMPLE_RATE_KEY, fft.sample_rate)
     self.controller.subscribe(DECIMATION_KEY, fft.set_decimation)
     self.controller.publish(DECIMATION_KEY, fft.decimation)
     self.controller.subscribe(FRAME_RATE_KEY, fft.set_vec_rate)
     self.controller.publish(FRAME_RATE_KEY, fft.frame_rate)
     #start input watcher
     common.input_watcher(msgq, self.controller, MSG_KEY)
     #create window
     self.win = waterfall_window.waterfall_window(
         parent=parent,
         controller=self.controller,
         size=size,
         title=title,
         real=self._real,
         fft_size=fft_size,
         num_lines=num_lines,
         baseband_freq=baseband_freq,
         decimation_key=DECIMATION_KEY,
         sample_rate_key=SAMPLE_RATE_KEY,
         frame_rate_key=FRAME_RATE_KEY,
         dynamic_range=dynamic_range,
         ref_level=ref_level,
         average_key=AVERAGE_KEY,
         avg_alpha_key=AVG_ALPHA_KEY,
         msg_key=MSG_KEY,
     )
     common.register_access_methods(self, self.win)
     setattr(self.win, 'set_baseband_freq',
             getattr(self, 'set_baseband_freq'))  #BACKWARDS
     #connect
     self.wxgui_connect(self, fft, sink)
Ejemplo n.º 53
0
	def __init__(
		self,
		baseband_freq =0,
		ref_scale = 2.0, 
		y_per_div = 10,
		y_divs = 8,
		ref_level = 50,
		sample_rate = 1,
		fft_size = 512,
		fft_rate = 20,
		average = False,
		avg_alpha = None,
		title = '',
		size = (600, 300),
		peak_hold = False,
		win = None,
		use_persistence = False,
		persist_alpha = None,
		**kwargs
	):
		#ensure avg alpha
		if avg_alpha is None: 
			avg_alpha = 2.0 / fft_rate
		
		#ensure analog alpha
		if persist_alpha is None:
			actual_fft_rate = float(sample_rate / fft_size) / float(max(1, int(float((sample_rate / fft_size) / fft_rate))))
			#print "requested_fft_rate ",fft_rate
			#print "actual_fft_rate    ",actual_fft_rate
			analog_cutoff_freq = 0.5 # Hertz
			#calculate alpha from wanted cutoff freq
			persist_alpha = 1.0 - math.exp(-2.0*math.pi*analog_cutoff_freq/actual_fft_rate)

		#init
		gr.hier_block2.__init__(
			self,
			"zmq_fft_sink",
			gr.io_signature(1, 1, gr.sizeof_gr_complex),
			gr.io_signature(0, 0, 0),
		)

		#blocks
		fft_0 = fft.logpwrfft_c(
			sample_rate = sample_rate,
			fft_size = fft_size,
			frame_rate = fft_rate,
			ref_scale = ref_scale,
			avg_alpha = avg_alpha,
			average = average,
			win = win,
		)

		msgq = gr.msg_queue(2)
		sink = gr.message_sink(gr.sizeof_float*fft_size, msgq, True)

		#controller
		#self.controller = pubsub()
		#self.controller.subscribe(AVERAGE_KEY, fft_0.set_average)
		#self.controller.publish(AVERAGE_KEY, fft_0.average)
		#self.controller.subscribe(AVG_ALPHA_KEY, fft_0.set_avg_alpha)
		#self.controller.publish(AVG_ALPHA_KEY, fft_0.avg_alpha)
		#self.controller.subscribe(SAMPLE_RATE_KEY, fft_0.set_sample_rate)
		#self.controller.publish(SAMPLE_RATE_KEY, fft_0.sample_rate)
		#start input watcher
		input_watcher(msgq)

		#connect
		self.connect(self, fft_0, sink)
Ejemplo n.º 54
0
    def __init__(self, options):
        gr.top_block.__init__(self)

        if options.rx_freq is not None:
            u = uhd_receiver(options.args, options.bandwidth, options.rx_freq,
                             options.rx_gain, options.spec, options.antenna,
                             options.verbose)
        elif options.infile is not None:
            u = gr.file_source(gr.sizeof_gr_complex, options.infile)
        else:
            import sys
            sys.stderr.write("--freq or --infile must be specified\n")
            raise SystemExit

        self.scope = None

        if options.outfile is not None:
            rx = gr.file_sink(gr.sizeof_gr_complex, options.outfile)
        else:
            rx = ofdm_rxtx.RX(options)
            data_tones = rx.params.data_tones
            if options.rxdata is not None:
                if options.rxdata == '.':
                    import scope
                    # scope it out
                    rxs = gr.vector_to_stream(gr.sizeof_gr_complex, data_tones)
                    self.connect(rx, rxs)
                    self.scope = scope.scope(self,
                                             rxs,
                                             'Frame SNR',
                                             isComplex=True)
                else:
                    if options.char > 0:
                        # rail and scale
                        self.connect(
                            rx,
                            gr.vector_to_stream(gr.sizeof_float,
                                                data_tones * 2),
                            gr.multiply_const_ff(128.0 * (2**0.5) /
                                                 options.char),
                            gr.rail_ff(-128.0, 127.0), gr.float_to_char(),
                            gr.file_sink(gr.sizeof_char, options.rxdata))
                    else:
                        self.connect(
                            rx,
                            gr.file_sink(data_tones * gr.sizeof_gr_complex,
                                         options.rxdata))

            if options.snrdata is not None:
                # select one of the snr modes
                snr = ofdm_rxtx.SNR(rx.params.data_tones,
                                    options.size,
                                    mode=options.snrmode)
                if options.char > 0:
                    # NOTE: we use repeat, assuming the file is long enough or properly aligned
                    data = gr.stream_to_vector(gr.sizeof_float, data_tones * 2)
                    self.connect(
                        gr.file_source(gr.sizeof_char,
                                       options.txdata,
                                       repeat=True), gr.char_to_float(),
                        gr.multiply_const_ff(options.char * (2**-0.5) / 128.0),
                        data)
                else:
                    data = ofdm_rxtx.make_data(rx.params.data_tones,
                                               options.size, options.txdata)
                self.connect(rx, (snr, 0))
                self.connect(data, (snr, 1))
                if options.snrdata == '-':
                    # print it out
                    msgq = gr.msg_queue(16)
                    self.connect(snr,
                                 gr.message_sink(gr.sizeof_float, msgq, True))
                    self.watcher = ofdm_rxtx.queue_watcher(msgq)
                elif options.snrdata == '.':
                    import scope
                    # scope it out
                    self.scope = scope.scope(self, snr, 'Frame SNR')
                else:
                    self.connect(
                        snr, gr.file_sink(gr.sizeof_float, options.snrdata))
            else:
                pass
                #self.connect(rx, gr.null_sink(symbol_size)) # XXX do we still need this?

        self.connect(u, rx)