/* * Read a PEM or BER X.509 object */ void X509_Object::init(DataSource& in, const std::string& labels) { m_PEM_labels_allowed = split_on(labels, '/'); if(m_PEM_labels_allowed.size() < 1) throw Invalid_Argument("Bad labels argument to X509_Object"); m_PEM_label_pref = m_PEM_labels_allowed[0]; std::sort(m_PEM_labels_allowed.begin(), m_PEM_labels_allowed.end()); try { if(ASN1::maybe_BER(in) && !PEM_Code::matches(in)) { BER_Decoder dec(in); decode_from(dec); } else { std::string got_label; DataSource_Memory ber(PEM_Code::decode(in, got_label)); if(!std::binary_search(m_PEM_labels_allowed.begin(), m_PEM_labels_allowed.end(), got_label)) throw Decoding_Error("Invalid PEM label: " + got_label); BER_Decoder dec(ber); decode_from(dec); } } catch(Decoding_Error& e) { throw Decoding_Error(m_PEM_label_pref + " decoding failed: " + e.what()); } }
void badCalls() { \u00FCber(0.5); // expected-warning{{implicit conversion from 'double' to 'int'}} \u00fcber = 0; // expected-error{{non-object type 'void (int)' is not assignable}} über(1, 2); \U000000FCber(); #ifdef __cplusplus // expected-error@-3 {{no matching function}} // expected-error@-3 {{no matching function}} #else // expected-error@-6 {{too many arguments to function call, expected 1, have 2}} // expected-error@-6 {{too few arguments to function call, expected 1, have 0}} #endif }
EC_Group::EC_Group(const std::vector<uint8_t>& ber_data) { BER_Decoder ber(ber_data); BER_Object obj = ber.get_next_object(); if(obj.type_tag == NULL_TAG) throw Decoding_Error("Cannot handle ImplicitCA ECDSA parameters"); else if(obj.type_tag == OBJECT_ID) { OID dom_par_oid; BER_Decoder(ber_data).decode(dom_par_oid); *this = EC_Group(dom_par_oid); } else if(obj.type_tag == SEQUENCE) { BigInt p, a, b; std::vector<uint8_t> sv_base_point; BER_Decoder(ber_data) .start_cons(SEQUENCE) .decode_and_check<size_t>(1, "Unknown ECC param version code") .start_cons(SEQUENCE) .decode_and_check(OID("1.2.840.10045.1.1"), "Only prime ECC fields supported") .decode(p) .end_cons() .start_cons(SEQUENCE) .decode_octet_string_bigint(a) .decode_octet_string_bigint(b) .end_cons() .decode(sv_base_point, OCTET_STRING) .decode(m_order) .decode(m_cofactor) .end_cons() .verify_end(); m_curve = CurveGFp(p, a, b); m_base_point = OS2ECP(sv_base_point, m_curve); } else throw Decoding_Error("Unexpected tag while decoding ECC domain params"); }
/* * Extract a public key and return it */ Public_Key* load_key(DataSource& source) { try { AlgorithmIdentifier alg_id; secure_vector<byte> key_bits; if(ASN1::maybe_BER(source) && !PEM_Code::matches(source)) { BER_Decoder(source) .start_cons(SEQUENCE) .decode(alg_id) .decode(key_bits, BIT_STRING) .verify_end() .end_cons(); } else { DataSource_Memory ber( PEM_Code::decode_check_label(source, "PUBLIC KEY") ); BER_Decoder(ber) .start_cons(SEQUENCE) .decode(alg_id) .decode(key_bits, BIT_STRING) .verify_end() .end_cons(); } if(key_bits.empty()) throw Decoding_Error("X.509 public key decoding failed"); return make_public_key(alg_id, key_bits); } catch(Decoding_Error& e) { throw Decoding_Error("X.509 public key decoding failed: " + std::string(e.what())); } }
/* * Read a PEM or BER X.509 object */ void X509_Object::load_data(DataSource& in) { try { if(ASN1::maybe_BER(in) && !PEM_Code::matches(in)) { BER_Decoder dec(in); decode_from(dec); } else { std::string got_label; DataSource_Memory ber(PEM_Code::decode(in, got_label)); if(got_label != PEM_label()) { bool is_alternate = false; for(std::string alt_label : alternate_PEM_labels()) { if(got_label == alt_label) { is_alternate = true; break; } } if(!is_alternate) throw Decoding_Error("Unexpected PEM label for " + PEM_label() + " of " + got_label); } BER_Decoder dec(ber); decode_from(dec); } } catch(Decoding_Error& e) { throw Decoding_Error(PEM_label() + " decoding", e); } }
Binary& get(Binary& b) { b.resize( ber() ); read(b); return b; }
int main(int argc, char *argv[]) { int i,j,k; //Counter variable bvec b_source_bits, b_decoded_bits, b_encoded_bits; ivec i_decoded_bits, i_decoded_symbols; cvec c_received_signals; vec d_received_llr; ivec No_of_Errors, No_of_Bits, No_of_BlockErrors, No_of_Blocks; //Channel setup cvec channel_gains; TDL_Channel ray_channel; // default: uncorrelated Rayleigh fading channel AWGN_Channel awgn_channel; // AWGN channel //-------------------------------------------------------CONV //Convolutional codes module, CONV CONV conv; char *ctrlfile; if(argc==1) ctrlfile = "control.conv.par"; else ctrlfile = argv[1]; conv.set_parameters_from_file(ctrlfile); conv.initialise(); //result file FILE *f; char *resultfile= conv.get_result_filename(); f=fopen(resultfile, "w"); //print out parameters conv.print_parameters(stdout); conv.print_parameters(f); //-------------------------------------------------------CONV // read simulation parameters FILE *sim_file; FILESERVICE fileser; sim_file = fopen("control.sim.par", "r"); if(sim_file==NULL) it_error("control.sim.par not found"); int max_nrof_frame = fileser.scan_integer(sim_file); double SNR_start = fileser.scan_double(sim_file); double SNR_step = fileser.scan_double(sim_file); double SNR_end = fileser.scan_double(sim_file); double G_sd = fileser.scan_double(sim_file); double G_sr = fileser.scan_double(sim_file); double G_rd = fileser.scan_double(sim_file); int channel_type = fileser.scan_integer(sim_file); int mapper_bps = fileser.scan_integer(sim_file); fclose(sim_file); char text[100]; sprintf( text, "%f:%f:%f", SNR_start, SNR_step, SNR_end ); //SNR setup vec SNRdB = text; //Setting the simulation Eb/N0 range in dB int M = 1<<mapper_bps; PSK psk(M); cvec source_frame; double rate = (double)mapper_bps * conv.get_rate(); printf ( "! %d-PSK (mapper_bps=%d) :: Overall_Rate=%.4f\n!\n", M, mapper_bps, rate); fprintf(f,"! %d-PSK (mapper_bps=%d) :: Overall_Rate=%.4f\n!\n", M, mapper_bps, rate); vec SNR = pow(10.0, SNRdB/10.0); vec N0 = 1.0/SNR; vec sigma2 = N0/2; BERC berc; //BER counter BLERC blerc; //FER counter Real_Timer tt; //Time counter vec ber(SNRdB.length()); //allocate memory for vector to store BER vec bler(SNRdB.length()); //allocate memory for vector to store FER ber.clear(); //Clear up buffer of BER counter bler.clear(); //Clear up buffer of FER counter blerc.set_blocksize((long)conv.get_info_bit_length()); //set blocksize of the FER counter tt.tic(); //Start timer //RNG_randomize(); //construct random source RNG_reset(0); //reset random seed b_source_bits.set_size(conv.get_info_bit_length(), false); b_encoded_bits.set_size(conv.get_coded_bit_length(), false); c_received_signals.set_size(conv.get_sym_length(), false); d_received_llr.set_size(conv.get_coded_bit_length(), false); b_decoded_bits.set_size(conv.get_info_bit_length(), false); No_of_Errors.set_size(SNRdB.length(), false); //Set the length No_of_Bits.set_size(SNRdB.length(), false); //for ivectors storing the no No_of_BlockErrors.set_size(SNRdB.length(),false); //of errors bits or error frames No_of_Blocks.set_size(SNRdB.length(),false); No_of_Errors.clear(); No_of_Bits.clear(); No_of_BlockErrors.clear(); No_of_Blocks.clear(); printf ( "!SNR(dB)\tEbN0(dB)\tBER\t\tFER\t\tnrof Frames\n"); fprintf(f,"!SNR(dB)\tEbN0(dB)\tBER\t\tFER\t\tnrof Frames\n"); for(i=0; i< SNRdB.length(); i++) { //Set channel noise level awgn_channel.set_noise(N0(i)); for(j=0;j<max_nrof_frame;j++) { //Generate random source bits b_source_bits = randb(conv.get_info_bit_length()); //CONV encode conv.encode_bits(b_source_bits, b_encoded_bits); source_frame = psk.modulate_bits(b_encoded_bits); // Fast Rayleigh channel + AWGN transmission channel_gains = my_channel(channel_type, source_frame.length(), G_sd, ray_channel); c_received_signals = elem_mult(source_frame, channel_gains); c_received_signals = awgn_channel( c_received_signals ); //Demodulation to get llr psk.demodulate_soft_bits(c_received_signals, channel_gains, N0(i), d_received_llr); //Convert to Log(Pr=1/Pr=0) d_received_llr = -1 * d_received_llr; //CONV decode conv.assign_apr_codeword(d_received_llr); conv.decode(i_decoded_bits, i_decoded_symbols); b_decoded_bits = to_bvec(i_decoded_bits.left(conv.get_info_bit_length())); // remove dummy bits if trellis/code termination is used berc.clear(); blerc.clear(); berc.count (b_source_bits, b_decoded_bits); //Count error bits in a word blerc.count (b_source_bits, b_decoded_bits); //Count frame errors No_of_Errors(i) += berc.get_errors(); //Updating counters No_of_Bits(i) += berc.get_errors()+berc.get_corrects(); No_of_BlockErrors(i) +=blerc.get_errors(); No_of_Blocks(i)++; if(No_of_Errors(i)>100000) break; } ber(i) = (double)No_of_Errors(i)/No_of_Bits(i); bler(i) = (double)No_of_BlockErrors(i)/No_of_Blocks(i); double EbN0dB = SNRdB(i) - 10*log10(rate); printf("%f\t%f\t%e\t%e\t%d\n", SNRdB(i), EbN0dB, ber(i), bler(i), No_of_Blocks(i)); fprintf(f,"%f\t%f\t%e\t%e\t%d\n", SNRdB(i), EbN0dB, ber(i), bler(i), No_of_Blocks(i)); if(ber(i)<1e-5) break; } fprintf(f,"!Elapsed time = %d s\n", tt.get_time()); //output simulation time tt.toc(); //Stop timer and output simulation time fclose(f); //close output file return 0 ; //exit program }
void ThroughPut::timerEvent(QTimerEvent *event){ char buff[14404*3+10]; struct pilot4id pilot42[1200]; for( int i = 0 ; i < 200 ; i++ ){ pilot42[i].id = i; pilot42[i].value = 0; } #ifdef connected recvfrom(sockser_chl1_3,&buff,14404*3+10,0,(struct sockaddr *)&addrrcv_chl1_3,(socklen_t*)&size_chl2_3);//port :7005.3 //qDebug() << "Counter is " << cnt_2++ << endl; /* qDebug() << buff << endl; */ // inverse for( int i = 0 ; i < 2405 ; i ++){ int position = i * 6; char tmp; //swap tmp = buff[position]; buff[position] = buff[position+3]; buff[position+3] = tmp; //swap position ++; tmp = buff[position]; buff[position] = buff[position+3]; buff[position+3] = tmp; }//for //qDebug() << buff << endl; int position = 12; // avoid the header a0aa 3c20 cccc for( int i = 0 ; i < 1200 ; i++){ for( int j = 0 ; j <8 ;) { map1200_3[i][j++] = buff[position++]; map1200_3[i][j++] = buff[position++]; position++;//avoid the comma }//for j }//for i for( int i = 0 ; i < 1200 ; i++){ data1_3[i][0]=hex2int(map1200_3[i][0],map1200_3[i][1],map1200_3[i][2],map1200_3[i][3]); data1_3[i][1]=hex2int(map1200_3[i][4],map1200_3[i][5],map1200_3[i][6],map1200_3[i][7]); //qDebug() << data1_3[i][0] << data1_3[i][1] <<data2_3[i][0] <<data2_3[i][1] <<endl; }//for i double pilot4H11[200][2] = {0}; int cnt_2H11 = 0; for( int i = 0 ; i < 1200 ; i++){ if(i % 6 == 0){//position for the pilot4 H11 pilot4H11[cnt_2H11][0] = data1_3[i][0]; pilot4H11[cnt_2H11][1] = data1_3[i][1]; pilot42[cnt_2H11].value = sqrt(data1_3[i][0]*data1_3[i][0]+data1_3[i][1]*data1_3[i][1]); cnt_2H11 += 1; }//if } for( int i = 0 ; i < 200 ; i++){ for( int j = i+1 ; j < 200 ; j++){ if( pilot42[i].value - pilot42[j].value < 1e-7 ){ struct pilot4id tmp = pilot42[i]; pilot42[i] = pilot42[j]; pilot42[j] = tmp; } } } double H11[200][2] = {0}; double absH11[200] = {0}; double absH11_6[1200][2] = {0}; //qDebug() << " ---- "; for( int i = 0 ; i < 200 ; i++ ){ H11[i][0] = (pilot4H11[i][0]*pilot4[i*6][0]+pilot4H11[i][1]*pilot4[i*6][1])/(pilot4[i*6][0]*pilot4[i*6][0]+pilot4[i*6][1]*pilot4[i*6][1]); H11[i][1] = (pilot4H11[i][1]*pilot4[i*6][0]-pilot4H11[i][0]*pilot4[i*6][1])/(pilot4[i*6][0]*pilot4[i*6][0]+pilot4[i*6][1]*pilot4[i*6][1]); //qDebug() << H11[i][0] << H11[i][1] << " angle : "<<atan(H11[i][1]/H11[i][0])<<"pilot4"<<pilot4[i*6][0]<<"|"<<pilot4[i*6][1]; //qDebug() << " angle : "<<atan(H11[i][1]/H11[i][0]); absH11[i] = sqrt(H11[i][0]*H11[i][0] + H11[i][1]*H11[i][1]); }//for icnt_err_g //interp :edited by hh for(int i=0;i<200;i++){ absH11_6[i*6][0] = H11[i][0]; absH11_6[i*6 + 1 ][0] = H11[i][0]; absH11_6[i*6 + 2 ][0] = H11[i][0]; absH11_6[i*6 + 3][0]= H11[i][0]; absH11_6[i*6 + 4 ][0] = H11[i][0]; absH11_6[i*6 + 5 ][0] = H11[i][0]; absH11_6[i*6][1] = H11[i][1]; absH11_6[i*6 + 1 ][1] = H11[i][1]; absH11_6[i*6 + 2 ][1] = H11[i][1]; absH11_6[i*6 + 3][1]= H11[i][1]; absH11_6[i*6 + 4 ][1] = H11[i][1]; absH11_6[i*6 + 5 ][1] = H11[i][1]; absH11_6[i*6 + 6 ][1] = H11[i][1]; } // qDebug() << " H : ---- "; int cnt_2g = 0; double guess[1000][2] = {0}; for( int i = 0 ; i < 1200 ; i++){ if(i%6 != 0){ // qDebug() << " H : "<<absH11_6[i][0]; guess[cnt_2g][0] = (data1_3[i][0]*absH11_6[i][0]+data1_3[i][1]*absH11_6[i][1])/(absH11_6[i][0]*absH11_6[i][0]+absH11_6[i][1]*absH11_6[i][1]); //guess[cnt_2g][0] /= 15000; guess[cnt_2g][1] = (data1_3[i][1]*absH11_6[i][0]-data1_3[i][0]*absH11_6[i][1])/(absH11_6[i][0]*absH11_6[i][0]+absH11_6[i][1]*absH11_6[i][1]); //guess[cnt_2g][1] /= 15000; cnt_2g++; }//if }//for pdata = &guess[0][0]; //*(pdata) = 2*sin(cnt_2_update); ber(); recvfrom(sockser_chl1_4,&buff,LENGTH_OF_OFDM*3+10,0,(struct sockaddr *)&addrrcv_chl1_4,(socklen_t*)&size_chl2_4);//port :7021 // qDebug() << "Counter is " << cnt++ << endl; // qDebug() << buff << endl; for( int i = 0 ; i < 2400 ; i ++){ int position = i * 6; char tmp; //swap tmp = buff[position]; buff[position] = buff[position+3]; buff[position+3] = tmp; //swap position ++; tmp = buff[position]; buff[position] = buff[position+3]; buff[position+3] = tmp; }//for //qDebug() << buff << endl; position = 12; // avoid the header a0aa 3c20 cccc for( int i = 0 ; i < 1200 ; i++){ for( int j = 0 ; j <8 ;) { map1200[i][j++] = buff[position++]; map1200[i][j++] = buff[position++]; position++;//avoid the comma }//for j }//for i for( int i = 0 ; i < 1200 ; i++){ data1[i][0]=hex2int(map1200[i][0],map1200[i][1],map1200[i][2],map1200[i][3]); data1[i][1]=hex2int(map1200[i][4],map1200[i][5],map1200[i][6],map1200[i][7]); // qDebug() << data1[i][0] << data1[i][1] ;//<<data2[i][0] <<data2[i][1] <<endl; }//for i sys_function();//data >> function >> HWS #endif sys_function();//data >> function >> HWS updateGL(); }
void goodCalls() { \u00FCber(0); \u00fcber(1); über(2); \U000000FCber(3); }
CORASMA_BER_Test::CORASMA_BER_Test() { modem=new Modem_CORASMA(); int L=1; int OF=1; cmat fading; cvec channel1,channel2,channel3,channel4,channel5,channel6,channel7,channel8,channel9,channel10,channel11,channel12,channel13,channel14,channel15,channel16; bvec transmitted_bits; bvec received_bits; cvec sum_chips; cvec transmitted_symbols; cvec received_chips; double norm_fading; BERC berc,berc1,berc2; AWGN_Channel channel; vec EbN0dB = linspace(1000, 1000, 1); vec EbN0 = pow(10, EbN0dB / 10); double Eb = 1.0; vec N0 = Eb * pow(EbN0, -1.0); int NumOfBits = modem->nb_bits; int MaxIterations = 10; int MaxNrOfErrors = 200; int MinNrOfErrors = 5; vec ber; ber.set_size(EbN0dB.size(), false); ber.clear(); RNG_randomize(); for (int i=0;i<EbN0dB.length();i++){ cout << endl << "Simulating point nr " << i + 1 << endl; berc.clear(); berc1.clear(); berc2.clear(); channel.set_noise(N0(i)); for (int j=0;j<MaxIterations;j++) { transmitted_bits = randb(NumOfBits); sum_chips=modem->modulate(transmitted_bits); transmitted_symbols.set_length(sum_chips.length()+L+1); transmitted_symbols.zeros(); fading.set_size(L,sum_chips.length()); fading.zeros(); channel1.set_length(sum_chips.length()); /* channel2.set_length(sum_chips.length()); channel3.set_length(sum_chips.length()); channel4.set_length(sum_chips.length()); channel5.set_length(sum_chips.length()); channel6.set_length(sum_chips.length()); channel7.set_length(sum_chips.length()); channel8.set_length(sum_chips.length()); channel9.set_length(sum_chips.length()); channel10.set_length(sum_chips.length()); channel11.set_length(sum_chips.length()); channel12.set_length(sum_chips.length()); channel13.set_length(sum_chips.length()); channel14.set_length(sum_chips.length()); channel15.set_length(sum_chips.length()); channel16.set_length(sum_chips.length());*/ for(int k=0;k<sum_chips.length()/OF;k++){ channel1.replace_mid(k*OF,ones_c(OF)); /* channel1.replace_mid(k*OF,randn_c()*ones(OF)); channel2.replace_mid(k*OF,randn_c()*ones(OF)); channel3.replace_mid(k*OF,randn_c()*ones(OF)); channel4.replace_mid(k*OF,randn_c()*ones(OF)); channel5.replace_mid(k*OF,randn_c()*ones(OF)); channel6.replace_mid(k*OF,randn_c()*ones(OF)); channel7.replace_mid(k*OF,randn_c()*ones(OF)); channel8.replace_mid(k*OF,randn_c()*ones(OF)); channel9.replace_mid(k*OF,randn_c()*ones(OF)); channel10.replace_mid(k*OF,randn_c()*ones(OF)); channel11.replace_mid(k*OF,randn_c()*ones(OF)); channel12.replace_mid(k*OF,randn_c()*ones(OF)); channel13.replace_mid(k*OF,randn_c()*ones(OF)); channel14.replace_mid(k*OF,randn_c()*ones(OF)); channel15.replace_mid(k*OF,randn_c()*ones(OF)); channel16.replace_mid(k*OF,randn_c()*ones(OF));*/ } norm_fading=1./sqrt(inv_dB(0)*norm(channel1)*norm(channel1)/sum_chips.length()/*+inv_dB(0)*norm(channel2)*norm(channel2)/sum_chips.length()+inv_dB(0)*norm(channel3)*norm(channel3)/sum_chips.length()+inv_dB(0)*norm(channel4)*norm(channel4)/sum_chips.length()+inv_dB(0)*norm(channel5)*norm(channel5)/sum_chips.length()+inv_dB(0)*norm(channel6)*norm(channel6)/sum_chips.length()+inv_dB(0)*norm(channel7)*norm(channel7)/sum_chips.length()+inv_dB(0)*norm(channel8)*norm(channel8)/sum_chips.length()+inv_dB(0)*norm(channel9)*norm(channel9)/sum_chips.length()+inv_dB(0)*norm(channel10)*norm(channel10)/sum_chips.length()+inv_dB(0)*norm(channel11)*norm(channel11)/sum_chips.length()+inv_dB(0)*norm(channel12)*norm(channel12)/sum_chips.length()+inv_dB(0)*norm(channel13)*norm(channel13)/sum_chips.length()+inv_dB(0)*norm(channel14)*norm(channel14)/sum_chips.length()+inv_dB(0)*norm(channel15)*norm(channel15)/sum_chips.length()+inv_dB(0)*norm(channel16)*norm(channel16)/sum_chips.length()*/); fading.set_row(0,norm_fading*channel1); /* fading.set_row(1,norm_fading*channel2); fading.set_row(2,norm_fading*channel3); fading.set_row(3,norm_fading*channel4); fading.set_row(4,norm_fading*channel5); fading.set_row(5,norm_fading*channel6); fading.set_row(6,norm_fading*channel7); fading.set_row(7,norm_fading*channel8); fading.set_row(8,norm_fading*channel9); fading.set_row(9,norm_fading*channel10); fading.set_row(10,norm_fading*channel11); fading.set_row(11,norm_fading*channel12); fading.set_row(12,norm_fading*channel13); fading.set_row(13,norm_fading*channel14); fading.set_row(14,norm_fading*channel15); fading.set_row(15,norm_fading*channel16);*/ for (int k=0;k<L;k++){ transmitted_symbols+=concat(zeros_c(k),elem_mult(to_cvec(sum_chips),fading.get_row(k)),zeros_c(L+1-k)); } received_chips = channel(/*transmitted_symbols*/sum_chips); cvec constellation; int time_offset_estimate; received_bits=modem->demodulate(received_chips,constellation,time_offset_estimate); bvec received_bits_inverted=received_bits+bin(1); //Generic Transmitter + First Receiver M&M + Costas berc1.count(transmitted_bits, received_bits); ber(i) = berc1.get_errorrate(); berc=berc1; berc2.count(transmitted_bits, received_bits_inverted); if(berc2.get_errorrate()<ber(i)){ ber(i) = berc2.get_errorrate(); berc=berc2; } cout << " Iteration " << j + 1 << ": ber = " << berc.get_errorrate() << endl; if (berc.get_errors() > MaxNrOfErrors) { cout << "Breaking on point " << i + 1 << " with " << berc.get_errors() << " errors." << endl; break; } } if (berc.get_errors() < MinNrOfErrors) { cout << "Exiting Simulation on point " << i + 1 << endl; break; } } //Print results: cout << endl; cout << "EbN0dB = " << EbN0dB << endl; cout << "ber = " << ber << endl; }
void QPSK3::timerEvent(QTimerEvent *event) { char buff[LENGTH_OF_OFDM*3+10]; struct pilotid pilot2[1200]; for( int i = 0 ; i < 200 ; i++ ) { pilot2[i].id = i; pilot2[i].value = 0; } recvfrom(sockser_chl1,&buff,LENGTH_OF_OFDM*3+10,0,(struct sockaddr *)&addrrcv_chl1,(socklen_t*)&size_chl2);//port :7005.3 qDebug() << "Counter is " << cnt++ << endl; //qDebug() << buff << endl; #ifdef operation // inverse for( int i = 0 ; i < 2400 ; i ++) { int position = i * 6; char tmp; //swap tmp = buff[position]; buff[position] = buff[position+3]; buff[position+3] = tmp; //swap position ++; tmp = buff[position]; buff[position] = buff[position+3]; buff[position+3] = tmp; }//for //qDebug() << buff << endl; int position = 0; // avoid the header a0aa 3c20 cccc for( int i = 0 ; i < 1200 ; i++) { for( int j = 0 ; j <8 ;) { map1200[i][j++] = buff[position++]; map1200[i][j++] = buff[position++]; position++;//avoid the comma }//for j }//for i for( int i = 0 ; i < 1200 ; i++) { data1[i][0]=hex2int(map1200[i][0],map1200[i][1],map1200[i][2],map1200[i][3]); data1[i][1]=hex2int(map1200[i][4],map1200[i][5],map1200[i][6],map1200[i][7]); //qDebug() << data1[i][0] << data1[i][1] <<data2[i][0] <<data2[i][1] <<endl; }//for i double pilotH11[200][2] = {0}; int cntH11 = 0; for( int i = 0 ; i < 1200 ; i++) { if(i % 6 == 0) { //position for the pilot H11 pilotH11[cntH11][0] = data1[i][0]; pilotH11[cntH11][1] = data1[i][1]; pilot2[cntH11].value = sqrt(data1[i][0]*data1[i][0]+data1[i][1]*data1[i][1]); cntH11 += 1; }//if } for( int i = 0 ; i < 200 ; i++) { for( int j = i+1 ; j < 200 ; j++) { if( pilot2[i].value - pilot2[j].value < 1e-7 ) { struct pilotid tmp = pilot2[i]; pilot2[i] = pilot2[j]; pilot2[j] = tmp; } } } /*commented by hh for( int i = 0 ; i < 100 ; i++ ){ pilotH11[pilot2[i+100].id ][0] = pilotH11[pilot2[i].id][0]; pilotH11[pilot2[i+100].id ][1] = pilotH11[pilot2[i].id][1]; pilot[pilot2[i+100].id][0] = pilot[pilot2[i].id][0]; pilot[pilot2[i+100].id][1] = pilot[pilot2[i].id][1]; data1[pilot2[i+100].id*6][0] = data1[pilot2[i].id*6][0]; data1[pilot2[i+100].id*6][1] = data1[pilot2[i].id*6][1]; data1[pilot2[i+100].id*6+1][0] = data1[pilot2[i].id*6+1][0]; data1[pilot2[i+100].id*6+1][1] = data1[pilot2[i].id*6+1][1]; data1[pilot2[i+100].id*6+2][0] = data1[pilot2[i].id*6+2][0]; data1[pilot2[i+100].id*6+2][1] = data1[pilot2[i].id*6+2][1]; data1[pilot2[i+100].id*6+3][0] = data1[pilot2[i].id*6+3][0]; data1[pilot2[i+100].id*6+3][1] = data1[pilot2[i].id*6+3][1]; data1[pilot2[i+100].id*6+4][0] = data1[pilot2[i].id*6+4][0]; data1[pilot2[i+100].id*6+4][1] = data1[pilot2[i].id*6+4][1]; data1[pilot2[i+100].id*6+5][0] = data1[pilot2[i].id*6+5][0]; data1[pilot2[i+100].id*6+5][1] = data1[pilot2[i].id*6+5][1]; } */ /* for( int i = 0 ; i < 200 ; i++ ){ qDebug() << pilot2[i].value << pilot2[i].id ; } */ double H11[200][2] = {0}; double absH11[200] = {0}; double absH11_6[1200][2] = {0}; //qDebug() << " ---- "; for( int i = 0 ; i < 200 ; i++ ) { H11[i][0] = (pilotH11[i][0]*pilot[i*6][0]+pilotH11[i][1]*pilot[i*6][1])/(pilot[i*6][0]*pilot[i*6][0]+pilot[i*6][1]*pilot[i*6][1]); H11[i][1] = (pilotH11[i][1]*pilot[i*6][0]-pilotH11[i][0]*pilot[i*6][1])/(pilot[i*6][0]*pilot[i*6][0]+pilot[i*6][1]*pilot[i*6][1]); //qDebug() << H11[i][0] << H11[i][1] << " angle : "<<atan(H11[i][1]/H11[i][0])<<"pilot"<<pilot[i*6][0]<<"|"<<pilot[i*6][1]; //qDebug() << " angle : "<<atan(H11[i][1]/H11[i][0]); absH11[i] = sqrt(H11[i][0]*H11[i][0] + H11[i][1]*H11[i][1]); }//for i //interp :edited by hh for(int i=0; i<200; i++) { absH11_6[i*6][0] = H11[i][0]; absH11_6[i*6 + 1 ][0] = H11[i][0]; absH11_6[i*6 + 2 ][0] = H11[i][0]; absH11_6[i*6 + 3][0]= H11[i][0]; absH11_6[i*6 + 4 ][0] = H11[i][0]; absH11_6[i*6 + 5 ][0] = H11[i][0]; absH11_6[i*6][1] = H11[i][1]; absH11_6[i*6 + 1 ][1] = H11[i][1]; absH11_6[i*6 + 2 ][1] = H11[i][1]; absH11_6[i*6 + 3][1]= H11[i][1]; absH11_6[i*6 + 4 ][1] = H11[i][1]; absH11_6[i*6 + 5 ][1] = H11[i][1]; absH11_6[i*6 + 6 ][1] = H11[i][1]; /* absH11_6[i*12][0] = H11[2*i][0]; absH11_6[i*12 + 1 ][0] = H11[2*i][0]; absH11_6[i*12 + 2 ][0] = H11[2*i][0]; absH11_6[i*12 + 3][0]= H11[2*i][0]; absH11_6[i*12 + 4 ][0] = H11[2*i][0]; absH11_6[i*12 + 5 ][0] = H11[2*i][0]; absH11_6[i*12 + 6 ][0] = H11[2*i][0]; absH11_6[i*12 + 7 ][0] = H11[2*i][0]; absH11_6[i*12 + 8][0]= H11[2*i][0]; absH11_6[i*12 + 9 ][0] = H11[2*i][0]; absH11_6[i*12 + 10 ][0] = H11[2*i][0]; absH11_6[i*12 + 11 ][0] = H11[2*i][0]; absH11_6[i*12][1] = H11[2*i][1]; absH11_6[i*12 + 1 ][1] = H11[2*i][1]; absH11_6[i*12 + 2 ][1] = H11[2*i][1]; absH11_6[i*12 + 3][1]= H11[2*i][1]; absH11_6[i*12 + 4 ][1] = H11[2*i][1]; absH11_6[i*12 + 5 ][1] = H11[2*i][1]; absH11_6[i*12 + 6 ][1] = H11[2*i][1]; absH11_6[i*12 + 7 ][1] = H11[2*i][1]; absH11_6[i*12 + 8][1]= H11[2*i][1]; absH11_6[i*12 + 9 ][1] = H11[2*i][1]; absH11_6[i*12 + 10 ][1] = H11[2*i][1]; absH11_6[i*12 + 11 ][1] = H11[2*i][1]; */ } // qDebug() << " H : ---- "; int cntg = 0; double guess[1000][2] = {0}; for( int i = 0 ; i < 600 ; i++) { if(i%6 != 0) { // qDebug() << " H : "<<absH11_6[i][0]; guess[cntg][0] = (data1[i][0]*absH11_6[i][0]+data1[i][1]*absH11_6[i][1])/(absH11_6[i][0]*absH11_6[i][0]+absH11_6[i][1]*absH11_6[i][1]); //guess[cntg][0] /= 15000; guess[cntg][1] = (data1[i][1]*absH11_6[i][0]-data1[i][0]*absH11_6[i][1])/(absH11_6[i][0]*absH11_6[i][0]+absH11_6[i][1]*absH11_6[i][1]); //guess[cntg][1] /= 15000; cntg++; }//if }//for for( int i = 600 ; i < 1200 ; i++ ) { guess[i][0] = guess[i-600][0]; guess[i][1] = guess[i-600][1]; } pdata = &guess[0][0]; /* if(first1 == 1){ first1 = 0; FILE *fp3 = fopen("ofdmdata.txt","w"); for( int i = 0 ; i <1000 ; i++){ fprintf(fp3,"%.6lf\t\t%.6lf\t\t%.3lf\t\t%.3lf\n", guess[i][0],guess[i][1]); } fclose(fp3); }//if */ ber(); updateGL(); //qDebug()<< "timer event in mygl2 Class!" << endl; #endif }
MCDAAOFDM_BER_Test::MCDAAOFDM_BER_Test() { modem=new Modem_MCDAAOFDM(); int L=1; int quasi_static=modem->Nfft+modem->Ncp; cmat fading; cvec channel1,channel2,channel3,channel4,channel5,channel6,channel7,channel8,channel9,channel10,channel11,channel12,channel13,channel14,channel15,channel16; bvec transmitted_bits; bvec received_bits; cvec modulated_ofdm; cvec transmitted_symbols; cvec received_ofdm; double norm_fading; BERC berc; AWGN_Channel channel; vec EbN0dB = linspace(0, 40, 41); vec EbN0 = pow(10, EbN0dB / 10); double Eb = 1.0; vec N0 = Eb * pow(EbN0, -1.0); int NumOfBits = 1000000; int MaxIterations = 10; int MaxNrOfErrors = 200; int MinNrOfErrors = 5; vec ber; ber.set_size(EbN0dB.size(), false); ber.clear(); RNG_randomize(); for (int i=0;i<EbN0dB.length();i++){ cout << endl << "Simulating point nr " << i + 1 << endl; berc.clear(); channel.set_noise(N0(i)); for (int j=0;j<MaxIterations;j++) { transmitted_bits = randb(NumOfBits); modulated_ofdm=sqrt(modem->Nfft+modem->Ncp)/sqrt(modem->Nfft)*modem->modulate_mask_qpsk(transmitted_bits,0); transmitted_symbols.set_length(modulated_ofdm.length()+L+1); transmitted_symbols.zeros(); fading.set_size(L,modulated_ofdm.length()); fading.zeros(); channel1.set_length(modulated_ofdm.length()); /* channel2.set_length(modulated_ofdm.length()); channel3.set_length(modulated_ofdm.length()); channel4.set_length(modulated_ofdm.length()); channel5.set_length(modulated_ofdm.length()); channel6.set_length(modulated_ofdm.length()); channel7.set_length(modulated_ofdm.length()); channel8.set_length(modulated_ofdm.length()); channel9.set_length(modulated_ofdm.length()); channel10.set_length(modulated_ofdm.length()); channel11.set_length(modulated_ofdm.length()); channel12.set_length(modulated_ofdm.length()); channel13.set_length(modulated_ofdm.length()); channel14.set_length(modulated_ofdm.length()); channel15.set_length(modulated_ofdm.length()); channel16.set_length(modulated_ofdm.length());*/ for(int k=0;k<modulated_ofdm.length()/quasi_static;k++){ channel1.replace_mid(k*quasi_static,ones_c(quasi_static)); //complex<double> random_complex= randn_c(); //double canal=sqrt(real(random_complex*conj(random_complex))); //channel1.replace_mid(k*quasi_static,canal*ones_c(quasi_static)); //channel1.replace_mid(k*quasi_static,randn_c()*ones(quasi_static)); /* channel2.replace_mid(k*quasi_static,randn_c()*ones(quasi_static)); channel3.replace_mid(k*quasi_static,randn_c()*ones(quasi_static)); channel4.replace_mid(k*quasi_static,randn_c()*ones(quasi_static)); channel5.replace_mid(k*quasi_static,randn_c()*ones(quasi_static)); channel6.replace_mid(k*quasi_static,randn_c()*ones(quasi_static)); channel7.replace_mid(k*quasi_static,randn_c()*ones(quasi_static)); channel8.replace_mid(k*quasi_static,randn_c()*ones(quasi_static)); channel9.replace_mid(k*quasi_static,randn_c()*ones(quasi_static)); channel10.replace_mid(k*quasi_static,randn_c()*ones(quasi_static)); channel11.replace_mid(k*quasi_static,randn_c()*ones(quasi_static)); channel12.replace_mid(k*quasi_static,randn_c()*ones(quasi_static)); channel13.replace_mid(k*quasi_static,randn_c()*ones(quasi_static)); channel14.replace_mid(k*quasi_static,randn_c()*ones(quasi_static)); channel15.replace_mid(k*quasi_static,randn_c()*ones(quasi_static)); channel16.replace_mid(k*quasi_static,randn_c()*ones(quasi_static));*/ } norm_fading=1./sqrt(inv_dB(0)*norm(channel1)*norm(channel1)/modulated_ofdm.length()/*+inv_dB(0)*norm(channel2)*norm(channel2)/modulated_ofdm.length()+inv_dB(0)*norm(channel3)*norm(channel3)/modulated_ofdm.length()+inv_dB(0)*norm(channel4)*norm(channel4)/modulated_ofdm.length()+inv_dB(0)*norm(channel5)*norm(channel5)/modulated_ofdm.length()+inv_dB(0)*norm(channel6)*norm(channel6)/modulated_ofdm.length()+inv_dB(0)*norm(channel7)*norm(channel7)/modulated_ofdm.length()+inv_dB(0)*norm(channel8)*norm(channel8)/modulated_ofdm.length()+inv_dB(0)*norm(channel9)*norm(channel9)/modulated_ofdm.length()+inv_dB(0)*norm(channel10)*norm(channel10)/modulated_ofdm.length()+inv_dB(0)*norm(channel11)*norm(channel11)/modulated_ofdm.length()+inv_dB(0)*norm(channel12)*norm(channel12)/modulated_ofdm.length()+inv_dB(0)*norm(channel13)*norm(channel13)/modulated_ofdm.length()+inv_dB(0)*norm(channel14)*norm(channel14)/modulated_ofdm.length()+inv_dB(0)*norm(channel15)*norm(channel15)/modulated_ofdm.length()+inv_dB(0)*norm(channel16)*norm(channel16)/modulated_ofdm.length()*/); fading.set_row(0,norm_fading*channel1); /* fading.set_row(1,norm_fading*channel2); fading.set_row(2,norm_fading*channel3); fading.set_row(3,norm_fading*channel4); fading.set_row(4,norm_fading*channel5); fading.set_row(5,norm_fading*channel6); fading.set_row(6,norm_fading*channel7); fading.set_row(7,norm_fading*channel8); fading.set_row(8,norm_fading*channel9); fading.set_row(9,norm_fading*channel10); fading.set_row(10,norm_fading*channel11); fading.set_row(11,norm_fading*channel12); fading.set_row(12,norm_fading*channel13); fading.set_row(13,norm_fading*channel14); fading.set_row(14,norm_fading*channel15); fading.set_row(15,norm_fading*channel16);*/ for (int k=0;k<L;k++){ transmitted_symbols+=concat(zeros_c(k),elem_mult(to_cvec(modulated_ofdm),fading.get_row(k)),zeros_c(L+1-k)); } received_ofdm = channel(transmitted_symbols); //received_chips = sum_chips; cvec constellation; vec estimated_channel; double metric; //bool is_ofdm=modem->detection(received_ofdm,metric); modem->time_offset_estimate=0; modem->frequency_offset_estimate=0; cvec demodulated_ofdm_symbols=modem->equalizer_fourth_power(received_ofdm,0,estimated_channel); received_bits=modem->demodulate_mask_gray_qpsk(demodulated_ofdm_symbols,0,constellation); berc.count(transmitted_bits, received_bits); ber(i) = berc.get_errorrate(); cout << " Iteration " << j + 1 << ": ber = " << berc.get_errorrate() << endl; if (berc.get_errors() > MaxNrOfErrors) { cout << "Breaking on point " << i + 1 << " with " << berc.get_errors() << " errors." << endl; break; } } if (berc.get_errors() < MinNrOfErrors) { cout << "Exiting Simulation on point " << i + 1 << endl; break; } } //Print results: cout << endl; cout << "EbN0dB = " << EbN0dB << endl; cout << "ber = " << ber << endl; }