コード例 #1
0
    def __init__(self, rx_callback):
        gr.hier_block2.__init__(self, "receive_path",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(0, 0, 0))

        self.callback = rx_callback

        self.demod = digital.gfsk_demod(
            samples_per_symbol=4,
            sensitivity=1.0,
            gain_mu=0.175,
            mu=0.5,
            omega_relative_limit=0.005,
            freq_error=0.0,
            verbose=False,
            log=False,
        )

        self.packetizer = mac_packetizer()
        self.rcvd_pktq = gr.msg_queue()
        self.message_sink = blocks.message_sink(gr.sizeof_char, self.rcvd_pktq,
                                                False)
        self.queue_watcher_thread = _queue_watcher_thread(
            self.rcvd_pktq, self.callback)
        self.connect(self, self.demod, self.packetizer, self.message_sink)
コード例 #2
0
ファイル: __init__.py プロジェクト: tashby/shinysdr
    def __init__(self, mode, input_rate=0, context=None):
        assert input_rate > 0
        self.__input_rate = input_rate
        gr.hier_block2.__init__(
            self, 'RTTY demodulator',
            gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
            gr.io_signature(1, 1, gr.sizeof_float * 1))

        channel_filter = self.__make_channel_filter()

        self.__text = u''
        self.__char_queue = gr.msg_queue(limit=100)
        self.__char_sink = blocks.message_sink(gr.sizeof_char,
                                               self.__char_queue, True)

        self.connect(self, channel_filter, self.__make_demodulator(),
                     self.__char_sink)

        self.connect(
            channel_filter, self.__make_audio_filter(),
            blocks.rotator_cc(
                rotator_inc(self.__demod_rate, 2000 + self.__spacing / 2)),
            blocks.complex_to_real(vlen=1),
            analog.agc2_ff(reference=dB(-10),
                           attack_rate=8e-1,
                           decay_rate=8e-1), self)
コード例 #3
0
ファイル: ascii_plot.py プロジェクト: antiface/gr-ofdm_tools
	def __init__(self, fft_len, sample_rate, tune_freq, average, rate, length, height):
		gr.hier_block2.__init__(self,
			"ascii plot",
			gr.io_signature(1, 1, gr.sizeof_gr_complex),
			gr.io_signature(0,0,0))
		self.fft_len = fft_len
		self.sample_rate = sample_rate
		self.average = average
		self.tune_freq = tune_freq
		self.rate = rate
		self.length = length
		self.height = height

		self.msgq = gr.msg_queue(2)

		#######BLOCKS#####
		self.s2p = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_len)
		self.one_in_n = blocks.keep_one_in_n(gr.sizeof_gr_complex * self.fft_len,
		 max(1, int(self.sample_rate/self.fft_len/self.rate)))

		mywindow = window.blackmanharris(self.fft_len)
		self.fft = fft.fft_vcc(self.fft_len, True, (), True)

		self.c2mag2 = blocks.complex_to_mag_squared(self.fft_len)
		self.avg = grfilter.single_pole_iir_filter_ff(1.0, self.fft_len)
		self.log = blocks.nlog10_ff(10, self.fft_len,
								-10*math.log10(self.fft_len)                # Adjust for number of bins
								-10*math.log10(self.sample_rate))                # Adjust for sample rate

		self.sink = blocks.message_sink(gr.sizeof_float * self.fft_len, self.msgq, True)
		#####CONNECTIONS####
		self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2mag2, self.avg, self.log, self.sink)

		self._main = main_thread(self.msgq, self.fft_len, self.sample_rate, self.tune_freq, self.length, self.height)
コード例 #4
0
ファイル: __init__.py プロジェクト: bitglue/shinysdr
    def __init__(self, mode, input_rate=0, context=None):
        assert input_rate > 0
        self.__input_rate = input_rate
        gr.hier_block2.__init__(
            self, 'RTTY demodulator',
            gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
            gr.io_signature(1, 1, gr.sizeof_float * 1))
        
        channel_filter = self.__make_channel_filter()

        self.__text = u''
        self.__char_queue = gr.msg_queue(limit=100)
        self.__char_sink = blocks.message_sink(gr.sizeof_char, self.__char_queue, True)

        self.connect(
            self,
            channel_filter,
            self.__make_demodulator(),
            self.__char_sink)
        
        self.connect(
            channel_filter,
            self.__make_audio_filter(),
            blocks.rotator_cc(rotator_inc(self.__demod_rate, 2000 + self.__spacing / 2)),
            blocks.complex_to_real(vlen=1),
            analog.agc2_ff(
                reference=dB(-10),
                attack_rate=8e-1,
                decay_rate=8e-1),
            self)
コード例 #5
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 = blocks.stream_to_vector(gr.sizeof_float, self.fft_size)
        self.one_in_n = blocks.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 = fft.fft_vfc(self.fft_size, True, mywindow)
        self.c2mag = blocks.complex_to_mag(self.fft_size)
        self.avg = filter.single_pole_iir_filter_ff(1.0, self.fft_size)
        self.log = blocks.nlog10_ff(20, self.fft_size, -20*math.log10(self.fft_size))
        self.sink = blocks.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)
コード例 #6
0
    def __init__(self, fft_len, rate, sample_rate):
        gr.hier_block2.__init__(self, "psd_logger",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(0, 0, 0))
        self.fft_len = fft_len
        self.rate = rate
        self.sample_rate = sample_rate
        self.msgq = gr.msg_queue(2)
        self.log_file = open(
            '/tmp/psd_log' + '-' + time.strftime("%y%m%d") + '-' +
            time.strftime("%H%M%S"), 'w')

        self.s2p = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_len)
        self.one_in_n = blocks.keep_one_in_n(
            gr.sizeof_gr_complex * self.fft_len,
            max(1, int(self.sample_rate / self.fft_len / self.rate)))

        mywindow = window.blackmanharris(self.fft_len)
        self.fft = fft.fft_vcc(self.fft_len, True, mywindow)
        power = 0
        for tap in mywindow:
            power += tap * tap

        self.c2mag = blocks.complex_to_mag(self.fft_len)

        self.sink = blocks.message_sink(gr.sizeof_float * self.fft_len,
                                        self.msgq, True)
        self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2mag,
                     self.sink)

        self._watcher = _queue_watcher(self.msgq, self.log_file)
コード例 #7
0
ファイル: packet.py プロジェクト: phoorichet/gnuradio
 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 = blocks.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)
コード例 #8
0
ファイル: wifiscan.py プロジェクト: ThomasHabets/wifispace
    def __init__(self, frequency):
        gr.top_block.__init__(self)

        sample_rate = 32000
        ampl = 0.1

        # Source.
        addr = ''
        stream_args = uhd.stream_args('fc32')
        self.src = uhd.usrp_source(addr, stream_args)
        #src.set_subdev_spec(options.spec, 0)
        self.src.set_samp_rate(32000)
        self.src.set_center_freq(frequency)
        self.src.set_gain(30)
        self.src.set_antenna('TX/RX')

        # SNR
        snr = digital.mpsk_snr_est_cc(type=0)
        snr.set_alpha(0.001)
        snr.set_tag_nsample(1000000)

        rms = blocks.rms_cf()
        rms.set_alpha(0.0001)

        self.msgq = gr.msg_queue(16)

        sink = blocks.message_sink(4, self.msgq, 'bleh')
        self.connect(self.src, snr, rms, sink)
コード例 #9
0
    def __init__(self, parent,
                 y_per_div=1, y_divs=8, ref_level=50, x_vals=numpy.arange(10), ninputs=1,
                 size=default_curvesink_size,
                 title='', x_units='', y_units='', legends=[], **kwargs):
        self.x_vals=x_vals;
        self.legends=legends
        gr.hier_block2.__init__(self, "curve_sink_f",
                                gr.io_signature(ninputs, ninputs, gr.sizeof_float),
                                gr.io_signature(0,0,0))

        curve_sink_base.__init__(self, input_is_real=True,
                                 y_per_div=y_per_div, y_divs=y_divs, ref_level=ref_level,
                                 title=title, x_units=x_units, y_units=y_units)
                               
        self.s2p = [];
        
        for i in range(0, ninputs):
            self.s2p.append(blocks.stream_to_vector(gr.sizeof_float, len(x_vals)))
        #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)))
        self.interleave = blocks.interleave(gr.sizeof_float * len(x_vals));
        
        self.s2v = blocks.stream_to_vector(gr.sizeof_float * len(x_vals), ninputs);
        
        self.sink = blocks.message_sink(gr.sizeof_float * len(x_vals) * ninputs, self.msgq, True);
        
        for i in range(0, ninputs):
            self.connect((self, i), self.s2p[i], (self.interleave, i))
        self.connect(self.interleave, self.s2v, self.sink);

        self.win=curve_window(self, parent, size=size, x_units=self.x_units, y_units=self.y_units, ninputs=ninputs)
