int _tmain(int argc, _TCHAR* argv[]) { transmiter tr; AWGN_Channel awg; receiver rec; GlobalRNG_randomize(); BERC brHS_DPCCH,brDPCCH,brE_DPCCH,brE_DPDCH1,brE_DPDCH2,brE_DPDCH3,brE_DPDCH4; vec berHS_DPCCH,berDPCCH,berE_DPCCH,berE_DPDCH1,berE_DPDCH2,berE_DPDCH3,berE_DPDCH4; vec EbN0dB,EbN0,N0; ofstream out; int numOfIteration=1000; int numOfErrors=100; double Eb; EbN0dB=linspace(-20,6,14); EbN0=pow(10,EbN0dB/10.0); Eb=tr.betaDPCCHlin+tr.betaE_DPCCHlin+tr.betaE_DPDCH1lin+tr.betaE_DPDCH2lin+tr.betaE_DPDCH3lin +tr.betaE_DPDCH4lin+tr.betaE_HS_DPCCHlin; N0=Eb*pow(EbN0,-1.0); berHS_DPCCH.set_size(EbN0dB.length(),false); berDPCCH.set_size(EbN0dB.length(),false); berE_DPCCH.set_size(EbN0dB.length(),false); berE_DPDCH1.set_size(EbN0dB.length(),false); berE_DPDCH2.set_size(EbN0dB.length(),false); berE_DPDCH3.set_size(EbN0dB.length(),false); berE_DPDCH4.set_size(EbN0dB.length(),false); for(int i=0;i<EbN0dB.length();i++) { brDPCCH.clear(); brHS_DPCCH.clear(); brE_DPCCH.clear(); brE_DPDCH1.clear(); brE_DPDCH2.clear(); brE_DPDCH3.clear(); brE_DPDCH4.clear(); cout<<"Eb N0: "<<EbN0dB(i)<<endl; for(int j=0;j<numOfIteration;j++) { cout<<"Num of Iteration: "<<j+1<<endl; //DPCCH tr.SP_DPCCH=tr.spreading(tr.DPCCH,tr.OVSF256_0); //HS-DPCCH tr.HS_DPCCH=randb(tr.HS_DPCCH_NBits); tr.SP_HS_DPCCH=tr.spreading(tr.HS_DPCCH,tr.OVSF256_33); //E-DPCCH tr.E_DPCCH=randb(tr.E_DPCCH_NBits); tr.SP_E_DPCCH=tr.spreading(tr.E_DPCCH,tr.OVSF256_1); //E-DPDCH tr.E_DPDCH1=randb(tr.E_DPDCH1_NData); tr.E_DPDCH2=randb(tr.E_DPDCH2_NData); tr.E_DPDCH3=randb(tr.E_DPDCH3_NData); tr.E_DPDCH4=randb(tr.E_DPDCH4_NData); tr.SP_E_DPDCH1=tr.spreading(tr.E_DPDCH1,tr.OVSF2_1); tr.SP_E_DPDCH2=tr.spreading(tr.E_DPDCH2,tr.OVSF2_1); tr.SP_E_DPDCH3=tr.spreading(tr.E_DPDCH3,tr.OVSF4_1); tr.SP_E_DPDCH4=tr.spreading(tr.E_DPDCH4,tr.OVSF4_1); //beta tr.SP_DPCCH=tr.SP_DPCCH*tr.betaDPCCHlin; tr.SP_HS_DPCCH=tr.SP_HS_DPCCH*tr.betaE_HS_DPCCHlin; tr.SP_E_DPCCH=tr.SP_E_DPCCH*tr.betaE_DPCCHlin; tr.SP_E_DPDCH1=tr.SP_E_DPDCH1*tr.betaE_DPDCH1lin; tr.SP_E_DPDCH2=tr.SP_E_DPDCH2*tr.betaE_DPDCH2lin; tr.SP_E_DPDCH3=tr.SP_E_DPDCH3*tr.betaE_DPDCH3lin; tr.SP_E_DPDCH4=tr.SP_E_DPDCH4*tr.betaE_DPDCH4lin; //radio frame tr.radioFrame.set_length(tr.gold.numG); for(int i=0;i<tr.gold.numG;i++) { tr.radioFrame[i]._Val[0]=tr.SP_E_DPCCH[i]+tr.SP_E_DPDCH1[i]+tr.SP_E_DPDCH3[i]; tr.radioFrame[i]._Val[1]=tr.SP_DPCCH[i]+tr.SP_HS_DPCCH[i]+tr.SP_E_DPDCH2[i]+tr.SP_E_DPDCH4[i]; } cvec radioFrameScrambling,radioFrameDescr,channel; radioFrameScrambling=tr.scrambling(tr.radioFrame,tr.gold.c); //kanal awg.set_noise(N0(i)); channel=awg(radioFrameScrambling); //odbiornik radioFrameDescr=rec.descrambling(channel,tr.gold.cConjugate); rec.rRecive=real(radioFrameDescr); rec.iRecive=imag(radioFrameDescr); rec.DPCCH=rec.despreading(tr.DPCCH_NBits,tr.OVSF256_0,true); rec.E_DPCCH=rec.despreading(tr.E_DPCCH_NBits,tr.OVSF256_1,false); rec.HS_DPCCH=rec.despreading(tr.HS_DPCCH_NBits,tr.OVSF256_33,true); rec.E_DPDCH1=rec.despreading(tr.E_DPDCH1_NData,tr.OVSF2_1,false); rec.E_DPDCH2=rec.despreading(tr.E_DPDCH2_NData,tr.OVSF2_1,true); rec.E_DPDCH3=rec.despreading(tr.E_DPDCH3_NData,tr.OVSF4_1,false); rec.E_DPDCH4=rec.despreading(tr.E_DPDCH4_NData,tr.OVSF4_1,true); brDPCCH.count(tr.DPCCH,rec.DPCCH); brHS_DPCCH.count(tr.HS_DPCCH,rec.HS_DPCCH); brE_DPCCH.count(tr.E_DPCCH,rec.E_DPCCH); brE_DPDCH1.count(tr.E_DPDCH1,rec.E_DPDCH1); brE_DPDCH2.count(tr.E_DPDCH2,rec.E_DPDCH2); brE_DPDCH3.count(tr.E_DPDCH3,rec.E_DPDCH3); brE_DPDCH4.count(tr.E_DPDCH4,rec.E_DPDCH4); berDPCCH(i)=brDPCCH.get_errorrate(); berHS_DPCCH(i)=brHS_DPCCH.get_errorrate(); berE_DPCCH(i)=brE_DPCCH.get_errorrate(); berE_DPDCH1(i)=brE_DPDCH1.get_errorrate(); berE_DPDCH2(i)=brE_DPDCH2.get_errorrate(); berE_DPDCH3(i)=brE_DPDCH3.get_errorrate(); berE_DPDCH4(i)=brE_DPDCH4.get_errorrate(); cout<<"errors DPCCH: "<<brDPCCH.get_errors()<<" errors HS-DPCCH: "<<brHS_DPCCH.get_errors()<<" errors E-DPCCH: " <<brE_DPCCH.get_errors()<<" errors E-DPDCH1: "<<brE_DPDCH1.get_errors()<<" errors E-DPDCH2: "<<brE_DPDCH2.get_errors() <<" errors E-DPDCH3: "<<brE_DPDCH3.get_errors()<<" errors E-DPDCH4: "<<brE_DPDCH4.get_errors()<<endl; if(brDPCCH.get_errors()>numOfErrors && brE_DPCCH.get_errors()>numOfErrors && brHS_DPCCH.get_errors()>numOfErrors && brE_DPDCH1.get_errors()>numOfErrors && brE_DPDCH2.get_errors()>numOfErrors &&brE_DPDCH3.get_errors()>numOfErrors && brE_DPDCH4.get_errors()>numOfErrors) { break; } } } //stats out.open("BER.csv", ios_base::out | ios_base::trunc); out<<"Eb/N0"<<';'<<"BER DPCCH"<<';'<<"BER HS_DPCCH"<<';'<<"BER E_DPCCH"<<';'<<"BER E_DPDCH1"<<';' <<"BER E_DPDCH2"<<';'<<"BER E_DPDCH3"<<';'<<"BER E_DPDCH4"<<endl; for(int i=0;i<EbN0dB.length();i++) { out<<EbN0dB(i)<<';'<<berDPCCH(i)<<';'<<berHS_DPCCH(i)<<';'<<berE_DPCCH(i)<<';'<<berE_DPDCH1(i)<<';' <<berE_DPDCH2(i)<<';'<<berE_DPDCH3(i)<<';'<<berE_DPDCH4(i)<<endl; } out.close(); /* BERC br; br.count(tr.DPCCH,rec.DPCCH); cout<<"bledy DPCCH"<<endl; cout<<br.get_errors()<<endl; cout<<"BER DPCCH"<<endl; cout<<br.get_errorrate()<<endl; br.clear(); br.count(tr.E_DPCCH,rec.E_DPCCH); cout<<"bledy E-DPCCH"<<endl; cout<<br.get_errors()<<endl; cout<<"BER E-DPCCH"<<endl; cout<<br.get_errorrate()<<endl; br.clear(); br.count(tr.HS_DPCCH,rec.HS_DPCCH); cout<<"bledy HS-DPCCH"<<endl; cout<<br.get_errors()<<endl; cout<<"BER HS-DPCCH"<<endl; cout<<br.get_errorrate()<<endl; br.clear(); br.count(tr.E_DPDCH1,rec.E_DPDCH1); cout<<"bledy E-DPDCH1"<<endl; cout<<br.get_errors()<<endl; cout<<"BER E-DPDCH1"<<endl; cout<<br.get_errorrate()<<endl; br.clear(); br.count(tr.E_DPDCH2,rec.E_DPDCH2); cout<<"bledy E-DPDCH2"<<endl; cout<<br.get_errors()<<endl; cout<<"BER E-DPDCH2"<<endl; cout<<br.get_errorrate()<<endl; br.clear(); br.count(tr.E_DPDCH3,rec.E_DPDCH3); cout<<"bledy E-DPDCH3"<<endl; cout<<br.get_errors()<<endl; cout<<"BER E-DPDCH3"<<endl; cout<<br.get_errorrate()<<endl; br.clear(); br.count(tr.E_DPDCH4,rec.E_DPDCH4); cout<<"bledy E-DPDCH4"<<endl; cout<<br.get_errors()<<endl; cout<<"BER E-DPDCH4"<<endl; cout<<br.get_errorrate()<<endl; */ return 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; }
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; }
int _tmain(int argc, _TCHAR* argv[]) { Parser p(std::string("config.txt")); transmiter tr; AWGN_Channel awg; receiver rec; GlobalRNG_randomize(); BERC brHS_DPCCH,brDPCCH,brE_DPCCH,brE_DPDCH1,brE_DPDCH2,brE_DPDCH3,brE_DPDCH4; vec berHS_DPCCH,berDPCCH,berE_DPCCH,berE_DPDCH1,berE_DPDCH2,berE_DPDCH3,berE_DPDCH4; vec EbN0dB,EbN0,N0; ofstream out; int numOfIteration=p.get_int("numOfIteration"); int numOfErrors=100; double Eb; EbN0dB=linspace(-20,2,12); EbN0=pow(10,EbN0dB/10.0); Eb=tr.betaDPCCHlin+tr.betaE_DPCCHlin+tr.betaE_DPDCH1lin+tr.betaE_DPDCH2lin+tr.betaE_DPDCH3lin +tr.betaE_DPDCH4lin+tr.betaE_HS_DPCCHlin; N0=Eb*pow(EbN0,-1.0); berHS_DPCCH.set_size(EbN0dB.length(),false); berDPCCH.set_size(EbN0dB.length(),false); berE_DPCCH.set_size(EbN0dB.length(),false); berE_DPDCH1.set_size(EbN0dB.length(),false); berE_DPDCH2.set_size(EbN0dB.length(),false); berE_DPDCH3.set_size(EbN0dB.length(),false); berE_DPDCH4.set_size(EbN0dB.length(),false); TDL_Channel tdlChanel; CHANNEL_PROFILE chProfile; chProfile= ITU_Vehicular_A; double samplingTime=(0.5)/(38.4e6); tdlChanel.set_channel_profile(chProfile,samplingTime); vec powerdB; ivec delayPath; tdlChanel.get_channel_profile(powerdB,delayPath); cout<<delayPath<<endl; cvec path1,path2,path3,path4,path5,path6; cvec radioFrameScrambling,radioFrameALL,radioFrameDescr,radioFrameChannel1,radioFrameChannel2; cmat coffeChannel; tdlChanel.init(); cvec mulPath1,mulPath2,mulPath3,mulPath4,mulPath5,mulPath6,sum; mulPath1.set_length(38400); mulPath2.set_length(38400); mulPath3.set_length(38400); mulPath4.set_length(38400); mulPath5.set_length(38400); mulPath6.set_length(38400); sum.set_length(38400); for(int i=0;i<EbN0dB.length();i++) { brDPCCH.clear(); brHS_DPCCH.clear(); brE_DPCCH.clear(); brE_DPDCH1.clear(); brE_DPDCH2.clear(); brE_DPDCH3.clear(); brE_DPDCH4.clear(); cout<<"Eb N0: "<<EbN0dB(i)<<endl; tr.E_DPCCHall.set_size(0); tr.DPCCHall.set_size(0); tr.HS_DPCCHall.set_size(0); tr.E_DPDCH1all.set_size(0); tr.E_DPDCH2all.set_size(0); tr.E_DPDCH3all.set_size(0); tr.E_DPDCH4all.set_size(0); for(int k=0;k<numOfIteration;k++) { cout<<"Num of Iteration: "<<k+1<<endl; //DPCCH tr.SP_DPCCH=tr.spreading(tr.DPCCH,tr.OVSF256_0); tr.DPCCHall=concat(tr.DPCCHall,tr.DPCCH); //HS-DPCCH tr.HS_DPCCH=randb(tr.HS_DPCCH_NBits); tr.HS_DPCCHall=concat(tr.HS_DPCCHall,tr.HS_DPCCH); tr.SP_HS_DPCCH=tr.spreading(tr.HS_DPCCH,tr.OVSF256_33); //E-DPCCH tr.E_DPCCH=randb(tr.E_DPCCH_NBits); tr.E_DPCCHall=concat(tr.E_DPCCHall,tr.E_DPCCH); tr.SP_E_DPCCH=tr.spreading(tr.E_DPCCH,tr.OVSF256_1); //E-DPDCH tr.E_DPDCH1=randb(tr.E_DPDCH1_NData); tr.E_DPDCH2=randb(tr.E_DPDCH2_NData); tr.E_DPDCH3=randb(tr.E_DPDCH3_NData); tr.E_DPDCH4=randb(tr.E_DPDCH4_NData); tr.E_DPDCH1all=concat(tr.E_DPDCH1,tr.E_DPDCH1all); tr.E_DPDCH2all=concat(tr.E_DPDCH2,tr.E_DPDCH2all); tr.E_DPDCH3all=concat(tr.E_DPDCH3,tr.E_DPDCH3all); tr.E_DPDCH4all=concat(tr.E_DPDCH4,tr.E_DPDCH4all); tr.SP_E_DPDCH1=tr.spreading(tr.E_DPDCH1,tr.OVSF2_1); tr.SP_E_DPDCH2=tr.spreading(tr.E_DPDCH2,tr.OVSF2_1); tr.SP_E_DPDCH3=tr.spreading(tr.E_DPDCH3,tr.OVSF4_1); tr.SP_E_DPDCH4=tr.spreading(tr.E_DPDCH4,tr.OVSF4_1); //beta tr.SP_DPCCH=tr.SP_DPCCH*tr.betaDPCCHlin; tr.SP_HS_DPCCH=tr.SP_HS_DPCCH*tr.betaE_HS_DPCCHlin; tr.SP_E_DPCCH=tr.SP_E_DPCCH*tr.betaE_DPCCHlin; tr.SP_E_DPDCH1=tr.SP_E_DPDCH1*tr.betaE_DPDCH1lin; tr.SP_E_DPDCH2=tr.SP_E_DPDCH2*tr.betaE_DPDCH2lin; tr.SP_E_DPDCH3=tr.SP_E_DPDCH3*tr.betaE_DPDCH3lin; tr.SP_E_DPDCH4=tr.SP_E_DPDCH4*tr.betaE_DPDCH4lin; //radio frame tr.radioFrame.set_length(tr.gold.numG); for(int i=0;i<tr.gold.numG;i++) { tr.radioFrame[i]._Val[0]=tr.SP_E_DPCCH[i]+tr.SP_E_DPDCH1[i]+tr.SP_E_DPDCH3[i]; tr.radioFrame[i]._Val[1]=tr.SP_DPCCH[i]+tr.SP_HS_DPCCH[i]+tr.SP_E_DPDCH2[i]+tr.SP_E_DPDCH4[i]; } radioFrameScrambling=tr.scrambling(tr.radioFrame,tr.gold.c); radioFrameALL=concat(radioFrameALL,radioFrameScrambling); } //kanal awg.set_noise(N0(i)); radioFrameChannel1=awg(radioFrameALL); tdlChanel(radioFrameChannel1,radioFrameChannel2,coffeChannel); //odbiornik coffeChannel=conj(coffeChannel); path1.set_length(38400*numOfIteration); path2.set_length(38400*numOfIteration); path3.set_length(38400*numOfIteration); path4.set_length(38400*numOfIteration); path5.set_length(38400*numOfIteration); path6.set_length(38400*numOfIteration); path1.zeros(); path2.zeros(); path3.zeros(); path4.zeros(); path5.zeros(); path6.zeros(); for(int i=0;i<38400*numOfIteration;i++) { path1(i)=radioFrameChannel2(i); if(delayPath(1)+i<38400*numOfIteration) { path2(i)=radioFrameChannel2(i+delayPath(1)); } if(delayPath(2)+i<38400*numOfIteration) { path3(i)=radioFrameChannel2(i+delayPath(2)); } if(delayPath(3)+i<38400*numOfIteration) { path4(i)=radioFrameChannel2(i+delayPath(3)); } if(delayPath(4)+i<38400*numOfIteration) { path5(i)=radioFrameChannel2(i+delayPath(4)); } if(delayPath(5)+i<38400*numOfIteration) { path6(i)=radioFrameChannel2(i+delayPath(5)); } } cvec path1Descrambling,path2Descrambling,path3Descrambling,path4Descrambling,path5Descrambling,path6Descrambling; vec path1DescramblingReal,path2DescramblingReal,path3DescramblingReal,path4DescramblingReal,path5DescramblingReal,path6DescramblingReal; vec path1DescramblingImag,path2DescramblingImag,path3DescramblingImag,path4DescramblingImag,path5DescramblingImag,path6DescramblingImag; vec correctionFactorPath1,correctionFactorPath2,correctionFactorPath3,correctionFactorPath4,correctionFactorPath5,correctionFactorPath6; correctionFactorPath1.set_length(numOfIteration*38400); correctionFactorPath2.set_length(numOfIteration*38400); correctionFactorPath3.set_length(numOfIteration*38400); correctionFactorPath4.set_length(numOfIteration*38400); correctionFactorPath5.set_length(numOfIteration*38400); correctionFactorPath6.set_length(numOfIteration*38400); path1Descrambling.set_length(numOfIteration*38400); path2Descrambling.set_length(numOfIteration*38400); path3Descrambling.set_length(numOfIteration*38400); path4Descrambling.set_length(numOfIteration*38400); path5Descrambling.set_length(numOfIteration*38400); path6Descrambling.set_length(numOfIteration*38400); for(int z=0;z<numOfIteration*38400;z++) { correctionFactorPath1[i]=abs(coffeChannel(i,0))*EbN0(i); correctionFactorPath2[i]=abs(coffeChannel(i,1))*EbN0(i); correctionFactorPath3[i]=abs(coffeChannel(i,2))*EbN0(i); correctionFactorPath4[i]=abs(coffeChannel(i,3))*EbN0(i); correctionFactorPath5[i]=abs(coffeChannel(i,4))*EbN0(i); correctionFactorPath6[i]=abs(coffeChannel(i,5))*EbN0(i); } //Descrambling for(int z=0;z<numOfIteration*38400;z++) { path1Descrambling[z]=path1(z)*tr.gold.cConjugate(z%38400); path2Descrambling[z]=path2(z)*tr.gold.cConjugate(z%38400); path3Descrambling[z]=path3(z)*tr.gold.cConjugate(z%38400); path4Descrambling[z]=path4(z)*tr.gold.cConjugate(z%38400); path5Descrambling[z]=path5(z)*tr.gold.cConjugate(z%38400); path6Descrambling[z]=path6(z)*tr.gold.cConjugate(z%38400); } path1DescramblingReal=real(path1Descrambling); path2DescramblingReal=real(path2Descrambling); path3DescramblingReal=real(path3Descrambling); path4DescramblingReal=real(path4Descrambling); path5DescramblingReal=real(path5Descrambling); path6DescramblingReal=real(path6Descrambling); path1DescramblingImag=imag(path1Descrambling); path2DescramblingImag=imag(path2Descrambling); path3DescramblingImag=imag(path3Descrambling); path4DescramblingImag=imag(path4Descrambling); path5DescramblingImag=imag(path5Descrambling); path6DescramblingImag=imag(path6Descrambling); vec path1HS_DPCCH,path2HS_DPCCH,path3HS_DPCCH,path4HS_DPCCH,path5HS_DPCCH,path6HS_DPCCH; vec path1DPCCH,path2DPCCH,path3DPCCH,path4DPCCH,path5DPCCH,path6DPCCH; vec path1E_DPCCH,path2E_DPCCH,path3E_DPCCH,path4E_DPCCH,path5E_DPCCH,path6E_DPCCH; vec path1E_DPDCH1,path2E_DPDCH1,path3E_DPDCH1,path4E_DPDCH1,path5E_DPDCH1,path6E_DPDCH1; vec path1E_DPDCH2,path2E_DPDCH2,path3E_DPDCH2,path4E_DPDCH2,path5E_DPDCH2,path6E_DPDCH2; vec path1E_DPDCH3,path2E_DPDCH3,path3E_DPDCH3,path4E_DPDCH3,path5E_DPDCH3,path6E_DPDCH3; vec path1E_DPDCH4,path2E_DPDCH4,path3E_DPDCH4,path4E_DPDCH4,path5E_DPDCH4,path6E_DPDCH4; path1HS_DPCCH.set_length(numOfIteration*38400); path2HS_DPCCH.set_length(numOfIteration*38400); path3HS_DPCCH.set_length(numOfIteration*38400); path4HS_DPCCH.set_length(numOfIteration*38400); path5HS_DPCCH.set_length(numOfIteration*38400); path6HS_DPCCH.set_length(numOfIteration*38400); path1DPCCH.set_length(numOfIteration*38400); path2DPCCH.set_length(numOfIteration*38400); path3DPCCH.set_length(numOfIteration*38400); path4DPCCH.set_length(numOfIteration*38400); path5DPCCH.set_length(numOfIteration*38400); path6DPCCH.set_length(numOfIteration*38400); path1E_DPCCH.set_length(numOfIteration*38400); path2E_DPCCH.set_length(numOfIteration*38400); path3E_DPCCH.set_length(numOfIteration*38400); path4E_DPCCH.set_length(numOfIteration*38400); path5E_DPCCH.set_length(numOfIteration*38400); path6E_DPCCH.set_length(numOfIteration*38400); path1E_DPDCH1.set_length(numOfIteration*38400); path2E_DPDCH1.set_length(numOfIteration*38400); path3E_DPDCH1.set_length(numOfIteration*38400); path4E_DPDCH1.set_length(numOfIteration*38400); path5E_DPDCH1.set_length(numOfIteration*38400); path6E_DPDCH1.set_length(numOfIteration*38400); path1E_DPDCH2.set_length(numOfIteration*38400); path2E_DPDCH2.set_length(numOfIteration*38400); path3E_DPDCH2.set_length(numOfIteration*38400); path4E_DPDCH2.set_length(numOfIteration*38400); path5E_DPDCH2.set_length(numOfIteration*38400); path6E_DPDCH2.set_length(numOfIteration*38400); path1E_DPDCH3.set_length(numOfIteration*38400); path2E_DPDCH3.set_length(numOfIteration*38400); path3E_DPDCH3.set_length(numOfIteration*38400); path4E_DPDCH3.set_length(numOfIteration*38400); path5E_DPDCH3.set_length(numOfIteration*38400); path6E_DPDCH3.set_length(numOfIteration*38400); path1E_DPDCH4.set_length(numOfIteration*38400); path2E_DPDCH4.set_length(numOfIteration*38400); path3E_DPDCH4.set_length(numOfIteration*38400); path4E_DPDCH4.set_length(numOfIteration*38400); path5E_DPDCH4.set_length(numOfIteration*38400); path6E_DPDCH4.set_length(numOfIteration*38400); for(int i=0;i<numOfIteration*38400;i++) { //HS_DPCCH path1HS_DPCCH[i]=path1DescramblingImag(i)*tr.OVSF256_33(i%256)*correctionFactorPath1(i); path2HS_DPCCH[i]=path2DescramblingImag(i)*tr.OVSF256_33(i%256)*correctionFactorPath2(i); path3HS_DPCCH[i]=path3DescramblingImag(i)*tr.OVSF256_33(i%256)*correctionFactorPath3(i); path4HS_DPCCH[i]=path4DescramblingImag(i)*tr.OVSF256_33(i%256)*correctionFactorPath4(i); path5HS_DPCCH[i]=path5DescramblingImag(i)*tr.OVSF256_33(i%256)*correctionFactorPath5(i); path6HS_DPCCH[i]=path6DescramblingImag(i)*tr.OVSF256_33(i%256)*correctionFactorPath6(i); //DPCCH path1DPCCH[i]=path1DescramblingImag(i)*tr.OVSF256_0(i%256)*correctionFactorPath1(i); path2DPCCH[i]=path2DescramblingImag(i)*tr.OVSF256_0(i%256)*correctionFactorPath2(i); path3DPCCH[i]=path3DescramblingImag(i)*tr.OVSF256_0(i%256)*correctionFactorPath3(i); path4DPCCH[i]=path4DescramblingImag(i)*tr.OVSF256_0(i%256)*correctionFactorPath4(i); path5DPCCH[i]=path5DescramblingImag(i)*tr.OVSF256_0(i%256)*correctionFactorPath5(i); path6DPCCH[i]=path6DescramblingImag(i)*tr.OVSF256_0(i%256)*correctionFactorPath6(i); //E_DPCCH path1E_DPCCH[i]=path1DescramblingReal(i)*tr.OVSF256_1(i%256)*correctionFactorPath1(i); path2E_DPCCH[i]=path2DescramblingReal(i)*tr.OVSF256_1(i%256)*correctionFactorPath2(i); path3E_DPCCH[i]=path3DescramblingReal(i)*tr.OVSF256_1(i%256)*correctionFactorPath3(i); path4E_DPCCH[i]=path4DescramblingReal(i)*tr.OVSF256_1(i%256)*correctionFactorPath4(i); path5E_DPCCH[i]=path5DescramblingReal(i)*tr.OVSF256_1(i%256)*correctionFactorPath5(i); path6E_DPCCH[i]=path6DescramblingReal(i)*tr.OVSF256_1(i%256)*correctionFactorPath6(i); //E_DPDCH1 path1E_DPDCH1[i]=path1DescramblingReal(i)*tr.OVSF2_1(i%2)*correctionFactorPath1(i); path2E_DPDCH1[i]=path2DescramblingReal(i)*tr.OVSF2_1(i%2)*correctionFactorPath2(i); path3E_DPDCH1[i]=path3DescramblingReal(i)*tr.OVSF2_1(i%2)*correctionFactorPath3(i); path4E_DPDCH1[i]=path4DescramblingReal(i)*tr.OVSF2_1(i%2)*correctionFactorPath4(i); path5E_DPDCH1[i]=path5DescramblingReal(i)*tr.OVSF2_1(i%2)*correctionFactorPath5(i); path6E_DPDCH1[i]=path6DescramblingReal(i)*tr.OVSF2_1(i%2)*correctionFactorPath6(i); //E_DPDCH2 path1E_DPDCH2[i]=path1DescramblingImag(i)*tr.OVSF2_1(i%2)*correctionFactorPath1(i); path2E_DPDCH2[i]=path2DescramblingImag(i)*tr.OVSF2_1(i%2)*correctionFactorPath2(i); path3E_DPDCH2[i]=path3DescramblingImag(i)*tr.OVSF2_1(i%2)*correctionFactorPath3(i); path4E_DPDCH2[i]=path4DescramblingImag(i)*tr.OVSF2_1(i%2)*correctionFactorPath4(i); path5E_DPDCH2[i]=path5DescramblingImag(i)*tr.OVSF2_1(i%2)*correctionFactorPath5(i); path6E_DPDCH2[i]=path6DescramblingImag(i)*tr.OVSF2_1(i%2)*correctionFactorPath6(i); //E_DPDCH3 path1E_DPDCH3[i]=path1DescramblingReal(i)*tr.OVSF4_1(i%4)*correctionFactorPath1(i); path2E_DPDCH3[i]=path2DescramblingReal(i)*tr.OVSF4_1(i%4)*correctionFactorPath2(i); path3E_DPDCH3[i]=path3DescramblingReal(i)*tr.OVSF4_1(i%4)*correctionFactorPath3(i); path4E_DPDCH3[i]=path4DescramblingReal(i)*tr.OVSF4_1(i%4)*correctionFactorPath4(i); path5E_DPDCH3[i]=path5DescramblingReal(i)*tr.OVSF4_1(i%4)*correctionFactorPath5(i); path6E_DPDCH3[i]=path6DescramblingReal(i)*tr.OVSF4_1(i%4)*correctionFactorPath6(i); //E_DPDCH3 path1E_DPDCH4[i]=path1DescramblingImag(i)*tr.OVSF4_1(i%4)*correctionFactorPath1(i); path2E_DPDCH4[i]=path2DescramblingImag(i)*tr.OVSF4_1(i%4)*correctionFactorPath2(i); path3E_DPDCH4[i]=path3DescramblingImag(i)*tr.OVSF4_1(i%4)*correctionFactorPath3(i); path4E_DPDCH4[i]=path4DescramblingImag(i)*tr.OVSF4_1(i%4)*correctionFactorPath4(i); path5E_DPDCH4[i]=path5DescramblingImag(i)*tr.OVSF4_1(i%4)*correctionFactorPath5(i); path6E_DPDCH4[i]=path6DescramblingImag(i)*tr.OVSF4_1(i%4)*correctionFactorPath6(i); } vec sumHS_DPCCH,sumE_DPCCH,sumDPCCH,sumE_DPDCH1,sumE_DPDCH2,sumE_DPDCH3,sumE_DPDCH4; sumDPCCH.set_length(numOfIteration*38400); sumE_DPCCH.set_length(numOfIteration*38400); sumHS_DPCCH.set_length(numOfIteration*38400); sumE_DPDCH1.set_length(numOfIteration*38400); sumE_DPDCH2.set_length(numOfIteration*38400); sumE_DPDCH3.set_length(numOfIteration*38400); sumE_DPDCH4.set_length(numOfIteration*38400); for(int z=0;z<numOfIteration;z++) { sumHS_DPCCH[z]=path1HS_DPCCH(z)+path2HS_DPCCH(z)+path3HS_DPCCH(z)+path4HS_DPCCH(z)+path5HS_DPCCH(z)+path6HS_DPCCH(z); sumDPCCH[z]=path1DPCCH(z)+path2DPCCH(z)+path3DPCCH(z)+path4DPCCH(z)+path5DPCCH(z)+path6DPCCH(z); sumE_DPCCH[z]=path1E_DPCCH(z)+path2E_DPCCH(z)+path3E_DPCCH(z)+path4E_DPCCH(z)+path5E_DPCCH(z)+path6E_DPCCH(z); sumE_DPDCH1[z]=path1E_DPDCH1(z)+path2E_DPDCH1(z)+path3E_DPDCH1(z)+path4E_DPDCH1(z)+path5E_DPDCH1(z)+path6E_DPDCH1(z); sumE_DPDCH2[z]=path1E_DPDCH2(z)+path2E_DPDCH2(z)+path3E_DPDCH2(z)+path4E_DPDCH2(z)+path5E_DPDCH2(z)+path6E_DPDCH2(z); sumE_DPDCH3[z]=path1E_DPDCH3(z)+path2E_DPDCH3(z)+path3E_DPDCH3(z)+path4E_DPDCH3(z)+path5E_DPDCH3(z)+path6E_DPDCH3(z); sumE_DPDCH4[z]=path1E_DPDCH4(z)+path2E_DPDCH4(z)+path3E_DPDCH4(z)+path4E_DPDCH4(z)+path5E_DPDCH4(z)+path6E_DPDCH4(z); } vec HS_DPCCH,E_DPCCH,DPCCH,E_DPDCH1,E_DPDCH2,E_DPDCH3,E_DPDCH4; bvec bHS_DPCCH,bE_DPCCH,bDPCCH,bE_DPDCH1,bE_DPDCH2,bE_DPDCH3,bE_DPDCH4; E_DPCCH.set_length(150*numOfIteration); DPCCH.set_length(150*numOfIteration); HS_DPCCH.set_length(150*numOfIteration); E_DPDCH1.set_length(19200*numOfIteration); E_DPDCH2.set_length(19200*numOfIteration); E_DPDCH3.set_length(9600*numOfIteration); E_DPDCH4.set_length(9600*numOfIteration); bE_DPCCH.set_length(150*numOfIteration); bDPCCH.set_length(150*numOfIteration); bHS_DPCCH.set_length(150*numOfIteration); bE_DPDCH1.set_length(19200*numOfIteration); bE_DPDCH2.set_length(19200*numOfIteration); bE_DPDCH3.set_length(9600*numOfIteration); bE_DPDCH4.set_length(9600*numOfIteration); E_DPCCH.zeros(); DPCCH.zeros(); HS_DPCCH.zeros(); E_DPDCH1.zeros(); E_DPDCH2.zeros(); E_DPDCH3.zeros(); E_DPDCH4.zeros(); for(int k=0;k<150*numOfIteration;k++) { for(int w=0;w<256;w++) { E_DPCCH[k]=E_DPCCH[k]+sumE_DPCCH[w]; DPCCH[k]=DPCCH[k]+sumDPCCH[w]; HS_DPCCH[k]=HS_DPCCH[k]+sumHS_DPCCH[w]; } (E_DPCCH[k]>0) ? bE_DPCCH[k]=1 : bE_DPCCH[k]=0; (DPCCH[k]>0) ? bDPCCH[k]=1 : bDPCCH[k]=0; (HS_DPCCH[k]>0) ? bHS_DPCCH[k]=1 : bHS_DPCCH[k]=0; } for(int k=0;k<19200*numOfIteration;k++) { for(int w=0;w<2;w++) { E_DPDCH1[k]=E_DPDCH1[k]+sumE_DPDCH1[w]; E_DPDCH2[k]=E_DPDCH2[k]+sumE_DPDCH2[w]; } (E_DPDCH1[k]>0) ? bE_DPDCH1[k]=1 : bE_DPDCH1[k]=0; (E_DPDCH2[k]>0) ? bE_DPDCH2[k]=1 : bE_DPDCH2[k]=0; } for(int k=0;k<9600*numOfIteration;k++) { for(int w=0;w<2;w++) { E_DPDCH3[k]=E_DPDCH3[k]+sumE_DPDCH3[w]; E_DPDCH4[k]=E_DPDCH4[k]+sumE_DPDCH4[w]; } (E_DPDCH3[k]>0) ? bE_DPDCH3[k]=1 : bE_DPDCH3[k]=0; (E_DPDCH4[k]>0) ? bE_DPDCH4[k]=1 : bE_DPDCH4[k]=0; } brDPCCH.count(tr.DPCCHall,bDPCCH); brHS_DPCCH.count(tr.HS_DPCCHall,bHS_DPCCH); brE_DPCCH.count(tr.E_DPCCHall,bE_DPCCH); brE_DPDCH1.count(tr.E_DPDCH1all,bE_DPDCH1); brE_DPDCH2.count(tr.E_DPDCH2all,bE_DPDCH2); brE_DPDCH3.count(tr.E_DPDCH3all,bE_DPDCH3); brE_DPDCH4.count(tr.E_DPDCH4all,bE_DPDCH4); berDPCCH(i)=brDPCCH.get_errorrate(); berHS_DPCCH(i)=brHS_DPCCH.get_errorrate(); berE_DPCCH(i)=brE_DPCCH.get_errorrate(); berE_DPDCH1(i)=brE_DPDCH1.get_errorrate(); berE_DPDCH2(i)=brE_DPDCH2.get_errorrate(); berE_DPDCH3(i)=brE_DPDCH3.get_errorrate(); berE_DPDCH4(i)=brE_DPDCH4.get_errorrate(); } //stats out.open("BER.csv", ios_base::out | ios_base::trunc); out<<"Eb/N0"<<';'<<"BER DPCCH"<<';'<<"BER HS_DPCCH"<<';'<<"BER E_DPCCH"<<';'<<"BER E_DPDCH1"<<';' <<"BER E_DPDCH2"<<';'<<"BER E_DPDCH3"<<';'<<"BER E_DPDCH4"<<endl; for(int i=0;i<EbN0dB.length();i++) { out<<EbN0dB(i)<<';'<<berDPCCH(i)<<';'<<berHS_DPCCH(i)<<';'<<berE_DPCCH(i)<<';'<<berE_DPDCH1(i)<<';' <<berE_DPDCH2(i)<<';'<<berE_DPDCH3(i)<<';'<<berE_DPDCH4(i)<<endl; } out.close(); return 0; }
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; }
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; }
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; }
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)); }
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; }