├── .gitattributes ├── .gitignore ├── Polar Codes.sln ├── Polar Codes ├── CRC.cpp ├── CRC.h ├── Channel.cpp ├── Channel.h ├── InfoSource.cpp ├── InfoSource.h ├── Modulation.cpp ├── Modulation.h ├── Polar Codes.vcxproj ├── Polar Codes.vcxproj.filters ├── Polar.cpp ├── Polar.h ├── Polar_decoder.cpp ├── Polar_decoder.h ├── Polar_encoder.cpp ├── Polar_encoder.h ├── allheader.h ├── ice_process.cpp ├── ice_process.h ├── ice_type.cpp ├── ice_type.h └── main.cpp └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | # DNX 42 | project.lock.json 43 | artifacts/ 44 | 45 | *_i.c 46 | *_p.c 47 | *_i.h 48 | *.ilk 49 | *.meta 50 | *.obj 51 | *.pch 52 | *.pdb 53 | *.pgc 54 | *.pgd 55 | *.rsp 56 | *.sbr 57 | *.tlb 58 | *.tli 59 | *.tlh 60 | *.tmp 61 | *.tmp_proj 62 | *.log 63 | *.vspscc 64 | *.vssscc 65 | .builds 66 | *.pidb 67 | *.svclog 68 | *.scc 69 | 70 | # Chutzpah Test files 71 | _Chutzpah* 72 | 73 | # Visual C++ cache files 74 | ipch/ 75 | *.aps 76 | *.ncb 77 | *.opensdf 78 | *.sdf 79 | *.cachefile 80 | 81 | # Visual Studio profiler 82 | *.psess 83 | *.vsp 84 | *.vspx 85 | 86 | # TFS 2012 Local Workspace 87 | $tf/ 88 | 89 | # Guidance Automation Toolkit 90 | *.gpState 91 | 92 | # ReSharper is a .NET coding add-in 93 | _ReSharper*/ 94 | *.[Rr]e[Ss]harper 95 | *.DotSettings.user 96 | 97 | # JustCode is a .NET coding add-in 98 | .JustCode 99 | 100 | # TeamCity is a build add-in 101 | _TeamCity* 102 | 103 | # DotCover is a Code Coverage Tool 104 | *.dotCover 105 | 106 | # NCrunch 107 | _NCrunch_* 108 | .*crunch*.local.xml 109 | 110 | # MightyMoose 111 | *.mm.* 112 | AutoTest.Net/ 113 | 114 | # Web workbench (sass) 115 | .sass-cache/ 116 | 117 | # Installshield output folder 118 | [Ee]xpress/ 119 | 120 | # DocProject is a documentation generator add-in 121 | DocProject/buildhelp/ 122 | DocProject/Help/*.HxT 123 | DocProject/Help/*.HxC 124 | DocProject/Help/*.hhc 125 | DocProject/Help/*.hhk 126 | DocProject/Help/*.hhp 127 | DocProject/Help/Html2 128 | DocProject/Help/html 129 | 130 | # Click-Once directory 131 | publish/ 132 | 133 | # Publish Web Output 134 | *.[Pp]ublish.xml 135 | *.azurePubxml 136 | ## TODO: Comment the next line if you want to checkin your 137 | ## web deploy settings but do note that will include unencrypted 138 | ## passwords 139 | #*.pubxml 140 | 141 | *.publishproj 142 | 143 | # NuGet Packages 144 | *.nupkg 145 | # The packages folder can be ignored because of Package Restore 146 | **/packages/* 147 | # except build/, which is used as an MSBuild target. 148 | !**/packages/build/ 149 | # Uncomment if necessary however generally it will be regenerated when needed 150 | #!**/packages/repositories.config 151 | 152 | # Windows Azure Build Output 153 | csx/ 154 | *.build.csdef 155 | 156 | # Windows Store app package directory 157 | AppPackages/ 158 | 159 | # Visual Studio cache files 160 | # files ending in .cache can be ignored 161 | *.[Cc]ache 162 | # but keep track of directories ending in .cache 163 | !*.[Cc]ache/ 164 | 165 | # Others 166 | ClientBin/ 167 | [Ss]tyle[Cc]op.* 168 | ~$* 169 | *~ 170 | *.dbmdl 171 | *.dbproj.schemaview 172 | *.pfx 173 | *.publishsettings 174 | node_modules/ 175 | orleans.codegen.cs 176 | 177 | # RIA/Silverlight projects 178 | Generated_Code/ 179 | 180 | # Backup & report files from converting an old project file 181 | # to a newer Visual Studio version. Backup files are not needed, 182 | # because we have git ;-) 183 | _UpgradeReport_Files/ 184 | Backup*/ 185 | UpgradeLog*.XML 186 | UpgradeLog*.htm 187 | 188 | # SQL Server files 189 | *.mdf 190 | *.ldf 191 | 192 | # Business Intelligence projects 193 | *.rdl.data 194 | *.bim.layout 195 | *.bim_*.settings 196 | 197 | # Microsoft Fakes 198 | FakesAssemblies/ 199 | 200 | # Node.js Tools for Visual Studio 201 | .ntvs_analysis.dat 202 | 203 | # Visual Studio 6 build log 204 | *.plg 205 | 206 | # Visual Studio 6 workspace options file 207 | *.opt 208 | 209 | # LightSwitch generated files 210 | GeneratedArtifacts/ 211 | _Pvt_Extensions/ 212 | ModelManifest.xml 213 | /Polar Codes/Polar_decoder.cpp.bak 214 | /Polar Codes/Polar_decoder.h.bak 215 | -------------------------------------------------------------------------------- /Polar Codes.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Polar Codes", "Polar Codes\Polar Codes.vcxproj", "{25ECDBD4-B0A8-4040-AE0D-307E2D124384}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {25ECDBD4-B0A8-4040-AE0D-307E2D124384}.Debug|x64.ActiveCfg = Debug|x64 17 | {25ECDBD4-B0A8-4040-AE0D-307E2D124384}.Debug|x64.Build.0 = Debug|x64 18 | {25ECDBD4-B0A8-4040-AE0D-307E2D124384}.Debug|x86.ActiveCfg = Debug|Win32 19 | {25ECDBD4-B0A8-4040-AE0D-307E2D124384}.Debug|x86.Build.0 = Debug|Win32 20 | {25ECDBD4-B0A8-4040-AE0D-307E2D124384}.Release|x64.ActiveCfg = Release|x64 21 | {25ECDBD4-B0A8-4040-AE0D-307E2D124384}.Release|x64.Build.0 = Release|x64 22 | {25ECDBD4-B0A8-4040-AE0D-307E2D124384}.Release|x86.ActiveCfg = Release|Win32 23 | {25ECDBD4-B0A8-4040-AE0D-307E2D124384}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /Polar Codes/CRC.cpp: -------------------------------------------------------------------------------- 1 | #include"CRC.h" 2 | 3 | void 4 | CRC::set_gen() 5 | { 6 | //default generate polynomial 7 | uint coef_one[] = {24, 23, 18, 17, 14, 11, 10, 7, 6, 5, 4, 3, 1, 0}; 8 | for (int i = 0; i < sizeof(coef_one)/sizeof(uint); ++i) 9 | posCoefOne.push_back(coef_one[i]); 10 | 11 | //real coefficient of gene: 1 1 0 ... 12 | coefOfGen.resize(R+1, 0); // all 0s 13 | for(std::size_t i = 0; i < sizeof(coef_one)/sizeof(uint); ++i) 14 | { 15 | coefOfGen[posCoefOne[i]] = 1; 16 | } 17 | } 18 | 19 | std::vector 20 | CRC::really_encode(const std::vector& info) 21 | { 22 | //R registers set to 0 23 | std::vector regist(R, 0); 24 | 25 | //m0 m1 ... mk-1 0 0 ...0 26 | std::vector code = info; 27 | for (std::size_t i = 0; i < regist.size(); ++i) 28 | code.push_back(0); 29 | 30 | //encode 31 | /* 32 | Attention: std::size_t unsigned 33 | */ 34 | for (std::size_t i = 0; i < info.size(); ++i) 35 | { 36 | uint tmp = regist[regist.size()-1] ^ code[i]; 37 | for (std::size_t j = regist.size()-1; j >= 1; --j) 38 | regist[j] = regist[j-1] ^ (tmp & coefOfGen[j]); 39 | regist[0] = tmp; 40 | } 41 | 42 | for (std::size_t i = 0; i < regist.size(); ++i) 43 | code[info.size() + i] = regist[regist.size()-1-i]; 44 | 45 | return code; 46 | } 47 | 48 | void 49 | CRC::Encode(void) 50 | { 51 | codeword = really_encode(infoBits); 52 | } 53 | 54 | bool 55 | CRC::IsCorrectCodeword(const std::vector &_cw, uint _r) 56 | { 57 | if (_cw.size() <= _r){ 58 | std::cout << "code word length is wrong in CRC!\n"; 59 | std::exit(EXIT_FAILURE); 60 | } 61 | 62 | std::vector info(_cw.size() - _r); 63 | for (std::size_t i = 0; i < info.size(); i++) 64 | info[i] = _cw[i]; 65 | 66 | std::vector new_codeword = really_encode(info); 67 | for (std::size_t i = info.size(); i < info.size()+R; i++) 68 | if (new_codeword[i] != _cw[i]) 69 | return false; 70 | return true; 71 | 72 | } 73 | 74 | CRC::CRC(const std::vector &bits, uint r, std::string gen_ploy, bool is_codeword) 75 | { 76 | R = r; 77 | if(is_codeword == true) 78 | { 79 | N = bits.size(); 80 | K = N - R; 81 | codeRate = 1.0*K/N; 82 | codeword = bits; 83 | }else 84 | { 85 | K = bits.size(); 86 | N = K + R; 87 | codeRate = 1.0*K/N; 88 | infoBits = bits; 89 | } 90 | 91 | genPloy = gen_ploy; 92 | set_gen(); 93 | } 94 | 95 | CRC::CRC(const InfoSource &src, std::string gen_ploy, uint r) 96 | { 97 | R = r; 98 | K = src.infoLen; 99 | N = K + R; 100 | codeRate = 1.0*K/N; 101 | infoBits = src.infoBits; 102 | genPloy = gen_ploy; 103 | set_gen(); 104 | } 105 | 106 | CRC::CRC(uint k, std::string gen_ploy, uint r) 107 | { 108 | R = r; 109 | K = k; 110 | N = k + r; 111 | codeRate = 1.0*K/N; 112 | genPloy = gen_ploy; 113 | set_gen(); 114 | } 115 | 116 | CRC::CRC(){} 117 | 118 | CRC::~CRC() {} -------------------------------------------------------------------------------- /Polar Codes/CRC.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/icehan/polar-codes/a89fd36b8c1c589699b825906d31291253aaa2b3/Polar Codes/CRC.h -------------------------------------------------------------------------------- /Polar Codes/Channel.cpp: -------------------------------------------------------------------------------- 1 | #include"Channel.h" 2 | #include 3 | 4 | void 5 | Channel::add_gauss() 6 | { 7 | std::random_device rd; 8 | std::mt19937 mt_gen(rd()); 9 | std::normal_distribution norm_dist(u, sigma); 10 | 11 | for (std::size_t i = 0; i < infoLen; ++i) 12 | infoOut[i] = infoIn[i] + norm_dist(mt_gen); 13 | } 14 | 15 | Channel::Channel(const std::vector& info, double _u, double _sigma2) 16 | { 17 | infoIn = info; 18 | infoLen = info.size(); 19 | infoOut.resize(infoLen); 20 | u = _u; 21 | sigma = sqrt(_sigma2); 22 | sigma2 = _sigma2; 23 | } 24 | 25 | Channel::Channel(const Modulation& modu, double _u, double _sigma2) 26 | { 27 | infoIn = modu.infoOut; 28 | infoLen = modu.infoLen; 29 | infoOut.resize(infoLen); 30 | u = _u; 31 | sigma = sqrt(_sigma2); 32 | sigma2 = _sigma2; 33 | } 34 | 35 | Channel::Channel() 36 | { 37 | infoLen = 0; 38 | u = 0.0; 39 | sigma = 1.0; 40 | sigma2 = 1.0; 41 | } 42 | 43 | Channel::~Channel() 44 | { 45 | } 46 | -------------------------------------------------------------------------------- /Polar Codes/Channel.h: -------------------------------------------------------------------------------- 1 | #ifndef CHANNEL_H 2 | #define CHANNEL_H 3 | 4 | #include"Modulation.h" 5 | #include 6 | 7 | class Channel 8 | { 9 | public: 10 | Channel(const std::vector& info, double _u=0, double _sigma2 = 1); 11 | Channel(const Modulation& modu, double _u=0, double _sigma2 = 1); 12 | Channel(); 13 | ~Channel(); 14 | 15 | void add_gauss(); 16 | 17 | public: 18 | std::vector infoIn; 19 | std::vector infoOut; 20 | std::size_t infoLen; 21 | double u; 22 | double sigma; 23 | double sigma2; 24 | }; 25 | 26 | #endif -------------------------------------------------------------------------------- /Polar Codes/InfoSource.cpp: -------------------------------------------------------------------------------- 1 | #include"InfoSource.h" 2 | #include 3 | 4 | InfoSource::InfoSource(int len) 5 | { 6 | infoLen = len; 7 | infoBits.resize(len); 8 | 9 | std::random_device rd; 10 | std::mt19937 mt_gen(rd()); 11 | std::uniform_int_distribution unif_dist(0, 1); 12 | 13 | for (int i = 0; i < len; ++i) 14 | infoBits[i] = unif_dist(mt_gen); 15 | 16 | #ifdef DEBUG 17 | for (size_t i = 0; i < 10; i++) 18 | infoBits[i] = 0; 19 | infoBits[11] = infoBits[12] = infoBits[13] = 1; 20 | #endif 21 | } 22 | 23 | InfoSource::InfoSource(uint a[], int len) 24 | { 25 | infoLen = len; 26 | infoBits.resize(len); 27 | for (int i = 0; i < len; ++i) 28 | infoBits[i] = a[i]; 29 | } 30 | 31 | InfoSource::InfoSource() 32 | { 33 | } 34 | 35 | void 36 | InfoSource::ShowInfo() 37 | { 38 | for (int i = 0; i < infoLen; ++i) 39 | std::cout << infoBits[i] << " "; 40 | } -------------------------------------------------------------------------------- /Polar Codes/InfoSource.h: -------------------------------------------------------------------------------- 1 | #ifndef INFO_SOURCE_H 2 | #define INFO_SOURCE_H 3 | 4 | #include 5 | #include 6 | #include"ice_type.h" 7 | 8 | class InfoSource 9 | { 10 | public: 11 | InfoSource(int len); 12 | InfoSource(uint a[], int len); 13 | InfoSource(); 14 | ~InfoSource() {}; 15 | void ShowInfo(); 16 | 17 | public: 18 | std::vector infoBits; 19 | int infoLen; 20 | }; 21 | 22 | #endif -------------------------------------------------------------------------------- /Polar Codes/Modulation.cpp: -------------------------------------------------------------------------------- 1 | #include"Modulation.h" 2 | 3 | void 4 | Modulation::bpsk() 5 | { 6 | //0 --> 1, 1 --> -1 7 | for(std::size_t i = 0; i < infoLen; ++i) 8 | infoOut[i] = 1 - 2*infoIn[i]; 9 | } 10 | 11 | Modulation::Modulation(const std::vector &info) 12 | { 13 | infoLen = info.size(); 14 | infoIn.resize(infoLen); 15 | infoOut.resize(infoLen); 16 | 17 | for(std::size_t i = 0; i < infoLen; ++i) 18 | infoIn[i] = info[i]; 19 | } 20 | 21 | Modulation::Modulation(const InfoSource& src) 22 | { 23 | infoLen = src.infoLen; 24 | infoIn.resize(infoLen); 25 | infoOut.resize(infoLen); 26 | 27 | for(std::size_t i = 0; i < infoLen; ++i) 28 | infoIn[i] = src.infoBits[i]; 29 | } 30 | 31 | Modulation::Modulation() 32 | { 33 | infoLen = 0; 34 | } 35 | 36 | Modulation::~Modulation() 37 | { 38 | } 39 | -------------------------------------------------------------------------------- /Polar Codes/Modulation.h: -------------------------------------------------------------------------------- 1 | #ifndef MODULATION_H 2 | #define MODULATION_H 3 | 4 | #include"ice_type.h" 5 | #include"InfoSource.h" 6 | #include 7 | 8 | class Modulation 9 | { 10 | public: 11 | Modulation(const std::vector &info); // uint -> int 12 | Modulation(const InfoSource& src); 13 | Modulation(); 14 | ~Modulation(); 15 | void bpsk(); 16 | public: 17 | std::vector infoOut; //modulated 18 | std::vector infoIn; 19 | std::size_t infoLen; 20 | }; 21 | 22 | #endif -------------------------------------------------------------------------------- /Polar Codes/Polar Codes.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {25ECDBD4-B0A8-4040-AE0D-307E2D124384} 23 | Win32Proj 24 | PolarCodes 25 | 8.1 26 | 27 | 28 | 29 | Application 30 | true 31 | v140 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v140 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v140 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v140 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | D:\Program Files\MATLAB\R2014a\extern\include\win32;D:\Program Files\MATLAB\R2014a\extern\include;$(IncludePath) 75 | D:\Program Files\MATLAB\R2014a\extern\lib\win32\microsoft;D:\Program Files\MATLAB\R2014a\extern\lib\win32;$(LibraryPath) 76 | $(ReferencePath) 77 | 78 | 79 | true 80 | 81 | 82 | false 83 | 84 | 85 | false 86 | 87 | 88 | 89 | 90 | 91 | Level3 92 | Disabled 93 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 94 | true 95 | %(AdditionalIncludeDirectories) 96 | true 97 | 98 | 99 | Console 100 | true 101 | %(AdditionalLibraryDirectories) 102 | libmx.lib;libmat.lib;libmex.lib;libeng.lib;%(AdditionalDependencies) 103 | 104 | 105 | 106 | 107 | 108 | 109 | Level3 110 | Disabled 111 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 112 | true 113 | 114 | 115 | Console 116 | true 117 | 118 | 119 | 120 | 121 | Level3 122 | 123 | 124 | MaxSpeed 125 | true 126 | true 127 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 128 | true 129 | 130 | 131 | Console 132 | true 133 | true 134 | true 135 | 136 | 137 | 138 | 139 | Level3 140 | 141 | 142 | MaxSpeed 143 | true 144 | true 145 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 146 | true 147 | 148 | 149 | Console 150 | true 151 | true 152 | true 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /Polar Codes/Polar Codes.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | 头文件 38 | 39 | 40 | 头文件 41 | 42 | 43 | 头文件 44 | 45 | 46 | 头文件 47 | 48 | 49 | 50 | 51 | 源文件 52 | 53 | 54 | 源文件 55 | 56 | 57 | 源文件 58 | 59 | 60 | 源文件 61 | 62 | 63 | 源文件 64 | 65 | 66 | 源文件 67 | 68 | 69 | 源文件 70 | 71 | 72 | 源文件 73 | 74 | 75 | 源文件 76 | 77 | 78 | 源文件 79 | 80 | 81 | -------------------------------------------------------------------------------- /Polar Codes/Polar.cpp: -------------------------------------------------------------------------------- 1 | #include"Polar.h" 2 | #include 3 | 4 | Polar::Polar(){} 5 | 6 | Polar::~Polar(){} 7 | 8 | uint* 9 | Polar::universal_encode(const uint* data, uint length, uint *dst) 10 | { 11 | if(NULL == data || NULL == dst || length == 0) 12 | return NULL; 13 | 14 | for (int i = 0; i < length; i++) 15 | dst[i] = data[i]; 16 | uint M = log(length*1.0)/log(2.0); 17 | for (uint i = 0; i < M; i++) 18 | { 19 | uint block_len = pow(2.0, i+1.0); 20 | uint jMax = pow(2.0, M - i - 1.0); 21 | for (uint j = 0; j < jMax; j++) 22 | { 23 | uint kLen = pow(2.0, i*1.0), sep = kLen; 24 | uint kBeg = j*block_len, kEnd = kBeg + kLen; 25 | for (uint k = kBeg; k < kEnd; k++) 26 | dst[k] = dst[k] ^ dst[k + sep]; 27 | } 28 | } 29 | return dst; 30 | } 31 | 32 | void 33 | Polar::set_pattern(std::size_t _K) 34 | { 35 | const uint *pt = get_point_of_pattern(_K*2); 36 | if (pt == NULL) 37 | { 38 | std::cout << "Only pattern 4/128/512 served!\n"; 39 | exit(EXIT_FAILURE); 40 | } 41 | 42 | //set_pattern 43 | pattern.resize(_K*2); 44 | for (std::size_t i = 0; i < _K*2; ++i) 45 | pattern[i] = pt[i]; 46 | } 47 | 48 | const uint* 49 | Polar::get_point_of_pattern(std::size_t _N) 50 | { 51 | const uint *pt = NULL; 52 | 53 | if (_N == 1024) 54 | pt = PATTERN1024; 55 | else if (_N == 256) 56 | pt = PATTERN256; 57 | else if (_N == 8) 58 | pt = PATTERN8; 59 | else if (_N == 4) 60 | pt = PATTERN4; 61 | 62 | return pt; 63 | } -------------------------------------------------------------------------------- /Polar Codes/Polar.h: -------------------------------------------------------------------------------- 1 | #ifndef POLAR_H 2 | #define POLAR_H 3 | 4 | #include"ice_type.h" 5 | #include 6 | 7 | const uint PATTERN4[] = {0,0,1,1}; 8 | const uint PATTERN8[] = {0,0,0,1,0,1,1,1}; 9 | const uint PATTERN16[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; 10 | const uint PATTERN256[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,1,1,1,0,0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1,0,1,1,1,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; 11 | const uint PATTERN1024[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,0,0,0,1,0,1,1,1,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,1,1,0,0,0,0,0,0,0,1,0,0,0,1,0,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,0,1,1,1,0,1,1,1,1,1,1,1,0,0,0,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,0,0,0,1,0,1,1,1,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; 12 | 13 | class Polar 14 | { 15 | public: 16 | Polar(); 17 | ~Polar(); 18 | void set_pattern(std::size_t _K); 19 | const uint *get_point_of_pattern(std::size_t _N); 20 | protected: 21 | uint* universal_encode(const uint* data, uint length, uint *dst); 22 | 23 | public: 24 | std::size_t K; 25 | std::size_t N; 26 | std::size_t R; //N-K 27 | std::size_t log2N; // log2(N) 28 | double codeRate; 29 | 30 | std::vector pattern; 31 | 32 | }; 33 | 34 | #endif -------------------------------------------------------------------------------- /Polar Codes/Polar_decoder.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/icehan/polar-codes/a89fd36b8c1c589699b825906d31291253aaa2b3/Polar Codes/Polar_decoder.cpp -------------------------------------------------------------------------------- /Polar Codes/Polar_decoder.h: -------------------------------------------------------------------------------- 1 | #ifndef POLAR_DECODER_H 2 | #define POLAR_DECODER_H 3 | 4 | #include"Polar.h" 5 | #include"Channel.h" 6 | #include 7 | #include 8 | #include 9 | 10 | class Polar_decoder : public Polar 11 | { 12 | public: 13 | Polar_decoder(const std::vector &_rec_codeword, double _code_rate = 0.5, double _sigma2 = 1.0); 14 | Polar_decoder(const Channel &_chan, double _code_rate = 0.5); 15 | Polar_decoder(); 16 | ~Polar_decoder(); 17 | void Decode(std::string _method, uint _search_width = 1, uint _CRC_para_r = 24); // _method = SC, SCL, CA-SCL 18 | 19 | private: 20 | //------------------------- CA-SCL & SCL ------------------------------- 21 | void decode_CASCL(uint _search_width = 1, uint _CRC_para_r = 24); 22 | void find_best_word_passing_CRC(uint _L); 23 | void decode_SCL(uint _search_width); 24 | void find_best_word(uint _L); 25 | 26 | //------------------------ High Level function -------------------------- 27 | void update_BAT_List(uint global_phase, uint _L); 28 | void update_LLR_List(uint global_phase, uint _L); 29 | void extendPath_UnfrozenBit(uint global_phase, uint _L); 30 | void extendPath_FrozenBit(uint global_phase, uint _L); 31 | 32 | //------------------------ Middle level function ------------------------- 33 | void populate_PathAcitveOrNot_KillInactive(uint _L); 34 | void populate_PathMetricsOfForks_ForkActiveOrNot(uint _L); 35 | void assignInitPath(); 36 | void killPath(uint path_ind_killed); 37 | uint clonePath(uint path_ind_cloned, uint global_phase); 38 | 39 | //----------------------- Basic function --------------------------------- 40 | void compute_channel_llr(double *_y_in, uint _length, double *_z_out); // layer = 0, _length = N 41 | void compute_inner_llr(double *_llr_in, uint _length, double *_llr_out, char _node_type, BOOL *_bat_arr); // layer > 0 42 | double f_blue(double L1, double L2); 43 | double g_red(double L1, double L2, BOOL u); 44 | friend int comparePMF(const void* pmf1, const void* pmf2); // increasing order 45 | friend int comparePM(const void* pm1, const void* pm2); 46 | 47 | //----------------------- data struct of SCL ------------------------------ 48 | void init_data_struct_of_SCL(uint _L); 49 | void set_data_struct_of_SCL(uint _L); 50 | void free_data_struct_of_SCL(uint _L); 51 | void show_data_struct_of_SCL(uint _L, uint _cur_phase); 52 | void show_fixed_struct_of_SCL(uint _L); 53 | void show_array_struct_of_SCL(uint _L); 54 | void show_code_struct_of_SCL(uint _L, uint _cur_phase); 55 | 56 | public: 57 | double sigma2; 58 | BOOL decode_correct; 59 | std::vector recCodeword; //after gaussin channel, received code 60 | std::vector deCodeword; //codeword decoded by algorithm using recCodeword 61 | std::vector deInfoBit; 62 | private: 63 | //************** fixed *************************************** 64 | char **NodeType; //N*(M+1) mat of type of node, red/blue 65 | uint *LayerBlockLen; //M+1 array of each layer 66 | uint *LayerRenewed; //M+1 array, when goes to i, which layer need to be renewed 67 | 68 | //************** array *************************************** 69 | double ***LLR; //L*(M+1) mat of pointer of LLR 70 | BOOL ***BAT; //L*(M+1) mat of pointer of u, bit array of assisting 71 | int **PathIndexToArrayIndex; // L*(M+1) 72 | uint **ArrayReferenceCount; // L*(M+1) 73 | std::vector> ArrayInactive; //(M+1)*(0:L) 74 | 75 | //*************** code *************************************** 76 | uint **EstimatedWord; //L*N mat of estimated codeword 77 | St_PMF *PathMetricsOfForks; //2*L array of extended PM 78 | St_PMF *copy_of_PMF; 79 | double *PathMetrics; //L array of PM 80 | BOOL **ForkActiveOrNot; //2*L array of bool, keep or not 81 | BOOL *PathActiveOrNot; //L array 82 | std::stack PathInactive; //0:L 83 | }; 84 | 85 | #endif -------------------------------------------------------------------------------- /Polar Codes/Polar_encoder.cpp: -------------------------------------------------------------------------------- 1 | #include"Polar_encoder.h" 2 | 3 | 4 | void 5 | Polar_encoder::Encode() 6 | { 7 | universal_encode(infoBitsAddPattern.data(), N, codeword.data()); 8 | /* 9 | codeword = infoBitsAddPattern; 10 | for (std::size_t i = 0; i < log2N; i++) 11 | { 12 | uint block_len = pow(2.0, i+1.0); 13 | uint jMax = pow(2.0, log2N - i - 1.0); 14 | for (uint j = 0; j < jMax; j++) 15 | { 16 | uint kLen = pow(2.0, i*1.0), sep = kLen; 17 | uint kBeg = j*block_len, kEnd = kBeg + kLen; 18 | for (uint k = kBeg; k < kEnd; k++) 19 | codeword[k] = codeword[k] ^ codeword[k + sep]; //CODEWORD must be continuing updating 20 | } 21 | } 22 | */ 23 | } 24 | 25 | Polar_encoder::Polar_encoder(const std::vector &bits, double code_rate) 26 | { 27 | K = bits.size(); 28 | codeRate = code_rate; 29 | N = K/code_rate; 30 | R = N - K; 31 | log2N = log(N*1.0)/log(2.0); 32 | infoBits = bits; 33 | codeword.resize(N); 34 | infoBitsAddPattern = set_info_using_pattern(bits); 35 | set_pattern(bits.size()); 36 | } 37 | 38 | Polar_encoder::Polar_encoder(const InfoSource &src, double code_rate) 39 | { 40 | K = src.infoLen; 41 | codeRate = code_rate; 42 | N = K/code_rate; 43 | R = N - K; 44 | log2N = log(N*1.0)/log(2.0); 45 | infoBits = src.infoBits; 46 | codeword.resize(N); 47 | infoBitsAddPattern = set_info_using_pattern(infoBits); 48 | set_pattern(src.infoLen); 49 | } 50 | 51 | Polar_encoder::~Polar_encoder(){} 52 | 53 | //private 54 | std::vector 55 | Polar_encoder::set_info_using_pattern(const std::vector& info) 56 | { 57 | const uint *pt = NULL; 58 | if (info.size() == 512) 59 | pt = PATTERN1024; 60 | else if (info.size() == 128) 61 | pt = PATTERN256; 62 | else if (info.size() == 4) 63 | pt = PATTERN8; 64 | else if (info.size() == 2) 65 | pt = PATTERN4; 66 | else 67 | { 68 | std::cout << "Only pattern 4/128/512 served!\n"; 69 | exit(EXIT_FAILURE); 70 | } 71 | 72 | std::vector ret(info.size()*2, 0); 73 | for (std::size_t i = 0, k = 0; (i> log2N-1-2*i ); 87 | 88 | return pos; 89 | } 90 | */ -------------------------------------------------------------------------------- /Polar Codes/Polar_encoder.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/icehan/polar-codes/a89fd36b8c1c589699b825906d31291253aaa2b3/Polar Codes/Polar_encoder.h -------------------------------------------------------------------------------- /Polar Codes/allheader.h: -------------------------------------------------------------------------------- 1 | #ifndef ALLHEADER_H 2 | #define ALLHEADER_H 3 | 4 | #include "ice_type.h" 5 | #include "InfoSource.h" 6 | #include "CRC.h" 7 | #include "Polar.h" 8 | #include "Polar_encoder.h" 9 | #include "Polar_decoder.h" 10 | #include "Modulation.h" 11 | #include "Channel.h" 12 | #include "ice_process.h" 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #endif -------------------------------------------------------------------------------- /Polar Codes/ice_process.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/icehan/polar-codes/a89fd36b8c1c589699b825906d31291253aaa2b3/Polar Codes/ice_process.cpp -------------------------------------------------------------------------------- /Polar Codes/ice_process.h: -------------------------------------------------------------------------------- 1 | #ifndef ICE_PROCESS_H 2 | #define ICE_PROCESS_H 3 | 4 | #include"ice_type.h" 5 | #include 6 | 7 | //multi-thread version 8 | void run_in_a_ebno(const St_CodeInfo& _st_code_info, const uint _counts, 9 | const double _ebno, long double &__FER); 10 | BOOL run_a_codeword(const St_CodeInfo& _st_code_info, const double _sigma2); 11 | 12 | 13 | #ifndef LJQ_COM 14 | void plot_curve(const St_CodeInfo& _st_code_info, const uint _snr_cnt, 15 | const double _ebno[], const long double _FER[]); 16 | #endif 17 | 18 | void save_simulation_result(const St_CodeInfo& _st_code_info, 19 | const uint _snr_cnt, const uint _Counts_Of_Each_Ebno[], 20 | const double _ebno[], const long double _FER[], 21 | const time_t &_start, const time_t &_end); 22 | 23 | void save_run_time(std::ofstream& fname, const time_t &_start, const time_t &_end); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /Polar Codes/ice_type.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/icehan/polar-codes/a89fd36b8c1c589699b825906d31291253aaa2b3/Polar Codes/ice_type.cpp -------------------------------------------------------------------------------- /Polar Codes/ice_type.h: -------------------------------------------------------------------------------- 1 | #ifndef ICE_TYPE_H 2 | 3 | #define ICE_TYPE_H 4 | 5 | #include 6 | 7 | #define ADD_CRC 8 | //#define LJQ_COM 9 | //#define DEBUG 10 | 11 | typedef unsigned int uint; 12 | typedef unsigned char uchar; 13 | typedef unsigned int BOOL; 14 | 15 | typedef struct st_path_metric_fork { 16 | uint path; 17 | BOOL u_bit; 18 | double metric; 19 | }St_PMF, *St_PMF_Ptr; 20 | 21 | typedef struct st_path_metric { 22 | uint path; 23 | double metric; 24 | }St_PM, *St_PM_Ptr; 25 | 26 | typedef struct st_code_info { 27 | std::string method_of_decoding; 28 | uint search_width; 29 | uint code_len; 30 | }St_CodeInfo, *St_CodeInfo_Ptr; 31 | 32 | #define TRUE 1 33 | #define FALSE 0 34 | #define INF -999 35 | #define SPACE_WARNING(value) \ 36 | {\ 37 | if (value == NULL){\ 38 | std::cout << "space not enough!\n";\ 39 | std::exit(EXIT_FAILURE);\ 40 | }\ 41 | } 42 | #define FREE_SPACE(value)\ 43 | {\ 44 | if(NULL != value){\ 45 | free(value);\ 46 | }else{\ 47 | std::cout << "can't free null space!\n";\ 48 | std::exit(EXIT_FAILURE);\ 49 | }\ 50 | } 51 | 52 | std::string int2str(const uint &double_temp); 53 | std::string double2str(const long double &int_temp); 54 | std::string ice_cur_time(); 55 | 56 | 57 | #endif -------------------------------------------------------------------------------- /Polar Codes/main.cpp: -------------------------------------------------------------------------------- 1 | #include"allheader.h" 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main() 7 | { 8 | //L=1 9 | uint Counts_Of_Each_Ebno[] = { 1000, 1000, 1000, 5000, 5000, 10000, 30000, 50000, 500000 }; 10 | const double Eb_N0[] = { 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5}; 11 | /* 12 | //L=2 13 | uint Counts_Of_Each_Ebno[] = { 1000, 1000, 5000, 10000, 50000, 100000, 500000}; 14 | const double Eb_N0[] = { 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3}; 15 | //L=4 16 | uint Counts_Of_Each_Ebno[] = { 1000, 1000, 5000, 5000, 10000, 50000, 200000 }; 17 | const double Eb_N0[] = { 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5 }; 18 | //L=8 19 | uint Counts_Of_Each_Ebno[] = { 1000, 1000, 5000, 10000, 50000, 200000 }; 20 | const double Eb_N0[] = { 1.0, 1.25, 1.5, 1.75, 2.0, 2.25}; 21 | //L=16 22 | uint Counts_Of_Each_Ebno[] = { 1000, 2000, 5000, 20000, 100000, 500000 }; 23 | const double Eb_N0[] = { 1.0, 1.25, 1.5, 1.75, 2.0, 2.25 }; 24 | //L=32 25 | uint Counts_Of_Each_Ebno[] = { 1000, 1000, 2000, 10000, 50000, 300000 }; 26 | const double Eb_N0[] = { 0.75, 1.0, 1.25, 1.5, 1.75, 2.0}; 27 | */ 28 | long double FER[sizeof(Eb_N0)/sizeof(double)] = {0}; 29 | 30 | St_CodeInfo st_code_info; 31 | st_code_info.method_of_decoding = "CA-SCL"; 32 | st_code_info.search_width = 1; 33 | st_code_info.code_len = 1024; 34 | 35 | //simulation 36 | time_t t_start = time(NULL); 37 | for (int i = 0; i < sizeof(Eb_N0) / sizeof(double); i++) // loop for every Eb/N0 38 | run_in_a_ebno(st_code_info, Counts_Of_Each_Ebno[i], Eb_N0[i], FER[i]); 39 | time_t t_end = time(NULL); 40 | 41 | //write results into file 42 | save_simulation_result(st_code_info, sizeof(Eb_N0) / sizeof(double), Counts_Of_Each_Ebno, Eb_N0, FER, t_start, t_end); 43 | 44 | #ifndef LJQ_COM 45 | //plot curve using matlab 46 | plot_curve(st_code_info, sizeof(Eb_N0) / sizeof(double), Eb_N0, FER); 47 | #endif 48 | 49 | return 0; 50 | } 51 | 52 | /* 53 | int main() 54 | { 55 | #pragma omp parallel for 56 | for (int i = 0; i < 1; i++) 57 | { 58 | cout << i << "\n"; 59 | InfoSource src(128 - 24); // 2 4 128 512 60 | 61 | CRC crc(src); 62 | crc.Encode(); 63 | 64 | Polar_encoder polenc(crc.codeword); 65 | polenc.Encode(); 66 | 67 | Modulation modu(polenc.codeword); 68 | modu.bpsk(); 69 | 70 | // Channel chan(modu.infoOut, 0, 0.05); 71 | // chan.add_gauss(); 72 | 73 | Polar_decoder poldec(modu.infoOut); 74 | poldec.Decode("CA-SCL", 4); 75 | 76 | #ifdef DEBUG 77 | cout << "info + crc:\n"; 78 | for (size_t i = 0; i < crc.N; i++) 79 | cout << crc.codeword[i] << " "; 80 | cout << endl; 81 | #endif 82 | } 83 | return 0; 84 | } 85 | */ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Polar-Codes 2 | 极化码是新近发现的理论上能达到香农限的唯一一种信道编码 3 | 0. 编码器采用蝶形图而非矩阵乘方法,相应模块代码在Polar_encoder.h/Polar_encoder.cpp; 4 | 1. 常用的译码算法有SC, SCL, CA-SCL,aCA-SCL译码算法,相应模块代码在Polar_decoder.h/Polar_decoder.cpp; 5 | 2. 常用的构造码字的方法有蒙特卡洛仿真、高斯近似等方法,相应模块代码在Polar_construction.h/Polar_construction.cpp; 6 | 3. 信道使用高斯信道,相应模块代码在Channel.h/Channel.cpp; 7 | 4. 调制方式为BPSK调制,相应模块代码在Modulation.h/Modulation.cpp; 8 | 5. 上层统计误码率、误比特率模块代码在ice_process.h/ice_process.cpp; 9 | 6. (1) main_TestConstruction.cpp 测试几种不同的构造方法; 10 | (2) main_TestDecodeSpeed.cpp 测试译码速度; 11 | (3) main_TestPerformaceCurve.CPP 统计译码曲线,可调用Matlab绘图接口显示误码率曲线。 12 | --------------------------------------------------------------------------------