コード例 #10
0
ファイル: psd_logger.py プロジェクト: antiface/gr-ofdm_tools
	def __init__(self, fft_len, rate, sample_rate):
		gr.hier_block2.__init__(self,
			"psd_logger",
			gr.io_signature(1, 1, gr.sizeof_gr_complex),
			gr.io_signature(0,0,0))
		self.fft_len = fft_len
		self.rate = rate
		self.sample_rate = sample_rate
		self.msgq = gr.msg_queue(2)
		self.log_file = open('/tmp/psd_log'+'-'+ time.strftime("%y%m%d") + '-' + time.strftime("%H%M%S"),'w')

		self.s2p = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_len)
		self.one_in_n = blocks.keep_one_in_n(gr.sizeof_gr_complex * self.fft_len,
		 max(1, int(self.sample_rate/self.fft_len/self.rate)))

		mywindow = window.blackmanharris(self.fft_len)
		self.fft = fft.fft_vcc(self.fft_len, True, mywindow)
		power = 0
		for tap in mywindow:
			power += tap*tap

		self.c2mag = blocks.complex_to_mag(self.fft_len)

		self.sink = blocks.message_sink(gr.sizeof_float * self.fft_len, self.msgq, True)
		self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2mag, self.sink)

		self._watcher = _queue_watcher(self.msgq, self.log_file)
コード例 #11
0
ファイル: wifiscan.py プロジェクト: salewski/wifispace
    def __init__(self, frequency):
        gr.top_block.__init__(self)

        sample_rate = 32000
        ampl = 0.1

        # Source.
        addr = ''
        stream_args = uhd.stream_args('fc32')
        self.src = uhd.usrp_source(addr, stream_args)
        #src.set_subdev_spec(options.spec, 0)
        self.src.set_samp_rate(32000)
        self.src.set_center_freq(frequency)
        self.src.set_gain(30)
        self.src.set_antenna('TX/RX')

        # SNR
        snr = digital.mpsk_snr_est_cc(type=0)
        snr.set_alpha(0.001)
        snr.set_tag_nsample(1000000)

        rms = blocks.rms_cf()
        rms.set_alpha(0.0001)

        self.msgq = gr.msg_queue(16)

        sink = blocks.message_sink(4, self.msgq, 'bleh')
        self.connect(self.src, snr, rms, sink)
コード例 #12
0
  def __init__(self, options,callback=None):
    p = ofdm_params(options)
    nsym = options.size+len(p.preambles)

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

    ################################################################################
    #                        Block Definition and Connection
    ################################################################################
    # to the synchronization algorithm
    #sync = ofdm_sync(p.fft_length, p.cp_length, p.cross_corr_preambles, 'RAW', options.log)
    sync = ofdm_sync_fir(p.fft_length, p.cp_length, p.cross_corr_preambles, options.bandwidth, 'RAW', options.log)
    sampler = raw.ofdm_sampler(p.fft_length, p.fft_length+p.cp_length, long(options.bandwidth), timeout=nsym, debug=False)
    self.connect(self, sync)
    self.params = p
    self.size = options.size
    self.callback = callback
    self._rcvd_pktq = gr.msg_queue()
    message_sink = blocks.message_sink(gr.sizeof_gr_complex*p.fft_length,self._rcvd_pktq,True)
    self.connect((sync,0), (sampler,0))
    self.connect((sync,1), (sampler,2))
    self.connect((sync,2), (sampler,1)) 
    self.connect(sampler,message_sink)
    if options.log:
      self.connect((sync,0),
                   blocks.file_sink(gr.sizeof_gr_complex, 'logs/rx-sync_0.dat'))  #signal output 
      self.connect((sync,1),
                   blocks.file_sink(gr.sizeof_float, 'logs/rx-sync_1.datf'))  #cfo output
      self.connect((sync,2),
                   blocks.file_sink(gr.sizeof_char, 'logs/rx-sync_2.datc'))  #peak out
      self.connect(sampler,blocks.file_sink(gr.sizeof_gr_complex*p.fft_length, 'sampler.dat'))  #LTS output 
    self._watcher = _queue_watcher_thread(self._rcvd_pktq, self.callback)
コード例 #13
0
ファイル: ascii_plot.py プロジェクト: ortalby/gr-ofdm_tools
    def __init__(self, fft_len, sample_rate, tune_freq, average, rate, width,
                 height):
        gr.hier_block2.__init__(self, "ascii plot",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(0, 0, 0))
        self.fft_len = fft_len
        self.sample_rate = sample_rate
        self.average = average
        self.tune_freq = tune_freq
        self.rate = rate
        if width == 0 and height == 0:
            rows, columns = os.popen('stty size', 'r').read().split()
            self.height = int(rows) - 5
            self.width = int(columns) / 2 - 10
        else:
            self.height = height
            self.width = width

        self.msgq = gr.msg_queue(2)

        #######BLOCKS#####
        self.s2p = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_len)
        self.one_in_n = blocks.keep_one_in_n(
            gr.sizeof_gr_complex * self.fft_len,
            max(1, int(self.sample_rate / self.fft_len / self.rate)))

        mywindow = window.blackmanharris(self.fft_len)
        self.fft = fft.fft_vcc(self.fft_len, True, (), True)

        self.c2mag2 = blocks.complex_to_mag_squared(self.fft_len)
        self.avg = grfilter.single_pole_iir_filter_ff(self.average,
                                                      self.fft_len)
        self.log = blocks.nlog10_ff(
            10,
            self.fft_len,
            -10 * math.log10(self.fft_len)  # Adjust for number of bins
            - 10 * math.log10(self.sample_rate))  # Adjust for sample rate

        self.sink = blocks.message_sink(gr.sizeof_float * self.fft_len,
                                        self.msgq, True)

        #register message out to other blocks
        self.message_port_register_hier_out("pkt_out")
        #packet generator
        self.packet_generator = of.chat_blocks.chat_sender()

        #####CONNECTIONS####
        self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2mag2,
                     self.avg, self.log, self.sink)

        #MSG output
        self.msg_connect(self.packet_generator, "out", self, "pkt_out")

        ####THREADS####
        self._ascii_plotter = ascii_plotter(self.width, self.height,
                                            self.tune_freq, self.sample_rate,
                                            self.fft_len)

        self._main = main_thread(self.msgq, self._ascii_plotter,
                                 self.packet_generator)
コード例 #14
0
ファイル: audiomux.py プロジェクト: Tubbz-alt/shinysdr-morgue
 def __init__(self, channels, queue):
     gr.hier_block2.__init__(
         self,
         type(self).__name__,
         gr.io_signature(1, 1, gr.sizeof_float * channels),
         gr.io_signature(0, 0, 0))
     sink = blocks.message_sink(gr.sizeof_float * channels, queue, True)
     self.connect(self, sink)
コード例 #15
0
ファイル: osmotcp.py プロジェクト: roseengineering/osmotcp
 def __init__(self, options):
     item_size = gr.sizeof_gr_complex
     gr.hier_block2.__init__(self, "queue_sink",
                             gr.io_signature(1, 1, item_size),
                             gr.io_signature(0, 0, 0))
     self.qu = gr.msg_queue(0)
     message_sink = blocks.message_sink(item_size, self.qu, False)
     self.connect(self, message_sink)
コード例 #16
0
 def subscribe(self, queue):
     assert queue not in self.__subscriptions
     sink = blocks.message_sink(self.__itemsize, queue, True)
     self.__subscriptions[queue] = sink
     try:
         self.__context.lock()
         self.connect(self, sink)
     finally:
         self.__context.unlock()
コード例 #17
0
ファイル: blocks.py プロジェクト: amberadams/shinysdr
	def subscribe(self, queue):
		assert queue not in self.__subscriptions
		sink = blocks.message_sink(self.__itemsize, queue, True)
		self.__subscriptions[queue] = sink
		try:
			self.__context.lock()
			self.connect(self, sink)
		finally:
			self.__context.unlock()
