def _setup_head(self): """ Sets up the input of the flow graph, i.e. determine which kind of file source is necessary. """ if self.filename[-4:].lower() == '.wav': if self.options.verbose: print 'Reading data from a WAV file.' src = blocks.wavfile_source(self.filename, True) f2c = blocks.float_to_complex() self.connect((src, 0), (f2c, 0)) if src.channels() == 2: self.connect((src, 1), (f2c, 1)) self.connect(f2c, self.head) else: if self.options.verbose: print 'Reading data from a raw data file.' src = blocks.file_source(self.options.sample_size, self.filename, True) if self.options.sample_size == gr.sizeof_float: f2c = blocks.float_to_complex() self.connect(src, f2c, self.head) if self.options.verbose: print ' Input data is considered real.' else: self.connect(src, self.head) if self.options.verbose: print ' Input data is considered complex.'
def __init__(self, context, mode, angle=0.0): gr.hier_block2.__init__( self, 'SimulatedDevice VOR modulator', gr.io_signature(1, 1, gr.sizeof_float * 1), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), ) self.__angle = 0.0 # dummy statically visible value will be overwritten # TODO: My signal level parameters are probably wrong because this signal doesn't look like a real VOR signal vor_30 = analog.sig_source_f(self.__audio_rate, analog.GR_COS_WAVE, self.__vor_sig_freq, 1, 0) vor_add = blocks.add_cc(1) vor_audio = blocks.add_ff(1) # Audio/AM signal self.connect( vor_30, blocks.multiply_const_ff(0.3), # M_n (vor_audio, 0)) self.connect( self, blocks.multiply_const_ff(audio_modulation_index), # M_i (vor_audio, 1)) # Carrier component self.connect( analog.sig_source_c(0, analog.GR_CONST_WAVE, 0, 0, 1), (vor_add, 0)) # AM component self.__delay = blocks.delay(gr.sizeof_gr_complex, 0) # configured by set_angle self.connect( vor_audio, make_resampler(self.__audio_rate, self.__rf_rate), # TODO make a complex version and do this last blocks.float_to_complex(1), self.__delay, (vor_add, 1)) # FM component vor_fm_mult = blocks.multiply_cc(1) self.connect( # carrier generation analog.sig_source_f(self.__rf_rate, analog.GR_COS_WAVE, fm_subcarrier, 1, 0), blocks.float_to_complex(1), (vor_fm_mult, 1)) self.connect( # modulation vor_30, make_resampler(self.__audio_rate, self.__rf_rate), analog.frequency_modulator_fc(2 * math.pi * fm_deviation / self.__rf_rate), blocks.multiply_const_cc(0.3), # M_d vor_fm_mult, (vor_add, 2)) self.connect( vor_add, self) # calculate and initialize delay self.set_angle(angle)
def __init__(self): gr.top_block.__init__(self, "Top Block") ################################################## # Blocks ################################################## self.blocks_uchar_to_float_1 = blocks.uchar_to_float() self.blocks_uchar_to_float_0 = blocks.uchar_to_float() self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vff((8e-3, )) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((8e-3, )) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, "/home/yann/Documents/INSA/5SEC/Drone/Dongle/script_grc/capture.bin", True) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex*1, "/home/yann/Documents/INSA/5SEC/Drone/Dongle/script_grc/capture.c", False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_deinterleave_0 = blocks.deinterleave(gr.sizeof_char*1, 1) self.blocks_add_const_vxx_1 = blocks.add_const_vff((-127, )) self.blocks_add_const_vxx_0 = blocks.add_const_vff((-127, )) ################################################## # Connections ################################################## self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_add_const_vxx_1, 0), (self.blocks_multiply_const_vxx_1, 0)) self.connect((self.blocks_deinterleave_0, 0), (self.blocks_uchar_to_float_0, 0)) self.connect((self.blocks_deinterleave_0, 1), (self.blocks_uchar_to_float_1, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_deinterleave_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_uchar_to_float_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_uchar_to_float_1, 0), (self.blocks_add_const_vxx_1, 0))
def __init__(self, target_id, packet_size=8192, number_channel=1, channels = "1"): gr.hier_block2.__init__(self, "rtdex_source", gr.io_signature(0,0,0), gr.io_signature(1,1,gr.sizeof_gr_complex)) self._target_id = target_id self._packet_size = packet_size self._number_channel = number_channel self._channels = channels self.source = nutaq.rtdex_source(self._target_id,gr.sizeof_short,self._number_channel,3) self.source.set_type(0) self.source.set_packet_size(self._packet_size) self.source.set_channels(self._channels) self.blocks_short_to_float_0_0 = blocks.short_to_float(1, 2047) self.blocks_short_to_float_0 = blocks.short_to_float(1, 2047) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_deinterleave_0 = blocks.deinterleave(gr.sizeof_short*1, 1) self.connect((self.blocks_deinterleave_0, 0), (self.blocks_short_to_float_0, 0)) self.connect((self.blocks_deinterleave_0, 1), (self.blocks_short_to_float_0_0, 0)) self.connect((self.blocks_short_to_float_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_short_to_float_0_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.source, 0), (self.blocks_deinterleave_0, 0)) self.connect(self.blocks_float_to_complex_0, self)
def __init__(self, magnitude=0, phase=0): gr.hier_block2.__init__( self, "IQ Imbalance Generator", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(1, 1, gr.sizeof_gr_complex*1), ) ################################################## # Parameters ################################################## self.magnitude = magnitude self.phase = phase ################################################## # Blocks ################################################## self.mag = blocks.multiply_const_vff((math.pow(10,magnitude/20.0), )) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((math.sin(phase*math.pi/180.0), )) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.blocks_add_xx_0 = blocks.add_vff(1) ################################################## # Connections ################################################## self.connect((self.blocks_float_to_complex_0, 0), (self, 0)) self.connect((self, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.blocks_complex_to_float_0, 0), (self.mag, 0)) self.connect((self.mag, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_multiply_const_vxx_0, 0))
def __init__(self, alpha=0): gr.hier_block2.__init__( self, "Amplitude Balance", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(1, 1, gr.sizeof_gr_complex*1), ) ################################################## # Parameters ################################################## self.alpha = alpha ################################################## # Blocks ################################################## self.blocks_rms_xx0 = blocks.rms_ff(alpha) self.blocks_rms_xx = blocks.rms_ff(alpha) self.blocks_multiply_vxx1 = blocks.multiply_vff(1) self.blocks_float_to_complex = blocks.float_to_complex(1) self.blocks_divide_xx = blocks.divide_ff(1) self.blocks_complex_to_float = blocks.complex_to_float(1) ################################################## # Connections ################################################## self.connect((self.blocks_float_to_complex, 0), (self, 0)) self.connect((self, 0), (self.blocks_complex_to_float, 0)) self.connect((self.blocks_complex_to_float, 0), (self.blocks_rms_xx, 0)) self.connect((self.blocks_complex_to_float, 1), (self.blocks_rms_xx0, 0)) self.connect((self.blocks_rms_xx, 0), (self.blocks_divide_xx, 0)) self.connect((self.blocks_rms_xx0, 0), (self.blocks_divide_xx, 1)) self.connect((self.blocks_complex_to_float, 0), (self.blocks_float_to_complex, 0)) self.connect((self.blocks_complex_to_float, 1), (self.blocks_multiply_vxx1, 1)) self.connect((self.blocks_divide_xx, 0), (self.blocks_multiply_vxx1, 0)) self.connect((self.blocks_multiply_vxx1, 0), (self.blocks_float_to_complex, 1))
def __init__(self): gr.top_block.__init__(self) #variables self.samp_rate = samp_rate self.direction = RC_NOTHING #no direction to start #blocks #define the gnuradio blocks #interpolator expands the input function - this creates long zeros and ones self.interpolator = rccar2.functioninterpolator(samp_rate) #functioncoder takes a functioncode into it and creates the appropriate command stream self.functioncoder = rccar2.functioncoder(samplerate=samp_rate, functioncode=1) #sink (the hackRF in this case), can be changed to your transmitting device of course self.hackrf = osmosdr.sink(args="numchan=" + str(1) + " " + "hackhf") self.hackrf.set_sample_rate(samp_rate) self.hackrf.set_center_freq(RC_FREQUENCY, 0) self.hackrf.set_freq_corr(0, 0) #enable the hackrf to transmit (need to set the gain to 14dB) self.hackrf.set_gain(14, 0) self.hackrf.set_if_gain(30, 0) self.hackrf.set_bb_gain(20, 0) self.hackrf.set_antenna("", 0) self.hackrf.set_bandwidth(0, 0) #conversion blocks self.float_to_complex = blocks.float_to_complex(1) self.char_to_float = blocks.char_to_float(1, 1) #vector source which sends the direction to the functioncoder self.vector_source = blocks.vector_source_i([self.direction], False) #connect it all up self.connect((self.char_to_float, 0), (self.float_to_complex, 0)) self.connect((self.char_to_float, 0), (self.float_to_complex, 1)) self.connect((self.interpolator, 0), (self.char_to_float, 0)) self.connect((self.float_to_complex, 0), (self.hackrf, 0)) self.connect((self.vector_source, 0), (self.functioncoder, 0)) self.connect((self.functioncoder, 0), (self.interpolator, 0))
def graph(args): print os.getpid() nargs = len(args) if nargs == 1: infile = args[0] else: sys.stderr.write('usage: interp.py input_file\n') sys.exit(1) tb = gr.top_block() srcf = blocks.file_source(gr.sizeof_short, infile) s2ss = blocks.stream_to_streams(gr.sizeof_short, 2) s2f1 = blocks.short_to_float() s2f2 = blocks.short_to_float() src0 = blocks.float_to_complex() lp_coeffs = filter.firdes.low_pass(3, 19.2e6, 3.2e6, .5e6, filter.firdes.WIN_HAMMING) lp = filter.interp_fir_filter_ccf(3, lp_coeffs) file = blocks.file_sink(gr.sizeof_gr_complex, "/tmp/atsc_pipe_1") tb.connect(srcf, s2ss) tb.connect((s2ss, 0), s2f1, (src0, 0)) tb.connect((s2ss, 1), s2f2, (src0, 1)) tb.connect(src0, lp, file) tb.start() raw_input('Head End: Press Enter to stop') tb.stop()
def __init__(self,delay_num,delay_denom): gr.hier_block2.__init__(self,"moms", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_gr_complex)) cmplx_to_real = blocks.complex_to_real() cmplx_to_img = blocks.complex_to_imag() iirf_real = filter.iir_filter_ffd([1.5],[1, -0.5]) self.moms_real = moms_ff() self.moms_real.set_init_ip_fraction(delay_num,delay_denom) iirf_imag = filter.iir_filter_ffd([1.5],[1, -0.5]) self.moms_imag = moms_ff() self.moms_imag.set_init_ip_fraction(delay_num,delay_denom) float_to_cmplx = blocks.float_to_complex() self.connect((self,0), (cmplx_to_real,0)) self.connect((self,0), (cmplx_to_img,0)) self.connect((cmplx_to_real,0), (iirf_real,0)) self.connect((cmplx_to_img,0), (iirf_imag,0)) self.connect((iirf_real,0), (self.moms_real,0)) self.connect((iirf_imag,0), (self.moms_imag,0)) self.connect((self.moms_real,0), (float_to_cmplx,0)) self.connect((self.moms_imag,0), (float_to_cmplx,1)) self.connect((float_to_cmplx,0), (self,0))
def test_001_t (self): self.degree = 5 self.length = 2**self.degree - 1 expected_result = (self.length - 1)*[-1.0/self.length]+[1] # send a maximum length sequence with period 31 src_real = digital.glfsr_source_f(self.degree, True, 0, 1) src_imag = blocks.null_source(gr.sizeof_float*1) f2c = blocks.float_to_complex(1) mls_correlator = channelsounder.mls_correlator(self.degree, mask = 0, seed = 1) # keep only the samples of the first two autocorrelation periods head = blocks.head(gr.sizeof_gr_complex, 2*self.length) dest = blocks.vector_sink_c(1) self.tb.connect( src_real, (f2c, 0)) self.tb.connect( src_imag, (f2c, 1)) self.tb.connect( f2c, mls_correlator ) self.tb.connect( mls_correlator, head, dest ) # set up fg self.tb.run () # check data result_data = dest.data() # discard the first period, since it is tainted by the zeros inserted # by set_history() result_data = result_data[self.length:] self.assertFloatTuplesAlmostEqual (expected_result, result_data, 6)
def __init__(self, device_name, sample_rate, channel_mapping): self.__device_name = device_name self.__sample_rate = sample_rate if len(channel_mapping) == 2: self.__signal_type = SignalType(kind='IQ', sample_rate=self.__sample_rate) # TODO should be configurable self.__usable_bandwidth = RangeT([(-self.__sample_rate / 2, self.__sample_rate / 2)]) else: self.__signal_type = SignalType( kind= 'USB', # TODO obtain correct type from config (or say hamlib) sample_rate=self.__sample_rate) self.__usable_bandwidth = RangeT([(500, 2500)]) gr.hier_block2.__init__( self, type(self).__name__, gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), ) self.__source = audio.source(self.__sample_rate, device_name=self.__device_name, ok_to_block=True) channel_matrix = blocks.multiply_matrix_ff(channel_mapping) combine = blocks.float_to_complex(1) for i in xrange(0, len(channel_mapping[0])): self.connect((self.__source, i), (channel_matrix, i)) for i in xrange(0, len(channel_mapping)): self.connect((channel_matrix, i), (combine, i)) self.connect(combine, self)
def _setup_head(self): """ Sets up the input of the flow graph, i.e. determine which kind of file source is necessary. """ if self.filename[-4:].lower() == '.wav': if self.options.verbose: print 'Reading data from a WAV file.' src = analog.wavfile_source(self.filename, True) f2c = blocks.float_to_complex() self.connect((src, 0), (f2c, 0)) if src.channels() == 2: self.connect((src, 1), (f2c, 1)) self.connect(f2c, self.head) else: if self.options.verbose: print 'Reading data from a raw data file.' src = blocks.file_source(self.options.sample_size, self.filename, True) if self.options.sample_size == gr.sizeof_float: f2c = gr.float_to_complex() self.connect(src, f2c, self.head) if self.options.verbose: print ' Input data is considered real.' else: self.connect(src, self.head) if self.options.verbose: print ' Input data is considered complex.'
def __init__(self, beta=0): gr.hier_block2.__init__( self, "Third Order Distortion", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(1, 1, gr.sizeof_gr_complex*1), ) ################################################## # Parameters ################################################## self.beta = beta ################################################## # Blocks ################################################## self.blocks_null_source_0 = blocks.null_source(gr.sizeof_float*1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((beta, )) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.blocks_add_xx_0 = blocks.add_vcc(1) ################################################## # Connections ################################################## self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_null_source_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self, 0))
def __init__(self, inputFile, outputFile, samp_rate): gr.top_block.__init__(self, "Wavtobin") ################################################## # Variables ################################################## self.samp_rate = samp_rate self.chip_rate = chip_rate = 64e3 ################################################## # Blocks ################################################## self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_ccf(chip_rate/samp_rate, taps=None, flt_size=32) self.blocks_wavfile_source_0 = blocks.wavfile_source(inputFile, False) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex*1, outputFile, False) self.blocks_file_sink_0.set_unbuffered(False) ################################################## # Connections ################################################## self.connect((self.blocks_wavfile_source_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_wavfile_source_0, 1), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_float_to_complex_0, 0), (self.pfb_arb_resampler_xxx_0, 0)) self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.blocks_file_sink_0, 0))
def __init__(self, src="uhd", dst=None, repeat=False, reader=True, tag=True, samp_rate=2e6, emulator=None): gr.hier_block2.__init__( self, "decoder", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(0, 0, 0)) # Output signature if src == "uhd": self._src = usrp_src.usrp_src(samp_rate=samp_rate, dst=dst) hi_val = 1.1 else: self._wav = blocks.wavfile_source(src, repeat) self._r2c = blocks.float_to_complex(1) self._src = blocks.complex_to_mag_squared(1) self.connect(self._wav, self._r2c, self._src) hi_val = 1.09 # may need to be set to 1.05 depending on antenna setup self._back = background.background(reader, tag, emulator) self._trans = transition_sink.transition_sink(samp_rate, self._back.append, hi_val=hi_val) self.connect(self._src, self._trans) if dst and dst != "uhd" and src == "uhd": self._rec = record.record(dst, samp_rate) self.connect(self._src, self._rec)
def __init__(self, device_name, sample_rate, quadrature_as_stereo): self.__device_name = device_name self.__sample_rate = sample_rate self.__quadrature_as_stereo = quadrature_as_stereo if self.__quadrature_as_stereo: self.__signal_type = SignalType( kind='IQ', sample_rate=self.__sample_rate) else: self.__signal_type = SignalType( kind='USB', # TODO obtain correct type from config (or say hamlib) sample_rate=self.__sample_rate) gr.hier_block2.__init__( self, type(self).__name__, gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), ) self.__source = audio.source( self.__sample_rate, device_name=self.__device_name, ok_to_block=True) combine = blocks.float_to_complex(1) self.connect(self.__source, combine, self) if self.__quadrature_as_stereo: # if we don't do this, the imaginary component is 0 and the spectrum is symmetric self.connect((self.__source, 1), (combine, 1))
def __init__(self): gr.top_block.__init__(self) #variables self.samp_rate = samp_rate self.direction = RC_NOTHING #no direction to start #blocks #define the gnuradio blocks #interpolator expands the input function - this creates long zeros and ones self.interpolator = rccar2.functioninterpolator(samp_rate) #functioncoder takes a functioncode into it and creates the appropriate command stream self.functioncoder = rccar2.functioncoder(samplerate=samp_rate, functioncode=1) #sink (the hackRF in this case), can be changed to your transmitting device of course self.hackrf = osmosdr.sink(args="numchan=" +str(1) + " " + "hackhf") self.hackrf.set_sample_rate(samp_rate) self.hackrf.set_center_freq(RC_FREQUENCY,0) self.hackrf.set_freq_corr(0,0) #enable the hackrf to transmit (need to set the gain to 14dB) self.hackrf.set_gain(14,0) self.hackrf.set_if_gain(30,0) self.hackrf.set_bb_gain(20,0) self.hackrf.set_antenna("",0) self.hackrf.set_bandwidth(0,0) #conversion blocks self.float_to_complex = blocks.float_to_complex(1) self.char_to_float = blocks.char_to_float(1,1) #vector source which sends the direction to the functioncoder self.vector_source = blocks.vector_source_i([self.direction], False) #connect it all up self.connect((self.char_to_float,0), (self.float_to_complex,0)) self.connect((self.char_to_float,0), (self.float_to_complex,1)) self.connect((self.interpolator,0), (self.char_to_float,0)) self.connect((self.float_to_complex,0), (self.hackrf,0)) self.connect((self.vector_source,0), (self.functioncoder,0)) self.connect((self.functioncoder,0), (self.interpolator,0))
def __init__(self): gr.top_block.__init__(self, "Acoust In") ################################################## # Variables ################################################## self.transistion = transistion = 100 self.sps = sps = 2 self.sideband_rx = sideband_rx = 1000 self.sideband = sideband = 1000 self.samp_rate = samp_rate = 48000 self.payload = payload = 20 self.interpolation = interpolation = 200 self.fd = fd = 1 self.carrier = carrier = 23000 ################################################## # Blocks ################################################## self.rational_resampler_xxx_0_0_0 = filter.rational_resampler_ccc( interpolation=1, decimation=interpolation, taps=None, fractional_bw=None, ) self.freq_xlating_fir_filter_xxx_0_0 = filter.freq_xlating_fir_filter_ccc(1, (filter.firdes.low_pass(1, samp_rate, sideband_rx,100)), carrier, samp_rate) self.digital_gfsk_demod_0 = digital.gfsk_demod( samples_per_symbol=sps, sensitivity=1.0, gain_mu=0.175, mu=0.5, omega_relative_limit=0.005, freq_error=0.0, verbose=False, log=False, ) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blks2_tcp_sink_0 = grc_blks2.tcp_sink( itemsize=gr.sizeof_char*1, addr="127.0.0.1", port=11000, server=False, ) self.blks2_packet_decoder_0 = grc_blks2.packet_demod_b(grc_blks2.packet_decoder( access_code="", threshold=-1, callback=lambda ok, payload: self.blks2_packet_decoder_0.recv_pkt(ok, payload), ), ) self.audio_source_0 = audio.source(48000, "", True) ################################################## # Connections ################################################## self.connect((self.blocks_float_to_complex_0, 0), (self.freq_xlating_fir_filter_xxx_0_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0_0, 0), (self.rational_resampler_xxx_0_0_0, 0)) self.connect((self.audio_source_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.rational_resampler_xxx_0_0_0, 0), (self.digital_gfsk_demod_0, 0)) self.connect((self.digital_gfsk_demod_0, 0), (self.blks2_packet_decoder_0, 0)) self.connect((self.blks2_packet_decoder_0, 0), (self.blks2_tcp_sink_0, 0))
def __init__(self, delay_num, delay_denom): gr.hier_block2.__init__(self, "moms", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) cmplx_to_real = blocks.complex_to_real() cmplx_to_img = blocks.complex_to_imag() iirf_real = filter.iir_filter_ffd([1.5], [1, -0.5]) self.moms_real = moms_ff() self.moms_real.set_init_ip_fraction(delay_num, delay_denom) iirf_imag = filter.iir_filter_ffd([1.5], [1, -0.5]) self.moms_imag = moms_ff() self.moms_imag.set_init_ip_fraction(delay_num, delay_denom) float_to_cmplx = blocks.float_to_complex() self.connect((self, 0), (cmplx_to_real, 0)) self.connect((self, 0), (cmplx_to_img, 0)) self.connect((cmplx_to_real, 0), (iirf_real, 0)) self.connect((cmplx_to_img, 0), (iirf_imag, 0)) self.connect((iirf_real, 0), (self.moms_real, 0)) self.connect((iirf_imag, 0), (self.moms_imag, 0)) self.connect((self.moms_real, 0), (float_to_cmplx, 0)) self.connect((self.moms_imag, 0), (float_to_cmplx, 1)) self.connect((float_to_cmplx, 0), (self, 0))
def __init__(self,samp_per_sym=1): valid_mod_block.__init__(self) # Blocks self.b_to_f = blocks.char_to_float(1, 1) self.interp_filter = filter.interp_fir_filter_fff(samp_per_sym, (np.ones(samp_per_sym))) self.f_to_c = blocks.float_to_complex(1) self.c_to_r = blocks.complex_to_real(1) self.decim_filter = filter.fir_filter_fff(samp_per_sym, (np.ones(samp_per_sym))) self.divide_f = blocks.multiply_const_vff((1.0/samp_per_sym, )) self.f_to_b = blocks.float_to_char(1,1) # Connections self.connect((self,0),self.b_to_f) self.connect(self.b_to_f,(self,2)) self.connect(self.b_to_f,self.interp_filter) self.connect(self.interp_filter,self.f_to_c) self.connect(self.f_to_c,(self,1)) self.connect((self,1),self.c_to_r) self.connect(self.c_to_r,self.decim_filter) self.connect(self.decim_filter,self.divide_f) self.connect(self.divide_f,(self,3)) self.connect(self.divide_f,self.f_to_b) self.connect(self.f_to_b,(self,0))
def __init__(self): gr.hier_block2.__init__( self, "Staticphaseshifter", gr.io_signaturev(2, 2, [gr.sizeof_gr_complex * 1, gr.sizeof_float * 1]), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), ) ################################################## # Blocks ################################################## self.blocks_transcendental_0_0 = blocks.transcendental("sin", "float") self.blocks_transcendental_0 = blocks.transcendental("cos", "float") self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1) self.blocks_float_to_complex_0_0 = blocks.float_to_complex(1) ################################################## # Connections ################################################## self.connect((self, 1), (self.blocks_transcendental_0_0, 0)) self.connect((self, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self, 0)) self.connect((self.blocks_float_to_complex_0_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.blocks_transcendental_0, 0), (self.blocks_float_to_complex_0_0, 0)) self.connect((self.blocks_transcendental_0_0, 0), (self.blocks_float_to_complex_0_0, 1)) self.connect((self, 1), (self.blocks_transcendental_0, 0))
def __init__(self, samp_per_sym=4): gr.hier_block2.__init__( self, "PSK31 Modulator", gr.io_signature(1, 1, gr.sizeof_char*1), gr.io_signature(1, 1, gr.sizeof_gr_complex*1), ) self.samp_per_sym = samp_per_sym self.connect( self, # PSK31 defines 0 as a phase change, opposite the usual # differential encoding which is: out = (next - prev) % 2 blocks.not_bb(), blocks.and_const_bb(1), digital.diff_encoder_bb(2), blocks.char_to_float(1, 1), blocks.add_const_vff((-0.5, )), blocks.multiply_const_vff((2, )), interp_fir_filter_fff(samp_per_sym, self._envelope_taps()), blocks.float_to_complex(1), self, )
def __init__(self, audio_rate=48000, samp_rate=512e3): gr.hier_block2.__init__( self, "FM receiver", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signaturev(5, 5, [gr.sizeof_char*1, gr.sizeof_char*1, gr.sizeof_float*1, gr.sizeof_float*1, gr.sizeof_gr_complex*1]), ) ################################################## # Parameters ################################################## self.audio_rate = audio_rate self.samp_rate = samp_rate ################################################## # Blocks ################################################## self.mpx_demod_0 = mpx_demod( audio_rate=audio_rate, samp_rate=samp_rate, ) self.blocks_float_to_complex_0_0 = blocks.float_to_complex(1) self.analog_quadrature_demod_cf_0 = analog.quadrature_demod_cf(2*math.pi*75e3/samp_rate) ################################################## # Connections ################################################## self.connect((self.analog_quadrature_demod_cf_0, 0), (self.blocks_float_to_complex_0_0, 0)) self.connect((self.blocks_float_to_complex_0_0, 0), (self.mpx_demod_0, 0)) self.connect((self.mpx_demod_0, 0), (self, 0)) self.connect((self.mpx_demod_0, 1), (self, 1)) self.connect((self.mpx_demod_0, 2), (self, 2)) self.connect((self.mpx_demod_0, 3), (self, 3)) self.connect((self.mpx_demod_0, 4), (self, 4)) self.connect((self, 0), (self.analog_quadrature_demod_cf_0, 0))
def test_001_t (self): self.degree = 5 self.length = 2**self.degree - 1 expected_result = (self.length - 1)*[-1.0/self.length]+[1] # send a maximum length sequence with period 31 src_real = digital.glfsr_source_f(self.degree, True, 0, 1) src_imag = blocks.null_source(gr.sizeof_float*1) f2c = blocks.float_to_complex(1) mls_correlator = channelsounder_swig.mls_correlator(self.degree, mask = 0, seed = 1) # keep only the samples of the first two autocorrelation periods head = blocks.head(gr.sizeof_gr_complex, 2*self.length) dest = blocks.vector_sink_c(1) self.tb.connect( src_real, (f2c, 0)) self.tb.connect( src_imag, (f2c, 1)) self.tb.connect( f2c, mls_correlator ) self.tb.connect( mls_correlator, head, dest ) # set up fg self.tb.run () # check data result_data = dest.data() # discard the first period, since it is tainted by the zeros inserted # by set_history() result_data = result_data[self.length:] self.assertFloatTuplesAlmostEqual (expected_result, result_data, 6)
def __init__(self, src="uhd", dst="uhd", in_rate=2e6, out_rate=2e6, extra=None): super(tag_emulate, self).__init__() uhd = dst == "uhd" if uhd: dst = None self._bin_src = binary_src.binary_src(out_rate, encode="manchester", idle_bit=0) parser = Parser(extra) self._tag = parser.get_tag(self._bin_src.set_bits) # Do not record here self._dec = decoder.decoder(src=src, dst=None, reader=True, tag=False, samp_rate=in_rate, emulator=self._tag) self.connect(self._dec) self._mult = multiplier.multiplier(samp_rate=out_rate) self.connect(self._bin_src, self._mult) if uhd: # active load modulation self._real = blocks.complex_to_real(1) self._thres = blocks.threshold_ff(0.02, 0.1, 0) self._r2c = blocks.float_to_complex(1) self._sink = usrp_sink.usrp_sink(out_rate) self.connect(self._mult, self._real, self._thres, self._r2c, self._sink) elif dst: self._sink = record.record(dst, out_rate) self.connect(self._mult, self._sink) else: self._sink = blocks.null_sink(gr.sizeof_gr_complex) self.connect(self._mult, self._sink)
def __init__(self, alpha=1e-2, reference=0.5): gr.hier_block2.__init__( self, "RMS AGC", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(1, 1, gr.sizeof_gr_complex*1), ) ################################################## # Parameters ################################################## self.alpha = alpha self.reference = reference ################################################## # Blocks ################################################## self.blocks_rms_xx_0 = blocks.rms_cf(alpha) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(1.0/reference) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_divide_xx_0 = blocks.divide_cc(1) self.blocks_add_const_vxx_0 = blocks.add_const_ff(1e-20) ################################################## # Connections ################################################## self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_divide_xx_0, 0), (self, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_divide_xx_0, 1)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_rms_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self, 0), (self.blocks_divide_xx_0, 0)) self.connect((self, 0), (self.blocks_rms_xx_0, 0))
def __init__(self, samp_rate, carrier, TxGain, RealFileName, ImaginaryFileName,NumSeconds): gr.top_block.__init__(self, "TransmitModulationData") ################################################## # Variables ################################################## self.samp_rate = samp_rate #= 1250000 self.carrier = carrier #= 990000000 self.TxGain = TxGain #= 30 self.RxGain = RxGain = 0 #ImaginaryFileName = sys.argv[2] #RealFileName = sys.argv[1] print('Real File Name is ', RealFileName) print('Imaginary File Name is ', ImaginaryFileName) self.NumSeconds = NumSeconds ################################################## # Blocks ################################################## self.uhd_usrp_sink_0 = uhd.usrp_sink( ",".join(("addr=192.168.10.2", "")), uhd.stream_args( cpu_format="fc32", channels=range(4), ), ) self.uhd_usrp_sink_0.set_samp_rate(samp_rate) self.uhd_usrp_sink_0.set_time_now(uhd.time_spec(time.time()), uhd.ALL_MBOARDS) self.uhd_usrp_sink_0.set_center_freq(carrier, 0) self.uhd_usrp_sink_0.set_gain(TxGain, 0) self.uhd_usrp_sink_0.set_antenna('TX/RX', 0) self.uhd_usrp_sink_0.set_center_freq(carrier, 1) self.uhd_usrp_sink_0.set_gain(TxGain, 1) self.uhd_usrp_sink_0.set_antenna('TX/RX', 1) self.uhd_usrp_sink_0.set_center_freq(carrier, 2) self.uhd_usrp_sink_0.set_gain(TxGain, 2) self.uhd_usrp_sink_0.set_antenna('TX/RX', 2) self.uhd_usrp_sink_0.set_center_freq(carrier, 3) self.uhd_usrp_sink_0.set_gain(TxGain, 3) self.uhd_usrp_sink_0.set_antenna('TX/RX', 3) self.blocks_head_0 = blocks.head(gr.sizeof_gr_complex*1, NumSeconds*samp_rate) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_file_source_0_0 = blocks.file_source(gr.sizeof_float*1, ImaginaryFileName, True) self.blocks_file_source_0_0.set_begin_tag(pmt.PMT_NIL) self.blocks_file_source_0 = blocks.file_source(gr.sizeof_float*1, RealFileName, True) self.blocks_file_source_0.set_begin_tag(pmt.PMT_NIL) self.blocks_null_source_0_1 = blocks.null_source(gr.sizeof_gr_complex*1) self.blocks_null_source_0_0 = blocks.null_source(gr.sizeof_gr_complex*1) self.blocks_null_source_0 = blocks.null_source(gr.sizeof_gr_complex*1) ################################################## # Connections ################################################## self.connect((self.blocks_file_source_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_file_source_0_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_head_0, 0)) self.connect((self.blocks_head_0, 0), (self.uhd_usrp_sink_0, 0)) self.connect((self.blocks_null_source_0_1, 0), (self.uhd_usrp_sink_0, 1)) self.connect((self.blocks_null_source_0_0, 0), (self.uhd_usrp_sink_0, 2)) self.connect((self.blocks_null_source_0, 0), (self.uhd_usrp_sink_0, 3))
def graph (args): print os.getpid() nargs = len (args) if nargs == 1: infile = args[0] else: sys.stderr.write('usage: interp.py input_file\n') sys.exit (1) tb = gr.top_block() srcf = blocks.file_source(gr.sizeof_short,infile) s2ss = blocks.stream_to_streams(gr.sizeof_short,2) s2f1 = blocks.short_to_float() s2f2 = blocks.short_to_float() src0 = blocks.float_to_complex() lp_coeffs = filter.firdes.low_pass(3, 19.2e6, 3.2e6, .5e6, filter.firdes.WIN_HAMMING) lp = filter.interp_fir_filter_ccf(3, lp_coeffs) file = blocks.file_sink(gr.sizeof_gr_complex,"/tmp/atsc_pipe_1") tb.connect( srcf, s2ss ) tb.connect( (s2ss, 0), s2f1, (src0,0) ) tb.connect( (s2ss, 1), s2f2, (src0,1) ) tb.connect( src0, lp, file) tb.start() raw_input ('Head End: Press Enter to stop') tb.stop()
def __init__(self, options): gr.hier_block2.__init__(self, "ReadByteFile", gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex)) ################################################## # Blocks ################################################## self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, options.source, False) self.blocks_deinterleave_0 = blocks.deinterleave(gr.sizeof_char*1) self.blocks_uchar_to_float_1 = blocks.uchar_to_float() self.blocks_uchar_to_float_0 = blocks.uchar_to_float() self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vff((8e-3, )) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((8e-3, )) self.blocks_add_const_vxx_1 = blocks.add_const_vff((-127, )) self.blocks_add_const_vxx_0 = blocks.add_const_vff((-127, )) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, options.rate, True) self.connect((self.blocks_file_source_0, 0), (self.blocks_deinterleave_0, 0)) self.connect((self.blocks_deinterleave_0, 0), (self.blocks_uchar_to_float_0, 0)) self.connect((self.blocks_deinterleave_0, 1), (self.blocks_uchar_to_float_1, 0)) self.connect((self.blocks_uchar_to_float_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_uchar_to_float_1, 0), (self.blocks_add_const_vxx_1, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_add_const_vxx_1, 0), (self.blocks_multiply_const_vxx_1, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_throttle_0, 0), (self, 0))
def __init__(self, device_name, sample_rate, quadrature_as_stereo): self.__device_name = device_name self.__sample_rate = sample_rate self.__quadrature_as_stereo = quadrature_as_stereo if self.__quadrature_as_stereo: self.__signal_type = SignalType(kind='IQ', sample_rate=self.__sample_rate) # TODO should be configurable self.__usable_bandwidth = Range([(-self.__sample_rate / 2, self.__sample_rate / 2)]) else: self.__signal_type = SignalType( kind= 'USB', # TODO obtain correct type from config (or say hamlib) sample_rate=self.__sample_rate) self.__usable_bandwidth = Range([(500, 2500)]) gr.hier_block2.__init__( self, type(self).__name__, gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), ) self.__source = audio.source(self.__sample_rate, device_name=self.__device_name, ok_to_block=True) combine = blocks.float_to_complex(1) self.connect(self.__source, combine, self) if self.__quadrature_as_stereo: # if we don't do this, the imaginary component is 0 and the spectrum is symmetric self.connect((self.__source, 1), (combine, 1))
def __init__(self): gr.top_block.__init__(self, "Dttsptx") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 8000000 self.output_rate = output_rate = 8000000 ################################################## # Blocks ################################################## self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=output_rate, decimation=48000, taps=None, fractional_bw=None, ) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, "/tmp/txiq", False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_complex_to_interleaved_char_0 = blocks.complex_to_interleaved_char(False) self.audio_source_0 = audio.source(48000, "", True) ################################################## # Connections ################################################## self.connect((self.audio_source_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.audio_source_0, 1), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_complex_to_interleaved_char_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_complex_to_interleaved_char_0, 0))
def __init__(self): gr.hier_block2.__init__( self, "Staticphaseshifter", gr.io_signaturev(2, 2, [gr.sizeof_gr_complex*1, gr.sizeof_float*1]), gr.io_signature(1, 1, gr.sizeof_gr_complex*1), ) ################################################## # Blocks ################################################## self.blocks_transcendental_0_0 = blocks.transcendental("sin", "float") self.blocks_transcendental_0 = blocks.transcendental("cos", "float") self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1) self.blocks_float_to_complex_0_0 = blocks.float_to_complex(1) ################################################## # Connections ################################################## self.connect((self, 1), (self.blocks_transcendental_0_0, 0)) self.connect((self, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.blocks_multiply_xx_0_0, 0), (self, 0)) self.connect((self.blocks_float_to_complex_0_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.blocks_transcendental_0, 0), (self.blocks_float_to_complex_0_0, 0)) self.connect((self.blocks_transcendental_0_0, 0), (self.blocks_float_to_complex_0_0, 1)) self.connect((self, 1), (self.blocks_transcendental_0, 0))
def __init__(self, Np=32, P=128, L=2, filename=None, sample_type='complex', verbose=True): gr.top_block.__init__(self) if filename is None: src = analog.noise_source_c(analog.GR_GAUSSIAN, 1) if verbose: print("Using Gaussian noise source.") else: if sample_type == 'complex': src = blocks.file_source(gr.sizeof_gr_complex, filename, True) else: fsrc = blocks.file_source(gr.sizeof_float, filename, True) src = blocks.float_to_complex() self.connect(fsrc, src) if verbose: print(("Reading data from %s" % filename)) if verbose: print("FAM configuration:") print(("N' = %d" % Np)) print(("P = %d" % P)) print(("L = %d" % L)) #print "Δf = %f" % asfd sink = blocks.null_sink(gr.sizeof_float * 2 * Np) self.cyclo_fam = specest.cyclo_fam(Np, P, L) self.connect(src, self.cyclo_fam, sink)
def BuildXlate(self,scope=True,tscope=True): self.f2c = blocks.float_to_complex() taps = filter.firdes.low_pass ( 1.0, rate, 2000, 750, filter.firdes.WIN_HAMMING ) self.xlate = filter.freq_xlating_fir_filter_ccf ( 12, taps, 10000, rate ) self.connect( self,self.f2c, self.xlate, self ) self.connect( (self,1), (self.f2c,1) ) if scope: self.scope = qtgui.sink_c(1024, filter.firdes.WIN_BLACKMAN_hARRIS, fc=0, bw=rate/12, name="FFT%d" % self.i, plotfreq=True, plotwaterfall=True, plottime=True, plotconst=True) self.connect( self.xlate, self.scope ) # Get the reference pointer to the SpectrumDisplayForm QWidget self.pyobj = sip.wrapinstance(self.scope.pyqwidget(), QtGui.QWidget) self.pyobj.show() if tscope: self.tscope = qtgui.sink_c(1024, filter.firdes.WIN_BLACKMAN_hARRIS, fc=0, bw=rate, name="Top FFT%d" % self.i, plotfreq=True, plotwaterfall=True, plottime=False, plotconst=False) self.connect(self.f2c,self.tscope) self.tpyobj = sip.wrapinstance(self.tscope.pyqwidget(), QtGui.QWidget) self.tpyobj.show()
def __init__(self, sample_rate, amplitude): gr.hier_block2.__init__(self, "gsm_source_c", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._symb_rate = 13e6 / 48; self._samples_per_symbol = 2 self._data = blocks.vector_source_b(self.gen_gsm_seq(), True, 2) self._split = blocks.vector_to_streams(gr.sizeof_char*1, 2) self._pack = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST) self._mod = digital.gmsk_mod(self._samples_per_symbol, bt=0.35) self._pwr_f = blocks.char_to_float(1, 1) self._pwr_c = blocks.float_to_complex(1) self._pwr_w = blocks.repeat(gr.sizeof_gr_complex*1, self._samples_per_symbol) self._mul = blocks.multiply_vcc(1) self._interpolate = filter.fractional_resampler_cc( 0, (self._symb_rate * self._samples_per_symbol) / sample_rate ) self._scale = blocks.multiply_const_cc(amplitude) self.connect(self._data, self._split) self.connect((self._split, 0), self._pack, self._mod, (self._mul, 0)) self.connect((self._split, 1), self._pwr_f, self._pwr_c, self._pwr_w, (self._mul, 1)) self.connect(self._mul, self._interpolate, self._scale, self)
def __init__(self, Np=32, P=128, L=2, filename=None, sample_type='complex', verbose=True): gr.top_block.__init__(self) if filename is None: src = analog.noise_source_c(analog.GR_GAUSSIAN, 1) if verbose: print "Using Gaussian noise source." else: if sample_type == 'complex': src = blocks.file_source(gr.sizeof_gr_complex, filename, True) else: fsrc = blocks.file_source(gr.sizeof_float, filename, True) src = blocks.float_to_complex() self.connect(fsrc, src) if verbose: print "Reading data from %s" % filename if verbose: print "FAM configuration:" print "N' = %d" % Np print "P = %d" % P print "L = %d" % L #print "Δf = %f" % asfd sink = blocks.null_sink(gr.sizeof_float * 2 * Np) self.cyclo_fam = specest.cyclo_fam(Np, P, L) self.connect(src, self.cyclo_fam, sink)
def __init__(self): gr.top_block.__init__(self, "Example Tx Ii With Geosson Gui") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 8000000 ################################################## # Blocks ################################################## self.remotecar_RemoteCarIIBaseBand_0 = remotecar.RemoteCarIIBaseBand(samp_rate,True, 99) self.osmosdr_sink_0 = osmosdr.sink( args="numchan=" + str(1) + " " + "" ) self.osmosdr_sink_0.set_sample_rate(samp_rate) self.osmosdr_sink_0.set_center_freq(27.15e6, 0) self.osmosdr_sink_0.set_freq_corr(0, 0) self.osmosdr_sink_0.set_gain(0, 0) self.osmosdr_sink_0.set_if_gain(50, 0) self.osmosdr_sink_0.set_bb_gain(30, 0) self.osmosdr_sink_0.set_antenna("", 0) self.osmosdr_sink_0.set_bandwidth(0, 0) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) ################################################## # Connections ################################################## self.connect((self.remotecar_RemoteCarIIBaseBand_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.remotecar_RemoteCarIIBaseBand_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_float_to_complex_0, 0), (self.osmosdr_sink_0, 0))
def __init__(self, sample_rate, amplitude): gr.hier_block2.__init__( self, "gsm_source_c", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._symb_rate = 13e6 / 48 self._samples_per_symbol = 2 self._data = blocks.vector_source_b(self.gen_gsm_seq(), True, 2) self._split = blocks.vector_to_streams(gr.sizeof_char * 1, 2) self._pack = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST) self._mod = digital.gmsk_mod(self._samples_per_symbol, bt=0.35) self._pwr_f = blocks.char_to_float(1, 1) self._pwr_c = blocks.float_to_complex(1) self._pwr_w = blocks.repeat(gr.sizeof_gr_complex * 1, self._samples_per_symbol) self._mul = blocks.multiply_vcc(1) self._interpolate = filter.fractional_resampler_cc( 0, (self._symb_rate * self._samples_per_symbol) / sample_rate) self._scale = blocks.multiply_const_cc(amplitude) self.connect(self._data, self._split) self.connect((self._split, 0), self._pack, self._mod, (self._mul, 0)) self.connect((self._split, 1), self._pwr_f, self._pwr_c, self._pwr_w, (self._mul, 1)) self.connect(self._mul, self._interpolate, self._scale, self)
def __init__(self, noise_mag=0, alpha=0.1): gr.hier_block2.__init__( self, "Phase Noise Generator", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(1, 1, gr.sizeof_gr_complex*1), ) ################################################## # Parameters ################################################## self.noise_mag = noise_mag self.alpha = alpha ################################################## # Blocks ################################################## self.filter_single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff(alpha, 1) self.blocks_transcendental_0_0 = blocks.transcendental("sin", "float") self.blocks_transcendental_0 = blocks.transcendental("cos", "float") self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, noise_mag, 42) ################################################## # Connections ################################################## self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.analog_noise_source_x_0, 0), (self.filter_single_pole_iir_filter_xx_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self, 0)) self.connect((self, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.filter_single_pole_iir_filter_xx_0, 0), (self.blocks_transcendental_0, 0)) self.connect((self.filter_single_pole_iir_filter_xx_0, 0), (self.blocks_transcendental_0_0, 0)) self.connect((self.blocks_transcendental_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_transcendental_0_0, 0), (self.blocks_float_to_complex_0, 1))
def __init__(self, inputFile, outputFile, samp_rate): gr.top_block.__init__(self, "Wavtobin") ################################################## # Variables ################################################## self.samp_rate = samp_rate self.chip_rate = chip_rate = 64e3 ################################################## # Blocks ################################################## self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_ccf(chip_rate / samp_rate, taps=None, flt_size=32) self.blocks_wavfile_source_0 = blocks.wavfile_source(inputFile, False) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex * 1, outputFile, False) self.blocks_file_sink_0.set_unbuffered(False) ################################################## # Connections ################################################## self.connect((self.blocks_wavfile_source_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_wavfile_source_0, 1), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_float_to_complex_0, 0), (self.pfb_arb_resampler_xxx_0, 0)) self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.blocks_file_sink_0, 0))
def add_vor(freq, angle): compensation = math.pi / 180 * -6.5 # empirical, calibrated against VOR receiver (and therefore probably wrong) angle = angle + compensation angle = angle % (2 * math.pi) vor_sig_freq = 30 phase_shift = int(rf_rate / vor_sig_freq * (angle / (2 * math.pi))) vor_dev = 480 vor_channel = make_channel(freq) vor_30 = analog.sig_source_f(audio_rate, analog.GR_COS_WAVE, vor_sig_freq, 1, 0) vor_add = blocks.add_cc(1) vor_audio = blocks.add_ff(1) # Audio/AM signal self.connect( vor_30, blocks.multiply_const_ff(0.3), # M_n (vor_audio, 0)) self.connect(audio_signal, blocks.multiply_const_ff(0.07), # M_i (vor_audio, 1)) # Carrier component self.connect( analog.sig_source_c(0, analog.GR_CONST_WAVE, 0, 0, 1), (vor_add, 0)) # AM component self.connect( vor_audio, blocks.float_to_complex(1), make_interpolator(), blocks.delay(gr.sizeof_gr_complex, phase_shift), (vor_add, 1)) # FM component vor_fm_mult = blocks.multiply_cc(1) self.connect( # carrier generation analog.sig_source_f(rf_rate, analog.GR_COS_WAVE, 9960, 1, 0), blocks.float_to_complex(1), (vor_fm_mult, 1)) self.connect( # modulation vor_30, filter.interp_fir_filter_fff(interp, interp_taps), # float not complex analog.frequency_modulator_fc(2 * math.pi * vor_dev / rf_rate), blocks.multiply_const_cc(0.3), # M_d vor_fm_mult, (vor_add, 2)) self.connect( vor_add, vor_channel) signals.append(vor_channel)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 44100 ################################################## # Blocks ################################################## self.wxgui_numbersink2_0 = numbersink2.number_sink_f( self.GetWin(), unit="Hz", minval=50, maxval=280, factor=1, decimal_places=2, ref_level=0, sample_rate=samp_rate, number_rate=15, average=False, avg_alpha=None, label="Number Plot", peak_hold=False, show_gauge=True, ) self.Add(self.wxgui_numbersink2_0.win) self.blocks_moving_average_xx_0 = blocks.moving_average_ff( samp_rate / 50, 25 / pi, 200) self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n( gr.sizeof_float * 1, 10) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.band_pass_filter_0 = filter.fir_filter_ccc( 1, firdes.complex_band_pass(1, samp_rate, 60, 255, 100, firdes.WIN_BLACKMAN, 6.76)) self.audio_source_0 = audio.source(samp_rate, "default", True) self.analog_pll_freqdet_cf_0 = analog.pll_freqdet_cf( 200 * 2.0 * pi / samp_rate, 260 * 2.0 * pi / samp_rate, 60 * 2.0 * pi / samp_rate) ################################################## # Connections ################################################## self.connect((self.blocks_moving_average_xx_0, 0), (self.wxgui_numbersink2_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.analog_pll_freqdet_cf_0, 0)) self.connect((self.audio_source_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.analog_pll_freqdet_cf_0, 0), (self.blocks_keep_one_in_n_0, 0)) self.connect((self.blocks_keep_one_in_n_0, 0), (self.blocks_moving_average_xx_0, 0))
def __init__(self, fft_size=4096): gr.hier_block2.__init__( self, "Fast Autocor", gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(1, 1, gr.sizeof_float * 1), ) ################################################## # Parameters ################################################## self.fft_size = fft_size ################################################## # Blocks ################################################## self.fft_vxx_0_0 = fft.fft_vcc(fft_size, False, (window.hamming(fft_size)), False, 1) self.fft_vxx_0 = fft.fft_vcc(fft_size, True, (window.hamming(fft_size)), False, 1) self.blocks_vector_to_stream_0_0 = blocks.vector_to_stream( gr.sizeof_gr_complex * 1, fft_size) self.blocks_vector_to_stream_0 = blocks.vector_to_stream( gr.sizeof_gr_complex * 1, fft_size) self.blocks_stream_to_vector_0_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, fft_size) self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, fft_size) self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vff( (1.0 / fft_size, )) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff( (2048.0 / fft_size, )) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) self.blocks_complex_to_mag_squared_1 = blocks.complex_to_mag_squared(1) ################################################## # Connections ################################################## self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_complex_to_mag_squared_1, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_vector_to_stream_0, 0)) self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0)) self.connect((self.blocks_stream_to_vector_0_0, 0), (self.fft_vxx_0_0, 0)) self.connect((self.fft_vxx_0_0, 0), (self.blocks_vector_to_stream_0_0, 0)) self.connect((self.blocks_vector_to_stream_0_0, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_stream_to_vector_0_0, 0)) self.connect((self.blocks_complex_to_real_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self, 0), (self.blocks_stream_to_vector_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self, 0)) self.connect((self.blocks_complex_to_mag_squared_1, 0), (self.blocks_multiply_const_vxx_1, 0)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.blocks_float_to_complex_0, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Ntsc Hackrf") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.samples_per_line = samples_per_line = 772 self.samp_rate = samp_rate = samples_per_line * 60 * .999 * 525 / 2 self.rf_gain = rf_gain = 14 self.if_gain = if_gain = 40 self.digital_gain = digital_gain = 0.9 self.center_freq = center_freq = 186000000 + 1250000 ################################################## # Blocks ################################################## self.zero = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 0) self.osmosdr_sink_0 = osmosdr.sink(args="numchan=" + str(1) + " " + "hackrf=0") self.osmosdr_sink_0.set_sample_rate(samp_rate) self.osmosdr_sink_0.set_center_freq(center_freq, 0) self.osmosdr_sink_0.set_freq_corr(0, 0) self.osmosdr_sink_0.set_gain(rf_gain, 0) self.osmosdr_sink_0.set_if_gain(if_gain, 0) self.osmosdr_sink_0.set_bb_gain(0, 0) self.osmosdr_sink_0.set_antenna("", 0) self.osmosdr_sink_0.set_bandwidth(0, 0) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff( (digital_gain, )) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_file_source_0 = blocks.file_source( gr.sizeof_float * 1, "/home/ubuntu/WAHD-TV/ve3irr-testing.dat", True) self.blocks_add_xx_0 = blocks.add_vcc(1) self.band_pass_filter_0 = filter.fir_filter_ccc( 1, firdes.complex_band_pass(1, samp_rate, -2475000 + 1725000, 2475000 + 1725000, 500000, firdes.WIN_HAMMING, 6.76)) self.analog_sig_source_x_1 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, 4500000, 0.1, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_1, 0), (self.blocks_add_xx_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_add_xx_0, 0), (self.osmosdr_sink_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.zero, 0), (self.blocks_float_to_complex_0, 1))
def oqpsktx(self, carrier=10000, samp_rate=80000, bw=4000, amp=1, code=codes.mycode, **kwargs): code_table, code_len = codes.codes2table(code), len(code) chunk_len = int(log(code_len, 2)) topblock(self, carrier, samp_rate, bw, amp) ################################################## # Blocks ################################################## self.blocks_packed_to_unpacked_xx_0 = blocks.packed_to_unpacked_bb( chunk_len, gr.GR_LSB_FIRST) self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc( (code_table), code_len) self.blocks_repeat_0 = blocks.repeat(gr.sizeof_gr_complex * 1, 4) self.blocks_vector_source_x_0 = blocks.vector_source_c( [0, sin(pi / 4), 1, sin(3 * pi / 4)], True, 1, []) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.blocks_delay_0 = blocks.delay(gr.sizeof_float * 1, 2) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=int(samp_rate / bw), decimation=1, taps=None, fractional_bw=None, ) ################################################## # Connections ################################################## self.connect((self.source, 0), (self.blocks_packed_to_unpacked_xx_0, 0)) self.connect((self.blocks_packed_to_unpacked_xx_0, 0), (self.digital_chunks_to_symbols_xx_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.blocks_repeat_0, 0)) self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_repeat_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_delay_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_float_to_complex_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.sink, 0))
def test_001_t (self): """AGC on random noisy QPSK symbols""" # Parameters snr_db = 0.0 const_mult = 1.5 agc_rate = 1e-4 agc_ref = 1.0 agc_gain = 1.0 N_last = 1000 # analyze the last symbols # Constants n_symbols = int(10*(1/agc_rate)) noise_v = 1/sqrt((10**(float(snr_db)/10))) rndm = random.Random() # Input data in_vec = tuple([rndm.randint(0,1) for i in range(0, n_symbols)]) # Flowgraph src = blocks.vector_source_b(in_vec) pack = blocks.repack_bits_bb(1, 2, "", False, gr.GR_MSB_FIRST) const = digital.constellation_qpsk().base() cmap = digital.chunks_to_symbols_bc(const.points()) mult = blocks.multiply_const_cc(const_mult) nadder = blocks.add_cc() noise = analog.noise_source_c(analog.GR_GAUSSIAN, noise_v, 0) agc = blocksat.agc_cc(agc_rate, agc_ref, agc_gain) snk = blocks.vector_sink_c() snk2 = blocks.vector_sink_c() # Reference AGC approach rms_cf = blocks.rms_cf(0.0001) f2c = blocks.float_to_complex() div = blocks.divide_cc() snk3 = blocks.vector_sink_c() self.tb.connect(src, pack, cmap, mult) self.tb.connect(mult, (nadder, 0)) self.tb.connect(noise, (nadder, 1)) self.tb.connect(nadder, agc, snk) self.tb.connect(nadder, snk2) self.tb.connect(nadder, (div, 0)) self.tb.connect(nadder, rms_cf, (f2c, 0), (div, 1)) self.tb.connect(div, snk3) self.tb.run() # Collect results agc_syms = snk.data() pre_agc_syms = snk2.data() ref_agc_syms = snk3.data() rms_agc = self.rms(agc_syms, N_last) rms_pre_agc = self.rms(pre_agc_syms, N_last) rms_agc_ref = self.rms(ref_agc_syms, N_last) print('RMS before AGC: %f' %(rms_pre_agc)) print('RMS after AGC: %f' %(rms_agc)) print('RMS after reference AGC: %f' %(rms_agc_ref)) # Check results self.assertAlmostEqual(rms_agc, 1.0, places=1)
def __init__(self): analog_source.__init__(self, mod_name="am-dsb", audio_rate=44.1e3) self.interp = filter.fractional_resampler_ff( 0.0, self.audio_rate * 2 / 200e3) self.cnv = blocks.float_to_complex() self.add = blocks.add_const_cc(1.0) self.mod = blocks.multiply_cc() self.connect(self.random_source, self.interp, self.cnv, self.add, self)
def test_float_to_complex_1(self): src_data = (1.0, 3.0, 5.0, 7.0, 9.0) expected_data = (1+0j, 3+0j, 5+0j, 7+0j, 9+0j) src = blocks.vector_source_f(src_data) op = blocks.float_to_complex() dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
def __init__(self): gr.top_block.__init__(self, "Top Block") Qt.QWidget.__init__(self) self.setWindowTitle("Top Block") try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "top_block") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 44100 self.center1 = center1 = 0 ################################################## # Blocks ################################################## self._center1_range = Range(-20000, 20000, 100, 0, 200) self._center1_win = RangeWidget(self._center1_range, self.set_center1, "center1", "counter_slider", float) self.top_layout.addWidget(self._center1_win) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_fcf(1, (1, ), center1, samp_rate) self.freq_xlating_fft_filter_ccc_0 = filter.freq_xlating_fft_filter_ccc(1, (1, ), center1, samp_rate) self.freq_xlating_fft_filter_ccc_0.set_nthreads(1) self.freq_xlating_fft_filter_ccc_0.declare_sample_delay(0) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_complex_to_float_0_0 = blocks.complex_to_float(1) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.audio_source_0 = audio.source(samp_rate, "", True) self.audio_sink_0 = audio.sink(samp_rate, "", True) self.analog_const_source_x_0 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 0) ################################################## # Connections ################################################## self.connect((self.analog_const_source_x_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.audio_source_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.audio_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.blocks_complex_to_float_0, 0), (self.audio_sink_0, 0)) self.connect((self.blocks_complex_to_float_0_0, 0), (self.audio_sink_0, 1)) self.connect((self.blocks_float_to_complex_0, 0), (self.freq_xlating_fft_filter_ccc_0, 0)) self.connect((self.freq_xlating_fft_filter_ccc_0, 0), (self.blocks_complex_to_float_0_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.blocks_complex_to_float_0, 0))
def __init__(self): gr.top_block.__init__(self, "SSB Transmitter V1 - F1ATB - MAY 2020") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 2400000 self.LSB_USB = LSB_USB = 1 self.GainRF_TX = GainRF_TX = 100 self.GainIF_TX = GainIF_TX = 300 self.GainBB_TX = GainBB_TX = 40 self.Fr_TX = Fr_TX = 145100000 ################################################## # Blocks ################################################## self.rational_resampler_xxx_1 = filter.rational_resampler_ccc( interpolation=240, decimation=1, taps=None, fractional_bw=None) self.hilbert_fc_0 = filter.hilbert_fc(64, firdes.WIN_HAMMING, 6.76) self.hilbert_fc_0.set_min_output_buffer(10) self.hilbert_fc_0.set_max_output_buffer(10) self.blocks_udp_source_0 = blocks.udp_source(gr.sizeof_short * 1, '127.0.0.1', 9005, 512, True) self.blocks_udp_source_0.set_max_output_buffer(2048) self.blocks_short_to_float_0 = blocks.short_to_float(1, 32767) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex * 1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(LSB_USB) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.band_pass_filter_0 = filter.fir_filter_ccc( 1, firdes.complex_band_pass(1, samp_rate / 240, -1300 + LSB_USB * 1500, 1300 + LSB_USB * 1500, 200, firdes.WIN_HAMMING, 6.76)) ################################################## # Connections ################################################## self.connect((self.band_pass_filter_0, 0), (self.rational_resampler_xxx_1, 0)) self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_short_to_float_0, 0), (self.hilbert_fc_0, 0)) self.connect((self.blocks_udp_source_0, 0), (self.blocks_short_to_float_0, 0)) self.connect((self.hilbert_fc_0, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.rational_resampler_xxx_1, 0), (self.blocks_null_sink_0, 0))
def test_float_to_complex_1(self): src_data = (1.0, 3.0, 5.0, 7.0, 9.0) expected_data = (1 + 0j, 3 + 0j, 5 + 0j, 7 + 0j, 9 + 0j) src = blocks.vector_source_f(src_data) op = blocks.float_to_complex() dst = blocks.vector_sink_c() self.tb.connect(src, op, dst) self.tb.run() self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
def __init__(self): gr.hier_block2.__init__( self, "IEEE802.15.4 OQPSK PHY", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(1, 1, gr.sizeof_gr_complex*1), ) self.message_port_register_hier_in("txin") self.message_port_register_hier_out("rxout") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 4000000 ################################################## # Blocks ################################################## self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff(0.00016, 1) self.ieee802_15_4_packet_sink_0 = ieee802_15_4.packet_sink(10) self.ieee802_15_4_access_code_prefixer_0 = ieee802_15_4.access_code_prefixer() self.foo_burst_tagger_0 = foo.burst_tagger(pmt.intern("pdu_length"), 128) self.digital_clock_recovery_mm_xx_0 = digital.clock_recovery_mm_ff(2, 0.000225, 0.5, 0.03, 0.0002) self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc(([(1+1j), (-1+1j), (1-1j), (-1+1j), (1+1j), (-1-1j), (-1-1j), (1+1j), (-1+1j), (-1+1j), (-1-1j), (1-1j), (-1-1j), (1-1j), (1+1j), (1-1j), (1-1j), (-1-1j), (1+1j), (-1-1j), (1-1j), (-1+1j), (-1+1j), (1-1j), (-1-1j), (-1-1j), (-1+1j), (1+1j), (-1+1j), (1+1j), (1-1j), (1+1j), (-1+1j), (-1+1j), (-1-1j), (1-1j), (-1-1j), (1-1j), (1+1j), (1-1j), (1+1j), (-1+1j), (1-1j), (-1+1j), (1+1j), (-1-1j), (-1-1j), (1+1j), (-1-1j), (-1-1j), (-1+1j), (1+1j), (-1+1j), (1+1j), (1-1j), (1+1j), (1-1j), (-1-1j), (1+1j), (-1-1j), (1-1j), (-1+1j), (-1+1j), (1-1j), (-1-1j), (1-1j), (1+1j), (1-1j), (1+1j), (-1+1j), (1-1j), (-1+1j), (1+1j), (-1-1j), (-1-1j), (1+1j), (-1+1j), (-1+1j), (-1-1j), (1-1j), (-1+1j), (1+1j), (1-1j), (1+1j), (1-1j), (-1-1j), (1+1j), (-1-1j), (1-1j), (-1+1j), (-1+1j), (1-1j), (-1-1j), (-1-1j), (-1+1j), (1+1j), (1+1j), (-1-1j), (-1-1j), (1+1j), (-1+1j), (-1+1j), (-1-1j), (1-1j), (-1-1j), (1-1j), (1+1j), (1-1j), (1+1j), (-1+1j), (1-1j), (-1+1j), (1-1j), (-1+1j), (-1+1j), (1-1j), (-1-1j), (-1-1j), (-1+1j), (1+1j), (-1+1j), (1+1j), (1-1j), (1+1j), (1-1j), (-1-1j), (1+1j), (-1-1j), (1+1j), (1-1j), (1+1j), (-1+1j), (1-1j), (-1+1j), (1+1j), (-1-1j), (-1-1j), (1+1j), (-1+1j), (-1+1j), (-1-1j), (1-1j), (-1-1j), (1-1j), (1-1j), (1+1j), (1-1j), (-1-1j), (1+1j), (-1-1j), (1-1j), (-1+1j), (-1+1j), (1-1j), (-1-1j), (-1-1j), (-1+1j), (1+1j), (-1+1j), (1+1j), (-1-1j), (1+1j), (-1+1j), (-1+1j), (-1-1j), (1-1j), (-1-1j), (1-1j), (1+1j), (1-1j), (1+1j), (-1+1j), (1-1j), (-1+1j), (1+1j), (-1-1j), (-1+1j), (1-1j), (-1-1j), (-1-1j), (-1+1j), (1+1j), (-1+1j), (1+1j), (1-1j), (1+1j), (1-1j), (-1-1j), (1+1j), (-1-1j), (1-1j), (-1+1j), (-1-1j), (1-1j), (-1-1j), (1-1j), (1+1j), (1-1j), (1+1j), (-1+1j), (1-1j), (-1+1j), (1+1j), (-1-1j), (-1-1j), (1+1j), (-1+1j), (-1+1j), (-1+1j), (1+1j), (-1+1j), (1+1j), (1-1j), (1+1j), (1-1j), (-1-1j), (1+1j), (-1-1j), (1-1j), (-1+1j), (-1+1j), (1-1j), (-1-1j), (-1-1j), (1-1j), (-1+1j), (1+1j), (-1-1j), (-1-1j), (1+1j), (-1+1j), (-1+1j), (-1-1j), (1-1j), (-1-1j), (1-1j), (1+1j), (1-1j), (1+1j), (-1+1j), (1+1j), (-1-1j), (1-1j), (-1+1j), (-1+1j), (1-1j), (-1-1j), (-1-1j), (-1+1j), (1+1j), (-1+1j), (1+1j), (1-1j), (1+1j), (1-1j), (-1-1j)]), 16) self.blocks_vector_source_x_0 = blocks.vector_source_c([0, sin(pi/4), 1, sin(3*pi/4)], True, 1, []) self.blocks_sub_xx_0 = blocks.sub_ff(1) self.blocks_repeat_0 = blocks.repeat(gr.sizeof_gr_complex*1, 4) self.blocks_pdu_to_tagged_stream_0_0_0 = blocks.pdu_to_tagged_stream(blocks.byte_t, 'pdu_length') self.blocks_packed_to_unpacked_xx_0 = blocks.packed_to_unpacked_bb(4, gr.GR_LSB_FIRST) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_delay_0 = blocks.delay(gr.sizeof_float*1, 2) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.analog_quadrature_demod_cf_0 = analog.quadrature_demod_cf(1) ################################################## # Connections ################################################## self.msg_connect((self.ieee802_15_4_access_code_prefixer_0, 'out'), (self.blocks_pdu_to_tagged_stream_0_0_0, 'pdus')) self.msg_connect((self.ieee802_15_4_packet_sink_0, 'out'), (self, 'rxout')) self.msg_connect((self, 'txin'), (self.ieee802_15_4_access_code_prefixer_0, 'in')) self.connect((self.analog_quadrature_demod_cf_0, 0), (self.blocks_sub_xx_0, 0)) self.connect((self.analog_quadrature_demod_cf_0, 0), (self.single_pole_iir_filter_xx_0, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_delay_0, 0)) self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_float_to_complex_0, 0), (self.foo_burst_tagger_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.blocks_packed_to_unpacked_xx_0, 0), (self.digital_chunks_to_symbols_xx_0, 0)) self.connect((self.blocks_pdu_to_tagged_stream_0_0_0, 0), (self.blocks_packed_to_unpacked_xx_0, 0)) self.connect((self.blocks_repeat_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_sub_xx_0, 0), (self.digital_clock_recovery_mm_xx_0, 0)) self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.blocks_repeat_0, 0)) self.connect((self.digital_clock_recovery_mm_xx_0, 0), (self.ieee802_15_4_packet_sink_0, 0)) self.connect((self.foo_burst_tagger_0, 0), (self, 0)) self.connect((self, 0), (self.analog_quadrature_demod_cf_0, 0)) self.connect((self.single_pole_iir_filter_xx_0, 0), (self.blocks_sub_xx_0, 1))
def __init__(self, fg, src_type, file_samp_type, file_to_open, file_rec_samp_rate, uhd_samp_rate, uhd_gain, center_f, uhd_subdev_spec): gr.hier_block2.__init__(self, "head", gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex)) if(src_type == "File"): try: self.head_src = blocks.file_source(file_samp_type, file_to_open, True) fg.set_samp_rate(file_rec_samp_rate) fg.uhd_src_active = False if fg.cpu_watcher is not None: fg.cpu_watcher.quit() if(file_samp_type == gr.sizeof_float): self.head_bottom = blocks.float_to_complex() self.connect((self.head_src, 0), (self.head_bottom, 0)) self.connect((self.head_bottom, 0), (self, 0)) else: self.connect((self.head_src, 0), (self, 0)) except RuntimeError: print "Could not initialize file-source!" self.head_src = None elif(src_type == "UHD"): try: self.head_src = uhd.single_usrp_source(device_addr='', io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1) self.head_src.set_samp_rate(fg.d_uhd_samp_rate) self.head_src.set_gain(fg.d_uhd_gain, 0) self.head_src.set_center_freq(fg.center_f*1e6 ,0) self.head_src.set_subdev_spec(fg.d_uhd_subdev_spec) fg.set_samp_rate(fg.d_uhd_samp_rate) fg.uhd_src_active = True fg.cpu_watcher.start() if(fg.d_uhd_samp_type == gr.sizeof_float): self.head_bottom = blocks.float_to_complex() self.connect((self.head_src, 0), (self.head_bottom, 0)) self.connect((self.head_bottom, 0), (self, 0)) else: self.connect((self.head_src, 0), (self, 0)) except RuntimeError: print "Could not initialize UHD source!" self.head_src = None else: print "Unknown type of source!"
def __init__(self, txstr="Hello World", carrier=10000, samp_rate = 80000, bw=4000, amp=1): gr.top_block.__init__(self, "Top Block") ################################################## # Variables ################################################## self.samp_rate = samp_rate self.carrier = carrier self.bw = bw ################################################## # Blocks ################################################## self.source = blocks.vector_source_b(tuple(bytearray(txstr)), False, 1, []) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=int(samp_rate/bw), decimation=1, taps=None, fractional_bw=None, ) self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc((CODE_TABLE), CODE_LEN) self.blocks_vector_source_x_0 = blocks.vector_source_c([0, sin(pi/4), 1, sin(3*pi/4)], True, 1, []) self.blocks_repeat_0 = blocks.repeat(gr.sizeof_gr_complex*1, 4) self.blocks_packed_to_unpacked_xx_0 = blocks.packed_to_unpacked_bb(CHUNK_LEN, gr.GR_LSB_FIRST) self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_delay_0 = blocks.delay(gr.sizeof_float*1, 2) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.audio_sink_0 = audio.sink(samp_rate, "") #XXX Hack: 0.07 should actually be parameter amp, but RPI crashes self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, carrier, 0.07, 0) ################################################## # Connections ################################################## self.connect((self.source, 0), (self.blocks_packed_to_unpacked_xx_0, 0)) self.connect((self.blocks_packed_to_unpacked_xx_0, 0), (self.digital_chunks_to_symbols_xx_0, 0)) self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.blocks_repeat_0, 0)) self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_repeat_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_delay_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_float_to_complex_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_multiply_xx_0_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0_0, 1)) self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.blocks_complex_to_real_0, 0), (self.audio_sink_0, 0))
def test_float_to_complex(): top = gr.top_block() src = blocks.null_source(gr.sizeof_float) floattocomplex = blocks.float_to_complex() probe = blocks.probe_rate(gr.sizeof_gr_complex) top.connect((src, 0), (floattocomplex, 0)) top.connect((src, 0), (floattocomplex, 1)) top.connect(floattocomplex, probe) return top, probe
def __init__(self, context, mode, rate=8000): gr.hier_block2.__init__( self, type(self).__name__, gr.io_signature(1, 1, gr.sizeof_float * 1), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), ) self.__rate = rate self.connect(self, blocks.float_to_complex(1), self)
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) self.frame = frame self.panel = panel options = get_options() sample_rate = int(options.sample_rate) self.asrc = audio.source(sample_rate, options.audio_device, True) self.f2c = blocks.float_to_complex(1) self.connect((self.asrc, 1), (self.f2c, 1)) self.connect((self.asrc, 0), (self.f2c, 0)) symbol_rate = 18000 sps = 2 # output rate will be 36,000 ntaps = 11 * sps new_sample_rate = symbol_rate * sps channel_taps = filter.firdes.low_pass(1.0, sample_rate, options.low_pass, options.low_pass * 0.1, filter.firdes.WIN_HANN) FILTER = filter.freq_xlating_fir_filter_ccf(1, channel_taps, options.calibration, sample_rate) sys.stderr.write("sample rate: %d\n" %(sample_rate)) DEMOD = cqpsk.cqpsk_demod( samples_per_symbol = sps, excess_bw=0.35, costas_alpha=0.03, gain_mu=0.05, mu=0.05, omega_relative_limit=0.05, log=options.log, verbose=options.verbose) OUT = blocks.file_sink(gr.sizeof_float, options.output_file) r = float(sample_rate) / float(new_sample_rate) INTERPOLATOR = filter.fractional_interpolator_cc(0, r) self.connect(self.f2c, FILTER, INTERPOLATOR, DEMOD, OUT) self.scope = fftsink2.fft_sink_c(panel, fft_size=512, sample_rate=sample_rate, ref_scale=2.0, ref_level=-30, y_divs=10, fft_rate=10, average=True, avg_alpha=0.2) self.connect(self.f2c, self.scope)