import numpy as np import gnuradio # import scipy import csv, time, os, glob, sys from ofdmrx_block_code import ofdm_block2 ########################################################## # read file names to a list # for each file transmit it using block of OFDM, retransmit repeatdely for 15 sec # after 5 sec of transmittion, start receiving and dump the received data to a file. # repeat for the next input file. #################################################################### ########################## Tx Part ############################ if __name__ == "__main__": #read file names # /home/moath/Documents/OFDM/ofdm_block/RandVector/Code/files # os.chdir(r'/home/moath/Documents/OFDM/ofdm_block/RandVector/Code/') # tx_files=glob.glob('*.txt') # # fn,tmp,thr =my_files[0].split("_") # print("There are ",len(tx_files)," file; first one is: ", tx_files[0]) # to print the number of files in the directory and the name for the first file. # print("-----------------------") for index in range(1,101): tb=ofdm_block(index) tb.start() time.sleep(3) tb.stop() tb.wait() print("Sleeping for a while!") time.sleep(7) ########################## Rx part ############################# # def write_csv(writecsvfile,write_csv_data): # with open(writecsvfile,'a') as real_handle: # writer = csv.writer(real_handle) # writer.writerow(write_csv_data) # def split_iq_writecsv(iqchunk,txr, rxr, mod): # filename = 'Txr_'+txr+'-Rvr_'+rxr+'-'+mod + '.csv' # for index, value in enumerate(range(0,iqchunk.shape[1]+1,1024)): # sliced_sample = iqchunk[0][value:value+1024] # if sliced_sample.shape[0] == 1024: # write_csv(filename, sliced_sample.tolist()) # sample_count = index+1 # else: # print("Alert : Discarding sample slice !!!!") # return sample_count # def data_processor(data_file, transmitter, receiver, modulation): # data_list_nn = [] # dtype_all = scipy.dtype([('raw-iq0', scipy.complex64)]) # iqdata = np.fromfile(open(data_file),dtype = dtype_all) # no_of_data = iqdata.shape[0] # print("Data collected: ", no_of_data*2) # xdata = np.concatenate([iqdata['raw-iq0'].real.reshape(no_of_data,1),iqdata['raw-iq0'].imag.reshape(no_of_data,1)],axis = 1) # trans_x_orig = xdata.reshape(1,no_of_data*2) # sample_count = split_iq_writecsv(trans_x_orig, transmitter, receiver ,modulation) # print("Number of samples collected: ", sample_count) # return sample_count # ############################################################# # if __name__ == "__main__": # ########################################################## # # read file names to a list # # for each file transmit it using block of OFDM, retransmit repeatdely for 15 sec # # after 5 sec of transmittion, start receiving and dump the received data to a file. # # repeat for the next input file. # ####################################################################3 # #read file names # os.chdir(r'/home/moath/emitter/Copy_results') # tx_files=glob.glob('*.txt') # # fn,tmp,thr =my_files[0].split("_") # print(len(my_files), tx_files[0]) # to print the number of files in the directory and the name for the first file. # const_list = ['bpsk','qpsk','8_psk','16_qam','64_qam'] # # tx_src=sys.argv[1] # # rx_source = sys.argv[2] # # constellation = sys.argv[3] # #for constellation in const_list: # total_samples = 0 # rounds = 0 # while total_samples < 100000: # if constellation == '64_qam': # tb = top_block(rx_source, constellation,'qam') # elif constellation != '64_qam': # tb = top_block(rx_source, constellation,'generic') # rounds +=1 # print("-----------------------") # print("Receiving round (",rounds,") with total samples of:",total_samples+1,': ',constellation) # print("-----------------------") # tb.start() # time.sleep(5) # tb.stop() # tb.wait() # no_of_samples = data_processor('iqdump.dat', tx_src, rx_source, constellation) # total_samples = total_samples + no_of_samples # print("total_samples= ", total_samples)