コード例 #18
0
	def __init__(self, N, sample_rate, search_bw = 1, threshold = 10, threshold_mtm = 0.2,
	 tune_freq = 0, alpha_avg = 1, test_duration = 1, period = 3600, stats = False, output = False, rate = 10,
	  subject_channels = [], valve_callback = None):

		gr.hier_block2.__init__(self,
			"coherence_detector",
			gr.io_signature3(3, 3, gr.sizeof_float*N, gr.sizeof_float*N, gr.sizeof_float*N),
			gr.io_signature(0, 0, 0))
		self.N = N #lenght of the fft for spectral analysis
		self.sample_rate = sample_rate 
		self.search_bw = search_bw #search bandwidth within each channel
		self.threshold = threshold #threshold comparison
		self.threshold_mtm = threshold_mtm
		self.tune_freq = tune_freq #center frequency
		self.alpha_avg = alpha_avg #averaging factor for noise level between consecutive measurements
		self.output = output
		self.subject_channels = subject_channels
		self.subject_channels_outcome = [0.1]*len(subject_channels)
		self.rate = rate
		self.valve_callback = valve_callback

		#data queue to share data between theads
		self.q0 = Queue.Queue()

		#gnuradio msg queues
		self.msgq = gr.msg_queue(2)
		self.msgq1 = gr.msg_queue(2)
		self.msgq2 = gr.msg_queue(2)

		#######BLOCKS#####
		self.sink = blocks.message_sink(gr.sizeof_float * self.N, self.msgq, True)
		self.sink1 = blocks.message_sink(gr.sizeof_float * self.N, self.msgq1, True)
		self.sink2 = blocks.message_sink(gr.sizeof_float * self.N, self.msgq2, True)

		#####CONNECTIONS####
		self.connect((self,0), self.sink)
		self.connect((self,1), self.sink1)
		self.connect((self,2), self.sink2)

		self._watcher = watcher(self.msgq, self.msgq1, self.msgq2, self.tune_freq, self.threshold, self.threshold_mtm, self.search_bw, self.N,
		 self.sample_rate, self.q0, self.subject_channels, self.set_subject_channels_outcome, self.rate, self.valve_callback)
		if self.output != False:
			self._output_data = output_data(self.q0, self.sample_rate, self.tune_freq, self.N,
				 self.search_bw, self.output, self.subject_channels, self.get_subject_channels_outcome)
コード例 #19
0
ファイル: audiomux.py プロジェクト: thefinn93/shinysdr
 def __init__(self, channels, queue):
     gr.hier_block2.__init__(
         self, type(self).__name__,
         gr.io_signature(1, 1, gr.sizeof_float * channels),
         gr.io_signature(0, 0, 0))
     sink = blocks.message_sink(
         gr.sizeof_float * channels,
         queue,
         True)
     self.connect(self, sink)
コード例 #20
0
    def __init__(self, freq, ppm, osmosdr_args):
        gr.top_block.__init__(self, "gr_omnicon")

        self.msgq_out = blocks_message_sink_0_msgq_out = gr.msg_queue(0)
        ##################################################
        # Variables
        ##################################################
        self.xlate_bandwidth = xlate_bandwidth = 15.0e3
        self.samp_rate = samp_rate = 1.2e6
        self.xlate_decimation = xlate_decimation = int(samp_rate/(xlate_bandwidth*3.2))
        self.baud_rate = baud_rate = 2400
        self.lowpass_decimation = lowpass_decimation = int((samp_rate/xlate_decimation)/(baud_rate*4))
        self.freq_offset = freq_offset = 250000
        self.sps = sps = (samp_rate/xlate_decimation/lowpass_decimation)/baud_rate
        self.omega_rel_limit = omega_rel_limit = ((2450.0-2400.0)/2400.0)
        self.gain_omega = gain_omega = 0
        self.gain_mu = gain_mu = 0.1
        self.freq_tune = freq_tune = freq-freq_offset

        ##################################################
        # Blocks
        ##################################################
        self.rtlsdr_source_0 = osmosdr.source(args=osmosdr_args)
        self.rtlsdr_source_0.set_sample_rate(samp_rate)
        self.rtlsdr_source_0.set_center_freq(freq_tune, 0)
        self.rtlsdr_source_0.set_freq_corr(ppm, 0)
        self.rtlsdr_source_0.set_dc_offset_mode(0, 0)
        self.rtlsdr_source_0.set_iq_balance_mode(0, 0)
        self.rtlsdr_source_0.set_gain_mode(True, 0)
        self.rtlsdr_source_0.set_gain(42, 0)
        self.rtlsdr_source_0.set_if_gain(10, 0)
        self.rtlsdr_source_0.set_bb_gain(10, 0)
        self.rtlsdr_source_0.set_antenna("", 0)
        self.rtlsdr_source_0.set_bandwidth(0, 0)
          
        self.low_pass_filter_0 = filter.fir_filter_fff(lowpass_decimation, firdes.low_pass(
        	1, samp_rate/xlate_decimation, baud_rate, (baud_rate)/10, firdes.WIN_HAMMING, 6.76))
        self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(xlate_decimation, (firdes.low_pass(1, samp_rate, xlate_bandwidth, xlate_bandwidth/20 )), freq_offset, samp_rate)
        self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_ff(sps, gain_omega, 0.5, gain_mu, omega_rel_limit)
        self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb()
        self.dc_blocker_xx_0 = filter.dc_blocker_ff(500, True)
        self.blocks_message_sink_0 = blocks.message_sink(gr.sizeof_char*1, blocks_message_sink_0_msgq_out, False)
        self.analog_quadrature_demod_cf_0_0_0 = analog.quadrature_demod_cf(1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_quadrature_demod_cf_0_0_0, 0), (self.dc_blocker_xx_0, 0))
        #self.connect((self.blocks_message_sink_0, 'msg'), (self, 0))
        self.connect((self.dc_blocker_xx_0, 0), (self.low_pass_filter_0, 0))
        self.connect((self.digital_binary_slicer_fb_0, 0), (self.blocks_message_sink_0, 0))
        self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.digital_binary_slicer_fb_0, 0))
        self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.analog_quadrature_demod_cf_0_0_0, 0))
        self.connect((self.low_pass_filter_0, 0), (self.digital_clock_recovery_mm_xx_0, 0))
        self.connect((self.rtlsdr_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
コード例 #21
0
    def __init__(self, fft_len, sample_rate, average, rate, max_tu,
                 data_precision):
        gr.hier_block2.__init__(self, "ascii plot",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(0, 0, 0))
        self.fft_len = fft_len
        self.sample_rate = sample_rate
        self.average = average
        self.rate = rate
        self.max_tu = max_tu - 2  #reserve two bytes for segmentation

        self.data_precision = data_precision

        if data_precision:
            print '32bit FFT in use (more bandwidth and precision)'
        else:
            print '8bit FFT in use (less bandwidth and precision)'

        self.msgq = gr.msg_queue(2)

        #######BLOCKS#####
        self.s2p = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_len)
        self.one_in_n = blocks.keep_one_in_n(
            gr.sizeof_gr_complex * self.fft_len,
            max(1, int(self.sample_rate / self.fft_len / self.rate)))

        mywindow = window.blackmanharris(self.fft_len)
        self.fft = fft.fft_vcc(self.fft_len, True, mywindow, True)

        self.c2mag2 = blocks.complex_to_mag_squared(self.fft_len)
        self.avg = grfilter.single_pole_iir_filter_ff(self.average,
                                                      self.fft_len)
        self.log = blocks.nlog10_ff(
            10,
            self.fft_len,
            -10 * math.log10(self.fft_len)  # Adjust for number of bins
            - 10 * math.log10(self.sample_rate))  # Adjust for sample rate

        self.sink = blocks.message_sink(gr.sizeof_float * self.fft_len,
                                        self.msgq, True)

        #register message out to other blocks
        self.message_port_register_hier_out("pdus")

        self._packet_source = packet_source()

        #####CONNECTIONS####
        self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2mag2,
                     self.avg, self.log, self.sink)
        self.msg_connect(self._packet_source, "out", self, "pdus")

        ####THREADS####
        self._main = main_thread(self.msgq, self._packet_source, self.max_tu,
                                 self.fft_len, self.data_precision)
