当前位置: 首页>>代码示例>>C++>>正文


C++ Estimator::estimate方法代码示例

本文整理汇总了C++中Estimator::estimate方法的典型用法代码示例。如果您正苦于以下问题:C++ Estimator::estimate方法的具体用法?C++ Estimator::estimate怎么用?C++ Estimator::estimate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Estimator的用法示例。


在下文中一共展示了Estimator::estimate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: runbenchmark

void runbenchmark(const vector<int>& Ls, const Pulse& tx, function<Estimator(vector<int>&,vector<int>&,vector<complex<double>>&)> estf, string name) {

  default_random_engine generator; 
      //SNRs
  double SNRdB = 10.0;
  double SNR = pow(10.0, SNRdB/10.0);
  normal_distribution<double> noise(0.0,T/Ts/SNR/2);
  uniform_int_distribution<int> unifM(1, M); //for generating M-PSK symbols
  
  vector<double> times; //array to store output
  
  for(auto L : Ls) {

    const unsigned int numpilots = L/5; //about 10% pilots 
    //symbol position setup
    vector<int> P;
    for(int i = 0; i < numpilots; i++) P.push_back(i); //pilots at the front
    vector<int> D;
    for(int i = numpilots; i < L; i++) D.push_back(i); //data at the back
    vector<complex<double>> s;
    for (int m = 1; m <= L; m++) s.push_back(polar<double>(1.0, 2 * pi * unifM(generator) / M));
    vector<complex<double>> pilots;
    for (int m = 0; m < numpilots; m++) pilots.push_back(s[m]);

    //construct the estimator we will run
    Estimator est = estf(P,D,pilots);
   
    //number of samples
    unsigned int N = (unsigned int) ceil((T*(L+40)+taumax)/Ts); //number of samples
    const complex<double> a0 = polar<double>(1,0.1*pi); //phase and amplitude
    
    //transmitted signal
    auto x = [&s,&tx,T,L] (double t) {
      int mini = max(1, (int)ceil((t - tx.tmax())/T));
      int maxi = min(L, (int)floor((t - tx.tmin())/T));
      complex<double> sum(0,0);
      for(int i = mini; i <= maxi; i++) sum += s[i-1] * tx.pulse(t - i*T);
      return sum;
    };

    //sampled received signal
    vector<complex<double>> r;
    for(int n = 1; n <= N; n++) r.push_back(a0*x(n*Ts-tau0) + complex<double>(noise(generator), noise(generator)));

    cout << "Benchmarking " << name << " L = " << L << " ... ";
    long iters = 0;
    double errmse = 0.0;
    clock_t started = clock();
    while( ((double)(clock() - started))/CLOCKS_PER_SEC < benchtime) {
      double tauhat = est.estimate(r);
      errmse += (tauhat - tau0)*(tauhat - tau0); //use tauhat otherwise it might get compiled out!
      iters++;
    }
    clock_t stopped = clock();
    double microsecs = ((double)(stopped - started))/CLOCKS_PER_SEC/iters/L*1000000;
    times.push_back(microsecs);
    cout << " requires  " << microsecs << " microseconds per symbol with average error " << (errmse/iters) << endl;
  }

  ofstream file(string("data/") + name + string("bench"));
  for(int i = 0; i < Ls.size(); i++) file << Ls[i] << "\t" << times[i] << endl;
  file.close();

}
开发者ID:trada006,项目名称:Android-audio-communication-project,代码行数:64,代码来源:benchmark.cpp


注:本文中的Estimator::estimate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。