示例#1
0
bvec decode(Convolutional_Code& nsc, int constraint_length, const bvec& decoder_input, int blockSize, bool verbose)
{
  BPSK mod;
  vec decoder_input_mod = mod.modulate_bits(decoder_input);
  int codedLen = 2 * (blockSize + (constraint_length - 1));
  int nBlock_rcvd = decoder_input_mod.length() / codedLen;
  if (verbose) {cout << "rcvd number of blocks : " << nBlock_rcvd << endl;}
  
  vec codedBlock(codedLen);
  bvec bit_rcvd_tmp(blockSize);
  bvec bit_decoded;
  
  for (int j = 0; j < nBlock_rcvd; j++) {
    for (int k = 0; k < codedLen; k++) {
      codedBlock[k] = decoder_input_mod[k + j*codedLen];
    }
    //cout << codedBlock << endl;
    bit_rcvd_tmp = nsc.decode_tail(codedBlock);
    bit_decoded = concat(bit_decoded, bit_rcvd_tmp);
  }
  
  // Deal with residual sources if remainder exsists
  vec residual_bits = decoder_input_mod.get(nBlock_rcvd*codedLen, decoder_input_mod.length()-1);
  nsc.decode_tail( residual_bits, bit_rcvd_tmp);
  bit_decoded = concat(bit_decoded, bit_rcvd_tmp);
  
  if (verbose) {cout << "decode output : " << bit_decoded << endl;}
  return bit_decoded;
}
示例#2
0
int main()
{
  cout << "======================================" << endl;
  cout << "    Test of pulse shaping routines    " << endl;
  cout << "======================================" << endl << endl;

  BPSK bpsk;
  vec symbols, samples, rsymbols;
  Root_Raised_Cosine<double> rrc_tx(0.5), rrc_rx(0.5);
  Raised_Cosine<double> rc_tx(0.5);

  bpsk.modulate_bits(randb(20), symbols);
  samples = rrc_tx.shape_symbols(symbols);
  rsymbols = rrc_rx.shape_samples(samples);

  cout << "*** Root Raised Cosine; real input ***" << endl << endl;
  cout << "pulse, RRC = " << round_to_zero(rrc_tx.get_pulse_shape())
       << endl << endl;
  cout << "symbols = " << round_to_zero(symbols) << endl << endl;
  cout << "samples = " << round_to_zero(samples) << endl << endl;
  cout << "received symbols =" << fixed << round_to_zero(rsymbols) << endl << endl;

  samples = rc_tx.shape_symbols(symbols);

  cout << "*** Raised Cosine; real input ***" << endl << endl;
  cout << "pulse, RC = " << fixed << round_to_zero(rc_tx.get_pulse_shape())
       << endl << endl;
  cout << "symbols = " << fixed << round_to_zero(symbols) << endl << endl;
  cout << "samples = " << fixed << round_to_zero(samples) << endl << endl;

  QPSK qpsk;
  cvec csymbols, csamples, crsymbols;
  Root_Raised_Cosine<complex<double> > crrc_tx(0.5), crrc_rx(0.5);
  Raised_Cosine<complex<double> > crc_tx(0.5);

  qpsk.modulate_bits(randb(40), csymbols);
  csamples = crrc_tx.shape_symbols(csymbols);
  crsymbols = crrc_rx.shape_samples(csamples);

  cout << "*** Root Raised Cosine; complex input ***" << endl << endl;
  cout << "pulse, RRC = " << fixed << round_to_zero(crrc_tx.get_pulse_shape())
       << endl << endl;
  cout << "symbols = " << fixed << round_to_zero(csymbols) << endl << endl;
  cout << "samples = " << fixed << round_to_zero(csamples) << endl << endl;
  cout << "received symbols = " << fixed << round_to_zero(crsymbols) << endl << endl;

  csamples = crc_tx.shape_symbols(csymbols);

  cout << "*** Raised Cosine; complex input ***" << endl << endl;
  cout << "pulse, RC = " << fixed << round_to_zero(crc_tx.get_pulse_shape())
       << endl << endl;
  cout << "symbols = " << fixed << round_to_zero(csymbols) << endl << endl;
  cout << "samples = " << fixed << round_to_zero(csamples) << endl << endl;

  return 0;
}
示例#3
0
int main(void)
{
    //general parameters
    double threshold_value = 10;
    string map_metric="maxlogMAP";
    ivec gen = "07 05";//octal form, feedback first
    int constraint_length = 3;
    int nb_errors_lim = 3000;
    int nb_bits_lim = int(1e6);
    int perm_len = (1<<14);//total number of bits in a block (with tail)
    int nb_iter = 10;//number of iterations in the turbo decoder
    vec EbN0_dB = "0:0.1:5";
    double R = 1.0/3.0;//coding rate (non punctured PCCC)
    double Ec = 1.0;//coded bit energy

    //other parameters
    int nb_bits = perm_len-(constraint_length-1);//number of bits in a block (without tail)
    vec sigma2 = (0.5*Ec/R)*pow(inv_dB(EbN0_dB), -1.0);//N0/2
    double Lc;//scaling factor
    int nb_blocks;//number of blocks
    int nb_errors;
    ivec perm(perm_len);
    ivec inv_perm(perm_len);
    bvec bits(nb_bits);
    int cod_bits_len = perm_len*gen.length();
    bmat cod1_bits;//tail is added
    bvec tail;
    bvec cod2_input;
    bmat cod2_bits;
    int rec_len = int(1.0/R)*perm_len;
    bvec coded_bits(rec_len);
    vec rec(rec_len);
    vec dec1_intrinsic_coded(cod_bits_len);
    vec dec2_intrinsic_coded(cod_bits_len);
    vec apriori_data(perm_len);//a priori LLR for information bits
    vec extrinsic_coded(perm_len);
    vec extrinsic_data(perm_len);
    bvec rec_bits(perm_len);
    int snr_len = EbN0_dB.length();
    mat ber(nb_iter,snr_len);
    ber.zeros();
    register int en,n;

    //Recursive Systematic Convolutional Code
    Rec_Syst_Conv_Code cc;
    cc.set_generator_polynomials(gen, constraint_length);//initial state should be the zero state

    //BPSK modulator
    BPSK bpsk;

    //AWGN channel
    AWGN_Channel channel;

    //SISO modules
    SISO siso;
    siso.set_generators(gen, constraint_length);
    siso.set_map_metric(map_metric);

    //BER
    BERC berc;

    //Randomize generators
    RNG_randomize();

    //main loop
    for (en=0;en<snr_len;en++)
    {
        cout << "EbN0_dB = " << EbN0_dB(en) << endl;
        channel.set_noise(sigma2(en));
        Lc = -2/sigma2(en);//normalisation factor for intrinsic information (take into account the BPSK mapping)
        nb_errors = 0;
        nb_blocks = 0;
        while ((nb_errors<nb_errors_lim) && (nb_blocks*nb_bits<nb_bits_lim))
        {
            //permutation
            perm = sort_index(randu(perm_len));
            //inverse permutation
            inv_perm = sort_index(perm);

            //bits generation
            bits = randb(nb_bits);

            //parallel concatenated convolutional code
            cc.encode_tail(bits, tail, cod1_bits);//tail is added here to information bits to close the trellis
            cod2_input = concat(bits, tail);
            cc.encode(cod2_input(perm), cod2_bits);
            for (n=0;n<perm_len;n++)//output with no puncturing
            {
                coded_bits(3*n) = cod2_input(n);//systematic output
                coded_bits(3*n+1) = cod1_bits(n,0);//first parity output
                coded_bits(3*n+2) = cod2_bits(n,0);//second parity output
            }

            //BPSK modulation (1->-1,0->+1) + AWGN channel
            rec = channel(bpsk.modulate_bits(coded_bits));

            //form input for SISO blocks
            for (n=0;n<perm_len;n++)
            {
                dec1_intrinsic_coded(2*n) = Lc*rec(3*n);
                dec1_intrinsic_coded(2*n+1) = Lc*rec(3*n+1);
                dec2_intrinsic_coded(2*n) = 0.0;//systematic output of the CC is already used in decoder1
                dec2_intrinsic_coded(2*n+1) = Lc*rec(3*n+2);
            }
            //turbo decoder
            apriori_data.zeros();//a priori LLR for information bits
            for (n=0;n<nb_iter;n++)
            {
                //first decoder (terminated trellis)
                siso.rsc(extrinsic_coded, extrinsic_data, dec1_intrinsic_coded, apriori_data, true);
                //interleave
                apriori_data = extrinsic_data(perm);
                //threshold
                apriori_data = SISO::threshold(apriori_data, threshold_value);
                //second decoder (unterminated trellis)
                siso.rsc(extrinsic_coded, extrinsic_data, dec2_intrinsic_coded, apriori_data);

                //decision
                apriori_data += extrinsic_data;//a posteriori information
                rec_bits = bpsk.demodulate_bits(-apriori_data(inv_perm));//take into account the BPSK mapping
                //count errors
                berc.clear();
                berc.count(bits, rec_bits.left(nb_bits));
                ber(n,en) += berc.get_errorrate();

                //deinterleave for the next iteration
                apriori_data = extrinsic_data(inv_perm);
            }//end iterations
            nb_errors += int(berc.get_errors());//get number of errors at the last iteration
            nb_blocks++;
        }//end blocks (while loop)

        //compute BER over all tx blocks
        ber.set_col(en, ber.get_col(en)/nb_blocks);
    }

    it_file ff("pccc_bersim_awgn.it");
    ff << Name("EbN0_dB") << EbN0_dB;
    ff << Name("BER") << ber;
    ff.close();

    return 0;
}
示例#4
0
int main()
{
    RNG_reset(12345);

    cout << "===========================================================" << endl;
    cout << "                    Test of Modulators                     " << endl;
    cout << "===========================================================" << endl;

    const int no_symbols = 5;
    const double N0 = 0.1;

    {
        cout << endl << "Modulator_1D (configured as BPSK)" << endl;
        Modulator_1D  mod("1.0 -1.0", "0 1");
        int bps = round_i(mod.bits_per_symbol());

        bvec tx_bits = randb(no_symbols * bps);
        ivec tx_sym_numbers = randi(no_symbols, 0, pow2i(bps) - 1);
        vec noise = sqrt(N0) * randn(no_symbols);

        vec tx_symbols = mod.modulate_bits(tx_bits);
        vec rx_symbols = tx_symbols + noise;
        bvec decbits = mod.demodulate_bits(rx_symbols);

        cout << "* modulating bits:" << endl;
        cout << "  tx_bits         = " << tx_bits << endl;
        cout << "  tx_symbols      = " << tx_symbols << endl;
        cout << "  rx_symbols      = " << rx_symbols << endl;
        cout << "  decbits         = " << decbits << endl;

        tx_symbols = mod.modulate(tx_sym_numbers);
        rx_symbols = tx_symbols + noise;
        ivec dec_sym_numbers = mod.demodulate(rx_symbols);

        cout << "* modulating symbol numbers:" << endl;
        cout << "  tx_sym_numbers  = " << tx_sym_numbers << endl;
        cout << "  tx_symbols      = " << tx_symbols << endl;
        cout << "  rx_symbols      = " << rx_symbols << endl;
        cout << "  dec_sym_numbers = " << dec_sym_numbers << endl;

        cout << endl << "BPSK (real signal)" << endl;
        BPSK bpsk;

        bpsk.modulate_bits(tx_bits, tx_symbols);
        rx_symbols = tx_symbols + noise;
        bpsk.demodulate_bits(rx_symbols, decbits);

        cout << "* modulating bits:" << endl;
        cout << "  tx_bits         = " << tx_bits << endl;
        cout << "  tx_symbols      = " << tx_symbols << endl;
        cout << "  rx_symbols      = " << rx_symbols << endl;
        cout << "  decbits         = " << decbits << endl;

        cout << endl << "BPSK (complex signal)" << endl;
        BPSK_c bpsk_c;

        cvec tx_csymbols = bpsk_c.modulate_bits(tx_bits);
        cvec rx_csymbols = tx_csymbols + to_cvec(noise, -noise);
        decbits = bpsk_c.demodulate_bits(rx_csymbols);
        vec softbits_approx = bpsk_c.demodulate_soft_bits(rx_csymbols, N0, APPROX);
        vec softbits = bpsk_c.demodulate_soft_bits(rx_csymbols, N0, LOGMAP);

        cout << "* modulating bits:" << endl;
        cout << "  tx_bits         = " << tx_bits << endl;
        cout << "  tx_csymbols     = " << tx_csymbols << endl;
        cout << "  rx_csymbols     = " << rx_csymbols << endl;
        cout << "  decbits         = " << decbits << endl;
        cout << "  softbits        = " << softbits << endl;
        cout << "  softbits_approx = " << softbits_approx << endl << endl;
    }

    cout << "===========================================================" << endl;

    {
        cout << endl << "Modulator_1D (configured as 4-PAM)" << endl;
        Modulator_1D mod("-3.0 -1.0 1.0 3.0", "0 1 3 2");
        int bps = round_i(mod.bits_per_symbol());

        bvec tx_bits = randb(no_symbols * bps);
        ivec tx_sym_numbers = randi(no_symbols, 0, pow2i(bps) - 1);
        vec noise = sqrt(N0) * randn(no_symbols);

        vec tx_symbols = mod.modulate_bits(tx_bits);
        vec rx_symbols = tx_symbols + noise;
        bvec decbits = mod.demodulate_bits(rx_symbols);

        cout << "* modulating bits:" << endl;
        cout << "  tx_bits         = " << tx_bits << endl;
        cout << "  tx_symbols      = " << tx_symbols << endl;
        cout << "  rx_symbols      = " << rx_symbols << endl;
        cout << "  decbits         = " << decbits << endl;

        tx_symbols = mod.modulate(tx_sym_numbers);
        rx_symbols = tx_symbols + noise;
        ivec dec_sym_numbers = mod.demodulate(rx_symbols);

        cout << "* modulating symbol numbers:" << endl;
        cout << "  tx_sym_numbers  = " << tx_sym_numbers << endl;
        cout << "  tx_symbols      = " << tx_symbols << endl;
        cout << "  rx_symbols      = " << rx_symbols << endl;
        cout << "  dec_sym_numbers = " << dec_sym_numbers << endl;

        cout << endl << "4-PAM (real signal)" << endl;
        PAM pam(4);

        pam.modulate_bits(tx_bits, tx_symbols);
        rx_symbols = tx_symbols + noise;
        pam.demodulate_bits(rx_symbols, decbits);

        cout << "* modulating bits:" << endl;
        cout << "  tx_bits         = " << tx_bits << endl;
        cout << "  tx_symbols      = " << tx_symbols << endl;
        cout << "  rx_symbols      = " << rx_symbols << endl;
        cout << "  decbits         = " << decbits << endl;

        cout << endl << "4-PAM (complex signal)" << endl;
        PAM_c pam_c(4);

        cvec tx_csymbols = pam_c.modulate_bits(tx_bits);
        cvec rx_csymbols = tx_csymbols + to_cvec(noise, -noise);
        decbits = pam_c.demodulate_bits(rx_csymbols);
        vec softbits_approx = pam_c.demodulate_soft_bits(rx_csymbols, N0, APPROX);
        vec softbits = pam_c.demodulate_soft_bits(rx_csymbols, N0, LOGMAP);

        cout << "* modulating bits:" << endl;
        cout << "  tx_bits         = " << tx_bits << endl;
        cout << "  tx_csymbols     = " << tx_csymbols << endl;
        cout << "  rx_csymbols     = " << rx_csymbols << endl;
        cout << "  decbits         = " << decbits << endl;
        cout << "  softbits        = " << softbits << endl;
        cout << "  softbits_approx = " << softbits_approx << endl << endl;
    }

    cout << "===========================================================" << endl;

    {
        cout << endl << "Modulator_2D (configured as 256-QAM)" << endl;
        QAM qam(256);
        Modulator_2D mod(qam.get_symbols(), qam.get_bits2symbols());
        int bps = round_i(mod.bits_per_symbol());

        bvec tx_bits = randb(no_symbols * bps);
        ivec tx_sym_numbers = randi(no_symbols, 0, pow2i(bps) - 1);
        cvec noise = sqrt(N0) * randn_c(no_symbols);

        cvec tx_symbols = mod.modulate(tx_sym_numbers);
        cvec rx_symbols = tx_symbols + noise;
        ivec dec_sym_numbers = mod.demodulate(rx_symbols);

        cout << "* modulating symbol numbers:" << endl;
        cout << "  tx_sym_numbers  = " << tx_sym_numbers << endl;
        cout << "  tx_symbols      = " << tx_symbols << endl;
        cout << "  rx_symbols      = " << rx_symbols << endl;
        cout << "  dec_sym_numbers = " << dec_sym_numbers << endl;

        tx_symbols = mod.modulate_bits(tx_bits);
        rx_symbols = tx_symbols + noise;
        bvec decbits = mod.demodulate_bits(rx_symbols);
        vec softbits_approx = mod.demodulate_soft_bits(rx_symbols, N0, APPROX);
        vec softbits = mod.demodulate_soft_bits(rx_symbols, N0, LOGMAP);

        cout << "* modulating bits:" << endl;
        cout << "  tx_bits         = " << tx_bits << endl;
        cout << "  tx_symbols      = " << tx_symbols << endl;
        cout << "  rx_symbols      = " << rx_symbols << endl;
        cout << "  decbits         = " << decbits << endl;
        cout << "  softbits        = " << softbits << endl;
        cout << "  softbits_approx = " << softbits_approx << endl;

        cout << endl << "256-QAM" << endl;

        tx_symbols = qam.modulate(tx_sym_numbers);
        rx_symbols = tx_symbols + noise;
        dec_sym_numbers = qam.demodulate(rx_symbols);

        cout << "* modulating symbol numbers:" << endl;
        cout << "  tx_sym_numbers  = " << tx_sym_numbers << endl;
        cout << "  tx_symbols      = " << tx_symbols << endl;
        cout << "  rx_symbols      = " << rx_symbols << endl;
        cout << "  dec_sym_numbers = " << dec_sym_numbers << endl;

        tx_symbols = qam.modulate_bits(tx_bits);
        rx_symbols = tx_symbols + noise;
        decbits = qam.demodulate_bits(rx_symbols);
        softbits_approx = qam.demodulate_soft_bits(rx_symbols, N0, APPROX);
        softbits = qam.demodulate_soft_bits(rx_symbols, N0, LOGMAP);

        cout << "* modulating bits:" << endl;
        cout << "  tx_bits         = " << tx_bits << endl;
        cout << "  tx_symbols      = " << tx_symbols << endl;
        cout << "  rx_symbols      = " << rx_symbols << endl;
        cout << "  decbits         = " << decbits << endl;
        cout << "  softbits        = " << softbits << endl;
        cout << "  softbits_approx = " << softbits_approx << endl << endl;
    }

    cout << "===========================================================" << endl;

    {
        cout << endl << "8-PSK" << endl;
        PSK psk(8);
        int bps = round_i(psk.bits_per_symbol());

        bvec tx_bits = randb(no_symbols * bps);
        ivec tx_sym_numbers = randi(no_symbols, 0, pow2i(bps) - 1);
        cvec noise = sqrt(N0) * randn_c(no_symbols);

        cvec tx_symbols = psk.modulate(tx_sym_numbers);
        cvec rx_symbols = tx_symbols + noise;
        ivec dec_sym_numbers = psk.demodulate(rx_symbols);

        cout << "* modulating symbol numbers:" << endl;
        cout << "  tx_sym_numbers  = " << tx_sym_numbers << endl;
        cout << "  tx_symbols      = " << tx_symbols << endl;
        cout << "  rx_symbols      = " << rx_symbols << endl;
        cout << "  dec_sym_numbers = " << dec_sym_numbers << endl;

        tx_symbols = psk.modulate_bits(tx_bits);
        rx_symbols = tx_symbols + noise;
        bvec decbits = psk.demodulate_bits(rx_symbols);
        vec softbits_approx = psk.demodulate_soft_bits(rx_symbols, N0, APPROX);
        vec softbits = psk.demodulate_soft_bits(rx_symbols, N0, LOGMAP);

        cout << "* modulating bits:" << endl;
        cout << "  tx_bits         = " << tx_bits << endl;
        cout << "  tx_symbols      = " << tx_symbols << endl;
        cout << "  rx_symbols      = " << rx_symbols << endl;
        cout << "  decbits         = " << decbits << endl;
        cout << "  softbits        = " << softbits << endl;
        cout << "  softbits_approx = " << softbits_approx << endl << endl;
    }

    cout << "===========================================================" << endl;

    {
        cout << endl << "16-QAM" << endl;
        QAM qam(16);
        int bps = round_i(qam.bits_per_symbol());

        bvec tx_bits = randb(no_symbols * bps);
        ivec tx_sym_numbers = randi(no_symbols, 0, pow2i(bps) - 1);
        cvec noise = sqrt(N0) * randn_c(no_symbols);

        cvec tx_symbols = qam.modulate(tx_sym_numbers);
        cvec rx_symbols = tx_symbols + noise;
        ivec dec_sym_numbers = qam.demodulate(rx_symbols);

        cout << "* modulating symbol numbers:" << endl;
        cout << "  tx_sym_numbers  = " << tx_sym_numbers << endl;
        cout << "  tx_symbols      = " << tx_symbols << endl;
        cout << "  rx_symbols      = " << rx_symbols << endl;
        cout << "  dec_sym_numbers = " << dec_sym_numbers << endl;

        tx_symbols = qam.modulate_bits(tx_bits);
        rx_symbols = tx_symbols + noise;
        bvec decbits = qam.demodulate_bits(rx_symbols);
        vec softbits_approx = qam.demodulate_soft_bits(rx_symbols, N0, APPROX);
        vec softbits = qam.demodulate_soft_bits(rx_symbols, N0, LOGMAP);

        cout << "* modulating bits:" << endl;
        cout << "  tx_bits         = " << tx_bits << endl;
        cout << "  tx_symbols      = " << tx_symbols << endl;
        cout << "  rx_symbols      = " << rx_symbols << endl;
        cout << "  decbits         = " << decbits << endl;
        cout << "  softbits        = " << softbits << endl;
        cout << "  softbits_approx = " << softbits_approx << endl << endl;
    }
}
示例#5
0
    EbN0db = x;
    single_snr_mode = true;
  }

  cout << "Running with Eb/N0: " << EbN0db << endl;

  // High performance: 2500 iterations, high resolution LLR algebra
  C.set_exit_conditions(2500);

  // Alternate high speed settings: 50 iterations, logmax approximation
  // C.set_llrcalc(LLR_calc_unit(12,0,7));

  cout << C << endl;

  int N = C.get_nvar();             // number of bits per codeword
  BPSK Mod;
  bvec bitsin = zeros_b(N);
  vec s = Mod.modulate_bits(bitsin);

  RNG_randomize();

  for (int j = 0; j < length(EbN0db); j++) {
    // Noise variance is N0/2 per dimension
    double N0 = pow(10.0, -EbN0db(j) / 10.0) / C.get_rate();
    AWGN_Channel chan(N0 / 2);
    BERC berc;  // Counters for coded and uncoded BER
    BLERC ferc; // Counter for coded FER
    ferc.set_blocksize(C.get_nvar() - C.get_ncheck());

    for (int64_t i = 0; i < Nbits; i += C.get_nvar()) {
      // Received data
示例#6
0
int main(void)
{
    //general parameters
    double threshold_value = 50;
    string map_metric="logMAP";
    ivec gen = "037 021";//octal form
    int constraint_length = 5;
    int nb_errors_lim = 1500;
    int nb_bits_lim = int(1e6);
    int perm_len = pow2i(14);//permutation length
    int nb_iter = 10;//number of iterations in the turbo decoder
    vec EbN0_dB = "0:0.1:5";
    double R = 1.0/4.0;//coding rate (non punctured SCCC)
    double Ec = 1.0;//coded bit energy

    //other parameters
    string filename = "Res/sccc_"+map_metric+".it";
    int nb_bits_tail = perm_len/gen.length();
    int nb_bits = nb_bits_tail-(constraint_length-1);//number of bits in a block (without tail)
    vec sigma2 = (0.5*Ec/R)*pow(inv_dB(EbN0_dB), -1.0);//N0/2
    double Lc;//scaling factor for intrinsic information
    int nb_blocks;//number of blocks
    int nb_errors;
    bvec bits(nb_bits);//data bits
    bvec nsc_coded_bits;//tail is added
    bmat rsc_parity_bits;
    ivec perm(perm_len);
    ivec inv_perm(perm_len);
    int rec_len = gen.length()*perm_len;
    bvec coded_bits(rec_len);    
    vec rec(rec_len);    
    //SISO RSC
    vec rsc_intrinsic_coded(rec_len);
    vec rsc_apriori_data(perm_len);
    vec rsc_extrinsic_coded;
    vec rsc_extrinsic_data;
    //SISO NSC
    vec nsc_intrinsic_coded(perm_len);
    vec nsc_apriori_data(nb_bits_tail);
    nsc_apriori_data.zeros();//always zero
    vec nsc_extrinsic_coded;
    vec nsc_extrinsic_data;
    //decision
    bvec rec_bits(nb_bits_tail);    
    int snr_len = EbN0_dB.length();
    mat ber(nb_iter,snr_len);
    ber.zeros();
    register int en,n;
    
    //Non recursive non Systematic Convolutional Code
    Convolutional_Code nsc;
    nsc.set_generator_polynomials(gen, constraint_length);
        
    //Recursive Systematic Convolutional Code
    Rec_Syst_Conv_Code rsc;
    rsc.set_generator_polynomials(gen, constraint_length);//initial state should be the zero state
    
    //BPSK modulator
    BPSK bpsk;
    
    //AWGN channel
    AWGN_Channel channel;

    //SISO blocks
    SISO siso;
    siso.set_generators(gen, constraint_length);
    siso.set_map_metric(map_metric);
    
    //BER
    BERC berc;

    //Progress timer
    tr::Progress_Timer timer;
    timer.set_max(snr_len);
            
    //Randomize generators
    RNG_randomize();
    
    //main loop
    timer.progress(0.0);
    for (en=0;en<snr_len;en++)
    {
        channel.set_noise(sigma2(en));
        Lc = -2.0/sigma2(en);//take into account the BPSK mapping
        nb_errors = 0;
        nb_blocks = 0;
        while ((nb_errors<nb_errors_lim) && (nb_blocks*nb_bits<nb_bits_lim))//if at the last iteration the nb. of errors is inferior to lim, then process another block
        {
            //permutation
            perm = sort_index(randu(perm_len));
            //inverse permutation
            inv_perm = sort_index(perm);

            //bits generation
            bits = randb(nb_bits);

            //serial concatenated convolutional code
            nsc.encode_tail(bits, nsc_coded_bits);//tail is added here to information bits to close the trellis
            nsc_coded_bits = nsc_coded_bits(perm);//interleave 
            rsc.encode(nsc_coded_bits, rsc_parity_bits);//no tail added            
            for(n=0;n<perm_len;n++)
            {
            	coded_bits(2*n) = nsc_coded_bits(n);//systematic output
            	coded_bits(2*n+1) = rsc_parity_bits(n,0);//parity output
            }

            //BPSK modulation (1->-1,0->+1) + channel
            rec = channel(bpsk.modulate_bits(coded_bits));

            //turbo decoder
            rsc_intrinsic_coded = Lc*rec;//intrinsic information of coded bits
            rsc_apriori_data.zeros();//a priori LLR for information bits
            for (n=0;n<nb_iter;n++)
            {
                //first decoder
                siso.rsc(rsc_extrinsic_coded, rsc_extrinsic_data, rsc_intrinsic_coded, rsc_apriori_data, false);                
                
                //deinterleave+threshold
                nsc_intrinsic_coded = threshold(rsc_extrinsic_data(inv_perm), threshold_value);
                
                //second decoder
                siso.nsc(nsc_extrinsic_coded, nsc_extrinsic_data, nsc_intrinsic_coded, nsc_apriori_data, true);              

                //decision
                rec_bits = bpsk.demodulate_bits(-nsc_extrinsic_data);//suppose that a priori info is zero
                //count errors
                berc.clear();
                berc.count(bits, rec_bits.left(nb_bits));
                ber(n,en) += berc.get_errorrate();

                //interleave
                rsc_apriori_data = nsc_extrinsic_coded(perm);
            }//end iterations
            nb_errors += int(berc.get_errors());//get number of errors at the last iteration
            nb_blocks++;
        }//end blocks (while loop)

        //compute BER over all tx blocks
        ber.set_col(en, ber.get_col(en)/nb_blocks);

        //show progress
        timer.progress(1+en);
    }
    timer.toc_print();

#ifdef TO_FILE
	//save results to file
    it_file ff(filename);
    ff << Name("BER") << ber;
    ff << Name("EbN0_dB") << EbN0_dB;
    ff << Name("gen") << gen;
    ff << Name("R") << R;
    ff << Name("nb_iter") << nb_iter;
    ff << Name("total_nb_bits") << nb_bits;
    ff << Name("nb_errors_lim") << nb_errors_lim;
    ff << Name("nb_bits_lim") << nb_bits_lim;
    ff.close();
#else
    //show BER
    cout << ber << endl;
#endif    
    
    return 0;
}
示例#7
0
/**	Channel unknown
 * 	ESE with CE
 */
Array<bvec> IdmaRx::receive(cvec &recv_sig, double noise_var, int no_taps) {
	LOG4CXX_DEBUG(logger, "IdmaRx::receive() with CE");
	
	BPSK bpsk;
	int num_user = intls.size();
	int len_recv = recv_sig.size();
	int len_sym = len_recv - no_taps + 1;
	Array<bvec> est_bmsgs(num_user);
	LOG4CXX_TRACE(logger, "recv_sig="<<recv_sig);

	// TODO: To be modified if a convolutional code is not used
	int constraint_length = fec_wrap->get_constraint_length();
	int len_msg = recv_sig.size() * 2 / len_spread * fec_wrap->get_rate();
	if(constraint_length>0)
		len_msg -= constraint_length - 1;
	LOG4CXX_DEBUG(logger, "len_msg="<<len_msg);
	
	// initialize ese
	LOG4CXX_DEBUG(logger, "ce_init"); 
	ese.ce_init(recv_sig, no_taps, noise_var);
	
	// Beginning from zero prior
	Array<vec> llr_priors(num_user);
	for(int i=0; i<llr_priors.size(); i++) 
		llr_priors(i) = zeros(len_recv*2);	// TODO: len_sp_spread
		
	// // Initialize ch_coeffs
	// Array<cmat> ch_coeffs(num_user);
	// for(int i=0; i<num_user; i++) {
		// ch_coeffs(i).set_size(len_sym, no_taps);
	// }
		
	/*  Itarative decoding
	 */
	for(int iter=0; iter<num_iteration; iter++) {
		
		LOG4CXX_TRACE(logger, "================================================");
		LOG4CXX_TRACE(logger, "          ite="<<iter<<"                        ");
		LOG4CXX_TRACE(logger, "================================================");
		
		
		for(int nuser=0; nuser<num_user; nuser++) {
			
			/*	Channel estimation
			 *	Single-path and block fading channel only
			 *	TODO: multipath & time-varying channels
			 */
#ifdef LI_CE
            cvec hval = ese.li_est_ch(nuser, llr_priors(nuser));
#else
			cvec hval = ese.est_ch(nuser, llr_priors(nuser));
#endif
            LOG4CXX_DEBUG(logger, "hval: "<<hval);			

					
			/* SISO */
			// TODO: check 
#ifdef GRAY_IDMA
			vec llr_ese = ese.ce_siso_user(nuser);
#else
			vec llr_ese = ese.ce_siso_user(nuser, recv_sig, *pqam, llr_priors(nuser));
#endif
			
			check_llr(llr_ese);
  			LOG4CXX_TRACE(logger, "llr_ese: "<<llr_ese);
 
			/* de-interleaving */
			vec deintl_llr_ese = intls(nuser).deinterleave(llr_ese);
			LOG4CXX_TRACE(logger, "deintl_llr_ese: "<<deintl_llr_ese);
			
			/* despread */
			vec desp_llr_prior = spreader.llr_despread(deintl_llr_ese);
			LOG4CXX_TRACE(logger, "desp_llr_prior: "<<desp_llr_prior);
			
			/* soft-decoding */
			vec extrinsic_coded;
			vec extrinsic_data;
			vec appllr_coded;

			fec_wrap->inner_soft_decode(desp_llr_prior, extrinsic_coded, extrinsic_data, appllr_coded, true); /*with_padded*/
			LOG4CXX_TRACE(logger, "extrinsic_coded="<<extrinsic_coded);
			LOG4CXX_TRACE(logger, "extrinsic_data="<<extrinsic_data);
			LOG4CXX_DEBUG(logger, "appllr_coded="<<appllr_coded);
			
			est_bmsgs(nuser) = bpsk.demodulate_bits(extrinsic_data).left(len_msg);	// hard-decoding			
			LOG4CXX_TRACE(logger, "est_bmsgs("<<nuser<<"): "<<est_bmsgs(nuser));
			
			/* spread */
			//vec llr_sp_dec = spreader.llr_spread(extrinsic_coded) - deintl_llr_ese;
			vec llr_sp_dec = spreader.llr_spread(appllr_coded) - deintl_llr_ese;
			LOG4CXX_TRACE(logger, "llr_sp_dec: "<<llr_sp_dec);
			
			/* interleaving */
			llr_priors(nuser) = intls(nuser).interleave(llr_sp_dec);
			check_llr(llr_priors(nuser));
			LOG4CXX_TRACE(logger, "llr_priors("<<nuser<<"): "<<llr_priors(nuser));
		}
		mse.calculate(iter, ese.get_h());
	}

	return est_bmsgs;
}
示例#8
0
/**	Channel known
 * 	Original ESE with perfect CSI	
 */
Array<bvec> IdmaRx::receive(cvec &recv_sig, Array<cmat> &ch_coeffs, double noise_var) {
	LOG4CXX_DEBUG(logger, "IdmaRx::receive()");
	
	int no_taps = ch_coeffs(0).cols();
	LOG4CXX_DEBUG(logger, "channel taps = " <<no_taps);
	
	BPSK bpsk;
	int num_user = intls.size();
	int len_recv = recv_sig.size();
	Array<bvec> est_bmsgs(num_user);
	
	// TODO: To be modified if a convolutional code is not used
	int constraint_length = fec_wrap->get_constraint_length();
	int len_tx_sym = recv_sig.size() - no_taps + 1;
	int len_sp_codeword = len_tx_sym * pqam->bits_per_symbol();
	int len_codeword = len_sp_codeword / len_spread;
	int len_msg = len_codeword * fec_wrap->get_rate();
	if(constraint_length>0)
		len_msg -= constraint_length - 1;
		
	LOG4CXX_DEBUG(logger, "constraint_length="<<constraint_length);
    LOG4CXX_DEBUG(logger, "len_tx_sym="<<len_tx_sym);		
	LOG4CXX_DEBUG(logger, "len_sp_codeword="<<len_sp_codeword);
	LOG4CXX_DEBUG(logger, "len_codeword="<<len_codeword);
	LOG4CXX_DEBUG(logger, "len_msg="<<len_msg);
	
	
	// initialize ese
	ese.recv_init(recv_sig, ch_coeffs, noise_var);
	
	// Beginning from zero prior
	Array<vec> llr_priors(num_user);
	for(int i=0; i<llr_priors.size(); i++) 
		llr_priors(i) = zeros(len_sp_codeword);	// TODO: len_sp_spread
	
	for(int iter=0; iter<num_iteration; iter++) {
		
		LOG4CXX_TRACE(logger, "================================================");
		LOG4CXX_TRACE(logger, "          ite="<<iter<<"                        ");
		LOG4CXX_TRACE(logger, "================================================");
		
		for(int nuser=0; nuser<num_user; nuser++) {
			/* ESE */
#ifdef GRAY_IDMA
			vec llr_ese = ese.siso_user(nuser, llr_priors(nuser));
#else
			vec llr_ese = ese.siso_user(nuser, recv_sig, *pqam, llr_priors(nuser));
#endif
			check_llr(llr_ese);
			LOG4CXX_DEBUG(logger, "llr_ese: "<<llr_ese);
			
			/* de-interleaving */
			vec deintl_llr_ese = intls(nuser).deinterleave(llr_ese);
			LOG4CXX_TRACE(logger, "deintl_llr_ese: "<<deintl_llr_ese);
			
			/* despread */
			vec desp_llr_prior = spreader.llr_despread(deintl_llr_ese);
			check_llr(desp_llr_prior);
			LOG4CXX_TRACE(logger, "desp_llr_prior: "<<desp_llr_prior);
			
			/* soft-decoding */
			vec extrinsic_coded;
			vec extrinsic_data;
			vec appllr_coded;
			
			fec_wrap->inner_soft_decode(desp_llr_prior, extrinsic_coded, extrinsic_data, appllr_coded, true); /*with_padded*/
			LOG4CXX_TRACE(logger, "extrinsic_coded="<<extrinsic_coded);
			LOG4CXX_DEBUG(logger, "extrinsic_data="<<extrinsic_data);
			LOG4CXX_DEBUG(logger, "appllr_coded="<<appllr_coded);
			
			est_bmsgs(nuser) = bpsk.demodulate_bits(extrinsic_data).left(len_msg);	// hard-decoding
			LOG4CXX_TRACE(logger, "est_bmsgs("<<nuser<<"): "<<est_bmsgs(nuser));
			
			/* spread */
			//vec llr_sp_dec = spreader.llr_spread(extrinsic_coded) - deintl_llr_ese;
			vec llr_sp_dec = spreader.llr_spread(appllr_coded) - deintl_llr_ese;
			LOG4CXX_DEBUG(logger, "llr_sp_dec: "<<llr_sp_dec);
			
			/* interleaving */
			llr_priors(nuser) = intls(nuser).interleave(llr_sp_dec);
			check_llr(llr_priors(nuser));
			LOG4CXX_TRACE(logger, "llr_priors("<<nuser<<"): "<<llr_priors(nuser));
		}
	}
	
	return est_bmsgs;
}
int main(void)
{
  //general parameters
  double threshold_value = 50;
  string map_metric = "maxlogMAP";
  ivec gen = "07 05";//octal notation
  int constraint_length = 3;
  int ch_nb_taps = 4;//number of channel multipaths
  int nb_errors_lim = 3000;
  int nb_bits_lim = int(1e6);
  int perm_len = pow2i(14);//permutation length
  int nb_iter = 10;//number of iterations in the turbo decoder
  vec EbN0_dB = "0:0.5:10";
  double R = 1.0 / 2.0;//coding rate of FEC
  double Ec = 1.0;//coded bit energy
#ifdef USE_PRECODER
  ivec prec_gen = "03 02";//octal notation
  int prec_gen_length = 2;
#endif

  //other parameters
  int nb_bits_tail = perm_len / gen.length();
  int nb_bits = nb_bits_tail - (constraint_length - 1);//number of bits in a block (without tail)
  vec sigma2 = (0.5 * Ec / R) * pow(inv_dB(EbN0_dB), -1.0);//N0/2
  int nb_blocks;//number of blocks
  int nb_errors;
  bvec bits(nb_bits);//data bits
  bvec nsc_coded_bits(perm_len);//tail is added
  bvec em_bits(perm_len);
  bmat parity_bits;
  ivec perm(perm_len);
  ivec inv_perm(perm_len);
  vec rec(perm_len);
  //SISO equalizer
  vec eq_apriori_data(perm_len);
  vec eq_extrinsic_data;
  //SISO NSC
  vec nsc_intrinsic_coded(perm_len);
  vec nsc_apriori_data(nb_bits_tail);
  nsc_apriori_data.zeros();//always zero
  vec nsc_extrinsic_coded;
  vec nsc_extrinsic_data;
  //decision
  bvec rec_bits(nb_bits_tail);
  int snr_len = EbN0_dB.length();
  mat ber(nb_iter, snr_len);
  ber.zeros();
  register int en, n;

  //CCs
  Convolutional_Code nsc;
  nsc.set_generator_polynomials(gen, constraint_length);
#ifdef USE_PRECODER
  Rec_Syst_Conv_Code prec;
  prec.set_generator_polynomials(prec_gen, prec_gen_length);
#endif

  //BPSK
  BPSK bpsk;

  //AWGN
  AWGN_Channel awgn;

  //multipath channel impulse response (Rayleigh fading) with real coefficients
  vec ch_imp_response(ch_nb_taps);
  vec ini_state = ones(ch_nb_taps);//initial state is zero
  MA_Filter<double, double, double> multipath_channel;

  //SISO blocks
  SISO siso;
  siso.set_generators(gen, constraint_length);
  siso.set_map_metric(map_metric);
#ifdef USE_PRECODER
  siso.set_precoder_generator(prec_gen(0), prec_gen_length);
#endif

  //BER
  BERC berc;

  //Randomize generators
  RNG_randomize();

  //main loop
  for (en = 0;en < snr_len;en++) {
    cout << "EbN0_dB = " << EbN0_dB(en) << endl;
    awgn.set_noise(sigma2(en));
    siso.set_noise(sigma2(en));
    nb_errors = 0;
    nb_blocks = 0;
    while ((nb_errors < nb_errors_lim) && (nb_blocks*nb_bits < nb_bits_lim))//if at the last iteration the nb. of errors is inferior to lim, then process another block
    {
      //permutation
      perm = sort_index(randu(perm_len));
      //inverse permutation
      inv_perm = sort_index(perm);

      //bits generation
      bits = randb(nb_bits);

      //convolutional code
      nsc.encode_tail(bits, nsc_coded_bits);//tail is added here to information bits to close the trellis

      //permutation
      em_bits = nsc_coded_bits(perm);

#ifdef USE_PRECODER
      //precoder
      prec.encode(em_bits, parity_bits);
      em_bits = parity_bits.get_col(0);
#endif

      //BPSK modulation (1->-1,0->+1) + multipath channel
      ch_imp_response = randray(ch_nb_taps);
      ch_imp_response /= sqrt(sum_sqr(ch_imp_response));//normalized power profile
      multipath_channel.set_coeffs(ch_imp_response);
      multipath_channel.set_state(ini_state);//inital state is zero
      rec = awgn(multipath_channel(bpsk.modulate_bits(em_bits)));

      //turbo equalizer
      eq_apriori_data.zeros();//a priori information of emitted symbols
      siso.set_impulse_response(ch_imp_response);
      for (n = 0;n < nb_iter;n++)
      {
        //first decoder
        siso.equalizer(eq_extrinsic_data, rec, eq_apriori_data, false);//no tail
        //deinterleave+threshold
        nsc_intrinsic_coded = SISO::threshold(eq_extrinsic_data(inv_perm), threshold_value);
        //second decoder
        siso.nsc(nsc_extrinsic_coded, nsc_extrinsic_data, nsc_intrinsic_coded, nsc_apriori_data, true);//tail

        //decision
        rec_bits = bpsk.demodulate_bits(-nsc_extrinsic_data);//assume that a priori info is zero
        //count errors
        berc.clear();
        berc.count(bits, rec_bits.left(nb_bits));
        ber(n, en) += berc.get_errorrate();

        //interleave
        eq_apriori_data = nsc_extrinsic_coded(perm);
      }//end iterations
      nb_errors += int(berc.get_errors());//get number of errors at the last iteration
      nb_blocks++;
    }//end blocks (while loop)

    //compute BER over all tx blocks
    ber.set_col(en, ber.get_col(en) / nb_blocks);
  }

  //save results to file
  it_file ff("turbo_equalizer_bersim_multipath.it");
  ff << Name("BER") << ber;
  ff << Name("EbN0_dB") << EbN0_dB;
  ff.close();

  return 0;
}
示例#10
0
TEST(SISO, all)
{
    //general parameters
    string map_metric="maxlogMAP";
    ivec gen = "07 05";//octal form, feedback first
    int constraint_length = 3;
    int nb_errors_lim = 300;
    int nb_bits_lim = int(1e4);
    int perm_len = (1<<14);//total number of bits in a block (with tail)
    int nb_iter = 10;//number of iterations in the turbo decoder
    vec EbN0_dB = "0.0 0.5 1.0 1.5 2.0";
    double R = 1.0/3.0;//coding rate (non punctured PCCC)
    double Ec = 1.0;//coded bit energy

    //other parameters
    int nb_bits = perm_len-(constraint_length-1);//number of bits in a block (without tail)
    vec sigma2 = (0.5*Ec/R)*pow(inv_dB(EbN0_dB), -1.0);//N0/2
    double Lc;//scaling factor
    int nb_blocks;//number of blocks
    int nb_errors;
    ivec perm(perm_len);
    ivec inv_perm(perm_len);
    bvec bits(nb_bits);
    int cod_bits_len = perm_len*gen.length();
    bmat cod1_bits;//tail is added
    bvec tail;
    bvec cod2_input;
    bmat cod2_bits;
    int rec_len = int(1.0/R)*perm_len;
    bvec coded_bits(rec_len);
    vec rec(rec_len);
    vec dec1_intrinsic_coded(cod_bits_len);
    vec dec2_intrinsic_coded(cod_bits_len);
    vec apriori_data(perm_len);//a priori LLR for information bits
    vec extrinsic_coded(perm_len);
    vec extrinsic_data(perm_len);
    bvec rec_bits(perm_len);
    int snr_len = EbN0_dB.length();
    mat ber(nb_iter,snr_len);
    ber.zeros();
    register int en,n;

    //Recursive Systematic Convolutional Code
    Rec_Syst_Conv_Code cc;
    cc.set_generator_polynomials(gen, constraint_length);//initial state should be the zero state

    //BPSK modulator
    BPSK bpsk;

    //AWGN channel
    AWGN_Channel channel;

    //SISO modules
    SISO siso;
    siso.set_generators(gen, constraint_length);
    siso.set_map_metric(map_metric);

    //BER
    BERC berc;

    //Fix random generators
    RNG_reset(12345);

    //main loop
    for (en=0;en<snr_len;en++)
    {
        channel.set_noise(sigma2(en));
        Lc = -2/sigma2(en);//normalisation factor for intrinsic information (take into account the BPSK mapping)
        nb_errors = 0;
        nb_blocks = 0;
        while ((nb_errors<nb_errors_lim) && (nb_blocks*nb_bits<nb_bits_lim))//if at the last iteration the nb. of errors is inferior to lim, then process another block
        {
            //permutation
            perm = sort_index(randu(perm_len));
            //inverse permutation
            inv_perm = sort_index(perm);

            //bits generation
            bits = randb(nb_bits);

            //parallel concatenated convolutional code
            cc.encode_tail(bits, tail, cod1_bits);//tail is added here to information bits to close the trellis
            cod2_input = concat(bits, tail);
            cc.encode(cod2_input(perm), cod2_bits);
            for (n=0;n<perm_len;n++)//output with no puncturing
            {
                coded_bits(3*n) = cod2_input(n);//systematic output
                coded_bits(3*n+1) = cod1_bits(n,0);//first parity output
                coded_bits(3*n+2) = cod2_bits(n,0);//second parity output
            }

            //BPSK modulation (1->-1,0->+1) + AWGN channel
            rec = channel(bpsk.modulate_bits(coded_bits));

            //form input for SISO blocks
            for (n=0;n<perm_len;n++)
            {
                dec1_intrinsic_coded(2*n) = Lc*rec(3*n);
                dec1_intrinsic_coded(2*n+1) = Lc*rec(3*n+1);
                dec2_intrinsic_coded(2*n) = 0.0;//systematic output of the CC is already used in decoder1
                dec2_intrinsic_coded(2*n+1) = Lc*rec(3*n+2);
            }
            //turbo decoder
            apriori_data.zeros();//a priori LLR for information bits
            for (n=0;n<nb_iter;n++)
            {
                //first decoder
               siso.rsc(extrinsic_coded, extrinsic_data, dec1_intrinsic_coded, apriori_data, true);
                //interleave
                apriori_data = extrinsic_data(perm);
                //second decoder
                siso.rsc(extrinsic_coded, extrinsic_data, dec2_intrinsic_coded, apriori_data, false);

                //decision
                apriori_data += extrinsic_data;//a posteriori information
                rec_bits = bpsk.demodulate_bits(-apriori_data(inv_perm));//take into account the BPSK mapping
                //count errors
                berc.clear();
                berc.count(bits, rec_bits.left(nb_bits));
                ber(n,en) += berc.get_errorrate();

                //deinterleave for the next iteration
                apriori_data = extrinsic_data(inv_perm);
            }//end iterations
            nb_errors += int(berc.get_errors());//get number of errors at the last iteration
            nb_blocks++;
        }//end blocks (while loop)

        //compute BER over all tx blocks
        ber.set_col(en, ber.get_col(en)/nb_blocks);
    }

    // Results for max log MAP algorithm
    vec ref = "0.158039 0.110731 0.0770358 0.0445611 0.0235014";
    assert_vec(ref, ber.get_row(0));
    ref = "0.14168 0.0783177 0.0273471 0.00494445 0.00128189";
    assert_vec(ref, ber.get_row(1));
    ref = "0.141375 0.0565865 0.00817971 0.000305213 0";
    assert_vec(ref, ber.get_row(2));
    ref = "0.142412 0.0421194 0.000732511 0 0";
    assert_vec(ref, ber.get_row(3));
    ref = "0.144244 0.0282017 0.000183128 0 0";
    assert_vec(ref, ber.get_row(4));
    ref = "0.145587 0.0142229 0 0 0";
    assert_vec(ref, ber.get_row(5));
    ref = "0.148517 0.00714199 0 0 0";
    assert_vec(ref, ber.get_row(6));
    ref = "0.141619 0.00225858 0 0 0";
    assert_vec(ref, ber.get_row(7));
    ref = "0.149676 0.000549383 0 0 0";
    assert_vec(ref, ber.get_row(8));
    ref = "0.14461 0 0 0 0";
    assert_vec(ref, ber.get_row(9));
}
示例#11
0
文件: IDMA.cpp 项目: haocui/turbosiso
int main(void)
{
    //general parameters
    string mud_method = "maxlogTMAP";
    int nb_usr = 2;
    int spreading_factor = 16;
#ifdef USE_CC
    string map_metric="maxlogMAP";
    ivec gen = "037 021";
    int constraint_length = 5;
    spreading_factor = 8;
#endif
    double threshold_value = 50;
    int ch_nb_taps = 4;//number of channel multipaths
    int nb_errors_lim = 1500;
    int nb_bits_lim = int(1e3);//int(1e6);
    int perm_len = 1024;//38400;//permutation length
    int nb_iter = 15;//number of iterations in the turbo decoder
    vec EbN0_dB = "10";//"0:10:20";
    double Ec = 1.0;//chip energy

#ifdef USE_CC
    int inv_R = spreading_factor*gen.length();
#else
    int inv_R = spreading_factor;
#endif
    double R = 1.0/double(inv_R);//coding rate

    //other parameters
    string filename = "IDMA_"+mud_method+"_"+to_str(nb_usr)+".it";
#ifdef USE_CC
    filename = "cc"+filename;
#endif
    filename = "Res/"+filename;
    int nb_bits = perm_len/inv_R;//number of bits in a block
    vec sigma2 = (0.5*Ec/R)*pow(inv_dB(EbN0_dB), -1.0);//N0/2
    int nb_blocks = 0;//number of blocks
    int nb_errors = 0;//number of errors
    bmat bits(nb_usr,nb_bits);//data bits
#ifdef USE_CC
    bvec coded_bits(nb_bits*gen.length());
    vec mod_bits(nb_bits*gen.length());
#else
    vec mod_bits(nb_bits);
#endif
    vec chips(perm_len);
    imat perm(nb_usr,perm_len);
    imat inv_perm(nb_usr,perm_len);
    vec em(perm_len);
    vec rec(perm_len+ch_nb_taps-1);//padding zeros are added

    //SISO MUD
    mat mud_apriori_data(nb_usr,perm_len);
    mat mud_extrinsic_data;

    //SISO decoder (scrambler or CC)
    vec dec_intrinsic_coded(perm_len);
    vec dec_apriori_data(nb_bits);
    dec_apriori_data.zeros();//always zero
    vec dec_extrinsic_coded;
    vec dec_extrinsic_data;

    //decision
    bvec rec_bits(nb_bits);
    int snr_len = EbN0_dB.length();
    mat ber(nb_iter,snr_len);
    ber.zeros();
    register int en,n,u;

#ifdef USE_CC
    //CC
    Convolutional_Code nsc;
    nsc.set_generator_polynomials(gen, constraint_length);
#endif

    //BPSK
    BPSK bpsk;

    //scrambler pattern
    vec pattern = kron(ones(spreading_factor/2), vec("1.0 -1.0"));

    //AWGN
    AWGN_Channel awgn;
    //multipath channel impulse response (Rayleigh fading) with real coefficients
    vec single_ch(ch_nb_taps);
    mat ch_imp_response(nb_usr, ch_nb_taps);
    vec ini_state = zeros(ch_nb_taps);
    MA_Filter<double,double,double> multipath_channel(ini_state);
    multipath_channel.set_state(ini_state);//initial state is always 0 due to Zero Padding technique
    vec padding_zeros = zeros(ch_nb_taps-1);

    //SISO blocks
    SISO siso;
    siso.set_scrambler_pattern(pattern);
    siso.set_mud_method(mud_method);
#ifdef USE_CC
    siso.set_generators(gen, constraint_length);
    siso.set_map_metric(map_metric);
    siso.set_tail(false);
#endif

    //BER
    BERC berc;

    //progress timer
    tr::Progress_Timer timer;
    timer.set_max(snr_len);

    //Randomize generators
    RNG_randomize();

    //main loop
    timer.progress(0.0);
    for (en=0; en<snr_len; en++)
    {
        awgn.set_noise(sigma2(en));
        siso.set_noise(sigma2(en));
        nb_errors = 0;
        nb_blocks = 0;
        while ((nb_errors<nb_errors_lim) && (nb_blocks*nb_bits<nb_bits_lim))//if at the last iteration the nb. of errors is inferior to lim, then process another block
        {
            rec.zeros();
            for (u=0; u<nb_usr; u++)
            {
                //permutation
                perm.set_row(u, sort_index(randu(perm_len)));
                //inverse permutation
                inv_perm.set_row(u, sort_index(perm.get_row(u)));

                //bits generation
                bits.set_row(u, randb(nb_bits));

#ifdef USE_CC
                //convolutional code
                nsc.encode(bits.get_row(u), coded_bits);//no tail

                //BPSK modulation (1->-1,0->+1)
                mod_bits = bpsk.modulate_bits(coded_bits);
#else
                //BPSK modulation (1->-1,0->+1)
                mod_bits = bpsk.modulate_bits(bits.get_row(u));
#endif

                //scrambler
                chips = kron(mod_bits, pattern);

                //permutation
                em = chips(perm.get_row(u));

                //multipath channel
                single_ch = randray(ch_nb_taps);
                single_ch /= sqrt(sum_sqr(single_ch));//normalized power profile
                ch_imp_response.set_row(u, single_ch);
                multipath_channel.set_coeffs(ch_imp_response.get_row(u));
                rec += multipath_channel(concat(em, padding_zeros));//Zero Padding
            }
            rec = awgn(rec);

            //turbo MUD
            mud_apriori_data.zeros();//a priori LLR of emitted symbols
            siso.set_impulse_response(ch_imp_response);
            for (n=0; n<nb_iter; n++)
            {
                //MUD
                siso.mud(mud_extrinsic_data, rec, mud_apriori_data);
                berc.clear();//mean error rate over all users
                for (u=0; u<nb_usr; u++)
                {
                    //deinterleave
                    dec_intrinsic_coded = mud_extrinsic_data.get_row(u)(inv_perm.get_row(u));
#ifdef USE_CC
                    //decoder+descrambler
                    siso.nsc(dec_extrinsic_coded, dec_extrinsic_data, dec_intrinsic_coded, dec_apriori_data);
#else
                    //descrambler
                    siso.descrambler(dec_extrinsic_coded, dec_extrinsic_data, dec_intrinsic_coded, dec_apriori_data);
#endif
                    //decision
                    rec_bits = bpsk.demodulate_bits(-dec_extrinsic_data);//suppose that a priori info is zero
                    //count errors
                    berc.count(bits.get_row(u), rec_bits);
                    //interleave+threshold
                    mud_apriori_data.set_row(u, threshold(dec_extrinsic_coded(perm.get_row(u)), threshold_value));
                }
                ber(n,en) += berc.get_errorrate();
            }//end iterations
            nb_errors += int(berc.get_errors());//get number of errors at the last iteration
            nb_blocks++;
        }//end blocks (while loop)

        //compute BER over all tx blocks
        ber.set_col(en, ber.get_col(en)/nb_blocks);

        //show progress
        timer.progress(1+en);
    }
    timer.toc_print();

    //save results to file
#ifdef TO_FILE
    it_file ff(filename);
    ff << Name("BER") << ber;
    ff << Name("EbN0_dB") << EbN0_dB;
    ff << Name("nb_usr") << nb_usr;
    ff << Name("gen") << spreading_factor;
    ff << Name("nb_iter") << nb_iter;
    ff << Name("total_nb_bits") << nb_bits;
    ff << Name("nb_errors_lim") << nb_errors_lim;
    ff << Name("nb_bits_lim") << nb_bits_lim;
#ifdef USE_CC
    ff << Name("gen") << gen;
#endif
    ff.close();
#else
    //show BER
    cout << ber << endl;
#endif

    return 0;
}
示例#12
0
int main(int argc, char *argv[])
{
	//receiver parameters
	ivec gen = "0133 0171";
	int constraint_length = 7;
	int const_size = 16;//constellation size
	int coherence_time = 512;//expressed in symbol durations, multiple of T, T<=coherence_time<=tx_duration, T is the ST code duration
	double threshold_value = 50;
	string map_metric="maxlogMAP";
	string demapper_method = "mmsePIC";//Hassibi_maxlogMAP or GA or sGA or mmsePIC or zfPIC or Alamouti_maxlogMAP
	int nb_errors_lim = 1500;
	int nb_bits_lim = int(1e6);
	int perm_len = pow2i(14);//permutation length
	int nb_iter = 5;//number of iterations in the turbo decoder
	int rec_antennas = 2;//number of reception antennas
	vec EbN0_dB = "0:20";
	double Es = 1.0;//mean symbol energy
	int em_antennas = 2;//number of emission antennas
	int channel_uses = 1;//ST code duration
	string code_name = "V-BLAST_MxN";//V-BLAST_MxN, Golden_2x2, Damen_2x2, Alamouti_2xN
	bool ideal_channel = false;
	bool to_file = false;

	//get parameters if any
	if (EXIT_FAILURE == get_opts(argc, argv, demapper_method, const_size,
			nb_errors_lim, nb_bits_lim, perm_len, nb_iter, rec_antennas, em_antennas,
			channel_uses, code_name, ideal_channel, to_file, EbN0_dB))
	{
		print_help(argv[0]);
		return EXIT_FAILURE;
	}

	//convolutional code generator polynomials
	Convolutional_Code nsc;
	nsc.set_generator_polynomials(gen, constraint_length);
	double coding_rate = 1.0/2.0;

	//QAM modulator class
	QAM mod(const_size);

	//Space-Time code parameters
	STC st_block_code(code_name, const_size, em_antennas, channel_uses);//generate matrices for LD code (following Hassibi's approach)
	int symb_block = st_block_code.get_nb_symbols_per_block();
	em_antennas = st_block_code.get_nb_emission_antenna();//these parameters could by changed depending on the selected code
	channel_uses = st_block_code.get_channel_uses();

	//recompute interleaver length
	int G = coherence_time*mod.bits_per_symbol()*symb_block;
	perm_len = G*(perm_len/G);//recompute interleaver length
	int block_len = int(coding_rate*perm_len);//informational block length
	int nb_symb = perm_len/mod.bits_per_symbol();//number of symbols at the modulator output
	int nb_subblocks = nb_symb/symb_block;//number of blocks of ST code emitted in an interleaver period
	int tx_duration = channel_uses*nb_subblocks;//transmission duration expressed in number of symbol periods

	//show configuration parameters
	std::cout << "const_size = " << const_size
	<< "\ndemapper_method = " << demapper_method
	<< "\nnb_errors_lim = " << nb_errors_lim
	<< "\nnb_bits_lim = " << nb_bits_lim
	<< "\nperm_len = " << perm_len
	<< "\ncode_name = " << code_name
	<< "\nem_antennas = " << em_antennas
	<< "\nchannel_uses = " << channel_uses
	<< "\nnb_iter = " << nb_iter
	<< "\nrec_antennas = " << rec_antennas
	<< "\nEbN0_dB = " << EbN0_dB << std::endl;
	if (true == ideal_channel)
	{
		if (em_antennas == rec_antennas)
		{
			std::cout << "Using ideal AWGN MIMO channel (no MAI)" << std::endl;
		} else
		{
			std::cout << "Warning: cannot use ideal AWGN MIMO channel" << std::endl;
			ideal_channel = false;
		}
	} else
	{
		std::cout << "Using random MIMO channel (with MAI)" << std::endl;
	}

	//fading channel parameters
	if (coherence_time%channel_uses)//check if the coherence time is a multiple of channel_uses
	{
		coherence_time = channel_uses*(coherence_time/channel_uses);
		std::cout << "Warning! The coherence time must be a multiple of T. Choosing coherence_time=channel_uses*floor(coherence_time/channel_uses) = "\
				<< coherence_time << std::endl;
	}
	if (coherence_time>tx_duration)
	{
		coherence_time = channel_uses*(tx_duration/channel_uses);
		std::cout << "Warning! The coherence time must be <= tx_duration. Choosing coherence_time = channel_uses*floor(tx_duration/channel_uses) = "\
				<< coherence_time << std::endl;
	}
	cmat fading_pattern = ones_c(1, coherence_time/channel_uses);

	//other parameters
	string filename = "STBICM_"+map_metric+"_"+demapper_method+".it";
	if (true == to_file)
	{
		std::cout << "Saving results to " << filename << std::endl;
	}
	double R = coding_rate*double(mod.bits_per_symbol()*symb_block)/double(channel_uses);//ST code rate in (info.) bits/channel use
	vec sigma2 = (0.5*Es/(R*double(mod.bits_per_symbol())))*pow(inv_dB(EbN0_dB), -1.0);//N0/2
	int nb_blocks;//number of blocks
	int nb_errors;
	bvec bits(block_len);//data bits
	bvec coded_bits(perm_len);//no tail
	cvec em(nb_symb);
	ivec perm(perm_len);
	ivec inv_perm(perm_len);
	//SISO demapper
	vec demapper_apriori_data(perm_len);
	vec demapper_extrinsic_data(perm_len);
	//SISO NSC
	vec nsc_intrinsic_coded(perm_len);
	vec nsc_apriori_data(block_len);
	nsc_apriori_data.zeros();//always zero
	vec nsc_extrinsic_coded(perm_len);
	vec nsc_extrinsic_data(block_len);
	//decision
	bvec rec_bits(block_len);
	int snr_len = EbN0_dB.length();
	mat ber(nb_iter,snr_len);
	ber.zeros();
	register int en,n,ns;
	cmat S(tx_duration, em_antennas);
	cmat rec(tx_duration,rec_antennas);

	//Rayleigh fading
	cmat ch_attenuations(em_antennas*rec_antennas,tx_duration/channel_uses);

	//SISO blocks
	SISO siso;
	siso.set_map_metric(map_metric);
	siso.set_generators(gen, constraint_length);
	siso.set_demapper_method(demapper_method);
	siso.set_constellation(mod.bits_per_symbol(), mod.get_symbols()/sqrt(em_antennas), mod.get_bits2symbols());
	siso.set_st_block_code(st_block_code.get_nb_symbols_per_block(), st_block_code.get_1st_gen_matrix(), st_block_code.get_2nd_gen_matrix(), rec_antennas);

	//decision
	BPSK bpsk;

	//BER
	BERC berc;

	//Randomize generators
	RNG_randomize();

	//main loop
	std::cout << std::endl;
	for (en=0;en<snr_len;en++)
	{
		std::cout << "EbN0_dB = " << EbN0_dB[en] << std::endl;
		siso.set_noise(sigma2(en));
		nb_errors = 0;
		nb_blocks = 0;
		while ((nb_errors<nb_errors_lim) && (nb_blocks*block_len<nb_bits_lim))//if at the last iteration the nb. of errors is inferior to lim, then process another block
		{
			//permutation
			perm = sort_index(randu(perm_len));
			//inverse permutation
			inv_perm = sort_index(perm);

			//bits generation
			bits = randb(block_len);

			//convolutional code
			nsc.encode(bits, coded_bits);//no tail

			//permutation+QAM modulation
			em = mod.modulate_bits(coded_bits(perm))/sqrt(em_antennas);//normalize emitted symbols

			//ST code
			S = st_block_code.encode(em);

			/* channel matrices (there are tx_duration/tau_c different channel matrices MxN)
			 * a channel matrix is represented as a M*Nx1 vector (first M elements are the first column of the channel matrix)
			 * the channel matrix is constant over tau_c symbol periods (a multiple of T symbol durations)
			 * the channel matrix is the transpose of the true channel matrix
			 */
			if (false == ideal_channel)
			{
				ch_attenuations = kron(randn_c(em_antennas*rec_antennas, tx_duration/coherence_time), fading_pattern);
			} else
			{
				cmat mimo_channel = kron(reshape(eye_c(em_antennas),
						em_antennas*rec_antennas, 1), ones_c(1, tx_duration/coherence_time));
				ch_attenuations = kron(mimo_channel, fading_pattern);
			}

			//flat-fading MIMO channel
			for (ns=0;ns<nb_subblocks;ns++)
				rec.set_submatrix(ns*channel_uses, 0, \
						S(ns*channel_uses, (ns+1)*channel_uses-1, 0, em_antennas-1)*reshape(ch_attenuations.get_col(ns), em_antennas, rec_antennas));
			rec += sqrt(2*sigma2(en))*randn_c(tx_duration,rec_antennas);//sigma2 is the variance on each dimension

			//turbo receiver
			demapper_apriori_data.zeros();//a priori information of emitted bits
			siso.set_impulse_response(ch_attenuations);
			for (n=0;n<nb_iter;n++)
			{
				//first decoder
				siso.demapper(demapper_extrinsic_data, rec, demapper_apriori_data);

				//deinterleave+threshold
				nsc_intrinsic_coded = SISO::threshold(demapper_extrinsic_data(inv_perm), threshold_value);

				//second decoder
				siso.nsc(nsc_extrinsic_coded, nsc_extrinsic_data, nsc_intrinsic_coded, nsc_apriori_data, false);

				//decision
				rec_bits = bpsk.demodulate_bits(-nsc_extrinsic_data);//suppose that a priori info is zero
				//count errors
				berc.clear();
				berc.count(bits, rec_bits);
				ber(n,en) += berc.get_errorrate();

				//interleave
				demapper_apriori_data = nsc_extrinsic_coded(perm);
			}//end iterations
			nb_errors += int(berc.get_errors());//get number of errors at the last iteration
			nb_blocks++;
		}//end blocks (while loop)

		//compute BER over all tx blocks
		ber.set_col(en, ber.get_col(en)/nb_blocks);
	}

	if (true == to_file)
	{
		//save results to file
		it_file ff(filename);
		ff << Name("BER") << ber;
		ff << Name("EbN0_dB") << EbN0_dB;
		ff << Name("gen") << gen;
		ff << Name("coding_rate") << coding_rate;
		ff << Name("nb_iter") << nb_iter;
		ff << Name("block_len") << block_len;
		ff << Name("nb_errors_lim") << nb_errors_lim;
		ff << Name("nb_bits_lim") << nb_bits_lim;
		ff << Name("const_size") << const_size;
		ff.close();
	} else
	{
		//show BER
		cout << "BER = " << ber << endl;
	}

	return 0;
}
示例#13
0
TEST(PulseShape, All)
{
  // Test of pulse shaping routines
  RNG_reset(0);

  BPSK bpsk;
  vec symbols, samples, rsymbols;
  Root_Raised_Cosine<double> rrc_tx(0.5), rrc_rx(0.5);
  Raised_Cosine<double> rc_tx(0.5);

  bpsk.modulate_bits(randb(20), symbols);
  samples = rrc_tx.shape_symbols(symbols);
  rsymbols = rrc_rx.shape_samples(samples);

  // Root Raised Cosine; real input
  vec ref = "0.00107181 -0.0027027 -0.00581667 -0.00696875 -0.00530516 -0.000815537 0.00546883 0.0115738 0.0150053 "
  "0.0134306 0.00546883 -0.00861562 -0.0265258 -0.0440088 -0.0554523 -0.0549318 -0.0375132 -0.000532387 0.0554523 "
  "0.126288 0.204577 0.280729 0.344536 0.386975 0.401856 0.386975 0.344536 0.280729 0.204577 0.126288 0.0554523 "
  "-0.000532387 -0.0375132 -0.0549318 -0.0554523 -0.0440088 -0.0265258 -0.00861562 0.00546883 0.0134306 0.0150053 "
  "0.0115738 0.00546883 -0.000815537 -0.00530516 -0.00696875 -0.00581667 -0.0027027 0.00107181";
  assert_vec(ref, rrc_tx.get_pulse_shape());
  ref = "-0.00107181 0.0027027 0.00581667 0.00696875 0.00530516 0.000815537 -0.00546883 -0.0115738 -0.0160771 "
  "-0.0107279 0.000347842 0.0155844 0.031831 0.0448243 0.0499834 0.0433579 0.0214361 -0.0101955 -0.0551044 "
  "-0.110704 -0.172746 -0.235905 -0.294553 -0.343617 -0.38042 -0.397171 -0.399641 -0.391433 -0.377324 -0.362193 "
  "-0.350005 -0.343085 -0.340763 -0.347645 -0.355822 -0.361361 -0.361408 -0.355208 -0.344536 -0.333368 -0.327901 "
  "-0.326952 -0.338719 -0.36384 -0.398545 -0.434626 -0.460562 -0.463676 -0.43401 -0.354878 -0.238753 -0.094032 "
  "0.063662 0.214849 0.339415 0.420138 0.446872 0.414732 0.327782 0.200912 0.0530516 -0.0956631 -0.227815 -0.33173 "
  "-0.401856 -0.442221 -0.461257 -0.465795 -0.462207 -0.453488 -0.438686 -0.413668 -0.373989 -0.304869 -0.216877 "
  "-0.112894 1.38778e-17 0.112894 0.216877 0.304869 0.373989 0.413668 0.438686 0.453488 0.462207 0.465795 0.461257 "
  "0.442221 0.401856 0.33173 0.227815 0.0956631 -0.0530516 -0.200912 -0.327782 -0.414732 -0.446872 -0.420138 "
  "-0.339415 -0.214849 -0.063662 0.094032 0.238753 0.354878 0.431866 0.469082 0.472195 0.448563 0.409155 0.365471 "
  "0.327782 0.303804 0.296819 0.30921 0.339415 0.379408 0.419765 0.450195 0.461257 0.445934 0.399712 0.333422 "
  "0.239448 0.125201 -1.38778e-17 -0.125201 -0.239448 -0.333422 -0.399712 -0.445934 -0.461257 -0.450195 -0.419765 "
  "-0.379408 -0.339415 -0.30921 -0.296819 -0.303804 -0.327782 -0.365471 -0.409155 -0.448563 -0.472195 -0.469082 "
  "-0.431866 -0.354878 -0.238753 -0.094032 0.063662 0.214849 0.339415 0.420138 0.446872 0.414732 0.327782 0.200912 "
  "0.0530516 -0.0956631 -0.227815 -0.33173";
  assert_vec(ref, samples);
  ref = "-1.14877e-06 5.79353e-06 5.16411e-06 -1.65031e-05 -6.01302e-05 -0.000107998 -0.000126412 -7.86767e-05 "
  "5.33562e-05 0.000260324 0.000459271 0.000528627 0.00034915 -0.000140663 -0.000892236 -0.00171907 -0.00231299 "
  "-0.00229884 -0.00137958 0.000562355 0.00336609 0.00655046 0.00935825 0.0108978 0.0103664 0.00732923 0.00192998 "
  "-0.00492754 -0.0115725 -0.0157611 -0.0150763 -0.00748811 0.00802133 0.0308814 0.0586051 0.0867172 0.109087 "
  "0.118648 0.108416 0.0726618 0.00800958 -0.0857266 -0.205223 -0.343836 -0.492374 -0.640337 -0.777394 -0.894844 "
  "-0.986783 -1.05073 -1.08773 -1.10165 -1.09811 -1.08321 -1.06236 -1.03947 -1.01677 -0.995122 -0.974794 -0.956374 "
  "-0.941541 -0.933381 -0.936049 -0.953742 -0.989175 -1.04189 -1.10689 -1.17398 -1.22825 -1.25181 -1.22656 -1.13759 "
  "-0.976659 -0.744793 -0.453718 -0.125306 0.210732 0.520675 0.771508 0.935703 0.995194 0.943845 0.788112 0.545574 "
  "0.241958 -0.0928153 -0.428764 -0.739431 -1.00437 -1.21023 -1.35063 -1.42483 -1.43609 -1.38985 -1.29244 -1.15025 "
  "-0.96958 -0.756879 -0.519122 -0.264014 -2.08438e-17 0.264014 0.519122 0.756879 0.969578 1.15026 1.29245 1.38982 "
  "1.43597 1.42462 1.35038 1.21007 1.00447 0.739946 0.429677 0.0938891 -0.241199 -0.545747 -0.78977 -0.947205 -0.999873 "
  "-0.940561 -0.774727 -0.520079 -0.204349 0.138547 0.473327 0.768307 0.999707 1.15454 1.23178 1.24143 1.20186 "
  "1.13612 1.06763 1.01617 0.994738 1.00769 1.05044 1.11059 1.17023 1.20906 1.20773 1.1509 1.02972 0.843259 0.598789 "
  "0.310972 2.53974e-17 -0.310972 -0.598789 -0.843259 -1.02972 -1.1509 -1.20773 -1.20906 -1.17023 -1.11059 -1.05044 -1.00769";
  assert_vec(ref, rsymbols);

  samples = rc_tx.shape_symbols(symbols);

  // Raised Cosine; real input
  ref = "8.95103e-34 0.00113767 0.00477279 0.0105661 0.0171489 0.0221856 0.0227496 0.015992 -1.29939e-17 -0.0253289 "
  "-0.0576127 -0.0917169 -0.120042 -0.133416 -0.122502 -0.0795251 3.06162e-17 0.115879 0.262504 0.428983 0.600211 "
  "0.758749 0.887236 0.970942 1 0.970942 0.887236 0.758749 0.600211 0.428983 0.262504 0.115879 3.06162e-17 "
  "-0.0795251 -0.122502 -0.133416 -0.120042 -0.0917169 -0.0576127 -0.0253289 -1.29939e-17 0.015992 0.0227496 "
  "0.0221856 0.0171489 0.0105661 0.00477279 0.00113767 8.95103e-34";
  assert_vec(ref, rc_tx.get_pulse_shape());
  ref = "-8.95103e-34 -0.00113767 -0.00477279 -0.0105661 -0.0171489 -0.0221856 -0.0227496 -0.015992 1.29939e-17 "
  "0.0241912 0.0528399 0.0811508 0.102893 0.11123 0.0997521 0.0635331 -1.76223e-17 -0.0916881 -0.209664 "
  "-0.347832 -0.497318 -0.647518 -0.787484 -0.907409 -1 -1.06263 -1.0969 -1.10658 -1.09753 -1.0765 -1.04999 "
  "-1.02329 -1 -0.980829 -0.964853 -0.952033 -0.943189 -0.940413 -0.946876 -0.965975 -1 -1.04975 -1.11237 "
  "-1.17878 -1.23472 -1.26218 -1.24215 -1.15815 -1 -0.767338 -0.47214 -0.137385 0.205787 0.522147 0.777324 "
  "0.942787 1 0.945062 0.78687 0.543279 0.240084 -0.0930137 -0.426641 -0.735354 -1 -1.20653 -1.34783 -1.42448 "
  "-1.44051 -1.40124 -1.31188 -1.17682 -1 -0.786012 -0.541866 -0.276447 3.46945e-17 0.276447 0.541866 0.786012 "
  "1 1.17682 1.31188 1.40124 1.44051 1.42448 1.34783 1.20653 1 0.735354 0.426641 0.0930137 -0.240084 -0.543279 "
  "-0.78687 -0.945062 -1 -0.942787 -0.777324 -0.522147 -0.205787 0.137385 0.47214 0.767338 1 1.15587 1.23261 "
  "1.24105 1.20042 1.13441 1.06687 1.01777 1 1.0155 1.05733 1.11328 1.16612 1.19668 1.18711 1.12389 1 0.81572 "
  "0.57782 0.299687 6.93889e-18 -0.299687 -0.57782 -0.81572 -1 -1.12389 -1.18711 -1.19668 -1.16612 -1.11328 "
  "-1.05733 -1.0155 -1 -1.01777 -1.06687 -1.13441 -1.20042 -1.24105 -1.23261 -1.15587 -1 -0.767338 -0.47214 "
  "-0.137385 0.205787 0.522147 0.777324 0.942787 1 0.945062 0.78687 0.543279 0.240084 -0.0930137 -0.426641 -0.735354";
  assert_vec(ref, samples);

  QPSK qpsk;
  cvec csymbols, csamples, crsymbols;
  Root_Raised_Cosine<complex<double> > crrc_tx(0.5), crrc_rx(0.5);
  Raised_Cosine<complex<double> > crc_tx(0.5);

  qpsk.modulate_bits(randb(40), csymbols);
  csamples = crrc_tx.shape_symbols(csymbols);
  crsymbols = crrc_rx.shape_samples(csamples);

  // Root Raised Cosine; complex input
  ref = "0.00107181 -0.0027027 -0.00581667 -0.00696875 -0.00530516 -0.000815537 0.00546883 0.0115738 0.0150053 "
  "0.0134306 0.00546883 -0.00861562 -0.0265258 -0.0440088 -0.0554523 -0.0549318 -0.0375132 -0.000532387 0.0554523 "
  "0.126288 0.204577 0.280729 0.344536 0.386975 0.401856 0.386975 0.344536 0.280729 0.204577 0.126288 0.0554523 "
  "-0.000532387 -0.0375132 -0.0549318 -0.0554523 -0.0440088 -0.0265258 -0.00861562 0.00546883 0.0134306 0.0150053 "
  "0.0115738 0.00546883 -0.000815537 -0.00530516 -0.00696875 -0.00581667 -0.0027027 0.00107181";
  assert_vec(ref, crrc_tx.get_pulse_shape());
  cvec ref_c = "0.00107181+0i -0.0027027+0i -0.00581667+0i -0.00696875+0i -0.00530516+0i -0.000815537+0i 0.00546883+0i "
  "0.0115738+0i 0.0150053-0.00107181i 0.0134306+0.0027027i 0.00546883+0.00581667i -0.00861562+0.00696875i "
  "-0.0265258+0.00530516i -0.0440088+0.000815537i -0.0554523-0.00546883i -0.0549318-0.0115738i -0.0364414-0.0150053i "
  "-0.00323508-0.0134306i 0.0496356-0.00546883i 0.119319+0.00861562i 0.199272+0.0265258i 0.279913+0.0440088i "
  "0.350005+0.0554523i 0.398549+0.0549318i 0.415789+0.0375132i 0.403109+0.000532387i 0.355822-0.0554523i "
  "0.279082-0.126288i 0.183357-0.204577i 0.083095-0.280729i -0.00546883-0.344536i -0.067038-0.386975i "
  "-0.0900316-0.402928i -0.0688947-0.384273i -0.00546883-0.338719i 0.0908951-0.27376i 0.204577-0.199272i "
  "0.316122-0.125473i 0.405457-0.0609211i 0.455338-0.0110414i 0.454374+0.0214361i 0.399082+0.0442039i "
  "0.294553+0.0558001i 0.153625+0.0595931i -0.00530516+0.0583568i -0.161409+0.0534399i -0.294901+0.0445146i "
  "-0.39021+0.0299274i -0.439369+0.00750264i -0.439204-0.024472i -0.394172-0.0663899i -0.317769-0.116857i "
  "-0.225798-0.172746i -0.134088-0.229751i -0.0554523-0.283267i 0.00238914-0.329341i 0.0375132-0.366486i "
  "0.053075-0.38374i 0.0554523-0.394172i 0.0518088-0.400048i 0.0477465-0.40385i 0.0456556-0.406202i 0.0441668-0.405457i "
  "0.0387985-0.398017i 0.0235797-0.38042i -0.0110414-0.342772i -0.0609211-0.288736i -0.125473-0.221136i "
  "-0.199272-0.146221i -0.27376-0.0728483i -0.338719-0.0109377i -0.384273+0.0304597i -0.402928+0.0460876i "
  "-0.386975+0.027757i -0.344536-0.0167543i -0.280729-0.079817i -0.204577-0.151526i -0.126288-0.221951i "
  "-0.0554523-0.283267i 0.000532387-0.331198i 0.0375132-0.366486i 0.0549318-0.381884i 0.0554523-0.394172i "
  "0.0440088-0.407848i 0.0265258-0.42507i 0.00861562-0.443242i -0.00546883-0.455093i -0.0134306-0.450246i "
  "-0.0150053-0.419005i -0.0115738-0.343304i -0.00546883-0.233284i 0.000815537-0.0948476i 0.00530516+0.0583568i "
  "0.00696875+0.207881i 0.00581667+0.333598i 0.0027027+0.417435i -0.00214361+0.446872i 0.0027027+0.417435i "
  "0.00581667+0.333598i 0.00696875+0.207881i 0.00530516+0.0583568i 0.000815537-0.0948476i -0.00546883-0.233284i "
  "-0.0115738-0.343304i -0.0139335-0.417933i -0.0161333-0.452949i -0.0112855-0.460909i 0.00164687-0.45021i "
  "0.0212207-0.430376i 0.0431932-0.408664i 0.0609211-0.388703i 0.0665056-0.37031i 0.0525185-0.349337i "
  "0.013963-0.323172i -0.0499834-0.289432i -0.134904-0.244504i -0.231103-0.188662i -0.324738-0.125457i "
  "-0.399988-0.0612689i -0.441907-0.00402706i -0.439369+0.0375132i -0.387508+0.0594912i -0.289084+0.0612689i "
  "-0.154441+0.0431774i 0+0.0106103i 0.154441-0.0276089i 0.289084-0.0605732i 0.387508-0.0772335i 0.439369-0.0696673i "
  "0.441907-0.0228341i 0.399988+0.0503313i 0.324738+0.142688i 0.231103+0.241714i 0.134904+0.332522i "
  "0.0499834+0.400336i -0.013963+0.433036i -0.0525185+0.424364i -0.0665056+0.371374i -0.0609211+0.277798i "
  "-0.0431932+0.156088i -0.0212207+0.0212207i -0.00164687-0.111247i 0.0112855-0.228163i 0.0161333-0.321002i "
  "0.0128617-0.386851i 0.0142765-0.427944i 0.0112855-0.449972i 0.00615321-0.459641i 0-0.462207i -0.00615321-0.459641i "
  "-0.0112855-0.449972i -0.0142765-0.427944i -0.0150053-0.386851i -0.0107279-0.321002i 0.000347842-0.228163i "
  "0.0155844-0.111247i 0.031831+0.0212207i 0.0448243+0.156088i 0.0499834+0.277798i 0.0433579+0.371374i";
  assert_cvec(ref_c, csamples);
  ref_c = "1.14877e-06+0i -5.79353e-06+0i -5.16411e-06+0i 1.65031e-05+0i 6.01302e-05+0i 0.000107998+0i 0.000126412+0i "
  "7.86767e-05+0i -5.4505e-05-1.14877e-06i -0.00025453+5.79353e-06i -0.000454107+5.16411e-06i -0.00054513-1.65031e-05i "
  "-0.00040928-6.01302e-05i 3.26645e-05-0.000107998i 0.000765824-0.000126412i 0.00164039-7.86767e-05i 0.00236749+5.4505e-05i "
  "0.00255337+0.00025453i 0.00183369+0.000454107i -1.72249e-05+0.00054513i -0.00295681+0.00040928i -0.00658312-3.26645e-05i "
  "-0.0101241-0.000765824i -0.0125382-0.00164039i -0.0127351-0.00236634i -0.00987681-0.00255917i -0.0037585-0.00183885i "
  "0.00492827+3.37281e-05i 0.0144692+0.00301694i 0.0222362+0.00669112i 0.025074+0.0102505i 0.0199476+0.0126168i "
  "0.00476824+0.0126783i -0.0207501+0.00963387i -0.0543925+0.00331472i -0.0911003-0.0055064i -0.123147-0.0149987i "
  "-0.140917-0.0224196i -0.134256-0.024561i -0.0942497-0.0184646i -0.0151453-0.00229404i 0.103923+0.0238241i "
  "0.257782+0.0571447i 0.434953+0.0921403i 0.618478+0.120889i 0.787837+0.134052i 0.921774+0.122347i 1.00163+0.0782734i "
  "1.01466-0.00221228i 0.956699-0.118415i 0.833718-0.264315i 0.661716-0.428851i 0.464984-0.597096i 0.272817-0.752176i "
  "0.11513-0.877604i 0.0176536-0.959653i -0.002492-0.989322i 0.0599364-0.963554i 0.19683-0.885613i 0.387394-0.764307i "
  "0.600932-0.612504i 0.801383-0.445158i 0.952877-0.277241i 1.02542-0.121958i 0.999715+0.0104849i 0.870345+0.113445i "
  "0.646754+0.183694i 0.35175+0.220843i 0.0179555+0.226489i -0.317224+0.203352i -0.617217+0.154598i -0.85153+0.0834514i "
  "-0.999734-0.00690592i -1.05361-0.113243i -1.01727-0.23207i -0.905208-0.359534i -0.739017-0.491435i -0.543387-0.623365i "
  "-0.342212-0.750929i -0.155501-0.869953i 0.0024659-0.976598i 0.123583-1.0673i 0.205125-1.13875i 0.248149-1.18759i "
  "0.255608-1.21042i 0.230749-1.20393i 0.176161-1.1654i 0.0936737-1.09351i -0.0149818-0.989149i -0.147035-0.856266i "
  "-0.297489-0.702322i -0.458324-0.538057i -0.618418-0.376641i -0.764341-0.232223i -0.881946-0.118129i -0.958448-0.0450215i "
  "-0.984588-0.0194324i -0.956366-0.0429516i -0.876067-0.112261i -0.752127-0.219976i -0.597975-0.356077i -0.430049-0.509566i "
  "-0.26535-0.66993i -0.119003-0.828077i -0.00226564-0.976543i 0.0786795-1.109i 0.123049-1.21942i 0.13483-1.30095i "
  "0.121478-1.34543i 0.0922487-1.34353i 0.056495-1.28597i 0.0222508-1.16543i -0.00471259-0.978988i -0.0212782-0.730363i "
  "-0.0268539-0.431444i -0.022931-0.102415i -0.0123911+0.229627i 0.00121738+0.533584i 0.014331+0.77839i 0.0238911+0.937463i "
  "0.027724+0.992771i 0.0248041+0.937721i 0.0153989+0.778308i 0.00116749+0.532195i -0.0149386+0.22602i -0.0289689-0.108637i "
  "-0.0365239-0.439825i -0.0335619-0.739512i -0.0173931-0.986829i 0.0122953-1.16976i 0.0526101-1.28527i 0.097069-1.33769i "
  "0.135887-1.33623i 0.15705-1.29218i 0.148128-1.21637i 0.0986329-1.11756i 0.00250145-1.00187i -0.139753-0.873213i "
  "-0.319742-0.734629i -0.521149-0.589586i -0.721122-0.443193i -0.893044-0.302671i -1.01032-0.176894i -1.05062-0.0750385i "
  "-0.999736-0.00463313i -0.854513+0.0305213i -0.624153+0.0319934i -0.329421+0.00743645i -6.01302e-05-0.0299373i "
  "0.329297-0.0631639i 0.624032-0.0743647i 0.85444-0.0481098i 0.999787+0.0253505i 1.05088+0.147654i 1.01079+0.31122i "
  "0.893556+0.499822i 0.721411+0.690715i 0.520901+0.858007i 0.318724+0.976665i 0.137955+1.02644i";
  assert_cvec(ref_c, crsymbols);

  csamples = crc_tx.shape_symbols(csymbols);

  // Raised Cosine; complex input
  ref = "8.95103e-34 0.00113767 0.00477279 0.0105661 0.0171489 0.0221856 0.0227496 0.015992 -1.29939e-17 -0.0253289 "
  "-0.0576127 -0.0917169 -0.120042 -0.133416 -0.122502 -0.0795251 3.06162e-17 0.115879 0.262504 0.428983 0.600211 "
  "0.758749 0.887236 0.970942 1 0.970942 0.887236 0.758749 0.600211 0.428983 0.262504 0.115879 3.06162e-17 -0.0795251 "
  "-0.122502 -0.133416 -0.120042 -0.0917169 -0.0576127 -0.0253289 -1.29939e-17 0.015992 0.0227496 0.0221856 0.0171489 "
  "0.0105661 0.00477279 0.00113767 8.95103e-34";
  assert_vec(ref, crc_tx.get_pulse_shape());
  ref_c = "8.95103e-34+0i 0.00113767+0i 0.00477279+0i 0.0105661+0i 0.0171489+0i 0.0221856+0i 0.0227496+0i 0.015992+0i "
  "-1.29939e-17-8.95103e-34i -0.0253289-0.00113767i -0.0576127-0.00477279i -0.0917169-0.0105661i -0.120042-0.0171489i "
  "-0.133416-0.0221856i -0.122502-0.0227496i -0.0795251-0.015992i 3.06162e-17+1.29939e-17i 0.117017+0.0253289i "
  "0.267277+0.0576127i 0.439549+0.0917169i 0.61736+0.120042i 0.780934+0.133416i 0.909986+0.122502i 0.986934+0.0795251i "
  "1-3.06162e-17i 0.944475-0.115879i 0.824851-0.262504i 0.656466-0.428983i 0.46302-0.600211i 0.273381-0.758749i "
  "0.117252-0.887236i 0.0203623-0.970942i 7.42262e-17-1i 0.0616832-0.972079i 0.197615-0.892009i 0.387284-0.769315i "
  "0.600211-0.61736i 0.800447-0.451168i 0.952125-0.285253i 1.02514-0.131871i 1-1.76223e-17i 0.871054+0.103716i "
  "0.647482+0.175342i 0.351951+0.214566i 0.0171489+0.222935i -0.3192+0.202947i -0.61996+0.157365i -0.853925+0.088862i "
  "-1-4.62836e-18i -1.0516-0.106542i -1.01451-0.227641i -0.90273-0.359451i -0.737402-0.497318i -0.542885-0.635899i "
  "-0.342866-0.769507i -0.1572-0.892554i -3.06162e-17-1i 0.120846-1.08796i 0.202864-1.15451i 0.247318-1.1983i "
  "0.257233-1.21757i 0.235699-1.20992i 0.184887-1.17249i 0.105992-1.10281i -1.76223e-17-1i -0.131871-0.867225i "
  "-0.285253-0.711894i -0.451168-0.544182i -0.61736-0.377275i -0.769315-0.226036i -0.892009-0.105139i "
  "-0.972079-0.0270174i -1-3.52445e-17i -0.970942-0.0258797i -0.887236-0.100366i -0.758749-0.21547i "
  "-0.600211-0.360127i -0.428983-0.521996i -0.262504-0.689145i -0.115879-0.851233i -3.06162e-17-1i 0.0795251-1.12928i "
  "0.122502-1.23487i 0.133416-1.3122i 0.120042-1.35476i 0.0917169-1.3539i 0.0576127-1.29976i 0.0253289-1.18348i "
  "1.29939e-17-1i -0.015992-0.751346i -0.0227496-0.449391i -0.0221856-0.115199i -0.0171489+0.222935i "
  "-0.0105661+0.532713i -0.00477279+0.782097i -0.00113767+0.943924i -1.79021e-33+1i -0.00113767+0.943924i "
  "-0.00477279+0.782097i -0.0105661+0.532713i -0.0171489+0.222935i -0.0221856-0.115199i -0.0227496-0.449391i "
  "-0.015992-0.751346i 1.29939e-17-1i 0.0264666-1.18234i 0.0623855-1.29499i 0.102283-1.34333i 0.137191-1.33761i "
  "0.155601-1.29001i 0.145251-1.21213i 0.095517-1.11329i -4.36101e-17-1i -0.141208-0.874287i -0.320116-0.737212i "
  "-0.5207-0.592581i -0.720253-0.445871i -0.892164-0.304514i -1.00974-0.177369i -1.05047-0.0734208i -1-3.06162e-17i "
  "-0.855062+0.0370665i -0.624732+0.0373666i -0.329766+0.00894711i 0-0.0342978i 0.329766-0.0744505i "
  "0.624732-0.0924114i 0.855062-0.0713258i 1+5.6604e-17i 1.05047+0.124079i 1.00974+0.292594i 0.892164+0.487948i "
  "0.720253+0.685955i 0.5207+0.859413i 0.320116+0.982215i 0.141208+1.03334i 4.36101e-17+1i -0.095517+0.881529i "
  "-0.145251+0.687118i -0.155601+0.432049i -0.137191+0.137191i -0.102283-0.174165i -0.0623855-0.479481i "
  "-0.0264666-0.759545i -1.29939e-17-1i 0.0148543-1.19168i 0.0179768-1.32985i 0.0116196-1.41286i 0-1.44051i "
  "-0.0116196-1.41286i -0.0179768-1.32985i -0.0148543-1.19168i 1.29939e-17-1i 0.0241912-0.759545i 0.0528399-0.479481i "
  "0.0811508-0.174165i 0.102893+0.137191i 0.11123+0.432049i 0.0997521+0.687118i 0.0635331+0.881529i";
  assert_cvec(ref_c, csamples);
}