コード例 #22
0
ファイル: curvesink_nongl.py プロジェクト: sqf-ice/fecapi
    def __init__(self,
                 parent,
                 y_per_div=1,
                 y_divs=8,
                 ref_level=50,
                 x_vals=numpy.arange(10),
                 ninputs=1,
                 size=default_curvesink_size,
                 title='',
                 x_units='',
                 y_units='',
                 legends=[],
                 **kwargs):
        self.x_vals = x_vals
        self.legends = legends
        gr.hier_block2.__init__(
            self, "curve_sink_f",
            gr.io_signature(ninputs, ninputs, gr.sizeof_float),
            gr.io_signature(0, 0, 0))

        curve_sink_base.__init__(self,
                                 input_is_real=True,
                                 y_per_div=y_per_div,
                                 y_divs=y_divs,
                                 ref_level=ref_level,
                                 title=title,
                                 x_units=x_units,
                                 y_units=y_units)

        self.s2p = []

        for i in range(0, ninputs):
            self.s2p.append(
                blocks.stream_to_vector(gr.sizeof_float, len(x_vals)))
        #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)))
        self.interleave = blocks.interleave(gr.sizeof_float * len(x_vals))

        self.s2v = blocks.stream_to_vector(gr.sizeof_float * len(x_vals),
                                           ninputs)

        self.sink = blocks.message_sink(
            gr.sizeof_float * len(x_vals) * ninputs, self.msgq, True)

        for i in range(0, ninputs):
            self.connect((self, i), self.s2p[i], (self.interleave, i))
        self.connect(self.interleave, self.s2v, self.sink)

        self.win = curve_window(self,
                                parent,
                                size=size,
                                x_units=self.x_units,
                                y_units=self.y_units,
                                ninputs=ninputs)
コード例 #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 = blocks.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)
コード例 #24
0
ファイル: specest_gui.py プロジェクト: NOY6/gr-specest
 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 = blocks.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)
コード例 #25
0
ファイル: tx_voice.py プロジェクト: bolin-hsu/jelli-gnuradio
    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
        self.sample_rate = sample_rate = 8000
        src = audio.source(sample_rate, audio_input_dev)
        src_scale = blocks.multiply_const_ff(32767)
        f2s = blocks.float_to_short()
        voice_coder = vocoder.gsm_fr_encode_sp()
        self.packets_from_encoder = gr.msg_queue()
        packet_sink = blocks.message_sink(33, self.packets_from_encoder, False)
        self.connect(src, src_scale, f2s, voice_coder, packet_sink)
コード例 #26
0
ファイル: tx_voice.py プロジェクト: Gibran000/gnuradio
    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
        self.sample_rate = sample_rate = 8000
        src = audio.source(sample_rate, audio_input_dev)
        src_scale = blocks.multiply_const_ff(32767)
        f2s = blocks.float_to_short()
        voice_coder = vocoder.gsm_fr_encode_sp()
        self.packets_from_encoder = gr.msg_queue()
        packet_sink = blocks.message_sink(33, self.packets_from_encoder, False)
        self.connect(src, src_scale, f2s, voice_coder, packet_sink)
コード例 #27
0
ファイル: demod_rf.py プロジェクト: rowhit/waveconverter
    def __init__(self, samp_rate_in, samp_rate_out, center_freq, tune_freq,
                 channel_width, transition_width, threshold, iq_filename,
                 dig_out_filename):
        gr.top_block.__init__(self)

        ##################################################
        # Variables
        ##################################################
        self.cutoff_freq = channel_width / 2
        self.firdes_taps = firdes.low_pass(1, samp_rate_in, self.cutoff_freq,
                                           transition_width)

        ##################################################
        # Blocks
        ##################################################
        self.tuning_filter_0 = filter.freq_xlating_fir_filter_ccc(
            int(samp_rate_in / samp_rate_out), (self.firdes_taps),
            tune_freq - center_freq, samp_rate_in)
        self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb()
        self.blocks_file_source_0 = blocks.file_source(
            gr.sizeof_gr_complex * 1, iq_filename, False)
        self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1)
        self.blocks_add_const_vxx_0 = blocks.add_const_vff((-1 * threshold, ))

        # message sink is primary method of getting baseband data into waveconverter
        self.sink_queue = gr.msg_queue()
        self.blocks_message_sink_0 = blocks.message_sink(
            gr.sizeof_char * 1, self.sink_queue, False)

        # if directed, we also dump the baseband data into a file
        if len(dig_out_filename) > 0:
            print "Outputing baseband to waveform to " + dig_out_filename
            self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char * 1,
                                                       dig_out_filename, False)
            self.blocks_file_sink_0.set_unbuffered(False)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_add_const_vxx_0, 0),
                     (self.digital_binary_slicer_fb_0, 0))
        self.connect((self.blocks_complex_to_mag_0, 0),
                     (self.blocks_add_const_vxx_0, 0))
        self.connect((self.blocks_file_source_0, 0), (self.tuning_filter_0, 0))
        self.connect((self.tuning_filter_0, 0),
                     (self.blocks_complex_to_mag_0, 0))

        self.connect((self.digital_binary_slicer_fb_0, 0),
                     (self.blocks_message_sink_0, 0))
        if len(dig_out_filename) > 0:
            self.connect((self.digital_binary_slicer_fb_0, 0),
                         (self.blocks_file_sink_0, 0))
コード例 #28
0
ファイル: top.py プロジェクト: LucaBongiorni/shinysdr
	def add_audio_queue(self, queue, queue_rate):
		# TODO: place limit on maximum requested sample rate
		sink = blocks.message_sink(
			gr.sizeof_float * num_audio_channels,
			queue,
			True)
		interleaver = blocks.streams_to_vector(gr.sizeof_float, num_audio_channels)
		# TODO: bundle the interleaver and sink in a hier block so it doesn't have to be reconnected
		self.audio_queue_sinks[queue] = (queue_rate, interleaver, sink)
		
		self.__needs_reconnect = True
		self._do_connect()
		self.__start_or_stop()
コード例 #29
0
    def __init__(self, samp_rate_in, samp_rate_out, center_freq, tune_freq,
                 channel_width, transition_width, threshold, fsk_deviation,
                 fskSquelch, iq_filename, dig_out_filename):
        gr.top_block.__init__(self)

        ##################################################
        # Variables
        ##################################################
        self.cutoff_freq = channel_width / 2
        self.firdes_taps = firdes.low_pass(1, samp_rate_in, self.cutoff_freq,
                                           transition_width)

        ##################################################
        # Blocks
        ##################################################
        self.blocks_file_source_0 = blocks.file_source(
            gr.sizeof_gr_complex * 1, iq_filename, False)
        self.blocks_tuning_filter_0 = filter.freq_xlating_fir_filter_ccc(
            int(samp_rate_in / samp_rate_out), (self.firdes_taps),
            tune_freq - center_freq, samp_rate_in)
        self.analog_pwr_squelch_xx_0 = analog.pwr_squelch_cc(
            fskSquelch, 1, 1, False)
        self.blocks_quadrature_demod_0 = analog.quadrature_demod_cf(
            samp_rate_out / (2 * pi * fsk_deviation / 2))
        self.blocks_add_const_vxx_0 = blocks.add_const_vff((-1 * threshold, ))
        self.blocks_digital_binary_slicer_fb_0 = digital.binary_slicer_fb()

        # swapped message sink for file sink
        #self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, dig_out_filename, False)
        #self.blocks_file_sink_0.set_unbuffered(False)
        self.sink_queue = gr.msg_queue()
        self.blocks_message_sink_0 = blocks.message_sink(
            gr.sizeof_char * 1, self.sink_queue, False)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_file_source_0, 0),
                     (self.blocks_tuning_filter_0, 0))
        self.connect((self.blocks_tuning_filter_0, 0),
                     (self.analog_pwr_squelch_xx_0, 0))
        self.connect((self.analog_pwr_squelch_xx_0, 0),
                     (self.blocks_quadrature_demod_0, 0))
        self.connect((self.blocks_quadrature_demod_0, 0),
                     (self.blocks_add_const_vxx_0, 0))
        self.connect((self.blocks_add_const_vxx_0, 0),
                     (self.blocks_digital_binary_slicer_fb_0, 0))

        #self.connect((self.digital_binary_slicer_fb_0, 0), (self.blocks_file_sink_0, 0))
        self.connect((self.blocks_digital_binary_slicer_fb_0, 0),
                     (self.blocks_message_sink_0, 0))
