⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 refl_02.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
    }        // compute the reflection coefficients using the autocorrelation    // coefficients via the DURBAL algorithm with order M    //    reflc.set(AUTOCORRELATION, DURBIN, M, -200);    reflc.compute(refl_coef, auto_coeff);            if (!refl_coef.almostEqual(res_refl_coef_autoc)) {      refl_coef.debug(L"refl_coef");      res_refl_coef_autoc.debug(L"res_refl_coef");      return Error::handle(name(), L"compute", ERR, __FILE__,			   __LINE__);    }    // since the order for computing the reflection coefficients is M    // we sould get M reflection coefficients    //    if (refl_coef.length() != M) {      return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);    }    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=    // case: Algorithm = AUTOCORRELATION, Implementation = DURBIN    //       Input = zero CORRELATION vector    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=            // test the algorithm for a vector of zeros    //    auto_coeff.assign(0.0);    reflc.compute(refl_coef, auto_coeff);    if (!refl_coef.almostEqual(zeros)) {      return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);    }        refl_coef.clear();    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=    // case: Algorithm = COVARIANCE, Implementation = CHOLESKY    //       Input = non-zero COVARIANCE matrix    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=        // compute the covariance coefficients of order M    //    Covariance covar(Covariance::DEF_ALGORITHM, Covariance::DEF_IMPLEMENTATION,		     Covariance::DEF_NORMALIZATION, M);    MatrixFloat covar_coeff;    covar.compute(covar_coeff, input);    // compute the reflection coefficients using the covariance    // coefficients via the CHOLESKY algorithm with order M    //    reflc.set(COVARIANCE, CHOLESKY, M, -200);    reflc.compute(refl_coef, covar_coeff, AlgorithmData::COVARIANCE);        if (!refl_coef.almostEqual(res_refl_coef_cov)) {      res_pred_coef_cov.debug(L"res_pred_coef");      refl_coef.debug(L"refl_coef");      res_refl_coef_cov.debug(L"res_refl_coef");      return Error::handle(name(), L"compute", ERR, __FILE__, __LINE__);      }    // since the order for computing the reflection coefficients is M    // we sould get M reflection coefficients    //    if (refl_coef.length() != M) {      return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);    }        // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=    // case: Algorithm = COVARIANCE, Implementation = CHOLESKY    //       Input = zero COVARIANCE matrix    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=    // test the algorithm for a vector of zeros    //    covar_coeff.assign(0);    reflc.compute(refl_coef, covar_coeff, AlgorithmData::COVARIANCE);        if (!refl_coef.almostEqual(zeros)) {      return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);    }    refl_coef.clear();    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=    // case: Algorithm = LATTICE, Implementation = BURG    //       Input = non-zero SIGNAL vector    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=    // compute the reflection coefficients using the BURG algorithm via    // a lattice with order M    //    reflc.set(LATTICE, BURG, M, -200);    reflc.compute(refl_coef, input, AlgorithmData::SIGNAL);      if (!refl_coef.almostEqual(res_refl_coef_burg)) {      refl_coef.debug(L"pred_coef");      res_refl_coef_burg.debug(L"res_refl_coef");      return Error::handle(name(), L"compute", ERR, __FILE__, __LINE__);        }    // since the order for computing the reflection coefficients is M    // we sould get M reflection coefficients    //    if (refl_coef.length() != M) {      return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);    }    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=    // case: Algorithm = LATTICE, Implementation = BURG    //       Input = zero SIGNAL vector    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=    // test the algorithm for a vector of zeros    //    input.assign(0.0);    reflc.compute(refl_coef, input, AlgorithmData::SIGNAL);        if (!refl_coef.almostEqual(zeros)) {      return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);    }        refl_coef.clear();        // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=    // case: Algorithm = PREDICTION, Implementation = STEP_DOWN    //       Input = non-zero PREDICTION vector    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=        // compute the reflection coefficients from the predictor coefficients    //    pred_coef.assign(L"1.000000, -0.9666891, 0.00009353, 0.00009286241, 0.03525937");    reflc.setAlgorithm(PREDICTION);    reflc.setImplementation(STEP_UP);    reflc.compute(refl_coef, pred_coef, AlgorithmData::PREDICTION);    VectorFloat res_refl_coef;    res_refl_coef.assign(L"-0.9378492, 0.03325092, 0.03422026, 0.03525937");        if (!refl_coef.almostEqual(res_refl_coef, .3)) {      refl_coef.debug(L"refl_coef from predictor");      return Error::handle(name(), L"computeFromRefelction", ERR, __FILE__,			   __LINE__);    }    // since we have used M + 1  predictor coefficients to compute the    // reflection coefficients we should get M reflection coefficients    //    if (refl_coef.length() != M) {      return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);    }    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=    // case: Algorithm = PREDICTION, Implementation = STEP_DOWN    //       Input = zero PREDICTION vector    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=    // test the algorithm for a vector of zeros    //    pred_coef.assign(0.0);    reflc.compute(refl_coef, pred_coef, AlgorithmData::PREDICTION);    if (!refl_coef.almostEqual(zeros)) {      return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);    }        refl_coef.clear();        // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=    // case: Algorithm = LOG_AREA_RATIO, Implementation = KELLY_LOCHBAUM    //       Input = non-zero LOG_AREA_RATIO vector    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=        // compute the reflection coefficients from the log area ratio coefficients    //    VectorFloat log_arr_coef(L"3.43977, -0.0665264, -0.0684673, -0.070548");    reflc.setAlgorithm(LOG_AREA_RATIO);    reflc.setImplementation(KELLY_LOCHBAUM);    reflc.compute(refl_coef, log_arr_coef, AlgorithmData::LOG_AREA_RATIO);    if (!refl_coef.almostEqual(refl_coef, .3)) {      refl_coef.debug(L"refl_coef from log_arr");      return Error::handle(name(), L"computeFromLogArr", ERR,			   __FILE__, __LINE__);    }    // since we have used M log area ratio coefficients to compute the    // reflection coefficients we should get M reflection coefficients    //    if (refl_coef.length() != M) {      return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);    }    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=    // case: Algorithm = LOG_AREA_RATIO, Implementation = KELLY_LOCHBAUM    //       Input = zero LOG_AREA_RATIO vector    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=        // test the algorithm for a vector of zeros    //    log_arr_coef.assign(0.0);    reflc.compute(refl_coef, log_arr_coef, AlgorithmData::LOG_AREA_RATIO);        if (!refl_coef.almostEqual(zeros)) {      return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);    }    refl_coef.clear();  }  // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }  // --------------------------------------------------------------------  //  // 5. class-specific public methods  //     apply methods  //  // --------------------------------------------------------------------  // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing class-specific public methods: apply methods...\n");    Console::increaseIndention();  }  // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  // case: Algorithm = LATTICE, Implementation = BURG  //       Input = non-zero and zero SIGNAL at channel 0 and 1  // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  // local variables  //  Vector< CircularBuffer<AlgorithmData> > in;  Vector<AlgorithmData> out;  AlgorithmData data;    float z = 1;  for (long i = 4; i < 20; i++) {    input(i) = 2 * z - z * z;    z = 0.99 * z;  }      // number of channels  //  long N = 2;    in.setLength(N);  out.setLength(N);    for (long i = 0; i < N; i++) {    in(i).append(data);    in(i)(0).makeVectorFloat();    in(i)(0).setCoefType(AlgorithmData::SIGNAL);  }  in(0)(0).getVectorFloat().assign(input);  input.assign((float)0);  in(1)(0).getVectorFloat().assign(input);      // compute the reflection coefficients using the BURG algorithm via  // a lattice with order M  //  long M = 4;  reflc.set(LATTICE, BURG, M, -200);  reflc.apply(out, in);  VectorFloat res_refl_coef_burg(L"-0.9378492, 0.03325069, 0.03421993, 0.03525940");  VectorFloat zeros(L"0, 0, 0, 0");    if (!out(0).getVectorFloat().almostEqual(res_refl_coef_burg)) {    out(0).getVectorFloat().debug(L"refl(0)");    res_refl_coef_burg.debug(L"res_refl_coef");    return Error::handle(name(), L"diagnose", ERR, __FILE__, __LINE__);      }  if (!out(1).getVectorFloat().almostEqual(zeros)) {    out(1).getVectorFloat().debug(L"refl(1)");    zeros.debug(L"zeros_refl_coef");    return Error::handle(name(), L"diagnose", ERR, __FILE__, __LINE__);      }    Error::reset();  Error::set(Error::WARNING);  // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }  //---------------------------------------------------------------------------  //  // 6. print completion message  //  //---------------------------------------------------------------------------  // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }    if (level_a > Integral::NONE) {    SysString output(L"diagnostics passed for class ");    output.concat(name());    output.concat(L"\n");    Console::put(output);  }    // exit gracefully  //  return true;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -