![]() |
IA_CoMP
Interference Alignment and Coordinated Multipoint
|
00001 // Copyright 2011-2013, Per Zetterberg, KTH Royal Institute of Technology 00002 // This program is free software: you can redistribute it and/or modify 00003 // it under the terms of the GNU General Public License as published by 00004 // the Free Software Foundation, either version 3 of the License, or 00005 // (at your option) any later version. 00006 // 00007 // This program is distributed in the hope that it will be useful, 00008 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00010 // GNU General Public License for more details. 00011 // 00012 // You should have received a copy of the GNU General Public License 00013 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00014 // 00015 00016 #include "IA2_node.hpp" 00017 #include <itpp/itcomm.h> 00018 #include <itpp/stat/misc_stat.h> 00019 00020 00021 00022 IA2_node::IA2_node(uint32_t no_ant1, uint32_t no_ant2 , uint32_t skip_ant, 00023 float start_gain, uint32_t node_ix , double frequency, 00024 bool use_same_antenna, 00025 std::vector<std::string> IP_addresses,bool simulate, 00026 int receiver_delay_samples,int seed, bool run_decoder, 00027 int scenario_in) 00028 : four_multi_node(20000,no_ant1,no_ant2,false,use_same_antenna,node_ix,IP_addresses,simulate,skip_ant) 00029 { 00030 00031 00032 bool use_pilot_carriers=true; 00033 uint32_t cyclic_prefix_length=12; 00034 uint32_t no_ant=no_ant1+no_ant2; 00035 int noise_estimation_start_ix; 00036 uint32_t num_payload_symbols_before_pilots=10; 00037 uint32_t num_payload_symbols_after_pilots=10; 00038 uint32_t num_symbols=num_payload_symbols_before_pilots+num_payload_symbols_after_pilots+1; 00039 ivec known_pos; 00040 scenario=scenario_in; // 1=pure IA, 2=CoMP, 3=MIMO, 4=SIMO 00041 use_udp=true; 00042 00043 use_old_rand=false; 00044 do_calculate_beamformers=true; 00045 offset_time=0.0; 00046 scaling_tx_signal=50000; 00047 if ((scenario_in<3) && use_udp) { 00048 time_between_frames=0.06; 00049 } else { 00050 time_between_frames=0.1; 00051 }; 00052 shift_transmit_signal_samples=2000; 00053 noise_estimation_start_ix=1001; 00054 replicas_start=5000; 00055 replicas_spacing=3000; 00056 d_seed=seed; 00057 codec_ix=3; 00058 modulation_order=16; 00059 00060 00061 d_gain_rx=start_gain; 00062 d_node_ix=node_ix; 00063 d_frame_ix=0; 00064 d_frequency=frequency; 00065 d_gain_tx=20; 00066 d_frame_ix=0; 00067 d_no_frames=5; 00068 00069 ai.resize(3); 00070 00071 00072 if (scenario==1) { 00073 num_links=3; // Node 0,1,2 =BS 3,4,5 =MS 00074 num_streams=3; 00075 num_bs=3; 00076 num_ms=3; 00077 num_streams_per_bs=1; 00078 num_streams_per_ms=1; 00079 num_antennas_in_system=6; 00080 replica_positions_this_bs.set_length(num_streams_per_bs); 00081 replica_positions_this_bs(0)=replicas_start+(d_node_ix % num_links)*replicas_spacing; 00082 replica_positions.set_length(num_streams); 00083 for (uint32_t i1=0;i1<num_streams;i1++) { 00084 replica_positions(i1)=replicas_start+i1*replicas_spacing; 00085 }; 00086 00087 stream_ix_this_node.set_length(1); 00088 stream_ix_this_node(0)=d_node_ix % num_links; 00089 00090 num_ant_ms=2; 00091 num_ant_bs=2; 00092 00093 bs_to_stream_ix="0 ; 1 ; 2"; 00094 stream_ix_to_ms_ix="0,1,2"; 00095 00096 if (node_ix<num_links) 00097 is_bs=true; 00098 else 00099 is_bs=false; 00100 00101 00102 }; 00103 if (scenario==2) { 00104 00105 num_ant_ms=2; 00106 num_ant_bs=6; 00107 00108 num_bs=1; 00109 num_ms=3; 00110 num_links=3; // Node 0 =BS 1,2,3 =MS 00111 num_streams=3; 00112 num_streams_per_bs=3; 00113 num_streams_per_ms=1; 00114 num_antennas_in_system=6; 00115 if (node_ix==0) { 00116 is_bs=true; 00117 bs_to_stream_ix="0 1 2"; 00118 stream_ix_to_ms_ix="0,1,2"; 00119 stream_ix_this_node="0 1 2"; 00120 } else { 00121 stream_ix_this_node.set_length(1); 00122 stream_ix_this_node(0)=d_node_ix-1; 00123 is_bs=false; 00124 }; 00125 replica_positions_this_bs.set_length(num_streams_per_bs); 00126 for (uint32_t i1=0;i1<num_streams_per_bs;i1++) { 00127 replica_positions_this_bs(i1)=replicas_start+i1*replicas_spacing; 00128 }; 00129 replica_positions.set_length(num_streams); 00130 for (uint32_t i1=0;i1<num_streams;i1++) { 00131 replica_positions(i1)=replicas_start+i1*replicas_spacing; 00132 }; 00133 00134 00135 }; 00136 if (scenario==3) { // Node 0,1,2 =BS 3,4,5 =MS, MIMO 00137 num_bs=3; 00138 num_ms=3; 00139 00140 num_ant_ms=2; 00141 num_ant_bs=2; 00142 00143 num_links=3; 00144 num_streams=2; 00145 num_streams_per_bs=2; 00146 num_streams_per_ms=2; 00147 num_antennas_in_system=6; 00148 replica_positions_this_bs.set_length(num_streams_per_bs); 00149 replica_positions_this_bs(0)=replicas_start; 00150 replica_positions_this_bs(1)=replicas_start+replicas_spacing; 00151 stream_ix_this_node="0 1"; 00152 bs_to_stream_ix="0 1;0 1;0 1"; 00153 do_calculate_beamformers=false; 00154 00155 MIMO_active_tx_node_tx=0; 00156 MIMO_closed_loop=false; 00157 MIMO_all_active=false; 00158 stream_ix_to_ms_ix="0,0"; 00159 00160 if (node_ix<num_links) 00161 is_bs=true; 00162 else 00163 is_bs=false; 00164 }; 00165 if (scenario==4) { // SIMO 00166 00167 num_ant_ms=2; 00168 num_ant_bs=2; 00169 00170 num_bs=3; 00171 num_ms=3; 00172 num_links=1; 00173 num_streams=1; 00174 num_streams_per_bs=1; 00175 num_streams_per_ms=1; 00176 num_antennas_in_system=6; 00177 replica_positions_this_bs.set_length(num_streams_per_bs); 00178 replica_positions_this_bs(0)=replicas_start+(d_node_ix % num_links)*replicas_spacing; 00179 stream_ix_this_node.set_length(1); 00180 stream_ix_this_node(0)=d_node_ix % num_links; 00181 do_calculate_beamformers=false; 00182 bs_to_stream_ix="0;0;0"; 00183 00184 if (node_ix<num_bs) 00185 is_bs=true; 00186 else 00187 is_bs=false; 00188 00189 }; 00190 00191 if (!is_bs) { 00192 demodulation_position.set_size(num_streams_per_ms); 00193 for (uint32_t i1=0;i1<num_streams_per_ms;i1++) { 00194 demodulation_position(i1)=shift_transmit_signal_samples; 00195 //demodulation_position(i1)=replica_positions(stream_ix_this_node(i1)); 00196 demodulation_position(i1)+=receiver_delay_samples; 00197 00198 }; 00199 }; 00200 00201 antenna_pilot_position.set_length(num_antennas_in_system); 00202 antenna_pilot_position_this_bs.set_length(no_ant); 00203 00204 00205 for (uint32_t i1=0;i1<num_antennas_in_system;i1++) { 00206 antenna_pilot_position(i1)=num_payload_symbols_before_pilots+ 00207 num_streams+i1; 00208 }; 00209 00210 00211 00212 if (scenario!=2) { 00213 for (uint32_t i1=0;i1<no_ant;i1++) { 00214 antenna_pilot_position_this_bs[i1]=antenna_pilot_position[(node_ix % num_links)*no_ant+i1]; 00215 }; 00216 } else 00217 antenna_pilot_position_this_bs=antenna_pilot_position; 00218 00219 00220 00221 known_pos_all.set_length(num_streams); 00222 for (uint32_t i1=0;i1<num_streams;i1++) { 00223 reorder_all[i1].set_length(num_symbols); 00224 known_pos_all(i1)=num_payload_symbols_before_pilots+i1; 00225 for (uint32_t i2=0;i2<num_payload_symbols_before_pilots;i2++) { 00226 (reorder_all[i1])(i2)=i2; 00227 }; 00228 reorder_all[i1](num_payload_symbols_before_pilots)=num_payload_symbols_before_pilots+i1; 00229 for (uint32_t i2=0;i2<num_payload_symbols_after_pilots;i2++) { 00230 (reorder_all[i1])(i2+num_payload_symbols_before_pilots+1)= 00231 num_payload_symbols_before_pilots+num_streams+num_antennas_in_system+i2; 00232 }; 00233 }; 00234 known_pos.set_length(1); 00235 known_pos(0)=num_payload_symbols_before_pilots; 00236 00237 if (scenario==2) { 00238 if (node_ix==0) { 00239 for (uint32_t i1=0;i1<num_streams_per_bs;i1++) { 00240 00241 ai[i1].init(use_pilot_carriers,false,cyclic_prefix_length,num_symbols, 00242 known_pos,reorder_all[i1]); 00243 00244 ai[i1].estimate_SINR=run_decoder; 00245 }; 00246 } 00247 else { 00248 00249 ai[0].init(use_pilot_carriers,false,cyclic_prefix_length,num_symbols, 00250 known_pos,reorder_all[node_ix-1]); 00251 ai[0].estimate_SINR=run_decoder; 00252 ai[0].noise_estimation_start_ix=noise_estimation_start_ix; 00253 ai[0].noise_estimation_stop_ix=shift_transmit_signal_samples-10; 00254 00255 }; 00256 }; 00257 00258 00259 00260 if (scenario==3) { 00261 for (uint32_t i1=0;i1<num_streams_per_ms;i1++) { 00262 ai[i1].init(use_pilot_carriers,false,cyclic_prefix_length,num_symbols, 00263 known_pos,reorder_all[i1]); 00264 ai[i1].estimate_SINR=run_decoder; 00265 ai[i1].noise_estimation_start_ix=noise_estimation_start_ix; 00266 ai[i1].noise_estimation_stop_ix=shift_transmit_signal_samples-10; 00267 00268 }; 00269 }; 00270 if ((scenario==1) | (scenario==4)) { 00271 ai[0].init(use_pilot_carriers,false,cyclic_prefix_length,num_symbols, 00272 known_pos,reorder_all[node_ix % num_links]); 00273 ai[0].estimate_SINR=run_decoder; 00274 ai[0].noise_estimation_start_ix=noise_estimation_start_ix; 00275 ai[0].noise_estimation_stop_ix=shift_transmit_signal_samples-10; 00276 }; 00277 00278 00279 00280 00281 00282 if (!is_bs) { 00283 for (int i1=0;i1<stream_ix_this_node.length();i1++) { 00284 ivec interferer_pos(num_streams-1); 00285 int i10=0; 00286 for (int i2=0;i2<(int) num_streams;i2++) { 00287 if (stream_ix_this_node(i1)!=i2) { 00288 interferer_pos(i10)=known_pos_all(i2); 00289 i10++; 00290 }; 00291 }; 00292 ai[i1].init_multi_antenna(no_ant, d_buffer_length, interferer_pos); 00293 }; 00294 }; 00295 if (node_ix==0) { 00296 for (uint32_t i1=0;i1<num_antennas_in_system;i1++) { 00297 for (uint32_t i2=0;i2<num_ms;i2++) { 00298 H[i2][i1].set_size(num_ant_ms,ai[0].length_ix_all); 00299 }; 00300 }; 00301 00302 for (uint32_t i1=0;i1<num_streams;i1++) { 00303 Vbig[i1].set_size(no_ant,ai[0].length_ix_all); 00304 //Ubig[i1].set_size(no_ant,ai[0].length_ix_all); 00305 Vbig[i1]=randn_c(no_ant,ai[0].length_ix_all); 00306 normalize_columns(Vbig[i1]); 00307 00308 }; 00309 }; 00310 00311 //int bits_per_symbol=log2(qam_order); 00312 00313 word_length=ai[0].length_ix*5*2*4; 00314 amc.init(word_length,true); 00315 amc.only_raw_bits=true; 00316 if (run_decoder) { 00317 amc.only_raw_bits=false; 00318 d_run_decoder=run_decoder; 00319 }; 00320 00321 transmitted.set_length(word_length); 00322 transmitted_hat.set_length(word_length); 00323 message_hat.set_length(amc.codec_message_size(amc.no_of_codecs()-1)); 00324 decoded_bits.set_length(amc.codec_message_size(amc.no_of_codecs()-1)); 00325 input.set_length(amc.codec_message_size(amc.no_of_codecs()-1)); 00326 00327 //soft_bit.set_length((ai[0].Ns-1)*ai[0].length_ix*bits_per_symbol); 00328 00329 waveform_rx.set_size(no_ant,d_buffer_length); 00330 waveform_tx.set_length(d_buffer_length); 00331 waveform_tx_temp.set_length(d_buffer_length); 00332 waveform_rx.zeros(); 00333 waveform_tx.zeros(); 00334 waveform_tx_temp.zeros(); 00335 00336 BERraw.set_length(100); 00337 BER.set_length(100); 00338 EVM.set_length(100); 00339 SINR.set_length(100); 00340 00341 ber_i=0; 00342 00343 00344 symbols.set_length((ai[0].Ns-1)*ai[0].length_ix); 00345 00346 } 00347 00348 IA2_node::~IA2_node(void) { 00349 }; 00350 00351 frame_settings IA2_node::node_init(void) { 00352 00353 noise_variance=21.7*21.7; 00354 ber_i=0; 00355 d_frame_ix=0; 00356 feedback_buffer_size=num_antennas_in_system*num_ant_ms* 00357 sizeof(std::complex<int16_t>)*ai[0].Nfftr(); 00358 00359 feedback_buffer_size_tx=num_ant_bs* 00360 sizeof(std::complex<int16_t>)*ai[0].length_ix_all*num_streams_per_bs; 00361 00362 00363 00364 if (feedback_buffer_size>feedback_buffer_size_tx) { 00365 feedback_buffer=(std::complex<int16_t> *) malloc(feedback_buffer_size); 00366 feedback_buffer0=(std::complex<int16_t> *) malloc(feedback_buffer_size); 00367 feedback_buffer1=(std::complex<int16_t> *) malloc(feedback_buffer_size); 00368 feedback_buffer2=(std::complex<int16_t> *) malloc(feedback_buffer_size); 00369 00370 } else { 00371 feedback_buffer=(std::complex<int16_t> *) malloc(feedback_buffer_size_tx); 00372 feedback_buffer0=(std::complex<int16_t> *) malloc(feedback_buffer_size); 00373 feedback_buffer1=(std::complex<int16_t> *) malloc(feedback_buffer_size); 00374 feedback_buffer2=(std::complex<int16_t> *) malloc(feedback_buffer_size); 00375 }; 00376 00377 if (other_node_ixs.size()==0) { 00378 other_node_ixs.push_back(0); // Changed later on 00379 other_node_ixs.push_back(1); 00380 other_node_ixs.push_back(2); 00381 pointers_to_data.push_back(feedback_buffer0); 00382 pointers_to_data.push_back(feedback_buffer1); 00383 pointers_to_data.push_back(feedback_buffer2); 00384 num_bytess.push_back(feedback_buffer_size); 00385 num_bytess.push_back(feedback_buffer_size); 00386 num_bytess.push_back(feedback_buffer_size); 00387 }; 00388 00389 00390 if ((scenario==3) && (!MIMO_closed_loop)) { 00391 do_calculate_beamformers=false; 00392 if (MIMO_all_active) { 00393 if ((d_node_ix==0) | (d_node_ix==3)) 00394 stream_ix_this_node="0 1"; 00395 if ((d_node_ix==1) | (d_node_ix==4)) 00396 stream_ix_this_node="2 3"; 00397 if ((d_node_ix==2) | (d_node_ix==5)) 00398 stream_ix_this_node="4 5"; 00399 }; 00400 }; 00401 00402 00403 00404 if (is_bs) { 00405 00406 00407 // Initialize pre-coding matrices 00408 if (is_bs) { 00409 for (uint32_t i1=0;i1<num_streams_per_bs;i1++) { 00410 v[i1].set_size(d_no_ant,ai[i1].length_ix_all); 00411 v[i1].zeros(); 00412 if ((d_node_ix==0) & (i1==0)) { 00413 v[i1].set_row(0,ones_c(ai[i1].length_ix_all)); 00414 //Vbig[i1]=v[i1]; 00415 }; 00416 }; 00417 }; 00418 00419 00420 00421 return node_process(); // TX 00422 } else { //RX 00423 frame_settings frame; 00424 std::vector<double> gain_rx_vec(1); 00425 std::vector<double> gain_tx_vec(1); 00426 std::vector<double> freq_vec(1); 00427 00428 00429 gain_rx_vec[0]=d_gain_rx; 00430 gain_tx_vec[0]=d_gain_tx; 00431 freq_vec[0]=d_frequency; 00432 frame.what=RX; 00433 frame.gain_rx=gain_rx_vec; 00434 frame.gain_tx=gain_tx_vec; 00435 frame.frequency=freq_vec; 00436 frame.time=offset_time; 00437 00438 00439 return frame; 00440 }; 00441 00442 }; 00443 00444 00445 void IA2_node::end_of_run(){ 00446 free(feedback_buffer); 00447 free(feedback_buffer0); 00448 free(feedback_buffer1); 00449 free(feedback_buffer2); 00450 00451 BER=BER.mid(0,ber_i); 00452 BERraw=BERraw.mid(0,ber_i); 00453 EVM=EVM.mid(0,ber_i); 00454 SINR=SINR.mid(0,ber_i); 00455 }; 00456 00457 frame_settings IA2_node::node_process(void) { 00458 00459 00460 frame_settings frame; 00461 std::vector<double> gain_rx_vec(1); 00462 std::vector<double> gain_tx_vec(1); 00463 std::vector<double> freq_vec(1); 00464 00465 00466 gain_rx_vec[0]=d_gain_rx; 00467 gain_tx_vec[0]=d_gain_tx; 00468 freq_vec[0]=d_frequency; 00469 00470 frame.frequency=freq_vec; 00471 frame.gain_rx=gain_rx_vec; 00472 frame.gain_tx=gain_tx_vec; 00473 00474 d_frame_ix++; 00475 00476 00477 if (!is_bs) { /****** RX ***********/ 00478 00479 std::cout << "Processing in the receiver \n"; 00480 00481 00482 // Feedback raw signal samples during common pilots 00483 if (true) { // Need only be done ones 00484 00485 std::complex<int16_t> *p1; 00486 int c=0; 00487 for (uint32_t i2=0;i2<num_antennas_in_system;i2++) { 00488 00489 00490 int s=(ai[0].Nfftr()+ai[0].Np)*antenna_pilot_position(i2)+ 00491 demodulation_position(0); 00492 00493 for (uint32_t i3=0;i3<d_no_ant;i3++) { 00494 00495 p1=(std::complex<int16_t> *) d_rx_buffers[i3]; 00496 int d=ai[0].Nfftr()*sizeof(std::complex<int16_t>); 00497 memcpy(&feedback_buffer[c*ai[0].Nfftr()],&p1[s],d); 00498 c++; 00499 00500 }; 00501 }; 00502 00503 00504 if (do_calculate_beamformers) { 00505 x2_tx(0,feedback_buffer,feedback_buffer_size); 00506 } else { 00507 x2_tx(0,feedback_buffer,10); 00508 }; 00509 }; 00510 00511 00512 frame.time=d_frame_ix*time_between_frames+offset_time; 00513 00514 /* Data is available in d_rx_buffers[0] */ 00515 00516 for (uint32_t i2=0;i2<d_no_ant;i2++) { 00517 std::complex<int16_t> *p1; 00518 p1=(std::complex<int16_t> *) d_rx_buffers[i2]; 00519 for (uint32_t i1=0;i1<d_buffer_length;i1++) 00520 waveform_rx(i2,i1)=p1[i1]; 00521 }; 00522 00523 00524 for (uint32_t i1=0;i1<num_streams_per_ms;i1++) { 00525 00526 00527 ai[i1].extract_multi_antenna(waveform_rx,demodulation_position(i1),symbols); 00528 noise_variance_norm=amc.noise_variance(symbols,modulation_order); 00529 //ai[i1].de_interleave_symbols(symbols,stream_ix_this_node(i1)+d_frame_ix); 00530 00531 SINR_temp=ai[i1].SINR; 00532 decode_rx_symbols(codec_ix,modulation_order,stream_ix_this_node(i1)); 00533 00534 00535 00536 00537 //itpp::it_file d1; 00538 //d1.open("d1.it"); 00539 //d1<< itpp::Name("w_rx") << waveform_rx; 00540 //d1.close(); 00541 00542 00543 00544 }; 00545 #if 0 00546 if ((d_frame_ix==2) & (d_node_ix>3)){ 00547 cout << "d_node_ix=" << d_node_ix << endl; 00548 itpp::it_file d1; 00549 d1.open("d1.it"); 00550 d1<< itpp::Name("waveform_rx") << waveform_rx; 00551 d1<< itpp::Name("symbols") << symbols; 00552 d1<< itpp::Name("h") << ai[0].h ; 00553 //d1<< itpp::Name("part_waveform_rx") << 00554 // waveform_rx.get_row(1).mid(ai[0].start_of_known_symbol()(0)+ 00555 // demodulation_position(0),ai[0].Nfftr()); 00556 00557 //d1<< itpp::Name("Const") << ai[0].ConstellationStorage ; 00558 d1.close(); 00559 exit(1); 00560 }; 00561 #endif 00562 00563 frame.what=RX; 00564 00565 if (d_frame_ix==(d_no_frames)) 00566 frame.what=END; 00567 00568 00569 00570 return frame; 00571 00572 00573 }; 00574 00575 if (is_bs) { // ***** TX ****** 00576 00577 00578 00579 frame.time=(d_frame_ix-1)*time_between_frames+offset_time; 00580 std::cout << "Processing in the transmitter \n"; 00581 double rms_power=-10; // Disable calculation of rms_power 00582 00583 00584 if ((d_node_ix==0) & (d_frame_ix>1)){ 00585 00586 00587 // Receive data from feedback buffer 00588 // node_ix=0 is the boss! 00589 00590 cvec waveform_temp(ai[0].Nfftr()); 00591 double nvn, nv; 00592 cvec h(ai[0].length_ix_all); 00593 00594 00595 00596 other_node_ixs[0]=num_bs; 00597 other_node_ixs[1]=num_bs+1; 00598 other_node_ixs[2]=num_bs+2; 00599 00600 std::vector<uint32_t> num_bytess_short(3); 00601 num_bytess_short[0]=10; 00602 num_bytess_short[1]=10; 00603 num_bytess_short[2]=10; 00604 00605 00606 if (do_calculate_beamformers) { 00607 x2_rx(other_node_ixs ,pointers_to_data,num_bytess); 00608 } else { 00609 x2_rx(other_node_ixs ,pointers_to_data,num_bytess_short); 00610 }; 00611 std::complex<int16_t> *fe; 00612 00613 for (uint32_t i1=0;i1<num_ms;i1++) { 00614 fe=(std::complex<short int>*) pointers_to_data[i1]; 00615 int i40=0; 00616 for (uint32_t i2=0;i2<num_antennas_in_system;i2++) { 00617 for (uint32_t i3=0;i3<num_ant_ms;i3++) { 00618 for (uint32_t i4=0;i4<ai[0].Nfftr();i4++) { 00619 waveform_temp(i4)=fe[i40+i4]; 00620 }; // i4 00621 00622 i40+=ai[0].Nfftr(); 00623 ai[0].estimate_channel(waveform_temp,nvn,h,0,nv); 00624 00625 H[i1][i2].set_row(i3,h); 00626 }; // i3 00627 }; // i2 00628 }; //i1 00629 00630 timer.reset(); 00631 timer.start(); 00632 00633 // Compress feedback according to IEEE802.11n/802.11ac-style 00634 for (uint32_t i1=0;i1<num_ms;i1++) { 00635 OFDM2::compressed_feedback_IEEE80211ac f; 00636 f=ai[0].compress_feedback(H[i1],num_antennas_in_system,noise_variance*80); 00637 ai[0].uncompress_feedback(H[i1],f); 00638 }; 00639 timer.stop(); 00640 std::cout << "timer.get_time()=" << timer.get_time() << std::endl; 00641 00642 00643 // Calculate beamformers for all streams 00644 00645 timer.reset(); 00646 timer.start(); 00647 if (do_calculate_beamformers) { 00648 calculate_beamformers(); 00649 }; 00650 timer.stop(); 00651 //std::cout << "timer.get_time()=" << timer.get_time() << std::endl; 00652 00653 if (!do_calculate_beamformers) { 00654 00655 for (uint32_t i1=0;i1<num_streams;i1++) { 00656 for (uint32_t i2=0;i2<ai[0].length_ix_all;i2++) { 00657 for (int i3=0;i3<Vbig[i1].rows();i3++) { 00658 00659 if (scenario==3) { 00660 if (((int) i3)==i1) { 00661 Vbig[i1](i3,i2)=1; 00662 } else { 00663 Vbig[i1](i3,i2)=0; 00664 }; // if 00665 } else { // scenario==4 00666 if (((int) i3)==(d_frame_ix % num_ant_bs)) { 00667 Vbig[i1](i3,i2)=1; 00668 } else { 00669 Vbig[i1](i3,i2)=0; 00670 }; // if 00671 }; 00672 }; // i3 00673 }; // i2 00674 }; // i1 00675 }; 00676 00677 00678 if (d_simulate) { 00679 stringstream filename; 00680 stringstream variable_name; 00681 filename << "Vbig" << d_frame_ix-1 << "_" << scenario << ".it"; 00682 itpp::it_file d1; 00683 d1.open(filename.str()); 00684 00685 00686 d1<< itpp::Name("Vbig0") << Vbig[0]; 00687 if (scenario!=4) 00688 d1<< itpp::Name("Vbig1") << Vbig[1]; 00689 if ((scenario!=3) && (scenario!=4)) 00690 d1<< itpp::Name("Vbig2") << Vbig[2]; 00691 d1.close(); 00692 }; 00693 00694 00695 }; 00696 00697 00698 if (d_node_ix==0) { 00699 00700 // Transmit precoders to the other TX:s 00701 //std::cout << "Transmit precoders to the other TX:s \n"; 00702 00703 if (d_frame_ix>1) { 00704 for (uint32_t i1=1;i1<num_bs;i1++) { 00705 int i30=0; 00706 for (uint32_t i4=0;i4<num_streams_per_bs;i4++) { 00707 for (uint32_t i2=0;i2<d_no_ant;i2++) { 00708 for (uint32_t i3=0;i3<ai[0].length_ix_all;i3++) { 00709 feedback_buffer[i3+i30]=10000*(Vbig[bs_to_stream_ix(i1,i4)] 00710 (i2,i3)); 00711 00712 }; 00713 i30+=ai[0].length_ix_all; 00714 }; 00715 }; 00716 x2_tx(i1,feedback_buffer,feedback_buffer_size_tx); 00717 }; 00718 v[0]=Vbig[0]; 00719 if (scenario==2) { 00720 v[1]=Vbig[1]; 00721 v[2]=Vbig[2]; 00722 }; 00723 if (scenario==3) { 00724 v[1]=Vbig[1]; 00725 }; 00726 }; 00727 //std::cout << "Done transmit precoders to the other TX:s \n"; 00728 00729 00730 } else { 00731 00732 if (d_frame_ix>1) { 00733 00734 // Receive precoders from node_ix=0 00735 00736 x2_rx(0,feedback_buffer,feedback_buffer_size_tx); 00737 00738 int i30=0; 00739 complex<double> temp; 00740 for (uint32_t i4=0;i4<num_streams_per_bs;i4++) { 00741 for (uint32_t i2=0;i2<d_no_ant;i2++) { 00742 for (uint32_t i3=0;i3<ai[0].length_ix_all;i3++) { 00743 temp=feedback_buffer[i3+i30]; 00744 temp=temp*1e-4; 00745 v[i4](i2,i3)=temp; 00746 }; 00747 i30+=ai[0].length_ix_all; 00748 }; 00749 }; 00750 }; 00751 }; 00752 00753 00754 if (scenario==4) { 00755 (v[0]).zeros(); 00756 }; 00757 00758 00759 if ((scenario==3) && (!(d_node_ix==MIMO_active_tx_node_tx)) && (!MIMO_all_active)) { 00760 (v[0]).zeros(); 00761 (v[1]).zeros(); 00762 }; 00763 00764 00765 // Format data to be transmitted in the next burst 00766 //timer.reset(); 00767 //timer.start(); 00768 00769 00770 00771 for (uint32_t i2=0;i2<d_no_ant;i2++) { 00772 00773 00774 00775 waveform_tx.zeros(); 00776 ai[0].insert_pilot(waveform_tx,antenna_pilot_position_this_bs[i2], 00777 shift_transmit_signal_samples, 00778 ones_c(ai[0].length_ix_all)); 00779 00780 00781 // Payload data 00782 for (uint32_t i1=0;i1<num_streams_per_bs;i1++) { 00783 00784 00785 format_tx_symbols(codec_ix,modulation_order,stream_ix_this_node(i1)); 00786 //ai[i1].interleave_symbols(symbols,stream_ix_this_node(i1)+d_frame_ix); 00787 00788 waveform_tx_temp.zeros(); 00789 ai[i1].modulate(waveform_tx_temp,symbols,shift_transmit_signal_samples, 00790 rms_power,v[i1].get_row(i2)); 00791 waveform_tx+=waveform_tx_temp; 00792 00793 // Create replica 00794 waveform_tx.replace_mid(replica_positions_this_bs(i1), 00795 waveform_tx_temp.mid(shift_transmit_signal_samples,replicas_spacing)); 00796 00797 00798 ai[0].insert_pilot(waveform_tx,antenna_pilot_position_this_bs(i2), 00799 replica_positions_this_bs(i1), 00800 ones_c(ai[0].length_ix_all)); 00801 00802 00803 00804 }; 00805 00806 00807 00808 00809 waveform_tx=scaling_tx_signal*waveform_tx; 00810 00811 std::complex<int16_t> *p1; 00812 p1=(std::complex<int16_t> *) d_tx_buffers[i2]; 00813 for (uint32_t i1=0;i1<d_buffer_length;i1++) { 00814 p1[i1]=waveform_tx(i1); 00815 }; 00816 00817 //timer.stop(); 00818 //std::cout << "Time formatting data timer.get_time()=" << timer.get_time() << std::endl; 00819 00820 00821 00822 }; 00823 00824 00825 00826 frame.what=TX; 00827 00828 if (d_frame_ix==(d_no_frames+1)) 00829 frame.what=END; 00830 00831 }; 00832 00833 00834 return frame; 00835 00836 00837 } 00838 00839 00840 void IA2_node::normalize_columns(cmat &M) { 00841 double n; 00842 for (int i1=0; i1<M.cols();i1++) { 00843 00844 n=norm(M.get_col(i1),2); 00845 M.set_col(i1,M.get_col(i1)/n); 00846 00847 }; 00848 }; 00849 00850 00851 00852 void IA2_node::format_tx_symbols(uint32_t codec_ix, uint32_t modulation_order,int stream_ix) 00853 { 00854 00855 00856 int l=amc.codec_message_size(codec_ix); 00857 00858 if (use_old_rand) { 00859 RNG_reset(100+10000*stream_ix+d_seed); 00860 input.set_subvector(0,randb(l)); 00861 } else { 00862 temp_seed=100+10000*stream_ix+d_seed; 00863 amc.randb_thread_safe(0,l,input,&temp_seed) ; 00864 }; 00865 00866 amc.modulate(modulation_order,codec_ix,input.mid(0,l), 00867 transmitted,symbols,0) ; 00868 00869 00870 if (modulation_order>15) { 00871 if (use_old_rand) { 00872 RNG_reset(110+10000*stream_ix+d_seed); 00873 input.set_subvector(0,randb(l)); 00874 } else { 00875 temp_seed=110+10000*stream_ix+d_seed; 00876 amc.randb_thread_safe(0,l,input,&temp_seed) ; 00877 }; 00878 00879 amc.modulate(modulation_order,codec_ix,input.mid(0,l), 00880 transmitted,symbols, word_length/(log2(modulation_order))) ; 00881 }; 00882 00883 if (modulation_order>63) { 00884 if (use_old_rand) { 00885 RNG_reset(120+10000*stream_ix+d_seed); 00886 input.set_subvector(0,randb(l)); 00887 } else { 00888 temp_seed=120+10000*stream_ix+d_seed; 00889 amc.randb_thread_safe(0,l,input,&temp_seed) ; 00890 }; 00891 00892 amc.modulate(modulation_order,codec_ix,input.mid(0,l), 00893 transmitted,symbols,2*word_length/(log2(modulation_order))); 00894 00895 }; 00896 if (modulation_order>255) { 00897 00898 if (use_old_rand) { 00899 RNG_reset(130+10000*stream_ix+d_seed); 00900 input.set_subvector(0,randb(l)); 00901 } else { 00902 temp_seed=130+10000*stream_ix+d_seed; 00903 amc.randb_thread_safe(0,l,input,&temp_seed) ; 00904 }; 00905 amc.modulate(modulation_order,codec_ix,input.mid(0,l), 00906 transmitted,symbols,3*word_length/(log2(modulation_order))); 00907 00908 }; 00909 00910 }; 00911 00912 00913 void IA2_node::decode_rx_symbols(uint32_t codec_ix, uint32_t modulation_order, int stream_ix) 00914 { 00915 00916 00917 cout << "(" << d_node_ix << "," << stream_ix << ")" << endl; 00918 00919 int l=amc.codec_message_size(codec_ix); 00920 00921 if (use_old_rand) { 00922 RNG_reset(100+10000*stream_ix+d_seed); 00923 input.set_subvector(0,randb(l)); 00924 } else { 00925 temp_seed=100+10000*stream_ix+d_seed; 00926 amc.randb_thread_safe(0,l,input,&temp_seed) ; 00927 }; 00928 00929 amc.encode(codec_ix,input.mid(0,l),transmitted) ; 00930 00931 00932 amc.demodulate(symbols.mid(0,word_length/log2( modulation_order)), 00933 noise_variance_norm, 00934 modulation_order,codec_ix,message_hat,transmitted_hat); 00935 00936 00937 if (d_run_decoder) { 00938 EVM[ber_i]=amc.evm(modulation_order,transmitted,symbols,0); 00939 SINR[ber_i]=SINR_temp; 00940 }; 00941 00942 berc.clear(); 00943 berc.count(transmitted,transmitted_hat); 00944 BERraw[ber_i]=berc.get_errorrate(); 00945 SINR[ber_i]=SINR_temp; 00946 berc.clear(); 00947 berc.count(input.mid(0,l),message_hat.mid(0,l)); 00948 BER[ber_i]=berc.get_errorrate(); 00949 ber_i++; 00950 00951 00952 00953 00954 if (modulation_order>15) { 00955 00956 if (use_old_rand) { 00957 RNG_reset(110+10000*stream_ix+d_seed); 00958 input.set_subvector(0,randb(l)); 00959 } else { 00960 temp_seed=110+10000*stream_ix+d_seed; 00961 amc.randb_thread_safe(0,l,input,&temp_seed) ; 00962 }; 00963 amc.encode(codec_ix,input.mid(0,l),transmitted) ; 00964 00965 amc.demodulate(symbols.mid(word_length/log2( modulation_order), 00966 word_length/log2( modulation_order)), 00967 noise_variance_norm, 00968 modulation_order,codec_ix,message_hat,transmitted_hat); 00969 00970 00971 if (d_run_decoder) { 00972 EVM[ber_i]=amc.evm(modulation_order,transmitted,symbols, 00973 word_length/(log2(modulation_order))); 00974 SINR[ber_i]=SINR_temp; 00975 }; 00976 00977 berc.clear(); 00978 berc.count(transmitted,transmitted_hat); 00979 BERraw[ber_i]=berc.get_errorrate(); 00980 //cout << "BER(raw)=" << BERraw[ber_i] << endl; 00981 berc.clear(); 00982 berc.count(input.mid(0,l),message_hat.mid(0,l)); 00983 BER[ber_i]=berc.get_errorrate(); 00984 //cout << "BER=" << BER[ber_i] << endl; 00985 ber_i++; 00986 00987 }; 00988 00989 if (modulation_order>63) { 00990 00991 if (use_old_rand) { 00992 RNG_reset(120+10000*stream_ix+d_seed); 00993 input.set_subvector(0,randb(l)); 00994 } else { 00995 temp_seed=120+10000*stream_ix+d_seed; 00996 amc.randb_thread_safe(0,l,input,&temp_seed) ; 00997 00998 }; 00999 amc.encode(codec_ix,input.mid(0,l),transmitted) ; 01000 01001 amc.demodulate(symbols.mid(2*word_length/log2( modulation_order), 01002 word_length/log2( modulation_order)), 01003 noise_variance_norm, 01004 modulation_order,codec_ix,message_hat,transmitted_hat); 01005 01006 01007 if (d_run_decoder) { 01008 EVM[ber_i]=amc.evm(modulation_order,transmitted,symbols, 01009 2*word_length/(log2(modulation_order))); 01010 SINR[ber_i]=SINR_temp; 01011 }; 01012 01013 berc.clear(); 01014 berc.count(transmitted,transmitted_hat); 01015 BERraw[ber_i]=berc.get_errorrate(); 01016 //cout << "BER(raw)=" << BER[0] << endl; 01017 berc.clear(); 01018 berc.count(input.mid(0,l),message_hat.mid(0,l)); 01019 BER[ber_i]=berc.get_errorrate(); 01020 //cout << "BER=" << BER[0] << endl; 01021 ber_i++; 01022 01023 }; 01024 if (modulation_order>255) { 01025 01026 if (use_old_rand) { 01027 RNG_reset(130+10000*stream_ix+d_seed); 01028 input.set_subvector(0,randb(l)); 01029 } else { 01030 temp_seed=130+10000*stream_ix+d_seed; 01031 amc.randb_thread_safe(0,l,input,&temp_seed) ; 01032 }; 01033 01034 amc.encode(codec_ix,input.mid(0,l),transmitted) ; 01035 amc.demodulate(symbols.mid(3*word_length/log2( modulation_order), 01036 word_length/log2( modulation_order)), 01037 noise_variance_norm, 01038 modulation_order,codec_ix,message_hat,transmitted_hat); 01039 01040 if (d_run_decoder) { 01041 EVM[ber_i]=amc.evm(modulation_order,transmitted,symbols, 01042 3*word_length/(log2(modulation_order))); 01043 SINR[ber_i]=SINR_temp; 01044 }; 01045 01046 berc.clear(); 01047 berc.count(transmitted,transmitted_hat); 01048 BERraw[ber_i]=berc.get_errorrate(); 01049 //cout << "BER(raw)=" << BER[0] << endl; 01050 berc.clear(); 01051 berc.count(input.mid(0,l),message_hat.mid(0,l)); 01052 BER[ber_i]=berc.get_errorrate(); 01053 //cout << "BER=" << BER[0] << endl; 01054 ber_i++; 01055 01056 }; 01057 01058 };