コード例 #30
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 2048000
        self.fft_size = fft_size = 4096

        ##################################################
        # Message queues (added by grcconvert)
        ##################################################
        self.msgq_out = blocks_message_sink_0_msgq_out = gr.msg_queue(2)

        ##################################################
        # Blocks
        ##################################################
        self.rtlsdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " +
                                              "rtl=0")
        self.rtlsdr_source_0.set_sample_rate(samp_rate)
        self.rtlsdr_source_0.set_center_freq(100e6, 0)
        self.rtlsdr_source_0.set_freq_corr(0, 0)
        self.rtlsdr_source_0.set_dc_offset_mode(0, 0)
        self.rtlsdr_source_0.set_iq_balance_mode(0, 0)
        self.rtlsdr_source_0.set_gain_mode(0, 0)
        self.rtlsdr_source_0.set_gain(10, 0)
        self.rtlsdr_source_0.set_if_gain(20, 0)
        self.rtlsdr_source_0.set_bb_gain(20, 0)
        self.rtlsdr_source_0.set_antenna("", 0)
        self.rtlsdr_source_0.set_bandwidth(0, 0)

        self.logpwrfft_x_0 = logpwrfft.logpwrfft_c(
            sample_rate=samp_rate,
            fft_size=4096,
            ref_scale=2,
            frame_rate=30,
            avg_alpha=1.0,
            average=False,
        )
        self.blocks_message_sink_0 = blocks.message_sink(
            gr.sizeof_float * 4096, blocks_message_sink_0_msgq_out, False)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.rtlsdr_source_0, 0), (self.logpwrfft_x_0, 0))
        self.connect((self.logpwrfft_x_0, 0), (self.blocks_message_sink_0, 0))
コード例 #31
0
    def __init__(self, rx_callback, tx_status, rx_status):
        gr.hier_block2.__init__(self, "receive_path",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),
            gr.io_signature(0, 0, 0))

        ##################################################
        # Variables
        ##################################################
        self.callback = rx_callback

        ##################################################
        # Blocks
        ##################################################
        self.demod = digital.gfsk_demod(
        	samples_per_symbol=4,
        	sensitivity=1.0,
        	gain_mu=0.175,
        	mu=0.5,
        	omega_relative_limit=0.005,
        	freq_error=0.0,
        	verbose=False,
        	log=False,
        )
        self.frame_sync = frame_sync(tx_status, rx_status) # Your custom block!!!

        self.output_unpacked_to_packed = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)

        self.rcvd_pktq = gr.msg_queue()
        self.message_sink = blocks.message_sink(gr.sizeof_char, self.rcvd_pktq, True)

        self.queue_watcher_thread = _queue_watcher_thread(self.rcvd_pktq, self.callback)

        self.blocks_max = blocks.max_ff(1,1)

        #Don't Search if nothing is transmitting
        self.blocks_threshold_ff_0 = blocks.threshold_ff(0.00002, 0.00002, 0)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1)
        self.analog_simple_squelch_cc_0 = analog.simple_squelch_cc(-80, 0.55)
        ##################################################
        # Connections
        ##################################################
        #main path
        self.connect(self, self.demod, (self.frame_sync, 0))
        self.connect(self.frame_sync, self.output_unpacked_to_packed, self.message_sink)

        #squelch path
        self.connect(self, (self.analog_simple_squelch_cc_0, 0), (self.blocks_complex_to_mag_squared_0, 0))
        self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_max, 0), (self.blocks_threshold_ff_0, 0))
        self.connect((self.blocks_threshold_ff_0, 0), (self.frame_sync, 1))
コード例 #32
0
ファイル: audiomux.py プロジェクト: hofschroeer/shinysdr
 def __init__(self, channels, queue):
     gr.hier_block2.__init__(
         self,
         "ShinySDR AudioQueueSink",
         gr.io_signature(channels, channels, gr.sizeof_float),
         gr.io_signature(0, 0, 0),
     )
     sink = blocks.message_sink(gr.sizeof_float * channels, queue, True)
     if channels == 1:
         self.connect((self, 0), sink)
     else:
         interleaver = blocks.streams_to_vector(gr.sizeof_float, channels)
         for ch in xrange(channels):
             self.connect((self, ch), (interleaver, ch))
         self.connect(interleaver, sink)
コード例 #33
0
ファイル: audiomux.py プロジェクト: misterdevil/shinysdr
 def __init__(self, channels, queue):
     gr.hier_block2.__init__(
         self,
         'ShinySDR AudioQueueSink',
         gr.io_signature(channels, channels, gr.sizeof_float),
         gr.io_signature(0, 0, 0),
     )
     sink = blocks.message_sink(gr.sizeof_float * channels, queue, True)
     if channels == 1:
         self.connect((self, 0), sink)
     else:
         interleaver = blocks.streams_to_vector(gr.sizeof_float, channels)
         for ch in xrange(channels):
             self.connect((self, ch), (interleaver, ch))
         self.connect(interleaver, sink)
コード例 #34
0
ファイル: payload_sink.py プロジェクト: ortalby/gr-ofdm_tools
	def __init__(self, callback = ''):
		gr.hier_block2.__init__(self, "payload_sink",
				gr.io_signature(1, 1, gr.sizeof_char*1),
				gr.io_signature(0, 0, 0))

		# initialize the message queue
		self.sink_queue = gr.msg_queue()
		self.callback = callback

		#data sink!
		self.msg_sink = blocks.message_sink(gr.sizeof_char*1, self.sink_queue, False)     

		# Connections
		self.connect(self, self.msg_sink)

		self._watcher = _queue_watcher_thread_mod(self.sink_queue, self.callback)
コード例 #35
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 2048000
        self.fft_size = fft_size = 4096

        ##################################################
        # Message queues (added by grcconvert)
        ##################################################
        self.msgq_out = blocks_message_sink_0_msgq_out = gr.msg_queue(2)

        ##################################################
        # Blocks
        ##################################################
        self.rtlsdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "rtl=0" )
        self.rtlsdr_source_0.set_sample_rate(samp_rate)
        self.rtlsdr_source_0.set_center_freq(100e6, 0)
        self.rtlsdr_source_0.set_freq_corr(0, 0)
        self.rtlsdr_source_0.set_dc_offset_mode(0, 0)
        self.rtlsdr_source_0.set_iq_balance_mode(0, 0)
        self.rtlsdr_source_0.set_gain_mode(0, 0)
        self.rtlsdr_source_0.set_gain(10, 0)
        self.rtlsdr_source_0.set_if_gain(20, 0)
        self.rtlsdr_source_0.set_bb_gain(20, 0)
        self.rtlsdr_source_0.set_antenna("", 0)
        self.rtlsdr_source_0.set_bandwidth(0, 0)
          
        self.logpwrfft_x_0 = logpwrfft.logpwrfft_c(
        	sample_rate=samp_rate,
        	fft_size=4096,
        	ref_scale=2,
        	frame_rate=30,
        	avg_alpha=1.0,
        	average=False,
        )
        self.blocks_message_sink_0 = blocks.message_sink(gr.sizeof_float*4096, blocks_message_sink_0_msgq_out, False)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.rtlsdr_source_0, 0), (self.logpwrfft_x_0, 0))
        self.connect((self.logpwrfft_x_0, 0), (self.blocks_message_sink_0, 0))
コード例 #36
0
	def __init__(self, fft_len, sens_per_sec, sample_rate, channel_space = 1,
	 search_bw = 1, thr_leveler = 10, tune_freq = 0, alpha_avg = 1, test_duration = 1,
	  period = 3600, trunc_band = 1, verbose = False, peak_alpha = 0, subject_channels = []):
		gr.hier_block2.__init__(self,
			"flank detector",
			gr.io_signature(1, 1, gr.sizeof_gr_complex),
			gr.io_signature(0,0,0))
		self.fft_len = fft_len #lenght of the fft for spectral analysis
		self.sens_per_sec = sens_per_sec #number of measurements per second (decimates)
		self.sample_rate = sample_rate 
		self.channel_space = channel_space #channel space for analysis
		self.search_bw = search_bw #search bandwidth within each channel
		self.thr_leveler = thr_leveler #leveler factor for noise floor / threshold comparison
		self.tune_freq = tune_freq #center frequency
		self.threshold = 0 #actual value of the threshold
		self.alpha_avg = alpha_avg #averaging factor for noise level between consecutive measurements
		self.peak_alpha = peak_alpha  #averaging factor for peak level between consecutive measurements
		self.subject_channels = subject_channels #channels whose flancks will be analysed
		

		self.msgq0 = gr.msg_queue(2)

		#######BLOCKS#####
		self.s2p = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_len)
		self.one_in_n = blocks.keep_one_in_n(gr.sizeof_gr_complex * self.fft_len,
		 max(1, int(self.sample_rate/self.fft_len/self.sens_per_sec)))

		mywindow = window.blackmanharris(self.fft_len)
		self.fft = fft.fft_vcc(self.fft_len, True, (), True)

		self.c2mag2 = blocks.complex_to_mag_squared(self.fft_len)
		self.multiply = blocks.multiply_const_vff(np.array([1.0/float(self.fft_len**2)]*fft_len))

		self.sink0 = blocks.message_sink(gr.sizeof_float * self.fft_len, self.msgq0, True)
		#####CONNECTIONS####
		self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2mag2, self.multiply, self.sink0)

		#start periodic logging
		self._logger = logger(period, test_duration)
		#self._logger = None

		#Watchers
		#statistics and power
		self._watcher0 = _queue0_watcher(self.msgq0, sens_per_sec, self.tune_freq, self.channel_space,
		 self.search_bw, self.fft_len, self.sample_rate, self.thr_leveler, self.alpha_avg, test_duration,
		  trunc_band, verbose, peak_alpha, subject_channels, self._logger)
