Package: py-polar-codes
Polar Codes in PythonA library written in Python3 for Polar Codes, a capacity-achieving channel coding technique used in 5G. The library includes functions for construction, encoding, decoding, and simulation of polar codes. In addition, it supports puncturing and shortening.It provides:a systematic and non-systemic encoder.non-recursive implementations of the successive cancellation decoder (SCD).mothercode construction of polar codes using Bhattacharyya Bounds or Gaussian Approximationsupport for puncturing and shortening.Bit-Reversal Shortening (BRS), Wang-Liu Shortening (WLS), and Bioglio-Gabry-Land (BGL) shortening constructions.an AWGN channel with BPSK modulation.an easy-to-use Graphical User Interface (GUI)Documentation:Main reference (pdf)Quick reference (website)Introduction to polar codes, shortening, and the library:http://www.youtube.com/watch?v=v47rn77RAxMGetting StartedInstall the package withpip install py-polar-codesfromhttps://pypi.org/project/py-polar-codes/.Install matplotlib fromhttps://matplotlib.org/users/installing.html.Install numpy fromhttps://docs.scipy.org/doc/numpy/user/install.html.Run test.py using a Python3 compiler. If the program runs successfully, the library is ready to use. Make sure the compiler has writing access to directory "root/data", where simulation data will be saved by default.CallGUI()to start the GUI.ExamplesMothercode Encoding & DecodingAn example of encoding and decoding over an AWGN channel for a (256,100) non-systematic mothercode, using Bhattacharyya Bounds for construction and SCD for decoding.
For systematic encoding and decoding, replaceEncode(myPC)withEncode(myPC, 'systematic_encode')andDecode(myPC)withDecode(myPC, 'systematic_scd').importnumpyasnpfrompolarcodesimport*# initialise polar codemyPC=PolarCode(256,100)myPC.construction_type='bb'# mothercode constructiondesign_SNR=5.0Construct(myPC,design_SNR)print(myPC,"\n\n")# set messagemy_message=np.random.randint(2,size=myPC.K)myPC.set_message(my_message)print("The message is:",my_message)# encode messageEncode(myPC)print("The coded message is:",myPC.get_codeword())# transmit the codewordAWGN(myPC,design_SNR)print("The log-likelihoods are:",myPC.likelihoods)# decode the received codewordDecode(myPC)print("The decoded message is:",myPC.message_received)Shortened Code ConstructionAn example of constructing a shortened polar code with Bit-Reversal Shortening (BRS) algorithm.
The shortening parameters are set by the tupleshorten_params, the third argument ofPolarCode, and is defined by:Puncturing type:shortenorpunct.Puncturing algorithm:brs,wls, orbgl.Puncturing set (for manual puncturing):ndarray<int>Overcapable set (for manual puncturing):ndarray<int>Update reliabilities after puncturing (or use mothercode reliabilities):TrueorFalse.importnumpyasnpfrompolarcodesimport*# initialise shortened polar codeshorten_params=('shorten','brs',None,None,False)myPC=PolarCode(200,100,shorten_params)# constructiondesign_SNR=5.0Shorten(myPC,design_SNR)print(myPC,"\n\n")Simulation & PlottingA script to simulate a defined polar code, save the data to directory "/data", and then display the result in amatplotlibfigure.# simulate polar codemyPC.simulate(save_to='data/pc_sim',Eb_No_vec=np.arange(1,5),manual_const_flag=True)# plot the frame error ratemyPC.plot(['pc_sim'],'data/')The simulation will save your PolarCode object in a JSON file, for example:{"N":64,"n":6,"K":32,"frozen":[22,38,49,26,42,3,28,50,5,44,9,52,6,17,10,33,56,18,12,34,20,36,1,24,40,48,2,4,8,16,32,0],"construction_type":"bb","punct_flag":false,"punct_type":"","punct_set":[],"source_set":[],"punct_algorithm":"","update_frozen_flag":[],"BER":[0.09709375,0.03740625,0.00815625,0.0010184612211221122],"FER":[0.313,0.126,0.03,0.004125412541254125],"SNR":[1,2,3,4]}Graphical User InterfaceAn example of using the GUI to simulate and plot a specified polar code. Note: if "manual construction" is ticked, the user is required to input the frozen bits and the shortened bits.This is a final year project created by Brendon McBain under the supervision of Dr Harish Vangala at Monash University.