IA_CoMP
Interference Alignment and Coordinated Multipoint
IA1/IA1_node.hpp
00001 //
00002 // Copyright 2011-2013, Per Zetterberg, 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 #ifndef IA1_NODE_EXAMPLE_HPP
00019 #define IA1_NODE_EXAMPLE_HPP
00020 
00021 #include <uhd/device.hpp>
00022 #include <uhd/utils/thread_priority.hpp>
00023 #include <uhd/utils/safe_main.hpp>
00024 #include <uhd/usrp/multi_usrp.hpp>
00025 #include <iostream>
00026 #include <complex>
00027 #include <uhd/types/clock_config.hpp>
00028 #include <four_multi/gps.hpp>
00029 #include <four_multi/four_multi.hpp>
00030 #include <four_multi/modem_OFDM1.hpp>
00031 #include <four_multi/AMC.hpp>
00032 #include <itpp/itbase.h>
00033 #include <itpp/itcomm.h>
00034 #include <itpp/stat/misc_stat.h>
00035 
00036 
00037 using namespace itpp;
00038 
00050 class IA1_node : public four_multi_node {
00051 
00052    public:
00053    
00054 
00091    IA1_node(uint32_t no_ant1, uint32_t no_ant2 , uint32_t skip_ant, 
00092            float start_gain,  uint32_t node_ix , double frequency,
00093             bool use_same_antenna,std::vector<std::string> IP_addresses,
00094             bool simulate, int receiver_delay_samples,int seed, 
00095             bool run_decoder, int scenario);
00096 
00097    uint32_t frame_ix(void ){ return d_frame_ix;};
00098    int codec_ix, modulation_order; // Codec index, and modulation order used with LDPC code.
00099 
00100    double offset_time;
00101   
00102    ~IA1_node();
00103   
00104    double get_gain(void) {return d_gain_rx;};
00105    std::vector<OFDM1> ai;
00106   //OFDM1 ai[3];  // Maximum 3 streams per node.
00107    uint32_t num_streams_per_bs; 
00108    uint32_t num_streams_per_ms; 
00109    uint32_t num_antennas_in_system; 
00110   
00111    cmat waveform_rx;
00112    cvec waveform_tx, waveform_tx_temp; 
00113 
00115    vec BERraw;
00117    vec BER;
00118 
00119    vec EVM;
00120    vec SINR;
00121    double SINR_temp;
00122    int ber_i;
00123    bvec input, transmitted;
00124    bvec message_hat, decoded_bits, transmitted_hat;
00125    vec soft_bit;
00126 
00127    cmat H[20][8]; //Channel matrices for beamforming design at the node_ix=0.
00128                  // Max 20 transmitter antennas in system
00129                  // max 8 mobile-station.
00130   
00131    double time_between_frames;
00132 
00136    uint32_t MIMO_active_tx_node_tx;
00138    bool MIMO_closed_loop;
00140    bool MIMO_all_active;
00141 
00142    protected: 
00143 
00144 
00145    virtual frame_settings node_init(void) ;
00146    virtual frame_settings node_process(void) ;
00147    virtual void end_of_run(void) ;
00148 
00149    void calculate_beamformers(void);
00150    void iteration(const cmat v_old,int subcarrier_ix_start,
00151  int subcarrier_ix_stop,
00152                   int increment);
00153 
00154 
00155    static const int iterations = 5;
00156    static const uint32_t block_length=400;
00157    static const uint32_t noise_estimation_start=1000;
00158    static const uint32_t noise_estimation_length=800;
00159    static const uint32_t constraint_length = 3;
00160 
00161    double scaling_tx_signal;
00162    ivec demodulation_position;
00163 
00164    uint32_t d_frame_ix, d_no_frames, scenario;
00165    bool do_calculate_beamformers;
00166    double d_gain_rx, d_gain_tx, d_frequency;
00167   //cmat waveform_rx;
00168   // cvec waveform_tx, waveform_tx_temp; 
00169   //bvec input, transmitted;
00170   //vec soft_bit;
00171    ivec interleaver_sequence;
00172    std::string metric;
00173    double logmax_scale_factor;
00174    bool adaptive_stop;
00175    ivec gen;
00176    BERC berc;
00177    ivec nrof_used_iterations;
00178    double target_rx_base_band_rms_ampl;
00179    ivec reorder_all[10]; // Max 10 streams in the system.
00180    uint32_t num_links, num_bs, num_ms;
00181    uint32_t num_ant_ms, num_ant_bs;
00182    cmat v[10]; // Precoding matrices for the user in question. Max 10 streams.
00183   //cmat u[10]; // Receiver matrices for the user in question. Max 10 streams.
00184    cmat Vbig[10]; // Precoding matrices matrices for all streams
00185                    // Used by node_ix=0.. Max 10 streams.
00186   //cmat Ubig[10]; // Receiver matrices for all streams. Max 10 streams.
00187                      // Used by node_ix=0.
00188 
00189    cvec symbols; // Transmit signal of a stream.
00190   
00191   
00192 
00193    std::complex<int16_t> *feedback_buffer; // Place to store samples used for 
00194                                            // RX to TX feedback
00195 
00196    std::complex<int16_t> *feedback_buffer0; // Place to store samples used for 
00197                                            // RX to TX feedback
00198 
00199    std::complex<int16_t> *feedback_buffer1; // Place to store samples used for 
00200                                            // RX to TX feedback
00201 
00202    std::complex<int16_t> *feedback_buffer2; // Place to store samples used for 
00203                                            // RX to TX feedback
00204 
00205    std::vector<uint32_t> other_node_ixs;
00206    std::vector<void  *> pointers_to_data;
00207    std::vector<uint32_t> num_bytess;
00208    
00209 
00210    int feedback_buffer_size; // RX->TX
00211    int feedback_buffer_size_tx; // TX->TX
00212 
00213    ivec antenna_pilot_position;
00214    ivec antenna_pilot_position_this_bs;
00215    ivec known_pos_all;
00216    bool is_bs;
00217 
00218    uint32_t shift_transmit_signal_samples;
00219    uint32_t replicas_start;
00220    uint32_t replicas_spacing;
00221    ivec replica_positions_this_bs;
00222    ivec replica_positions;
00223 
00224    ivec stream_ix_this_node;
00225    imat bs_to_stream_ix;
00226    ivec stream_ix_to_ms_ix;
00227    int d_seed;
00228    uint32_t num_streams; // Total number of streams in the system.
00229 
00230    void normalize_columns(cmat &M);
00231    void calculate_v(void);
00232 
00233    void format_tx_symbols(uint32_t codec_ix, uint32_t modulation_order, int stream_ix);
00234    void decode_rx_symbols(uint32_t codec_ix, uint32_t modulation_order, int stream_ix);
00235    AMC amc; // Adaptive coding and modulation object
00236    int word_length; // Code-word length
00237    double noise_variance_norm;
00238    bool d_run_decoder;
00239    uint64_t temp_seed;
00240    bool use_old_rand;
00241 
00242    Real_Timer timer;
00243 };
00244 
00245 
00246 
00247 #endif
 All Classes Functions Variables