コード例 #37
0
    def __init__(self,
                 type='BER',
                 win_size=default_win_size,
                 bits_per_symbol=2):
        """
        Error rate constructor.

        Args:
            type: a string 'BER' or 'SER'
            win_size: the number of samples to calculate over
            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),
        )

        print "Warning: the blks2.error_rate is deprecated."

        assert type in ('BER', 'SER')
        self._max_samples = win_size
        self._bits_per_symbol = bits_per_symbol
        #setup message queue
        msg_source = blocks.message_source(gr.sizeof_float, 1)
        self._msgq_source = msg_source.msgq()
        msgq_sink = gr.msg_queue(2)
        msg_sink = blocks.message_sink(gr.sizeof_char, msgq_sink,
                                       False)  #False -> blocking
        inter = blocks.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)
コード例 #38
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 = blocks.stream_to_vector(gr.sizeof_float, self.fft_size)
        self.one_in_n = blocks.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 = fft.fft_vfc(self.fft_size, True, mywindow)
        self.c2mag = blocks.complex_to_mag(self.fft_size)
        self.avg = filter.single_pole_iir_filter_ff(1.0, self.fft_size)
        self.log = blocks.nlog10_ff(20, self.fft_size,
                                    -20 * math.log10(self.fft_size))
        self.sink = blocks.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)
コード例 #39
0
    def __init__(self, mode,
            input_rate=0,
            context=None):
        assert input_rate > 0
        gr.hier_block2.__init__(
            self, 'RTTY demodulator',
            gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
            gr.io_signature(1, 1, gr.sizeof_float * 1),
        )
        self.__text = u''
        
        baud = _DEFAULT_BAUD  # TODO param
        self.baud = baud

        demod_rate = 6000  # TODO optimize this value
        self.samp_rate = demod_rate  # TODO rename
        
        self.__channel_filter = MultistageChannelFilter(
            input_rate=input_rate,
            output_rate=demod_rate,
            cutoff_freq=self.__filter_high,
            transition_width=self.__transition)  # TODO optimize filter band
        self.__sharp_filter = grfilter.fir_filter_ccc(
            1,
            firdes.complex_band_pass(1.0, demod_rate,
                self.__filter_low,
                self.__filter_high,
                self.__transition,
                firdes.WIN_HAMMING))
        self.fsk_demod = RTTYFSKDemodulator(input_rate=demod_rate, baud=baud)
        self.__real = blocks.complex_to_real(vlen=1)
        self.__char_queue = gr.msg_queue(limit=100)
        self.char_sink = blocks.message_sink(gr.sizeof_char, self.__char_queue, True)

        self.connect(
            self,
            self.__channel_filter,
            self.__sharp_filter,
            self.fsk_demod,
            rtty.rtty_decode_ff(rate=demod_rate, baud=baud, polarity=False),
            self.char_sink)
        
        self.connect(
            self.__sharp_filter,
            self.__real,
            self)
コード例 #40
0
ファイル: __init__.py プロジェクト: croutonage/shinysdr
    def __init__(self, mode,
            input_rate=0,
            context=None):
        assert input_rate > 0
        gr.hier_block2.__init__(
            self, 'RTTY demodulator',
            gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
            gr.io_signature(1, 1, gr.sizeof_float * 1),
        )
        self.__text = u''
        
        baud = _DEFAULT_BAUD  # TODO param
        self.baud = baud

        demod_rate = 6000  # TODO optimize this value
        self.samp_rate = demod_rate  # TODO rename
        
        self.__channel_filter = MultistageChannelFilter(
            input_rate=input_rate,
            output_rate=demod_rate,
            cutoff_freq=self.__filter_high,
            transition_width=self.__transition)  # TODO optimize filter band
        self.__sharp_filter = grfilter.fir_filter_ccc(
            1,
            firdes.complex_band_pass(1.0, demod_rate,
                self.__filter_low,
                self.__filter_high,
                self.__transition,
                firdes.WIN_HAMMING))
        self.fsk_demod = RTTYFSKDemodulator(input_rate=demod_rate, baud=baud)
        self.__real = blocks.complex_to_real(vlen=1)
        self.__char_queue = gr.msg_queue(limit=100)
        self.char_sink = blocks.message_sink(gr.sizeof_char, self.__char_queue, True)

        self.connect(
            self,
            self.__channel_filter,
            self.__sharp_filter,
            self.fsk_demod,
            rtty.rtty_decode_ff(rate=demod_rate, baud=baud, polarity=False),
            self.char_sink)
        
        self.connect(
            self.__sharp_filter,
            self.__real,
            self)
コード例 #41
0
ファイル: fftsink_nongl.py プロジェクト: Andy-Vuong/gnuradio
    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 = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)
        self.one_in_n = blocks.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 = fft.fft_vcc(self.fft_size, True, mywindow)
        power = 0
        for tap in mywindow:
            power += tap*tap

        self.c2magsq = blocks.complex_to_mag_squared(self.fft_size)
        self.avg = grfilter.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 = blocks.nlog10_ff(10, self.fft_size,
                                -20*math.log10(self.fft_size)                # Adjust for number of bins
                                -10*math.log10(power/self.fft_size)        # Adjust for windowing loss
                                -20*math.log10(ref_scale/2))                # Adjust for reference scale

        self.sink = blocks.message_sink(gr.sizeof_float * self.fft_size, self.msgq, True)
        self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2magsq, 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)
コード例 #42
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))
     tx_msgq.insert_tail(gr.message(1))                  # send EOF
     tb = gr.top_block()
     src = blocks.message_source(gr.sizeof_char, tx_msgq, "packet_length")
     snk = blocks.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)
コード例 #43
0
    def __init__(self, options):

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


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

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

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

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

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

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

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

        self.sink = blocks.message_sink(gr.sizeof_float * self.fft_size, self.msgq, True)
        self.connect(self, self.s2p, self.fft, self.c2mag, self.avg, self.log, self.sink)
コード例 #44
0
ファイル: eye.py プロジェクト: vibhoresaini/gr-baz-vib
    def __init__(self,
                 parent,
                 title='Eye Diagram',
                 sample_rate=1,
                 size=default_scopesink_size,
                 frame_decim=default_frame_decim,
                 samples_per_symbol=10,
                 num_plots=100,
                 sym_decim=20,
                 v_scale=default_v_scale,
                 t_scale=None,
                 num_inputs=1,
                 **kwargs):

        if t_scale == 0:
            t_scale = None
        if v_scale == 0:
            v_scale = default_v_scale

        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 = blocks.message_sink(gr.sizeof_float, msgq, True)
        self.connect((self, 0), self.st)

        self.win = datascope_window(
            datascope_win_info(
                msgq,
                sample_rate,
                frame_decim,
                v_scale,
                t_scale,
                #None,  # scopesink (not used)
                title=title),
            parent,
            samples_per_symbol=samples_per_symbol,
            num_plots=num_plots,
            sym_decim=sym_decim,
            size=size)
コード例 #45
0
ファイル: packet.py プロジェクト: 232675/gnuradio
 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 = blocks.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)
コード例 #46
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 = blocks.stream_to_vector(gr.sizeof_float, self.fac_size)
        self.one_in_n = blocks.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, ())
        fac = fft.fft_vfc(self.fac_size, True, ())

        c2mag = blocks.complex_to_mag(self.fac_size)
        self.avg = filter.single_pole_iir_filter_ff_make(1.0, self.fac_size)

        fac_fac   = fft.fft_vfc(self.fac_size, True, ())
        fac_c2mag = blocks.complex_to_mag_make(fac_size)

        # FIXME  We need to add 3dB to all bins but the DC bin
        log = blocks.nlog10_ff_make(20, self.fac_size,
                           -20*math.log10(self.fac_size) )
        sink = blocks.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)
コード例 #47
0
ファイル: eye.py プロジェクト: balint256/gr-baz
    def __init__(self,
            parent,
            title='Eye Diagram',
            sample_rate=1,
            size=default_scopesink_size,
            frame_decim=default_frame_decim,
            samples_per_symbol=10,
            num_plots=100,
            sym_decim=20,
            v_scale=default_v_scale,
            t_scale=None,
            num_inputs=1,
            **kwargs):
        
        if t_scale == 0:
            t_scale = None
        if v_scale == 0:
            v_scale = default_v_scale

        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 = blocks.message_sink(gr.sizeof_float, msgq, True)
        self.connect((self, 0), self.st)

        self.win = datascope_window(
            datascope_win_info(
                msgq,
                sample_rate,
                frame_decim,
                v_scale,
                t_scale,
                #None,  # scopesink (not used)
                title=title),
            parent,
            samples_per_symbol=samples_per_symbol,
            num_plots=num_plots,
            sym_decim=sym_decim,
            size=size)
コード例 #48
0
ファイル: __init__.py プロジェクト: bitglue/shinysdr
    def __init__(self, mode, input_rate=0, context=None):
        assert input_rate > 0
        self.__input_rate = input_rate
        gr.hier_block2.__init__(
            self, type(self).__name__,
            gr.io_signature(1, 1, gr.sizeof_gr_complex),
            gr.io_signature(1, 1, gr.sizeof_float))
        
        channel_filter = self.__make_channel_filter()

        self.__text = u''
        self.__char_queue = gr.msg_queue(limit=100)
        self.__char_sink = blocks.message_sink(gr.sizeof_char, self.__char_queue, True)

        # The output of the channel filter is oversampled so we don't need to
        # interpolate for the audio monitor. So we'll downsample before going into
        # the demodulator.
        samp_per_sym = 8
        downsample = self.__demod_rate / samp_per_sym / self.__symbol_rate
        assert downsample % 1 == 0
        downsample = int(downsample)

        self.connect(
            self,
            channel_filter,
            blocks.keep_one_in_n(gr.sizeof_gr_complex, downsample),
            psk31_coherent_demodulator_cc(samp_per_sym=samp_per_sym),
            psk31_constellation_decoder_cb(
                varicode_decode=True,
                differential_decode=True),
            self.__char_sink)
        
        self.connect(
            channel_filter,
            blocks.rotator_cc(rotator_inc(self.__demod_rate, self.__audio_frequency)),
            blocks.complex_to_real(vlen=1),
            analog.agc2_ff(
                reference=dB(-10),
                attack_rate=8e-1,
                decay_rate=8e-1),
            self)
コード例 #49
0
ファイル: error_rate.py プロジェクト: Flamewires/gnuradio
    def __init__(self, type='BER', win_size=default_win_size, bits_per_symbol=2):
        """
        Error rate constructor.

        Args:
            type: a string 'BER' or 'SER'
            win_size: the number of samples to calculate over
            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),
        )

        print "Warning: the blks2.error_rate is deprecated."

        assert type in ('BER', 'SER')
        self._max_samples = win_size
        self._bits_per_symbol = bits_per_symbol
        #setup message queue
        msg_source = blocks.message_source(gr.sizeof_float, 1)
        self._msgq_source = msg_source.msgq()
        msgq_sink = gr.msg_queue(2)
        msg_sink = blocks.message_sink(gr.sizeof_char, msgq_sink, False) #False -> blocking
        inter = blocks.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)
