![]() |
IA_CoMP
Interference Alignment and Coordinated Multipoint
|
00001 // 00002 // Copyright 2011-2012 KTH Royal Institute of Technology 00003 // 00004 // This program is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 00017 00018 00019 #include <fstream> 00020 #include <uhd/utils/thread_priority.hpp> 00021 #include <uhd/utils/safe_main.hpp> 00022 #include <uhd/usrp/multi_usrp.hpp> 00023 #include <boost/program_options.hpp> 00024 #include <boost/format.hpp> 00025 #include <iostream> 00026 #include <uhd/types/clock_config.hpp> 00027 #include <itpp/itbase.h> 00028 #include <itpp/base/itfile.h> 00029 #include <itpp/stat/misc_stat.h> 00030 #include <itpp/itcomm.h> 00031 #include <four_multi/AMC.hpp> 00032 #include <four_multi/modem_OFDM1.hpp> 00033 #include <itpp/stat/misc_stat.h> 00034 #include <iostream> 00035 00036 namespace po = boost::program_options; 00037 using namespace itpp; 00038 using namespace std; 00039 00040 00041 00042 00043 int UHD_SAFE_MAIN(int argc, char *argv[]){ 00044 00045 00046 int s, stream_ix, codec_ix, modulation_order, frame_ix, scenario; 00047 bvec input,transmitted, transmitted1, transmitted2; 00048 cvec symbols, symbols_in; 00049 ivec known_pos_all; 00050 ivec reorder_all[10]; 00051 //bool use_old_rand; 00052 00053 00054 //use_old_rand=true; 00055 string dir; 00056 00057 if (!(uhd::set_thread_priority_safe(1,true))) { 00058 std::cout << "Problem setting thread priority" << std::endl; 00059 return 1; 00060 }; 00061 00062 //variables to be set by po 00063 std::vector<string> IP_addresses; 00064 00065 // Internal variables // PZ 00066 uhd::clock_config_t my_clock_config; //PZ 00067 00068 //setup the program options 00069 po::options_description desc("Allowed options"); 00070 desc.add_options() 00071 ("help", "help message") 00072 ("fi", po::value<int>(&s)->default_value(0), "file index") 00073 ("s_ix", po::value<int>(&stream_ix)->default_value(0), "stream index") 00074 ("dir", po::value<string>(&dir) 00075 ->default_value("/usr/local/meas_data/"), "directory") 00076 ("c_ix", po::value<int>(&codec_ix)->default_value(3), "codec index") 00077 ("m_o", po::value<int>(&modulation_order)->default_value(16), 00078 "modulation order") 00079 ("f_ix", po::value<int>(&frame_ix)->default_value(1), 00080 "frame_index") 00081 ("sc", po::value<int>(&scenario)->default_value(1),"scenario") 00082 ; 00083 00084 po::variables_map vm; 00085 po::store(po::parse_command_line(argc, argv, desc), vm); 00086 po::notify(vm); 00087 00088 if (vm.count("help")){ 00089 std::cout << boost::format("Ping pong %s") % desc << std::endl; 00090 return ~0; 00091 } 00092 00093 00094 00095 AMC amc; 00096 OFDM1 ai; 00097 int num_streams=3; 00098 int num_symbols=21; 00099 int num_payload_symbols_before_pilots=10; 00100 int num_payload_symbols_after_pilots=10; 00101 int num_antennas_in_system=6; 00102 00103 00104 known_pos_all.set_length(num_streams); 00105 for (int i1=0;i1<num_streams;i1++) { 00106 reorder_all[i1].set_length(num_symbols); 00107 known_pos_all(i1)=num_payload_symbols_before_pilots+i1; 00108 for (int i2=0;i2<num_payload_symbols_before_pilots;i2++) { 00109 (reorder_all[i1])(i2)=i2; 00110 }; 00111 reorder_all[i1](num_payload_symbols_before_pilots)=num_payload_symbols_before_pilots+i1; 00112 for (int i2=0;i2<num_payload_symbols_after_pilots;i2++) { 00113 (reorder_all[i1])(i2+num_payload_symbols_before_pilots+1)= 00114 num_payload_symbols_before_pilots+num_streams+num_antennas_in_system+i2; 00115 }; 00116 }; 00117 00118 00119 #if 1 00120 itpp::it_file d1; 00121 d1.open("symbols_in.it"); 00122 d1 >> Name("symbolsc") >> symbols_in; 00123 d1.close(); 00124 #endif 00125 00126 00127 // Estimate noise variance in symbols_in 00128 QAM modulation; 00129 modulation.set_M(modulation_order); 00130 double noise_variance_norm=0; 00131 cvec symbol(1), closest_constellation_point(1); 00132 for (int i1=0;i1<symbols_in.length();i1++) { 00133 symbol=symbols_in(i1); 00134 closest_constellation_point=modulation.modulate_bits( 00135 modulation.demodulate_bits(symbol)); 00136 00137 noise_variance_norm+=sum(sqr(symbol-closest_constellation_point)); 00138 }; 00139 noise_variance_norm/=symbols_in.length(); 00140 00141 00142 00143 ivec known_pos(1); 00144 known_pos(0)=10; 00145 ai.init(false,false,12,21,known_pos,reorder_all[0]); 00146 00147 00148 int word_length=38*5*2*4; 00149 amc.init(word_length,true); 00150 input.set_length(amc.codec_message_size(amc.no_of_codecs()-1)); 00151 transmitted.set_length(word_length); 00152 bvec transmitted_hat, message_hat; 00153 transmitted_hat.set_length(word_length); 00154 message_hat.set_length(amc.codec_message_size(amc.no_of_codecs()-1)); 00155 symbols.set_length(38*20); 00156 int l=amc.codec_message_size(codec_ix); 00157 //amc.skip_symbols=0; 00158 00159 00160 #if 1 00161 00162 RNG_reset(100+10000*stream_ix+s); 00163 input.set_subvector(0,randb(l)); 00164 amc.modulate(modulation_order,codec_ix,input.mid(0,l), 00165 transmitted,symbols,0) ; 00166 00167 transmitted1=transmitted; 00168 #endif 00169 00170 00171 #if 0 00172 stringstream filename; 00173 00174 filename << "Vbig" << frame_ix-1 << "_" << scenario << ".it"; 00175 itpp::it_file d2; 00176 d2.open(filename.str()); 00177 00178 00179 stringstream variable_name; 00180 variable_name.str(""); variable_name.clear(); 00181 variable_name << "transmitted" << stream_ix << "_a"; 00182 d2 >> itpp::Name(variable_name.str()) >> transmitted; 00183 d2>> itpp::Name("symbol_interleave_matrix") >> ai.symbol_interleave_matrix; 00184 d2>> itpp::Name("symbol_de_interleave_matrix") >> 00185 ai.symbol_de_interleave_matrix; 00186 00187 00188 variable_name.str(""); variable_name.clear(); 00189 variable_name << "input" << stream_ix << "_a"; 00190 d2 >> itpp::Name(variable_name.str()) >> input; 00191 00192 #endif 00193 00194 00195 00196 int n; 00197 n=word_length/log2( modulation_order); 00198 ai.de_interleave_symbols(symbols_in,stream_ix+frame_ix); 00199 00200 00201 amc.demodulate(symbols_in.mid(0,n), 00202 noise_variance_norm, 00203 modulation_order,codec_ix,message_hat,transmitted_hat); 00204 00205 00206 00207 BERC berc; 00208 vec BERraw(2), BER(2); 00209 berc.clear(); 00210 berc.count(transmitted,transmitted_hat); 00211 BERraw(0)=berc.get_errorrate(); 00212 berc.clear(); 00213 berc.count(input,message_hat); 00214 BER(0)=berc.get_errorrate(); 00215 00216 00217 00218 if (modulation_order>15) { 00219 00220 #if 1 00221 RNG_reset(110+10000*stream_ix+s); 00222 input.set_subvector(0,randb(l)); 00223 amc.modulate(modulation_order,codec_ix,input.mid(0,l), 00224 transmitted,symbols,word_length/(log2(modulation_order))); 00225 transmitted2=transmitted; 00226 00227 00228 00229 #endif 00230 00231 #if 0 00232 variable_name.str(""); variable_name.clear(); 00233 variable_name << "transmitted" << stream_ix << "_b"; 00234 d2 >> itpp::Name(variable_name.str()) >> transmitted; 00235 variable_name.str(""); variable_name.clear(); 00236 variable_name << "input" << stream_ix << "_b"; 00237 d2 >> itpp::Name(variable_name.str()) >> input; 00238 #endif 00239 00240 amc.demodulate(symbols_in.mid(n,n), 00241 noise_variance_norm, 00242 modulation_order,codec_ix,message_hat,transmitted_hat); 00243 00244 berc.clear(); 00245 berc.count(transmitted,transmitted_hat); 00246 BERraw(1)=berc.get_errorrate(); 00247 berc.clear(); 00248 berc.count(input,message_hat); 00249 BER(1)=berc.get_errorrate(); 00250 00251 00252 }; 00253 00254 #if 0 00255 00256 variable_name.str(""); variable_name.clear(); 00257 variable_name << "symbols" << stream_ix; 00258 d2 >> itpp::Name(variable_name.str()) >> symbols; 00259 #endif 00260 ai.interleave_symbols(symbols,stream_ix+frame_ix); 00261 00262 int shift_transmit_signal_samples=2000; 00263 cvec waveform_tx_temp(10000); 00264 double rms_power; 00265 00266 00267 ai.modulate(waveform_tx_temp,symbols,shift_transmit_signal_samples, 00268 rms_power,ones_c(ai.length_ix_all)); 00269 00270 float scaling_tx_signal=70000; 00271 waveform_tx_temp=scaling_tx_signal*waveform_tx_temp; 00272 00273 d1.open("symbols_true.it"); 00274 d1<< itpp::Name("symbols_true") << symbols; 00275 d1<< itpp::Name("BERraw") << BERraw; 00276 d1<< itpp::Name("BER") << BER; 00277 d1<< itpp::Name("transmitted1") << transmitted1; 00278 d1<< itpp::Name("transmitted2") << transmitted2; 00279 d1<< itpp::Name("waveform_tx_temp") << waveform_tx_temp; 00280 d1.close(); 00281 00282 return 0; 00283 00284 } 00285 //08-59090500