#~ table2.append(json.loads(line)) #~ print len(table2) table3 = [] with open(filename3, 'r') as f: for line in f: table3.append(json.loads(line)) #plt.subplot(2,1,1) plt.semilogy(table1[7], [10**i for i in table1[8]], 'k-o', label="Polar Code for p=" + str(p)) #plt.semilogy(table2[7],[10**i for i in table2[8]],'b',linestyle=":",label="Polar Code for p="+str(p1)) #plt.semilogy(table1[7],[10**i for i in table1[8]],'r-o',label="1Iter") #plt.semilogy(table2[9],[10**i for i in table2[10]],'b-o',label="Rateless KRX") (A_r, BER) = ml.sortAextend(table3[11], table3[12]) plt.semilogy(A_r, [10**i for i in BER], 'g-o', label="Inc-Frz with PHY-ED$^{*}$") plt.xlabel('Achieved Rate') plt.ylabel('Frame Error rate.') plt.title('FER vs Rate for SW compression \nN=1024,p=' + str(p) + ',Capacity=' + str(pl.CapacityBSC(1, p))) plt.legend(loc="best") plt.grid(True) plt.figtext(0.005, 0.03, "$^{*}$Compound Channel=$\{$0.04,0.15,0.2,0.25$\}$" ) #+filename0+"\n"+filename3) #~ plt.subplot(2,1,2)
def send_rateless_kRx(UN, N, channel_p, compound_plist_u, derate, use_adjusted_Rate): #print "In send rateless..." #Reliability ordering #print "R_order" I_ord = pcon.getreliability_order(N) #print I_ord #compound channel compound_plist = list(compound_plist_u) #best channel first compound_plist.sort() Ratelist = pl.getRatelist(compound_plist, derate) #best rate first Glist = [int(N * r) for r in Ratelist] #print "Compund Channel" #print plist #print Glist #print "will be working with below to meet R R/2 R/3 R/4 constraint" Glist = adjustG(Glist) #print Glist #given Channel might not be an entry in compound but within bounds R = pl.getRatelist([channel_p], derate)[0] #calculates rate for given channel G = int(R * N) #print "Actual channel" #print channel_p #print G if use_adjusted_Rate: G = Glist[compound_plist.index(channel_p)] #----------------------------------------------------Iterations start Iterhistory = {} #contains indexes of UN sent in each iteration decoded = False # for first Tx Iter = 0 Iter_UN = UN Iter_p = compound_plist[0] Iter_R = Ratelist[0] Iter_G = Glist[0] Iter_I = I_ord[:Iter_G] Iter_UN_ind = range(len(UN)) #Iter_data={} #print float(len(Iter_I))/N #print "Forward decoding" while not decoded: #print "Iter"+str(Iter) Iter_UN = [UN[i] for i in Iter_UN_ind] Iter_D = np.zeros(N - Iter_G, dtype=int).tolist() #frozen data Iter_XN = ec.polarencodeG(Iter_UN, N, Iter_I, list(Iter_D), False) #data goes in as per R.I #--------------------Note channel_p used for flipping Iter_YN = pl.BSCN(channel_p, Iter_XN) #-----------------------decoding based on this tx only Iter_UN_hat = ec.polarSCdecodeG(Iter_YN, N, Iter_p, Iter_I, list(Iter_D), False) Iter_UN_decoded = ec.getUN(Iter_UN_hat, Iter_I, False) #storage needed for final decoding Iterhistory[Iter] = [Iter_UN_ind, Iter_UN_decoded, Iter_YN] #pprint(Iterhistory) #For simulation of Rx knows channel case #Assuming Rx knows the capacity of the channel #hence as long as the rate used is above #the capacity is declares Not decodable #the rate at which decoding is possible and the rate achieved is same #print Iterhistory if not is_decodable_kRx(G, Iter_G): # picking out all the channels that are suspected to be bad in past # iterations and putting them for next iteration. # Note first iteration Whole UN is sent # in next only suspected bad channels are sent prev_I = Iter_I Iter += 1 #New channel params Iter_p = compound_plist[Iter] Iter_R = Ratelist[Iter] Iter_G = Glist[Iter] Iter_I = I_ord[:Iter_G] tosend_ind = [] for i in range(Iter): #picking out the bad channels from prev iterations sent_ind = Iterhistory[i][0] sent_ind_last_iter = sent_ind[:Glist[Iter - 1]] bad_ind = sent_ind_last_iter[Iter_G:] #print bad_ind tosend_ind.extend(bad_ind) Iter_UN_ind = list(set(tosend_ind)) Iter_UN_ind.sort() #print Iter_UN_ind else: #the final reliable good channels is that of last iteration final_Iter = Iter final_G = Iter_G #channel_p is already updated final_p = Iter_p final_I = I_ord[:final_G] decoded = True #pprint(Iterhistory) #final decoding #number retrodecoding needed = iter-1 #print "Final Decoding..." #print final_p #print final_G #print Iter for Iter in range(final_Iter - 1, -1, -1): #print "Here" #print "Iter"+str(Iter)+"-"*10 #print "Prev frozen" Prev_correct_ind = Iterhistory[Iter + 1][0] Prev_correct_data = Iterhistory[Iter + 1][1] #print Prev_correct_ind #print Prev_correct_data #print "Inc frozen needed" IncFreeze_ind_UN = [ i for i in Prev_correct_ind if i in Iterhistory[Iter][0] ] #basically intersection with some order picking the indexes of the prev iter frozen data needed in this iter i.e, 12 #print IncFreeze_ind_UN #picking the data i.e. u12 IncFreeze_ind_ind = [ Prev_correct_ind.index(j) for j in IncFreeze_ind_UN ] IncFreeze_data = [Prev_correct_data[k] for k in IncFreeze_ind_ind] #print IncFreeze_data #finding the channels where 12 went in this iter 16 15 14 "13"<--- here #i.e, removing the top channel_G channels (as they are good) from top Iter_i_G channels Iter_G = Glist[Iter] IncFreeze_ind = I_ord[:Iter_G][final_G:] #print "Inc Frozen Data going in" #print IncFreeze_ind #print "Frozen zeroes" Iter_D = np.zeros(N - Iter_G, dtype=int).tolist() #frozen data as per iteration #print len(Iter_D) Iter_YN = Iterhistory[Iter][2] Iter_UN_hat = ec.polarIncFrzSCdecodeG(Iter_YN, N, final_p, final_I, list(Iter_D), IncFreeze_ind, IncFreeze_data, False) Iter_UN_decoded = ec.getUN(Iter_UN_hat, final_I, False) #print Iter_UN_decoded #history update Iterhistory_ind_upd = list(Prev_correct_ind) Iterhistory_ind_upd.extend( Iterhistory[Iter][0][:final_G]) #ie adding 5,6,11 to 4,10,12 Iterhistory_data_upd = np.hstack( (Prev_correct_data, Iter_UN_decoded)) #same as extend #print "Update" #print Iterhistory_ind_upd #print Iterhistory_data_upd #print "sorted" (Iterhistory[Iter][0], Iterhistory[Iter][1]) = ml.sortAextend(Iterhistory_ind_upd, Iterhistory_data_upd.tolist()) #print Iterhistory[Iter][0] #print Iterhistory[Iter][1] #pprint(Iterhistory) final_decoded = Iterhistory[0][1] achieved_rate = float(len(UN)) / ((final_Iter + 1) * N) return (achieved_rate, np.array(final_decoded))
def send_rateless_file_kRx(XN,N,channel_p,compound_plist_u,derate,use_adjusted_Rate): I_ord=pcon.getreliability_order(N) compound_plist=list(compound_plist_u) #best channel first compound_plist.sort() Ratelist = pl.getRatelist(compound_plist,derate) #best rate first Glist=[int(N*r) for r in Ratelist] #print "will be working with below to meet R R/2 R/3 R/4 constraint" Glist=adjustG(Glist) R=pl.getRatelist([channel_p],derate)[0] #calculates rate for given channel G=int(R*N) if use_adjusted_Rate: G=Glist[compound_plist.index(channel_p)] #----------------------------------------------------Iterations start Iterhistory={} #contains indexes of UN sent in each iteration decoded=False #------------------for filing Tx side # reverse arikan :: THIS IS OF SIZE N UN_N=ec.polarencode(XN,N) # for first Tx Iter=0 Iter_p=compound_plist[0] Iter_R=Ratelist[0] Iter_G=Glist[0] Iter_I=I_ord[:Iter_G] UN=ec.getUN(UN_N,Iter_I,False) #print Iter_I #print UN Iter_UN=UN Iter_UN_ind=range(len(UN)) F=list(set(range(N))-set(Iter_I)) FD=ec.getUN(UN_N,F,True) #-------------------------------------------Forward decoding #in case of first iteration FD, XN is used #from next iteration more bits from reverse Arikan UN is used while not decoded: if Iter==0: Iter_XN=XN else: Iter_UN=[UN[i] for i in Iter_UN_ind] Iter_D=np.zeros(N-Iter_G,dtype=int).tolist() #frozen data Iter_XN=ec.polarencodeG(Iter_UN,N,Iter_I,list(Iter_D),False) #data goes in as per R.I #--------------------Note channel_p used for flipping Iter_YN=pl.BSCN(channel_p,Iter_XN) #-----------------------decoding based on this tx only if Iter==0: Iter_UN_hat=ec.polarSCdecodeG(Iter_YN,N,Iter_p,Iter_I,list(FD),False) else: Iter_UN_hat=ec.polarSCdecodeG(Iter_YN,N,Iter_p,Iter_I,list(Iter_D),False) Iter_UN_decoded=ec.getUN(Iter_UN_hat,Iter_I,False) #storage needed for final decoding Iterhistory[Iter]=[Iter_UN_ind,Iter_UN_decoded,Iter_YN] #For simulation of Rx knows channel case #Assuming Rx knows the capacity of the channel #hence as long as the rate used is above #the capacity is declares Not decodable #the rate at which decoding is possible and the rate achieved is same if not is_decodable_kRx(G,Iter_G): #print "here" # picking out all the channels that are suspected to be bad in past # iterations and putting them for next iteration. # Note first iteration Whole UN is sent # in next only suspected bad channels are sent prev_I=Iter_I Iter+=1 #New channel params Iter_p=compound_plist[Iter] Iter_R=Ratelist[Iter] Iter_G=Glist[Iter] Iter_I=I_ord[:Iter_G] tosend_ind=[] for i in range(Iter): #picking out the bad channels from prev iterations sent_ind=Iterhistory[i][0] sent_ind_last_iter=sent_ind[:Glist[Iter-1]] bad_ind=sent_ind_last_iter[Iter_G:] tosend_ind.extend(bad_ind) Iter_UN_ind=list(set(tosend_ind)) Iter_UN_ind.sort() else: #the final reliable good channels is that of last iteration final_Iter=Iter final_G=Iter_G final_p=Iter_p final_I=I_ord[:final_G] #~ if Iter=0: #~ final_XN=ec.polarencode(Iter_UN_hat,N) #in case first iteration is last decoded= True #------------------------------------------------final decoding #number retrodecoding needed = iter-1 #print Iter for Iter in range(final_Iter-1,-1,-1): #print "retro"+str(Iter) Prev_correct_ind=Iterhistory[Iter+1][0] Prev_correct_data=Iterhistory[Iter+1][1] IncFreeze_ind_UN=[i for i in Prev_correct_ind if i in Iterhistory[Iter][0]] #basically intersection with some order picking the indexes of the prev iter frozen data needed in this iter i.e, 12 #print IncFreeze_ind_UN #picking the data i.e. u12 IncFreeze_ind_ind=[Prev_correct_ind.index(j) for j in IncFreeze_ind_UN] IncFreeze_data=[Prev_correct_data[k] for k in IncFreeze_ind_ind] #print IncFreeze_data #finding the channels where 12 went in this iter 16 15 14 "13"<--- here #i.e, removing the top channel_G channels (as they are good) from top Iter_i_G channels Iter_G=Glist[Iter] IncFreeze_ind=I_ord[:Iter_G][final_G:] if Iter==0: Iter_D=FD else: Iter_D=np.zeros(N-Iter_G,dtype=int).tolist() #frozen data as per iteration Iter_YN=Iterhistory[Iter][2] Iter_UN_hat=ec.polarIncFrzSCdecodeG(Iter_YN,N,final_p,final_I,list(Iter_D),IncFreeze_ind,IncFreeze_data,False) Iter_UN_decoded=ec.getUN(Iter_UN_hat,final_I,False) #history update Iterhistory_ind_upd=list(Prev_correct_ind) Iterhistory_ind_upd.extend(Iterhistory[Iter][0][:final_G]) #ie adding 5,6,11 to 4,10,12 Iterhistory_data_upd=np.hstack((Prev_correct_data,Iter_UN_decoded)) #same as extend (Iterhistory[Iter][0],Iterhistory[Iter][1])=ml.sortAextend(Iterhistory_ind_upd,Iterhistory_data_upd.tolist()) final_decoded= Iterhistory[0][1] final_XN=ec.polarencode(Iter_UN_hat,N) achieved_rate=float(len(UN))/((final_Iter+1)*N) return (achieved_rate,np.array(final_XN))