コード例 #50
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 = blocks.message_sink(self._item_size*self._vlen, self._msgq, False) #False -> blocking
		#connect
		self.connect(self, message_sink)

		self.arr = None
		self.idx = 0					
コード例 #51
0
    def __init__(self, fft_len, sample_rate, tune_freq, average, rate, width,
                 height):
        gr.hier_block2.__init__(self, "ascii plot",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(0, 0, 0))
        self.fft_len = fft_len
        self.sample_rate = sample_rate
        self.average = average
        self.tune_freq = tune_freq
        self.rate = rate
        self.width = width
        self.height = height

        self.msgq = gr.msg_queue(2)

        #######BLOCKS#####
        self.s2p = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_len)
        self.one_in_n = blocks.keep_one_in_n(
            gr.sizeof_gr_complex * self.fft_len,
            max(1, int(self.sample_rate / self.fft_len / self.rate)))

        mywindow = window.blackmanharris(self.fft_len)
        self.fft = fft.fft_vcc(self.fft_len, True, (), True)

        self.c2mag2 = blocks.complex_to_mag_squared(self.fft_len)
        self.avg = grfilter.single_pole_iir_filter_ff(1.0, self.fft_len)
        self.log = blocks.nlog10_ff(
            10,
            self.fft_len,
            -10 * math.log10(self.fft_len)  # Adjust for number of bins
            - 10 * math.log10(self.sample_rate))  # Adjust for sample rate

        self.sink = blocks.message_sink(gr.sizeof_float * self.fft_len,
                                        self.msgq, True)
        #####CONNECTIONS####
        self.connect(self, self.s2p, self.one_in_n, self.fft, self.c2mag2,
                     self.avg, self.log, self.sink)

        self._main = main_thread(self.msgq, self.fft_len, self.sample_rate,
                                 self.tune_freq, self.width, self.height)
コード例 #52
0
    def __init__(self, mode, input_rate=0, context=None):
        assert input_rate > 0
        self.__input_rate = input_rate
        gr.hier_block2.__init__(
            self, type(self).__name__,
            gr.io_signature(1, 1, gr.sizeof_gr_complex),
            gr.io_signature(1, 1, gr.sizeof_float))
        
        channel_filter = self.__make_channel_filter()

        self.__char_queue = gr.msg_queue(limit=100)
        self.__char_sink = blocks.message_sink(gr.sizeof_char, self.__char_queue, True)

        # The output of the channel filter is oversampled so we don't need to
        # interpolate for the audio monitor. So we'll downsample before going into
        # the demodulator.
        samp_per_sym = 8
        downsample = self.__demod_rate / samp_per_sym / self.__symbol_rate
        assert downsample % 1 == 0
        downsample = int(downsample)

        self.connect(
            self,
            channel_filter,
            blocks.keep_one_in_n(gr.sizeof_gr_complex, downsample),
            psk31_coherent_demodulator_cc(samp_per_sym=samp_per_sym),
            psk31_constellation_decoder_cb(
                varicode_decode=True,
                differential_decode=True),
            self.__char_sink)
        
        self.connect(
            channel_filter,
            blocks.rotator_cc(rotator_inc(self.__demod_rate, self.__audio_frequency)),
            blocks.complex_to_real(vlen=1),
            analog.agc2_ff(
                reference=dB(-10),
                attack_rate=8e-1,
                decay_rate=8e-1),
            self)
コード例 #53
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
		message_sink = blocks.message_sink(self._item_size*self._vlen, self._msgq, False) #False -> blocking
		#connect
		self.connect(self, message_sink)

		self.arr = None
		self.idx = 0					
