def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option, usage="%prog: [options] input-filename") parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=(0, 0), help="select USRP Tx side A or B [default=A]") parser.add_option("-f", "--freq", type="eng_float", default=227.36e6, help="set frequency to FREQ [default=%default]") parser.add_option("-g", "--tx-gain", type="eng_float", default=None, help="set transmit gain in dB (default is midpoint)") parser.add_option('-v', '--verbose', action="store_true", default=False, help="verbose output") parser.add_option('-a', '--antenna', type="string", default="TX/RX", help="select antenna") (options, args) = parser.parse_args () if len(args)!=1: parser.print_help() sys.exit(1) else: self.filename = args[0] # if gr.enable_realtime_scheduling() != gr.RT_OK: # print "-> failed to enable realtime scheduling" interp = 64 self.sample_rate = 128e6/interp self.dab_params = dab.parameters.dab_parameters(mode=1, sample_rate=2000000, verbose=options.verbose) self.src = blocks.file_source(gr.sizeof_char, self.filename) self.trigsrc = blocks.vector_source_b([1]+[0]*(self.dab_params.symbols_per_frame-1),True) self.s2v = blocks.stream_to_vector(gr.sizeof_char, 384) self.mod = dab.ofdm_mod(self.dab_params, verbose=options.verbose) #self.sink = usrp.sink_c(interp_rate = interp) self.sink = uhd.usrp_sink("",uhd.io_type.COMPLEX_FLOAT32,1) self.sink.set_samp_rate(self.sample_rate) #self.sink.set_mux(usrp.determine_tx_mux_value(self.sink, options.tx_subdev_spec)) #self.subdev = usrp.selected_subdev(self.sink, options.tx_subdev_spec) self.sink.set_antenna(options.antenna) print "--> using sample rate: " + str(self.sample_rate) self.connect(self.src, self.s2v, self.mod, self.sink) self.connect(self.trigsrc, (self.mod,1)) # tune frequency self.sink.set_center_freq(options.freq) # set gain if options.tx_gain is None: # if no gain was specified, use the mid-point in dB g = self.sink.get_gain_range() options.tx_gain = float(g.start()+g.stop())/2 self.sink.set_gain(options.tx_gain)
def setup_flowgraph(self, mode, ber_skipbytes=0): # parameters self.dp.set_mode(mode) self.rp.set_mode(mode) self.vlen = self.dp.num_carriers/4 self.ber_skipbytes = ber_skipbytes # trigger signals frame_trigger = [1]+[0]*(self.dp.symbols_per_frame-2) self.frame_start = frame_trigger*(len(self.random_bytes)/(self.vlen*(self.dp.symbols_per_frame-1)))+frame_trigger[0:(len(self.random_bytes)/self.vlen)%(self.dp.symbols_per_frame-1)] # sources/sinks self.source = gr.vector_source_b(self.random_bytes, False) self.trig = gr.vector_source_b(self.frame_start, False) if self.ber_sink: self.sink = dab.blocks.measure_ber_b() else: self.sink = gr.vector_sink_b() self.trig_sink = gr.null_sink(gr.sizeof_char) # self.noise_start = gr.noise_source_c(gr.GR_GAUSSIAN, math.sqrt(2), random.randint(0,10000)) # self.noise_start_head = gr.head(gr.sizeof_gr_complex, NOISE_SAMPLES_AT_START) # self.noise_end = gr.noise_source_c(gr.GR_GAUSSIAN, math.sqrt(2), random.randint(0,10000)) # self.noise_end_head = gr.head(gr.sizeof_gr_complex, NOISE_SAMPLES_AT_END) # blocks self.s2v = gr.stream_to_vector(gr.sizeof_char, self.vlen) self.v2s = gr.vector_to_stream(gr.sizeof_char, self.vlen) if self.ber_sink: self.ber_skipbytes0 = gr.skiphead(gr.sizeof_char, self.ber_skipbytes) self.ber_skipbytes1 = gr.skiphead(gr.sizeof_char, self.ber_skipbytes+self.dp.bytes_per_frame) # more blocks (they have state, so better reinitialise them) self.mod = dab.ofdm_mod(self.dp, debug = False) self.rescale = gr.multiply_const_cc(1) self.amp = gr.multiply_const_cc(1) self.channel = blks2.channel_model(noise_voltage=0, noise_seed=random.randint(0,10000)) # self.cat = dab.concatenate_signals(gr.sizeof_gr_complex) self.demod = dab.ofdm_demod(self.dp, self.rp, debug = False, verbose = True) # connect it all if self.ber_sink: self.connect(self.source, self.s2v, (self.mod,0), self.rescale, self.amp, self.channel, (self.demod,0), self.v2s, self.ber_skipbytes0, self.sink) self.connect(self.source, self.ber_skipbytes1, (self.sink,1)) else: self.connect(self.source, self.s2v, (self.mod,0), self.rescale, self.amp, self.channel, (self.demod,0), self.v2s, self.sink) self.connect(self.trig, (self.mod,1)) self.connect((self.demod, 1), self.trig_sink) # SNR calculation and prober self.probe_signal = gr.probe_avg_mag_sqrd_c(0,0.00001) self.probe_total = gr.probe_avg_mag_sqrd_c(0,0.00001) self.connect(self.amp, self.probe_signal) self.connect(self.channel, self.probe_total)
def __init__(self, dab_params, sampling_rate, num_subch, ensemble_lable, service_label, service_comp_label, service_language, protection_mode, data_rate_n): gr.hier_block2.__init__( self, "transmitter_c", gr.io_signature(0, 0, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self.dp = dab_params self.sampling_rate = sampling_rate # FIC self.fic_source = dab.fib_source_b_make(self.dp.mode, num_subch, ensemble_lable, service_label, service_comp_label, service_language, protection_mode, data_rate_n) self.fic_encode = dab.fic_encode(self.dp) # MSC self.msc_encoder() for i in range(0, num_subch): self.msc_encoder[i] = dab.msc_encode(self.dp, data_rate_n[i], protection_mode[i]) # MUX self.subch_size = 6 * data_rate_n self.mux = dab.dab_transmission_frame_mux_bb_make( self.dp.mode, num_subch, self.subch_size) # OFDM Modulator self.s2v = blocks.stream_to_vector(gr.sizeof_char, 384) self.mod = dab.ofdm_mod(self.dp) # connect everything self.connect(self.fic_source, self.fic_encode, (self.mux, 0)) for i in range(0, num_subch): self.connect((self, i), self.msc_encoder[i], (self.mux, i + 1)) self.connect((self.mux, 0), self.s2v, (self.mod, 0)) self.connect((self.mux, 1), (self.mod, 1)) self.connect(self.mod, self)
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option, usage="%prog: [options] input-filename") parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=(0, 0), help="select USRP Tx side A or B [default=A]") parser.add_option("-f", "--freq", type="eng_float", default=227.36e6, help="set frequency to FREQ [default=%default]") parser.add_option("-g", "--tx-gain", type="eng_float", default=None, help="set transmit gain in dB (default is midpoint)") parser.add_option('-v', '--verbose', action="store_true", default=False, help="verbose output") parser.add_option('-a', '--antenna', type="string", default="TX/RX", help="select antenna") (options, args) = parser.parse_args() if len(args) != 1: parser.print_help() sys.exit(1) else: self.filename = args[0] # if gr.enable_realtime_scheduling() != gr.RT_OK: # print "-> failed to enable realtime scheduling" interp = 64 self.sample_rate = 128e6 / interp self.dab_params = dab.parameters.dab_parameters( mode=1, sample_rate=2000000, verbose=options.verbose) self.src = blocks.file_source(gr.sizeof_char, self.filename) self.trigsrc = blocks.vector_source_b( [1] + [0] * (self.dab_params.symbols_per_frame - 1), True) self.s2v = blocks.stream_to_vector(gr.sizeof_char, 384) self.mod = dab.ofdm_mod(self.dab_params, verbose=options.verbose) #self.sink = usrp.sink_c(interp_rate = interp) self.sink = uhd.usrp_sink("", uhd.io_type.COMPLEX_FLOAT32, 1) self.sink.set_samp_rate(self.sample_rate) #self.sink.set_mux(usrp.determine_tx_mux_value(self.sink, options.tx_subdev_spec)) #self.subdev = usrp.selected_subdev(self.sink, options.tx_subdev_spec) self.sink.set_antenna(options.antenna) print "--> using sample rate: " + str(self.sample_rate) self.connect(self.src, self.s2v, self.mod, self.sink) self.connect(self.trigsrc, (self.mod, 1)) # tune frequency self.sink.set_center_freq(options.freq) # set gain if options.tx_gain is None: # if no gain was specified, use the mid-point in dB g = self.sink.get_gain_range() options.tx_gain = float(g.start() + g.stop()) / 2 self.sink.set_gain(options.tx_gain)
def __init__(self, frequency, num_subch, ensemble_label, service_label, language, protections, data_rates_n, src_paths, selected_audio, use_usrp, sink_path="dab_iq_generated.dat"): gr.top_block.__init__(self) self.dab_mode = 1 self.frequency = frequency interp = 64 self.sample_rate = 128e6 / interp self.dp = dab.parameters.dab_parameters(self.dab_mode, 2000000, False) self.num_subch = num_subch self.ensemble_label = ensemble_label self.service_label = service_label self.language = language self.protections = protections self.data_rates_n = data_rates_n self.subch_sizes = np.multiply(self.data_rates_n, 6) self.src_paths = src_paths self.use_usrp = use_usrp self.sink_path = sink_path self.selected_audio = selected_audio self.volume = 80 ######################## # FIC ######################## # source self.fic_src = dab.fib_source_b_make(self.dab_mode, self.num_subch, self.ensemble_label, self.service_label, "", self.language, self.protections, self.data_rates_n) # encoder self.fic_enc = dab.fic_encode(self.dp) ######################## # MSC ######################## self.msc_sources = [None] * self.num_subch self.f2s_left_converters = [None] * self.num_subch self.f2s_right_converters = [None] * self.num_subch self.mp4_encoders = [None] * self.num_subch self.rs_encoders = [None] * self.num_subch self.msc_encoders = [None] * self.num_subch for i in range(0, self.num_subch): # source self.msc_sources[i] = blocks.wavfile_source_make( self.src_paths[i], True) # float to short self.f2s_left_converters[i] = blocks.float_to_short_make(1, 32767) self.f2s_right_converters[i] = blocks.float_to_short_make(1, 32767) # mp4 encoder and Reed-Solomon encoder self.mp4_encoders[i] = dab.mp4_encode_sb_make( self.data_rates_n[i], 2, 32000, 1) self.rs_encoders[i] = dab.reed_solomon_encode_bb_make( self.data_rates_n[i]) # encoder self.msc_encoders[i] = dab.msc_encode(self.dp, self.data_rates_n[i], self.protections[i]) ######################## # MUX ######################## self.mux = dab.dab_transmission_frame_mux_bb_make( self.dab_mode, self.num_subch, self.subch_sizes) #self.mux = dab.dab_transmission_frame_mux_bb_make(1, 1, [84, 84]) self.trigsrc = blocks.vector_source_b([1] + [0] * 74, True) ######################## # Modulator ######################## self.s2v_mod = blocks.stream_to_vector(gr.sizeof_char, 384) self.mod = dab.ofdm_mod(self.dp) ######################## # Sink ######################## if self.use_usrp: self.sink = uhd.usrp_sink("", uhd.io_type.COMPLEX_FLOAT32, 1) self.sink.set_samp_rate(self.sample_rate) self.sink.set_antenna("TX/RX") self.sink.set_center_freq(self.frequency) else: self.sink = blocks.file_sink_make(gr.sizeof_gr_complex, self.sink_path) # audio sink self.audio = audio.sink_make(32000) self.gain_left = blocks.multiply_const_ff_make(1, 1) self.gain_right = blocks.multiply_const_ff_make(1, 1) ######################## # Connections ######################## self.connect(self.fic_src, self.fic_enc, (self.mux, 0)) for i in range(0, self.num_subch): self.connect((self.msc_sources[i], 0), self.f2s_left_converters[i], (self.mp4_encoders[i], 0), self.rs_encoders[i], self.msc_encoders[i], (self.mux, i + 1)) self.connect((self.msc_sources[i], 1), self.f2s_right_converters[i], (self.mp4_encoders[i], 1)) self.connect((self.mux, 0), self.s2v_mod, (self.mod, 0)) self.connect(self.trigsrc, (self.mod, 1)) self.connect(self.mod, self.sink) self.connect((self.msc_sources[self.selected_audio - 1], 0), self.gain_left, (self.audio, 0)) self.connect((self.msc_sources[self.selected_audio - 1], 1), self.gain_right, (self.audio, 1))
def __init__(self, dab_mode, frequency, num_subch, ensemble_label, service_label, language, country_ID, protections, data_rates_n, stereo_flags, audio_sampling_rates, src_paths, selected_audio, use_usrp, dabplus_types, sink_path="dab_iq_generated.dat"): gr.top_block.__init__(self) self.dab_mode = dab_mode self.frequency = frequency interp = 64 self.sample_rate = 128e6 / interp self.dp = dab.parameters.dab_parameters(self.dab_mode, 2000000, False) self.num_subch = num_subch self.ensemble_label = ensemble_label self.service_label = service_label self.language = language self.protections = protections self.data_rates_n = data_rates_n self.src_paths = src_paths self.use_usrp = use_usrp self.dabplus_types = dabplus_types self.sink_path = sink_path self.selected_audio = selected_audio self.volume = 80 sizes = {0: 12, 1: 8, 2: 6, 3: 4} self.subch_sizes = [None] * len(self.data_rates_n) for i in range(0, len(self.data_rates_n)): self.subch_sizes[i] = self.data_rates_n[i] * sizes[protections[i]] ######################## # FIC ######################## # source self.fic_src = dab.fib_source_b_make( self.dab_mode, country_ID, self.num_subch, self.ensemble_label, self.service_label, "", self.language, self.protections, self.data_rates_n, self.dabplus_types) # encoder self.fic_enc = dab.fic_encode(self.dp) ######################## # MSC ######################## self.recorder = audio.source_make(32000) self.msc_sources = [None] * self.num_subch self.f2s_left_converters = [None] * self.num_subch self.f2s_right_converters = [None] * self.num_subch self.mp4_encoders = [None] * self.num_subch self.mp2_encoders = [None] * self.num_subch self.rs_encoders = [None] * self.num_subch self.msc_encoders = [None] * self.num_subch for i in range(0, self.num_subch): if not self.src_paths[i] is "mic": # source self.msc_sources[i] = blocks.wavfile_source_make( self.src_paths[i], True) # float to short self.f2s_left_converters[i] = blocks.float_to_short_make(1, 32767) self.f2s_right_converters[i] = blocks.float_to_short_make(1, 32767) if self.dabplus_types[i] is 1: # mp4 encoder and Reed-Solomon encoder self.mp4_encoders[i] = dab.mp4_encode_sb_make( self.data_rates_n[i], 2, audio_sampling_rates[i], 1) self.rs_encoders[i] = dab.reed_solomon_encode_bb_make( self.data_rates_n[i]) else: # mp2 encoder self.mp2_encoders[i] = dab.mp2_encode_sb_make( self.data_rates_n[i], 2, audio_sampling_rates[i]) # encoder self.msc_encoders[i] = dab.msc_encode(self.dp, self.data_rates_n[i], self.protections[i]) ######################## # MUX ######################## self.mux = dab.dab_transmission_frame_mux_bb_make( self.dab_mode, self.num_subch, self.subch_sizes) self.trigsrc = blocks.vector_source_b( [1] + [0] * (self.dp.symbols_per_frame - 2), True) ######################## # Modulator ######################## self.s2v_mod = blocks.stream_to_vector(gr.sizeof_char, self.dp.num_carriers / 4) self.mod = dab.ofdm_mod(self.dp) ######################## # Sink ######################## if self.use_usrp: self.sink = uhd.usrp_sink("", uhd.io_type.COMPLEX_FLOAT32, 1) self.sink.set_samp_rate(self.sample_rate) self.sink.set_antenna("TX/RX") self.sink.set_center_freq(self.frequency) else: self.sink = blocks.file_sink_make(gr.sizeof_gr_complex, self.sink_path) # audio sink self.audio = audio.sink_make(32000) self.gain_left = blocks.multiply_const_ff_make(1, 1) self.gain_right = blocks.multiply_const_ff_make(1, 1) self.s2f_left = blocks.short_to_float_make(1, 32767) self.s2f_right = blocks.short_to_float_make(1, 32767) ######################## # Connections ######################## self.connect(self.fic_src, self.fic_enc, (self.mux, 0)) for i in range(0, self.num_subch): if self.dabplus_types[i] is 1: if self.src_paths[i] is "mic": self.connect( (self.recorder, 0), self.f2s_left_converters[i], (self.mp4_encoders[i], 0), self.rs_encoders[i], self.msc_encoders[i], (self.mux, i + 1)) if stereo_flags[i] == 0: self.connect((self.recorder, 1), self.f2s_right_converters[i], (self.mp4_encoders[i], 1)) else: self.connect(self.f2s_left_converters[i], (self.mp4_encoders[i], 1)) else: self.connect( (self.msc_sources[i], 0), self.f2s_left_converters[i], (self.mp4_encoders[i], 0), self.rs_encoders[i], self.msc_encoders[i], (self.mux, i + 1)) if stereo_flags[i] == 0: self.connect((self.msc_sources[i], 1), self.f2s_right_converters[i], (self.mp4_encoders[i], 1)) else: self.connect(self.f2s_left_converters[i], (self.mp4_encoders[i], 1)) else: self.connect((self.msc_sources[i], 0), self.f2s_left_converters[i], (self.mp2_encoders[i], 0), self.msc_encoders[i], (self.mux, i + 1)) if stereo_flags[i] == 0: self.connect((self.msc_sources[i], 1), self.f2s_right_converters[i], (self.mp2_encoders[i], 1)) else: self.connect(self.f2s_left_converters[i], (self.mp2_encoders[i], 1)) self.connect((self.mux, 0), self.s2v_mod, (self.mod, 0)) self.connect(self.trigsrc, (self.mod, 1)) if use_usrp: self.connect(self.mod, self.sink) else: self.connect(self.mod, blocks.throttle_make(gr.sizeof_gr_complex, 2e6), self.sink)