def build_graph(): sample_rate = 8000 scale_factor = 32000 tb = gr.top_block() src = audio.source(sample_rate, "plughw:0,0") src_scale = blocks.multiply_const_ff(scale_factor) interp = filter.rational_resampler_fff(8, 1) f2s = blocks.float_to_short() enc = vocoder.cvsd_encode_sb() dec = vocoder.cvsd_decode_bs() s2f = blocks.short_to_float() decim = filter.rational_resampler_fff(1, 8) sink_scale = blocks.multiply_const_ff(1.0/scale_factor) sink = audio.sink(sample_rate, "plughw:0,0") tb.connect(src, src_scale, interp, f2s, enc) tb.connect(enc, dec, s2f, decim, sink_scale, sink) if 0: # debug tb.conect(src, blocks.file_sink(gr.sizeof_float, "source.dat")) tb.conect(src_scale, blocks.file_sink(gr.sizeof_float, "src_scale.dat")) tb.conect(interp, blocks.file_sink(gr.sizeof_float, "interp.dat")) tb.conect(f2s, blocks.file_sink(gr.sizeof_short, "f2s.dat")) tb.conect(enc, blocks.file_sink(gr.sizeof_char, "enc.dat")) tb.conect(dec, blocks.file_sink(gr.sizeof_short, "dec.dat")) tb.conect(s2f, blocks.file_sink(gr.sizeof_float, "s2f.dat")) tb.conect(decim, blocks.file_sink(gr.sizeof_float, "decim.dat")) tb.conect(sink_scale, blocks.file_sink(gr.sizeof_float, "sink_scale.dat")) return tb
def __init__(self, dab_params, bit_rate, address, subch_size, protection, output_float, verbose=False, debug=False): if output_float: # map short samples to the range [-1,1] in floats gr.hier_block2.__init__(self, "dab_audio_decoder_ff", # Input signature gr.io_signature(1, 1, gr.sizeof_float * dab_params.num_carriers * 2), # Output signature gr.io_signature2(2, 2, gr.sizeof_float, gr.sizeof_float)) else: # output signed 16 bit integers (directly from decoder) gr.hier_block2.__init__(self, "dab_audio_decoder_ff", # Input signature gr.io_signature(1, 1, gr.sizeof_float * dab_params.num_carriers * 2), # Output signature gr.io_signature2(2, 2, gr.sizeof_short, gr.sizeof_short)) self.msc_dec = grdab.msc_decode(dab_params, address, subch_size, protection) self.unpack = blocks.packed_to_unpacked_bb_make(1, gr.GR_MSB_FIRST) self.mp2_dec = grdab.mp2_decode_bs_make(bit_rate / 8) self.connect((self, 0), self.msc_dec, self.unpack, self.mp2_dec) if output_float: # map short samples to the range [-1,1] in floats self.s2f_left = blocks.short_to_float_make(1, 32767) self.s2f_right = blocks.short_to_float_make(1, 32767) self.gain_left = blocks.multiply_const_ff(1, 1) self.gain_right = blocks.multiply_const_ff(1, 1) self.connect((self.mp2_dec, 0), self.s2f_left, self.gain_left, (self, 0)) self.connect((self.mp2_dec, 1), self.s2f_right, self.gain_right, (self, 1)) else: # output signed 16 bit integers (directly from decoder) self.connect((self.mp2_dec, 0), (self, 0)) self.connect((self.mp2_dec, 1), (self, 1))
def __init__(self, output_sample_rate=_def_output_sample_rate, reverse=_def_reverse, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered P25 FM modulation. The input is a dibit (P25 symbol) stream (char, not packed) and the output is the float "C4FM" signal at baseband, suitable for application to an FM modulator stage Input is at the base symbol rate (4800), output sample rate is typically either 32000 (USRP TX chain) or 48000 (sound card) @param output_sample_rate: output sample rate @type output_sample_rate: integer @param reverse: reverse polarity flag @type reverse: bool @param verbose: Print information about modulator? @type verbose: bool @param debug: Print modulation data to files? @type debug: bool """ gr.hier_block2.__init__(self, "p25_c4fm_mod_bf", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature input_sample_rate = 4800 # P25 baseband symbol rate lcm = gru.lcm(input_sample_rate, output_sample_rate) self._interp_factor = int(lcm // input_sample_rate) self._decimation = int(lcm // output_sample_rate) mod_map = [1.0/3.0, 1.0, -(1.0/3.0), -1.0] self.C2S = digital.chunks_to_symbols_bf(mod_map) if reverse: self.polarity = blocks.multiply_const_ff(-1) else: self.polarity = blocks.multiply_const_ff( 1) self.filter = filter.interp_fir_filter_fff(self._interp_factor, c4fm_taps(sample_rate=output_sample_rate).generate()) if verbose: self._print_verbage() if log: self._setup_logging() self.connect(self, self.C2S, self.polarity, self.filter) if (self._decimation > 1): self.decimator = filter.rational_resampler_fff(1, self._decimation) self.connect(self.filter, self.decimator, self) else: self.connect(self.filter, self)
def __init__(self, options): gr.top_block.__init__(self) self.options = options # create a QT application self.qapp = QtGui.QApplication(sys.argv) # give Ctrl+C back to system signal.signal(signal.SIGINT, signal.SIG_DFL) # socket addresses rpc_adr_server = "tcp://localhost:6666" rpc_adr_reply = "tcp://*:6666" probe_adr_gui = "tcp://localhost:5556" probe_adr_fg = "tcp://*:5556" sink_adr = "tcp://*:5555" source_adr = "tcp://localhost:5555" # create the main window self.ui = gui.gui("Loop",rpc_adr_server,rpc_adr_server,probe_adr_gui) self.ui.show() # the strange sampling rate gives a nice movement in the plot :P self.samp_rate = samp_rate = 48200 # blocks self.gr_sig_source = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE , 1000, 1, 0) self.null_source = blocks.null_source(gr.sizeof_float) self.throttle = blocks.throttle(gr.sizeof_float, samp_rate) self.zmq_source = zmqblocks.source_pushpull_feedback(gr.sizeof_float,source_adr) self.mult_a = blocks.multiply_const_ff(1) self.mult_b = blocks.multiply_const_ff(0.5) self.add = blocks.add_ff(1) #self.zmq_sink = zmqblocks.sink_reqrep_nopoll(gr.sizeof_float, sink_adr) #self.zmq_sink = zmqblocks.sink_reqrep(gr.sizeof_float, sink_adr) self.zmq_sink = zmqblocks.sink_pushpull(gr.sizeof_float, sink_adr) self.zmq_probe = zmqblocks.sink_pushpull(gr.sizeof_float, probe_adr_fg) #self.null_sink = blocks.null_sink(gr.sizeof_float) # connects self.connect(self.gr_sig_source, self.mult_a) self.connect(self.zmq_source, self.mult_b, (self.add,1)) # self.connect(self.null_source, (self.add,1)) self.connect(self.mult_a, (self.add, 0), self.throttle, self.zmq_sink) self.connect(self.throttle, self.zmq_probe) # ZeroMQ self.rpc_manager = zmqblocks.rpc_manager() self.rpc_manager.set_reply_socket(rpc_adr_reply) self.rpc_manager.add_interface("start_fg",self.start_fg) self.rpc_manager.add_interface("stop_fg",self.stop_fg) self.rpc_manager.add_interface("set_waveform",self.set_waveform) self.rpc_manager.add_interface("set_k",self.mult_a.set_k) self.rpc_manager.add_interface("get_sample_rate",self.throttle.sample_rate) self.rpc_manager.start_watcher()
def __init__(self, dab_params, bit_rate, address, subch_size, protection, output_float, verbose=False, debug=False): if output_float: # map short samples to the range [-1,1] in floats gr.hier_block2.__init__(self, "dabplus_audio_decoder_ff", # Input signature gr.io_signature(1, 1, gr.sizeof_float * dab_params.num_carriers * 2), # Output signature gr.io_signature2(2, 2, gr.sizeof_float, gr.sizeof_float)) else: # output signed 16 bit integers (directly from decoder) gr.hier_block2.__init__(self, "dabplus_audio_decoder_ff", # Input signature gr.io_signature(1, 1, gr.sizeof_float * dab_params.num_carriers * 2), # Output signature gr.io_signature2(2, 2, gr.sizeof_short, gr.sizeof_short)) self.dp = dab_params self.bit_rate_n = bit_rate / 8 self.address = address self.size = subch_size self.protection = protection self.output_float = output_float self.verbose = verbose self.debug = debug # sanity check # if self.bit_rate_n*6 != self.size: # log = gr.logger("log") # log.debug("bit rate and subchannel size are not fitting") # log.set_level("ERROR") # raise ValueError # MSC decoder extracts logical frames out of transmission frame and decodes it self.msc_decoder = grdab.msc_decode(self.dp, self.address, self.size, self.protection, self.verbose, self.debug) # firecode synchronizes to superframes and checks self.firecode = grdab.firecode_check_bb_make(self.bit_rate_n) # Reed-Solomon error repair self.rs = grdab.reed_solomon_decode_bb_make(self.bit_rate_n) # mp4 decoder self.mp4 = grdab.mp4_decode_bs_make(self.bit_rate_n) self.connect((self, 0), self.msc_decoder, self.firecode, self.rs, self.mp4) if self.output_float: # map short samples to the range [-1,1] in floats self.s2f_left = blocks.short_to_float_make(1, 32767) self.s2f_right = blocks.short_to_float_make(1, 32767) self.gain_left = blocks.multiply_const_ff(1, 1) self.gain_right = blocks.multiply_const_ff(1, 1) self.connect((self.mp4, 0), self.s2f_left, self.gain_left, (self, 0)) self.connect((self.mp4, 1), self.s2f_right, self.gain_right, (self, 1)) else: # output signed 16 bit integers (directly from decoder) self.connect((self.mp4, 0), (self, 0)) self.connect((self.mp4, 1), (self, 1))
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 build_graph(): tb = gr.top_block() src = audio.source(8000) src_scale = blocks.multiply_const_ff(32767) f2s = blocks.float_to_short() enc = vocoder.g721_encode_sb() dec = vocoder.g721_decode_bs() s2f = blocks.short_to_float() sink_scale = blocks.multiply_const_ff(1.0 / 32767.0) sink = audio.sink(8000) tb.connect(src, src_scale, f2s, enc, dec, s2f, sink_scale, sink) return tb
def __init__(self, mode="MODE-S", input_rate=0, audio_rate=0, context=None): assert input_rate > 0 gr.hier_block2.__init__( self, "Mode S/ADS-B/1090 demodulator", gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), # TODO: Add generic support for demodulators with no audio output gr.io_signature(2, 2, gr.sizeof_float * 1), ) self.mode = mode self.input_rate = input_rate # Subprocess self.dump1090 = SubprocessSink(args=["dump1090", "--ifile", "-"], itemsize=gr.sizeof_char) # Output self.band_filter_block = filter = MultistageChannelFilter( input_rate=input_rate, output_rate=pipe_rate, # expected by dump1090 cutoff_freq=pipe_rate / 2, transition_width=transition_width, ) # TODO optimize filter band interleaver = blocks.interleave(gr.sizeof_char) self.connect( self, filter, blocks.complex_to_real(1), blocks.multiply_const_ff(255.0 / 2), blocks.add_const_ff(255.0 / 2), blocks.float_to_uchar(), (interleaver, 0), self.dump1090, ) self.connect( filter, blocks.complex_to_imag(1), blocks.multiply_const_ff(255.0 / 2), blocks.add_const_ff(255.0 / 2), blocks.float_to_uchar(), (interleaver, 1), ) # Dummy audio zero = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 0) self.throttle = blocks.throttle(gr.sizeof_float, audio_rate) self.connect(zero, self.throttle) self.connect(self.throttle, (self, 0)) self.connect(self.throttle, (self, 1))
def __init__(self, options): gr.top_block.__init__(self, "mhp") self.lfsr = lfsr.p25p2_lfsr(options.nac, options.sysid, options.wacn) xor_mask = '' for c in self.lfsr.xorsyms: xor_mask += chr(c) IN = blocks.file_source(gr.sizeof_char, options.input_file) slotid = options.tdma_slotid msgq = gr.msg_queue(2) do_msgq = False wireshark_host = '' udp_port = 0 verbosity = 100 do_imbe = 1 do_output = 1 do_msgq = 0 rx_q = gr.msg_queue(1) do_audio_output = 1 phase2_tdma = 1 FRAMER = op25_repeater.p25_frame_assembler(wireshark_host, udp_port, verbosity, do_imbe, do_output, do_msgq, rx_q, do_audio_output, phase2_tdma) FRAMER.set_xormask(xor_mask) S2F = blocks.short_to_float() M = blocks.multiply_const_ff(1.0 / 32767.0) SINK = audio.sink(8000, 'plughw:0,0') self.connect(IN, FRAMER, S2F, M, SINK)
def test_00(self): expected_result = ( 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff) # Filter taps to expand the data to oversample by 8 # Just using a RRC for some basic filter shape taps = filter.firdes.root_raised_cosine(8, 8, 1.0, 0.5, 21) src = blocks.vector_source_b(expected_result) frame = digital.simple_framer(4) unpack = blocks.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST) expand = filter.interp_fir_filter_fff(8, taps) b2f = blocks.char_to_float() mult2 = blocks.multiply_const_ff(2) sub1 = blocks.add_const_ff(-1) op = digital.simple_correlator(4) dst = blocks.vector_sink_b() self.tb.connect(src, frame, unpack, b2f, mult2, sub1, expand) self.tb.connect(expand, op, dst) self.tb.run() result_data = dst.data() self.assertEqual(expected_result, result_data)
def __init__(self, length, debug=False): """ Hierarchical block to detect Null symbols @param length length of the Null symbol (in samples) @param debug whether to write signals out to files """ gr.hier_block2.__init__(self,"detect_null", gr.io_signature(1, 1, gr.sizeof_gr_complex), # input signature gr.io_signature(1, 1, gr.sizeof_char)) # output signature # get the magnitude squared self.ns_c2magsquared = blocks.complex_to_mag_squared() # this wastes cpu cycles: # ns_detect_taps = [1]*length # self.ns_moving_sum = gr.fir_filter_fff(1,ns_detect_taps) # this isn't better: #self.ns_filter = gr.iir_filter_ffd([1]+[0]*(length-1)+[-1],[0,1]) # this does the same again, but is actually faster (outsourced to an independent block ..): self.ns_moving_sum = dab_swig.moving_sum_ff(length) self.ns_invert = blocks.multiply_const_ff(-1) # peak detector on the inverted, summed up signal -> we get the nulls (i.e. the position of the start of a frame) self.ns_peak_detect = blocks.peak_detector_fb(0.6,0.7,10,0.0001) # mostly found by try and error -> remember that the values are negative! # connect it all self.connect(self, self.ns_c2magsquared, self.ns_moving_sum, self.ns_invert, self.ns_peak_detect, self) if debug: self.connect(self.ns_invert, blocks.file_sink(gr.sizeof_float, "debug/ofdm_sync_dab_ns_filter_inv_f.dat")) self.connect(self.ns_peak_detect,blocks.file_sink(gr.sizeof_char, "debug/ofdm_sync_dab_peak_detect_b.dat"))
def __init__(self, mode, freq_absolute=100.0, freq_relative=None, freq_linked_to_device=False, audio_destination=None, device_name=None, audio_gain=-6, audio_pan=0, audio_channels=0, context=None): assert audio_channels == 1 or audio_channels == 2 assert audio_destination is not None assert device_name is not None gr.hier_block2.__init__( # str() because insists on non-unicode self, str('%s receiver' % (mode,)), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(audio_channels, audio_channels, gr.sizeof_float * 1), ) if lookup_mode(mode) is None: # TODO: communicate back to client if applicable log.msg('Unknown mode %r in Receiver(); using AM' % (mode,)) mode = 'AM' # Provided by caller self.context = context self.__audio_channels = audio_channels # cached info from device self.__device_name = device_name # Simple state self.mode = mode self.audio_gain = audio_gain self.audio_pan = min(1, max(-1, audio_pan)) self.__audio_destination = audio_destination # Receive frequency. self.__freq_linked_to_device = bool(freq_linked_to_device) if self.__freq_linked_to_device and freq_relative is not None: self.__freq_relative = float(freq_relative) self.__freq_absolute = self.__freq_relative + self.__get_device().get_freq() else: self.__freq_absolute = float(freq_absolute) self.__freq_relative = self.__freq_absolute - self.__get_device().get_freq() # Blocks self.__rotator = blocks.rotator_cc() self.__demodulator = self.__make_demodulator(mode, {}) self.__update_demodulator_info() self.__audio_gain_blocks = [blocks.multiply_const_ff(0.0) for _ in xrange(self.__audio_channels)] self.probe_audio = analog.probe_avg_mag_sqrd_f(0, alpha=10.0 / 44100) # TODO adapt to output audio rate # Other internals self.__last_output_type = None self.__update_rotator() # initialize rotator, also in case of __demod_tunable self.__update_audio_gain() self.__do_connect(reason=u'initialization')
def __init__( self, if_rate, af_rate ): gr.hier_block2.__init__(self, "ssb_demod", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(1,1,gr.sizeof_float)) self.if_rate = int(if_rate) self.af_rate = int(af_rate) self.if_decim = int(if_rate / af_rate) self.sideband = 1 self.xlate_taps = ([complex(v) for v in file('ssb_taps').readlines()]) self.audio_taps = filter.firdes.low_pass( 1.0, self.af_rate, 3e3, 600, filter.firdes.WIN_HAMMING ) self.xlate = filter.freq_xlating_fir_filter_ccc( self.if_decim, self.xlate_taps, 0, self.if_rate ) self.split = blocks.complex_to_float() self.lpf = filter.fir_filter_fff( 1, self.audio_taps ) self.sum = blocks.add_ff( ) self.am_sel = blocks.multiply_const_ff( 0 ) self.sb_sel = blocks.multiply_const_ff( 1 ) self.mixer = blocks.add_ff() self.am_det = blocks.complex_to_mag() self.connect(self, self.xlate) self.connect(self.xlate, self.split) self.connect((self.split, 0), (self.sum, 0)) self.connect((self.split, 1), (self.sum, 1)) self.connect(self.sum, self.sb_sel) self.connect(self.xlate, self.am_det) self.connect(self.sb_sel, (self.mixer, 0)) self.connect(self.am_det, self.am_sel) self.connect(self.am_sel, (self.mixer, 1)) self.connect(self.mixer, self.lpf) self.connect(self.lpf, self)
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 test_multiply_const_ff(): top = gr.top_block() src = blocks.null_source(gr.sizeof_float) mul = blocks.multiply_const_ff(random.random()) probe = blocks.probe_rate(gr.sizeof_float) top.connect(src, mul, probe) return top, probe
def __init__(self, uhd_address, options): gr.top_block.__init__(self) self.uhd_addr = uhd_address self.freq = options.freq self.samp_rate = options.samp_rate self.gain = options.gain self.threshold = options.threshold self.trigger = options.trigger self.uhd_src = uhd.single_usrp_source( device_addr=self.uhd_addr, stream_args=uhd.stream_args('fc32')) self.uhd_src.set_samp_rate(self.samp_rate) self.uhd_src.set_center_freq(self.freq, 0) self.uhd_src.set_gain(self.gain, 0) taps = firdes.low_pass_2(1, 1, 0.4, 0.1, 60) self.chanfilt = filter.fir_filter_ccc(10, taps) self.tagger = blocks.burst_tagger(gr.sizeof_gr_complex) # Dummy signaler to collect a burst on known periods data = 1000*[0,] + 1000*[1,] self.signal = blocks.vector_source_s(data, True) # Energy detector to get signal burst ## use squelch to detect energy self.det = analog.simple_squelch_cc(self.threshold, 0.01) ## convert to mag squared (float) self.c2m = blocks.complex_to_mag_squared() ## average to debounce self.avg = filter.single_pole_iir_filter_ff(0.01) ## rescale signal for conversion to short self.scale = blocks.multiply_const_ff(2**16) ## signal input uses shorts self.f2s = blocks.float_to_short() # Use file sink burst tagger to capture bursts self.fsnk = blocks.tagged_file_sink(gr.sizeof_gr_complex, self.samp_rate) ################################################## # Connections ################################################## self.connect((self.uhd_src, 0), (self.tagger, 0)) self.connect((self.tagger, 0), (self.fsnk, 0)) if self.trigger: # Connect a dummy signaler to the burst tagger self.connect((self.signal, 0), (self.tagger, 1)) else: # Connect an energy detector signaler to the burst tagger self.connect(self.uhd_src, self.det) self.connect(self.det, self.c2m, self.avg, self.scale, self.f2s) self.connect(self.f2s, (self.tagger, 1))
def __init__(self, dest = _def_dest, do_imbe = _def_do_imbe, num_ambe = _def_num_ambe, wireshark_host = _def_wireshark_host, udp_port = _def_udp_port, do_msgq = False, msgq = None, audio_output = _def_audio_output, debug = _def_debug): """ Hierarchical block for P25 decoding. @param debug: debug level @type debug: int """ gr.hier_block2.__init__(self, "p25_demod_c", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(0, 0, 0)) # Output signature assert 0 <= num_ambe <= _def_max_tdma_timeslots assert not (num_ambe > 1 and dest != 'wav') self.debug = debug self.dest = dest do_output = 1 do_audio_output = True if msgq is None: msgq = gr.msg_queue(1) self.p25_decoders = [] self.audio_s2f = [] self.scaler = [] self.audio_sink = [] self.xorhash = [] num_decoders = 1 if num_ambe > 1: num_decoders += num_ambe - 1 for slot in xrange(num_decoders): self.p25_decoders.append(op25_repeater.p25_frame_assembler(wireshark_host, udp_port, debug, do_imbe, do_output, do_msgq, msgq, do_audio_output, True)) self.p25_decoders[slot].set_slotid(slot) self.audio_s2f.append(blocks.short_to_float()) # another ridiculous conversion self.scaler.append(blocks.multiply_const_ff(1 / 32768.0)) self.xorhash.append('') if dest == 'wav': filename = 'default-%f-%d.wav' % (time.time(), slot) n_channels = 1 sample_rate = 8000 bits_per_sample = 16 self.audio_sink.append(blocks.wavfile_sink(filename, n_channels, sample_rate, bits_per_sample)) elif dest == 'audio': self.audio_sink.append(audio.sink(_def_audio_rate, audio_output, True)) self.connect(self, self.p25_decoders[slot], self.audio_s2f[slot], self.scaler[slot], self.audio_sink[slot])
def __init__( self, rate, device ): gr.hier_block2.__init__(self, "output", gr.io_signature(1,1,gr.sizeof_float), gr.io_signature(0,0,0)) self.vol = blocks.multiply_const_ff( 0.1 ) self.out = audio.sink( int(rate), device ) self.connect( self, self.vol, self.out )
def __init__(self, mode, input_rate=0, input_center_freq=0, audio_rate=0, rec_freq=100.0, audio_gain=-6, audio_pan=0, context=None): assert input_rate > 0 assert audio_rate > 0 gr.hier_block2.__init__( # str() because insists on non-unicode self, str('%s receiver' % (mode,)), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(2, 2, gr.sizeof_float * 1), ) # Provided by caller self.input_rate = input_rate self.input_center_freq = input_center_freq self.audio_rate = audio_rate self.context = context # Simple state self.mode = mode self.rec_freq = rec_freq self.audio_gain = audio_gain self.audio_pan = min(1, max(-1, audio_pan)) # Blocks self.oscillator = analog.sig_source_c(input_rate, analog.GR_COS_WAVE, -rec_freq, 1, 0) self.mixer = blocks.multiply_cc(1) self.demodulator = self.__make_demodulator(mode, {}) self.__demod_tunable = ITunableDemodulator.providedBy(self.demodulator) self.audio_gain_l_block = blocks.multiply_const_ff(0.0) self.audio_gain_r_block = blocks.multiply_const_ff(0.0) self.probe_audio = analog.probe_avg_mag_sqrd_f(0, alpha=10.0 / audio_rate) self.__update_oscillator() # in case of __demod_tunable self.__update_audio_gain() self.__do_connect()
def __init__(self, audio_output_dev): gr.hier_block2.__init__(self, "audio_tx", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(0, 0, 0)) # Output signature self.sample_rate = sample_rate = 8000 self.packet_src = blocks.message_source(33) voice_decoder = vocoder.gsm_fr_decode_ps() s2f = blocks.short_to_float() sink_scale = blocks.multiply_const_ff(1.0/32767.) audio_sink = audio.sink(sample_rate, audio_output_dev) self.connect(self.packet_src, voice_decoder, s2f, sink_scale, audio_sink)
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)
def __init__( self ): gr.hier_block2.__init__(self, "agc", gr.io_signature(1,1,gr.sizeof_float), gr.io_signature(1,1,gr.sizeof_float)) self.split = blocks.multiply_const_ff( 1 ) self.sqr = blocks.multiply_ff( ) self.int0 = filter.iir_filter_ffd( [.004, 0], [0, .999] ) self.offs = blocks.add_const_ff( -30 ) self.gain = blocks.multiply_const_ff( 70 ) self.log = blocks.nlog10_ff( 10, 1 ) self.agc = blocks.divide_ff( ) self.connect(self, self.split) self.connect(self.split, (self.agc, 0)) self.connect(self.split, (self.sqr, 0)) self.connect(self.split, (self.sqr, 1)) self.connect(self.sqr, self.int0) self.connect(self.int0, self.log) self.connect(self.log, self.offs) self.connect(self.offs, self.gain) self.connect(self.gain, (self.agc, 1)) self.connect(self.agc, self)
def __init__(self, mode, input_rate=0, input_center_freq=0, rec_freq=100.0, audio_destination=None, audio_gain=-6, audio_pan=0, audio_channels=0, context=None): assert input_rate > 0 assert audio_channels == 1 or audio_channels == 2 assert audio_destination is not None gr.hier_block2.__init__( # str() because insists on non-unicode self, str('%s receiver' % (mode,)), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(audio_channels, audio_channels, gr.sizeof_float * 1), ) if lookup_mode(mode) is None: # TODO: communicate back to client if applicable log.msg('Unknown mode %r in Receiver(); using AM' % (mode,)) mode = 'AM' # Provided by caller self.context = context self.input_rate = input_rate self.input_center_freq = input_center_freq self.__audio_channels = audio_channels # Simple state self.mode = mode self.rec_freq = rec_freq self.audio_gain = audio_gain self.audio_pan = min(1, max(-1, audio_pan)) self.__audio_destination = audio_destination # Blocks self.__rotator = blocks.rotator_cc() self.demodulator = self.__make_demodulator(mode, {}) self.__update_demodulator_info() self.__audio_gain_blocks = [blocks.multiply_const_ff(0.0) for _ in xrange(self.__audio_channels)] self.probe_audio = analog.probe_avg_mag_sqrd_f(0, alpha=10.0 / 44100) # TODO adapt to output audio rate # Other internals self.__last_output_type = None self.__update_rotator() # initialize rotator, also in case of __demod_tunable self.__update_audio_gain() self.__do_connect()
def xtest_ccsds_27 (self): src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) expected = (0, 0, 0, 0, 1, 2, 3, 4, 5, 6) src = blocks.vector_source_b(src_data) enc = fec.encode_ccsds_27_bb() b2f = blocks.char_to_float() add = blocks.add_const_ff(-0.5) mul = blocks.multiply_const_ff(2.0) dec = fec.decode_ccsds_27_fb() dst = blocks.vector_sink_b() self.tb.connect(src, enc, b2f, add, mul, dec, dst) self.tb.run() dst_data = dst.data() self.assertEqual(expected, dst_data)
def __rebuild_demodulator_nodirty(self, mode=None): if self.__demodulator is None: defaults = {} else: defaults = self.__demodulator.state_to_json() if mode is None: mode = self.mode self.__demodulator = self.__make_demodulator(mode, defaults) self.__update_demodulator_info() self.__update_rotator() self.mode = mode # Replace blocks downstream of the demodulator so as to flush samples that are potentially at a different sample rate and would therefore be audibly wrong. Caller will handle reconnection. self.__audio_gain_blocks = [blocks.multiply_const_ff(0.0) for _ in xrange(self.__audio_channels)] self.__update_audio_gain()
def __init__(self): gr.hier_block2.__init__( self, "phase_calc_ccf", gr.io_signature(2, 2, gr.sizeof_gr_complex), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature self.block = dict() self.block['mult_conj'] = blocks.multiply_conjugate_cc() self.block['arg'] = blocks.complex_to_arg() self.block['mult_const'] = blocks.multiply_const_ff(180.0 / np.pi) self.connect((self, 0), (self.block['mult_conj'], 0)) self.connect((self, 1), (self.block['mult_conj'], 1)) self.connect((self.block['mult_conj'], 0), (self.block['arg'], 0)) self.connect((self.block['arg'], 0), (self.block['mult_const'], 0)) self.connect((self.block['mult_const'], 0), (self, 0))
def BuildConjMult(self,scope=True): ## Compute angle difference #self.conj = blocks.conjugate_cc() self.mult = blocks.multiply_conjugate_cc() self.connect(self.rx0, blocks.multiply_const_cc(10000), (self.mult,0)) self.connect(self.rx1, blocks.multiply_const_cc(10000), (self.mult,1)) self.histo = qtgui.histogram_sink_f(1000,360,-179,180,"Histogram") #self.histo.enable_autoscale(False) self.histo.enable_accumulate(True) self.histo.enable_grid(True) #self.histo.enable_menu(True) self.connect(self.mult,blocks.complex_to_arg(), blocks.multiply_const_ff(180.0/np.pi),self.histo) self.pyobj = sip.wrapinstance(self.histo.pyqwidget(), QtGui.QWidget) self.pyobj.show()
def __init__(self, bits_per_byte): gr.hier_block2.__init__(self, "BitErrors", gr.io_signature(2, 2, gr.sizeof_char), gr.io_signature(1, 1, gr.sizeof_int)) # Bit comparison comp = blocks.xor_bb() intdump_decim = 100000 if N_BITS < intdump_decim: intdump_decim = int(N_BITS) self.connect(self, comp, blocks.unpack_k_bits_bb(bits_per_byte), blocks.uchar_to_float(), blocks.integrate_ff(intdump_decim), blocks.multiply_const_ff(1.0 / N_BITS), self) self.connect((self, 1), (comp, 1))
def __init__(self, resample=8, bw=0.5): ''' When using the CVSD vocoder, appropriate sampling rates are from 8k to 64k with resampling rates from 1 to 8. A rate of 8k with a resampling rate of 8 provides a good quality signal. ''' gr.hier_block2.__init__(self, "cvsd_decode", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature scale_factor = 32000.0 self.decim = resample dec = vocoder_swig.cvsd_decode_bs() s2f = blocks.short_to_float() taps = filter.firdes.low_pass(1, 1, bw, 2*bw) decim = filter.fir_filter_fff(self.decim, taps) sink_scale = blocks.multiply_const_ff(1.0/scale_factor) self.connect(self, dec, s2f, decim, sink_scale, self)
def __init__(self, resample=8, bw=0.5): ''' When using the CVSD vocoder, appropriate sampling rates are from 8k to 64k with resampling rates from 1 to 8. A rate of 8k with a resampling rate of 8 provides a good quality signal. ''' gr.hier_block2.__init__(self, "cvsd_encode", gr.io_signature(1, 1, gr.sizeof_float), # Input signature gr.io_signature(1, 1, gr.sizeof_char)) # Output signature scale_factor = 32000.0 self.interp = resample src_scale = blocks.multiply_const_ff(scale_factor) taps = filter.firdes.low_pass(self.interp, self.interp, bw, 2*bw) interp = filter.interp_fir_filter_fff(self.interp, taps) f2s = blocks.float_to_short() enc = vocoder_swig.cvsd_encode_sb() self.connect(self, src_scale, interp, f2s, enc, self)
def __init__(self, args, spec, antenna, gain, audio_input): gr.hier_block2.__init__(self, "transmit_path", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(0, 0, 0)) # Output signature self.u = uhd.usrp_sink(device_addr=args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if(spec): self.u.set_subdev_spec(spec, 0) # Set the antenna if(antenna): self.u.set_antenna(antenna, 0) self.if_rate = 320e3 self.audio_rate = 32e3 self.u.set_samp_rate(self.if_rate) dev_rate = self.u.get_samp_rate() self.audio_gain = 10 self.normal_gain = 32000 self.audio = audio.source(int(self.audio_rate), audio_input) self.audio_amp = blocks.multiply_const_ff(self.audio_gain) lpf = filter.firdes.low_pass(1, # gain self.audio_rate, # sampling rate 3800, # low pass cutoff freq 300, # width of trans. band filter.firdes.WIN_HANN) # filter type hpf = filter.firdes.high_pass(1, # gain self.audio_rate, # sampling rate 325, # low pass cutoff freq 50, # width of trans. band filter.firdes.WIN_HANN) # filter type audio_taps = convolve(array(lpf),array(hpf)) self.audio_filt = filter.fir_filter_fff(1,audio_taps) self.pl = analog.ctcss_gen_f(self.audio_rate,123.0) self.add_pl = blocks.add_ff() self.connect(self.pl,(self.add_pl,1)) self.fmtx = analog.nbfm_tx(self.audio_rate, self.if_rate) self.amp = blocks.multiply_const_cc (self.normal_gain) rrate = dev_rate / self.if_rate self.resamp = filter.pfb.arb_resampler_ccf(rrate) self.connect(self.audio, self.audio_amp, self.audio_filt, (self.add_pl,0), self.fmtx, self.amp, self.resamp, self.u) if gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() gain = float(g.start() + g.stop())/2.0 self.set_gain(gain) self.set_enable(False)
def __init__(self): gr.top_block.__init__(self, "Not titled yet") Qt.QWidget.__init__(self) self.setWindowTitle("Not titled yet") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "fsk") try: if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"): self.restoreGeometry( self.settings.value("geometry").toByteArray()) else: self.restoreGeometry(self.settings.value("geometry")) except: pass ################################################## # Variables ################################################## self.samp_rate = samp_rate = 48000 self.vco_offset = vco_offset = 0.85 self.vco_max = vco_max = 2.5e3 self.sq_lvl = sq_lvl = -70 self.repeat = repeat = (int)(samp_rate * 0.022) self.inp_amp = inp_amp = 0.068 self.fsk_deviation = fsk_deviation = 170 self.delay = delay = 200 self.center = center = 2210 self.baud = baud = 1 / 0.022 ################################################## # Blocks ################################################## self._sq_lvl_range = Range(-100, 0, 5, -70, 200) self._sq_lvl_win = RangeWidget(self._sq_lvl_range, self.set_sq_lvl, 'Squelch', "counter_slider", float) self.top_grid_layout.addWidget(self._sq_lvl_win) self._delay_range = Range(0, 250, 1, 200, 200) self._delay_win = RangeWidget(self._delay_range, self.set_delay, 'Delay', "counter_slider", float) self.top_grid_layout.addWidget(self._delay_win) self.qtgui_time_sink_x_1 = qtgui.time_sink_f( 16384, #size samp_rate, #samp_rate "", #name 3 #number of inputs ) self.qtgui_time_sink_x_1.set_update_time(0.10) self.qtgui_time_sink_x_1.set_y_axis(-1, 1) self.qtgui_time_sink_x_1.set_y_label('Amplitude', "") self.qtgui_time_sink_x_1.enable_tags(True) self.qtgui_time_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_1.enable_autoscale(False) self.qtgui_time_sink_x_1.enable_grid(False) self.qtgui_time_sink_x_1.enable_axis_labels(True) self.qtgui_time_sink_x_1.enable_control_panel(True) self.qtgui_time_sink_x_1.enable_stem_plot(False) labels = [ 'Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5', 'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10' ] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ 'blue', 'red', 'green', 'black', 'cyan', 'magenta', 'yellow', 'dark red', 'dark green', 'dark blue' ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] for i in range(3): if len(labels[i]) == 0: self.qtgui_time_sink_x_1.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_1.set_line_label(i, labels[i]) self.qtgui_time_sink_x_1.set_line_width(i, widths[i]) self.qtgui_time_sink_x_1.set_line_color(i, colors[i]) self.qtgui_time_sink_x_1.set_line_style(i, styles[i]) self.qtgui_time_sink_x_1.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_1.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_1_win = sip.wrapinstance( self.qtgui_time_sink_x_1.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_sink_x_1_win) self.low_pass_filter_0 = filter.fir_filter_fff( 1, firdes.low_pass(1, samp_rate, 200, 1000, firdes.WIN_HAMMING, 6.76)) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_fcf( 1, firdes.low_pass(1.0, samp_rate, 1000, 400), 2.21e3, samp_rate) self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb() self.blocks_vco_f_0 = blocks.vco_f(samp_rate, 15.708e3, 0.5) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(8) self.blocks_uchar_to_float_1 = blocks.uchar_to_float() self.blocks_uchar_to_float_0 = blocks.uchar_to_float() self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char * 1, samp_rate, True) self.blocks_sub_xx_0 = blocks.sub_ff(1) self.blocks_repeat_0 = blocks.repeat(gr.sizeof_char * 1, repeat) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(inp_amp) self.blocks_delay_0 = blocks.delay(gr.sizeof_float * 1, delay) self.blocks_add_const_vxx_0 = blocks.add_const_ff(vco_offset) self.analog_simple_squelch_cc_0 = analog.simple_squelch_cc(sq_lvl, 1) self.analog_random_source_x_0 = blocks.vector_source_b( list(map(int, numpy.random.randint(0, 256, 1000))), True) self.analog_quadrature_demod_cf_0 = analog.quadrature_demod_cf( samp_rate / (2 * math.pi * fsk_deviation / 8.0)) ################################################## # Connections ################################################## self.connect((self.analog_quadrature_demod_cf_0, 0), (self.digital_binary_slicer_fb_0, 0)) self.connect((self.analog_random_source_x_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.analog_simple_squelch_cc_0, 0), (self.analog_quadrature_demod_cf_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_vco_f_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_sub_xx_0, 1)) self.connect((self.blocks_delay_0, 0), (self.qtgui_time_sink_x_1, 2)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_repeat_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_sub_xx_0, 0), (self.qtgui_time_sink_x_1, 1)) self.connect((self.blocks_throttle_0, 0), (self.blocks_uchar_to_float_0, 0)) self.connect((self.blocks_uchar_to_float_0, 0), (self.blocks_delay_0, 0)) self.connect((self.blocks_uchar_to_float_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.blocks_uchar_to_float_1, 0), (self.blocks_sub_xx_0, 0)) self.connect((self.blocks_uchar_to_float_1, 0), (self.qtgui_time_sink_x_1, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_repeat_0, 0)) self.connect((self.blocks_vco_f_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.digital_binary_slicer_fb_0, 0), (self.blocks_uchar_to_float_1, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.analog_simple_squelch_cc_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.blocks_multiply_const_vxx_0, 0))
def multiply_const_ff(N): k = 3.3 op = blocks.multiply_const_ff(k) tb = helper(N, op, gr.sizeof_float, gr.sizeof_float, 1, 1) return tb
def __init__(self): gr.top_block.__init__(self) #rt = gr.enable_realtime_scheduling() # Adam Laurie self.select = True # set to True to use SELECT before initial QUERY #self.mask = '111' # SELECT bit mask (up to 256 bits, e.g. '10100'). empty mask matches all tags. self.mask = '' ######## Variables ######### self.dac_rate = 1e6 # DAC rate self.adc_rate = 100e6 / 50 # ADC rate (2MS/s complex samples) self.decim = 5 # Decimation (downsampling factor) self.ampl = 0.1 # Output signal amplitude (signal power vary for different RFX900 cards) self.freq = 910e6 # Modulation frequency (can be set between 902-920) self.rx_gain = 20 # RX Gain (gain at receiver) self.tx_gain = 0 # RFX900 no Tx gain option self.usrp_address_source = "addr=192.168.10.2,recv_frame_size=256" self.usrp_address_sink = "addr=192.168.10.2,recv_frame_size=256" # Each FM0 symbol consists of ADC_RATE/BLF samples (2e6/40e3 = 50 samples) # 10 samples per symbol after matched filtering and decimation self.num_taps = [1] * 25 # matched to half symbol period ######## File sinks for debugging (1 for each block) ######### self.file_sink_source = blocks.file_sink(gr.sizeof_gr_complex * 1, "../misc/data/source", False) self.file_sink_matched_filter = blocks.file_sink( gr.sizeof_gr_complex * 1, "../misc/data/matched_filter", False) self.file_sink_gate = blocks.file_sink(gr.sizeof_gr_complex * 1, "../misc/data/gate", False) self.file_sink_decoder = blocks.file_sink(gr.sizeof_gr_complex * 1, "../misc/data/decoder", False) self.file_sink_reader = blocks.file_sink(gr.sizeof_float * 1, "../misc/data/reader", False) ######## Blocks ######### self.matched_filter = filter.fir_filter_ccc(self.decim, self.num_taps) self.gate = rfid.gate(int(self.adc_rate / self.decim)) self.tag_decoder = rfid.tag_decoder(int(self.adc_rate / self.decim)) self.reader = rfid.reader(int(self.adc_rate / self.decim), int(self.dac_rate), self.select, self.mask) self.amp = blocks.multiply_const_ff(self.ampl) self.to_complex = blocks.float_to_complex() if (DEBUG == False): # Real Time Execution # USRP blocks self.u_source() self.u_sink() ######## Connections ######### self.connect(self.source, self.matched_filter) self.connect(self.matched_filter, self.gate) self.connect(self.gate, self.tag_decoder) self.connect((self.tag_decoder, 0), self.reader) self.connect(self.reader, self.amp) self.connect(self.amp, self.to_complex) self.connect(self.to_complex, self.sink) #File sinks for logging (Remove comments to log data) #self.connect(self.source, self.file_sink_source) else: # Offline Data self.file_source = blocks.file_source( gr.sizeof_gr_complex * 1, "../misc/data/file_source_test", False) ## instead of uhd.usrp_source self.file_sink = blocks.file_sink( gr.sizeof_gr_complex * 1, "../misc/data/file_sink", False) ## instead of uhd.usrp_sink ######## Connections ######### self.connect(self.file_source, self.matched_filter) self.connect(self.matched_filter, self.gate) self.connect(self.gate, self.tag_decoder) self.connect((self.tag_decoder, 0), self.reader) self.connect(self.reader, self.amp) self.connect(self.amp, self.to_complex) self.connect(self.to_complex, self.file_sink) #File sinks for logging #self.connect(self.gate, self.file_sink_gate) self.connect((self.tag_decoder, 1), self.file_sink_decoder) # (Do not comment this line)
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) usage="%prog: [options] [input_filename]. \n If you don't specify an input filename the usrp will be used as source\n " \ "Make sure your input capture file contains interleaved shorts not complex floats" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate") parser.add_option("-f", "--freq", type="eng_float", default=519.25e6, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-c", "--contrast", type="eng_float", default=1.0, help="set contrast (default is 1.0)") parser.add_option("-b", "--brightness", type="eng_float", default=0.0, help="set brightness (default is 0)") parser.add_option("-p", "--pal", action="store_true", default=False, help="PAL video format (this is the default)") parser.add_option("-n", "--ntsc", action="store_true", default=False, help="NTSC video format") parser.add_option( "-o", "--out-filename", type="string", default="sdl", help= "For example out_raw_uchar.gray. If you don't specify an output filename you will get a video_sink_sdl realtime output window. You then need to have gr-video-sdl installed)" ) parser.add_option("-r", "--repeat", action="store_false", default=True, help="repeat file in a loop") parser.add_option("", "--freq-min", type="eng_float", default=50.25e6, help="Set a minimum frequency [default=%default]") parser.add_option("", "--freq-max", type="eng_float", default=900.25e6, help="Set a maximum frequency [default=%default]") (options, args) = parser.parse_args() if not ((len(args) == 1) or (len(args) == 0)): parser.print_help() sys.exit(1) if len(args) == 1: filename = args[0] else: filename = None self.frame = frame self.panel = panel self.contrast = options.contrast self.brightness = options.brightness self.state = "FREQ" self.freq = 0 self.tv_freq_min = options.freq_min self.tv_freq_max = options.freq_max # build graph self.u = None if not (options.out_filename == "sdl"): options.repeat = False usrp_rate = options.samp_rate if not ((filename is None) or (filename == "usrp")): # file is data source self.filesource = blocks.file_source(gr.sizeof_short, filename, options.repeat) self.istoc = blocks.interleaved_short_to_complex() self.connect(self.filesource, self.istoc) self.src = self.istoc options.gain = 0.0 self.gain = 0.0 else: # use a UHD device self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if (options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if (options.antenna): self.u.set_antenna(options.antenna, 0) self.u.set_samp_rate(usrp_rate) dev_rate = self.u.get_samp_rate() if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start() + g.stop()) / 2.0 self.src = self.u self.gain = options.gain f2uc = blocks.float_to_uchar() # sdl window as final sink if not (options.pal or options.ntsc): options.pal = True #set default to PAL if options.pal: lines_per_frame = 625.0 frames_per_sec = 25.0 show_width = 768 elif options.ntsc: lines_per_frame = 525.0 frames_per_sec = 29.97002997 show_width = 640 width = int(usrp_rate / (lines_per_frame * frames_per_sec)) height = int(lines_per_frame) if (options.out_filename == "sdl"): #Here comes the tv screen, you have to build and install #gr-video-sdl for this (subproject of gnuradio, only in cvs #for now) try: video_sink = video_sdl.sink_uc(frames_per_sec, width, height, 0, show_width, height) except: print "gr-video-sdl is not installed" print "realtime \"sdl\" video output window is not available" raise SystemExit, 1 self.dst = video_sink else: print "You can use the imagemagick display tool to show the resulting imagesequence" print "use the following line to show the demodulated TV-signal:" print "display -depth 8 -size " +str(width)+ "x" + str(height) \ + " gray:" + options.out_filename print "(Use the spacebar to advance to next frames)" options.repeat = False file_sink = blocks.file_sink(gr.sizeof_char, options.out_filename) self.dst = file_sink self.agc = analog.agc_cc(1e-7, 1.0, 1.0) #1e-7 self.am_demod = blocks.complex_to_mag() self.set_blacklevel = blocks.add_const_ff(0.0) self.invert_and_scale = blocks.multiply_const_ff( 0.0) #-self.contrast *128.0*255.0/(200.0) # now wire it all together #sample_rate=options.width*options.height*options.framerate process_type = 'do_no_sync' if process_type == 'do_no_sync': self.connect(self.src, self.agc, self.am_demod, self.invert_and_scale, self.set_blacklevel, f2uc, self.dst) elif process_type == 'do_tv_sync_adv': #defaults: gr.tv_sync_adv (double sampling_freq, unsigned #int tv_format,bool output_active_video_only=false, bool #do_invert=false, double wanted_black_level=0.0, double #wanted_white_level=255.0, double avg_alpha=0.1, double #initial_gain=1.0, double initial_offset=0.0,bool #debug=false) #note, this block is not yet in cvs self.tv_sync_adv = gr.tv_sync_adv(usrp_rate, 0, False, False, 0.0, 255.0, 0.01, 1.0, 0.0, False) self.connect(self.src, self.am_demod, self.invert_and_scale, self.tv_sync_adv, s2f, f2uc, self.dst) elif process_type == 'do_nullsink': #self.connect (self.src, self.am_demod,self.invert_and_scale,f2uc,video_sink) c2r = blocks.complex_to_real() nullsink = blocks.null_sink(gr.sizeof_float) self.connect(self.src, c2r, nullsink) #video_sink) elif process_type == 'do_tv_sync_corr': frame_size = width * height #int(usrp_rate/25.0) nframes = 10 # 32 search_window = 20 * nframes debug = False video_alpha = 0.3 #0.1 corr_alpha = 0.3 #Note: this block is not yet in cvs tv_corr = gr.tv_correlator_ff(frame_size, nframes, search_window, video_alpha, corr_alpha, debug) shift = blocks.add_const_ff(-0.7) self.connect(self.src, self.agc, self.am_demod, tv_corr, self.invert_and_scale, self.set_blacklevel, f2uc, self.dst) else: # process_type=='do_test_image': src_vertical_bars = analog.sig_source_f(usrp_rate, analog.GR_SIN_WAVE, 10.0 * usrp_rate / 320, 255, 128) self.connect(src_vertical_bars, f2uc, self.dst) self._build_gui(vbox, usrp_rate, usrp_rate, usrp_rate) frange = self.u.get_freq_range() if (frange.start() > self.tv_freq_max or frange.stop() < self.tv_freq_min): sys.stderr.write( "Radio does not support required frequency range.\n") sys.exit(1) if (options.freq < self.tv_freq_min or options.freq > self.tv_freq_max): sys.stderr.write( "Requested frequency is outside of required frequency range.\n" ) sys.exit(1) # set initial values self.set_gain(options.gain) self.set_contrast(self.contrast) self.set_brightness(options.brightness) if not (self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def __init__(self, decoder_obj_list, threading, ann=None, puncpat='11', integration_period=10000, flush=None, rotator=None): gr.hier_block2.__init__(self, "extended_decoder", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_char)) self.blocks = [] self.ann = ann self.puncpat = puncpat self.flush = flush if (type(decoder_obj_list) == list): if (type(decoder_obj_list[0]) == list): gr.log.info("fec.extended_decoder: Parallelism must be 1.") raise AttributeError else: # If it has parallelism of 0, force it into a list of 1 decoder_obj_list = [ decoder_obj_list, ] message_collector_connected = False ##anything going through the annihilator needs shifted, uchar vals if fec.get_decoder_input_conversion(decoder_obj_list[0]) == "uchar" or \ fec.get_decoder_input_conversion(decoder_obj_list[0]) == "packed_bits": self.blocks.append(blocks.multiply_const_ff(48.0)) if fec.get_shift(decoder_obj_list[0]) != 0.0: self.blocks.append( blocks.add_const_ff(fec.get_shift(decoder_obj_list[0]))) elif fec.get_decoder_input_conversion( decoder_obj_list[0]) == "packed_bits": self.blocks.append(blocks.add_const_ff(128.0)) if fec.get_decoder_input_conversion(decoder_obj_list[0]) == "uchar" or \ fec.get_decoder_input_conversion(decoder_obj_list[0]) == "packed_bits": self.blocks.append(blocks.float_to_uchar()) const_index = 0 #index that corresponds to mod order for specinvert purposes if not self.flush: flush = 10000 else: flush = self.flush if self.ann: #ann and puncpat are strings of 0s and 1s cat = fec.ULLVector() for i in fec.read_big_bitlist(ann): cat.append(i) synd_garble = .49 idx_list = list(self.garbletable.keys()) idx_list.sort() for i in idx_list: if 1.0 / self.ann.count('1') >= i: synd_garble = self.garbletable[i] print('using syndrom garble threshold ' + str(synd_garble) + 'for conv_bit_corr_bb') print('ceiling: .0335 data garble rate') self.blocks.append( fec.conv_bit_corr_bb(cat, len(puncpat) - puncpat.count('0'), len(ann), integration_period, flush, synd_garble)) if self.puncpat != '11': self.blocks.append( fec.depuncture_bb(len(puncpat), read_bitlist(puncpat), 0)) if fec.get_decoder_input_conversion( decoder_obj_list[0]) == "packed_bits": self.blocks.append(blocks.uchar_to_float()) self.blocks.append(blocks.add_const_ff(-128.0)) self.blocks.append(digital.binary_slicer_fb()) self.blocks.append(blocks.unpacked_to_packed_bb(1, 0)) if (len(decoder_obj_list) > 1): if (fec.get_history(decoder_obj_list[0]) != 0): gr.log.info( "fec.extended_decoder: Cannot use multi-threaded parallelism on a decoder with history." ) raise AttributeError if threading == 'capillary': self.blocks.append( capillary_threaded_decoder( decoder_obj_list, fec.get_decoder_input_item_size(decoder_obj_list[0]), fec.get_decoder_output_item_size(decoder_obj_list[0]))) elif threading == 'ordinary': self.blocks.append( threaded_decoder( decoder_obj_list, fec.get_decoder_input_item_size(decoder_obj_list[0]), fec.get_decoder_output_item_size(decoder_obj_list[0]))) else: self.blocks.append( fec.decoder( decoder_obj_list[0], fec.get_decoder_input_item_size(decoder_obj_list[0]), fec.get_decoder_output_item_size(decoder_obj_list[0]))) if fec.get_decoder_output_conversion(decoder_obj_list[0]) == "unpack": self.blocks.append(blocks.packed_to_unpacked_bb( 1, gr.GR_MSB_FIRST)) self.connect((self, 0), (self.blocks[0], 0)) self.connect((self.blocks[-1], 0), (self, 0)) for i in range(len(self.blocks) - 1): self.connect((self.blocks[i], 0), (self.blocks[i + 1], 0))
def __init__( self, EbN0=0, esprit_decimation=128, fc=436e6, mx=4, my=4, n=1, phi=50, rs_decimation=8, theta=30, ): gr.top_block.__init__(self, "BER Simulation") ################################################## # Parameters ################################################## self.EbN0 = EbN0 self.esprit_decimation = esprit_decimation self.fc = fc self.mx = mx self.my = my self.n = n self.phi = phi self.rs_decimation = rs_decimation self.theta = theta ################################################## # Variables ################################################## self.sps = sps = 5 self.N_BITS = N_BITS = 1e5 self.samp_rate = samp_rate = 32000 self.noise_voltage = noise_voltage = 1.0 / math.sqrt( 1 / float(sps) * 10**(float(EbN0) / 10)) self.intdump_decim = intdump_decim = min(int(N_BITS / 10), 100000) self.const = const = digital.constellation_bpsk().base() self.alpha = alpha = 0.35 self.SKIP = SKIP = 1000 self.RAND_SEED = RAND_SEED = 42 ################################################## # Blocks ################################################## self.lilacsat1_ber_bpsk_0 = lilacsat1_ber_bpsk( bfo=12000, callsign="", ip="::", latitude=0, longitude=0, port=7355, recstart="", ) self.digital_scrambler_bb_0 = digital.scrambler_bb(0x21, 0x0, 16) self.digital_diff_encoder_bb_0 = digital.diff_encoder_bb(2) self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(2) self.digital_descrambler_bb_0 = digital.descrambler_bb(0x21, 0x00, 16) self.digital_constellation_modulator_0 = digital.generic_mod( constellation=const, differential=False, samples_per_symbol=sps, pre_diff_code=True, excess_bw=alpha, verbose=False, log=False, ) self.channels_channel_model_0 = channels.channel_model( noise_voltage=noise_voltage, frequency_offset=0.0, epsilon=1.0, taps=( 0, 0, (1 + 1j) / numpy.sqrt(2), ), noise_seed=RAND_SEED, block_tags=False, ) self.blocks_vector_to_stream_0 = blocks.vector_to_stream( gr.sizeof_gr_complex * 1, mx * my) self.blocks_vector_source_x_0 = blocks.vector_source_b([1], True, 1, []) self.blocks_vector_sink_x_0_0_0 = blocks.vector_sink_f(1, 1024) self.blocks_vector_sink_x_0_0 = blocks.vector_sink_f(1, 1024) self.blocks_vector_sink_x_0 = blocks.vector_sink_f(1, 1024) self.blocks_uchar_to_float_0 = blocks.uchar_to_float() self.blocks_stream_to_vector_0 = blocks.stream_to_vector( gr.sizeof_gr_complex * 1, mx * my) self.blocks_skiphead_0 = blocks.skiphead(gr.sizeof_char * 1, SKIP) self.blocks_pack_k_bits_bb_0 = blocks.pack_k_bits_bb(8) self.blocks_not_xx_0 = blocks.not_bb() self.blocks_multiply_const_vxx_1 = blocks.multiply_const_cc(0.1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff( 1.0 / intdump_decim) self.blocks_integrate_xx_0 = blocks.integrate_ff(intdump_decim, 1) self.blocks_head_0 = blocks.head(gr.sizeof_char * 1, int(N_BITS)) self.blocks_and_const_xx_0 = blocks.and_const_bb(1) self.beamforming_randomsampler_py_cc_0_0 = beamforming.randomsampler_py_cc( mx * my, rs_decimation) self.beamforming_phasedarray_py_cc_0 = beamforming.phasedarray_py_cc( mx, my, theta, phi, fc, 0) self.beamforming_doaesprit_py_cf_0 = beamforming.doaesprit_py_cf( 128, mx, my, fc, n) self.beamforming_beamformer_py_cc_0 = beamforming.beamformer_py_cc( mx, my, fc, 0, 0, 8 * 128) ################################################## # Connections ################################################## self.connect( (self.beamforming_beamformer_py_cc_0, 0), (self.blocks_multiply_const_vxx_1, 0), ) self.connect( (self.beamforming_doaesprit_py_cf_0, 0), (self.beamforming_beamformer_py_cc_0, 1), ) self.connect( (self.beamforming_doaesprit_py_cf_0, 1), (self.beamforming_beamformer_py_cc_0, 2), ) self.connect((self.beamforming_doaesprit_py_cf_0, 0), (self.blocks_vector_sink_x_0_0, 0)) self.connect( (self.beamforming_doaesprit_py_cf_0, 1), (self.blocks_vector_sink_x_0_0_0, 0), ) self.connect( (self.beamforming_phasedarray_py_cc_0, 0), (self.blocks_vector_to_stream_0, 0), ) self.connect( (self.beamforming_randomsampler_py_cc_0_0, 0), (self.beamforming_doaesprit_py_cf_0, 0), ) self.connect((self.blocks_and_const_xx_0, 0), (self.blocks_uchar_to_float_0, 0)) self.connect((self.blocks_head_0, 0), (self.digital_scrambler_bb_0, 0)) self.connect((self.blocks_integrate_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_vector_sink_x_0, 0)) self.connect((self.blocks_multiply_const_vxx_1, 0), (self.lilacsat1_ber_bpsk_0, 0)) self.connect((self.blocks_not_xx_0, 0), (self.blocks_and_const_xx_0, 0)) self.connect( (self.blocks_pack_k_bits_bb_0, 0), (self.digital_constellation_modulator_0, 0), ) self.connect((self.blocks_skiphead_0, 0), (self.blocks_not_xx_0, 0)) self.connect( (self.blocks_stream_to_vector_0, 0), (self.beamforming_beamformer_py_cc_0, 0), ) self.connect( (self.blocks_stream_to_vector_0, 0), (self.beamforming_randomsampler_py_cc_0_0, 0), ) self.connect((self.blocks_uchar_to_float_0, 0), (self.blocks_integrate_xx_0, 0)) self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_head_0, 0)) self.connect((self.blocks_vector_to_stream_0, 0), (self.channels_channel_model_0, 0)) self.connect((self.channels_channel_model_0, 0), (self.blocks_stream_to_vector_0, 0)) self.connect( (self.digital_constellation_modulator_0, 0), (self.beamforming_phasedarray_py_cc_0, 0), ) self.connect((self.digital_descrambler_bb_0, 0), (self.blocks_skiphead_0, 0)) self.connect((self.digital_diff_decoder_bb_0, 0), (self.digital_descrambler_bb_0, 0)) self.connect((self.digital_diff_encoder_bb_0, 0), (self.blocks_pack_k_bits_bb_0, 0)) self.connect((self.digital_scrambler_bb_0, 0), (self.digital_diff_encoder_bb_0, 0)) self.connect((self.lilacsat1_ber_bpsk_0, 0), (self.digital_diff_decoder_bb_0, 0))
def test_multiply_const_ff(self): src_data = (-1, 0, 1, 2, 3) expected_result = (-5, 0, 5, 10, 15) op = blocks.multiply_const_ff(5) self.help_ff((src_data,), expected_result, op)
def __init__(self, myfreq): gr.top_block.__init__(self) ######## Variables ######### self.dac_rate = 1e6 # DAC rate self.adc_rate = 100e6 / 50 # ADC rate (2MS/s complex samples) self.decim = 5 # Decimation (downsampling factor) self.ampl = 0.8 # Output signal amplitude (signal power vary for different RFX900 cards) self.freq = myfreq # Modulation frequency (can be set between 902-920) # self.rx_gain = -15 # RX Gain (gain at receiver) self.tx_gain = 30 # RFX900 no Tx gain option self.usrp_address_source = "addr=192.168.10.105,recv_frame_size=256" self.usrp_address_sink = "addr=192.168.10.105,recv_frame_size=256" # Each FM0 symbol consists of ADC_RATE/BLF samples (2e6/40e3 = 50 samples) # 10 samples per symbol after matched filtering and decimation self.num_taps = [1] * 25 # matched to half symbol period ######## File sinks for debugging (1 for each block) ######### self.file_sink_source = blocks.file_sink(gr.sizeof_gr_complex * 1, "../misc/data/source", False) self.file_sink_matched_filter = blocks.file_sink( gr.sizeof_gr_complex * 1, "../misc/data/matched_filter", False) self.file_sink_gate = blocks.file_sink(gr.sizeof_gr_complex * 1, "../misc/data/gate", False) self.file_sink_decoder = blocks.file_sink(gr.sizeof_gr_complex * 1, "../misc/data/decoder", False) self.file_sink_reader = blocks.file_sink(gr.sizeof_float * 1, "../misc/data/reader", False) self.file_sink_amp = blocks.file_sink(gr.sizeof_float * 1, "../misc/data/amp", False) ######## Blocks ######### self.matched_filter = filter.fir_filter_ccc(self.decim, self.num_taps) self.gate = rfid.gate(int(self.adc_rate / self.decim)) self.tag_decoder = rfid.tag_decoder(int(self.adc_rate / self.decim)) self.reader = rfid.reader(int(self.adc_rate / self.decim), int(self.dac_rate)) self.amp = blocks.multiply_const_ff(self.ampl) self.to_complex = blocks.float_to_complex() # USRP blocks self.u_source() self.u_sink() ######## Connections ######### self.connect(self.source, self.matched_filter) self.connect(self.matched_filter, self.gate) self.connect(self.gate, self.tag_decoder) self.connect((self.tag_decoder, 0), self.reader) self.connect(self.reader, self.amp) self.connect(self.amp, self.to_complex) self.connect(self.to_complex, self.sink) #File sinks for logging (Remove comments to log data) self.connect(self.source, self.file_sink_source) #File sinks for logging self.connect(self.gate, self.file_sink_gate) self.connect((self.tag_decoder, 1), self.file_sink_decoder) # (Do not comment this line) #self.connect(self.file_sink_reader, self.file_sink_reader) self.connect(self.matched_filter, self.file_sink_matched_filter) self.connect(self.amp, self.file_sink_amp)
def __init__(self): gr.top_block.__init__(self, "10Ghz 2de Garmonic with hackrf") Qt.QWidget.__init__(self) self.setWindowTitle("10Ghz 2de Garmonic with hackrf") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "The_10G_second_harmonic_hackrf") try: if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"): self.restoreGeometry( self.settings.value("geometry").toByteArray()) else: self.restoreGeometry(self.settings.value("geometry")) except: pass ################################################## # Variables ################################################## self.variable_qtgui_range_0_1 = variable_qtgui_range_0_1 = 10352560000 self.variable_qtgui_range_0_0_0_0 = variable_qtgui_range_0_0_0_0 = 50 self.variable_qtgui_range_0_0_0 = variable_qtgui_range_0_0_0 = 60 self.variable_qtgui_range_0_0 = variable_qtgui_range_0_0 = 60 self.variable_qtgui_range_0 = variable_qtgui_range_0 = 2.5e3 self.variable_qtgui_label_0 = variable_qtgui_label_0 = variable_qtgui_range_0_1 / 2 self.variable_qtgui_chooser_PTT_0 = variable_qtgui_chooser_PTT_0 = 0 self.samp_rate = samp_rate = 4800000 ################################################## # Blocks ################################################## self._variable_qtgui_range_0_1_range = Range(10338000000, 10702000000, 1, 10352560000, 200) self._variable_qtgui_range_0_1_win = RangeWidget( self._variable_qtgui_range_0_1_range, self.set_variable_qtgui_range_0_1, 'Frequency', "counter_slider", float) self.top_grid_layout.addWidget(self._variable_qtgui_range_0_1_win) self._variable_qtgui_range_0_0_0_0_range = Range(5, 60, 1, 50, 200) self._variable_qtgui_range_0_0_0_0_win = RangeWidget( self._variable_qtgui_range_0_0_0_0_range, self.set_variable_qtgui_range_0_0_0_0, 'bb_power', "counter_slider", float) self.top_grid_layout.addWidget(self._variable_qtgui_range_0_0_0_0_win) self._variable_qtgui_range_0_0_0_range = Range(5, 60, 1, 60, 200) self._variable_qtgui_range_0_0_0_win = RangeWidget( self._variable_qtgui_range_0_0_0_range, self.set_variable_qtgui_range_0_0_0, 'if_power', "counter_slider", float) self.top_grid_layout.addWidget(self._variable_qtgui_range_0_0_0_win) self._variable_qtgui_range_0_0_range = Range(10, 65, 1, 60, 200) self._variable_qtgui_range_0_0_win = RangeWidget( self._variable_qtgui_range_0_0_range, self.set_variable_qtgui_range_0_0, 'tx_power', "counter_slider", float) self.top_grid_layout.addWidget(self._variable_qtgui_range_0_0_win) self._variable_qtgui_range_0_range = Range(0, 12.5e3, 1, 2.5e3, 200) self._variable_qtgui_range_0_win = RangeWidget( self._variable_qtgui_range_0_range, self.set_variable_qtgui_range_0, 'div', "counter_slider", float) self.top_grid_layout.addWidget(self._variable_qtgui_range_0_win) # Create the options list self._variable_qtgui_chooser_PTT_0_options = ( 0, 1, ) # Create the labels list self._variable_qtgui_chooser_PTT_0_labels = ( 'TX', 'RX', ) # Create the combo box self._variable_qtgui_chooser_PTT_0_tool_bar = Qt.QToolBar(self) self._variable_qtgui_chooser_PTT_0_tool_bar.addWidget( Qt.QLabel('PTT' + ": ")) self._variable_qtgui_chooser_PTT_0_combo_box = Qt.QComboBox() self._variable_qtgui_chooser_PTT_0_tool_bar.addWidget( self._variable_qtgui_chooser_PTT_0_combo_box) for _label in self._variable_qtgui_chooser_PTT_0_labels: self._variable_qtgui_chooser_PTT_0_combo_box.addItem(_label) self._variable_qtgui_chooser_PTT_0_callback = lambda i: Qt.QMetaObject.invokeMethod( self._variable_qtgui_chooser_PTT_0_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._variable_qtgui_chooser_PTT_0_options.index(i) )) self._variable_qtgui_chooser_PTT_0_callback( self.variable_qtgui_chooser_PTT_0) self._variable_qtgui_chooser_PTT_0_combo_box.currentIndexChanged.connect( lambda i: self.set_variable_qtgui_chooser_PTT_0( self._variable_qtgui_chooser_PTT_0_options[i])) # Create the radio buttons self.top_grid_layout.addWidget( self._variable_qtgui_chooser_PTT_0_tool_bar) self._variable_qtgui_label_0_tool_bar = Qt.QToolBar(self) if None: self._variable_qtgui_label_0_formatter = None else: self._variable_qtgui_label_0_formatter = lambda x: eng_notation.num_to_str( x) self._variable_qtgui_label_0_tool_bar.addWidget( Qt.QLabel('freq' + ": ")) self._variable_qtgui_label_0_label = Qt.QLabel( str( self._variable_qtgui_label_0_formatter( self.variable_qtgui_label_0))) self._variable_qtgui_label_0_tool_bar.addWidget( self._variable_qtgui_label_0_label) self.top_grid_layout.addWidget(self._variable_qtgui_label_0_tool_bar) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=10, decimation=1, taps=None, fractional_bw=None) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name 1) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(False) self.qtgui_freq_sink_x_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in range(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win) self.osmosdr_sink_0 = osmosdr.sink(args="numchan=" + str(1) + " " + 'hackrf=0') self.osmosdr_sink_0.set_time_unknown_pps(osmosdr.time_spec_t()) self.osmosdr_sink_0.set_sample_rate(samp_rate) self.osmosdr_sink_0.set_center_freq(variable_qtgui_range_0_1 / 2, 0) self.osmosdr_sink_0.set_freq_corr(0, 0) self.osmosdr_sink_0.set_gain(variable_qtgui_range_0_0, 0) self.osmosdr_sink_0.set_if_gain(variable_qtgui_range_0_0_0, 0) self.osmosdr_sink_0.set_bb_gain(variable_qtgui_range_0_0_0_0, 0) self.osmosdr_sink_0.set_antenna('', 0) self.osmosdr_sink_0.set_bandwidth(0, 0) self.blocks_wavfile_source_0 = blocks.wavfile_source( '/home/anton/gnuradio-grc-examples/test_audio.wav', True) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1, 48000, True) self.blocks_selector_0 = blocks.selector(gr.sizeof_gr_complex * 1, variable_qtgui_chooser_PTT_0, 0) self.blocks_selector_0.set_enabled(True) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(1) self.analog_nbfm_tx_0_0 = analog.nbfm_tx( audio_rate=48000, quad_rate=480000, tau=75e-6, max_dev=variable_qtgui_range_0, fh=-1.0, ) self.analog_const_source_x_0_0 = analog.sig_source_c( 0, analog.GR_CONST_WAVE, 0, 0, 0) ################################################## # Connections ################################################## self.connect((self.analog_const_source_x_0_0, 0), (self.blocks_selector_0, 1)) self.connect((self.analog_nbfm_tx_0_0, 0), (self.blocks_selector_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_selector_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.analog_nbfm_tx_0_0, 0)) self.connect((self.blocks_wavfile_source_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.osmosdr_sink_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.qtgui_freq_sink_x_0, 0))
def __init__(self): gr.top_block.__init__(self, "Not titled yet") Qt.QWidget.__init__(self) self.setWindowTitle("Not titled yet") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "m2k_am_to_fm_pluto") try: if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"): self.restoreGeometry( self.settings.value("geometry").toByteArray()) else: self.restoreGeometry(self.settings.value("geometry")) except: pass ################################################## # Variables ################################################## self.tx_samp_rate = tx_samp_rate = 600000 self.tx_freq = tx_freq = 90e6 self.samp_rate = samp_rate = 10000000 self.rr_interp = rr_interp = 8 self.rr_decim = rr_decim = 5 self.osr = osr = 5 self.lp_decim = lp_decim = 10 self.if_freq = if_freq = 475000 self.fx_decim = fx_decim = 10 ################################################## # Blocks ################################################## self.rational_resampler_xxx_0 = filter.rational_resampler_fff( interpolation=rr_interp, decimation=rr_decim, taps=[128], fractional_bw=0.8) self.qtgui_time_sink_x_0_1 = qtgui.time_sink_f( 4096, #size samp_rate / (osr * fx_decim), #samp_rate "Demodulated Baseband", #name 1 #number of inputs ) self.qtgui_time_sink_x_0_1.set_update_time(0.10) self.qtgui_time_sink_x_0_1.set_y_axis(-1, 1) self.qtgui_time_sink_x_0_1.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0_1.enable_tags(True) self.qtgui_time_sink_x_0_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0_1.enable_autoscale(True) self.qtgui_time_sink_x_0_1.enable_grid(True) self.qtgui_time_sink_x_0_1.enable_axis_labels(True) self.qtgui_time_sink_x_0_1.enable_control_panel(True) self.qtgui_time_sink_x_0_1.enable_stem_plot(False) labels = [ 'Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5', 'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10' ] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ 'blue', 'red', 'green', 'black', 'cyan', 'magenta', 'yellow', 'dark red', 'dark green', 'dark blue' ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] for i in range(1): if len(labels[i]) == 0: self.qtgui_time_sink_x_0_1.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0_1.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0_1.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0_1.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0_1.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0_1.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0_1.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_1_win = sip.wrapinstance( self.qtgui_time_sink_x_0_1.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_1_win) self.qtgui_time_sink_x_0_0 = qtgui.time_sink_c( 4096, #size samp_rate / (osr * fx_decim), #samp_rate "Translated I.F.", #name 1 #number of inputs ) self.qtgui_time_sink_x_0_0.set_update_time(0.10) self.qtgui_time_sink_x_0_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0_0.enable_tags(True) self.qtgui_time_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0_0.enable_autoscale(True) self.qtgui_time_sink_x_0_0.enable_grid(True) self.qtgui_time_sink_x_0_0.enable_axis_labels(True) self.qtgui_time_sink_x_0_0.enable_control_panel(True) self.qtgui_time_sink_x_0_0.enable_stem_plot(False) labels = [ 'Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5', 'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10' ] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ 'blue', 'red', 'green', 'black', 'cyan', 'magenta', 'yellow', 'dark red', 'dark green', 'dark blue' ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] for i in range(2): if len(labels[i]) == 0: if (i % 2 == 0): self.qtgui_time_sink_x_0_0.set_line_label( i, "Re{{Data {0}}}".format(i / 2)) else: self.qtgui_time_sink_x_0_0.set_line_label( i, "Im{{Data {0}}}".format(i / 2)) else: self.qtgui_time_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_0_win) self.m2k_analog_in_source_0 = m2k.analog_in_source( 'ip:192.168.3.1', 16384, [True, False], [0, 0], samp_rate, osr, 4, True, True, [2, 0], [0, 0], 0, 0, [0, 0]) self.low_pass_filter_0 = filter.fir_filter_fff( lp_decim, firdes.low_pass(1, samp_rate / (osr * fx_decim), 3000, 500, firdes.WIN_HAMMING, 6.76)) self.iio_pluto_sink_0 = iio.pluto_sink('ip:192.168.2.1', int(tx_freq), tx_samp_rate, 200000, 32768, False, 0, '', True) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_fcc( fx_decim, firdes.low_pass(1, (samp_rate / osr), (samp_rate / osr) / (2 * fx_decim), 20000), if_freq, samp_rate / osr) self.dc_blocker_xx_0 = filter.dc_blocker_ff(32, True) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(1) self.blocks_complex_to_mag_1 = blocks.complex_to_mag(1) self.audio_sink_0 = audio.sink(32000, '', False) self.analog_wfm_tx_0 = analog.wfm_tx( audio_rate=int(samp_rate / (osr * fx_decim * lp_decim)), quad_rate=tx_samp_rate, tau=75e-6, max_dev=150e3, fh=-1.0, ) ################################################## # Connections ################################################## self.connect((self.analog_wfm_tx_0, 0), (self.iio_pluto_sink_0, 0)) self.connect((self.blocks_complex_to_mag_1, 0), (self.dc_blocker_xx_0, 0)) self.connect((self.blocks_complex_to_mag_1, 0), (self.qtgui_time_sink_x_0_1, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 1)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.dc_blocker_xx_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.blocks_complex_to_mag_1, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.qtgui_time_sink_x_0_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.analog_wfm_tx_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.m2k_analog_in_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_multiply_const_vxx_0, 0))
def __init__(self): gr.top_block.__init__(self, "Lab 4 Task 2a") Qt.QWidget.__init__(self) self.setWindowTitle("Lab 4 Task 2a") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "lab4_task2a") try: if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"): self.restoreGeometry( self.settings.value("geometry").toByteArray()) else: self.restoreGeometry(self.settings.value("geometry")) except: pass ################################################## # Variables ################################################## self.samp_rate = samp_rate = 320000 self.amplitude = amplitude = 0.01 ################################################## # Blocks ################################################## self._amplitude_range = Range(0.01, 1, 0.01, 0.01, 200) self._amplitude_win = RangeWidget(self._amplitude_range, self.set_amplitude, 'amplitude', "counter_slider", float) self.top_grid_layout.addWidget(self._amplitude_win) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_f( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw 'Differential Output', #name 1) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(False) self.qtgui_freq_sink_x_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in range(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win) self.blocks_transcendental_0 = blocks.transcendental('tanh', "float") self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1, samp_rate, True) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(10e-4) self.blocks_file_source_0 = blocks.file_source( gr.sizeof_float * 1, '/home/ipsit/Documents/EE 340/Lab 4/Input.bin', True, 0, 0) self.blocks_file_source_0.set_begin_tag(pmt.PMT_NIL) self.blocks_add_xx_0 = blocks.add_vff(1) self.analog_sig_source_x_0 = analog.sig_source_f( samp_rate, analog.GR_COS_WAVE, 48000, amplitude, 0, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_transcendental_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_throttle_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.blocks_transcendental_0, 0), (self.blocks_throttle_0, 0))
def __init__(self): global output_gains, gain_adjust, gain_adjust_fullrate, mod_adjust gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-a", "--args", type="string", default="", help="device args") parser.add_option("-A", "--alt-modulator-rate", type="int", default=50000, help="when mod rate is not a submutiple of IF rate") parser.add_option("-b", "--bt", type="float", default=0.5, help="specify bt value") parser.add_option("-c", "--config-file", type="string", default=None, help="specify the config file name") parser.add_option("-f", "--file1", type="string", default=None, help="specify the input file slot 1") parser.add_option("-F", "--file2", type="string", default=None, help="specify the input file slot 2 (DMR)") parser.add_option("-g", "--gain", type="float", default=1.0, help="input gain") parser.add_option("-i", "--if-rate", type="int", default=480000, help="output rate to sdr") parser.add_option( "-I", "--audio-input", type="string", default="", help="pcm input device name. E.g., hw:0,0 or /dev/dsp") parser.add_option("-k", "--symbol-sink", type="string", default=None, help="write symbols to file (optional)") parser.add_option("-N", "--gains", type="string", default=None, help="gain settings") parser.add_option( "-O", "--audio-output", type="string", default="default", help="pcm output device name. E.g., hw:0,0 or /dev/dsp") parser.add_option("-o", "--output-file", type="string", default=None, help="specify the output file") parser.add_option( "-p", "--protocol", type="choice", default=None, choices=('dmr', 'dstar', 'p25', 'ysf', 'nxdn48', 'nxdn96'), help="specify protocol: dmr, dstar, p25, ysf, nxdn48, nxdn96") parser.add_option("-q", "--frequency-correction", type="float", default=0.0, help="ppm") parser.add_option("-Q", "--frequency", type="float", default=0.0, help="Hz") parser.add_option("-r", "--repeat", action="store_true", default=False, help="input file repeat") parser.add_option("-P", "--plot-audio", action="store_true", default=False, help="scope input") parser.add_option("-R", "--fullrate-mode", action="store_true", default=False, help="ysf fullrate") parser.add_option("-s", "--modulator-rate", type="int", default=48000, help="must be submultiple of IF rate - see also -A") parser.add_option("-S", "--alsa-rate", type="int", default=48000, help="sound source/sink sample rate") parser.add_option("-t", "--test", type="string", default=None, help="test pattern symbol file") parser.add_option("-v", "--verbose", type="int", default=0, help="additional output") (options, args) = parser.parse_args() max_inputs = 1 if options.protocol is None: print('protocol [-p] option missing') sys.exit(0) if options.protocol == 'ysf' or options.protocol == 'dmr' or options.protocol == 'dstar' or options.protocol.startswith( 'nxdn'): assert options.config_file # dstar, dmr, ysf, and nxdn require config file ("-c FILENAME" option) output_gain = output_gains[options.protocol] if options.test: # input file is in symbols of size=char ENCODER = blocks.file_source(gr.sizeof_char, options.test, True) elif options.protocol == 'dmr': max_inputs = 2 ENCODER = op25_repeater.ambe_encoder_sb(options.verbose) ENCODER2 = op25_repeater.ambe_encoder_sb(options.verbose) ENCODER2.set_gain_adjust(gain_adjust['dmr']) DMR = op25_repeater.dmr_bs_tx_bb(options.verbose, options.config_file) self.connect(ENCODER, (DMR, 0)) self.connect(ENCODER2, (DMR, 1)) elif options.protocol == 'dstar': ENCODER = op25_repeater.dstar_tx_sb(options.verbose, options.config_file) elif options.protocol == 'p25': ENCODER = op25_repeater.vocoder( True, # 0=Decode,True=Encode False, # Verbose flag 0, # flex amount "", # udp ip address 0, # udp port False) # dump raw u vectors elif options.protocol == 'ysf': ENCODER = op25_repeater.ysf_tx_sb(options.verbose, options.config_file, options.fullrate_mode) if options.fullrate_mode: ENCODER.set_gain_adjust(gain_adjust_fullrate['ysf']) else: ENCODER.set_gain_adjust(gain_adjust['ysf']) elif options.protocol.startswith('nxdn'): ENCODER = op25_repeater.nxdn_tx_sb(options.verbose, options.config_file, options.protocol == 'nxdn96') if options.protocol == 'p25' and not options.test: ENCODER.set_gain_adjust(gain_adjust_fullrate[options.protocol]) elif not options.test and not options.protocol == 'ysf': ENCODER.set_gain_adjust(gain_adjust[options.protocol]) nfiles = 0 if options.file1: nfiles += 1 if options.file2 and options.protocol == 'dmr': nfiles += 1 if nfiles < max_inputs and not options.test: AUDIO = audio.source(options.alsa_rate, options.audio_input) lpf_taps = filter.firdes.low_pass(1.0, options.alsa_rate, 3400.0, 3400 * 0.1, filter.firdes.WIN_HANN) audio_rate = 8000 AUDIO_DECIM = filter.fir_filter_fff( int(options.alsa_rate / audio_rate), lpf_taps) AUDIO_SCALE = blocks.multiply_const_ff(32767.0 * options.gain) AUDIO_F2S = blocks.float_to_short() self.connect(AUDIO, AUDIO_DECIM, AUDIO_SCALE, AUDIO_F2S) if options.plot_audio: PLOT_F = float_sink_f() self.connect(AUDIO, PLOT_F) if options.file1: IN1 = blocks.file_source(gr.sizeof_short, options.file1, options.repeat) S2F1 = blocks.short_to_float() AMP1 = blocks.multiply_const_ff(options.gain) F2S1 = blocks.float_to_short() self.connect(IN1, S2F1, AMP1, F2S1, ENCODER) elif not options.test: self.connect(AUDIO_F2S, ENCODER) if options.protocol == 'dmr': if options.file2: IN2 = blocks.file_source(gr.sizeof_short, options.file2, options.repeat) S2F2 = blocks.short_to_float() AMP2 = blocks.multiply_const_ff(options.gain) F2S2 = blocks.float_to_short() self.connect(IN2, S2F2, AMP2, F2S2, ENCODER2) else: self.connect(AUDIO_F2S, ENCODER2) MOD = p25_mod_bf(output_sample_rate=options.modulator_rate, dstar=(options.protocol == 'dstar'), bt=options.bt, rc=RC_FILTER[options.protocol]) AMP = blocks.multiply_const_ff(output_gain) if options.output_file: OUT = blocks.file_sink(gr.sizeof_float, options.output_file) elif not options.args: OUT = audio.sink(options.alsa_rate, options.audio_output) if options.symbol_sink: SYMBOL_SINK = blocks.file_sink(gr.sizeof_char, options.symbol_sink) if options.protocol == 'dmr' and not options.test: self.connect(DMR, MOD) if options.symbol_sink: self.connect(DMR, SYMBOL_SINK) else: self.connect(ENCODER, MOD) if options.symbol_sink: self.connect(ENCODER, SYMBOL_SINK) if options.args: self.setup_sdr_output(options, mod_adjust[options.protocol]) f1 = float(options.if_rate) / options.modulator_rate i1 = int(options.if_rate / options.modulator_rate) if f1 - i1 > 1e-3: f1 = float(options.if_rate) / options.alt_modulator_rate i1 = int(options.if_rate / options.alt_modulator_rate) if f1 - i1 > 1e-3: print( '*** Error, sdr rate %d not an integer multiple of alt modulator rate %d - ratio=%f' % (options.if_rate, options.alt_modulator_rate, f1)) sys.exit(0) a_resamp = filter.pfb.arb_resampler_fff( options.alt_modulator_rate / float(options.modulator_rate)) sys.stderr.write( 'adding resampler for rate change %d ===> %d\n' % (options.modulator_rate, options.alt_modulator_rate)) interp = filter.rational_resampler_fff( options.if_rate / options.alt_modulator_rate, 1) self.connect(MOD, AMP, a_resamp, interp, self.fm_modulator, self.u) else: interp = filter.rational_resampler_fff( options.if_rate // options.modulator_rate, 1) self.connect(MOD, AMP, interp, self.fm_modulator, self.u) else: self.connect(MOD, AMP, OUT)
def __init__(self, *args, **kwds): # begin wxGlade: MyFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) # Menu Bar self.frame_1_menubar = wx.MenuBar() self.SetMenuBar(self.frame_1_menubar) wxglade_tmp_menu = wx.Menu() self.Exit = wx.MenuItem(wxglade_tmp_menu, ID_EXIT, "Exit", "Exit", wx.ITEM_NORMAL) wxglade_tmp_menu.AppendItem(self.Exit) self.frame_1_menubar.Append(wxglade_tmp_menu, "File") # Menu Bar end self.panel_1 = wx.Panel(self, -1) self.button_1 = wx.Button(self, ID_BUTTON_1, "LSB") self.button_2 = wx.Button(self, ID_BUTTON_2, "USB") self.button_3 = wx.Button(self, ID_BUTTON_3, "AM") self.button_4 = wx.Button(self, ID_BUTTON_4, "CW") self.button_5 = wx.ToggleButton(self, ID_BUTTON_5, "Upper") self.slider_fcutoff_hi = wx.Slider(self, ID_SLIDER_1, 0, -15798, 15799, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.button_6 = wx.ToggleButton(self, ID_BUTTON_6, "Lower") self.slider_fcutoff_lo = wx.Slider(self, ID_SLIDER_2, 0, -15799, 15798, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.panel_5 = wx.Panel(self, -1) self.label_1 = wx.StaticText(self, -1, " Band\nCenter") self.text_ctrl_1 = wx.TextCtrl(self, ID_TEXT_1, "") self.panel_6 = wx.Panel(self, -1) self.panel_7 = wx.Panel(self, -1) self.panel_2 = wx.Panel(self, -1) self.button_7 = wx.ToggleButton(self, ID_BUTTON_7, "Freq") self.slider_3 = wx.Slider(self, ID_SLIDER_3, 3000, 0, 6000) self.spin_ctrl_1 = wx.SpinCtrl(self, ID_SPIN_1, "", min=0, max=100) self.button_8 = wx.ToggleButton(self, ID_BUTTON_8, "Vol") self.slider_4 = wx.Slider(self, ID_SLIDER_4, 0, 0, 500) self.slider_5 = wx.Slider(self, ID_SLIDER_5, 0, 0, 20) self.button_9 = wx.ToggleButton(self, ID_BUTTON_9, "Time") self.button_11 = wx.Button(self, ID_BUTTON_11, "Rew") self.button_10 = wx.Button(self, ID_BUTTON_10, "Fwd") self.panel_3 = wx.Panel(self, -1) self.label_2 = wx.StaticText(self, -1, "PGA ") self.panel_4 = wx.Panel(self, -1) self.panel_8 = wx.Panel(self, -1) self.panel_9 = wx.Panel(self, -1) self.panel_10 = wx.Panel(self, -1) self.panel_11 = wx.Panel(self, -1) self.panel_12 = wx.Panel(self, -1) self.__set_properties() self.__do_layout() # end wxGlade parser = OptionParser(option_class=eng_option) parser.add_option("", "--args", type="string", default="addr=''", help="Arguments for UHD device, [default=%default]") parser.add_option("", "--spec", type="string", default="A:0", help="UHD device subdev spec, [default=%default]") parser.add_option("-c", "--ddc-freq", type="eng_float", default=3.9e6, help="set Rx DDC frequency to FREQ", metavar="FREQ") parser.add_option( "-s", "--samp-rate", type="eng_float", default=256000, help="set sample rate (bandwidth) [default=%default]") parser.add_option("-a", "--audio_file", default="", help="audio output file", metavar="FILE") parser.add_option("-r", "--radio_file", default="", help="radio output file", metavar="FILE") parser.add_option("-i", "--input_file", default="", help="radio input file", metavar="FILE") parser.add_option( "-O", "--audio-output", type="string", default="", help="audio output device name. E.g., hw:0,0, /dev/dsp, or pulse") parser.add_option("", "--audio-rate", type="int", default=32000, help="audio output sample rate [default=%default]") (options, args) = parser.parse_args() self.usrp_center = options.ddc_freq self.input_rate = input_rate = options.samp_rate self.slider_range = input_rate * 0.9375 self.f_lo = self.usrp_center - (self.slider_range / 2) self.f_hi = self.usrp_center + (self.slider_range / 2) self.af_sample_rate = options.audio_rate self.tb = gr.top_block() # radio variables, initial conditions self.frequency = self.usrp_center # these map the frequency slider (0-6000) to the actual range self.f_slider_offset = self.f_lo self.f_slider_scale = 10000 / 250 self.spin_ctrl_1.SetRange(self.f_lo, self.f_hi) self.text_ctrl_1.SetValue(str(int(self.usrp_center))) self.slider_5.SetValue(0) self.AM_mode = False self.slider_3.SetValue( (self.frequency - self.f_slider_offset) / self.f_slider_scale) self.spin_ctrl_1.SetValue(int(self.frequency)) POWERMATE = True try: self.pm = powermate.powermate(self) except: sys.stderr.write("Unable to find PowerMate or Contour Shuttle\n") POWERMATE = False if POWERMATE: powermate.EVT_POWERMATE_ROTATE(self, self.on_rotate) powermate.EVT_POWERMATE_BUTTON(self, self.on_pmButton) self.active_button = 7 # command line options if options.audio_file == "": SAVE_AUDIO_TO_FILE = False else: SAVE_AUDIO_TO_FILE = True if options.radio_file == "": SAVE_RADIO_TO_FILE = False else: SAVE_RADIO_TO_FILE = True if options.input_file == "": self.PLAY_FROM_USRP = True else: self.PLAY_FROM_USRP = False if self.PLAY_FROM_USRP: self.src = uhd.usrp_source(options.args, stream_args=uhd.stream_args('fc32')) self.src.set_samp_rate(input_rate) self.src.set_subdev_spec(options.spec) self.input_rate = input_rate = self.src.get_samp_rate() self.src.set_center_freq(self.usrp_center, 0) self.tune_offset = 0 fir_decim = long(self.input_rate / self.af_sample_rate) rrate = self.af_sample_rate / (self.input_rate / float(fir_decim)) print "Actual Input Rate: ", self.input_rate print "FIR DECIM: ", fir_decim print "Remaining resampling: ", rrate print "Sampling Rate at Audio Sink: ", (self.input_rate / fir_decim) * rrate print "Request Rate at Audio Sink: ", self.af_sample_rate else: self.src = blocks.file_source(gr.sizeof_short, options.input_file) self.tune_offset = 2200 # 2200 works for 3.5-4Mhz band # convert rf data in interleaved short int form to complex s2ss = blocks.stream_to_streams(gr.sizeof_short, 2) s2f1 = blocks.short_to_float() s2f2 = blocks.short_to_float() src_f2c = blocks.float_to_complex() self.tb.connect(self.src, s2ss) self.tb.connect((s2ss, 0), s2f1) self.tb.connect((s2ss, 1), s2f2) self.tb.connect(s2f1, (src_f2c, 0)) self.tb.connect(s2f2, (src_f2c, 1)) fir_decim = long(self.input_rate / self.af_sample_rate) rrate = self.af_sample_rate / (self.input_rate / float(fir_decim)) print "FIR DECIM: ", fir_decim print "Remaining resampling: ", rrate print "Sampling Rate at Audio Sink: ", (self.input_rate / fir_decim) * rrate print "Request Rate at Audio Sink: ", self.af_sample_rate # save radio data to a file if SAVE_RADIO_TO_FILE: radio_file = blocks.file_sink(gr.sizeof_short, options.radio_file) self.tb.connect(self.src, radio_file) # 2nd DDC xlate_taps = filter.firdes.low_pass ( \ 1.0, input_rate, 16e3, 4e3, filter.firdes.WIN_HAMMING ) self.xlate = filter.freq_xlating_fir_filter_ccf ( \ fir_decim, xlate_taps, self.tune_offset, input_rate ) nflts = 32 audio_coeffs = filter.firdes.complex_band_pass( nflts, # gain self.input_rate * nflts, # sample rate -3000.0, # low cutoff 0.0, # high cutoff 100.0, # transition filter.firdes.WIN_KAISER, 7.0) # window self.slider_fcutoff_hi.SetValue(0) self.slider_fcutoff_lo.SetValue(-3000) # Filter and resample based on actual radio's sample rate self.audio_filter = filter.pfb.arb_resampler_ccc(rrate, audio_coeffs) # Main +/- 16Khz spectrum display self.fft = fftsink2.fft_sink_c(self.panel_2, fft_size=512, sample_rate=self.af_sample_rate, average=True, size=(640, 240), baseband_freq=self.usrp_center) c2f = blocks.complex_to_float() # AM branch self.sel_am = blocks.multiply_const_cc(0) # the following frequencies turn out to be in radians/sample # analog.pll_refout_cc(alpha,beta,min_freq,max_freq) # suggested alpha = X, beta = .25 * X * X pll = analog.pll_refout_cc( .05, (2. * math.pi * 7.5e3 / self.af_sample_rate), (2. * math.pi * 6.5e3 / self.af_sample_rate)) self.pll_carrier_scale = blocks.multiply_const_cc(complex(10, 0)) am_det = blocks.multiply_cc() # these are for converting +7.5kHz to -7.5kHz # for some reason blocks.conjugate_cc() adds noise ?? c2f2 = blocks.complex_to_float() c2f3 = blocks.complex_to_float() f2c = blocks.float_to_complex() phaser1 = blocks.multiply_const_ff(1) phaser2 = blocks.multiply_const_ff(-1) # filter for pll generated carrier pll_carrier_coeffs = filter.firdes.complex_band_pass( 2.0, # gain self.af_sample_rate, # sample rate 7400, # low cutoff 7600, # high cutoff 100, # transition filter.firdes.WIN_HAMMING) # window self.pll_carrier_filter = filter.fir_filter_ccc(1, pll_carrier_coeffs) self.sel_sb = blocks.multiply_const_ff(1) combine = blocks.add_ff() #AGC sqr1 = blocks.multiply_ff() intr = filter.iir_filter_ffd([.004, 0], [0, .999]) offset = blocks.add_const_ff(1) agc = blocks.divide_ff() self.scale = blocks.multiply_const_ff(0.00001) dst = audio.sink(long(self.af_sample_rate), options.audio_output) if self.PLAY_FROM_USRP: self.tb.connect(self.src, self.xlate, self.fft) else: self.tb.connect(src_f2c, self.xlate, self.fft) self.tb.connect(self.xlate, self.audio_filter, self.sel_am, (am_det, 0)) self.tb.connect(self.sel_am, pll, self.pll_carrier_scale, self.pll_carrier_filter, c2f3) self.tb.connect((c2f3, 0), phaser1, (f2c, 0)) self.tb.connect((c2f3, 1), phaser2, (f2c, 1)) self.tb.connect(f2c, (am_det, 1)) self.tb.connect(am_det, c2f2, (combine, 0)) self.tb.connect(self.audio_filter, c2f, self.sel_sb, (combine, 1)) self.tb.connect(combine, self.scale) self.tb.connect(self.scale, (sqr1, 0)) self.tb.connect(self.scale, (sqr1, 1)) self.tb.connect(sqr1, intr, offset, (agc, 1)) self.tb.connect(self.scale, (agc, 0)) self.tb.connect(agc, blocks.null_sink(gr.sizeof_float)) self.tb.connect(c2f3, dst) if SAVE_AUDIO_TO_FILE: f_out = blocks.file_sink(gr.sizeof_short, options.audio_file) sc1 = blocks.multiply_const_ff(64000) f2s1 = blocks.float_to_short() self.tb.connect(agc, sc1, f2s1, f_out) self.tb.start() # left click to re-tune self.fft.win.plotter.Bind(wx.EVT_LEFT_DOWN, self.Click) # start a timer to check for web commands if WEB_CONTROL: self.timer = UpdateTimer(self, 1000) # every 1000 mSec, 1 Sec wx.EVT_BUTTON(self, ID_BUTTON_1, self.set_lsb) wx.EVT_BUTTON(self, ID_BUTTON_2, self.set_usb) wx.EVT_BUTTON(self, ID_BUTTON_3, self.set_am) wx.EVT_BUTTON(self, ID_BUTTON_4, self.set_cw) wx.EVT_BUTTON(self, ID_BUTTON_10, self.fwd) wx.EVT_BUTTON(self, ID_BUTTON_11, self.rew) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_5, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_6, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_7, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_8, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_9, self.on_button) wx.EVT_SLIDER(self, ID_SLIDER_1, self.set_filter) wx.EVT_SLIDER(self, ID_SLIDER_2, self.set_filter) wx.EVT_SLIDER(self, ID_SLIDER_3, self.slide_tune) wx.EVT_SLIDER(self, ID_SLIDER_4, self.set_volume) wx.EVT_SLIDER(self, ID_SLIDER_5, self.set_pga) wx.EVT_SPINCTRL(self, ID_SPIN_1, self.spin_tune) wx.EVT_MENU(self, ID_EXIT, self.TimeToQuit)
def __init__(self): gr.top_block.__init__(self, "Cross Correlation Test") Qt.QWidget.__init__(self) self.setWindowTitle("Cross Correlation Test") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "xcorr_test_opencl") try: if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"): self.restoreGeometry( self.settings.value("geometry").toByteArray()) else: self.restoreGeometry(self.settings.value("geometry")) except: pass ################################################## # Variables ################################################## self.delay_0 = delay_0 = 0 self.samp_rate = samp_rate = 2.4e6 self.max_search = max_search = 500 self.lag = lag = 10 self.gain = gain = 32 self.delay_label = delay_label = delay_0 self.corr_frame_size = corr_frame_size = 8192 self.corr_frame_decim = corr_frame_decim = 6 self.center_freq = center_freq = 162.425e6 ################################################## # Blocks ################################################## self._lag_range = Range(0, 20, 1, 10, 200) self._lag_win = RangeWidget(self._lag_range, self.set_lag, 'lag', "counter_slider", int) self.top_grid_layout.addWidget(self._lag_win, 0, 2, 1, 2) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(2, 4): self.top_grid_layout.setColumnStretch(c, 1) self._gain_range = Range(0, 60, 2, 32, 200) self._gain_win = RangeWidget(self._gain_range, self.set_gain, 'Gain', "counter_slider", float) self.top_grid_layout.addWidget(self._gain_win, 0, 0, 1, 2) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 2): self.top_grid_layout.setColumnStretch(c, 1) self.xcorrelate_ExtractDelay_0 = xcorrelate.ExtractDelay( 0, self.set_delay_0, False) self.uhd_usrp_source_0 = uhd.usrp_source( ",".join(("", "num_recv_frames=128")), uhd.stream_args( cpu_format="fc32", args='', channels=list(range(0, 1)), ), ) self.uhd_usrp_source_0.set_center_freq(center_freq, 0) self.uhd_usrp_source_0.set_gain(gain, 0) self.uhd_usrp_source_0.set_antenna('RX2', 0) self.uhd_usrp_source_0.set_samp_rate(samp_rate) # No synchronization enforced. self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 64, #size samp_rate, #samp_rate "", #name 3 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.10) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0.enable_tags(True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(True) self.qtgui_time_sink_x_0.enable_grid(False) self.qtgui_time_sink_x_0.enable_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(False) self.qtgui_time_sink_x_0.enable_stem_plot(False) labels = [ 'Reference', 'Signal 1', 'Correlated', 'Signal 4', 'Signal 5', 'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10' ] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ 'blue', 'red', 'green', 'black', 'cyan', 'magenta', 'yellow', 'dark red', 'dark green', 'dark blue' ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] for i in range(3): if len(labels[i]) == 0: self.qtgui_time_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win, 4, 0, 2, 4) for r in range(4, 6): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 4): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_number_sink_0_0_0 = qtgui.number_sink( gr.sizeof_float, 0, qtgui.NUM_GRAPH_HORIZ, 1) self.qtgui_number_sink_0_0_0.set_update_time(0.10) self.qtgui_number_sink_0_0_0.set_title("Improvement") labels = ['', '', '', '', '', '', '', '', '', ''] units = ['', '', '', '', '', '', '', '', '', ''] colors = [("blue", "red"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in range(1): self.qtgui_number_sink_0_0_0.set_min(i, -10) self.qtgui_number_sink_0_0_0.set_max(i, 10) self.qtgui_number_sink_0_0_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0_0_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0_0_0.set_label(i, labels[i]) self.qtgui_number_sink_0_0_0.set_unit(i, units[i]) self.qtgui_number_sink_0_0_0.set_factor(i, factor[i]) self.qtgui_number_sink_0_0_0.enable_autoscale(False) self._qtgui_number_sink_0_0_0_win = sip.wrapinstance( self.qtgui_number_sink_0_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_number_sink_0_0_0_win, 7, 0, 1, 3) for r in range(7, 8): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 3): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_number_sink_0 = qtgui.number_sink(gr.sizeof_float, 0, qtgui.NUM_GRAPH_HORIZ, 2) self.qtgui_number_sink_0.set_update_time(0.10) self.qtgui_number_sink_0.set_title('Max Power') labels = ['Ref Signal', 'Correlated', '', '', '', '', '', '', '', ''] units = ['', '', '', '', '', '', '', '', '', ''] colors = [("blue", "red"), ("blue", "red"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in range(2): self.qtgui_number_sink_0.set_min(i, -100) self.qtgui_number_sink_0.set_max(i, -10) self.qtgui_number_sink_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0.set_label(i, labels[i]) self.qtgui_number_sink_0.set_unit(i, units[i]) self.qtgui_number_sink_0.set_factor(i, factor[i]) self.qtgui_number_sink_0.enable_autoscale(False) self._qtgui_number_sink_0_win = sip.wrapinstance( self.qtgui_number_sink_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_number_sink_0_win, 6, 0, 1, 3) for r in range(6, 7): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 3): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype center_freq, #fc samp_rate, #bw "", #name 3) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(False) self.qtgui_freq_sink_x_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) labels = [ 'Reference', 'Delayed', 'Correlated', '', '', '', '', '', '', '' ] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in range(3): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 1, 0, 2, 4) for r in range(1, 3): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 4): self.top_grid_layout.setColumnStretch(c, 1) self.logpwrfft_x_0_0 = logpwrfft.logpwrfft_c(sample_rate=samp_rate, fft_size=1024, ref_scale=2, frame_rate=30, avg_alpha=1.0, average=False) self.logpwrfft_x_0 = logpwrfft.logpwrfft_c(sample_rate=samp_rate, fft_size=1024, ref_scale=2, frame_rate=30, avg_alpha=1.0, average=False) self._delay_label_tool_bar = Qt.QToolBar(self) if None: self._delay_label_formatter = None else: self._delay_label_formatter = lambda x: str(x) self._delay_label_tool_bar.addWidget( Qt.QLabel('Correcting Delay' + ": ")) self._delay_label_label = Qt.QLabel( str(self._delay_label_formatter(self.delay_label))) self._delay_label_tool_bar.addWidget(self._delay_label_label) self.top_grid_layout.addWidget(self._delay_label_tool_bar, 0, 4, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(4, 5): self.top_grid_layout.setColumnStretch(c, 1) self.clenabled_XCorrelate_0 = clenabled.clXCorrelate( 1, 1, 0, 0, False, 2, 8192, 2, gr.sizeof_float, 600, 6) self.blocks_sub_xx_0 = blocks.sub_ff(1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(-1) self.blocks_max_xx_0_0 = blocks.max_ff(1024, 1) self.blocks_max_xx_0 = blocks.max_ff(1024, 1) self.blocks_delay_0_0_0 = blocks.delay(gr.sizeof_gr_complex * 1, delay_0) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1, lag) self.blocks_complex_to_mag_0_0_0 = blocks.complex_to_mag(1) self.blocks_complex_to_mag_0_0 = blocks.complex_to_mag(1) self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1) self.blocks_add_xx_0 = blocks.add_vcc(1) ################################################## # Connections ################################################## self.msg_connect((self.clenabled_XCorrelate_0, 'corr'), (self.xcorrelate_ExtractDelay_0, 'corr')) self.connect((self.blocks_add_xx_0, 0), (self.blocks_complex_to_mag_0_0_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.logpwrfft_x_0_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.qtgui_freq_sink_x_0, 2)) self.connect((self.blocks_complex_to_mag_0, 0), (self.clenabled_XCorrelate_0, 0)) self.connect((self.blocks_complex_to_mag_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blocks_complex_to_mag_0_0, 0), (self.clenabled_XCorrelate_0, 1)) self.connect((self.blocks_complex_to_mag_0_0, 0), (self.qtgui_time_sink_x_0, 1)) self.connect((self.blocks_complex_to_mag_0_0_0, 0), (self.qtgui_time_sink_x_0, 2)) self.connect((self.blocks_delay_0, 0), (self.blocks_complex_to_mag_0_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_delay_0_0_0, 0)) self.connect((self.blocks_delay_0, 0), (self.qtgui_freq_sink_x_0, 1)) self.connect((self.blocks_delay_0_0_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_max_xx_0, 0), (self.blocks_sub_xx_0, 0)) self.connect((self.blocks_max_xx_0, 0), (self.qtgui_number_sink_0, 0)) self.connect((self.blocks_max_xx_0_0, 0), (self.blocks_sub_xx_0, 1)) self.connect((self.blocks_max_xx_0_0, 0), (self.qtgui_number_sink_0, 1)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.qtgui_number_sink_0_0_0, 0)) self.connect((self.blocks_sub_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.logpwrfft_x_0, 0), (self.blocks_max_xx_0, 0)) self.connect((self.logpwrfft_x_0_0, 0), (self.blocks_max_xx_0_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.blocks_complex_to_mag_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.blocks_delay_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.logpwrfft_x_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.qtgui_freq_sink_x_0, 0))
def __init__(self): gr.top_block.__init__(self, "FM_Rec") Qt.QWidget.__init__(self) self.setWindowTitle("FM_Rec") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "top_block") try: if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"): self.restoreGeometry( self.settings.value("geometry").toByteArray()) else: self.restoreGeometry(self.settings.value("geometry")) except: pass ################################################## # Variables ################################################## self.volume = volume = 50 self.samp_rate = samp_rate = 2000000 self.gain = gain = 40 self.frequency = frequency = 89.3e6 self.down_rate = down_rate = 250000 self.bandwidth = bandwidth = 1536 ################################################## # Blocks ################################################## self._volume_range = Range(0, 100, 1, 50, 200) self._volume_win = RangeWidget(self._volume_range, self.set_volume, 'Volume', "counter_slider", float) self.top_grid_layout.addWidget(self._volume_win, 0, 2, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(2, 3): self.top_grid_layout.setColumnStretch(c, 1) self._gain_range = Range(20, 59, 1, 40, 200) self._gain_win = RangeWidget(self._gain_range, self.set_gain, 'Gain', "counter_slider", int) self.top_grid_layout.addWidget(self._gain_win, 0, 1, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) # Create the options list self._frequency_options = ( 94.4e6, 96.7e6, 89.3e6, 91.8e6, ) # Create the labels list self._frequency_labels = ( 'hr1', 'hr2', 'hr3', 'radio X', ) # Create the combo box self._frequency_tool_bar = Qt.QToolBar(self) self._frequency_tool_bar.addWidget(Qt.QLabel('Frequenz' + ": ")) self._frequency_combo_box = Qt.QComboBox() self._frequency_tool_bar.addWidget(self._frequency_combo_box) for _label in self._frequency_labels: self._frequency_combo_box.addItem(_label) self._frequency_callback = lambda i: Qt.QMetaObject.invokeMethod( self._frequency_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._frequency_options.index(i))) self._frequency_callback(self.frequency) self._frequency_combo_box.currentIndexChanged.connect( lambda i: self.set_frequency(self._frequency_options[i])) # Create the radio buttons self.top_grid_layout.addWidget(self._frequency_tool_bar, 0, 0, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) # Create the options list self._bandwidth_options = [200, 300, 600, 1536, 5000, 6000, 7000, 8000] # Create the labels list self._bandwidth_labels = [ '200', '300', '600', '1536', '5000', '6000', '7000', '8000' ] # Create the combo box self._bandwidth_tool_bar = Qt.QToolBar(self) self._bandwidth_tool_bar.addWidget(Qt.QLabel('Bandwidth' + ": ")) self._bandwidth_combo_box = Qt.QComboBox() self._bandwidth_tool_bar.addWidget(self._bandwidth_combo_box) for _label in self._bandwidth_labels: self._bandwidth_combo_box.addItem(_label) self._bandwidth_callback = lambda i: Qt.QMetaObject.invokeMethod( self._bandwidth_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._bandwidth_options.index(i))) self._bandwidth_callback(self.bandwidth) self._bandwidth_combo_box.currentIndexChanged.connect( lambda i: self.set_bandwidth(self._bandwidth_options[i])) # Create the radio buttons self.top_grid_layout.addWidget(self._bandwidth_tool_bar, 0, 3, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(3, 4): self.top_grid_layout.setColumnStretch(c, 1) self.rational_resampler_xxx_0 = filter.rational_resampler_fff( interpolation=24, decimation=250, taps=None, fractional_bw=None) self.qtgui_waterfall_sink_x_0_0 = qtgui.waterfall_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype frequency, #fc samp_rate / 50, #bw "", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_0_0.set_update_time(0.10) self.qtgui_waterfall_sink_x_0_0.enable_grid(False) self.qtgui_waterfall_sink_x_0_0.enable_axis_labels(True) labels = ['', '', '', '', '', '', '', '', '', ''] colors = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in range(1): if len(labels[i]) == 0: self.qtgui_waterfall_sink_x_0_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_0_0.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_0_0.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_0_0.set_intensity_range(-140, 10) self._qtgui_waterfall_sink_x_0_0_win = sip.wrapinstance( self.qtgui_waterfall_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_0_0_win, 1, 0, 2, 4) for r in range(1, 3): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 4): self.top_grid_layout.setColumnStretch(c, 1) self.msz_rsp1a_0 = msz.rsp1a(frequency, samp_rate, gain, bandwidth) self.low_pass_filter_0 = filter.fir_filter_ccf( int(samp_rate / down_rate), firdes.low_pass(2, samp_rate, 100e3, 10e3, firdes.WIN_KAISER, 6.76)) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(volume / 100) self.audio_sink_0 = audio.sink(24000, '', True) self.analog_wfm_rcv_0 = analog.wfm_rcv( quad_rate=down_rate, audio_decimation=1, ) ################################################## # Connections ################################################## self.connect((self.analog_wfm_rcv_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.analog_wfm_rcv_0, 0)) self.connect((self.msz_rsp1a_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.msz_rsp1a_0, 0), (self.qtgui_waterfall_sink_x_0_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_multiply_const_vxx_0, 0))
def __init__(self): gr.top_block.__init__(self, "Top Block", catch_exceptions=True) Qt.QWidget.__init__(self) self.setWindowTitle("Top Block") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "top_block") try: if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"): self.restoreGeometry(self.settings.value("geometry").toByteArray()) else: self.restoreGeometry(self.settings.value("geometry")) except: pass ################################################## # Variables ################################################## self.samp_rate = samp_rate = 20e6 self.channel_width = channel_width = 200e3 self.channel_freq = channel_freq = 96.5e6 self.center_freq = center_freq = 97.9e6 self.audio_gain = audio_gain = 0.5 ################################################## # Blocks ################################################## self._audio_gain_range = Range(0, 5, 0.1, 0.5, 200) self._audio_gain_win = RangeWidget(self._audio_gain_range, self.set_audio_gain, 'audio_gain', "counter_slider", float, QtCore.Qt.Horizontal) self.top_grid_layout.addWidget(self._audio_gain_win) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=12, decimation=5, taps=[], fractional_bw=-1.0) self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c( 1024, #size window.WIN_BLACKMAN_hARRIS, #wintype center_freq, #fc samp_rate, #bw "freq", #name 1, None # parent ) self.qtgui_freq_sink_x_0_0.set_update_time(0.10) self.qtgui_freq_sink_x_0_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0_0.enable_autoscale(False) self.qtgui_freq_sink_x_0_0.enable_grid(True) self.qtgui_freq_sink_x_0_0.set_fft_average(0.1) self.qtgui_freq_sink_x_0_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0_0.enable_control_panel(True) self.qtgui_freq_sink_x_0_0.set_fft_window_normalized(True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue"] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in range(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_0_win) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 1024, #size window.WIN_BLACKMAN_hARRIS, #wintype center_freq, #fc samp_rate, #bw "center", #name 1, None # parent ) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(True) self.qtgui_freq_sink_x_0.set_fft_average(0.1) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(True) self.qtgui_freq_sink_x_0.set_fft_window_normalized(True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue"] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in range(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win) self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + '' ) self.osmosdr_source_0.set_time_unknown_pps(osmosdr.time_spec_t()) self.osmosdr_source_0.set_sample_rate(samp_rate) self.osmosdr_source_0.set_center_freq(center_freq, 0) self.osmosdr_source_0.set_freq_corr(0, 0) self.osmosdr_source_0.set_dc_offset_mode(0, 0) self.osmosdr_source_0.set_iq_balance_mode(0, 0) self.osmosdr_source_0.set_gain_mode(False, 0) self.osmosdr_source_0.set_gain(0, 0) self.osmosdr_source_0.set_if_gain(20, 0) self.osmosdr_source_0.set_bb_gain(20, 0) self.osmosdr_source_0.set_antenna('', 0) self.osmosdr_source_0.set_bandwidth(0, 0) self.low_pass_filter_0 = filter.fir_filter_ccf( int(samp_rate/channel_width), firdes.low_pass( 1, samp_rate, 75e3, 25e3, window.WIN_HAMMING, 6.76)) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(audio_gain) self.audio_sink_0 = audio.sink(48000, '', True) self.analog_wfm_rcv_0 = analog.wfm_rcv( quad_rate=480e3, audio_decimation=10, ) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, center_freq - channel_freq, 1, 0, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.analog_wfm_rcv_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.qtgui_freq_sink_x_0_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.analog_wfm_rcv_0, 0))
def __init__(self): gr.top_block.__init__(self, "HFS first channel") ################################################## # Variables ################################################## self.snr = snr = 10 self.vol = vol = 1 self.tau_a = tau_a = 1/100. self.tau = tau = 0.002 self.snr_out_func = snr_out_func = ([0]*3) self.samp_rate_0 = samp_rate_0 = 48000 self.samp_rate = samp_rate = 48000 self.out_rms_func = out_rms_func = 0 self.noSpread = noSpread = 1 self.kN = kN = pow(10.0, (-snr/20.0)) self.freqShift = freqShift = 0.0 self.fd = fd = 1 self.en_noise = en_noise = 0 self.doppler_ir = doppler_ir = [0.0016502763167573274, 0.0018854799389366934, 0.002149957633383614, 0.0024466994528029662, 0.002778907461425479, 0.003149998028185868, 0.003563602180973301, 0.00402356375450247, 0.004533935060796761, 0.0050989698117900155, 0.005723113028669535, 0.006410987682800636, 0.007167377828853199, 0.007997208012493867, 0.008905518763040982, 0.00989743801603955, 0.010978148351927763, 0.012152849984840378, 0.013426719489994542, 0.014804864318746317, 0.016292273216847054, 0.01789376273305468, 0.019613920081278834, 0.021457042698902442, 0.023427074925696508, 0.025527542310538734, 0.027761484135525694, 0.030131384827462734, 0.03263910500345486, 0.035285812968654906, 0.03807191754835305, 0.04099700319171279, 0.04405976832879332, 0.04725796799434838, 0.050588361749672524, 0.05404666793605477, 0.057627525278984175, 0.06132446283016882, 0.06512987918400244, 0.0690350318359975, 0.073030037462906, 0.07710388379815894, 0.08124445365265866, 0.08543856149104095, 0.08967200281887802, 0.0939296164688993, 0.09819535969651079, 0.10245239580938088, 0.10668319386560887, 0.1108696397832219, 0.11499315801386097, 0.11903484274903825, 0.12297559745183839, 0.12679628134392928, 0.1304778613306593, 0.13400156771907581, 0.1373490519778611, 0.14050254470705797, 0.14344501193124823, 0.14616030780428022, 0.14863332181791858, 0.15085011864154488, 0.1527980687853246, 0.154465968374505, 0.15584414644656272, 0.15692455833401583, 0.15770086387153975, 0.1581684893637365, 0.15832467246620405, 0.1581684893637365, 0.15770086387153975, 0.15692455833401583, 0.15584414644656272, 0.154465968374505, 0.1527980687853246, 0.15085011864154488, 0.14863332181791858, 0.14616030780428022, 0.14344501193124823, 0.14050254470705797, 0.1373490519778611, 0.13400156771907581, 0.1304778613306593, 0.12679628134392928, 0.12297559745183839, 0.11903484274903825, 0.11499315801386097, 0.1108696397832219, 0.10668319386560887, 0.10245239580938088, 0.09819535969651079, 0.0939296164688993, 0.08967200281887802, 0.08543856149104095, 0.08124445365265866, 0.07710388379815894, 0.073030037462906, 0.0690350318359975, 0.06512987918400244, 0.06132446283016882, 0.057627525278984175, 0.05404666793605477, 0.050588361749672524, 0.04725796799434838, 0.04405976832879332, 0.04099700319171279, 0.03807191754835305, 0.035285812968654906, 0.03263910500345486, 0.030131384827462734, 0.027761484135525694, 0.025527542310538734, 0.023427074925696508, 0.021457042698902442, 0.019613920081278834, 0.01789376273305468, 0.016292273216847054, 0.014804864318746317, 0.013426719489994542, 0.012152849984840378, 0.010978148351927763, 0.00989743801603955, 0.008905518763040982, 0.007997208012493867, 0.007167377828853199, 0.006410987682800636, 0.005723113028669535, 0.0050989698117900155, 0.004533935060796761, 0.00402356375450247, 0.003563602180973301, 0.003149998028185868, 0.002778907461425479, 0.0024466994528029662, 0.002149957633383614, 0.0018854799389366934, 0.0016502763167573274] self.ampl = ampl = [[1.0, 0.0], [1.0, 0.0]] ################################################## # Blocks ################################################## self.snr_out = blocks.probe_signal_f() self.out_rms = blocks.probe_signal_f() def _snr_out_func_probe(): while True: val = self.snr_out.level() try: self.set_snr_out_func(val) except AttributeError: pass time.sleep(1.0 / (10)) _snr_out_func_thread = threading.Thread(target=_snr_out_func_probe) _snr_out_func_thread.daemon = True _snr_out_func_thread.start() self.single_pole_iir_filter_xx_0_0 = filter.single_pole_iir_filter_ff(2*pi*tau_a/samp_rate, 1) self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff(2*pi*tau_a/samp_rate, 1) def _out_rms_func_probe(): while True: val = self.out_rms.level() try: self.set_out_rms_func(val) except AttributeError: pass time.sleep(1.0 / (10)) _out_rms_func_thread = threading.Thread(target=_out_rms_func_probe) _out_rms_func_thread.daemon = True _out_rms_func_thread.start() self.low_pass_filter_2_0 = filter.fir_filter_ccf( 1, firdes.low_pass( 1, samp_rate, 1550, 100, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_1_1 = filter.interp_fir_filter_ccf( int(samp_rate/100), firdes.low_pass( ampl[1][0]*(samp_rate/100.0), samp_rate, 50, 25, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_1_0_0 = filter.interp_fir_filter_ccf( int(samp_rate/100), firdes.low_pass( ampl[1][1]*(samp_rate/100.0), samp_rate, 50, 25, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0_0 = filter.fir_filter_ccf( 1, firdes.low_pass( 1, samp_rate, 1750+100, 600, firdes.WIN_HAMMING, 6.76)) self.epy_block_0_0_0_0 = epy_block_0_0_0_0.blk(fd=fd) self.epy_block_0_0_0 = epy_block_0_0_0.blk(fd=fd) self.blocks_selector_0_1 = blocks.selector(gr.sizeof_gr_complex*1,noSpread,0) self.blocks_selector_0_1.set_enabled(True) self.blocks_selector_0_0_0 = blocks.selector(gr.sizeof_gr_complex*1,noSpread,0) self.blocks_selector_0_0_0.set_enabled(True) self.blocks_rms_xx_0_1 = blocks.rms_cf(2*pi*tau_a*100/samp_rate) self.blocks_rms_xx_0_0 = blocks.rms_ff(2*pi*tau_a*10/samp_rate) self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, 1, 0) self.blocks_multiply_xx_1_0 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_1 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_0_1 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_0_0_1 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_0_0_0_1 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0_0_0_0_0_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_3 = blocks.multiply_const_ff(en_noise) self.blocks_multiply_const_vxx_2_0_0 = blocks.multiply_const_cc(vol) self.blocks_multiply_const_vxx_2_0 = blocks.multiply_const_cc(vol) self.blocks_multiply_const_vxx_1_0 = blocks.multiply_const_ff(2 * sqrt(ampl[1][0]**2 + ampl[1][1]**2)*2) self.blocks_multiply_const_vxx_0_0_0_0 = blocks.multiply_const_ff(0.5) self.blocks_multiply_const_vxx_0_0_0 = blocks.multiply_const_ff(0.5) self.blocks_float_to_complex_1_0 = blocks.float_to_complex(1) self.blocks_float_to_complex_0_0 = blocks.float_to_complex(1) self.blocks_divide_xx_1 = blocks.divide_ff(1) self.blocks_delay_0_0 = blocks.delay(gr.sizeof_gr_complex*1, int(tau*samp_rate)) self.blocks_complex_to_real_0_0_0 = blocks.complex_to_real(1) self.blocks_complex_to_real_0_0 = blocks.complex_to_real(1) self.blocks_complex_to_mag_squared_2_0 = blocks.complex_to_mag_squared(1) self.blocks_complex_to_mag_squared_2 = blocks.complex_to_mag_squared(1) self.blocks_add_xx_1 = blocks.add_vff(1) self.blocks_add_xx_0_1 = blocks.add_vcc(1) self.blocks_add_xx_0_0_0 = blocks.add_vcc(1) self.audio_source_1 = audio.source(samp_rate, 'in2', True) self.audio_sink_0_0 = audio.sink(samp_rate, 'out4', False) self.audio_sink_0 = audio.sink(samp_rate, 'out1', False) self.analog_sig_source_x_2_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 1850, 1, 0, 0) self.analog_sig_source_x_1_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, freqShift, 1, 0, 0) self.analog_sig_source_x_0_0_1 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, -1850, 1, 0, 0) self.analog_sig_source_x_0_0_0_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 1850, 1, 0, 0) self.analog_noise_source_x_1_0 = analog.noise_source_c(analog.GR_GAUSSIAN, 1e-0*kN, 13) self.analog_fastnoise_source_x_4 = analog.fastnoise_source_c(analog.GR_GAUSSIAN, 1, 11, 8192) self.analog_fastnoise_source_x_3 = analog.fastnoise_source_c(analog.GR_GAUSSIAN, 1, 10, 8192) self.analog_fastnoise_source_x_0 = analog.fastnoise_source_f(analog.GR_GAUSSIAN, 0.3, 0, 8192) self.analog_const_source_x_2_0 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 0) self.analog_const_source_x_1_1 = analog.sig_source_c(0, analog.GR_CONST_WAVE, 0, 0, ampl[1][0]) self.analog_const_source_x_1_0_0 = analog.sig_source_c(0, analog.GR_CONST_WAVE, 0, 0, ampl[1][1]) self.analog_const_source_x_0_0 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 0) ################################################## # Connections ################################################## self.connect((self.analog_const_source_x_0_0, 0), (self.blocks_float_to_complex_0_0, 1)) self.connect((self.analog_const_source_x_1_0_0, 0), (self.blocks_selector_0_0_0, 1)) self.connect((self.analog_const_source_x_1_1, 0), (self.blocks_selector_0_1, 1)) self.connect((self.analog_const_source_x_2_0, 0), (self.blocks_float_to_complex_1_0, 1)) self.connect((self.analog_fastnoise_source_x_0, 0), (self.blocks_multiply_const_vxx_3, 0)) self.connect((self.analog_fastnoise_source_x_3, 0), (self.epy_block_0_0_0, 0)) self.connect((self.analog_fastnoise_source_x_4, 0), (self.epy_block_0_0_0_0, 0)) self.connect((self.analog_noise_source_x_1_0, 0), (self.low_pass_filter_2_0, 0)) self.connect((self.analog_sig_source_x_0_0_0_0, 0), (self.blocks_multiply_xx_0_0_1, 1)) self.connect((self.analog_sig_source_x_0_0_1, 0), (self.blocks_multiply_xx_0_1, 1)) self.connect((self.analog_sig_source_x_1_0, 0), (self.blocks_multiply_xx_1_0, 0)) self.connect((self.analog_sig_source_x_2_0, 0), (self.blocks_multiply_xx_0_0_0_0_0_0, 1)) self.connect((self.audio_source_1, 0), (self.blocks_float_to_complex_0_0, 0)) self.connect((self.blocks_add_xx_0_0_0, 0), (self.blocks_multiply_const_vxx_2_0, 0)) self.connect((self.blocks_add_xx_0_1, 0), (self.blocks_multiply_xx_1_0, 1)) self.connect((self.blocks_add_xx_1, 0), (self.audio_sink_0, 0)) self.connect((self.blocks_add_xx_1, 0), (self.blocks_rms_xx_0_0, 0)) self.connect((self.blocks_complex_to_mag_squared_2, 0), (self.single_pole_iir_filter_xx_0, 0)) self.connect((self.blocks_complex_to_mag_squared_2_0, 0), (self.single_pole_iir_filter_xx_0_0, 0)) self.connect((self.blocks_complex_to_real_0_0, 0), (self.blocks_multiply_const_vxx_0_0_0, 0)) self.connect((self.blocks_complex_to_real_0_0_0, 0), (self.blocks_multiply_const_vxx_0_0_0_0, 0)) self.connect((self.blocks_delay_0_0, 0), (self.blocks_multiply_xx_0_0_0_0_1, 0)) self.connect((self.blocks_divide_xx_1, 0), (self.blocks_nlog10_ff_0, 0)) self.connect((self.blocks_float_to_complex_0_0, 0), (self.blocks_multiply_xx_0_1, 0)) self.connect((self.blocks_float_to_complex_1_0, 0), (self.blocks_multiply_xx_0_0_0_0_0_0, 2)) self.connect((self.blocks_multiply_const_vxx_0_0_0, 0), (self.blocks_add_xx_1, 0)) self.connect((self.blocks_multiply_const_vxx_0_0_0_0, 0), (self.audio_sink_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_1_0, 0), (self.blocks_float_to_complex_1_0, 0)) self.connect((self.blocks_multiply_const_vxx_2_0, 0), (self.blocks_complex_to_real_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_2_0_0, 0), (self.blocks_complex_to_real_0_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_3, 0), (self.blocks_add_xx_1, 1)) self.connect((self.blocks_multiply_xx_0_0_0_0_0_0, 0), (self.blocks_add_xx_0_0_0, 1)) self.connect((self.blocks_multiply_xx_0_0_0_0_0_0, 0), (self.blocks_complex_to_mag_squared_2_0, 0)) self.connect((self.blocks_multiply_xx_0_0_0_0_0_0, 0), (self.blocks_multiply_const_vxx_2_0_0, 0)) self.connect((self.blocks_multiply_xx_0_0_0_0_1, 0), (self.blocks_add_xx_0_1, 1)) self.connect((self.blocks_multiply_xx_0_0_0_1, 0), (self.blocks_add_xx_0_1, 0)) self.connect((self.blocks_multiply_xx_0_0_1, 0), (self.blocks_delay_0_0, 0)) self.connect((self.blocks_multiply_xx_0_0_1, 0), (self.blocks_multiply_xx_0_0_0_1, 0)) self.connect((self.blocks_multiply_xx_0_0_1, 0), (self.blocks_rms_xx_0_1, 0)) self.connect((self.blocks_multiply_xx_0_1, 0), (self.low_pass_filter_0_0, 0)) self.connect((self.blocks_multiply_xx_1_0, 0), (self.blocks_add_xx_0_0_0, 0)) self.connect((self.blocks_multiply_xx_1_0, 0), (self.blocks_complex_to_mag_squared_2, 0)) self.connect((self.blocks_nlog10_ff_0, 0), (self.snr_out, 0)) self.connect((self.blocks_rms_xx_0_0, 0), (self.out_rms, 0)) self.connect((self.blocks_rms_xx_0_1, 0), (self.blocks_multiply_const_vxx_1_0, 0)) self.connect((self.blocks_selector_0_0_0, 0), (self.blocks_multiply_xx_0_0_0_0_1, 1)) self.connect((self.blocks_selector_0_1, 0), (self.blocks_multiply_xx_0_0_0_1, 1)) self.connect((self.epy_block_0_0_0, 0), (self.low_pass_filter_1_1, 0)) self.connect((self.epy_block_0_0_0_0, 0), (self.low_pass_filter_1_0_0, 0)) self.connect((self.low_pass_filter_0_0, 0), (self.blocks_multiply_xx_0_0_1, 0)) self.connect((self.low_pass_filter_1_0_0, 0), (self.blocks_selector_0_0_0, 0)) self.connect((self.low_pass_filter_1_1, 0), (self.blocks_selector_0_1, 0)) self.connect((self.low_pass_filter_2_0, 0), (self.blocks_multiply_xx_0_0_0_0_0_0, 0)) self.connect((self.single_pole_iir_filter_xx_0, 0), (self.blocks_divide_xx_1, 0)) self.connect((self.single_pole_iir_filter_xx_0_0, 0), (self.blocks_divide_xx_1, 1))
def __init__(self, dest=_def_dest, do_imbe=_def_do_imbe, num_ambe=_def_num_ambe, wireshark_host=_def_wireshark_host, udp_port=_def_udp_port, do_msgq=False, msgq=None, audio_output=_def_audio_output, debug=_def_debug, nocrypt=_def_nocrypt): """ Hierarchical block for P25 decoding. @param debug: debug level @type debug: int """ gr.hier_block2.__init__( self, "p25_demod_c", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(0, 0, 0)) # Output signature assert 0 <= num_ambe <= _def_max_tdma_timeslots assert not (num_ambe > 1 and dest != 'wav') self.debug = debug self.dest = dest do_output = False do_audio_output = False do_phase2_tdma = False do_nocrypt = nocrypt if dest == 'wav': do_output = True if do_imbe: do_audio_output = True if num_ambe > 0: do_phase2_tdma = True if msgq is None: msgq = gr.msg_queue(1) self.p25_decoders = [] self.audio_s2f = [] self.scaler = [] self.audio_sink = [] self.xorhash = [] num_decoders = 1 if num_ambe > 1: num_decoders += num_ambe - 1 for slot in xrange(num_decoders): self.p25_decoders.append( op25_repeater.p25_frame_assembler(wireshark_host, udp_port, debug, do_imbe, do_output, do_msgq, msgq, do_audio_output, do_phase2_tdma, do_nocrypt)) self.p25_decoders[slot].set_slotid(slot) self.xorhash.append('') if dest == 'wav': filename = 'default-%f-%d.wav' % (time.time(), slot) n_channels = 1 sample_rate = 8000 bits_per_sample = 16 self.audio_s2f.append( blocks.short_to_float()) # another ridiculous conversion self.scaler.append(blocks.multiply_const_ff(1 / 32768.0)) self.audio_sink.append( blocks.wavfile_sink(filename, n_channels, sample_rate, bits_per_sample)) self.connect(self, self.p25_decoders[slot], self.audio_s2f[slot], self.scaler[slot], self.audio_sink[slot]) elif dest == 'audio': self.connect(self, self.p25_decoders[slot])
def __init__(self): gr.top_block.__init__(self, "Stereo FM receiver and RDS Decoder", catch_exceptions=True) Qt.QWidget.__init__(self) self.setWindowTitle("Stereo FM receiver and RDS Decoder") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "rds_rx") try: if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"): self.restoreGeometry( self.settings.value("geometry").toByteArray()) else: self.restoreGeometry(self.settings.value("geometry")) except: pass ################################################## # Variables ################################################## self.freq_offset = freq_offset = 250000 self.freq = freq = 88.5 self.volume = volume = 0 self.samp_rate = samp_rate = 2000000 self.gain = gain = 25 self.freq_tune = freq_tune = freq * 1e6 - freq_offset ################################################## # Blocks ################################################## self._volume_range = Range(-20, 10, 1, 0, 200) self._volume_win = RangeWidget(self._volume_range, self.set_volume, 'Volume', "counter_slider", float, QtCore.Qt.Horizontal) self.top_grid_layout.addWidget(self._volume_win, 1, 0, 1, 1) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self._gain_range = Range(0, 49.6, 1, 25, 200) self._gain_win = RangeWidget(self._gain_range, self.set_gain, 'RF Gain', "counter_slider", float, QtCore.Qt.Horizontal) self.top_grid_layout.addWidget(self._gain_win, 2, 0, 1, 1) for r in range(2, 3): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self._freq_range = Range(77, 108, 0.1, 88.5, 200) self._freq_win = RangeWidget(self._freq_range, self.set_freq, 'Frequency', "counter_slider", float, QtCore.Qt.Horizontal) self.top_grid_layout.addWidget(self._freq_win, 0, 0, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self.rtlsdr_source_0_0 = osmosdr.source(args="numchan=" + str(1) + " " + '') self.rtlsdr_source_0_0.set_time_unknown_pps(osmosdr.time_spec_t()) self.rtlsdr_source_0_0.set_sample_rate(samp_rate) self.rtlsdr_source_0_0.set_center_freq(freq_tune, 0) self.rtlsdr_source_0_0.set_freq_corr(0, 0) self.rtlsdr_source_0_0.set_dc_offset_mode(0, 0) self.rtlsdr_source_0_0.set_iq_balance_mode(0, 0) self.rtlsdr_source_0_0.set_gain_mode(False, 0) self.rtlsdr_source_0_0.set_gain(14, 0) self.rtlsdr_source_0_0.set_if_gain(24, 0) self.rtlsdr_source_0_0.set_bb_gain(gain, 0) self.rtlsdr_source_0_0.set_antenna('', 0) self.rtlsdr_source_0_0.set_bandwidth(0, 0) self.root_raised_cosine_filter_0 = filter.fir_filter_ccf( 2, firdes.root_raised_cosine(1, 19000, 2375, 1, 100)) self.rds_parser_0 = rds.parser(False, False, 0) self.rds_panel_0 = rds.rdsPanel(freq) self._rds_panel_0_win = self.rds_panel_0 self.top_layout.addWidget(self._rds_panel_0_win) self.rds_decoder_0 = rds.decoder(False, False) self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_f( 1024, #size window.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name 1, #number of inputs None # parent ) self.qtgui_waterfall_sink_x_0.set_update_time(0.10) self.qtgui_waterfall_sink_x_0.enable_grid(False) self.qtgui_waterfall_sink_x_0.enable_axis_labels(True) self.qtgui_waterfall_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] colors = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in range(1): if len(labels[i]) == 0: self.qtgui_waterfall_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_0.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_0.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_0.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_0.set_intensity_range(-140, 10) self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance( self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_waterfall_sink_x_0_win) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 1024, #size window.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name 1, None # parent ) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(False) self.qtgui_freq_sink_x_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) self.qtgui_freq_sink_x_0.set_fft_window_normalized(False) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in range(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_freq_sink_x_0_win) self.pfb_arb_resampler_xxx_1 = pfb.arb_resampler_fff(240000.0 / 250000, taps=None, flt_size=32) self.pfb_arb_resampler_xxx_1.declare_sample_delay(0) self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_ccf(19000 / 250e3, taps=None, flt_size=32) self.pfb_arb_resampler_xxx_0.declare_sample_delay(0) self.freq_xlating_fir_filter_xxx_2 = filter.freq_xlating_fir_filter_fcf( 5, firdes.low_pass(1.0, 240000, 13e3, 3e3), 38000, 240000) self.freq_xlating_fir_filter_xxx_1_0 = filter.freq_xlating_fir_filter_fcc( 1, firdes.low_pass(2500.0, 250000, 2.6e3, 2e3), 57e3, 250000) self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc( 1, firdes.low_pass(1, samp_rate, 80000, 20000), freq_offset, samp_rate) self.fir_filter_xxx_1 = filter.fir_filter_fff( 5, firdes.low_pass(1.0, 240000, 13e3, 3e3)) self.fir_filter_xxx_1.declare_sample_delay(0) self.digital_psk_demod_0 = digital.psk.psk_demod( constellation_points=2, differential=False, samples_per_symbol=4, excess_bw=0.35, phase_bw=6.28 / 100.0, timing_bw=6.28 / 100.0, mod_code="gray", verbose=False, log=False) self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(2) self.blocks_sub_xx_0 = blocks.sub_ff(1) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_ff( 10**(1. * (volume) / 10)) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff( 10**(1. * (volume) / 10)) self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n( gr.sizeof_char * 1, 2) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) self.blocks_add_xx_0 = blocks.add_vff(1) self.audio_sink_0 = audio.sink(48000, '', True) self.analog_wfm_rcv_0 = analog.wfm_rcv( quad_rate=samp_rate, audio_decimation=8, ) self.analog_fm_deemph_0_0_0 = analog.fm_deemph(fs=48000, tau=75e-6) self.analog_fm_deemph_0_0 = analog.fm_deemph(fs=48000, tau=75e-6) ################################################## # Connections ################################################## self.msg_connect((self.rds_decoder_0, 'out'), (self.rds_parser_0, 'in')) self.msg_connect((self.rds_parser_0, 'out'), (self.rds_panel_0, 'in')) self.connect((self.analog_fm_deemph_0_0, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.analog_fm_deemph_0_0_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.analog_wfm_rcv_0, 0), (self.freq_xlating_fir_filter_xxx_1_0, 0)) self.connect((self.analog_wfm_rcv_0, 0), (self.pfb_arb_resampler_xxx_1, 0)) self.connect((self.analog_wfm_rcv_0, 0), (self.qtgui_waterfall_sink_x_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.analog_fm_deemph_0_0_0, 0)) self.connect((self.blocks_complex_to_real_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_complex_to_real_0, 0), (self.blocks_sub_xx_0, 1)) self.connect((self.blocks_keep_one_in_n_0, 0), (self.digital_diff_decoder_bb_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.audio_sink_0, 1)) self.connect((self.blocks_sub_xx_0, 0), (self.analog_fm_deemph_0_0, 0)) self.connect((self.digital_diff_decoder_bb_0, 0), (self.rds_decoder_0, 0)) self.connect((self.digital_psk_demod_0, 0), (self.blocks_keep_one_in_n_0, 0)) self.connect((self.fir_filter_xxx_1, 0), (self.blocks_add_xx_0, 0)) self.connect((self.fir_filter_xxx_1, 0), (self.blocks_sub_xx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.analog_wfm_rcv_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_1_0, 0), (self.pfb_arb_resampler_xxx_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_2, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.root_raised_cosine_filter_0, 0)) self.connect((self.pfb_arb_resampler_xxx_1, 0), (self.fir_filter_xxx_1, 0)) self.connect((self.pfb_arb_resampler_xxx_1, 0), (self.freq_xlating_fir_filter_xxx_2, 0)) self.connect((self.root_raised_cosine_filter_0, 0), (self.digital_psk_demod_0, 0)) self.connect((self.rtlsdr_source_0_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0))
def __init__(self, decoder_obj_list, ann=None, puncpat='11', integration_period=10000, flush=None, rotator=None, lentagname=None, mtu=1500): gr.hier_block2.__init__(self, "extended_decoder", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_char)) self.blocks=[] self.ann=ann self.puncpat=puncpat self.flush=flush if(type(decoder_obj_list) == list): # This block doesn't handle parallelism of > 1 # We could just grab encoder [0][0], but we don't want to encourage this. if(type(decoder_obj_list[0]) == list): gr.log.info("fec.extended_tagged_decoder: Parallelism must be 1.") raise AttributeError decoder_obj = decoder_obj_list[0] # Otherwise, just take it as is else: decoder_obj = decoder_obj_list # If lentagname is None, fall back to using the non tagged # stream version if type(lentagname) == str: if(lentagname.lower() == 'none'): lentagname = None message_collector_connected=False ##anything going through the annihilator needs shifted, uchar vals if fec.get_decoder_input_conversion(decoder_obj) == "uchar" or \ fec.get_decoder_input_conversion(decoder_obj) == "packed_bits": self.blocks.append(blocks.multiply_const_ff(48.0)) if fec.get_shift(decoder_obj) != 0.0: self.blocks.append(blocks.add_const_ff(fec.get_shift(decoder_obj))) elif fec.get_decoder_input_conversion(decoder_obj) == "packed_bits": self.blocks.append(blocks.add_const_ff(128.0)) if fec.get_decoder_input_conversion(decoder_obj) == "uchar" or \ fec.get_decoder_input_conversion(decoder_obj) == "packed_bits": self.blocks.append(blocks.float_to_uchar()); const_index = 0; #index that corresponds to mod order for specinvert purposes if not self.flush: flush = 10000; else: flush = self.flush; if self.ann: #ann and puncpat are strings of 0s and 1s cat = fec.ULLVector(); for i in fec.read_big_bitlist(ann): cat.append(i); synd_garble = .49 idx_list = list(self.garbletable.keys()) idx_list.sort() for i in idx_list: if 1.0 / self.ann.count('1') >= i: synd_garble = self.garbletable[i] print('using syndrom garble threshold ' + str(synd_garble) + 'for conv_bit_corr_bb') print('ceiling: .0335 data garble rate') self.blocks.append(fec.conv_bit_corr_bb(cat, len(puncpat) - puncpat.count('0'), len(ann), integration_period, flush, synd_garble)) if self.puncpat != '11': self.blocks.append(fec.depuncture_bb(len(puncpat), read_bitlist(puncpat), 0)) if fec.get_decoder_input_conversion(decoder_obj) == "packed_bits": self.blocks.append(blocks.uchar_to_float()) self.blocks.append(blocks.add_const_ff(-128.0)) self.blocks.append(digital.binary_slicer_fb()) self.blocks.append(blocks.unpacked_to_packed_bb(1,0)) else: if(not lentagname): self.blocks.append(fec.decoder(decoder_obj, fec.get_decoder_input_item_size(decoder_obj), fec.get_decoder_output_item_size(decoder_obj))) else: self.blocks.append(fec.tagged_decoder(decoder_obj, fec.get_decoder_input_item_size(decoder_obj), fec.get_decoder_output_item_size(decoder_obj), lentagname, mtu)) if fec.get_decoder_output_conversion(decoder_obj) == "unpack": self.blocks.append(blocks.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST)); self.connect((self, 0), (self.blocks[0], 0)); self.connect((self.blocks[-1], 0), (self, 0)); for i in range(len(self.blocks) - 1): self.connect((self.blocks[i], 0), (self.blocks[i+1], 0));
def __init__(self, myfreq): gr.top_block.__init__(self) rt = gr.enable_realtime_scheduling() # ****************************************************************************** ######## Variables ######### self.dac_rate = 100e6/50 # DAC rate self.adc_rate = 100e6/22 # ADC rate (4.54....MS/s complex samples) self.decim = 2 # Decimation (downsampling factor) self.ampl = 0.7 # Output signal amplitude (signal power vary for different RFX900 cards) self.freq = myfreq # Modulation frequency (can be set between 902-920) # self.rx_gain = -5 # RX Gain (gain at receiver) self.tx_gain = 25#gains configuration without use of Power Amplifier self.usrp_address_source = "addr=192.168.10.2,recv_frame_size=256" self.usrp_address_sink = "addr=192.168.10.2,recv_frame_size=256" # Each FM0 symbol consists of ADC_RATE/BLF samples (4.54...e6/160e3 =28.2 samples) # 14 samples per symbol after matched filtering and decimation self.num_taps = [1] *14 # matched to half symbol period ######## File sinks for debugging (1 for each block) ######### self.file_sink_source = blocks.file_sink(gr.sizeof_gr_complex*1, "../misc/data/source", False) self.file_sink_matched_filter = blocks.file_sink(gr.sizeof_gr_complex*1, "../misc/data/matched_filter", False) self.file_sink_gate = blocks.file_sink(gr.sizeof_gr_complex*1, "../misc/data/gate", False) self.file_sink_decoder = blocks.file_sink(gr.sizeof_gr_complex*1, "../misc/data/decoder", False) self.file_sink_reader = blocks.file_sink(gr.sizeof_float*1, "../misc/data/reader", False) #sample rate (analog-to-digital) = adc_rate/decimation ####### Blocks ######### self.matched_filter = filter.fir_filter_ccc(self.decim,self.num_taps) self.gate = rfid.gate(int(self.adc_rate/self.decim)) self.tag_decoder = rfid.tag_decoder(int(self.adc_rate/self.decim)) self.reader = rfid.reader(int(self.adc_rate/self.decim),int(self.dac_rate)) self.amp = blocks.multiply_const_ff(self.ampl) self.to_complex = blocks.float_to_complex() if (DEBUG == False) : # Real Time Execution # USRP blocks self.u_source() self.u_sink() ######## Connections ######### self.connect(self.source, self.matched_filter) self.connect(self.matched_filter, self.gate) self.connect(self.gate, self.tag_decoder) self.connect((self.tag_decoder,0), self.reader) self.connect(self.reader, self.amp) self.connect(self.amp, self.to_complex) self.connect(self.to_complex, self.sink) #File sinks for logging (Remove comments to log data) self.connect(self.source, self.file_sink_source) else : # Offline Data self.file_source = blocks.file_source(gr.sizeof_gr_complex*1, "../misc/data/file_sink_source",False) ## instead of uhd.usrp_source self.file_sink = blocks.file_sink(gr.sizeof_gr_complex*1, "../misc/data/file_sink", False) ## instead of uhd.usrp_sink ######## Connections ######### self.connect(self.file_source, self.matched_filter) self.connect(self.matched_filter, self.gate) self.connect(self.gate, self.tag_decoder) self.connect((self.tag_decoder,0), self.reader) self.connect(self.reader, self.amp) self.connect(self.amp, self.to_complex) self.connect(self.to_complex, self.file_sink) #File sinks for logging self.connect(self.gate, self.file_sink_gate) self.connect((self.tag_decoder,1), self.file_sink_decoder) # (Do not comment this line) self.connect(self.reader, self.file_sink_reader) self.connect(self.matched_filter, self.file_sink_matched_filter)
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) parser = OptionParser(option_class=eng_option) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-f", "--freq", type="eng_float", default=100.1e6, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-s", "--squelch", type="eng_float", default=0, help="set squelch level (default is 0)") parser.add_option("-V", "--volume", type="eng_float", default=None, help="set volume (default is midpoint)") parser.add_option( "-O", "--audio-output", type="string", default="default", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") parser.add_option("", "--freq-min", type="eng_float", default=87.9e6, help="Set a minimum frequency [default=%default]") parser.add_option("", "--freq-max", type="eng_float", default=108.1e6, help="Set a maximum frequency [default=%default]") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.frame = frame self.panel = panel self.vol = 0 self.state = "FREQ" self.freq = 0 self.fm_freq_min = options.freq_min self.fm_freq_max = options.freq_max # build graph self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if (options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if (options.antenna): self.u.set_antenna(options.antenna, 0) usrp_rate = 320e3 demod_rate = 320e3 audio_rate = 48e3 audio_decim = 10 self.u.set_samp_rate(usrp_rate) dev_rate = self.u.get_samp_rate() nfilts = 32 chan_coeffs = filter.firdes.low_pass_2( nfilts, # gain nfilts * usrp_rate, # sampling rate 90e3, # passband cutoff 30e3, # stopband cutoff 70) # stopband attenuation rrate = usrp_rate / dev_rate self.chan_filt = filter.pfb.arb_resampler_ccf(rrate, chan_coeffs, nfilts) self.guts = analog.wfm_rcv_pll(demod_rate, audio_decim) chan_rate = audio_rate / (demod_rate / audio_decim) self.rchan_filt = filter.pfb.arb_resampler_fff(chan_rate) self.lchan_filt = filter.pfb.arb_resampler_fff(chan_rate) # FIXME rework {add,multiply}_const_* to handle multiple streams self.volume_control_l = blocks.multiply_const_ff(self.vol) self.volume_control_r = blocks.multiply_const_ff(self.vol) # sound card as final sink self.audio_sink = audio.sink(int(audio_rate), options.audio_output, False) # ok_to_block # now wire it all together self.connect(self.u, self.chan_filt, self.guts) self.connect((self.guts, 0), self.lchan_filt, self.volume_control_l, (self.audio_sink, 0)) self.connect((self.guts, 1), self.rchan_filt, self.volume_control_r, (self.audio_sink, 1)) try: self.guts.stereo_carrier_pll_recovery.squelch_enable(True) except: print "FYI: This implementation of the stereo_carrier_pll_recovery has no squelch implementation yet" self._build_gui(vbox, usrp_rate, demod_rate, audio_rate) if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start() + g.stop()) / 2.0 if options.volume is None: g = self.volume_range() options.volume = float(g[0] + g[1]) / 2 frange = self.u.get_freq_range() if (frange.start() > self.fm_freq_max or frange.stop() < self.fm_freq_min): sys.stderr.write( "Radio does not support required frequency range.\n") sys.exit(1) if (options.freq < self.fm_freq_min or options.freq > self.fm_freq_max): sys.stderr.write( "Requested frequency is outside of required frequency range.\n" ) sys.exit(1) # set initial values self.set_gain(options.gain) self.set_vol(options.volume) try: self.guts.stereo_carrier_pll_recovery.set_lock_threshold( options.squelch) except: print "FYI: This implementation of the stereo_carrier_pll_recovery has no squelch implementation yet" if not (self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def __init__(self, args, spec, antenna, gain, audio_output): gr.hier_block2.__init__(self, "receive_path", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(0, 0, 0)) # Output signature self.u = uhd.usrp_source(device_addr=args, io_type=uhd.io_type.COMPLEX_FLOAT32, num_channels=1) self.if_rate = 256e3 self.quad_rate = 64e3 self.audio_rate = 32e3 self.u.set_samp_rate(self.if_rate) dev_rate = self.u.get_samp_rate() # Create filter to get actual channel we want nfilts = 32 chan_coeffs = filter.firdes.low_pass(nfilts, # gain nfilts*dev_rate, # sampling rate 13e3, # low pass cutoff freq 4e3, # width of trans. band filter.firdes.WIN_HANN) # filter type rrate = self.quad_rate / dev_rate self.resamp = filter.pfb.arb_resampler_ccf(rrate, chan_coeffs, nfilts) # instantiate the guts of the single channel receiver self.fmrx = analog.nbfm_rx(self.audio_rate, self.quad_rate) # standard squelch block self.squelch = analog.standard_squelch(self.audio_rate) # audio gain / mute block self._audio_gain = blocks.multiply_const_ff(1.0) # sound card as final sink audio_sink = audio.sink(int(self.audio_rate), audio_output) # now wire it all together self.connect(self.u, self.resamp, self.fmrx, self.squelch, self._audio_gain, audio_sink) if gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() gain = float(g.start() + g.stop())/2.0 self.enabled = True self.set_gain(gain) v = self.volume_range() self.set_volume((v[0]+v[1])/2) s = self.squelch_range() self.set_squelch((s[0]+s[1])/2) # Set the subdevice spec if(spec): self.u.set_subdev_spec(spec, 0) # Set the antenna if(antenna): self.u.set_antenna(antenna, 0)
def __init__(self, output_sample_rate=_def_output_sample_rate, excess_bw=_def_excess_bw, reverse=_def_reverse, verbose=_def_verbose, log=_def_log): """ Hierarchical block for RRC-filtered P25 FM modulation. The input is a dibit (P25 symbol) stream (char, not packed) and the output is the float "C4FM" signal at baseband, suitable for application to an FM modulator stage Input is at the base symbol rate (4800), output sample rate is typically either 32000 (USRP TX chain) or 48000 (sound card) @param output_sample_rate: output sample rate @type output_sample_rate: integer @param excess_bw: Root-raised cosine filter excess bandwidth @type excess_bw: float @param reverse: reverse polarity flag @type reverse: bool @param verbose: Print information about modulator? @type verbose: bool @param debug: Print modulation data to files? @type debug: bool """ gr.hier_block2.__init__( self, "p25_c4fm_mod_bf", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature input_sample_rate = 4800 # P25 baseband symbol rate lcm = gru.lcm(input_sample_rate, output_sample_rate) self._interp_factor = int(lcm // input_sample_rate) self._decimation = int(lcm // output_sample_rate) self._excess_bw = excess_bw mod_map = [1.0 / 3.0, 1.0, -(1.0 / 3.0), -1.0] self.C2S = digital.chunks_to_symbols_bf(mod_map) if reverse: self.polarity = blocks.multiply_const_ff(-1) else: self.polarity = blocks.multiply_const_ff(1) ntaps = 11 * self._interp_factor rrc_taps = filter.firdes.root_raised_cosine( self._interp_factor, # gain (since we're interpolating by sps) lcm, # sampling rate input_sample_rate, # symbol rate self._excess_bw, # excess bandwidth (roll-off factor) ntaps) # rrc_coeffs work slightly differently: each input sample # (from mod_map above) at 4800 rate, then 9 zeros are inserted # to bring to 48000 rate, then this filter is applied: # rrc_filter = gr.fir_filter_fff(1, rrc_coeffs) # FIXME: how to insert the 9 zero samples using gr ? # rrc_coeffs = [0, -0.003, -0.006, -0.009, -0.012, -0.014, -0.014, -0.013, -0.01, -0.006, 0, 0.007, 0.014, 0.02, 0.026, 0.029, 0.029, 0.027, 0.021, 0.012, 0, -0.013, -0.027, -0.039, -0.049, -0.054, -0.055, -0.049, -0.038, -0.021, 0, 0.024, 0.048, 0.071, 0.088, 0.098, 0.099, 0.09, 0.07, 0.039, 0, -0.045, -0.091, -0.134, -0.17, -0.193, -0.199, -0.184, -0.147, -0.085, 0, 0.105, 0.227, 0.36, 0.496, 0.629, 0.751, 0.854, 0.933, 0.983, 1, 0.983, 0.933, 0.854, 0.751, 0.629, 0.496, 0.36, 0.227, 0.105, 0, -0.085, -0.147, -0.184, -0.199, -0.193, -0.17, -0.134, -0.091, -0.045, 0, 0.039, 0.07, 0.09, 0.099, 0.098, 0.088, 0.071, 0.048, 0.024, 0, -0.021, -0.038, -0.049, -0.055, -0.054, -0.049, -0.039, -0.027, -0.013, 0, 0.012, 0.021, 0.027, 0.029, 0.029, 0.026, 0.02, 0.014, 0.007, 0, -0.006, -0.01, -0.013, -0.014, -0.014, -0.012, -0.009, -0.006, -0.003, 0] self.rrc_filter = filter.interp_fir_filter_fff(self._interp_factor, rrc_taps) # FM pre-emphasis filter shaping_coeffs = [ -0.018, 0.0347, 0.0164, -0.0064, -0.0344, -0.0522, -0.0398, 0.0099, 0.0798, 0.1311, 0.121, 0.0322, -0.113, -0.2499, -0.3007, -0.2137, -0.0043, 0.2825, 0.514, 0.604, 0.514, 0.2825, -0.0043, -0.2137, -0.3007, -0.2499, -0.113, 0.0322, 0.121, 0.1311, 0.0798, 0.0099, -0.0398, -0.0522, -0.0344, -0.0064, 0.0164, 0.0347, -0.018 ] self.shaping_filter = filter.fir_filter_fff(1, shaping_coeffs) if verbose: self._print_verbage() if log: self._setup_logging() self.connect(self, self.C2S, self.polarity, self.rrc_filter, self.shaping_filter) if (self._decimation > 1): self.decimator = filter.rational_resampler_fff(1, self._decimation) self.connect(self.shaping_filter, self.decimator, self) else: self.connect(self.shaping_filter, self)
def __init__(self): gr.top_block.__init__(self, "MODULADOR DQPSK") Qt.QWidget.__init__(self) self.setWindowTitle("MODULADOR DQPSK") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "top_block") try: if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"): self.restoreGeometry( self.settings.value("geometry").toByteArray()) else: self.restoreGeometry(self.settings.value("geometry")) except: pass ################################################## # Variables ################################################## self.samp_rate_2920_rx = samp_rate_2920_rx = 100000000 self.coef_rx = coef_rx = 2**8 self.samp_rate = samp_rate = int(samp_rate_2920_rx / coef_rx) self.Sps = Sps = 128 self.M = M = 2 self.Rs = Rs = samp_rate / Sps self.BpS = BpS = int(math.log(M, 2)) self.Rb = Rb = Rs / BpS self.no_code = no_code = digital.utils.mod_codes.NO_CODE self.W = W = Rb / 2 self.Rolloff = Rolloff = 1.0 self.ntaps = ntaps = Sps * 16 self.h = h = wform.rect(Sps) self.constelacion = constelacion = digital.psk_constellation( M, no_code, False) self.Retardo_bits = Retardo_bits = 0 self.Retardo_Timing = Retardo_Timing = 0 self.BW_rect = BW_rect = samp_rate / 2 self.BW = BW = W * (1 + Rolloff) ################################################## # Blocks ################################################## self.menu = Qt.QTabWidget() self.menu_widget_0 = Qt.QWidget() self.menu_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.menu_widget_0) self.menu_grid_layout_0 = Qt.QGridLayout() self.menu_layout_0.addLayout(self.menu_grid_layout_0) self.menu.addTab(self.menu_widget_0, 'Timing') self.menu_widget_1 = Qt.QWidget() self.menu_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.menu_widget_1) self.menu_grid_layout_1 = Qt.QGridLayout() self.menu_layout_1.addLayout(self.menu_grid_layout_1) self.menu.addTab(self.menu_widget_1, 'T0 versus R0') self.menu_widget_2 = Qt.QWidget() self.menu_layout_2 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.menu_widget_2) self.menu_grid_layout_2 = Qt.QGridLayout() self.menu_layout_2.addLayout(self.menu_grid_layout_2) self.menu.addTab(self.menu_widget_2, 'T1 versus R1') self.menu_widget_3 = Qt.QWidget() self.menu_layout_3 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.menu_widget_3) self.menu_grid_layout_3 = Qt.QGridLayout() self.menu_layout_3.addLayout(self.menu_grid_layout_3) self.menu.addTab(self.menu_widget_3, 'T2 versus R2') self.menu_widget_4 = Qt.QWidget() self.menu_layout_4 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.menu_widget_4) self.menu_grid_layout_4 = Qt.QGridLayout() self.menu_layout_4.addLayout(self.menu_grid_layout_4) self.menu.addTab(self.menu_widget_4, 'T3 versus R3') self.menu_widget_5 = Qt.QWidget() self.menu_layout_5 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.menu_widget_5) self.menu_grid_layout_5 = Qt.QGridLayout() self.menu_layout_5.addLayout(self.menu_grid_layout_5) self.menu.addTab(self.menu_widget_5, 'RF') self.top_grid_layout.addWidget(self.menu, 2, 0, 1, 2) for r in range(2, 3): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 2): self.top_grid_layout.setColumnStretch(c, 1) self._Retardo_bits_range = Range(0, Sps * 10, 1, 0, 200) self._Retardo_bits_win = RangeWidget( self._Retardo_bits_range, self.set_Retardo_bits, 'Delay transmited signal to match with the received signal', "counter_slider", int) self.menu_grid_layout_4.addWidget(self._Retardo_bits_win, 0, 0, 1, 1) for r in range(0, 1): self.menu_grid_layout_4.setRowStretch(r, 1) for c in range(0, 1): self.menu_grid_layout_4.setColumnStretch(c, 1) self._Retardo_Timing_range = Range(0, Sps - 1, 1, 0, 200) self._Retardo_Timing_win = RangeWidget(self._Retardo_Timing_range, self.set_Retardo_Timing, 'Timing', "counter", int) self.menu_grid_layout_0.addWidget(self._Retardo_Timing_win, 0, 0, 1, 1) for r in range(0, 1): self.menu_grid_layout_0.setRowStretch(r, 1) for c in range(0, 1): self.menu_grid_layout_0.setColumnStretch(c, 1) self.qtgui_time_sink_x_1 = qtgui.time_sink_f( 1024, #size samp_rate, #samp_rate "", #name 3 #number of inputs ) self.qtgui_time_sink_x_1.set_update_time(0.10) self.qtgui_time_sink_x_1.set_y_axis(-1, 1) self.qtgui_time_sink_x_1.set_y_label('Amplitude', "") self.qtgui_time_sink_x_1.enable_tags(True) self.qtgui_time_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_1.enable_autoscale(False) self.qtgui_time_sink_x_1.enable_grid(False) self.qtgui_time_sink_x_1.enable_axis_labels(True) self.qtgui_time_sink_x_1.enable_control_panel(False) self.qtgui_time_sink_x_1.enable_stem_plot(False) labels = [ 'Senal RF', 'EC (Re)', 'EC(Im)', 'Signal 4', 'Signal 5', 'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10' ] widths = [3, 3, 3, 1, 1, 1, 1, 1, 1, 1] colors = [ 'blue', 'red', 'green', 'black', 'cyan', 'magenta', 'yellow', 'dark red', 'dark green', 'dark blue' ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] for i in range(3): if len(labels[i]) == 0: self.qtgui_time_sink_x_1.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_1.set_line_label(i, labels[i]) self.qtgui_time_sink_x_1.set_line_width(i, widths[i]) self.qtgui_time_sink_x_1.set_line_color(i, colors[i]) self.qtgui_time_sink_x_1.set_line_style(i, styles[i]) self.qtgui_time_sink_x_1.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_1.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_1_win = sip.wrapinstance( self.qtgui_time_sink_x_1.pyqwidget(), Qt.QWidget) self.menu_grid_layout_5.addWidget(self._qtgui_time_sink_x_1_win, 0, 0, 1, 1) for r in range(0, 1): self.menu_grid_layout_5.setRowStretch(r, 1) for c in range(0, 1): self.menu_grid_layout_5.setColumnStretch(c, 1) self.qtgui_time_sink_x_0_1 = qtgui.time_sink_c( 1024, #size samp_rate, #samp_rate "", #name 2 #number of inputs ) self.qtgui_time_sink_x_0_1.set_update_time(0.10) self.qtgui_time_sink_x_0_1.set_y_axis(-1, 1) self.qtgui_time_sink_x_0_1.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0_1.enable_tags(True) self.qtgui_time_sink_x_0_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0_1.enable_autoscale(False) self.qtgui_time_sink_x_0_1.enable_grid(False) self.qtgui_time_sink_x_0_1.enable_axis_labels(True) self.qtgui_time_sink_x_0_1.enable_control_panel(False) self.qtgui_time_sink_x_0_1.enable_stem_plot(False) labels = [ 'Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5', 'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10' ] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ 'blue', 'red', 'green', 'black', 'cyan', 'magenta', 'yellow', 'dark red', 'dark green', 'dark blue' ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] for i in range(4): if len(labels[i]) == 0: if (i % 2 == 0): self.qtgui_time_sink_x_0_1.set_line_label( i, "Re{{Data {0}}}".format(i / 2)) else: self.qtgui_time_sink_x_0_1.set_line_label( i, "Im{{Data {0}}}".format(i / 2)) else: self.qtgui_time_sink_x_0_1.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0_1.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0_1.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0_1.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0_1.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0_1.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_1_win = sip.wrapinstance( self.qtgui_time_sink_x_0_1.pyqwidget(), Qt.QWidget) self.menu_grid_layout_1.addWidget(self._qtgui_time_sink_x_0_1_win, 2, 0, 1, 1) for r in range(2, 3): self.menu_grid_layout_1.setRowStretch(r, 1) for c in range(0, 1): self.menu_grid_layout_1.setColumnStretch(c, 1) self.qtgui_time_sink_x_0_0 = qtgui.time_sink_f( 1024, #size Rs, #samp_rate "", #name 2 #number of inputs ) self.qtgui_time_sink_x_0_0.set_update_time(0.10) self.qtgui_time_sink_x_0_0.set_y_axis(-0.5, 1.5) self.qtgui_time_sink_x_0_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0_0.enable_tags(True) self.qtgui_time_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0_0.enable_autoscale(False) self.qtgui_time_sink_x_0_0.enable_grid(False) self.qtgui_time_sink_x_0_0.enable_axis_labels(True) self.qtgui_time_sink_x_0_0.enable_control_panel(False) self.qtgui_time_sink_x_0_0.enable_stem_plot(True) labels = [ 'Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5', 'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10' ] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ 'blue', 'red', 'green', 'black', 'cyan', 'magenta', 'yellow', 'dark red', 'dark green', 'dark blue' ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [0, 0, -1, -1, -1, -1, -1, -1, -1, -1] for i in range(2): if len(labels[i]) == 0: self.qtgui_time_sink_x_0_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0_0.pyqwidget(), Qt.QWidget) self.menu_grid_layout_4.addWidget(self._qtgui_time_sink_x_0_0_win, 1, 0, 1, 1) for r in range(1, 2): self.menu_grid_layout_4.setRowStretch(r, 1) for c in range(0, 1): self.menu_grid_layout_4.setColumnStretch(c, 1) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 1024, #size Rs, #samp_rate "", #name 2 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.10) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0.enable_tags(True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(False) self.qtgui_time_sink_x_0.enable_grid(False) self.qtgui_time_sink_x_0.enable_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(False) self.qtgui_time_sink_x_0.enable_stem_plot(True) labels = [ 'Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5', 'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10' ] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ 'blue', 'red', 'green', 'black', 'cyan', 'magenta', 'yellow', 'dark red', 'dark green', 'dark blue' ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [0, 0, -1, -1, -1, -1, -1, -1, -1, -1] for i in range(2): if len(labels[i]) == 0: self.qtgui_time_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance( self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.menu_grid_layout_3.addWidget(self._qtgui_time_sink_x_0_win, 1, 0, 1, 1) for r in range(1, 2): self.menu_grid_layout_3.setRowStretch(r, 1) for c in range(0, 1): self.menu_grid_layout_3.setColumnStretch(c, 1) self.qtgui_const_sink_x_0_0_0_0 = qtgui.const_sink_c( 1024, #size "", #name 1 #number of inputs ) self.qtgui_const_sink_x_0_0_0_0.set_update_time(0.10) self.qtgui_const_sink_x_0_0_0_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0_0_0_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0_0_0_0.set_trigger_mode( qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0_0_0_0.enable_autoscale(False) self.qtgui_const_sink_x_0_0_0_0.enable_grid(False) self.qtgui_const_sink_x_0_0_0_0.enable_axis_labels(True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "red", "red", "red", "red", "red", "red", "red", "red" ] styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in range(1): if len(labels[i]) == 0: self.qtgui_const_sink_x_0_0_0_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0_0_0_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0_0_0_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0_0_0_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0_0_0_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0_0_0_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0_0_0_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_0_0_0_win = sip.wrapinstance( self.qtgui_const_sink_x_0_0_0_0.pyqwidget(), Qt.QWidget) self.menu_grid_layout_0.addWidget(self._qtgui_const_sink_x_0_0_0_0_win, 2, 1, 1, 1) for r in range(2, 3): self.menu_grid_layout_0.setRowStretch(r, 1) for c in range(1, 2): self.menu_grid_layout_0.setColumnStretch(c, 1) self.qtgui_const_sink_x_0_0_0 = qtgui.const_sink_c( 1024, #size "", #name 1 #number of inputs ) self.qtgui_const_sink_x_0_0_0.set_update_time(0.10) self.qtgui_const_sink_x_0_0_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0_0_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0_0_0.enable_autoscale(False) self.qtgui_const_sink_x_0_0_0.enable_grid(False) self.qtgui_const_sink_x_0_0_0.enable_axis_labels(True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "red", "red", "red", "red", "red", "red", "red", "red" ] styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in range(1): if len(labels[i]) == 0: self.qtgui_const_sink_x_0_0_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0_0_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0_0_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0_0_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0_0_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0_0_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0_0_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_0_0_win = sip.wrapinstance( self.qtgui_const_sink_x_0_0_0.pyqwidget(), Qt.QWidget) self.menu_grid_layout_0.addWidget(self._qtgui_const_sink_x_0_0_0_win, 2, 0, 1, 1) for r in range(2, 3): self.menu_grid_layout_0.setRowStretch(r, 1) for c in range(0, 1): self.menu_grid_layout_0.setColumnStretch(c, 1) self.qtgui_const_sink_x_0_0 = qtgui.const_sink_c( 1024, #size "", #name 2 #number of inputs ) self.qtgui_const_sink_x_0_0.set_update_time(0.10) self.qtgui_const_sink_x_0_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0_0.enable_autoscale(False) self.qtgui_const_sink_x_0_0.enable_grid(False) self.qtgui_const_sink_x_0_0.enable_axis_labels(True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "red", "red", "red", "red", "red", "red", "red", "red" ] styles = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] markers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in range(2): if len(labels[i]) == 0: self.qtgui_const_sink_x_0_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_0_win = sip.wrapinstance( self.qtgui_const_sink_x_0_0.pyqwidget(), Qt.QWidget) self.menu_grid_layout_2.addWidget(self._qtgui_const_sink_x_0_0_win, 1, 0, 1, 1) for r in range(1, 2): self.menu_grid_layout_2.setRowStretch(r, 1) for c in range(0, 1): self.menu_grid_layout_2.setColumnStretch(c, 1) self.qtgui_const_sink_x_0 = qtgui.const_sink_c( 1024, #size "", #name 2 #number of inputs ) self.qtgui_const_sink_x_0.set_update_time(0.10) self.qtgui_const_sink_x_0.set_y_axis(-2, 2) self.qtgui_const_sink_x_0.set_x_axis(-2, 2) self.qtgui_const_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "") self.qtgui_const_sink_x_0.enable_autoscale(False) self.qtgui_const_sink_x_0.enable_grid(False) self.qtgui_const_sink_x_0.enable_axis_labels(True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "red", "red", "red", "red", "red", "red", "red", "red" ] styles = [1, 1, 0, 0, 0, 0, 0, 0, 0, 0] markers = [-1, -1, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in range(2): if len(labels[i]) == 0: self.qtgui_const_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_const_sink_x_0.set_line_label(i, labels[i]) self.qtgui_const_sink_x_0.set_line_width(i, widths[i]) self.qtgui_const_sink_x_0.set_line_color(i, colors[i]) self.qtgui_const_sink_x_0.set_line_style(i, styles[i]) self.qtgui_const_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_const_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_const_sink_x_0_win = sip.wrapinstance( self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget) self.menu_grid_layout_1.addWidget(self._qtgui_const_sink_x_0_win, 1, 0, 1, 1) for r in range(1, 2): self.menu_grid_layout_1.setRowStretch(r, 1) for c in range(0, 1): self.menu_grid_layout_1.setColumnStretch(c, 1) self.interp_fir_filter_xxx_0_0 = filter.interp_fir_filter_ccc(1, h) self.interp_fir_filter_xxx_0_0.declare_sample_delay(0) self.interp_fir_filter_xxx_0 = filter.interp_fir_filter_ccc(Sps, h) self.interp_fir_filter_xxx_0.declare_sample_delay(0) self.epy_block_0 = epy_block_0.blk(Sps=Sps) self.e_VCO_fase_fc_0 = e_VCO_fase_fc_0.blk() self.digital_constellation_receiver_cb_0 = digital.constellation_receiver_cb( constelacion.base(), 2 * math.pi / 1000.0, -0.250, 0.250) self.blocks_unpacked_to_packed_xx_0_1 = blocks.unpacked_to_packed_bb( BpS, gr.GR_MSB_FIRST) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(8) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate, True) self.blocks_packed_to_unpacked_xx_0_0 = blocks.packed_to_unpacked_bb( BpS, gr.GR_MSB_FIRST) self.blocks_pack_k_bits_bb_0_0_0 = blocks.pack_k_bits_bb(8) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_char * 1) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_ff( (2 * math.pi) / M) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_cc(1 / Sps) self.blocks_delay_1 = blocks.delay(gr.sizeof_float * 1, Retardo_bits) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1, Retardo_Timing) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.blocks_char_to_float_0_2 = blocks.char_to_float(1, 1) self.blocks_char_to_float_0_1 = blocks.char_to_float(1, 1) self.blocks_char_to_float_0_0_0 = blocks.char_to_float(1, 1) self.blocks_char_to_float_0_0 = blocks.char_to_float(1, 1) self.blocks_char_to_float_0 = blocks.char_to_float(1, 1) self.blocks_add_xx_0 = blocks.add_vcc(1) self.b_upconverter_cf_0 = b_upconverter_cf( Fc=Rs * 2, samp_rate=44000, ) self.b_PSD_c_0 = b_PSD_c( Ensayos=1000000, Fc=0, N=1024, Ymax=6e-6, samp_rate_audio=samp_rate, ) self.menu_grid_layout_1.addWidget(self.b_PSD_c_0, 3, 0, 1, 1) for r in range(3, 4): self.menu_grid_layout_1.setRowStretch(r, 1) for c in range(0, 1): self.menu_grid_layout_1.setColumnStretch(c, 1) self.b_Eye_Diagram_simple_c_0 = b_Eye_Diagram_simple_c( AlphaLineas=0.5, Delay_i=0, GrosorLineas=20, Kint=1, N_eyes=2, Samprate1=samp_rate, Sps1=Sps, Title="Eye Diagramm", Ymax=2, Ymin=-2, ) self.menu_grid_layout_0.addWidget(self.b_Eye_Diagram_simple_c_0, 1, 0, 1, 2) for r in range(1, 2): self.menu_grid_layout_0.setRowStretch(r, 1) for c in range(0, 2): self.menu_grid_layout_0.setColumnStretch(c, 1) self.analog_random_source_x_0 = blocks.vector_source_b( list(map(int, numpy.random.randint(0, 2, 10000000))), True) self.analog_noise_source_x_0 = analog.noise_source_c( analog.GR_GAUSSIAN, 0.1, 0) self.analog_const_source_x_0_0_0 = analog.sig_source_f( 0, analog.GR_CONST_WAVE, 0, 0, 1) ################################################## # Connections ################################################## self.connect((self.analog_const_source_x_0_0_0, 0), (self.e_VCO_fase_fc_0, 1)) self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.analog_random_source_x_0, 0), (self.blocks_char_to_float_0_1, 0)) self.connect((self.analog_random_source_x_0, 0), (self.blocks_pack_k_bits_bb_0_0_0, 0)) self.connect((self.b_upconverter_cf_0, 0), (self.qtgui_time_sink_x_1, 0)) self.connect((self.blocks_add_xx_0, 0), (self.interp_fir_filter_xxx_0_0, 0)) self.connect((self.blocks_char_to_float_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blocks_char_to_float_0_0, 0), (self.qtgui_time_sink_x_0, 1)) self.connect((self.blocks_char_to_float_0_0_0, 0), (self.qtgui_time_sink_x_0_0, 1)) self.connect((self.blocks_char_to_float_0_1, 0), (self.blocks_delay_1, 0)) self.connect((self.blocks_char_to_float_0_2, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.qtgui_time_sink_x_1, 2)) self.connect((self.blocks_complex_to_float_0, 0), (self.qtgui_time_sink_x_1, 1)) self.connect((self.blocks_delay_0, 0), (self.b_Eye_Diagram_simple_c_0, 0)) self.connect((self.blocks_delay_0, 0), (self.epy_block_0, 0)) self.connect((self.blocks_delay_0, 0), (self.qtgui_const_sink_x_0_0_0, 0)) self.connect((self.blocks_delay_1, 0), (self.qtgui_time_sink_x_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.b_PSD_c_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_delay_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.qtgui_time_sink_x_0_1, 1)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.e_VCO_fase_fc_0, 0)) self.connect((self.blocks_pack_k_bits_bb_0_0_0, 0), (self.blocks_packed_to_unpacked_xx_0_0, 0)) self.connect((self.blocks_packed_to_unpacked_xx_0_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.blocks_packed_to_unpacked_xx_0_0, 0), (self.blocks_char_to_float_0_2, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_char_to_float_0_0_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_null_sink_0, 0)) self.connect((self.blocks_unpacked_to_packed_xx_0_1, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.digital_constellation_receiver_cb_0, 0), (self.blocks_char_to_float_0_0, 0)) self.connect((self.digital_constellation_receiver_cb_0, 0), (self.blocks_unpacked_to_packed_xx_0_1, 0)) self.connect((self.e_VCO_fase_fc_0, 0), (self.interp_fir_filter_xxx_0, 0)) self.connect((self.e_VCO_fase_fc_0, 0), (self.qtgui_const_sink_x_0_0, 0)) self.connect((self.epy_block_0, 0), (self.digital_constellation_receiver_cb_0, 0)) self.connect((self.epy_block_0, 0), (self.qtgui_const_sink_x_0_0, 1)) self.connect((self.epy_block_0, 0), (self.qtgui_const_sink_x_0_0_0_0, 0)) self.connect((self.interp_fir_filter_xxx_0, 0), (self.b_upconverter_cf_0, 0)) self.connect((self.interp_fir_filter_xxx_0, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.interp_fir_filter_xxx_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.interp_fir_filter_xxx_0, 0), (self.qtgui_const_sink_x_0, 1)) self.connect((self.interp_fir_filter_xxx_0, 0), (self.qtgui_time_sink_x_0_1, 0)) self.connect((self.interp_fir_filter_xxx_0_0, 0), (self.blocks_multiply_const_vxx_0, 0))
def __init__(self): gr.top_block.__init__(self) parser = ArgumentParser(description="Decode WFM signal into WAV file.") parser.add_argument("-V", "--volume", type=eng_float, help="Volume (dB) <%r, %r> (default is midpoint)" % self.volume_range()[:2]) parser.add_argument("input_file", help="Input file (complex samples)") parser.add_argument("output_file", help="Output WAV file") args = parser.parse_args() self.vol = 0 # build graph self.src = blocks.file_source(gr.sizeof_gr_complex, args.input_file, False) adc_rate = 64e6 # 64 MS/s usrp_decim = 200 usrp_rate = adc_rate / usrp_decim # 320 kS/s chanfilt_decim = 1 demod_rate = usrp_rate / chanfilt_decim audio_decimation = 10 audio_rate = demod_rate / audio_decimation # 32 kHz chan_filt_coeffs = filter.optfir.low_pass( 1, # gain usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation # print len(chan_filt_coeffs) chan_filt = filter.fir_filter_ccf(chanfilt_decim, chan_filt_coeffs) #self.guts = analog.wfm_rcv (demod_rate, audio_decimation) self.guts = analog.wfm_rcv_pll(demod_rate, audio_decimation) # FIXME rework {add,multiply}_const_* to handle multiple streams self.volume_control_l = blocks.multiply_const_ff(self.vol) self.volume_control_r = blocks.multiply_const_ff(self.vol) # wave file as final sink if 1: sink = blocks.wavfile_sink(args.output_file, 2, int(audio_rate), blocks.FORMAT_WAV, blocks.FORMAT_PCM_16) else: sink = audio.sink(int(audio_rate), args.audio_output, False) # ok_to_block # now wire it all together self.connect(self.src, chan_filt, self.guts) self.connect((self.guts, 0), self.volume_control_l, (sink, 0)) self.connect((self.guts, 1), self.volume_control_r, (sink, 1)) if args.volume is None: g = self.volume_range() args.volume = float(g[0] + g[1]) / 2 # set initial values self.set_vol(args.volume)
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--spec", type="string", default="A:0 A:0", help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("", "--f1", type="eng_float", default=100.7e6, help="set 1st station frequency to FREQ", metavar="FREQ") parser.add_option("", "--f2", type="eng_float", default=102.5e6, help="set 2nd station freq to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option( "-O", "--audio-output", type="string", default="default", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") parser.add_option("", "--freq-min", type="eng_float", default=87.9e6, help="Set a minimum frequency [default=%default]") parser.add_option("", "--freq-max", type="eng_float", default=108.1e6, help="Set a maximum frequency [default=%default]") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) if abs(options.f1 - options.f2) > 5.5e6: print "Sorry, two stations must be within 5.5MHz of each other" raise SystemExit f = (options.f1, options.f2) self.vol = .1 self.state = "FREQ" self.fm_freq_min = options.freq_min self.fm_freq_max = options.freq_max # build graph stream_args = uhd.stream_args('fc32', channels=range(2)) self.u = uhd.usrp_source(device_addr=options.args, stream_args=stream_args) # Set front end channel mapping self.u.set_subdev_spec(options.spec) usrp_rate = 320e3 demod_rate = 320e3 audio_rate = 32e3 audio_decim = int(demod_rate / audio_rate) self.u.set_samp_rate(usrp_rate) dev_rate = self.u.get_samp_rate() # Make sure dboard can suppor the required frequencies frange = self.u.get_freq_range() if (frange.start() > self.fm_freq_max or frange.stop() < self.fm_freq_min): sys.stderr.write( "Radio does not support required frequency range.\n") sys.exit(1) # sound card as final sink self.audio_sink = audio.sink(int(audio_rate), options.audio_output) # taps for channel filter nfilts = 32 chan_coeffs = filter.optfir.low_pass( nfilts, # gain nfilts * usrp_rate, # sampling rate 80e3, # passband cutoff 115e3, # stopband cutoff 0.1, # passband ripple 60) # stopband attenuation rrate = usrp_rate / dev_rate # set front end PLL to middle frequency mid_freq = (f[0] + f[1]) / 2.0 if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start() + g.stop()) / 2.0 for n in range(2): chan_filt = filter.pfb.arb_resampler_ccf(rrate, chan_coeffs, nfilts) guts = analog.wfm_rcv(demod_rate, audio_decim) volume_control = blocks.multiply_const_ff(self.vol) #self.connect((self.di, n), chan_filt) self.connect((self.u, n), chan_filt) self.connect(chan_filt, guts, volume_control) self.connect(volume_control, (self.audio_sink, n)) # Test the the requested frequencies are in range if (f[n] < self.fm_freq_min or f[n] > self.fm_freq_max): sys.stderr.write( "Requested frequency is outside of required frequency range.\n" ) sys.exit(1) # Tune each channel by setting the RF freq to mid_freq and the # DDC freq to f[n]. tr = uhd.tune_request( f[n], rf_freq=mid_freq, rf_freq_policy=uhd.tune_request.POLICY_MANUAL) self.u.set_center_freq(tr, n) # Set gain for each channel self.set_gain(options.gain, n) # Set the antenna if (options.antenna): self.u.set_antenna(options.antenna, n)
def __init__(self, argv): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--dev", type="string", default=0, help="Device (rtl=0 or something") parser.add_option("-f", "--freqset", type="string", default="", help="Frequency set key=freq,key=freq,... in kHz") parser.add_option("-m", "--mode", type="string", default="fm", help="Mode (am or fm)") parser.add_option("-g", "--gain", type="eng_float", default=30.0, help="set gain in dB (default is maximum)") parser.add_option("-V", "--volume", type="eng_float", default=1.0, help="set volume (default is midpoint)") parser.add_option("-i", "--icecast", type="string", default="", help="Icecast host:port") parser.add_option("-p", "--icepw", type="string", default="127.0.0.1:8000", help="Icecast source password") parser.add_option( "-O", "--audio-output", type="string", default="", help="pcm device name. E.g., hw:0,0 or surround51 or /dev/dsp") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) if options.volume is None: options.volume = 0.8 self.vol = options.volume self.freqs = self.parse_freqset(options.freqset) self.freq_corr = 0 self.rf_gain = options.gain # around 20 self.if_gain = 7 self.bb_gain = 10.0 self.bandwidth = 2400000 self.channel_bw = 10000 freq_min = min(self.freqs.values()) freq_max = max(self.freqs.values()) print "Frequencies:" for k in self.freqs: print " %s: %.3f MHz" % (k, self.freqs[k] / 1000000.0) required_bw = freq_max - freq_min print "Required bandwidth: %.3f MHz" % (required_bw / 1000000.0) if required_bw > self.bandwidth: print "Required bandwidth %.3f MHz larger than maximum BW %.3f MHz" % ( required_bw / 1000000, self.bandwidth / 100000) return None # offset center frequency so that it's not on a monitored frequency self.center_freq = freq_min + (required_bw / 2) for f in self.freqs.values(): if abs(f - self.center_freq) < self.channel_bw: self.center_freq += self.channel_bw print "Center frequency: %.3f MHz" % self.center_freq print "" # build graph arg_s = options.dev #"rtl=%d" % options.dev u = self.u = osmosdr.source(args=arg_s) u.set_center_freq(self.center_freq, 0) u.set_freq_corr(self.freq_corr, 0) u.set_dc_offset_mode(0, 0) # 0-2: Off-Manual-Automatic u.set_iq_balance_mode(0, 0) # 0-2: Off-Manual-Automatic u.set_gain_mode(False, 0) # 0-1: Manual, Automatic u.set_gain(self.rf_gain, 0) u.set_if_gain(self.if_gain, 0) u.set_bb_gain(self.bb_gain, 0) u.set_antenna("all", 0) u.set_sample_rate(1024e3 * 2) u.set_bandwidth(self.bandwidth, 0) dev_rate = self.u.get_sample_rate() demod_rate = 64e3 audio_rate = 32e3 chanfilt_decim = int(dev_rate // demod_rate) audio_decim = int(demod_rate // audio_rate) print "Device rate %d, bandwidth %.3f MHz" % ( dev_rate, self.bandwidth / 1000000.0) print "Demod rate %d, audio rate %d" % (demod_rate, audio_rate) if options.mode == 'am': chan_filt_coeffs = filter.firdes.low_pass_2( 1, # gain dev_rate, # sampling rate 8e3, # passband cutoff 2e3, # transition bw 60) # stopband attenuation else: print "FM filter" chan_filt_coeffs = filter.firdes.low_pass_2( 1, # gain dev_rate, # sampling rate 16e3, # passband cutoff 3e3, # transition bw 60) # stopband attenuation audio_filt_coeffs = filter.firdes.low_pass_2( 1, # gain demod_rate, # sampling rate 7e3, # passband cutoff 2e3, # transition bw 60) # stopband attenuation demodulators = [] for k in self.freqs: f = self.freqs[k] print "Setting up %s: %.3f MHz" % (k, f / 1000000.0) if_freq = f - self.center_freq chan_filt = filter.freq_xlating_fir_filter_ccf( chanfilt_decim, chan_filt_coeffs, if_freq, dev_rate) agc = analog.agc_cc(0.1, 1, 1) if options.mode == 'am': demod = blocks.complex_to_mag() squelch = analog.standard_squelch(dev_rate / 10) sq_range = squelch.squelch_range() sq = (sq_range[0] + sq_range[1]) / 2 sq = 0.7 print "Squelch: range %.1f ... %.1f, using %.2f" % ( sq_range[0], sq_range[1], sq) squelch.set_threshold(sq) audio_filt = filter.fir_filter_fff(audio_decim, audio_filt_coeffs) self.connect(chan_filt, agc, demod, squelch, audio_filt) last_block = audio_filt else: print "FM demod" demod = analog.demod_20k0f3e_cf(demod_rate, audio_decim) squelch = analog.pwr_squelch_cc( -50.0, # Power threshold 125.0 / demod_rate, # Time constant int(demod_rate / 20), # 50ms rise/fall False) # Zero, not gate output self.connect(chan_filt, squelch, agc, demod) last_block = demod demodulators.append([chan_filt, last_block]) if options.icecast: # set up a file sink fname = self.setup_upstream_pipe(k, options) float_to_int = blocks.float_to_short(scale=7500.0) file_sink = blocks.file_sink(gr.sizeof_short, fname, append=True) self.connect(last_block, float_to_int, file_sink) self.adder = None if options.audio_output != "": self.volume_control = blocks.multiply_const_ff(self.vol) self.adder = blocks.add_ff(1) # sound card as final sink self.audio_sink = audio.sink(int(audio_rate), options.audio_output, False) # ok_to_block # now wire it all together ch = 0 for d in demodulators: self.connect(self.u, d[0]) if self.adder: self.connect(d[1], (self.adder, ch)) ch += 1 if self.adder: self.connect(self.adder, self.volume_control, self.audio_sink) if options.gain is None: g = self.u.get_gain_range() # if no gain was specified, use the mid gain options.gain = (g.start() + g.stop()) / 2.0
def __init__(self): gr.top_block.__init__(self, "FM Receiver") Qt.QWidget.__init__(self) self.setWindowTitle("FM Receiver") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "FM_Receiver") try: if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"): self.restoreGeometry(self.settings.value("geometry").toByteArray()) else: self.restoreGeometry(self.settings.value("geometry")) except: pass ################################################## # Variables ################################################## self.volume = volume = 1 self.transition = transition = 1000000 self.squelch = squelch = -50 self.samp_rate = samp_rate = 2000000 self.rf_gain = rf_gain = 50 self.quadrature = quadrature = 500000 self.frec = frec = 88000000 self.cutoff = cutoff = 500000 self.audio_dec = audio_dec = 10 ################################################## # Blocks ################################################## self._volume_range = Range(0, 10, 0.25, 1, 200) self._volume_win = RangeWidget(self._volume_range, self.set_volume, 'Volume', "counter_slider", float) self.top_grid_layout.addWidget(self._volume_win) self._rf_gain_range = Range(0, 100, 1, 50, 200) self._rf_gain_win = RangeWidget(self._rf_gain_range, self.set_rf_gain, 'RF Gain', "counter_slider", float) self.top_grid_layout.addWidget(self._rf_gain_win) self._frec_range = Range(88000000, 108000000, 100000, 88000000, 200) self._frec_win = RangeWidget(self._frec_range, self.set_frec, 'Frequency', "counter_slider", float) self.top_grid_layout.addWidget(self._frec_win) self._squelch_range = Range(-100, 0, 1, -50, 200) self._squelch_win = RangeWidget(self._squelch_range, self.set_squelch, 'Squelch Level', "counter_slider", float) self.top_grid_layout.addWidget(self._squelch_win) self.rational_resampler_xxx_0_0 = filter.rational_resampler_fff( interpolation=48, decimation=50, taps=None, fractional_bw=None) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=1, decimation=4, taps=None, fractional_bw=None) self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c( 4096, #size firdes.WIN_HAMMING, #wintype 0, #fc samp_rate, #bw 'Spectrogram', #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_0.set_update_time(0.10) self.qtgui_waterfall_sink_x_0.enable_grid(False) self.qtgui_waterfall_sink_x_0.enable_axis_labels(True) labels = ['Central Frec', '', '', '', '', '', '', '', '', ''] colors = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in range(1): if len(labels[i]) == 0: self.qtgui_waterfall_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_0.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_0.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_0.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_0.set_intensity_range(-140, 10) self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance(self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_0_win) self.qtgui_time_sink_x_1 = qtgui.time_sink_c( 4096, #size samp_rate, #samp_rate 'RF Signal', #name 1 #number of inputs ) self.qtgui_time_sink_x_1.set_update_time(0.10) self.qtgui_time_sink_x_1.set_y_axis(-1, 1) self.qtgui_time_sink_x_1.set_y_label('Amplitude', "") self.qtgui_time_sink_x_1.enable_tags(True) self.qtgui_time_sink_x_1.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_1.enable_autoscale(False) self.qtgui_time_sink_x_1.enable_grid(False) self.qtgui_time_sink_x_1.enable_axis_labels(True) self.qtgui_time_sink_x_1.enable_control_panel(False) self.qtgui_time_sink_x_1.enable_stem_plot(False) labels = ['Signal 1', 'Signal 2', 'Signal 3', 'Signal 4', 'Signal 5', 'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10'] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ['blue', 'red', 'green', 'black', 'cyan', 'magenta', 'yellow', 'dark red', 'dark green', 'dark blue'] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] for i in range(2): if len(labels[i]) == 0: if (i % 2 == 0): self.qtgui_time_sink_x_1.set_line_label(i, "Re{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_1.set_line_label(i, "Im{{Data {0}}}".format(i/2)) else: self.qtgui_time_sink_x_1.set_line_label(i, labels[i]) self.qtgui_time_sink_x_1.set_line_width(i, widths[i]) self.qtgui_time_sink_x_1.set_line_color(i, colors[i]) self.qtgui_time_sink_x_1.set_line_style(i, styles[i]) self.qtgui_time_sink_x_1.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_1.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_1_win = sip.wrapinstance(self.qtgui_time_sink_x_1.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_sink_x_1_win) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 4096, #size samp_rate, #samp_rate 'Demodulated Signal WB', #name 1 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.01) self.qtgui_time_sink_x_0.set_y_axis(-1, 1) self.qtgui_time_sink_x_0.set_y_label('Amplitude', "") self.qtgui_time_sink_x_0.enable_tags(True) self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "") self.qtgui_time_sink_x_0.enable_autoscale(False) self.qtgui_time_sink_x_0.enable_grid(False) self.qtgui_time_sink_x_0.enable_axis_labels(True) self.qtgui_time_sink_x_0.enable_control_panel(False) self.qtgui_time_sink_x_0.enable_stem_plot(False) labels = ['', 'Demodulated Signal NB', 'Signal 3', 'Signal 4', 'Signal 5', 'Signal 6', 'Signal 7', 'Signal 8', 'Signal 9', 'Signal 10'] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ['blue', 'red', 'green', 'black', 'cyan', 'magenta', 'yellow', 'dark red', 'dark green', 'dark blue'] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1] for i in range(1): if len(labels[i]) == 0: self.qtgui_time_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_time_sink_x_0.set_line_label(i, labels[i]) self.qtgui_time_sink_x_0.set_line_width(i, widths[i]) self.qtgui_time_sink_x_0.set_line_color(i, colors[i]) self.qtgui_time_sink_x_0.set_line_style(i, styles[i]) self.qtgui_time_sink_x_0.set_line_marker(i, markers[i]) self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win) self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + 'hackrf=0' ) self.osmosdr_source_0.set_time_now(osmosdr.time_spec_t(time.time()), osmosdr.ALL_MBOARDS) self.osmosdr_source_0.set_sample_rate(samp_rate) self.osmosdr_source_0.set_center_freq(frec, 0) self.osmosdr_source_0.set_freq_corr(0, 0) self.osmosdr_source_0.set_gain(rf_gain, 0) self.osmosdr_source_0.set_if_gain(20, 0) self.osmosdr_source_0.set_bb_gain(20, 0) self.osmosdr_source_0.set_antenna('', 0) self.osmosdr_source_0.set_bandwidth(0, 0) self.low_pass_filter_0 = filter.fir_filter_ccf( 1, firdes.low_pass( 1, samp_rate, cutoff, transition, firdes.WIN_HAMMING, 6.76)) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(volume) self.audio_sink_0 = audio.sink(48000, 'pulse', True) self.analog_wfm_rcv_0 = analog.wfm_rcv( quad_rate=quadrature, audio_decimation=audio_dec, ) self.analog_simple_squelch_cc_0 = analog.simple_squelch_cc(-50, 1) ################################################## # Connections ################################################## self.connect((self.analog_simple_squelch_cc_0, 0), (self.analog_wfm_rcv_0, 0)) self.connect((self.analog_wfm_rcv_0, 0), (self.rational_resampler_xxx_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.analog_simple_squelch_cc_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.qtgui_time_sink_x_1, 0)) self.connect((self.osmosdr_source_0, 0), (self.qtgui_waterfall_sink_x_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.rational_resampler_xxx_0_0, 0), (self.blocks_multiply_const_vxx_0, 0))