コード例 #54
0
    def __init__(self, fft_size, samp_rate, middle_freq, gain, bandwidth, sourceType = 0, filename = ""):
        gr.top_block.__init__(self, "Top Block")
        
        #### Variables ####
        
        self.fft_size = fft_size
        
        self.samp_rate = samp_rate
        self.middle_freq = middle_freq
        self.gain = gain
        self.bandwidth = bandwidth
        
        #### Blocks ####
        
        if sourceType == 0: #rtl2832 radio source
            self.rtl2832_source = osmosdr.source( args="numchan=" + str(1) + " " + "" )
            self.rtl2832_source.set_clock_source("gpsdo", 0)
            self.rtl2832_source.set_sample_rate(samp_rate)
            self.rtl2832_source.set_center_freq(middle_freq, 0)
            self.rtl2832_source.set_freq_corr(0, 0)
            self.rtl2832_source.set_dc_offset_mode(0, 0)
            self.rtl2832_source.set_iq_balance_mode(0, 0)
            self.rtl2832_source.set_gain_mode(False, 0)
            self.rtl2832_source.set_gain(gain, 0)
            self.rtl2832_source.set_if_gain(20, 0)
            self.rtl2832_source.set_bb_gain(20, 0)
            self.rtl2832_source.set_antenna("", 0)
            self.rtl2832_source.set_bandwidth(bandwidth, 0)
                
        elif sourceType == 1 and filename: #wave file source

            self.blocks_wavfile_source_0 = blocks.wavfile_source(filename, False)
            self.samp_rate = self.blocks_wavfile_source_0.sample_rate
            print "Sample rate set to ", samp_rate
            self.block_wav_float_to_complex = blocks.float_to_complex(1)
            self.block_throttle_real = blocks.throttle(gr.sizeof_float*1, samp_rate,True) #throttles reading from the wav file to simulate real time radio
            self.block_throttle_im = blocks.throttle(gr.sizeof_float*1, samp_rate,True)

        self.logpwrfft_x_0 = logpwrfft.logpwrfft_c(
               sample_rate=samp_rate,
               fft_size=fft_size,
               ref_scale=2,
               frame_rate=20,
               avg_alpha=1.0,
               average=False,
        )
        
        self.msgq_out = blocks_message_sink_0_msgq_out = gr.msg_queue(2)
        
        self.blocks_message_sink_0 = blocks.message_sink(gr.sizeof_float*fft_size, blocks_message_sink_0_msgq_out, False)
        


        #### Connections ####
        if sourceType == 0:
            self.connect((self.rtl2832_source, 0), (self.logpwrfft_x_0, 0))
        
        elif sourceType == 1:
            self.connect((self.blocks_wavfile_source_0, 1), (self.block_throttle_im, 0))
            self.connect((self.blocks_wavfile_source_0, 0), (self.block_throttle_real, 0))
            self.connect((self.block_throttle_real, 0), (self.block_wav_float_to_complex, 0))
            self.connect((self.block_throttle_im, 0), (self.block_wav_float_to_complex, 1))
            self.connect((self.block_wav_float_to_complex, 0), (self.logpwrfft_x_0, 0))

        self.connect((self.logpwrfft_x_0, 0), (self.blocks_message_sink_0, 0))
コード例 #55
0
ファイル: gr_ble.py プロジェクト: drtyhlpr/ble_dump
    def __init__(self):
        gr.top_block.__init__(self, "Bluetooth LE Receiver")

        ##################################################
        # Variables
        ##################################################
        self.transition_width = transition_width = 300e3
        self.sample_rate = sample_rate = 4e6
        self.data_rate = data_rate = 1e6
        self.cutoff_freq = cutoff_freq = 850e3
        self.ble_channel_spacing = ble_channel_spacing = 2e6
        self.ble_channel = ble_channel = 12
        self.ble_base_freq = ble_base_freq = 2402e6
        self.squelch_threshold = squelch_threshold = -70
        self.rf_gain = rf_gain = 10
        self.lowpass_filter = lowpass_filter = firdes.low_pass(1, sample_rate, cutoff_freq, transition_width, firdes.WIN_HAMMING, 6.76)
        self.gmsk_sps = gmsk_sps = int(sample_rate / data_rate)
        self.gmsk_omega_limit = gmsk_omega_limit = 0.035
        self.gmsk_mu = gmsk_mu = 0.5
        self.gmsk_gain_mu = gmsk_gain_mu = 0.7
        self.freq_offset = freq_offset = 1e6
        self.freq = freq = ble_base_freq+(ble_channel_spacing * ble_channel)

        ##################################################
        # Message Queues
        ##################################################
        self.message_queue = message_queue = gr.msg_queue(2)

        ##################################################
        # Blocks
        ##################################################
        self.unpacked_to_packed = blocks.unpacked_to_packed_bb(1, gr.GR_LSB_FIRST)
        self.osmosdr_source = osmosdr.source( args="numchan=" + str(1) + " " + "" )
        self.osmosdr_source.set_sample_rate(sample_rate)
        self.osmosdr_source.set_center_freq(freq+freq_offset, 0)
        self.osmosdr_source.set_freq_corr(0, 0)
        self.osmosdr_source.set_dc_offset_mode(0, 0)
        self.osmosdr_source.set_iq_balance_mode(0, 0)
        self.osmosdr_source.set_gain_mode(False, 0)
        self.osmosdr_source.set_gain(rf_gain, 0)
        self.osmosdr_source.set_if_gain(20, 0)
        self.osmosdr_source.set_bb_gain(20, 0)
        self.osmosdr_source.set_antenna("", 0)
        self.osmosdr_source.set_bandwidth(0, 0)
          
        self.message_sink = blocks.message_sink(gr.sizeof_char*1, message_queue, True)
        self.freq_xlating_fir_filter_lp = filter.freq_xlating_fir_filter_ccc(1, (lowpass_filter), -freq_offset, sample_rate)
        self.digital_gmsk_demod_0 = digital.gmsk_demod(
        	samples_per_symbol=gmsk_sps,
        	gain_mu=gmsk_gain_mu,
        	mu=gmsk_mu,
        	omega_relative_limit=gmsk_omega_limit,
        	freq_error=0.0,
        	verbose=False,
        	log=False,
        )
        self.analog_simple_squelch = analog.simple_squelch_cc(squelch_threshold, 0.1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.freq_xlating_fir_filter_lp, 0), (self.digital_gmsk_demod_0, 0))
        self.connect((self.digital_gmsk_demod_0, 0), (self.unpacked_to_packed, 0))
        self.connect((self.unpacked_to_packed, 0), (self.message_sink, 0))
        self.connect((self.osmosdr_source, 0), (self.analog_simple_squelch, 0))
        self.connect((self.analog_simple_squelch, 0), (self.freq_xlating_fir_filter_lp, 0))
コード例 #56
0
ファイル: fftsink_gl.py プロジェクト: Andy-Vuong/gnuradio
	def __init__(
		self,
		parent,
		baseband_freq=0,
		ref_scale=2.0,
		y_per_div=10,
		y_divs=8,
		ref_level=50,
		sample_rate=1,
		fft_size=512,
		fft_rate=fft_window.DEFAULT_FRAME_RATE,
		average=False,
		avg_alpha=None,
		title='',
		size=fft_window.DEFAULT_WIN_SIZE,
		peak_hold=False,
		win=None,
                use_persistence=False,
                persist_alpha=None,
		**kwargs #do not end with a comma
	):
		#ensure avg alpha
		if avg_alpha is None: avg_alpha = 2.0/fft_rate
                #ensure analog alpha
                if persist_alpha is None:
                  actual_fft_rate=float(sample_rate/fft_size)/float(max(1,int(float((sample_rate/fft_size)/fft_rate))))
                  #print "requested_fft_rate ",fft_rate
                  #print "actual_fft_rate    ",actual_fft_rate
                  analog_cutoff_freq=0.5 # Hertz
                  #calculate alpha from wanted cutoff freq
                  persist_alpha = 1.0 - math.exp(-2.0*math.pi*analog_cutoff_freq/actual_fft_rate)

		#init
		gr.hier_block2.__init__(
			self,
			"fft_sink",
			gr.io_signature(1, 1, self._item_size),
			gr.io_signature(0, 0, 0),
		)
		#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 = blocks.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)
		#start input watcher
		common.input_watcher(msgq, self.controller, MSG_KEY)
		#create window
		self.win = fft_window.fft_window(
			parent=parent,
			controller=self.controller,
			size=size,
			title=title,
			real=self._real,
			fft_size=fft_size,
			baseband_freq=baseband_freq,
			sample_rate_key=SAMPLE_RATE_KEY,
			y_per_div=y_per_div,
			y_divs=y_divs,
			ref_level=ref_level,
			average_key=AVERAGE_KEY,
			avg_alpha_key=AVG_ALPHA_KEY,
			peak_hold=peak_hold,
			msg_key=MSG_KEY,
                        use_persistence=use_persistence,
                        persist_alpha=persist_alpha,
		)
		common.register_access_methods(self, self.win)
		setattr(self.win, 'set_baseband_freq', getattr(self, 'set_baseband_freq')) #BACKWARDS
		setattr(self.win, 'set_peak_hold', getattr(self, 'set_peak_hold')) #BACKWARDS
		#connect
		self.wxgui_connect(self, fft, sink)