![]() |
four_multi
Multi-Antenna,Multi-Node,Multi-Band,Multi-Cell
|
00001 // Copyright 2011-2013, Nima Najari Moghadam and Per Zetterberg 00002 // KTH Royal Institute of Technology 00003 // 00004 // 00005 // This program is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 00019 #include <itpp/itcomm.h> 00020 #include "LDPC1.hpp" 00021 00022 00023 00024 00025 void LDPC1::init(double chan_code_rate, int word_size, int seed, bool load_from_file, string filename) { 00026 00027 // Use chan_code_rates: 1/4, 1/2, 3/4, 5/6 00028 00029 d_chan_code_rate=chan_code_rate; 00030 d_seed=seed; 00031 00032 //Nvar = int(msg_len'gth/chan_code_rate); 00033 00034 Nvar=word_size; 00035 k=int(Nvar*chan_code_rate); 00036 00037 00038 //std::cout << "Nvar=" << Nvar << endl; 00039 int Wc = 3; 00040 int Wr = int(Wc/(1-chan_code_rate)); 00041 00042 //std::cout << "R=" << 1-((float) Wc)/((float) Wr) << std::endl; 00043 //std::cout << "Wr=" << Wr << std::endl; 00044 //std::cout << "word_size=" << word_size << endl; 00045 00046 //R=1-(Wc/Wr) <==> (Wc/Wr)=1-R <==> Wr/Wc=1/(1-R) <==> Wr = Wc/(1-R) 00047 00048 00049 if (load_from_file) { 00050 Code.load_code(filename.c_str(),&G); 00051 } 00052 else 00053 { 00054 std::cout << "Generate code start \n"; 00055 RNG_reset(d_seed); 00056 H.generate(Nvar, Wc, Wr,"rand","500 10"); 00057 G.construct(&H); 00058 std::cout << "Generate code stop \n"; 00059 Code.set_code(&H,&G); 00060 Code.set_exit_conditions(10); 00061 Code.save_code(filename.c_str()); 00062 }; 00063 00064 00065 RNG_reset(d_seed); 00066 d_interleaver.set_interleaver_depth(Nvar); 00067 d_interleaver.randomize_interleaver_sequence(); 00068 00069 ivec s=d_interleaver.get_interleaver_sequence(); 00070 00071 code_word1.set_length(Nvar); 00072 code_word2.set_length(Nvar); 00073 00074 00075 } 00076 00077 00078 void LDPC1::chan_encode(bvec message, bvec &code_word) { 00079 00080 Code.encode(message,code_word); 00081 code_word1=to_vec(code_word); 00082 d_interleaver.interleave(code_word1,code_word2); 00083 code_word=to_bvec(code_word2); 00084 00085 } 00086 00087 void LDPC1::chan_decode(vec &soft_input,bvec &message_hat){ 00088 00089 bvec message_hat_temp; 00090 00091 message_hat_temp.set_length(k); 00092 d_interleaver.deinterleave(soft_input,code_word1); 00093 Code.decode(code_word1,message_hat_temp); 00094 message_hat.set_subvector(0,message_hat_temp); 00095 00096 00097 };