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 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, context, mode, rtty_baud=_DEFAULT_BAUD, rtty_shift=170.0, message='\0'): gr.hier_block2.__init__( self, type(self).__name__, gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1)) encoded_message = list( map(float, _encode_rtty_alloc(map(ord, message)))) # TODO char encoding issues half_bit_rate = rtty_baud * 2 wanted_bandwidth = rtty_shift * 1.5 sample_rate_as_half_bits = int( math.ceil(wanted_bandwidth / half_bit_rate)) self.__sample_rate_out = sample_rate_as_half_bits * half_bit_rate self.__char_rate = half_bit_rate / _HALF_BITS_PER_CODE self.__baud = rtty_baud self.connect( blocks.vector_source_f(encoded_message, repeat=True), # RTTYEncoder(), blocks.repeat(gr.sizeof_float, sample_rate_as_half_bits), blocks.add_const_ff(-0.5), analog.frequency_modulator_fc( (2 * math.pi) * rtty_shift / self.__sample_rate_out), self)
def __init__(self): gr.top_block.__init__(self, "Hd Tx Rtl File") ################################################## # Blocks ################################################## self.rational_resampler_xxx_1 = filter.rational_resampler_ccc( interpolation=2, decimation=1, taps=None, fractional_bw=None) self.nrsc5_sis_encoder_0 = nrsc5.sis_encoder('ABCD') self.nrsc5_psd_encoder_0 = nrsc5.psd_encoder(0, 'Title', 'Artist') self.nrsc5_l2_encoder_0 = nrsc5.l2_encoder(1, 0, 146176) self.nrsc5_l1_fm_encoder_mp1_0 = nrsc5.l1_fm_encoder(1) self.nrsc5_hdc_encoder_0 = nrsc5.hdc_encoder(2, 64000) self.fft_vxx_0 = fft.fft_vcc(2048, False, window.rectangular(2048), True, 1) self.blocks_wavfile_source_0 = blocks.wavfile_source('sample.wav', True) self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_gr_complex*1, 2048) self.blocks_vector_source_x_0 = blocks.vector_source_c([math.sin(math.pi / 2 * i / 112) for i in range(112)] + [1] * (2048-112) + [math.cos(math.pi / 2 * i / 112) for i in range(112)], True, 1, []) self.blocks_repeat_0 = blocks.repeat(gr.sizeof_gr_complex*2048, 2) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_cc(0.5) self.blocks_keep_m_in_n_0 = blocks.keep_m_in_n(gr.sizeof_gr_complex, 2160, 4096, 0) self.blocks_interleave_0 = blocks.interleave(gr.sizeof_float*1, 1) self.blocks_float_to_uchar_0 = blocks.float_to_uchar() self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, 'hd-generated.raw', False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_conjugate_cc_0 = blocks.conjugate_cc() self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.blocks_add_const_vxx_0_0 = blocks.add_const_ff(127.5) ################################################## # Connections ################################################## self.connect((self.blocks_add_const_vxx_0_0, 0), (self.blocks_float_to_uchar_0, 0)) self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_interleave_0, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_interleave_0, 1)) self.connect((self.blocks_conjugate_cc_0, 0), (self.rational_resampler_xxx_1, 0)) self.connect((self.blocks_float_to_uchar_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_interleave_0, 0), (self.blocks_add_const_vxx_0_0, 0)) self.connect((self.blocks_keep_m_in_n_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_conjugate_cc_0, 0)) self.connect((self.blocks_repeat_0, 0), (self.blocks_vector_to_stream_0, 0)) self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_keep_m_in_n_0, 0)) self.connect((self.blocks_wavfile_source_0, 1), (self.nrsc5_hdc_encoder_0, 1)) self.connect((self.blocks_wavfile_source_0, 0), (self.nrsc5_hdc_encoder_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_repeat_0, 0)) self.connect((self.nrsc5_hdc_encoder_0, 0), (self.nrsc5_l2_encoder_0, 0)) self.connect((self.nrsc5_l1_fm_encoder_mp1_0, 0), (self.fft_vxx_0, 0)) self.connect((self.nrsc5_l2_encoder_0, 0), (self.nrsc5_l1_fm_encoder_mp1_0, 0)) self.connect((self.nrsc5_psd_encoder_0, 0), (self.nrsc5_l2_encoder_0, 1)) self.connect((self.nrsc5_sis_encoder_0, 0), (self.nrsc5_l1_fm_encoder_mp1_0, 1)) self.connect((self.rational_resampler_xxx_1, 0), (self.blocks_multiply_const_vxx_0, 0))
def __init__(self): analog_source.__init__(self, mod_name="am-ssb", audio_rate=44.1e3) self.interp = filter.fractional_resampler_ff(0.0, self.audio_rate / 200e3) self.add = blocks.add_const_ff(1.0) self.mod = blocks.multiply_ff() self.filt = filter.hilbert_fc(401) self.connect(self.random_source, self.interp, self.add, self.filt, self)
def __init__(self, syncword_threshold = None, options = None): gr.hier_block2.__init__(self, "eirsat_concatenated_deframer", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(0, 0, 0)) options_block.__init__(self, options) self.message_port_register_hier_out('out') self.delay1 = blocks.delay(gr.sizeof_float, 1) self.viterbi0 = cmc_viterbi() self.viterbi1 = cmc_viterbi() self.char2float0 = blocks.char_to_float(1, 1) self.char2float1 = blocks.char_to_float(1, 1) self.addconst0 = blocks.add_const_ff(-0.5) self.addconst1 = blocks.add_const_ff(-0.5) self.rs0 = eirsat_deframer(syncword_threshold, options) self.rs1 = eirsat_deframer(syncword_threshold, options) self.connect(self, self.viterbi0, self.char2float0, self.addconst0, self.rs0) self.connect(self, self.delay1, self.viterbi1, self.char2float1, self.addconst1, self.rs1) self.msg_connect((self.rs0, 'out'), (self, 'out')) self.msg_connect((self.rs1, 'out'), (self, 'out'))
def __init__(self, audio_rate): gr.hier_block2.__init__( self, "standard_squelch", # Input signature gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_float)) # Output signature self.input_node = blocks.add_const_ff(0) # FIXME kludge self.low_iir = filter.iir_filter_ffd((0.0193, 0, -0.0193), (1, 1.9524, -0.9615)) self.low_square = blocks.multiply_ff() self.low_smooth = filter.single_pole_iir_filter_ff( 1 / (0.01 * audio_rate)) # 100ms time constant self.hi_iir = filter.iir_filter_ffd((0.0193, 0, -0.0193), (1, 1.3597, -0.9615)) self.hi_square = blocks.multiply_ff() self.hi_smooth = filter.single_pole_iir_filter_ff(1 / (0.01 * audio_rate)) self.sub = blocks.sub_ff() self.add = blocks.add_ff() self.gate = blocks.threshold_ff(0.3, 0.43, 0) self.squelch_lpf = filter.single_pole_iir_filter_ff( 1 / (0.01 * audio_rate)) self.div = blocks.divide_ff() self.squelch_mult = blocks.multiply_ff() self.connect(self, self.input_node) self.connect(self.input_node, (self.squelch_mult, 0)) self.connect(self.input_node, self.low_iir) self.connect(self.low_iir, (self.low_square, 0)) self.connect(self.low_iir, (self.low_square, 1)) self.connect(self.low_square, self.low_smooth, (self.sub, 0)) self.connect(self.low_smooth, (self.add, 0)) self.connect(self.input_node, self.hi_iir) self.connect(self.hi_iir, (self.hi_square, 0)) self.connect(self.hi_iir, (self.hi_square, 1)) self.connect(self.hi_square, self.hi_smooth, (self.sub, 1)) self.connect(self.hi_smooth, (self.add, 1)) self.connect(self.sub, (self.div, 0)) self.connect(self.add, (self.div, 1)) self.connect(self.div, self.gate, self.squelch_lpf, (self.squelch_mult, 1)) self.connect(self.squelch_mult, self)
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 __init__(self): gr.hier_block2.__init__(self, "transmitter_amssb", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.rate = 44.1e3 / 200e3 self.interp = filter.fractional_interpolator_ff(0.0, self.rate) self.mul = blocks.multiply_const_ff(1.0) self.add = blocks.add_const_ff(1.0) self.src = analog.sig_source_f(200e3, analog.GR_SIN_WAVE, 0e3, 1.0) self.mod = blocks.multiply_ff() self.filt = filter.hilbert_fc(401) self.connect(self, self.interp, self.mul, self.add, self.mod, self.filt, self) self.connect(self.src, (self.mod, 1))
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 __init__(self, chan_rate, target_dir, freq, holdoff, file_header, file_cb, start_cb, stop_cb): gr.hier_block2.__init__(self, "indri_voice_channel", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(0, 0, 0)) self.connect(self, blocks.null_sink(gr.sizeof_float)) self.target_dir = target_dir self.freq = freq self.holdoff = holdoff bpf_taps = firdes.band_pass(1, chan_rate, 300.0, 2000.0, 100, firdes.WIN_HAMMING, 6.76) bpf = gr_filter.fir_filter_fff(1, bpf_taps) agc = analog.agc_ff(1e-5, 0.6, 1.0) rational_resampler = gr_filter.rational_resampler_fff( interpolation=16, decimation=25, taps=None, fractional_bw=0.49, ) f_bias = blocks.add_const_ff(1.0) f_scale = blocks.multiply_const_ff(125.0) f_to_char = blocks.float_to_uchar() self.connect( self, #bpf, #agc, rational_resampler, f_bias, f_scale, f_to_char) pattern = "%s/audio_%d_%%s.wav" % (self.target_dir, self.freq) ttrig = time_trigger(self.holdoff, start_cb, stop_cb, self.freq) self.time_trigger = ttrig afile_sink = timestamp_file_sink(pattern, self.holdoff, header=file_header, final_cb=file_cb) self.connect(f_to_char, afile_sink) self.connect(f_to_char, ttrig)
def __init__(self, frame_size=223, precoding=None, rs_en=True, rs_basis='dual', rs_interleaving=1, scrambler='CCSDS', convolutional='CCSDS', syncword_threshold=None, options=None): gr.hier_block2.__init__(self, 'ccsds_concatenated_deframer', gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(0, 0, 0)) options_block.__init__(self, options) self.message_port_register_hier_out('out') self.delay1 = blocks.delay(gr.sizeof_float, 1) self.viterbi0 = ccsds_viterbi(convolutional) self.viterbi1 = ccsds_viterbi(convolutional) self.char2float0 = blocks.char_to_float(1, 1) self.char2float1 = blocks.char_to_float(1, 1) self.addconst0 = blocks.add_const_ff(-0.5) self.addconst1 = blocks.add_const_ff(-0.5) self.rs0 = ccsds_rs_deframer(frame_size, precoding, rs_en, rs_basis, rs_interleaving, scrambler, syncword_threshold, options) self.rs1 = ccsds_rs_deframer(frame_size, precoding, rs_en, rs_basis, rs_interleaving, scrambler, syncword_threshold, options) self.connect(self, self.viterbi0, self.char2float0, self.addconst0, self.rs0) self.connect(self, self.delay1, self.viterbi1, self.char2float1, self.addconst1, self.rs1) self.msg_connect((self.rs0, 'out'), (self, 'out')) self.msg_connect((self.rs1, 'out'), (self, 'out'))
def __init__(self, channel_rate, audio_decim, audio_pass, audio_stop): gr.hier_block2.__init__(self, "am_demod_cf", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Input signature MAG = blocks.complex_to_mag() DCR = blocks.add_const_ff(-1.0) audio_taps = filter.optfir.low_pass(0.5, # Filter gain channel_rate, # Sample rate audio_pass, # Audio passband audio_stop, # Audio stopband 0.1, # Passband ripple 60) # Stopband attenuation LPF = filter.fir_filter_fff(audio_decim, audio_taps) self.connect(self, MAG, DCR, LPF, self)
def __init__(self): gr.hier_block2.__init__(self, "transmitter_am", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_gr_complex)) samp_rate = 200e3 self.rate = 44.1e3 / samp_rate # #self.rate = 200e3/44.1e3 self.interp = filter.fractional_interpolator_ff(0.0, self.rate) self.mul = blocks.multiply_const_ff(1.0) self.add = blocks.add_const_ff(1.0) self.src = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, 0e3, 1.0) #self.src = analog.sig_source_c(200e3, analog.GR_SIN_WAVE, 50e3, 1.0) self.mod = blocks.multiply_ff() self.cnv = blocks.float_to_complex() self.connect(self, self.interp, self.mul, self.add, self.mod, self.cnv, self) self.connect(self.src, (self.mod, 1))
def __init__(self): gr.hier_block2.__init__(self, "transmitter_amssb", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.rate = 44.1e3/200e3 #self.rate = 200e3/44.1e3 self.interp = filter.fractional_interpolator_ff(0.0, self.rate) # self.cnv = blocks.float_to_complex() self.mul = blocks.multiply_const_ff(1.0) self.add = blocks.add_const_ff(1.0) self.src = analog.sig_source_f(200e3, analog.GR_SIN_WAVE, 0e3, 1.0) #self.src = analog.sig_source_c(200e3, analog.GR_SIN_WAVE, 50e3, 1.0) self.mod = blocks.multiply_ff() #self.filt = filter.fir_filter_ccf(1, firdes.band_pass(1.0, 200e3, 10e3, 60e3, 0.25e3, firdes.WIN_HAMMING, 6.76)) self.filt = filter.hilbert_fc(401) self.connect( self, self.interp, self.mul, self.add, self.mod, self.filt, self ) self.connect( self.src, (self.mod,1) )
def __init__(self, audio_rate): gr.hier_block2.__init__(self, "standard_squelch", gr.io_signature(1, 1, gr.sizeof_float), # Input signature gr.io_signature(1, 1, gr.sizeof_float)) # Output signature self.input_node = blocks.add_const_ff(0) # FIXME kludge self.low_iir = filter.iir_filter_ffd((0.0193,0,-0.0193),(1,1.9524,-0.9615)) self.low_square = blocks.multiply_ff() self.low_smooth = filter.single_pole_iir_filter_ff(1/(0.01*audio_rate)) # 100ms time constant self.hi_iir = filter.iir_filter_ffd((0.0193,0,-0.0193),(1,1.3597,-0.9615)) self.hi_square = blocks.multiply_ff() self.hi_smooth = filter.single_pole_iir_filter_ff(1/(0.01*audio_rate)) self.sub = blocks.sub_ff(); self.add = blocks.add_ff(); self.gate = blocks.threshold_ff(0.3,0.43,0) self.squelch_lpf = filter.single_pole_iir_filter_ff(1/(0.01*audio_rate)) self.div = blocks.divide_ff() self.squelch_mult = blocks.multiply_ff() self.connect(self, self.input_node) self.connect(self.input_node, (self.squelch_mult, 0)) self.connect(self.input_node,self.low_iir) self.connect(self.low_iir,(self.low_square,0)) self.connect(self.low_iir,(self.low_square,1)) self.connect(self.low_square,self.low_smooth,(self.sub,0)) self.connect(self.low_smooth, (self.add,0)) self.connect(self.input_node,self.hi_iir) self.connect(self.hi_iir,(self.hi_square,0)) self.connect(self.hi_iir,(self.hi_square,1)) self.connect(self.hi_square,self.hi_smooth,(self.sub,1)) self.connect(self.hi_smooth, (self.add,1)) self.connect(self.sub, (self.div, 0)) self.connect(self.add, (self.div, 1)) self.connect(self.div, self.gate, self.squelch_lpf, (self.squelch_mult,1)) self.connect(self.squelch_mult, self)
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): 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, context, mode, rtty_baud=_DEFAULT_BAUD, rtty_shift=170.0, message='\0'): gr.hier_block2.__init__( self, type(self).__name__, gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1)) encoded_message = map(float, _encode_rtty_alloc(map(ord, message))) # TODO char encoding issues half_bit_rate = rtty_baud * 2 wanted_bandwidth = rtty_shift * 1.5 sample_rate_as_half_bits = int(math.ceil(wanted_bandwidth / half_bit_rate)) self.__sample_rate_out = sample_rate_as_half_bits * half_bit_rate self.__char_rate = half_bit_rate / _HALF_BITS_PER_CODE self.__baud = rtty_baud self.connect( blocks.vector_source_f(encoded_message, repeat=True), # RTTYEncoder(), blocks.repeat(gr.sizeof_float, sample_rate_as_half_bits), blocks.add_const_ff(-0.5), analog.frequency_modulator_fc((2 * math.pi) * rtty_shift / self.__sample_rate_out), self)
def __init__(self, alpha=1e-2, reference=0.5): gr.hier_block2.__init__( self, 'RMS AGC', gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), ) ################################################## # Parameters ################################################## self.alpha = alpha self.reference = reference ################################################## # Blocks ################################################## self.blocks_rms_xx_0 = blocks.rms_cf(alpha) self.blocks_multiply_const_vxx_0 = (blocks.multiply_const_ff( 1.0 / reference)) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_divide_xx_0 = blocks.divide_cc(1) self.blocks_add_const_vxx_0 = blocks.add_const_ff(1e-20) ################################################## # Connections ################################################## self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_divide_xx_0, 0), (self, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_divide_xx_0, 1)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_rms_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self, 0), (self.blocks_divide_xx_0, 0)) self.connect((self, 0), (self.blocks_rms_xx_0, 0))
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) usage="%prog: [options] [input_filename]. \n If you don't specify an input filename the usrp will be used as source\n " \ "Make sure your input capture file containes interleaved shorts not complex floats" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate") parser.add_option("-f", "--freq", type="eng_float", default=519.25e6, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-c", "--contrast", type="eng_float", default=1.0, help="set contrast (default is 1.0)") parser.add_option("-b", "--brightness", type="eng_float", default=0.0, help="set brightness (default is 0)") parser.add_option("-p", "--pal", action="store_true", default=False, help="PAL video format (this is the default)") parser.add_option("-n", "--ntsc", action="store_true", default=False, help="NTSC video format") parser.add_option( "-o", "--out-filename", type="string", default="sdl", help= "For example out_raw_uchar.gray. If you don't specify an output filename you will get a video_sink_sdl realtime output window. You then need to have gr-video-sdl installed)" ) parser.add_option("-r", "--repeat", action="store_false", default=True, help="repeat file in a loop") parser.add_option("", "--freq-min", type="eng_float", default=50.25e6, help="Set a minimum frequency [default=%default]") parser.add_option("", "--freq-max", type="eng_float", default=900.25e6, help="Set a maximum frequency [default=%default]") (options, args) = parser.parse_args() if not ((len(args) == 1) or (len(args) == 0)): parser.print_help() sys.exit(1) if len(args) == 1: filename = args[0] else: filename = None self.frame = frame self.panel = panel self.contrast = options.contrast self.brightness = options.brightness self.state = "FREQ" self.freq = 0 self.tv_freq_min = options.freq_min self.tv_freq_max = options.freq_max # build graph self.u = None if not (options.out_filename == "sdl"): options.repeat = False usrp_rate = options.samp_rate if not ((filename is None) or (filename == "usrp")): # file is data source self.filesource = 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): gr.top_block.__init__(self, "Hd Tx Am Hackrf", catch_exceptions=True) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 2000000 self.freq = freq = 1710e3 self.audio_rate = audio_rate = 44100 ################################################## # Blocks ################################################## self.rational_resampler_xxx_2 = filter.rational_resampler_ccc( interpolation=4096, decimation=243, taps=[], fractional_bw=-1.0) self.rational_resampler_xxx_1 = filter.rational_resampler_ccc( interpolation=125, decimation=49, taps=[], fractional_bw=-1.0) self.rational_resampler_xxx_0_0 = filter.rational_resampler_ccc( interpolation=200, decimation=21, taps=[], fractional_bw=-1.0) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=100, decimation=21, taps=[], fractional_bw=-1.0) self.osmosdr_sink_0 = osmosdr.sink( args="numchan=" + str(1) + " " + "" ) 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(freq + 100000, 0) self.osmosdr_sink_0.set_freq_corr(0, 0) self.osmosdr_sink_0.set_gain(0, 0) self.osmosdr_sink_0.set_if_gain(1, 0) self.osmosdr_sink_0.set_bb_gain(20, 0) self.osmosdr_sink_0.set_antenna('', 0) self.osmosdr_sink_0.set_bandwidth(1.5e6, 0) self.nrsc5_sis_encoder_0 = nrsc5.sis_encoder('ABCD') self.nrsc5_psd_encoder_0 = nrsc5.psd_encoder(0, 'Title', 'Artist') self.nrsc5_l2_encoder_0 = nrsc5.l2_encoder(1, 0, 3750) self.nrsc5_l1_am_encoder_ma1_0 = nrsc5.l1_am_encoder(1) self.nrsc5_hdc_encoder_0 = nrsc5.hdc_encoder(1, 17900) self.low_pass_filter_1 = filter.fir_filter_fff( 1, firdes.low_pass( 0.5, audio_rate, 4500, 1000, window.WIN_HAMMING, 6.76)) self.fft_vxx_0 = fft.fft_vcc(256, False, window.rectangular(256), True, 1) self.blocks_wavfile_source_1 = blocks.wavfile_source('sample_mono.wav', True) self.blocks_wavfile_source_0 = blocks.wavfile_source('sample_mono.wav', True) self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_gr_complex*1, 256) self.blocks_vector_source_x_0 = blocks.vector_source_c([math.sin(math.pi / 2 * i / 14) for i in range(14)] + [1] * (256-14) + [math.cos(math.pi / 2 * i / 14) for i in range(14)], True, 1, []) self.blocks_rotator_cc_0 = blocks.rotator_cc(-2 * math.pi * 100000 / samp_rate) self.blocks_repeat_0 = blocks.repeat(gr.sizeof_gr_complex*256, 2) self.blocks_null_source_0 = blocks.null_source(gr.sizeof_char*24000) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_keep_m_in_n_0 = blocks.keep_m_in_n(gr.sizeof_gr_complex, 270, 512, 121) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_delay_0 = blocks.delay(gr.sizeof_float*1, int(audio_rate * 5.5)) self.blocks_add_xx_0 = blocks.add_vcc(1) self.blocks_add_const_vxx_0 = blocks.add_const_ff(0.5) ################################################## # Connections ################################################## self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_rotator_cc_0, 0)) self.connect((self.blocks_delay_0, 0), (self.low_pass_filter_1, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.blocks_keep_m_in_n_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_multiply_xx_0, 0), (self.rational_resampler_xxx_1, 0)) self.connect((self.blocks_null_source_0, 0), (self.nrsc5_l1_am_encoder_ma1_0, 1)) self.connect((self.blocks_repeat_0, 0), (self.blocks_vector_to_stream_0, 0)) self.connect((self.blocks_rotator_cc_0, 0), (self.osmosdr_sink_0, 0)) self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_keep_m_in_n_0, 0)) self.connect((self.blocks_wavfile_source_0, 0), (self.nrsc5_hdc_encoder_0, 0)) self.connect((self.blocks_wavfile_source_1, 0), (self.blocks_delay_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_repeat_0, 0)) self.connect((self.low_pass_filter_1, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.nrsc5_hdc_encoder_0, 0), (self.nrsc5_l2_encoder_0, 0)) self.connect((self.nrsc5_l1_am_encoder_ma1_0, 0), (self.fft_vxx_0, 0)) self.connect((self.nrsc5_l2_encoder_0, 0), (self.nrsc5_l1_am_encoder_ma1_0, 0)) self.connect((self.nrsc5_psd_encoder_0, 0), (self.nrsc5_l2_encoder_0, 1)) self.connect((self.nrsc5_sis_encoder_0, 0), (self.nrsc5_l1_am_encoder_ma1_0, 2)) self.connect((self.rational_resampler_xxx_0, 0), (self.rational_resampler_xxx_0_0, 0)) self.connect((self.rational_resampler_xxx_0_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.rational_resampler_xxx_1, 0), (self.rational_resampler_xxx_2, 0)) self.connect((self.rational_resampler_xxx_2, 0), (self.blocks_add_xx_0, 0))
def __init__(self): gr.top_block.__init__(self) usage=("%prog: [options] output_filename.\nSpecial output_filename" + \ "\"sdl\" will use video_sink_sdl as realtime output window. " + \ "You then need to have gr-video-sdl installed.\n" +\ "Make sure your input capture file containes interleaved " + \ "shorts not complex floats") parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate") parser.add_option("-c", "--contrast", type="eng_float", default=1.0, help="set contrast (default is 1.0)") parser.add_option("-b", "--brightness", type="eng_float", default=0.0, help="set brightness (default is 0)") parser.add_option("-i", "--in-filename", type="string", default=None, help="Use input file as source. samples must be " + \ "interleaved shorts \n Use usrp_rx_file.py or " + \ "usrp_rx_cfile.py --output-shorts.\n Special " + \ "name \"usrp\" results in realtime capturing " + \ "and processing using usrp.\n" + \ "You then probably need a decimation factor of 64 or higher.") parser.add_option( "-f", "--freq", type="eng_float", default=519.25e6, help= "set frequency to FREQ.\nNote that the frequency of the video carrier is not at the middle of the TV channel", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-p", "--pal", action="store_true", default=False, help="PAL video format (this is the default)") parser.add_option("-n", "--ntsc", action="store_true", default=False, help="NTSC video format") parser.add_option("-r", "--repeat", action="store_false", default=True, help="repeat in_file in a loop") parser.add_option("-N", "--nframes", type="eng_float", default=None, help="number of frames to collect [default=+inf]") parser.add_option("", "--freq-min", type="eng_float", default=50.25e6, help="Set a minimum frequency [default=%default]") parser.add_option("", "--freq-max", type="eng_float", default=900.25e6, help="Set a maximum frequency [default=%default]") (options, args) = parser.parse_args() if not (len(args) == 1): parser.print_help() sys.stderr.write('You must specify the output. FILENAME or sdl \n') sys.exit(1) filename = args[0] self.tv_freq_min = options.freq_min self.tv_freq_max = options.freq_max if options.in_filename is None: parser.print_help() sys.stderr.write( 'You must specify the input -i FILENAME or -i usrp\n') raise SystemExit, 1 if not (filename == "sdl"): options.repeat = False input_rate = options.samp_rate print "video sample rate %s" % (eng_notation.num_to_str(input_rate)) if not (options.in_filename == "usrp"): # file is data source, capture with usr_rx_csfile.py self.filesource = blocks.file_source(gr.sizeof_short, options.in_filename, options.repeat) self.istoc = blocks.interleaved_short_to_complex() self.connect(self.filesource, self.istoc) self.src = self.istoc else: if options.freq is None: parser.print_help() sys.stderr.write( 'You must specify the frequency with -f FREQ\n') raise SystemExit, 1 # build the graph self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if (options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if (options.antenna): self.u.set_antenna(options.antenna, 0) self.u.set_samp_rate(input_rate) dev_rate = self.u.get_samp_rate() self.src = self.u if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start() + g.stop()) / 2.0 self.u.set_gain(options.gain) r = self.u.set_center_freq(options.freq) if not r: sys.stderr.write('Failed to set frequency\n') raise SystemExit, 1 self.agc = 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(options.brightness + 255.0) self.invert_and_scale = blocks.multiply_const_ff( -options.contrast * 128.0 * 255.0 / (200.0)) self.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(input_rate / (lines_per_frame * frames_per_sec)) height = int(lines_per_frame) if filename == "sdl": #Here comes the tv screen, you have to build and install #gr-video-sdl for this (subproject of gnuradio) try: video_sink = video_sdl.sink_uc(frames_per_sec, width, height, 0, show_width, height) except: print "gr-video-sdl is not installed" print "realtime \"sdl\" video output window is not available" raise SystemExit, 1 self.dst = video_sink else: print "You can use the imagemagick display tool to show the resulting imagesequence" print "use the following line to show the demodulated TV-signal:" print "display -depth 8 -size " + str(width) + "x" + str( height) + " gray:" + filename print "(Use the spacebar to advance to next frames)" file_sink = blocks.file_sink(gr.sizeof_char, filename) self.dst = file_sink if options.nframes is None: self.connect(self.src, self.agc) else: self.head = blocks.head(gr.sizeof_gr_complex, int(options.nframes * width * height)) self.connect(self.src, self.head, self.agc) self.connect(self.agc, self.am_demod, self.invert_and_scale, self.set_blacklevel, self.f2uc, self.dst)
def __init__(self): gr.top_block.__init__(self, "Symbol Mapping Demo", catch_exceptions=True) Qt.QWidget.__init__(self) self.setWindowTitle("Symbol Mapping Demo") 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", "symbol_mapping_demo") 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 = 32000 self.constellation_order = constellation_order = 6 ################################################## # Blocks ################################################## self.symbolmapping_symbol_mapper_bc_0 = symbolmapping.symbol_mapper_bc( constellation_order, 'GRAY', True) self.symbolmapping_symbol_demapper_cf_0 = symbolmapping.symbol_demapper_cf( constellation_order, 'GRAY', 'snr') self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 1024, #size samp_rate, #samp_rate "", #name 2, #number of inputs None # parent ) self.qtgui_time_sink_x_0.set_update_time(0.10) self.qtgui_time_sink_x_0.set_y_axis(-1, 260) 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 = [ '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: 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.qtgui_const_sink_x_0 = qtgui.const_sink_c( 1024, #size "", #name 1, #number of inputs None # parent ) 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 = [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.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.top_grid_layout.addWidget(self._qtgui_const_sink_x_0_win) self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb() self.blocks_unpacked_to_packed_xx_0 = blocks.unpacked_to_packed_bb( 1, gr.GR_MSB_FIRST) self.blocks_uchar_to_float_0_0 = 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_float_to_char_0 = blocks.float_to_char(1, 1) self.blocks_char_to_float_0_0 = blocks.char_to_float(1, -1) self.blocks_add_const_vxx_0 = blocks.add_const_ff(1) self.analog_random_uniform_source_x_0 = analog.random_uniform_source_b( 0, 256, 0) ################################################## # Connections ################################################## self.connect((self.analog_random_uniform_source_x_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_float_to_char_0, 0)) self.connect((self.blocks_char_to_float_0_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_float_to_char_0, 0), (self.blocks_unpacked_to_packed_xx_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_uchar_to_float_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.symbolmapping_symbol_mapper_bc_0, 0)) self.connect((self.blocks_uchar_to_float_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blocks_uchar_to_float_0_0, 0), (self.qtgui_time_sink_x_0, 1)) self.connect((self.blocks_unpacked_to_packed_xx_0, 0), (self.blocks_uchar_to_float_0_0, 0)) self.connect((self.digital_binary_slicer_fb_0, 0), (self.blocks_char_to_float_0_0, 0)) self.connect((self.symbolmapping_symbol_demapper_cf_0, 0), (self.digital_binary_slicer_fb_0, 0)) self.connect((self.symbolmapping_symbol_mapper_bc_0, 0), (self.qtgui_const_sink_x_0, 0)) self.connect((self.symbolmapping_symbol_mapper_bc_0, 0), (self.symbolmapping_symbol_demapper_cf_0, 0))
def __init__(self, fft_length, cp_length, logging=False): """ OFDM synchronization using PN Correlation: T. M. Schmidl and D. C. Cox, "Robust Frequency and Timing Synchronization for OFDM," IEEE Trans. Communications, vol. 45, no. 12, 1997. """ gr.hier_block2.__init__(self, "ofdm_sync_pn", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature2(2, 2, gr.sizeof_float, gr.sizeof_char)) # Output signature self.input = blocks.add_const_cc(0) # PN Sync # Create a delay line self.delay = blocks.delay(gr.sizeof_gr_complex, fft_length/2) # Correlation from ML Sync self.conjg = blocks.conjugate_cc(); self.corr = blocks.multiply_cc(); # Create a moving sum filter for the corr output self.moving_sum_filter = filter.fir_filter_ccf(1, [1.0] * (fft_length//2)) # Create a moving sum filter for the input self.inputmag2 = blocks.complex_to_mag_squared() self.inputmovingsum = filter.fir_filter_fff(1, [1.0] * (fft_length//2)) self.square = blocks.multiply_ff() self.normalize = blocks.divide_ff() # Get magnitude (peaks) and angle (phase/freq error) self.c2mag = blocks.complex_to_mag_squared() self.angle = blocks.complex_to_arg() self.sample_and_hold = blocks.sample_and_hold_ff() #ML measurements input to sampler block and detect self.sub1 = blocks.add_const_ff(-1) self.pk_detect = blocks.peak_detector_fb(0.20, 0.20, 30, 0.001) self.connect(self, self.input) # Calculate the frequency offset from the correlation of the preamble self.connect(self.input, self.delay) self.connect(self.input, (self.corr,0)) self.connect(self.delay, self.conjg) self.connect(self.conjg, (self.corr,1)) self.connect(self.corr, self.moving_sum_filter) self.connect(self.moving_sum_filter, self.c2mag) self.connect(self.moving_sum_filter, self.angle) self.connect(self.angle, (self.sample_and_hold,0)) # Get the power of the input signal to normalize the output of the correlation self.connect(self.input, self.inputmag2, self.inputmovingsum) self.connect(self.inputmovingsum, (self.square,0)) self.connect(self.inputmovingsum, (self.square,1)) self.connect(self.square, (self.normalize,1)) self.connect(self.c2mag, (self.normalize,0)) # Create a moving sum filter for the corr output matched_filter_taps = [1.0/cp_length for i in range(cp_length)] self.matched_filter = filter.fir_filter_fff(1,matched_filter_taps) self.connect(self.normalize, self.matched_filter) self.connect(self.matched_filter, self.sub1, self.pk_detect) #self.connect(self.matched_filter, self.pk_detect) self.connect(self.pk_detect, (self.sample_and_hold,1)) # Set output signals # Output 0: fine frequency correction value # Output 1: timing signal self.connect(self.sample_and_hold, (self,0)) self.connect(self.pk_detect, (self,1)) if logging: self.connect(self.matched_filter, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pn-mf_f.dat")) self.connect(self.normalize, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pn-theta_f.dat")) self.connect(self.angle, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pn-epsilon_f.dat")) self.connect(self.pk_detect, blocks.file_sink(gr.sizeof_char, "ofdm_sync_pn-peaks_b.dat")) self.connect(self.sample_and_hold, blocks.file_sink(gr.sizeof_float, "ofdm_sync_pn-sample_and_hold_f.dat")) self.connect(self.input, blocks.file_sink(gr.sizeof_gr_complex, "ofdm_sync_pn-input_c.dat"))
def __init__(self): gr.top_block.__init__(self, "RTTY_vco", catch_exceptions=True) Qt.QWidget.__init__(self) self.setWindowTitle("RTTY_vco") 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", "RTTY_vco") 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.vco_max = vco_max = 2500 self.fsk_deviation = fsk_deviation = 170 self.center = center = 2210 self.vco_offset = vco_offset = (center - (fsk_deviation / 2)) / vco_max self.samp_rate = samp_rate = 48000 self.repeat = repeat = (int)(samp_rate * 0.022) self.inp_amp = inp_amp = ((center + (fsk_deviation / 2)) / vco_max) - vco_offset self.baud = baud = 1 / 0.022 ################################################## # Blocks ################################################## self.zeromq_pull_msg_source_0 = zeromq.pull_msg_source( 'tcp://127.0.0.1:50251', 100, False) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 4096, #size samp_rate, #samp_rate "", #name 2, #number of inputs None # parent ) self.qtgui_time_sink_x_0.set_update_time(0.10) self.qtgui_time_sink_x_0.set_y_axis(-1, 1.5) 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_NORM, qtgui.TRIG_SLOPE_NEG, 0.5, 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(True) self.qtgui_time_sink_x_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: 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.low_pass_filter_0 = filter.fir_filter_fff( 1, firdes.low_pass(1, samp_rate, 200, 1000, firdes.WIN_HAMMING, 6.76)) self.epy_block_0_0 = epy_block_0_0.mc_sync_block() self.blocks_vco_f_0 = blocks.vco_f(samp_rate, 15708, 0.5) self.blocks_uchar_to_float_0 = blocks.uchar_to_float() 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_add_const_vxx_0 = blocks.add_const_ff(vco_offset) self.audio_sink_0 = audio.sink(48000, '', True) ################################################## # Connections ################################################## self.msg_connect((self.zeromq_pull_msg_source_0, 'out'), (self.epy_block_0_0, 'msg_in')) self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_vco_f_0, 0)) 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_uchar_to_float_0, 0)) self.connect((self.blocks_uchar_to_float_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.blocks_vco_f_0, 0), (self.audio_sink_0, 0)) self.connect((self.blocks_vco_f_0, 0), (self.qtgui_time_sink_x_0, 1)) self.connect((self.epy_block_0_0, 0), (self.blocks_repeat_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.qtgui_time_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", "trx") 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 = 1.161e6 ################################################## # Blocks ################################################## self.vlc_nic_interface_b_0 = vlc.nic_interface_b('/tmp/vlc_gr_server') self.vlc_board_interface_b_0 = vlc.board_interface_bb( '192.168.1.22', 7777, 6666, 256) self.qtgui_time_sink_x_1 = qtgui.time_sink_f( 1024, #size 1, #samp_rate "", #name 2 #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: 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.qtgui_time_sink_x_0_0 = qtgui.time_sink_f( 1024, #size 1, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_0_0.set_update_time(0.1) self.qtgui_time_sink_x_0_0.set_y_axis(-1, 256) 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(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(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_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.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_0_win) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 1024, #size samp_rate, #samp_rate "", #name 1 #number of inputs ) self.qtgui_time_sink_x_0.set_update_time(0.1) self.qtgui_time_sink_x_0.set_y_axis(-1, 256) 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 = [ '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.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.digital_psk_mod_0 = digital.psk.psk_mod(constellation_points=4, mod_code="gray", differential=True, samples_per_symbol=8, excess_bw=0.35, verbose=True, log=True) self.digital_psk_demod_0 = digital.psk.psk_demod( constellation_points=4, differential=True, samples_per_symbol=8, excess_bw=0.35, phase_bw=6.28 / 100.0, timing_bw=6.28 / 100.0, mod_code="gray", verbose=False, log=False) self.blocks_uchar_to_float_0_0 = blocks.uchar_to_float() self.blocks_uchar_to_float_0 = blocks.uchar_to_float() self.blocks_pack_k_bits_bb_0 = blocks.pack_k_bits_bb(8) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(255 / 6) self.blocks_float_to_uchar_0 = blocks.float_to_uchar() self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char * 1, 'out.gr', False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.blocks_add_xx_0 = blocks.add_vff(1) self.blocks_add_const_vxx_0 = blocks.add_const_ff(3) ################################################## # Connections ################################################## self.msg_connect( (self.vlc_board_interface_b_0, 'vlc_board_int_msg_out'), (self.vlc_nic_interface_b_0, 'msg_in')) self.msg_connect( (self.vlc_nic_interface_b_0, 'msg_out'), (self.vlc_board_interface_b_0, 'vlc_board_int_msg_in')) self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_complex_to_float_0, 0), (self.qtgui_time_sink_x_1, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.qtgui_time_sink_x_1, 1)) self.connect((self.blocks_float_to_uchar_0, 0), (self.vlc_board_interface_b_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_float_to_uchar_0, 0)) self.connect((self.blocks_pack_k_bits_bb_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_uchar_to_float_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blocks_uchar_to_float_0_0, 0), (self.qtgui_time_sink_x_0_0, 0)) self.connect((self.digital_psk_demod_0, 0), (self.blocks_pack_k_bits_bb_0, 0)) self.connect((self.digital_psk_demod_0, 0), (self.blocks_uchar_to_float_0_0, 0)) self.connect((self.digital_psk_mod_0, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.digital_psk_mod_0, 0), (self.digital_psk_demod_0, 0)) self.connect((self.vlc_board_interface_b_0, 0), (self.blocks_uchar_to_float_0, 0)) self.connect((self.vlc_nic_interface_b_0, 0), (self.digital_psk_mod_0, 0))
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_interface", 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; message_collector_connected=False; ##anything going through the annihilator needs shifted, uchar vals if fec.get_conversion(decoder_obj_list[0]) == "uchar" or fec.get_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_conversion(decoder_obj_list[0]) == "packed_bits": self.blocks.append(blocks.add_const_ff(128.0)); if fec.get_conversion(decoder_obj_list[0]) == "uchar" or fec.get_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 read_big_bitlist(ann): cat.append(i); synd_garble = .49; idx_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 corr_bb' print 'ceiling: .0335 data garble rate' self.blocks.append(fec.corr_bb(cat, len(puncpat) - puncpat.count('0'), len(ann), integration_period, flush, synd_garble)); #print puncpat if self.puncpat != '11': self.blocks.append(fec.reinflate_bb(0, read_bitlist(puncpat), puncpat.count('0'), len(puncpat))); if fec.get_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): assert fec.get_history(decoder_obj_list[0]) == 0; 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_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, parent, unit='units', minval=0, maxval=1, factor=1, decimal_places=3, ref_level=0, sample_rate=1, number_rate=number_window.DEFAULT_NUMBER_RATE, average=False, avg_alpha=None, label='Number Plot', size=number_window.DEFAULT_WIN_SIZE, peak_hold=False, show_gauge=True, **kwargs #catchall for backwards compatibility ): #ensure avg alpha if avg_alpha is None: avg_alpha = 2.0/number_rate #init gr.hier_block2.__init__( self, "number_sink", gr.io_signature(1, 1, self._item_size), gr.io_signature(0, 0, 0), ) #blocks sd = blocks.stream_to_vector_decimator( item_size=self._item_size, sample_rate=sample_rate, vec_rate=number_rate, vec_len=1, ) if self._real: mult = blocks.multiply_const_ff(factor) add = blocks.add_const_ff(ref_level) avg = filter.single_pole_iir_filter_ff(1.0) else: mult = blocks.multiply_const_cc(factor) add = blocks.add_const_cc(ref_level) avg = filter.single_pole_iir_filter_cc(1.0) msgq = gr.msg_queue(2) sink = blocks.message_sink(self._item_size, msgq, True) #controller self.controller = pubsub() self.controller.subscribe(SAMPLE_RATE_KEY, sd.set_sample_rate) self.controller.publish(SAMPLE_RATE_KEY, sd.sample_rate) self.controller[AVERAGE_KEY] = average self.controller[AVG_ALPHA_KEY] = avg_alpha def update_avg(*args): if self.controller[AVERAGE_KEY]: avg.set_taps(self.controller[AVG_ALPHA_KEY]) else: avg.set_taps(1.0) update_avg() self.controller.subscribe(AVERAGE_KEY, update_avg) self.controller.subscribe(AVG_ALPHA_KEY, update_avg) #start input watcher common.input_watcher(msgq, self.controller, MSG_KEY) #create window self.win = number_window.number_window( parent=parent, controller=self.controller, size=size, title=label, units=unit, real=self._real, minval=minval, maxval=maxval, decimal_places=decimal_places, show_gauge=show_gauge, average_key=AVERAGE_KEY, avg_alpha_key=AVG_ALPHA_KEY, peak_hold=peak_hold, msg_key=MSG_KEY, sample_rate_key=SAMPLE_RATE_KEY, ) common.register_access_methods(self, self.controller) #backwards compadibility self.set_show_gauge = self.win.show_gauges #connect self.wxgui_connect(self, sd, mult, add, avg, sink)
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.label_3 = wx.StaticText(self, -1, "AM Sync\nCarrier") self.slider_6 = wx.Slider(self, ID_SLIDER_6, 50, 0, 200, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.label_4 = wx.StaticText(self, -1, "Antenna Tune") self.slider_7 = wx.Slider(self, ID_SLIDER_7, 1575, 950, 2200, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.panel_10 = wx.Panel(self, -1) self.button_12 = wx.ToggleButton(self, ID_BUTTON_12, "Auto Tune") self.button_13 = wx.Button(self, ID_BUTTON_13, "Calibrate") self.button_14 = wx.Button(self, ID_BUTTON_14, "Reset") 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( "", "--address", type="string", default="addr=192.168.10.2", help="Address of UHD device, [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=256e3, 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", ) (options, args) = parser.parse_args() self.usrp_center = options.ddc_freq 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 = 32000 fir_decim = long(input_rate / self.af_sample_rate) # data point arrays for antenna tuner self.xdata = [] self.ydata = [] 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 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(device_addr=options.address, io_type=uhd.io_type.COMPLEX_FLOAT32, num_channels=1) self.src.set_samp_rate(input_rate) input_rate = self.src.get_samp_rate() self.src.set_center_freq(self.usrp_center, 0) self.tune_offset = 0 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)) # 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) # Complex Audio filter audio_coeffs = filter.firdes.complex_band_pass( 1.0, # gain self.af_sample_rate, # sample rate -3000, # low cutoff 0, # high cutoff 100, # transition filter.firdes.WIN_HAMMING, ) # window self.slider_fcutoff_hi.SetValue(0) self.slider_fcutoff_lo.SetValue(-3000) self.audio_filter = filter.fir_filter_ccc(1, 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) ) # AM Sync carrier if AM_SYNC_DISPLAY: self.fft2 = fftsink.fft_sink_c( self.tb, self.panel_9, y_per_div=20, fft_size=512, sample_rate=self.af_sample_rate, average=True, size=(640, 240), ) 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( 0.5, 0.0625, (2.0 * math.pi * 7.5e3 / self.af_sample_rate), (2.0 * 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([0.004, 0], [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)) if AM_SYNC_DISPLAY: self.tb.connect(self.pll_carrier_filter, self.fft2) 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, 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() # for mouse position reporting on fft display self.fft.win.Bind(wx.EVT_LEFT_UP, self.Mouse) # and left click to re-tune self.fft.win.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_BUTTON(self, ID_BUTTON_13, self.AT_calibrate) wx.EVT_BUTTON(self, ID_BUTTON_14, self.AT_reset) 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_SLIDER(self, ID_SLIDER_6, self.am_carrier) wx.EVT_SLIDER(self, ID_SLIDER_7, self.antenna_tune) 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, "lab06_pam002") Qt.QWidget.__init__(self) self.setWindowTitle("lab06_pam002") 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", "lab06_pam002") 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.sym_dly = sym_dly = 0 self.sps = sps = 8 self.samp_rate = samp_rate = 32000 self.samp_dly = samp_dly = 0 self.ptype = ptype = "rect" self.pparams = pparams = 5, 0.5 self.nfilts = nfilts = 8 self.gain = gain = 1 self.Fs = Fs = 256000 ################################################## # Blocks ################################################## self._sym_dly_range = Range(0, 16, 1, 0, 200) self._sym_dly_win = RangeWidget(self._sym_dly_range, self.set_sym_dly, 'sym_dly', "counter_slider", float) self.top_grid_layout.addWidget(self._sym_dly_win) self._gain_range = Range(0, 2, 0.1, 1, 200) self._gain_win = RangeWidget(self._gain_range, self.set_gain, 'gain', "counter_slider", float) self.top_grid_layout.addWidget(self._gain_win) self._samp_dly_range = Range(0, 16, 1, 0, 200) self._samp_dly_win = RangeWidget(self._samp_dly_range, self.set_samp_dly, 'samp_dly', "counter_slider", float) self.top_grid_layout.addWidget(self._samp_dly_win) self.qtgui_time_sink_x_0_0 = qtgui.time_sink_f( 1024, #size samp_rate, #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(-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(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(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: 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.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_0_win) self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 1024, #size samp_rate, #samp_rate "", #name 1 #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(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.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) # Create the options list self._ptype_options = ( "rect", "rcf", "rrcf", ) # Create the labels list self._ptype_labels = ( '', '', '', ) # Create the combo box self._ptype_tool_bar = Qt.QToolBar(self) self._ptype_tool_bar.addWidget(Qt.QLabel('ptype' + ": ")) self._ptype_combo_box = Qt.QComboBox() self._ptype_tool_bar.addWidget(self._ptype_combo_box) for _label in self._ptype_labels: self._ptype_combo_box.addItem(_label) self._ptype_callback = lambda i: Qt.QMetaObject.invokeMethod( self._ptype_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._ptype_options.index(i))) self._ptype_callback(self.ptype) self._ptype_combo_box.currentIndexChanged.connect( lambda i: self.set_ptype(self._ptype_options[i])) # Create the radio buttons self.top_grid_layout.addWidget(self._ptype_tool_bar) self.interp_fir_filter_xxx_0_0 = filter.interp_fir_filter_fff(sps, [1]) self.interp_fir_filter_xxx_0_0.declare_sample_delay(0) self.interp_fir_filter_xxx_0 = filter.interp_fir_filter_fff( sps, [1, 1, 1, 1, 1, 1, 1, 1]) self.interp_fir_filter_xxx_0.declare_sample_delay(0) self.fir_filter_xxx_0_1 = filter.fir_filter_fff( 1, firdes.root_raised_cosine(nfilts, nfilts, 1.0 / float(sps), 0.35, 11 * sps * nfilts)) self.fir_filter_xxx_0_1.declare_sample_delay(0) self.fir_filter_xxx_0_0 = filter.fir_filter_fff(sps, [1]) self.fir_filter_xxx_0_0.declare_sample_delay(0) self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb() self.blocks_vector_source_x_0 = blocks.vector_source_b( list(ord(i) for i in 'The quick brown fox...'), True, 1, []) self.blocks_unpacked_to_packed_xx_0 = blocks.unpacked_to_packed_bb( 1, gr.GR_LSB_FIRST) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char * 1, samp_rate, True) self.blocks_packed_to_unpacked_xx_0 = blocks.packed_to_unpacked_bb( 1, gr.GR_LSB_FIRST) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(gain) self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char * 1, '/dev/pts/0', False) self.blocks_file_sink_0.set_unbuffered(False) self.blocks_delay_0_0 = blocks.delay(gr.sizeof_float * 1, sym_dly) self.blocks_delay_0 = blocks.delay(gr.sizeof_char * 1, sym_dly) self.blocks_char_to_float_0 = blocks.char_to_float(1, 0.5) self.blocks_add_const_vxx_0 = blocks.add_const_ff(-1) ################################################## # Connections ################################################## self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.interp_fir_filter_xxx_0, 0)) self.connect((self.blocks_char_to_float_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_delay_0, 0), (self.blocks_unpacked_to_packed_xx_0, 0)) self.connect((self.blocks_delay_0_0, 0), (self.fir_filter_xxx_0_0, 0)) self.connect((self.blocks_delay_0_0, 0), (self.qtgui_time_sink_x_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.fir_filter_xxx_0_1, 0)) self.connect((self.blocks_packed_to_unpacked_xx_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.blocks_unpacked_to_packed_xx_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_packed_to_unpacked_xx_0, 0)) self.connect((self.digital_binary_slicer_fb_0, 0), (self.blocks_delay_0, 0)) self.connect((self.fir_filter_xxx_0_0, 0), (self.digital_binary_slicer_fb_0, 0)) self.connect((self.fir_filter_xxx_0_0, 0), (self.interp_fir_filter_xxx_0_0, 0)) self.connect((self.fir_filter_xxx_0_1, 0), (self.blocks_delay_0_0, 0)) self.connect((self.interp_fir_filter_xxx_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.interp_fir_filter_xxx_0_0, 0), (self.qtgui_time_sink_x_0_0, 1))
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", "lab5_4fsk_demod") 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.fsk_deviation_hz = fsk_deviation_hz = 5000 self.samples_per_second = samples_per_second = 200 self.samp_rate = samp_rate = 4e5 self.filter_transition = filter_transition = 750 self.filter_cutoff = filter_cutoff = 3.5 * fsk_deviation_hz self.carrier_freq = carrier_freq = 20000 ################################################## # Blocks ################################################## self._fsk_deviation_hz_tool_bar = Qt.QToolBar(self) self._fsk_deviation_hz_tool_bar.addWidget( Qt.QLabel('fsk_deviation_hz' + ": ")) self._fsk_deviation_hz_line_edit = Qt.QLineEdit( str(self.fsk_deviation_hz)) self._fsk_deviation_hz_tool_bar.addWidget( self._fsk_deviation_hz_line_edit) self._fsk_deviation_hz_line_edit.returnPressed.connect( lambda: self.set_fsk_deviation_hz( int(str(self._fsk_deviation_hz_line_edit.text())))) self.top_grid_layout.addWidget(self._fsk_deviation_hz_tool_bar) self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw 'Demodulator Input', #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 = ['', '', '', '', '', '', '', '', '', ''] 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_f( 4096, #size samp_rate, #samp_rate 'Reciever Output', #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(1): 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.qtgui_time_sink_x_0 = qtgui.time_sink_f( 1024, #size samp_rate, #samp_rate 'Demodulator Output', #name 1 #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(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.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.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc( 1, firdes.low_pass(1, samp_rate, filter_cutoff, filter_transition), 0, samp_rate) self._carrier_freq_tool_bar = Qt.QToolBar(self) self._carrier_freq_tool_bar.addWidget(Qt.QLabel('carrier_freq' + ": ")) self._carrier_freq_line_edit = Qt.QLineEdit(str(self.carrier_freq)) self._carrier_freq_tool_bar.addWidget(self._carrier_freq_line_edit) self._carrier_freq_line_edit.returnPressed.connect( lambda: self.set_carrier_freq( int(str(self._carrier_freq_line_edit.text())))) self.top_grid_layout.addWidget(self._carrier_freq_tool_bar) self.blocks_unpacked_to_packed_xx_0 = blocks.unpacked_to_packed_bb( 2, gr.GR_MSB_FIRST) self.blocks_uchar_to_float_0 = blocks.uchar_to_float() self.blocks_keep_one_in_n_0 = blocks.keep_one_in_n( gr.sizeof_char * 1, samples_per_second) self.blocks_float_to_char_0 = blocks.float_to_char(1, 0.5) self.blocks_file_source_0 = blocks.file_source( gr.sizeof_gr_complex * 1, '/ad/eng/users/k/r/kremerme/Desktop/ec415/lab5/lab5_4fsk(1).iq', False, 0, 0) self.blocks_file_source_0.set_begin_tag(pmt.PMT_NIL) self.blocks_file_sink_0 = blocks.file_sink( gr.sizeof_char * 1, '/ad/eng/users/k/r/kremerme/Desktop/ec415/lab5/4fsk_out.bin', False) self.blocks_file_sink_0.set_unbuffered(True) self.blocks_add_const_vxx_0 = blocks.add_const_ff(3) self.analog_quadrature_demod_cf_0 = analog.quadrature_demod_cf( samp_rate / (2 * math.pi * fsk_deviation_hz)) ################################################## # Connections ################################################## self.connect((self.analog_quadrature_demod_cf_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.analog_quadrature_demod_cf_0, 0), (self.qtgui_time_sink_x_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_float_to_char_0, 0)) self.connect((self.blocks_file_source_0, 0), (self.freq_xlating_fir_filter_xxx_0, 0)) self.connect((self.blocks_float_to_char_0, 0), (self.blocks_keep_one_in_n_0, 0)) self.connect((self.blocks_float_to_char_0, 0), (self.blocks_uchar_to_float_0, 0)) self.connect((self.blocks_keep_one_in_n_0, 0), (self.blocks_unpacked_to_packed_xx_0, 0)) self.connect((self.blocks_uchar_to_float_0, 0), (self.qtgui_time_sink_x_1, 0)) self.connect((self.blocks_unpacked_to_packed_xx_0, 0), (self.blocks_file_sink_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.analog_quadrature_demod_cf_0, 0)) self.connect((self.freq_xlating_fir_filter_xxx_0, 0), (self.qtgui_waterfall_sink_x_0, 0))
def __init__(self): gr.top_block.__init__(self, "Hd Tx Am Soundcard") ################################################## # Variables ################################################## self.audio_rate = audio_rate = 44100 ################################################## # Blocks ################################################## self.rational_resampler_xxx_1 = filter.rational_resampler_ccc( interpolation=128, decimation=135, taps=None, fractional_bw=None) self.nrsc5_sis_encoder_0 = nrsc5.sis_encoder('ABCD') self.nrsc5_psd_encoder_0 = nrsc5.psd_encoder(0, 'Title', 'Artist') self.nrsc5_l2_encoder_0 = nrsc5.l2_encoder(1, 0, 3750) self.nrsc5_l1_am_encoder_ma1_0 = nrsc5.l1_am_encoder(1) self.nrsc5_hdc_encoder_0 = nrsc5.hdc_encoder(1, 17900) self.low_pass_filter_1 = filter.fir_filter_fff( 1, firdes.low_pass( 0.5, audio_rate, 4500, 1000, firdes.WIN_HAMMING, 6.76)) self.fft_vxx_0 = fft.fft_vcc(256, False, window.rectangular(256), True, 1) self.blocks_wavfile_source_1 = blocks.wavfile_source('sample_mono.wav', True) self.blocks_wavfile_source_0 = blocks.wavfile_source('sample_mono.wav', True) self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_gr_complex*1, 256) self.blocks_vector_source_x_0 = blocks.vector_source_c([math.sin(math.pi / 2 * i / 14) for i in range(14)] + [1] * (256-14) + [math.cos(math.pi / 2 * i / 14) for i in range(14)], True, 1, []) self.blocks_repeat_0 = blocks.repeat(gr.sizeof_gr_complex*256, 2) self.blocks_null_source_0 = blocks.null_source(gr.sizeof_char*24000) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_cc(0.7) self.blocks_keep_m_in_n_0 = blocks.keep_m_in_n(gr.sizeof_gr_complex, 270, 512, 121) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_delay_0 = blocks.delay(gr.sizeof_float*1, int(audio_rate * 5.5)) self.blocks_complex_to_float_0 = blocks.complex_to_float(1) self.blocks_add_xx_0 = blocks.add_vcc(1) self.blocks_add_const_vxx_0 = blocks.add_const_ff(0.5) self.audio_sink_0 = audio.sink(44100, '', True) ################################################## # Connections ################################################## self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_complex_to_float_0, 0), (self.audio_sink_0, 0)) self.connect((self.blocks_complex_to_float_0, 1), (self.audio_sink_0, 1)) self.connect((self.blocks_delay_0, 0), (self.low_pass_filter_1, 0)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_keep_m_in_n_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_complex_to_float_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.rational_resampler_xxx_1, 0)) self.connect((self.blocks_null_source_0, 0), (self.nrsc5_l1_am_encoder_ma1_0, 1)) self.connect((self.blocks_repeat_0, 0), (self.blocks_vector_to_stream_0, 0)) self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_keep_m_in_n_0, 0)) self.connect((self.blocks_wavfile_source_0, 0), (self.nrsc5_hdc_encoder_0, 0)) self.connect((self.blocks_wavfile_source_1, 0), (self.blocks_delay_0, 0)) self.connect((self.fft_vxx_0, 0), (self.blocks_repeat_0, 0)) self.connect((self.low_pass_filter_1, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.nrsc5_hdc_encoder_0, 0), (self.nrsc5_l2_encoder_0, 0)) self.connect((self.nrsc5_l1_am_encoder_ma1_0, 0), (self.fft_vxx_0, 0)) self.connect((self.nrsc5_l2_encoder_0, 0), (self.nrsc5_l1_am_encoder_ma1_0, 0)) self.connect((self.nrsc5_psd_encoder_0, 0), (self.nrsc5_l2_encoder_0, 1)) self.connect((self.nrsc5_sis_encoder_0, 0), (self.nrsc5_l1_am_encoder_ma1_0, 2)) self.connect((self.rational_resampler_xxx_1, 0), (self.blocks_add_xx_0, 0))
def __init__(self): gr.top_block.__init__(self, "Chu") Qt.QWidget.__init__(self) self.setWindowTitle("Chu") 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", "chu") 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 = 1200000 self.upconverter_lo_freq = upconverter_lo_freq = 0 self.space_tone = space_tone = 2025 self.offset = offset = 100000 self.mark_tone = mark_tone = 2225 self.gain = gain = 10 self.decimation = decimation = samp_rate // 48000 self.chu_freq = chu_freq = 3330000 self.channel_rate = channel_rate = 4800 ################################################## # Blocks ################################################## self._gain_range = Range(0, 50, 0.4, 10, 200) self._gain_win = RangeWidget(self._gain_range, self.set_gain, 'RX gain', "counter_slider", float) self.top_grid_layout.addWidget(self._gain_win) self.root_raised_cosine_filter_0 = filter.fir_filter_fff( 1, firdes.root_raised_cosine(1, channel_rate, 300, 0.35, 100)) self.qtgui_waterfall_sink_x_1 = qtgui.waterfall_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_1.set_update_time(0.10) self.qtgui_waterfall_sink_x_1.enable_grid(False) self.qtgui_waterfall_sink_x_1.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_1.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_1.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_1.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_1.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_1.set_intensity_range(-140, 10) self._qtgui_waterfall_sink_x_1_win = sip.wrapinstance( self.qtgui_waterfall_sink_x_1.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_1_win) self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "", #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 = ['', '', '', '', '', '', '', '', '', ''] 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_0 = qtgui.time_sink_f( 1024, #size samp_rate, #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(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: 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_1 = osmosdr.source(args="numchan=" + str(1) + " " + "") self.osmosdr_source_1.set_time_unknown_pps(osmosdr.time_spec_t()) self.osmosdr_source_1.set_sample_rate(samp_rate) self.osmosdr_source_1.set_center_freq( chu_freq - offset + upconverter_lo_freq, 0) self.osmosdr_source_1.set_freq_corr(0, 0) self.osmosdr_source_1.set_gain(gain, 0) self.osmosdr_source_1.set_if_gain(20, 0) self.osmosdr_source_1.set_bb_gain(20, 0) self.osmosdr_source_1.set_antenna('', 0) self.osmosdr_source_1.set_bandwidth(0, 0) self.low_pass_filter_1 = filter.fir_filter_ccf( 10, firdes.low_pass(1000, samp_rate / 25, 200, 50, firdes.WIN_HAMMING, 6.76)) self.low_pass_filter_0 = filter.fir_filter_ccf( decimation, firdes.low_pass(1, samp_rate, 20000, 5000, firdes.WIN_HAMMING, 6.76)) self.ham_chu_decode_0 = ham.chu_decode() self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb() self.blocks_multiply_xx_2 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_complex_to_real_0 = blocks.complex_to_real(1) self.blocks_char_to_float_0 = blocks.char_to_float(1, 0.5) self.blocks_add_const_vxx_0 = blocks.add_const_ff(-1) self.band_pass_filter_0 = filter.fir_filter_ccc( 1, firdes.complex_band_pass(1, samp_rate / decimation, 200, 2800, 200, firdes.WIN_HAMMING, 6.76)) self.audio_sink_0_0 = audio.sink(48000, '', True) self.analog_sig_source_x_1 = analog.sig_source_c( samp_rate / decimation, analog.GR_COS_WAVE, -(space_tone + mark_tone) / 2, 1, 0, 0) self.analog_sig_source_x_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, -offset, 1, 0, 0) self.analog_quadrature_demod_cf_0 = analog.quadrature_demod_cf( channel_rate / (3.1416 * (mark_tone - space_tone))) self.analog_pll_carriertracking_cc_0 = analog.pll_carriertracking_cc( 3.1416 / 500, 1.8, -1.8) self.analog_agc_xx_0 = analog.agc_ff(1e-1, 0.02, 1.0) self.analog_agc_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.analog_agc_xx_0, 0), (self.audio_sink_0_0, 0)) self.connect((self.analog_pll_carriertracking_cc_0, 0), (self.band_pass_filter_0, 0)) self.connect((self.analog_pll_carriertracking_cc_0, 0), (self.blocks_multiply_xx_2, 0)) self.connect((self.analog_pll_carriertracking_cc_0, 0), (self.qtgui_waterfall_sink_x_0, 0)) self.connect((self.analog_quadrature_demod_cf_0, 0), (self.root_raised_cosine_filter_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.analog_sig_source_x_1, 0), (self.blocks_multiply_xx_2, 1)) self.connect((self.band_pass_filter_0, 0), (self.blocks_complex_to_real_0, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.qtgui_time_sink_x_0, 1)) self.connect((self.blocks_char_to_float_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_complex_to_real_0, 0), (self.analog_agc_xx_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.blocks_multiply_xx_2, 0), (self.low_pass_filter_1, 0)) self.connect((self.digital_binary_slicer_fb_0, 0), (self.blocks_char_to_float_0, 0)) self.connect((self.digital_binary_slicer_fb_0, 0), (self.ham_chu_decode_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.analog_pll_carriertracking_cc_0, 0)) self.connect((self.low_pass_filter_1, 0), (self.analog_quadrature_demod_cf_0, 0)) self.connect((self.low_pass_filter_1, 0), (self.qtgui_waterfall_sink_x_1, 0)) self.connect((self.osmosdr_source_1, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.root_raised_cosine_filter_0, 0), (self.digital_binary_slicer_fb_0, 0)) self.connect((self.root_raised_cosine_filter_0, 0), (self.qtgui_time_sink_x_0, 0))
def __init__(self, options): grc_wxgui.top_block_gui.__init__(self, title="DSSDR") self.initialized = False self.stopped = False self.options = copy.copy(options) self._constellation = digital.constellation_bpsk() self._excess_bw = options.excess_bw self._phase_bw = options.phase_bw self._freq_bw = options.freq_bw self._timing_bw = options.timing_bw self._if_freq = options.if_freq self._timing_max_dev= 1.5 self._demod_class = digital.bpsk_demod # the demodulator_class we're using self._chbw_factor = options.chbw_factor # channel filter bandwidth factor self._samples_per_second = 2e6 self._nav_samples_per_second = 16e6 self._down_decim = 1 self._down_samples_per_second = self._scope_sample_rate = self._samples_per_second/self._down_decim self._up_samples_per_second = 1e6 self._asm_threshold = 0 self._access_code = None self._tm_packet_id = 4 self._timestamp_id = 5 self._down_bitrate = options.bitrate self._up_bitrate = options.up_bitrate self._up_samples_per_symbol = self._up_samples_per_second/self._up_bitrate self._samples_per_symbol = self._samples_per_second/self._down_decim/self._down_bitrate self._down_sub_freq = options.down_sub_freq self._up_sub_freq = 25e3 self._tm_len = 8920 self._up_tm_len = 8920 self._coding_method = options.coding_method self._up_coding_method = 'None' self._up_subcarrier = 'Square' self._rs_i = 1 self._ccsds_channel = 38 self._uhd_carrier_offset = 10e3 self._turn_div = 749 self._turn_mult = 880 self._modulation_index = 'pi/3' self._up_modulation_index = 1.047 self._max_carrier_offset = 0.1 self._dssdr_mixer_freq = options.rf_freq self._up_coding_rate = '1' self._down_coding_rate = '1' self._down_conv_en = "False" self._down_randomizer_en = options.down_randomizer_en self._down_manchester_en = options.down_manchester_en self._up_conv_en = "False" self._up_idle_sequence = "\\x55" self._down_default_gain = 64 self._up_default_gain = 44 self._up_en = True if self._access_code is None: self._access_code = packet_utils.default_access_code #Construct the lookup table for parameter-setting functions self.param_setters = { "DSSDR_CHANNEL": self.setChannel, "DSSDR_LO_FREQ": self.setLOFreq, "DSSDR_REF_FREQ": self.setRefFreq, "DSSDR_TURN_MULT": self.setTurnMult, "DSSDR_TURN_DIV": self.setTurnDiv, "DSSDR_UP_GAIN": self.setUpGain, "DSSDR_DOWN_GAIN": self.setDownGain, "DSSDR_UP_BITRATE": self.setUpBitrate, "DSSDR_DOWN_BITRATE": self.setDownBitrate, "DSSDR_DOWN_SAMPLE_RATE": self.setSampRate, "DSSDR_UP_SUB_FREQ": self.setUpSubFreq, "DSSDR_DOWN_SUB_FREQ": self.setDownSubFreq, "DSSDR_DOPPLER_REPORT": self.dopplerReport, "DSSDR_PN_RANGE": self.rangePN, "DSSDR_SEQUENTIAL_RANGE": self.rangeSequential, "DSSDR_DOWN_CODING_METHOD": self.setDownCodingMethod, "DSSDR_UP_CODING_METHOD": self.setUpCodingMethod, "DSSDR_DOWN_TM_LEN": self.setTMLen, "DSSDR_UP_TM_LEN": self.setUpTMLen, "DSSDR_DOWN_MOD_IDX": self.setDownModulationIndex, "DSSDR_UP_MOD_IDX": self.setUpModulationIndex, "DSSDR_DOWN_CONV_EN": self.setDownConvEn, "DSSDR_UP_CONV_EN": self.setUpConvEn, "DSSDR_ASM_TOL": self.setASMThreshold, "DSSDR_UP_SWEEP": self.freqSweep, "DSSDR_UP_IDLE": self.setUpIdleSequence, "DSSDR_UP_EN": self.setUpEn, "DSSDR_SYNC_TIME": self.syncSDRTime, "DSSDR_UP_SWEEP": self.freqSweep, "DSSDR_DOWN_ACQUIRE": self.acquireCarrier, "DSSDR_INPUT_SELECT": self.setPanelSelect, "DSSDR_REF_SELECT": self.setRefSelect, "DSSDR_PPS_SELECT": self.setPPSSelect } #TODO:Add status fields for things like DSSDR_REF_LOCK self._dssdr_channels = { 3: [7149597994, 8400061729], 4: [7150753857, 8401419752], 5: [7151909723, 8402777779], 6: [7153065586, 8404135802], 7: [7154221449, 8405493825], 8: [7155377316, 8406851853], 9: [7156533179, 8408209877], 10: [7157689045, 8409567903], 11: [7158844908, 8410925927], 12: [7160000771, 8412283950], 13: [7161156637, 8413641977], 14: [7162312500, 8415000000], 15: [7163468363, 8416358023], 16: [7164624229, 8417716050], 17: [7165780092, 8419074073], 18: [7166935955, 8420432097], 19: [7168091821, 8421790123], 20: [7169247684, 8423148147], 21: [7170403551, 8424506175], 22: [7171559414, 8425864198], 23: [7172715277, 8427222221], 24: [7173871143, 8428580248], 25: [7175027006, 8429938271], 26: [7176182869, 8431296295], 27: [7177338735, 8432654321], 28: [7178494598, 8434012345], 29: [7179650464, 8435370372], 30: [7180806327, 8436728395], 31: [7181962190, 8438086418], 32: [7183118057, 8439444446], 33: [7184273920, 8440802469], 34: [7185429783, 8442160493], 35: [7186585649, 8443518520], 36: [7187741512, 8444876543], 37: [7188897378, 8446234570], 38: [7190000000, 8450000000], } #FLOWGRAPH STUFF if options.test == True: self.u = blks2.tcp_source( itemsize=gr.sizeof_gr_complex*1, addr="", port=12905, server=True ) elif options.fromfile == True: self.u2 = blocks.file_meta_source("iq_in.dat") self.u = blocks.throttle(gr.sizeof_gr_complex*1, self._samples_per_second) elif options.frombitlog == True: self.u3 = blocks.file_source(gr.sizeof_char, "bitstream_recording.in", True) self.u2 = blocks.uchar_to_float() self.u1 = blocks.throttle(gr.sizeof_float*1, self._down_bitrate) self.u = blocks.add_const_ff(-0.5) else: self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) self.u.set_clock_source("external") self.u.set_time_source("external") self.u.set_samp_rate(self._samples_per_second) self.u.set_antenna("RX2") self.u.set_gain(self._down_default_gain) self.frontend = dfi.dssdrFrontendInterface(self.u) if options.debug_pps == True: self.debug_pps = blocks.tag_debug(gr.sizeof_gr_complex, "debug-pps", "rx_time") if options.tofile == True: self.u_tx = blocks.file_meta_sink(gr.sizeof_gr_complex, "iq_out.dat", self._up_samples_per_second) elif options.tonull == True: self.u_tx = blocks.null_sink(gr.sizeof_gr_complex) else: self.u_tx = uhd.usrp_sink(device_addr=options.args, stream_args=uhd.stream_args('fc32')) self.u_tx.set_clock_source("external") self.u_tx.set_time_source("external") self.u_tx.set_samp_rate(self._up_samples_per_second) self.u_tx.set_antenna("TX/RX") self.u_tx.set_gain(self._up_default_gain) #GUI STUFF if options.graphics == True: self.nb0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP) self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "RX") self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "TX") self.nb0.AddPage(grc_wxgui.Panel(self.nb0), "Nav") self.Add(self.nb0) self.constellation_scope = scopesink2.scope_sink_c( self.nb0.GetPage(0).GetWin(), title="Scope Plot", sample_rate=self._scope_sample_rate, v_scale=0, v_offset=0, t_scale=0, ac_couple=False, xy_mode=True, num_inputs=1, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label="Counts", ) self.nb0.GetPage(0).Add(self.constellation_scope.win) #self.constellation_scope.win.set_marker('plus') self._scope_is_fft = False self.time_scope = scopesink2.scope_sink_f( self.nb0.GetPage(0).GetWin(), title="Scope Plot", sample_rate=self._scope_sample_rate, v_scale=0, v_offset=0, t_scale=.005, ac_couple=False, xy_mode=False, num_inputs=1, trig_mode=wxgui.TRIG_MODE_AUTO, y_axis_label="Counts", ) self.nb0.GetPage(0).Add(self.time_scope.win) self.nb0.GetPage(0).GetWin()._box.Hide(self.time_scope.win) self.fft_scope = fftsink2.fft_sink_c( self.nb0.GetPage(0).GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=self._scope_sample_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.nb0.GetPage(0).Add(self.fft_scope.win) self.nb0.GetPage(0).GetWin()._box.Hide(self.fft_scope.win) self.row1_sizer = wx.BoxSizer(wx.HORIZONTAL) self.recording_onoff_chooser = forms.radio_buttons( parent=self.nb0.GetPage(0).GetWin(), value='Off', callback=self.setRecording, label="IQ Recording", choices=['Off','On'], labels=[], style=wx.RA_HORIZONTAL, ) self.front_panel_chooser = forms.radio_buttons( parent=self.nb0.GetPage(0).GetWin(), value='RF', callback=self.setPanelSelect, label="Input Select", choices=['RF','IF'], labels=[], style=wx.RA_HORIZONTAL, ) self.ref_chooser = forms.radio_buttons( parent=self.nb0.GetPage(0).GetWin(), value='Internal', callback=self.setRefSelect, label="Ref Select", choices=['Internal','External'], labels=[], style=wx.RA_HORIZONTAL, ) self.pps_chooser = forms.radio_buttons( parent=self.nb0.GetPage(0).GetWin(), value='Internal', callback=self.setPPSSelect, label="PPS Select", choices=['Internal','External'], labels=[], style=wx.RA_HORIZONTAL, ) self.sync_button = forms.button( parent=self.nb0.GetPage(0).GetWin(), value='Sync to PPS', callback=self.syncSDRTime, choices=['Sync to PPS'], style=wx.RA_HORIZONTAL, ) self.ref_locked_text = forms.static_text( parent=self.nb0.GetPage(0).GetWin(), value="", callback=self.setRefLocked, label="", converter=forms.str_converter(), ) self.row1_sizer.Add(self.recording_onoff_chooser, flag=wx.ALIGN_CENTER) self.row1_sizer.Add(self.front_panel_chooser, flag=wx.ALIGN_CENTER) self.row1_sizer.Add(self.ref_chooser, flag=wx.ALIGN_CENTER) self.row1_sizer.Add(self.pps_chooser, flag=wx.ALIGN_CENTER) self.row1_sizer.Add(self.sync_button, flag=wx.ALIGN_CENTER) self.row1_sizer.Add(self.ref_locked_text, flag=wx.ALIGN_CENTER) self.nb0.GetPage(0).Add(self.row1_sizer) self.complex_scope_chooser = forms.radio_buttons( parent=self.nb0.GetPage(0).GetWin(), value='Constellation', callback=self.setComplexScopeStyle, label="Complex Scope", choices=['Constellation','FFT'], labels=[], style=wx.RA_HORIZONTAL, ) self.nb0.GetPage(0).Add(self.complex_scope_chooser) self.scope_chooser = forms.radio_buttons( parent=self.nb0.GetPage(0).GetWin(), value='USRP', callback=self.setScopePoint, label="Scope Probe Point", choices=['USRP','Carrier Tracking','Sub-Carrier Costas','Sub-Carrier Sync','Data Sync'], labels=[], style=wx.RA_HORIZONTAL, ) self.nb0.GetPage(0).Add(self.scope_chooser) self._bitrate_text_box = forms.text_box( parent=self.nb0.GetPage(0).GetWin(), value=self._down_bitrate, callback=self.setDownBitrate, label="Symbol Rate", converter=forms.float_converter(), ) self.nb0.GetPage(0).Add(self._bitrate_text_box) self._samprate_text_box = forms.text_box( parent=self.nb0.GetPage(0).GetWin(), value=self._samples_per_second, callback=self.setSampRate, label="Sampling Rate", converter=forms.float_converter(), ) self.nb0.GetPage(0).Add(self._samprate_text_box) self._subcfreq_text_box = forms.text_box( parent=self.nb0.GetPage(0).GetWin(), value=self._down_sub_freq, callback=self.setDownSubFreq, label="Downlink Subcarrier Frequency", converter=forms.float_converter(), ) self.nb0.GetPage(0).Add(self._subcfreq_text_box) self._mod_index_chooser = forms.radio_buttons( parent=self.nb0.GetPage(0).GetWin(), value=self._modulation_index, callback=self.setDownModulationIndex, label="Modulation Index", choices=['pi/2', 'pi/3'], labels=[], style=wx.RA_HORIZONTAL, ) self.nb0.GetPage(0).Add(self._mod_index_chooser) self._pktlen_text_box = forms.text_box( parent=self.nb0.GetPage(0).GetWin(), value=self._tm_len, callback=self.setTMLen, label="Downlink Packet Length (bits)", converter=forms.float_converter(), ) self.nb0.GetPage(0).Add(self._pktlen_text_box) self._coding_chooser = forms.radio_buttons( parent=self.nb0.GetPage(0).GetWin(), value=self._coding_method, callback=self.setDownCodingMethod, label="Coding", choices=['None', 'RS', 'Turbo 1/2', 'Turbo 1/3', 'Turbo 1/4', 'Turbo 1/6'], labels=[], style=wx.RA_HORIZONTAL, ) self.nb0.GetPage(0).Add(self._coding_chooser) self._down_conv_check_box = forms.check_box( parent=self.nb0.GetPage(0).GetWin(), value=self._down_conv_en, callback=self.setDownConvEn, label="Convolutional Decode", true="True", false="False", ) self.nb0.GetPage(0).Add(self._down_conv_check_box) self._down_randomizer_check_box = forms.check_box( parent=self.nb0.GetPage(0).GetWin(), value=self._down_randomizer_en, callback=self.setDownRandomizerEn, label="De-randomizer", true=True, false=False, ) self.nb0.GetPage(0).Add(self._down_randomizer_check_box) self._down_manchester_check_box = forms.check_box( parent=self.nb0.GetPage(0).GetWin(), value=self._down_manchester_en, callback=self.setDownManchesterEn, label="Manchester Decode", true=True, false=False, ) self.nb0.GetPage(0).Add(self._down_manchester_check_box) self._pktlen_text_box = forms.text_box( parent=self.nb0.GetPage(0).GetWin(), value=self._asm_threshold, callback=self.setASMThreshold, label="ASM Error Tolerance (bits)", converter=forms.float_converter(), ) self.nb0.GetPage(0).Add(self._pktlen_text_box) self._coding_chooser = forms.radio_buttons( parent=self.nb0.GetPage(0).GetWin(), value=self._rs_i, callback=self.setRSI, label="Reed-Solomon Interleaving Depth", choices=[1,5], labels=[], style=wx.RA_HORIZONTAL, ) self.nb0.GetPage(0).Add(self._coding_chooser) self._ccsds_chan_text_box = forms.text_box( parent=self.nb0.GetPage(0).GetWin(), value=self._ccsds_channel, callback=self.setChannel, label="CCSDS Channel", converter=forms.int_converter(), ) self.nb0.GetPage(0).Add(self._ccsds_chan_text_box) self.setChannel(self._ccsds_channel) if options.test == True or options.fromfile == True or options.frombitlog == True: glow = 0.0 ghigh = 1.0 cur_g = 0.5 else: g = self.u.get_gain_range() cur_g = self._down_default_gain # some configurations don't have gain control if g.stop() <= g.start(): glow = 0.0 ghigh = 1.0 else: glow = g.start() ghigh = g.stop() self._uhd_gain_slider = wx.BoxSizer(wx.HORIZONTAL) form.slider_field( parent=self.nb0.GetPage(0).GetWin(), sizer=self._uhd_gain_slider, label="USRP RX Gain", weight=3, min=int(glow), max=int(ghigh), value=cur_g, callback=self.setDownGain ) self.nb0.GetPage(0).Add(self._uhd_gain_slider) #TX chain GUI components if options.test == True or options.tofile == True or options.tonull == True: gtxlow = 0.0 gtxhigh = 1.0 cur_gtx = 0.5 else: gtx = self.u_tx.get_gain_range() cur_gtx = self._up_default_gain # some configurations don't have gain control if gtx.stop() <= gtx.start(): gtxlow = 0.0 gtxhigh = 1.0 else: gtxlow = gtx.start() gtxhigh = gtx.stop() self._up_en_chooser = forms.check_box( parent=self.nb0.GetPage(1).GetWin(), value='True', callback=self.setUpEn, label="TX Enable", true='True', false='False', ) self.nb0.GetPage(1).Add(self._up_en_chooser) self._uhd_tx_gain_slider = wx.BoxSizer(wx.HORIZONTAL) form.slider_field( parent=self.nb0.GetPage(1).GetWin(), sizer=self._uhd_tx_gain_slider, label="USRP TX Gain", weight=3, min=int(gtxlow), max=int(gtxhigh), value=cur_gtx, callback=self.setUpGain ) self.nb0.GetPage(1).Add(self._uhd_tx_gain_slider) self._subcfreq_up_text_box = forms.text_box( parent=self.nb0.GetPage(1).GetWin(), value=self._up_sub_freq, callback=self.setUpSubFreq, label="Uplink Subcarrier Frequency", converter=forms.float_converter(), ) self.nb0.GetPage(1).Add(self._subcfreq_up_text_box) self._up_bitrate_text_box = forms.text_box( parent=self.nb0.GetPage(1).GetWin(), value=self._up_bitrate, callback=self.setUpBitrate, label="Uplink Bitrate", converter=forms.float_converter(), ) self.nb0.GetPage(1).Add(self._up_bitrate_text_box) self._up_data_text_box = forms.text_box( parent=self.nb0.GetPage(1).GetWin(), value="1234ABCD", callback=self.txData, label="TX Data", converter=forms.str_converter(), ) self.nb0.GetPage(1).Add(self._up_data_text_box) self._up_mod_index_chooser = forms.text_box( parent=self.nb0.GetPage(1).GetWin(), value=self._up_modulation_index, callback=self.setUpModulationIndex, label="Uplink Modulation Index", converter=forms.float_converter(), ) self.nb0.GetPage(1).Add(self._up_mod_index_chooser) self._up_coding_chooser = forms.radio_buttons( parent=self.nb0.GetPage(1).GetWin(), value=self._up_coding_method, callback=self.setUpCodingMethod, label="Coding", choices=['None', 'RS'], labels=[], style=wx.RA_HORIZONTAL, ) self.nb0.GetPage(1).Add(self._up_coding_chooser) self._subcarrier_chooser = forms.radio_buttons( parent=self.nb0.GetPage(1).GetWin(), value=self._up_subcarrier, callback=self.setUpSubcarrier, label="Subcarrier Type", choices=['Square','Sine'], labels=[], style=wx.RA_HORIZONTAL, ) self.nb0.GetPage(1).Add(self._subcarrier_chooser) self._up_conv_check_box = forms.check_box( parent=self.nb0.GetPage(1).GetWin(), value=self._up_conv_en, callback=self.setUpConvEn, label="Convolutional Encode", true="True", false="False", ) self.nb0.GetPage(1).Add(self._up_conv_check_box) self._up_pktlen_text_box = forms.text_box( parent=self.nb0.GetPage(1).GetWin(), value=self._up_tm_len, callback=self.setUpTMLen, label="Uplink Packet Length (bits)", converter=forms.float_converter(), ) self.nb0.GetPage(1).Add(self._up_pktlen_text_box) self._uhd_offset_text_box = forms.text_box( parent=self.nb0.GetPage(1).GetWin(), value=self._uhd_carrier_offset, callback=self.setUHDCarrierOffset, label="USRP Offset Frequency (Hz)", converter=forms.float_converter(), ) self.nb0.GetPage(1).Add(self._uhd_offset_text_box) self._sweep_gen_text_box = forms.text_box( parent=self.nb0.GetPage(1).GetWin(), value="rf2_1", callback=self.freqSweep, label="Frequency Sweep Profile", converter=forms.str_converter(), ) self.nb0.GetPage(1).Add(self._sweep_gen_text_box) self._idle_sequence_text_box = forms.text_box( parent=self.nb0.GetPage(1).GetWin(), value=self._up_idle_sequence, callback=self.setUpIdleSequence, label="Uplink Idle Sequence", converter=forms.str_converter(), ) self.nb0.GetPage(1).Add(self._idle_sequence_text_box) self._pn_ranging_text_box = forms.text_box( parent=self.nb0.GetPage(2).GetWin(), value="", callback=self.rangePN, label="Queue PN Ranging", converter=forms.str_converter(), ) self.nb0.GetPage(2).Add(self._pn_ranging_text_box) self._sequential_ranging_text_box = forms.text_box( parent=self.nb0.GetPage(2).GetWin(), value="", callback=self.rangeSequential, label="Queue Sequential Ranging", converter=forms.str_converter(), ) self.nb0.GetPage(2).Add(self._sequential_ranging_text_box) self.row2_sizer = wx.BoxSizer(wx.HORIZONTAL) self.freq_acq_button = forms.button( parent=self.nb0.GetPage(2).GetWin(), value='Acquire Carrier Offset', callback=self.acquireCarrier, choices=['Acquire Carrier Offset'], style=wx.RA_HORIZONTAL, ) self.carrier_offset_text = forms.static_text( parent=self.nb0.GetPage(2).GetWin(), value="", label="", converter=forms.str_converter(), ) self.row2_sizer.Add(self.freq_acq_button, flag=wx.ALIGN_CENTER) self.row2_sizer.Add(self.carrier_offset_text, flag=wx.ALIGN_CENTER) self.nb0.GetPage(2).Add(self.row2_sizer) self.file_sink = blocks.file_meta_sink(gr.sizeof_gr_complex, "iq_recording.dat", self._samples_per_second) self.file_sink.close() self.iq_recording_ctr = 0 # Selection logic to switch between recording and normal flowgraph routes # NOTE: u_valve logic is implemented backwards in GNURadio.... #self.u_valve = blks2.valve( # item_size=gr.sizeof_gr_complex, # open=False #) # Temporary code used to verify coherent turnaround self.turnaround_mixer = blocks.multiply_cc() self.turnaround_mixer_source = analog.sig_source_c(self._down_samples_per_second, analog.GR_SIN_WAVE, -25e3, 1.0) self.turnaround_iir = filter.single_pole_iir_filter_cc(0.0001) self.turnaround_null = blocks.null_sink(gr.sizeof_float) # PLL and associated carrier for tracking carrier frequency if residual carrier is used self.carrier_tracking = sdrp.pll_freq_acq_cc(math.pi/2000, math.pi, -math.pi, int(options.acq_samples)) self.imag_to_float = blocks.complex_to_imag() #Suppressed carrier requires costas after subcarrier mixer self.subcarrier_costas = digital.costas_loop_cc(0.001, 2) self.real_to_float = blocks.complex_to_real() #Square wave subcarrier sync self.subcarrier_sync = sdrp.square_sub_tracker_ff(0.001, 2*self._down_sub_freq/self._down_samples_per_second*1.0001, 2*self._down_sub_freq/self._down_samples_per_second*0.9999) #Data sync self.data_sync = sdrp.square_data_tracker_ff(0.001, self._down_bitrate/self._down_samples_per_second*1.001, self._down_bitrate/self._down_samples_per_second*0.999) #Data framing self.soft_correlator = sdrp.correlate_soft_access_tag_ff(conv_packed_binary_string_to_1_0_string('\x1A\xCF\xFC\x1D'), self._asm_threshold, "asm_corr") self.conv_decoder = sdrp.ccsds_tm_conv_decoder("asm_corr") self.de_randomizer = sdrp.ccsds_tm_derandomizer("asm_corr") self.tm_framer = sdrp.ccsds_tm_framer(self._tm_packet_id, self._timestamp_id, "asm_corr", "rx_time", self._down_bitrate) self.tm_framer.setFrameLength(self._tm_len) self._current_scope_block = None self._current_scoped_block = self.u self._current_scoped_block_port = 0 self._recording = 'Off' #TX path in flowgraph self.pkt_gen_msgq = gr.msg_queue(10) self.pkt_gen = sdrp.ccsds_tm_tx(self._tm_packet_id, self._timestamp_id, 1.0, 16, self.pkt_gen_msgq) self.conj = blocks.conjugate_cc() #Sweep generator for transponder lock self.sweep_gen = sdrp.sweep_generator_cc(self._up_samples_per_second) # DSSDR subcarrier mixer (either 25 kHz or 0 kHz depending on baud rate) self.up_subcarrier_mixer = blocks.multiply_ff() self.subcarrier_mixer_source_tx = analog.sig_source_f(self._up_samples_per_second, analog.GR_SQR_WAVE, 25e3, 2.0, -1.0) self.phase_mod_tx = analog.phase_modulator_fc(self._up_modulation_index) self.tx_attenuator = blocks.multiply_const_cc((0.1+0.0j)) #Add in bit recorder if needed if self.options.bitlog: self.bit_slicer = digital.binary_slicer_fb() self.bit_recorder = blocks.file_sink(1, "bitstream_recording.out") self.setDownCodingMethod(self._coding_method) self.setUpCodingMethod("None") self.setUpSubcarrier(self._up_subcarrier) self.setDownBitrate(self._down_bitrate) self.setUpBitrate(self._up_bitrate) self.setDownModulationIndex(self._modulation_index) self.setUpModulationIndex(self._up_modulation_index) self.setDownConvEn(self._down_conv_en) self.setUpConvEn(self._up_conv_en) self.setUpIdleSequence(self._up_idle_sequence) self.setDownRandomizerEn(self._down_randomizer_en) self.setDownManchesterEn(self._down_manchester_en) #Connection to outside world self.socket_pdu = blocks.socket_pdu("TCP_SERVER", "127.0.0.1", "12902", 10000) self.sdrp_interpreter = sdrp.sdrp_packet_interpreter() self.msg_connect(self.tm_framer, "tm_frame_out", self.sdrp_interpreter, "sdrp_pdu_in") self.msg_connect(self.sdrp_interpreter, "socket_pdu_out", self.socket_pdu, "pdus") self.msg_connect(self.socket_pdu, "pdus", self.sdrp_interpreter, "socket_pdu_in") self.msg_connect(self.sdrp_interpreter,"sdrp_pdu_out", self.pkt_gen, "ccsds_tx_msg_in") if options.test == False and options.fromfile == False and options.frombitlog == False: _threading.Thread(target=self.watchRef).start() self.initialized = True print "DS-SDR Initialized"
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): gr.top_block.__init__(self, "add constant") Qt.QWidget.__init__(self) self.setWindowTitle("add constant") 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", "addconstant") 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 ################################################## # Blocks ################################################## self.qtgui_time_sink_x_0 = qtgui.time_sink_f( 1024, #size samp_rate, #samp_rate "", #name 1 #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(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.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.blocks_throttle_0 = blocks.throttle(gr.sizeof_float * 1, samp_rate, True) self.blocks_multiply_xx_0 = blocks.multiply_vff(1) self.blocks_add_const_vxx_0 = blocks.add_const_ff(0) self.analog_sig_source_x_1 = analog.sig_source_f( samp_rate, analog.GR_COS_WAVE, 8000, 0.5, 0, 0) self.analog_sig_source_x_0 = analog.sig_source_f( samp_rate, analog.GR_COS_WAVE, 350, 0.9, 0, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.analog_sig_source_x_1, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.qtgui_time_sink_x_0, 0))
def test_add_const_ff(self): src_data = (1, 2, 3, 4, 5) expected_result = (6, 7, 8, 9, 10) op = blocks.add_const_ff(5) self.help_ff((src_data,), expected_result, op)
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, decoder_obj_list, threading, ann=None, puncpat='11', integration_period=10000, flush=None, rotator=None): gr.hier_block2.__init__(self, "extended_decoder_interface", 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 message_collector_connected = False ##anything going through the annihilator needs shifted, uchar vals if fec.get_conversion( decoder_obj_list[0]) == "uchar" or fec.get_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_conversion(decoder_obj_list[0]) == "packed_bits": self.blocks.append(blocks.add_const_ff(128.0)) if fec.get_conversion( decoder_obj_list[0]) == "uchar" or fec.get_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 read_big_bitlist(ann): cat.append(i) synd_garble = .49 idx_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 corr_bb' print 'ceiling: .0335 data garble rate' self.blocks.append( fec.corr_bb(cat, len(puncpat) - puncpat.count('0'), len(ann), integration_period, flush, synd_garble)) #print puncpat if self.puncpat != '11': self.blocks.append( fec.reinflate_bb(0, read_bitlist(puncpat), puncpat.count('0'), len(puncpat))) if fec.get_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): assert fec.get_history(decoder_obj_list[0]) == 0 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_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, 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): gr.top_block.__init__(self, "udp-recive") Qt.QWidget.__init__(self) self.setWindowTitle("udp-recive") 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 = 850e3 self.dec = dec = 25 self.freq_0 = freq_0 = 137.50625e6 self.bandwidth = bandwidth = 34e3 self.RF_gain = RF_gain = 40 self.Out_samprate = Out_samprate = samp_rate / dec self.NOAA19 = NOAA19 = -0.40625e6 self.NOAA18 = NOAA18 = 0.40625e6 self.NOAA15 = NOAA15 = 0.11375e6 self.IF_gain = IF_gain = 40 ################################################## # Blocks ################################################## self.rational_resampler_xxx_0 = filter.rational_resampler_fff( interpolation=11025, decimation=34000, taps=None, fractional_bw=None) self.qtgui_sink_x_0 = qtgui.sink_c( 2048, #fftsize firdes.WIN_HAMMING, #wintype 0, #fc 34e3, #bw "output sink", #name True, #plotfreq True, #plotwaterfall False, #plottime False #plotconst ) self.qtgui_sink_x_0.set_update_time(1.0 / 10) self._qtgui_sink_x_0_win = sip.wrapinstance( self.qtgui_sink_x_0.pyqwidget(), Qt.QWidget) self.qtgui_sink_x_0.enable_rf_freq(False) self.top_grid_layout.addWidget(self._qtgui_sink_x_0_win) self.qtgui_sink_x_0.set_block_alias("output sink") self.qtgui_number_sink_0 = qtgui.number_sink(gr.sizeof_short, 0, qtgui.NUM_GRAPH_NONE, 1) self.qtgui_number_sink_0.set_update_time(0.1) self.qtgui_number_sink_0.set_title("Selected channel") labels = ['', '', '', '', '', '', '', '', '', ''] units = ['', '', '', '', '', '', '', '', '', ''] colors = [("black", "black"), ("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.set_min(i, 0) self.qtgui_number_sink_0.set_max(i, 2) 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) self.blocks_udp_source_0_2 = blocks.udp_source( gr.sizeof_gr_complex * 1, '0.0.0.0', 1232, 4000, True) self.blocks_udp_source_0_1 = blocks.udp_source( gr.sizeof_gr_complex * 1, '0.0.0.0', 1230, 4000, True) self.blocks_udp_source_0 = blocks.udp_source(gr.sizeof_gr_complex * 1, '0.0.0.0', 1231, 4000, True) self.blocks_udp_sink_0 = blocks.udp_sink(gr.sizeof_float * 1, 'localhost', 7355, 1225, True) self.blocks_threshold_ff_0_1 = blocks.threshold_ff(1.5, 2.5, 0) self.blocks_threshold_ff_0_0 = blocks.threshold_ff(0.5, 1.5, 0) self.blocks_threshold_ff_0 = blocks.threshold_ff(-0.5, 0.5, 0) self.blocks_streams_to_vector_0 = blocks.streams_to_vector( gr.sizeof_float * 1, 3) self.blocks_short_to_float_0 = blocks.short_to_float(1, 1) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_short * 1) self.blocks_multiply_xx_2 = blocks.multiply_vcc(1) self.blocks_multiply_xx_1 = blocks.multiply_vcc(1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_moving_average_2_0 = blocks.moving_average_ff( 4000, 1, 4000, 1) self.blocks_moving_average_2 = blocks.moving_average_ff( 4000, 1, 4000, 1) self.blocks_moving_average_1 = blocks.moving_average_ff( 4000, 1, 4000, 1) self.blocks_float_to_complex_1_1 = blocks.float_to_complex(1) self.blocks_float_to_complex_1_0 = blocks.float_to_complex(1) self.blocks_float_to_complex_1 = blocks.float_to_complex(1) self.blocks_complex_to_mag_squared_0_1 = blocks.complex_to_mag_squared( 1) self.blocks_complex_to_mag_squared_0_0 = blocks.complex_to_mag_squared( 1) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.blocks_argmax_xx_0 = blocks.argmax_fs(3) self.blocks_add_xx_0 = blocks.add_vcc(1) self.blocks_add_const_vxx_0_0_0 = blocks.add_const_ff(-1) self.blocks_add_const_vxx_0_0 = blocks.add_const_ff(-1) self.blocks_add_const_vxx_0 = blocks.add_const_ff(-1) self.blocks_abs_xx_0_0_0 = blocks.abs_ff(1) self.blocks_abs_xx_0_0 = blocks.abs_ff(1) self.blocks_abs_xx_0 = blocks.abs_ff(1) self.analog_wfm_rcv_0 = analog.wfm_rcv( quad_rate=bandwidth, audio_decimation=1, ) self.NOAA19_fall = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype freq_0 + NOAA19, #fc Out_samprate, #bw "NOAA19 (stream 0)", #name True, #plotfreq True, #plotwaterfall False, #plottime False #plotconst ) self.NOAA19_fall.set_update_time(1.0 / 1) self._NOAA19_fall_win = sip.wrapinstance(self.NOAA19_fall.pyqwidget(), Qt.QWidget) self.NOAA19_fall.enable_rf_freq(True) self.top_grid_layout.addWidget(self._NOAA19_fall_win) self.NOAA18_fall = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype freq_0 + NOAA18, #fc Out_samprate, #bw "NOAA18 (stream 1)", #name True, #plotfreq True, #plotwaterfall False, #plottime False #plotconst ) self.NOAA18_fall.set_update_time(1.0 / 1) self._NOAA18_fall_win = sip.wrapinstance(self.NOAA18_fall.pyqwidget(), Qt.QWidget) self.NOAA18_fall.enable_rf_freq(True) self.top_grid_layout.addWidget(self._NOAA18_fall_win) self.NOAA15_fall = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype freq_0 + NOAA15, #fc Out_samprate, #bw "NOAA15 (stream 2)", #name True, #plotfreq True, #plotwaterfall False, #plottime False #plotconst ) self.NOAA15_fall.set_update_time(1.0 / 1) self._NOAA15_fall_win = sip.wrapinstance(self.NOAA15_fall.pyqwidget(), Qt.QWidget) self.NOAA15_fall.enable_rf_freq(True) self.top_grid_layout.addWidget(self._NOAA15_fall_win) ################################################## # Connections ################################################## self.connect((self.analog_wfm_rcv_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.blocks_abs_xx_0, 0), (self.blocks_float_to_complex_1, 0)) self.connect((self.blocks_abs_xx_0_0, 0), (self.blocks_float_to_complex_1_0, 0)) self.connect((self.blocks_abs_xx_0_0_0, 0), (self.blocks_float_to_complex_1_1, 0)) self.connect((self.blocks_add_const_vxx_0, 0), (self.blocks_abs_xx_0, 0)) self.connect((self.blocks_add_const_vxx_0_0, 0), (self.blocks_abs_xx_0_0, 0)) self.connect((self.blocks_add_const_vxx_0_0_0, 0), (self.blocks_abs_xx_0_0_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.analog_wfm_rcv_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.qtgui_sink_x_0, 0)) self.connect((self.blocks_argmax_xx_0, 1), (self.blocks_null_sink_0, 0)) self.connect((self.blocks_argmax_xx_0, 0), (self.blocks_short_to_float_0, 0)) self.connect((self.blocks_argmax_xx_0, 0), (self.qtgui_number_sink_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_moving_average_1, 0)) self.connect((self.blocks_complex_to_mag_squared_0_0, 0), (self.blocks_moving_average_2, 0)) self.connect((self.blocks_complex_to_mag_squared_0_1, 0), (self.blocks_moving_average_2_0, 0)) self.connect((self.blocks_float_to_complex_1, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_float_to_complex_1_0, 0), (self.blocks_multiply_xx_1, 1)) self.connect((self.blocks_float_to_complex_1_1, 0), (self.blocks_multiply_xx_2, 1)) self.connect((self.blocks_moving_average_1, 0), (self.blocks_streams_to_vector_0, 0)) self.connect((self.blocks_moving_average_2, 0), (self.blocks_streams_to_vector_0, 1)) self.connect((self.blocks_moving_average_2_0, 0), (self.blocks_streams_to_vector_0, 2)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_multiply_xx_1, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_multiply_xx_2, 0), (self.blocks_add_xx_0, 2)) self.connect((self.blocks_short_to_float_0, 0), (self.blocks_threshold_ff_0, 0)) self.connect((self.blocks_short_to_float_0, 0), (self.blocks_threshold_ff_0_0, 0)) self.connect((self.blocks_short_to_float_0, 0), (self.blocks_threshold_ff_0_1, 0)) self.connect((self.blocks_streams_to_vector_0, 0), (self.blocks_argmax_xx_0, 0)) self.connect((self.blocks_threshold_ff_0, 0), (self.blocks_add_const_vxx_0, 0)) self.connect((self.blocks_threshold_ff_0_0, 0), (self.blocks_add_const_vxx_0_0, 0)) self.connect((self.blocks_threshold_ff_0_1, 0), (self.blocks_add_const_vxx_0_0_0, 0)) self.connect((self.blocks_udp_source_0, 0), (self.NOAA19_fall, 0)) self.connect((self.blocks_udp_source_0, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.blocks_udp_source_0, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self.blocks_udp_source_0_1, 0), (self.NOAA18_fall, 0)) self.connect((self.blocks_udp_source_0_1, 0), (self.blocks_complex_to_mag_squared_0_0, 0)) self.connect((self.blocks_udp_source_0_1, 0), (self.blocks_multiply_xx_1, 0)) self.connect((self.blocks_udp_source_0_2, 0), (self.NOAA15_fall, 0)) self.connect((self.blocks_udp_source_0_2, 0), (self.blocks_complex_to_mag_squared_0_1, 0)) self.connect((self.blocks_udp_source_0_2, 0), (self.blocks_multiply_xx_2, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.blocks_udp_sink_0, 0))
def __init__(self): gr.top_block.__init__(self) usage=("%prog: [options] output_filename.\nSpecial output_filename" + \ "\"sdl\" will use video_sink_sdl as realtime output window. " + \ "You then need to have gr-video-sdl installed.\n" +\ "Make sure your input capture file containes interleaved " + \ "shorts not complex floats") parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-a", "--args", type="string", default="", help="UHD device address args [default=%default]") parser.add_option("", "--spec", type="string", default=None, help="Subdevice of UHD device where appropriate") parser.add_option("-A", "--antenna", type="string", default=None, help="select Rx Antenna where appropriate") parser.add_option("-s", "--samp-rate", type="eng_float", default=1e6, help="set sample rate") parser.add_option("-c", "--contrast", type="eng_float", default=1.0, help="set contrast (default is 1.0)") parser.add_option("-b", "--brightness", type="eng_float", default=0.0, help="set brightness (default is 0)") parser.add_option("-i", "--in-filename", type="string", default=None, help="Use input file as source. samples must be " + \ "interleaved shorts \n Use usrp_rx_file.py or " + \ "usrp_rx_cfile.py --output-shorts.\n Special " + \ "name \"usrp\" results in realtime capturing " + \ "and processing using usrp.\n" + \ "You then probably need a decimation factor of 64 or higher.") parser.add_option("-f", "--freq", type="eng_float", default=519.25e6, help="set frequency to FREQ.\nNote that the frequency of the video carrier is not at the middle of the TV channel", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-p", "--pal", action="store_true", default=False, help="PAL video format (this is the default)") parser.add_option("-n", "--ntsc", action="store_true", default=False, help="NTSC video format") parser.add_option("-r", "--repeat", action="store_false", default=True, help="repeat in_file in a loop") parser.add_option("-N", "--nframes", type="eng_float", default=None, help="number of frames to collect [default=+inf]") parser.add_option("", "--freq-min", type="eng_float", default=50.25e6, help="Set a minimum frequency [default=%default]") parser.add_option("", "--freq-max", type="eng_float", default=900.25e6, help="Set a maximum frequency [default=%default]") (options, args) = parser.parse_args () if not (len(args) == 1): parser.print_help() sys.stderr.write('You must specify the output. FILENAME or sdl \n'); sys.exit(1) filename = args[0] self.tv_freq_min = options.freq_min self.tv_freq_max = options.freq_max if options.in_filename is None: parser.print_help() sys.stderr.write('You must specify the input -i FILENAME or -i usrp\n'); raise SystemExit, 1 if not (filename=="sdl"): options.repeat=False input_rate = options.samp_rate print "video sample rate %s" % (eng_notation.num_to_str(input_rate)) if not (options.in_filename=="usrp"): # file is data source, capture with usr_rx_csfile.py self.filesource = blocks.file_source(gr.sizeof_short, options.in_filename, options.repeat) self.istoc = blocks.interleaved_short_to_complex() self.connect(self.filesource,self.istoc) self.src=self.istoc else: if options.freq is None: parser.print_help() sys.stderr.write('You must specify the frequency with -f FREQ\n'); raise SystemExit, 1 # build the graph self.u = uhd.usrp_source(device_addr=options.args, stream_args=uhd.stream_args('fc32')) # Set the subdevice spec if(options.spec): self.u.set_subdev_spec(options.spec, 0) # Set the antenna if(options.antenna): self.u.set_antenna(options.antenna, 0) self.u.set_samp_rate(input_rate) dev_rate = self.u.get_samp_rate() self.src=self.u if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.u.get_gain_range() options.gain = float(g.start()+g.stop())/2.0 self.u.set_gain(options.gain) r = self.u.set_center_freq(options.freq) if not r: sys.stderr.write('Failed to set frequency\n') raise SystemExit, 1 self.agc = 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(options.brightness +255.0) self.invert_and_scale = blocks.multiply_const_ff(-options.contrast *128.0*255.0/(200.0)) self.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(input_rate/(lines_per_frame*frames_per_sec)) height=int(lines_per_frame) if filename=="sdl": #Here comes the tv screen, you have to build and install #gr-video-sdl for this (subproject of gnuradio) try: video_sink = video_sdl.sink_uc(frames_per_sec, width, height, 0, show_width,height) except: print "gr-video-sdl is not installed" print "realtime \"sdl\" video output window is not available" raise SystemExit, 1 self.dst=video_sink else: print "You can use the imagemagick display tool to show the resulting imagesequence" print "use the following line to show the demodulated TV-signal:" print "display -depth 8 -size " +str(width)+ "x" + str(height) + " gray:" +filename print "(Use the spacebar to advance to next frames)" file_sink = blocks.file_sink(gr.sizeof_char, filename) self.dst =file_sink if options.nframes is None: self.connect(self.src, self.agc) else: self.head = blocks.head(gr.sizeof_gr_complex, int(options.nframes*width*height)) self.connect(self.src, self.head, self.agc) self.connect (self.agc, self.am_demod, self.invert_and_scale, self.set_blacklevel, self.f2uc, self.dst)