IA_CoMP
Interference Alignment and Coordinated Multipoint
IA1/IA1_simulate.cpp
00001 //
00002 // Copyright 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/stat/misc_stat.h>
00029 #include "IA1_node.hpp"
00030 #include <iostream>
00031 
00032 
00033 namespace po = boost::program_options;
00034 using namespace itpp;
00035 using namespace std;
00036 
00037 
00040 int UHD_SAFE_MAIN(int argc, char *argv[]){
00041     
00042  
00043     int s=69160;
00044 
00045     std::vector<four_multi_node*> all_my_IA_nodes;
00046     std::vector<four_multi_node*> all_my_CoMP_nodes;
00047     std::vector<four_multi_node*> all_my_MIMO_nodes;
00048 
00049     block_fading ch_model;
00050     string dir;
00051   
00052     /*
00053     if (!(uhd::set_thread_priority_safe(1,true))) {
00054       std::cout << "Problem setting thread priority" << std::endl;
00055       return 1;
00056     };
00057     */
00058 
00059     //variables to be set by po
00060     std::vector<string> IP_addresses;
00061     
00062 
00063     // Internal variables // PZ
00064     uhd::clock_config_t my_clock_config; //PZ
00065 
00066     //setup the program options
00067     po::options_description desc("Allowed options");
00068     desc.add_options()
00069       ("help", "help message")
00070       ("s", po::value<int>(&s)->default_value(0), "file index")
00071       ("dir", po::value<string>(&dir)
00072        ->default_value("/usr/local/meas_data/"), "directory with measurement files")
00073     ;
00074 
00075     po::variables_map vm;
00076     po::store(po::parse_command_line(argc, argv, desc), vm);
00077     po::notify(vm);
00078     
00079     if (vm.count("help")){
00080         std::cout << boost::format("Ping pong  %s") % desc << std::endl;
00081         return ~0;
00082     }
00083 
00084     int use_data_from_file;
00085     if (s==0) {
00086       use_data_from_file=0;
00087     } else {
00088       use_data_from_file=1;
00089     };
00090 
00091     
00092     std::stringstream s_s;
00093     s_s << s;
00094 
00095     int scenario;
00096     scenario=1;
00097     IA1_node node0_IA(2,0,0,0,0, 2490e6,false,IP_addresses,true,
00098                       6+use_data_from_file*54,s,true,scenario); // BS0
00099     IA1_node node1_IA(2,0,0,0,1, 2490e6,false,IP_addresses,true,
00100                    6+use_data_from_file*54,s,true,scenario); // BS1
00101     IA1_node node2_IA(2,0,0,0,2, 2490e6,false,IP_addresses,true,
00102                    6*1+use_data_from_file*54,s,true,scenario); // BS2
00103     IA1_node node3_IA(2,0,0,0,3, 2490e6,false,IP_addresses,true,
00104                    6*1+use_data_from_file*54,s,true,scenario); // MS0
00105     IA1_node node4_IA(2,0,0,0,4, 2490e6,false,IP_addresses,true,
00106                    6+use_data_from_file*54,s,true,scenario); // MS1
00107     IA1_node node5_IA(2,0,0,0,5, 2490e6,false,IP_addresses,true,
00108                    6+use_data_from_file*54,s,true,scenario); // MS2
00109     all_my_IA_nodes.push_back(&node0_IA);
00110     all_my_IA_nodes.push_back(&node1_IA);
00111     all_my_IA_nodes.push_back(&node2_IA);
00112     all_my_IA_nodes.push_back(&node3_IA);
00113     all_my_IA_nodes.push_back(&node4_IA);
00114     all_my_IA_nodes.push_back(&node5_IA);
00115 
00116     scenario=2;
00117     IA1_node node0_CoMP(6,0,0,0,0,2490e6,false,IP_addresses,true,
00118                    6+use_data_from_file*54,s,true,scenario); // BS0
00119     IA1_node node1_CoMP(2,0,0,0,1,2490e6,false,IP_addresses,true,
00120                    6+use_data_from_file*54,s,true,scenario); // MS1
00121     IA1_node node2_CoMP(2,0,0,0,2,2490e6,false,IP_addresses,true,
00122                    6+use_data_from_file*54,s,true,scenario); // MS2
00123     IA1_node node3_CoMP(2,0,0,0,3,2490e6,false,IP_addresses,true,
00124                    6+use_data_from_file*54,s,true,scenario); // MS3
00125     all_my_CoMP_nodes.push_back(&node0_CoMP);
00126     all_my_CoMP_nodes.push_back(&node1_CoMP);
00127     all_my_CoMP_nodes.push_back(&node2_CoMP);
00128     all_my_CoMP_nodes.push_back(&node3_CoMP);
00129 
00130 
00131     scenario=3;
00132     IA1_node node0_MIMO(2,0,0,0,0, 2490e6,false,IP_addresses,true,
00133                    6+use_data_from_file*54,s,true,scenario); // BS0
00134     IA1_node node1_MIMO(2,0,0,0,1, 2490e6,false,IP_addresses,true,
00135                    6+use_data_from_file*54,s,true,scenario); // BS1
00136     IA1_node node2_MIMO(2,0,0,0,2, 2490e6,false,IP_addresses,true,
00137                    6*1+use_data_from_file*54,s,true,scenario); // BS2
00138     IA1_node node3_MIMO(2,0,0,0,3, 2490e6,false,IP_addresses,true,
00139                    6*1+use_data_from_file*54,s,true,scenario); // MS0
00140     IA1_node node4_MIMO(2,0,0,0,4, 2490e6,false,IP_addresses,true,
00141                    6+use_data_from_file*54,s,true,scenario); // MS1
00142     IA1_node node5_MIMO(2,0,0,0,5, 2490e6,false,IP_addresses,true,
00143                    6+use_data_from_file*54,s,true,scenario); // MS2
00144 
00145 
00146     vec MIMO1,MIMO2,MIMO3 , MIMO1raw,MIMO2raw,MIMO3raw;
00147     vec MIMO1_EVM,  MIMO2_EVM,  MIMO3_EVM;
00148     mat MIMO4, MIMO4raw, MIMO4_EVM;
00149 
00150     all_my_MIMO_nodes.push_back(&node0_MIMO);
00151     all_my_MIMO_nodes.push_back(&node1_MIMO);
00152     all_my_MIMO_nodes.push_back(&node2_MIMO);
00153     all_my_MIMO_nodes.push_back(&node3_MIMO);
00154     all_my_MIMO_nodes.push_back(&node4_MIMO);
00155     all_my_MIMO_nodes.push_back(&node5_MIMO);
00156 
00157 
00158     //ch_model.scaling_signal=0.2;
00159     //ch_model.scaling_noise=sqrt(1e4/80);
00160     ch_model.forgetting_factor=1;
00161     ch_model.num_of_taps=2;
00162     ch_model.is_awgn=false;
00163     ch_model.is_diagonal=false;
00164 
00165     if (s>0) {
00166         from_file stored_data_IA(dir+"s="+s_s.str()+"_IA_");
00167         from_file stored_data_CoMP(dir+"s="+s_s.str()+"_CoMP_");
00168         from_file stored_data_MIMO1(dir+"s="+s_s.str()+"_MIMO1_");
00169         from_file stored_data_MIMO2(dir+"s="+s_s.str()+"_MIMO2_");
00170         from_file stored_data_MIMO3(dir+"s="+s_s.str()+"_MIMO3_");
00171         from_file stored_data_MIMO4(dir+"s="+s_s.str()+"_MIMO4_");
00172         simulate(&all_my_IA_nodes,&stored_data_IA);
00173         simulate(&all_my_CoMP_nodes,&stored_data_CoMP);
00174         node0_MIMO.MIMO_active_tx_node_tx=0;
00175         node1_MIMO.MIMO_active_tx_node_tx=0;
00176         node2_MIMO.MIMO_active_tx_node_tx=0;    
00177         simulate(&all_my_MIMO_nodes,&stored_data_MIMO1);
00178         MIMO1raw=node3_MIMO.BERraw;
00179         MIMO1=node3_MIMO.BER;
00180         MIMO1_EVM=node3_MIMO.EVM;
00181         node0_MIMO.MIMO_active_tx_node_tx=1;
00182         node1_MIMO.MIMO_active_tx_node_tx=1;
00183         node2_MIMO.MIMO_active_tx_node_tx=1;
00184         simulate(&all_my_MIMO_nodes,&stored_data_MIMO2);
00185         MIMO2raw=node4_MIMO.BERraw;
00186         MIMO2=node4_MIMO.BER;
00187         MIMO2_EVM=node4_MIMO.EVM;
00188         node0_MIMO.MIMO_active_tx_node_tx=2;
00189         node1_MIMO.MIMO_active_tx_node_tx=2;
00190         node2_MIMO.MIMO_active_tx_node_tx=2;
00191         simulate(&all_my_MIMO_nodes,&stored_data_MIMO3);
00192         MIMO3raw=node5_MIMO.BERraw;
00193         MIMO3=node5_MIMO.BER;
00194         MIMO3_EVM=node5_MIMO.EVM;
00195         
00196         node0_MIMO.MIMO_all_active=true;
00197         node1_MIMO.MIMO_all_active=true;
00198         node2_MIMO.MIMO_all_active=true;
00199         node3_MIMO.MIMO_all_active=true;
00200         node4_MIMO.MIMO_all_active=true;
00201         node5_MIMO.MIMO_all_active=true;
00202 
00203         simulate(&all_my_MIMO_nodes,&stored_data_MIMO4);
00204         MIMO4raw=node3_MIMO.BERraw;
00205         //MIMO4raw.append_column(node4_MIMO.BERraw);
00206         //MIMO4raw.append_column(node5_MIMO.BERraw);
00207         MIMO4=node3_MIMO.BER;
00208         //MIMO4.append_row(node4_MIMO.BER);
00209         //MIMO4.append_row(node5_MIMO.BER);
00210         MIMO4_EVM=node3_MIMO.EVM;
00211         //MIMO4_EVM.append_row(node4_MIMO.EVM);
00212         //MIMO4_EVM.append_row(node5_MIMO.EVM);
00213 
00214     } else {
00215       simulate(&all_my_IA_nodes,&ch_model);
00216       simulate(&all_my_CoMP_nodes,&ch_model);
00217         node0_MIMO.MIMO_active_tx_node_tx=2;
00218         node1_MIMO.MIMO_active_tx_node_tx=2;
00219         node2_MIMO.MIMO_active_tx_node_tx=2;
00220         
00221         node0_MIMO.MIMO_all_active=false;
00222         node1_MIMO.MIMO_all_active=false;
00223         node2_MIMO.MIMO_all_active=false;
00224         node3_MIMO.MIMO_all_active=false;
00225         node4_MIMO.MIMO_all_active=false;
00226         node5_MIMO.MIMO_all_active=false;
00227 
00228         simulate(&all_my_MIMO_nodes,&ch_model);
00229         MIMO1raw=node3_MIMO.BERraw;
00230         MIMO1=node3_MIMO.BER;
00231         MIMO2raw=node4_MIMO.BERraw;
00232         MIMO2=node4_MIMO.BER;
00233         MIMO3raw=node5_MIMO.BERraw;
00234         MIMO3=node5_MIMO.BER;
00235 
00236     }; 
00237     
00238 
00239     cout << "=================== IA ================== \n";
00240     cout << "Raw BER (node3) =" << node3_IA.BERraw << endl;
00241     cout << "BER (node3) =" << node3_IA.BER << endl;
00242     cout << "Raw BER (node4) =" << node4_IA.BERraw << endl;
00243     cout << "BER (node4) =" << node4_IA.BER << endl;
00244     cout << "Raw BER (node5) =" << node5_IA.BERraw << endl;
00245     cout << "BER (node5) =" << node5_IA.BER << endl;
00246 
00247 
00248     cout << "=============== CoMP ===================== \n";
00249     cout << "Raw BER (node1) =" << node1_CoMP.BERraw << endl;
00250     cout << "BER (node1) =" << node1_CoMP.BER << endl;
00251     cout << "Raw BER (node2) =" << node2_CoMP.BERraw << endl;
00252     cout << "BER (node2) =" << node2_CoMP.BER << endl;
00253     cout << "Raw BER (node3) =" << node3_CoMP.BERraw << endl;
00254     cout << "BER (node3) =" << node3_CoMP.BER << endl;
00255 
00256     
00257     cout << "=============== MIMO ===================== \n";
00258     cout << "Raw BER (node3) =" << MIMO1raw << endl;
00259     cout << "BER (node3) =" << MIMO1 << endl;
00260     cout << "Raw BER (node4) =" << MIMO2raw << endl;
00261     cout << "BER (node4) =" << MIMO2 << endl;
00262     cout << "Raw BER (node5) =" << MIMO3raw << endl;
00263     cout << "BER (node5) =" << MIMO3 << endl;
00264  
00265 
00266    
00267     #if 1
00268     itpp::it_file d1;
00269     d1.open("results.it");
00270     d1<< itpp::Name("BERraw_IA1") << node3_IA.BERraw;
00271     d1<< itpp::Name("BERraw_IA2") << node4_IA.BERraw;
00272     d1<< itpp::Name("BERraw_IA3") << node5_IA.BERraw;
00273     d1<< itpp::Name("BER_IA1") << node3_IA.BER;
00274     d1<< itpp::Name("BER_IA2") << node4_IA.BER;
00275     d1<< itpp::Name("BER_IA3") << node5_IA.BER;
00276     d1<< itpp::Name("BERraw_CoMP1") << node1_CoMP.BERraw;
00277     d1<< itpp::Name("BERraw_CoMP2") << node2_CoMP.BERraw;
00278     d1<< itpp::Name("BERraw_CoMP3") << node3_CoMP.BERraw;
00279     d1<< itpp::Name("BER_CoMP1") << node1_CoMP.BER;
00280     d1<< itpp::Name("BER_CoMP2") << node2_CoMP.BER;
00281     d1<< itpp::Name("BER_CoMP3") << node3_CoMP.BER;
00282     d1<< itpp::Name("BERraw_MIMO1") << MIMO1raw;
00283     d1<< itpp::Name("BERraw_MIMO2") << MIMO2raw;
00284     d1<< itpp::Name("BERraw_MIMO3") << MIMO3raw;
00285     d1<< itpp::Name("BERraw_MIMO4") << MIMO4raw;
00286     d1<< itpp::Name("BER_MIMO1") << MIMO1;
00287     d1<< itpp::Name("BER_MIMO2") << MIMO2;
00288     d1<< itpp::Name("BER_MIMO3") << MIMO3;
00289     d1<< itpp::Name("BER_MIMO4") << MIMO4;
00290 
00291     d1<< itpp::Name("EVM_IA1") << node3_IA.EVM;
00292     d1<< itpp::Name("EVM_IA2") << node4_IA.EVM;
00293     d1<< itpp::Name("EVM_IA3") << node5_IA.EVM;
00294     d1<< itpp::Name("EVM_CoMP1") << node1_CoMP.EVM;
00295     d1<< itpp::Name("EVM_CoMP2") << node2_CoMP.EVM;
00296     d1<< itpp::Name("EVM_CoMP3") << node3_CoMP.EVM;
00297     d1<< itpp::Name("EVM_MIMO1") << MIMO1_EVM;
00298     d1<< itpp::Name("EVM_MIMO2") << MIMO2_EVM;
00299     d1<< itpp::Name("EVM_MIMO3") << MIMO3_EVM;
00300     d1<< itpp::Name("EVM_MIMO4") << MIMO4_EVM;
00301 
00302     d1<< itpp::Name("SINR_IA1") << node3_IA.SINR;
00303     d1<< itpp::Name("SINR_IA2") << node4_IA.SINR;
00304     d1<< itpp::Name("SINR_IA3") << node5_IA.SINR;
00305     d1<< itpp::Name("SINR_CoMP1") << node1_CoMP.SINR;
00306     d1<< itpp::Name("SINR_CoMP2") << node2_CoMP.SINR;
00307     d1<< itpp::Name("SINR_CoMP3") << node3_CoMP.SINR;
00308 
00309     d1.close();
00310     #endif
00311 
00312    cout << "The end \n";
00313    return 0;
00314 
00315 }
 All Classes Functions Variables