コード例 #1
0
ファイル: sigfun.cpp プロジェクト: c304728539/itpp-fastica
vec spectrum(const vec &v, const vec &w, int noverlap)
{
  int nfft = w.size();
  it_assert_debug(pow2i(levels2bits(nfft)) == nfft,
                  "The window size must be a power of two in spectrum()!");

  vec P(nfft / 2 + 1), wd(nfft);

  P = 0.0;
  double w_energy = energy(w);

  if (nfft > v.size()) {
    P = sqr(abs(fft(to_cvec(elem_mult(zero_pad(v, nfft), w)))(0, nfft / 2)));
    P /= w_energy;
  }
  else {
    int k = (v.size() - noverlap) / (nfft - noverlap), idx = 0;
    for (int i = 0; i < k; i++) {
      wd = elem_mult(v(idx, idx + nfft - 1), w);
      P += sqr(abs(fft(to_cvec(wd))(0, nfft / 2)));
      idx += nfft - noverlap;
    }
    P /= k * w_energy;
  }

  P.set_size(nfft / 2 + 1, true);
  return P;
}
コード例 #2
0
ファイル: distance.cpp プロジェクト: greeness/graphlab_CMU
flt_dbl calc_euclidian_distance( sparse_flt_dbl_vec & datapoint,  sparse_flt_dbl_vec &cluster, flt_dbl sqr_sum, flt_dbl sqr_sum0){
  //sparse_flt_dbl_vec diff = minus(datapoint , cluster);
  //return sqrt(sum_sqr(diff));
  sparse_flt_dbl_vec mult = elem_mult(datapoint, cluster);
  flt_dbl diff = (sqr_sum + sqr_sum0 - 2*sum(mult));
  return sqrt(fabs(diff)); //because of numerical errors, diff may be negative
}
コード例 #3
0
ファイル: poly.cpp プロジェクト: c304728539/itpp-fastica
cvec polyval(const cvec &p, const cvec &x)
{
  it_error_if(p.size() == 0, "polyval: size of polynomial is zero");
  it_error_if(x.size() == 0, "polyval: size of input value vector is zero");

  cvec out(x.size());

  out = p(0);

  for (int i = 1; i < p.size(); i++)
    out = p(i) + elem_mult(x, out);

  return out;
}
コード例 #4
0
ファイル: poly.cpp プロジェクト: c304728539/itpp-fastica
cvec polyval(const cvec &p, const vec &x)
{
  it_error_if(p.size() == 0, "polyval: size of polynomial is zero");
  it_error_if(x.size() == 0, "polyval: size of input value vector is zero");

  cvec out(x.size());

  out = p(0);

  for (int i = 1; i < p.size(); i++)
    out = std::complex<double>(p(i)) + elem_mult(to_cvec(x), out);

  return out;
}
コード例 #5
0
ファイル: error_counters.cpp プロジェクト: nvmd/itpp
void BERC::estimate_delay(const bvec &in1, const bvec &in2, int mindelay,
                          int maxdelay)
{
  int num, start1, start2;
  int min_input_length = std::min(in1.length(), in2.length());
  int bestdelay = mindelay;
  double correlation;
  double bestcorr = 0;
  for (int i = mindelay; i < maxdelay; i++) {
    num = min_input_length - std::abs(i) - ignorefirst - ignorelast;
    start1 = (i < 0) ? -i : 0;
    start2 = (i > 0) ?  i : 0;
    correlation = fabs(sum(to_vec(elem_mult(in1.mid(start1, num),
                                            in2.mid(start2, num)))));
    if (correlation > bestcorr) {
      bestdelay = i;
      bestcorr  = correlation;
    }
  }
  delay = bestdelay;
}
コード例 #6
0
ファイル: QuantumStateITPP.cpp プロジェクト: Phali/libs
QuantumStateITPP evolve_with_phases(QuantumStateITPP &psi, itpp::Vec<double> eigenvalues, double t){
// 	psi=exp(-I*time*eigenvalues) * psi_0
	QuantumStateITPP tmp;
	tmp.coefficients = elem_mult(itpp::exp(eigenvalues * t * std::complex<double>(0.,1.)),psi.coefficients) ;
	return tmp;
}
コード例 #7
0
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
}
コード例 #8
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;

}
コード例 #9
0
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;

}
コード例 #10
0
ファイル: sigfun.cpp プロジェクト: c304728539/itpp-fastica
//Correlation
void xcorr(const cvec &x, const cvec &y, cvec &out, const int max_lag, const std::string scaleopt, bool autoflag)
{
  int N = std::max(x.length(), y.length());

  //Compute the FFT size as the "next power of 2" of the input vector's length (max)
  int b = ceil_i(::log2(2.0 * N - 1));
  int fftsize = pow2i(b);

  int end = fftsize - 1;

  cvec temp2;
  if (autoflag == true) {
    //Take FFT of input vector
    cvec X = fft(zero_pad(x, fftsize));

    //Compute the abs(X).^2 and take the inverse FFT.
    temp2 = ifft(elem_mult(X, conj(X)));
  }
  else {
    //Take FFT of input vectors
    cvec X = fft(zero_pad(x, fftsize));
    cvec Y = fft(zero_pad(y, fftsize));

    //Compute the crosscorrelation
    temp2 = ifft(elem_mult(X, conj(Y)));
  }

  // Compute the total number of lags to keep. We truncate the maximum number of lags to N-1.
  int maxlag;
  if ((max_lag == -1) || (max_lag >= N))
    maxlag = N - 1;
  else
    maxlag = max_lag;


  //Move negative lags to the beginning of the vector. Drop extra values from the FFT/IFFt
  if (maxlag == 0) {
    out.set_size(1, false);
    out = temp2(0);
  }
  else
    out = concat(temp2(end - maxlag + 1, end), temp2(0, maxlag));


  //Scale data
  if (scaleopt == "biased")
    //out = out / static_cast<double_complex>(N);
    out = out / static_cast<std::complex<double> >(N);
  else if (scaleopt == "unbiased") {
    //Total lag vector
    vec lags = linspace(-maxlag, maxlag, 2 * maxlag + 1);
    cvec scale = to_cvec(static_cast<double>(N) - abs(lags));
    out /= scale;
  }
  else if (scaleopt == "coeff") {
    if (autoflag == true) // Normalize by Rxx(0)
      out /= out(maxlag);
    else { //Normalize by sqrt(Rxx(0)*Ryy(0))
      double rxx0 = sum(abs(elem_mult(x, x)));
      double ryy0 = sum(abs(elem_mult(y, y)));
      out /= std::sqrt(rxx0 * ryy0);
    }
  }
  else if (scaleopt == "none") {}
  else
    it_warning("Unknow scaling option in XCORR, defaulting to <none> ");

}