def send_polarfile(XN,N,channel_p,compound_plist_u,derate,use_adjusted_Rate): #----------R and G here compound plist is not important 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] Glist=adjustG(Glist) R=pl.getRatelist([channel_p],derate)[0] #calculates rate for given channel G=int(R*N) Iterhistory={} # for first one Tx Iter=0 Iter_p=compound_plist[0] Iter_R=Ratelist[0] Iter_G=Glist[0] Iter_I=I_ord[:Iter_G] #------------------for filing Tx side # reverse arikan :: THIS IS OF SIZE N UN_N=ec.polarencode(XN,N) UN=ec.getUN(UN_N,Iter_I,False) Iter_UN_ind=range(len(UN)) Iter_UN=[UN[i] for i in Iter_UN_ind] #picking data from frozen channels F=list(set(range(N))-set(Iter_I)) FD=ec.getUN(UN_N,F,True) Iter_XN=XN #--------------------Note channel_p used for flipping Iter_YN=pl.BSCN(channel_p,Iter_XN) #-----------------------decoding based on this tx only #-----------------Rx side Iter_UN_hat=ec.polarSCdecodeG(Iter_YN,N,Iter_p,Iter_I,list(FD),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] final_Iter=Iter final_decoded= Iterhistory[0][1] final_UN_hat=Iter_UN_hat final_XN=ec.polarencode(final_UN_hat,N) achieved_rate=float(len(UN))/((final_Iter+1)*N) return (achieved_rate,np.array(final_XN))
def getGChMCK(design_p, N, K, runsim): p = design_p n = int(ma.log(N, 2)) err = np.zeros(N) print "MC(K)..." + str(runsim) for i in range(runsim): UN = np.random.randint(2, size=N) UN_decoded = ec.polarSCdecode(pl.BSCN(p, ec.polarencode(UN, len(UN))), len(UN), p) err = err + np.logical_xor(UN, UN_decoded) aZN = err / runsim sZN = np.sort(aZN) good_channels_all = aZN.argsort().tolist()[:K] good_channels = good_channels_all[:K] ber_exp = np.log10(sZN).tolist() rgood_channels = ec.bitreverseorder(good_channels, n) rgood_channels_all = ec.bitreverseorder(good_channels_all, n) f2 = open( "./simresults/GC/GCMK_" + str(N) + "_" + str(p).replace(".", "p") + "_" + str(K) + ".txt", 'w') json.dump(rgood_channels, f2) f3 = open("./simresults/GC/GCMK_ALL" + str(N) + ".txt", 'w') json.dump(rgood_channels_all, f3) return (rgood_channels, ber_exp[:K], ber_exp)
def polarfile_known(XN, p, pattern, I): N = len(XN) n = int(ma.log(N, 2)) #Tx side UN = ec.polarencode(XN, N) # reverse arikan #picking data from frozen channels F = list(set(range(N)) - set(I)) FD = ec.getUN(UN, F, True) YN = np.logical_xor(XN, pattern) #rx side UN_decoded = ec.polarSCdecodeG(YN, N, p, I, FD, False) XN_decoded = ec.polarencode(UN_decoded, N) return XN_decoded
def polarfile(XN, channel_p, design_p, I): p = channel_p N = len(XN) n = int(ma.log(N, 2)) #Tx side UN = ec.polarencode(XN, N) # reverse arikan #picking data from frozen channels F = list(set(range(N)) - set(I)) FD = ec.getUN(UN, F, True) YN = pl.BSCN(p, XN) #rx side UN_decoded = ec.polarSCdecodeG(YN, N, design_p, I, FD, False) XN_decoded = ec.polarencode(UN_decoded, N) return XN_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))