def main(): #self.data = ( [[random.randint(0,255) for x in xrange(self.data_len)] # +50*[0,],] ) #self.data = [[0 for x in xrange(self.data_len)],] \ # + self.nofdm_frames*[[random.randint(0,255) \ # for x in xrange(self.data_len)],] #self.data = self.nofdm_frames*[[x for x in xrange(self.data_len)],]\ # + [50*[0,],] args = get_arguments() constellation = { 1:digital.constellation_bpsk(), 2:digital.constellation_qpsk(), 3:digital.constellation_8psk(), } packet_len_tag = "packet_length" #fft_len = 64 #cp_len = 16 #occupied_carriers = (range(-26, -21) + range(-20, -7) + # range(-6, 0) + range(1, 7) + # range(8, 21) + range(22, 27),) #pilot_carriers = ((-21, -7, 7, 21),) #pilot_symbols = tuple([(1, -1, 1, -1),]) fft_len = 16 cp_len = 4 occupied_carriers = ((-5, -4, -2, -1, 1, 2, 4, 5),) pilot_carriers = ((-3, 3),) pilot_symbols = tuple([(1, -1),]) data_len = utils.ofdm_get_data_len( nofdm_symbols=args.nsymbols, noccupied_carriers=len(occupied_carriers[0]), constellation=constellation[args.bits] ) data = args.nframes*[[39 for x in xrange(data_len)],] # sometimes Schmidl-Cox-Correlator ignores first frame # so a dummy-frame is a good idea if args.dummy_frame_start == True: data.insert(0, data_len*[0]) # if file-output GNURadio needs extra frame at the and to loop over all # OFDM-Frames before, last OFDM-Frame is ignored # not so in case of using UHD-devices because there exists incoming # input-data all the time if args.dummy_frame_end == True: data.append(data_len*[0]) tb = gr.top_block() (data_tosend, tags) = packet_utils.packets_to_vectors( data, packet_len_tag ) data_source = blocks.vector_source_b( data=data_tosend, vlen=1, tags=tags, repeat=False ) ofdm_mapper = mimoots.ofdm_symbol_mapper_bc( constellation=constellation[args.bits], packet_len_tag=packet_len_tag, verbose=args.verbose ) ofdm_framer = mimoots.ofdm_symbols_to_frame_cvc( fft_len=fft_len, cp_len=cp_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, packet_len_tag=packet_len_tag, verbose=args.verbose ) ofdm_basebander = mimoots.ofdm_frames_to_basebandsignal_vcc( fft_len=fft_len, cp_len=cp_len, packet_len_tag=packet_len_tag, verbose=args.verbose ) if args.freq == None: data_sink = blocks.file_sink( itemsize=gr.sizeof_gr_complex, filename=args.to_file ) else: data_sink = mimoots.uhd_sink(freq=args.freq, gain=args.gain) tb.connect(data_source, ofdm_mapper, ofdm_framer, ofdm_basebander, data_sink) tb.run() # need to wait until the GNURadio-graph is finished time.sleep(5)
def __init__(self, data=[ [], ], fft_len=64, cp_len=16, nofdm_symbols=10, nofdm_frames=1, ofdm_symbol_scale=1, constellation=digital.constellation_bpsk(), occupied_carriers=(range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27), ), pilot_carriers=((-21, -7, 7, 21), ), pilot_symbols=tuple([ (1, -1, 1, -1), ]), scale=1.0, seq_seed=42, debug=False): gr.hier_block2.__init__( self, "ofdm_create_frames_bc", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature # ===================================================================== # Generate class-members # ===================================================================== self._def_occupied_carriers = occupied_carriers self._def_pilot_carriers = pilot_carriers self._def_pilot_symbols = pilot_symbols self._seq_seed = seq_seed self.data = data self.fft_len = fft_len self.cp_len = cp_len self.ofdm_symbol_scale = ofdm_symbol_scale self.constellation = constellation self.packet_len_tag = "packet_length" self.frame_length_tag_key = "frame_length" self.nofdm_symbols = nofdm_symbols self.nofdm_frames = nofdm_frames self.scale = scale self.debug = debug # ===================================================================== # Create data to convert into OFDM-Frames # ===================================================================== random.seed(self._seq_seed) self.data_len = utils.ofdm_get_data_len( nofdm_symbols=self.nofdm_symbols, noccupied_carriers=len(self._def_occupied_carriers[0]), constellation=constellation) if debug == True: print 'Frames: {}'.format(self.nofdm_frames) print 'Länge: {}'.format(self.data_len) (data_tosend, tags) = packet_utils.packets_to_vectors(self.data, self.packet_len_tag) # =================================================================== # Create all blocks # =================================================================== self.data_source = blocks.vector_source_b(data=data_tosend, vlen=1, tags=tags, repeat=False) self.payload_unpack = blocks.repack_bits_bb( k=8, l=self.constellation.bits_per_symbol(), len_tag_key=self.packet_len_tag) self.payload_mod = digital.chunks_to_symbols_bc( symbol_table=self.constellation.points()) self.allocator = digital.ofdm_carrier_allocator_cvc( fft_len=self.fft_len, occupied_carriers=self._def_occupied_carriers, pilot_carriers=self._def_pilot_carriers, pilot_symbols=self._def_pilot_symbols, sync_words=[ utils.ofdm_make_sync_word1(self.fft_len, self._def_occupied_carriers, self._def_pilot_carriers), utils.ofdm_make_sync_word2(self.fft_len, self._def_occupied_carriers, self._def_pilot_carriers), ], len_tag_key=self.packet_len_tag) self.ffter = fft.fft_vcc(fft_size=self.fft_len, forward=False, window=(), shift=True) self.scale = mimoots.ofdm_scale_symbol_vcvc(symbol_len=self.fft_len, scale=self.scale) self.cyclic_prefixer = digital.ofdm_cyclic_prefixer( input_size=self.fft_len, output_size=self.fft_len + cp_len, rolloff_len=0, len_tag_key=self.packet_len_tag) # =================================================================== # Connect all blocks # =================================================================== self.connect(self.data_source, self.payload_unpack, self.payload_mod, self.allocator, self.ffter, self.scale, self.cyclic_prefixer, self) #self.connect( # self.data_source, self.payload_mod, self.payload_unpack, # self.allocator, self.ffter, self.scale, self.cyclic_prefixer, # self #) # =================================================================== # Debug-Output # =================================================================== if self.debug == True: self.connect( self.data_source, blocks.file_sink(gr.sizeof_char, 'create-data_source.dat')) self.connect( self.payload_unpack, blocks.file_sink(gr.sizeof_char, 'create-payload_unpack.dat')) self.connect( self.payload_mod, blocks.file_sink(gr.sizeof_gr_complex, 'create-payload_mod.dat')) self.connect( self.allocator, blocks.file_sink(self.fft_len * gr.sizeof_gr_complex, 'create-allocator.dat')) self.connect( self.ffter, blocks.file_sink(self.fft_len * gr.sizeof_gr_complex, 'create-ffter.dat')) self.connect( self.scale, blocks.file_sink(self.fft_len * gr.sizeof_gr_complex, 'create-scale.dat')) self.connect( self.cyclic_prefixer, blocks.file_sink(gr.sizeof_gr_complex, 'create-cyclic_prefixer.dat'))
def setup_data_tags(self, data): return packet_utils.packets_to_vectors( data, self.tsb_key )
def main(): #self.data = ( [[random.randint(0,255) for x in xrange(self.data_len)] \ # +50*[0,],] ) #self.data = [[0 for x in xrange(self.data_len)],] \ # +self.nofdm_frames*[[random.randint(0,255) \ # for x in xrange(self.data_len)],] #self.data = self.nofdm_frames*[[x for x in xrange(self.data_len)],] \ # + [50*[0,],] args = get_arguments() constellation = { 1: digital.constellation_bpsk(), 2: digital.constellation_qpsk(), 3: digital.constellation_8psk(), } packet_len_tag = "packet_length" fft_len = 64 cp_len = 16 occupied_carriers = (range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27), ) pilot_carriers = ((-21, -7, 7, 21), ) pilot_symbols = tuple([ (1, -1, 1, -1), ]) data_len = utils.ofdm_get_data_len(nofdm_symbols=args.nsymbols, noccupied_carriers=len( occupied_carriers[0]), constellation=constellation[args.bits]) data0 = args.nframes * [ [1 for x in xrange(data_len)], ] data1 = args.nframes * [ [2 for x in xrange(data_len)], ] # sometimes Schmidl-Cox-Correlator ignores first frame # so a dummy-frame is a good idea if args.dummy_frame == True: data0.insert(0, data_len * [0]) data1.insert(0, data_len * [0]) # if file-output GNURadio needs extra frame at the and to loop over all # OFDM-Frames before, last OFDM-Frame is ignored # not so in case of using UHD-devices because there exists incoming # input-data all the time if args.freq == None: data0.append(data_len * [0]) data1.append(data_len * [0]) (data0_tosend, tags0) = packet_utils.packets_to_vectors(data0, packet_len_tag) (data1_tosend, tags1) = packet_utils.packets_to_vectors(data1, packet_len_tag) tb = gr.top_block() data_source0 = blocks.vector_source_b(data=data0_tosend, vlen=1, tags=tags0, repeat=False) data_source1 = blocks.vector_source_b(data=data1_tosend, vlen=1, tags=tags1, repeat=False) ofdm_mapper0 = mimoots.ofdm_symbol_mapper_bc( constellation=constellation[args.bits], packet_len_tag=packet_len_tag) ofdm_mapper1 = mimoots.ofdm_symbol_mapper_bc( constellation=constellation[args.bits], packet_len_tag=packet_len_tag) ofdm_framer0 = mimoots.ofdm_symbols_to_frame_cvc( fft_len=fft_len, cp_len=cp_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, packet_len_tag=packet_len_tag) ofdm_framer1 = mimoots.ofdm_symbols_to_frame_cvc( fft_len=fft_len, cp_len=cp_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, packet_len_tag=packet_len_tag) ofdm_basebander0 = mimoots.ofdm_frames_to_basebandsignal_vcc( fft_len=fft_len, cp_len=cp_len, packet_len_tag=packet_len_tag) ofdm_basebander1 = mimoots.ofdm_frames_to_basebandsignal_vcc( fft_len=fft_len, cp_len=cp_len, packet_len_tag=packet_len_tag) if args.freq == None: data_sink = mimoots.file_sink2( itemsize=(gr.sizeof_gr_complex, gr.sizeof_gr_complex), filename=('1.'.join(args.to_file.rsplit('.', 1)), '2.'.join(args.to_file.rsplit('.', 1)))) else: data_sink = mimoots.uhd_sink2(freq=args.freq, gain=args.gain) tb.connect(data_source0, ofdm_mapper0, ofdm_framer0, ofdm_basebander0, (data_sink, 0)) tb.connect(data_source1, ofdm_mapper1, ofdm_framer1, ofdm_basebander1, (data_sink, 1)) tb.run() time.sleep(5)
def setup_data_tags(self, data): return packet_utils.packets_to_vectors(data, self.tsb_key)
def main(): args = get_arguments() constellation = { 1:digital.constellation_bpsk(), 2:digital.constellation_qpsk(), 3:digital.constellation_8psk(), } packet_len_tag = "packet_length" fft_len = 64 cp_len = 16 occupied_carriers=(range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27),) pilot_carriers=((-21, -7, 7, 21),) pilot_symbols=tuple([(1, -1, 1, -1),]) data_len = utils.ofdm_get_data_len( nofdm_symbols=args.nsymbols, noccupied_carriers=len(occupied_carriers[0]), constellation=constellation[args.bits] ) data = args.nframes*[[1 for x in xrange(data_len)],] tb = gr.top_block() (data_tosend, tags) = packet_utils.packets_to_vectors( data, packet_len_tag ) data_source = blocks.vector_source_b( data=data_tosend, vlen=1, tags=tags, repeat=False ) ofdm_mapper = mimoots.ofdm_symbol_mapper_bc( constellation=constellation[args.bits], packet_len_tag=packet_len_tag ) ofdm_framer = mimoots.ofdm_symbols_to_frame_cvc( fft_len=fft_len, cp_len=cp_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, packet_len_tag=packet_len_tag ) ofdm_basebander = mimoots.ofdm_frames_to_basebandsignal_vcc( fft_len=fft_len, cp_len=cp_len, packet_len_tag=packet_len_tag ) shifter = blocks.delay( itemsize=gr.sizeof_gr_complex, delay=(fft_len+cp_len)*(3) ) xor_source = blocks.vector_source_c( data=5*[0]+(3*(fft_len+cp_len)-10)*[1]+5*[0]+3*(fft_len+cp_len)*[0], repeat=True ) xor1 = blocks.multiply_cc() xor2 = blocks.multiply_cc() if args.freq == None: data_sink = mimoots.file_sink2( itemsize=(gr.sizeof_gr_complex, gr.sizeof_gr_complex), filename=( '1.'.join(args.to_file.rsplit('.',1)), '2.'.join(args.to_file.rsplit('.',1)) ) ) else: data_sink = mimoots.uhd_sink2(freq=args.freq, gain=args.gain) tb.connect(xor_source, (xor1, 1)) tb.connect(xor_source, (xor2, 1)) tb.connect(data_source, ofdm_mapper, ofdm_framer, ofdm_basebander) tb.connect(ofdm_basebander, (xor1, 0), (data_sink, 0)) tb.connect(ofdm_basebander, (xor2, 0), shifter, (data_sink, 1)) tb.run() time.sleep(5)
def main(): #self.data = ( [[random.randint(0,255) for x in xrange(self.data_len)] # +50*[0,],] ) #self.data = [[0 for x in xrange(self.data_len)],] \ # + self.nofdm_frames*[[random.randint(0,255) \ # for x in xrange(self.data_len)],] #self.data = self.nofdm_frames*[[x for x in xrange(self.data_len)],]\ # + [50*[0,],] args = get_arguments() constellation = { 1: digital.constellation_bpsk(), 2: digital.constellation_qpsk(), 3: digital.constellation_8psk(), } packet_len_tag = "packet_length" #fft_len = 64 #cp_len = 16 #occupied_carriers = (range(-26, -21) + range(-20, -7) + # range(-6, 0) + range(1, 7) + # range(8, 21) + range(22, 27),) #pilot_carriers = ((-21, -7, 7, 21),) #pilot_symbols = tuple([(1, -1, 1, -1),]) fft_len = 16 cp_len = 4 occupied_carriers = ((-5, -4, -2, -1, 1, 2, 4, 5), ) pilot_carriers = ((-3, 3), ) pilot_symbols = tuple([ (1, -1), ]) data_len = utils.ofdm_get_data_len(nofdm_symbols=args.nsymbols, noccupied_carriers=len( occupied_carriers[0]), constellation=constellation[args.bits]) data = args.nframes * [ [39 for x in xrange(data_len)], ] # sometimes Schmidl-Cox-Correlator ignores first frame # so a dummy-frame is a good idea if args.dummy_frame_start == True: data.insert(0, data_len * [0]) # if file-output GNURadio needs extra frame at the and to loop over all # OFDM-Frames before, last OFDM-Frame is ignored # not so in case of using UHD-devices because there exists incoming # input-data all the time if args.dummy_frame_end == True: data.append(data_len * [0]) tb = gr.top_block() (data_tosend, tags) = packet_utils.packets_to_vectors(data, packet_len_tag) data_source = blocks.vector_source_b(data=data_tosend, vlen=1, tags=tags, repeat=False) ofdm_mapper = mimoots.ofdm_symbol_mapper_bc( constellation=constellation[args.bits], packet_len_tag=packet_len_tag, verbose=args.verbose) ofdm_framer = mimoots.ofdm_symbols_to_frame_cvc( fft_len=fft_len, cp_len=cp_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, packet_len_tag=packet_len_tag, verbose=args.verbose) ofdm_basebander = mimoots.ofdm_frames_to_basebandsignal_vcc( fft_len=fft_len, cp_len=cp_len, packet_len_tag=packet_len_tag, verbose=args.verbose) if args.freq == None: data_sink = blocks.file_sink(itemsize=gr.sizeof_gr_complex, filename=args.to_file) else: data_sink = mimoots.uhd_sink(freq=args.freq, gain=args.gain) tb.connect(data_source, ofdm_mapper, ofdm_framer, ofdm_basebander, data_sink) tb.run() # need to wait until the GNURadio-graph is finished time.sleep(5)
def main(): args = get_arguments() constellation = { 1: digital.constellation_bpsk(), 2: digital.constellation_qpsk(), 3: digital.constellation_8psk(), } packet_len_tag = "packet_length" fft_len = 64 cp_len = 16 occupied_carriers = (range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27), ) pilot_carriers = ((-21, -7, 7, 21), ) pilot_symbols = tuple([ (1, -1, 1, -1), ]) data_len = utils.ofdm_get_data_len(nofdm_symbols=args.nsymbols, noccupied_carriers=len( occupied_carriers[0]), constellation=constellation[args.bits]) data = args.nframes * [ [1 for x in xrange(data_len)], ] tb = gr.top_block() (data_tosend, tags) = packet_utils.packets_to_vectors(data, packet_len_tag) data_source = blocks.vector_source_b(data=data_tosend, vlen=1, tags=tags, repeat=False) ofdm_mapper = mimoots.ofdm_symbol_mapper_bc( constellation=constellation[args.bits], packet_len_tag=packet_len_tag) ofdm_framer = mimoots.ofdm_symbols_to_frame_cvc( fft_len=fft_len, cp_len=cp_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, packet_len_tag=packet_len_tag) ofdm_basebander = mimoots.ofdm_frames_to_basebandsignal_vcc( fft_len=fft_len, cp_len=cp_len, packet_len_tag=packet_len_tag) shifter = blocks.delay(itemsize=gr.sizeof_gr_complex, delay=(fft_len + cp_len) * (3)) xor_source = blocks.vector_source_c( data=5 * [0] + (3 * (fft_len + cp_len) - 10) * [1] + 5 * [0] + 3 * (fft_len + cp_len) * [0], repeat=True) xor1 = blocks.multiply_cc() xor2 = blocks.multiply_cc() if args.freq == None: data_sink = mimoots.file_sink2( itemsize=(gr.sizeof_gr_complex, gr.sizeof_gr_complex), filename=('1.'.join(args.to_file.rsplit('.', 1)), '2.'.join(args.to_file.rsplit('.', 1)))) else: data_sink = mimoots.uhd_sink2(freq=args.freq, gain=args.gain) tb.connect(xor_source, (xor1, 1)) tb.connect(xor_source, (xor2, 1)) tb.connect(data_source, ofdm_mapper, ofdm_framer, ofdm_basebander) tb.connect(ofdm_basebander, (xor1, 0), (data_sink, 0)) tb.connect(ofdm_basebander, (xor2, 0), shifter, (data_sink, 1)) tb.run() time.sleep(5)
def main(): #self.data = ( [[random.randint(0,255) for x in xrange(self.data_len)] \ # +50*[0,],] ) #self.data = [[0 for x in xrange(self.data_len)],] \ # +self.nofdm_frames*[[random.randint(0,255) \ # for x in xrange(self.data_len)],] #self.data = self.nofdm_frames*[[x for x in xrange(self.data_len)],] \ # + [50*[0,],] args = get_arguments() constellation = { 1:digital.constellation_bpsk(), 2:digital.constellation_qpsk(), 3:digital.constellation_8psk(), } packet_len_tag = "packet_length" fft_len = 64 cp_len = 16 occupied_carriers=(range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27),) pilot_carriers=((-21, -7, 7, 21),) pilot_symbols=tuple([(1, -1, 1, -1),]) data_len = utils.ofdm_get_data_len( nofdm_symbols=args.nsymbols, noccupied_carriers=len(occupied_carriers[0]), constellation=constellation[args.bits] ) data0 = args.nframes*[[1 for x in xrange(data_len)],] data1 = args.nframes*[[2 for x in xrange(data_len)],] # sometimes Schmidl-Cox-Correlator ignores first frame # so a dummy-frame is a good idea if args.dummy_frame == True: data0.insert(0, data_len*[0]) data1.insert(0, data_len*[0]) # if file-output GNURadio needs extra frame at the and to loop over all # OFDM-Frames before, last OFDM-Frame is ignored # not so in case of using UHD-devices because there exists incoming # input-data all the time if args.freq == None: data0.append(data_len*[0]) data1.append(data_len*[0]) (data0_tosend, tags0) = packet_utils.packets_to_vectors( data0, packet_len_tag ) (data1_tosend, tags1) = packet_utils.packets_to_vectors( data1, packet_len_tag ) tb = gr.top_block() data_source0 = blocks.vector_source_b( data=data0_tosend, vlen=1, tags=tags0, repeat=False ) data_source1 = blocks.vector_source_b( data=data1_tosend, vlen=1, tags=tags1, repeat=False ) ofdm_mapper0 = mimoots.ofdm_symbol_mapper_bc( constellation=constellation[args.bits], packet_len_tag=packet_len_tag ) ofdm_mapper1 = mimoots.ofdm_symbol_mapper_bc( constellation=constellation[args.bits], packet_len_tag=packet_len_tag ) ofdm_framer0 = mimoots.ofdm_symbols_to_frame_cvc( fft_len=fft_len, cp_len=cp_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, packet_len_tag=packet_len_tag ) ofdm_framer1 = mimoots.ofdm_symbols_to_frame_cvc( fft_len=fft_len, cp_len=cp_len, occupied_carriers=occupied_carriers, pilot_carriers=pilot_carriers, pilot_symbols=pilot_symbols, packet_len_tag=packet_len_tag ) ofdm_basebander0 = mimoots.ofdm_frames_to_basebandsignal_vcc( fft_len=fft_len, cp_len=cp_len, packet_len_tag=packet_len_tag ) ofdm_basebander1 = mimoots.ofdm_frames_to_basebandsignal_vcc( fft_len=fft_len, cp_len=cp_len, packet_len_tag=packet_len_tag ) if args.freq == None: data_sink = mimoots.file_sink2( itemsize=(gr.sizeof_gr_complex, gr.sizeof_gr_complex), filename=( '1.'.join(args.to_file.rsplit('.',1)), '2.'.join(args.to_file.rsplit('.',1)) ) ) else: data_sink = mimoots.uhd_sink2(freq=args.freq, gain=args.gain) tb.connect(data_source0, ofdm_mapper0, ofdm_framer0, ofdm_basebander0, (data_sink, 0)) tb.connect(data_source1, ofdm_mapper1, ofdm_framer1, ofdm_basebander1, (data_sink, 1)) tb.run() time.sleep(5)