IA_CoMP
Interference Alignment and Coordinated Multipoint
IA2/IA2_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 "IA2_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     IA2_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     IA2_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     IA2_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     IA2_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     IA2_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     IA2_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     IA2_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     IA2_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     IA2_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     IA2_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     IA2_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     IA2_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     IA2_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     IA2_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     IA2_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     IA2_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.045;
00159     ch_model.scaling_noise=10.0;
00160 
00161     ch_model.forgetting_factor=1;
00162     ch_model.num_of_taps=1;
00163     ch_model.is_awgn=false;
00164     ch_model.is_diagonal=false;
00165 
00166     if (s>0) {
00167         from_file stored_data_IA(dir+"s="+s_s.str()+"_IA_");
00168         from_file stored_data_CoMP(dir+"s="+s_s.str()+"_CoMP_");
00169         from_file stored_data_MIMO1(dir+"s="+s_s.str()+"_MIMO1_");
00170         from_file stored_data_MIMO2(dir+"s="+s_s.str()+"_MIMO2_");
00171         from_file stored_data_MIMO3(dir+"s="+s_s.str()+"_MIMO3_");
00172         from_file stored_data_MIMO4(dir+"s="+s_s.str()+"_MIMO4_");
00173         simulate(&all_my_IA_nodes,&stored_data_IA);
00174         simulate(&all_my_CoMP_nodes,&stored_data_CoMP);
00175         node0_MIMO.MIMO_active_tx_node_tx=0;
00176         node1_MIMO.MIMO_active_tx_node_tx=0;
00177         node2_MIMO.MIMO_active_tx_node_tx=0;    
00178         simulate(&all_my_MIMO_nodes,&stored_data_MIMO1);
00179         MIMO1raw=node3_MIMO.BERraw;
00180         MIMO1=node3_MIMO.BER;
00181         MIMO1_EVM=node3_MIMO.EVM;
00182         node0_MIMO.MIMO_active_tx_node_tx=1;
00183         node1_MIMO.MIMO_active_tx_node_tx=1;
00184         node2_MIMO.MIMO_active_tx_node_tx=1;
00185         simulate(&all_my_MIMO_nodes,&stored_data_MIMO2);
00186         MIMO2raw=node4_MIMO.BERraw;
00187         MIMO2=node4_MIMO.BER;
00188         MIMO2_EVM=node4_MIMO.EVM;
00189         node0_MIMO.MIMO_active_tx_node_tx=2;
00190         node1_MIMO.MIMO_active_tx_node_tx=2;
00191         node2_MIMO.MIMO_active_tx_node_tx=2;
00192         simulate(&all_my_MIMO_nodes,&stored_data_MIMO3);
00193         MIMO3raw=node5_MIMO.BERraw;
00194         MIMO3=node5_MIMO.BER;
00195         MIMO3_EVM=node5_MIMO.EVM;
00196         
00197         node0_MIMO.MIMO_all_active=true;
00198         node1_MIMO.MIMO_all_active=true;
00199         node2_MIMO.MIMO_all_active=true;
00200         node3_MIMO.MIMO_all_active=true;
00201         node4_MIMO.MIMO_all_active=true;
00202         node5_MIMO.MIMO_all_active=true;
00203 
00204         simulate(&all_my_MIMO_nodes,&stored_data_MIMO4);
00205         MIMO4raw=node3_MIMO.BERraw;
00206         //MIMO4raw.append_column(node4_MIMO.BERraw);
00207         //MIMO4raw.append_column(node5_MIMO.BERraw);
00208         MIMO4=node3_MIMO.BER;
00209         //MIMO4.append_row(node4_MIMO.BER);
00210         //MIMO4.append_row(node5_MIMO.BER);
00211         MIMO4_EVM=node3_MIMO.EVM;
00212         //MIMO4_EVM.append_row(node4_MIMO.EVM);
00213         //MIMO4_EVM.append_row(node5_MIMO.EVM);
00214 
00215     } else {
00216       simulate(&all_my_IA_nodes,&ch_model);
00217       simulate(&all_my_CoMP_nodes,&ch_model);
00218         node0_MIMO.MIMO_active_tx_node_tx=2;
00219         node1_MIMO.MIMO_active_tx_node_tx=2;
00220         node2_MIMO.MIMO_active_tx_node_tx=2;
00221         
00222         node0_MIMO.MIMO_all_active=false;
00223         node1_MIMO.MIMO_all_active=false;
00224         node2_MIMO.MIMO_all_active=false;
00225         node3_MIMO.MIMO_all_active=false;
00226         node4_MIMO.MIMO_all_active=false;
00227         node5_MIMO.MIMO_all_active=false;
00228 
00229         simulate(&all_my_MIMO_nodes,&ch_model);
00230         MIMO1raw=node3_MIMO.BERraw;
00231         MIMO1=node3_MIMO.BER;
00232         MIMO2raw=node4_MIMO.BERraw;
00233         MIMO2=node4_MIMO.BER;
00234         MIMO3raw=node5_MIMO.BERraw;
00235         MIMO3=node5_MIMO.BER;
00236 
00237     }; 
00238     
00239 
00240     cout << "=================== IA ================== \n";
00241     cout << "Raw BER (node3) =" << node3_IA.BERraw << endl;
00242     cout << "BER (node3) =" << node3_IA.BER << endl;
00243     cout << "Raw BER (node4) =" << node4_IA.BERraw << endl;
00244     cout << "BER (node4) =" << node4_IA.BER << endl;
00245     cout << "Raw BER (node5) =" << node5_IA.BERraw << endl;
00246     cout << "BER (node5) =" << node5_IA.BER << endl;
00247 
00248 
00249     cout << "=============== CoMP ===================== \n";
00250     cout << "Raw BER (node1) =" << node1_CoMP.BERraw << endl;
00251     cout << "BER (node1) =" << node1_CoMP.BER << endl;
00252     cout << "Raw BER (node2) =" << node2_CoMP.BERraw << endl;
00253     cout << "BER (node2) =" << node2_CoMP.BER << endl;
00254     cout << "Raw BER (node3) =" << node3_CoMP.BERraw << endl;
00255     cout << "BER (node3) =" << node3_CoMP.BER << endl;
00256 
00257     
00258     cout << "=============== MIMO ===================== \n";
00259     cout << "Raw BER (node3) =" << MIMO1raw << endl;
00260     cout << "BER (node3) =" << MIMO1 << endl;
00261     cout << "Raw BER (node4) =" << MIMO2raw << endl;
00262     cout << "BER (node4) =" << MIMO2 << endl;
00263     cout << "Raw BER (node5) =" << MIMO3raw << endl;
00264     cout << "BER (node5) =" << MIMO3 << endl;
00265  
00266 
00267    
00268     #if 1
00269     itpp::it_file d1;
00270     d1.open("results.it");
00271     d1<< itpp::Name("BERraw_IA1") << node3_IA.BERraw;
00272     d1<< itpp::Name("BERraw_IA2") << node4_IA.BERraw;
00273     d1<< itpp::Name("BERraw_IA3") << node5_IA.BERraw;
00274     d1<< itpp::Name("BER_IA1") << node3_IA.BER;
00275     d1<< itpp::Name("BER_IA2") << node4_IA.BER;
00276     d1<< itpp::Name("BER_IA3") << node5_IA.BER;
00277     d1<< itpp::Name("BERraw_CoMP1") << node1_CoMP.BERraw;
00278     d1<< itpp::Name("BERraw_CoMP2") << node2_CoMP.BERraw;
00279     d1<< itpp::Name("BERraw_CoMP3") << node3_CoMP.BERraw;
00280     d1<< itpp::Name("BER_CoMP1") << node1_CoMP.BER;
00281     d1<< itpp::Name("BER_CoMP2") << node2_CoMP.BER;
00282     d1<< itpp::Name("BER_CoMP3") << node3_CoMP.BER;
00283     d1<< itpp::Name("BERraw_MIMO1") << MIMO1raw;
00284     d1<< itpp::Name("BERraw_MIMO2") << MIMO2raw;
00285     d1<< itpp::Name("BERraw_MIMO3") << MIMO3raw;
00286     d1<< itpp::Name("BERraw_MIMO4") << MIMO4raw;
00287     d1<< itpp::Name("BER_MIMO1") << MIMO1;
00288     d1<< itpp::Name("BER_MIMO2") << MIMO2;
00289     d1<< itpp::Name("BER_MIMO3") << MIMO3;
00290     d1<< itpp::Name("BER_MIMO4") << MIMO4;
00291 
00292     d1<< itpp::Name("EVM_IA1") << node3_IA.EVM;
00293     d1<< itpp::Name("EVM_IA2") << node4_IA.EVM;
00294     d1<< itpp::Name("EVM_IA3") << node5_IA.EVM;
00295     d1<< itpp::Name("EVM_CoMP1") << node1_CoMP.EVM;
00296     d1<< itpp::Name("EVM_CoMP2") << node2_CoMP.EVM;
00297     d1<< itpp::Name("EVM_CoMP3") << node3_CoMP.EVM;
00298     d1<< itpp::Name("EVM_MIMO1") << MIMO1_EVM;
00299     d1<< itpp::Name("EVM_MIMO2") << MIMO2_EVM;
00300     d1<< itpp::Name("EVM_MIMO3") << MIMO3_EVM;
00301     d1<< itpp::Name("EVM_MIMO4") << MIMO4_EVM;
00302 
00303     d1<< itpp::Name("SINR_IA1") << node3_IA.SINR;
00304     d1<< itpp::Name("SINR_IA2") << node4_IA.SINR;
00305     d1<< itpp::Name("SINR_IA3") << node5_IA.SINR;
00306     d1<< itpp::Name("SINR_CoMP1") << node1_CoMP.SINR;
00307     d1<< itpp::Name("SINR_CoMP2") << node2_CoMP.SINR;
00308     d1<< itpp::Name("SINR_CoMP3") << node3_CoMP.SINR;
00309 
00310     d1.close();
00311     #endif
00312 
00313    cout << "The end \n";
00314    return 0;
00315 
00316 }
 All Classes Functions Variables