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

📄 refl_02.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
// file: $isip/class/algo/Reflection/refl_02.cc// version: $Id: refl_02.cc,v 1.12 2002/02/06 03:16:43 zheng Exp $//// isip include files//#include "Reflection.h"#include <Console.h>// method: diagnose//// arguments://  Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//boolean Reflection::diagnose(Integral::DEBUG level_a) {    //---------------------------------------------------------------------------  //  // 0. preliminaries  //  //---------------------------------------------------------------------------  // output the class name  //  if (level_a > Integral::NONE) {    SysString output(L"diagnosing class ");    output.concat(CLASS_NAME);    output.concat(L": ");    Console::put(output);    Console::increaseIndention();  }  //--------------------------------------------------------------------------  //  // 1. required public methods  //  //--------------------------------------------------------------------------  // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing required public methods...\n");    Console::increaseIndention();  }  // test memory manager methods  //  Reflection refl;  Reflection::setGrowSize((long)500);  Reflection* reflp = new Reflection();  for (long j = 1; j <= 100; j++) {    Reflection** refl1 = new Reflection*[j * 100];        // create the objects    //    for (long i = 0; i < j * 100; i++) {      refl1[i] = new Reflection();    }        // delete objects    //    for (long i = (j * 100) - 1; i >= 0; i--) {      delete refl1[i];    }          delete [] refl1;  }   delete reflp;    // test i/o methods  //  Reflection refl0;  Reflection refl1;  Reflection refl2;  refl0.set(COVARIANCE, CHOLESKY, 20, -30);    // we need binary and text sof files  //  String tmp_filename0;  Integral::makeTemp(tmp_filename0);  String tmp_filename1;  Integral::makeTemp(tmp_filename1);  // open files in write mode  //  Sof tmp_file0;  tmp_file0.open(tmp_filename0, File::WRITE_ONLY, File::TEXT);  Sof tmp_file1;  tmp_file1.open(tmp_filename1, File::WRITE_ONLY, File::BINARY);  refl0.write(tmp_file0, (long)0);  refl0.write(tmp_file1, (long)0);  // close the files  //  tmp_file0.close();  tmp_file1.close();  // open the files in read mode  //  tmp_file0.open(tmp_filename0);  tmp_file1.open(tmp_filename1);  // read the value back  //  if (!refl1.read(tmp_file0, (long)0) ||      (refl1.getOrder() != refl0.getOrder()) ||      (refl1.getDynRange() != refl0.getDynRange()) ||      (refl1.getAlgorithm() != refl0.getAlgorithm())) {    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);  }  if (!refl2.read(tmp_file0, (long)0) ||      (refl2.getOrder() != refl0.getOrder()) ||      (refl2.getDynRange() != refl0.getDynRange()) ||      (refl2.getAlgorithm() != refl0.getAlgorithm())) {    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);  }  // close and  delete the temporary files  //  tmp_file0.close();  tmp_file1.close();  File::remove(tmp_filename0);  File::remove(tmp_filename1);    // test the conditional i/o methods  //  Reflection refl_0;  refl_0.setOrder(20);  Sof tmp_file2;  String tmp_filename2;  Integral::makeTemp(tmp_filename2);  tmp_file2.open(tmp_filename2, File::WRITE_ONLY);  refl_0.write(tmp_file2, (long)1);  // close the file  //  tmp_file2.close();  // open the file in read mode  //  tmp_file2.open(tmp_filename2);  refl_0.read(tmp_file2, (long)5);   if (refl_0.getOrder() != 20) {    return Error::handle(name(), L"readData", Error::TEST, __FILE__, __LINE__);  }    refl_0.read(tmp_file2, (long)1);    // close and delete the temporary files  //  tmp_file2.close();    File::remove(tmp_filename2);  if (level_a > Integral::BRIEF) {    Console::close();    File::remove(tmp_filename0);    Console::put(L"closed and removed temp console");  }  // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }    //---------------------------------------------------------------------------  //  // 3. class-specific public methods:  //     set and get methods       //  //---------------------------------------------------------------------------    // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing class-specific public methods: set and get methods...\n");    Console::increaseIndention();  }  // set and get the order  //  Reflection reflc_1;  reflc_1.setOrder((long)4);  if (reflc_1.getOrder() != 4) {    return Error::handle(name(), L"set/get order", Error::TEST,                         __FILE__, __LINE__);  }  // set and get the algorithm  //  reflc_1.setAlgorithm(AUTOCORRELATION);   if (reflc_1.getAlgorithm() != AUTOCORRELATION) {    return Error::handle(name(), L"set/get algorithm", Error::TEST,                         __FILE__, __LINE__);  }    // set and get the dynamic range  //  reflc_1.setDynRange((float)4.5);  if (reflc_1.getDynRange() != 4.5) {    return Error::handle(name(), L"set/get DynRange", Error::TEST,                         __FILE__, __LINE__);  }    // set and get the set  //  long ord;  ALGORITHM alg;  IMPLEMENTATION imp;  float dyn;  reflc_1.set(AUTOCORRELATION, DURBIN, 4, (float)4.5);  reflc_1.get(alg, imp, ord, dyn);  if ((ord != 4) || (alg != AUTOCORRELATION) || (imp != DURBIN) ||      (dyn != 4.5)) {    return Error::handle(name(), L"set/get method", Error::TEST,                         __FILE__, __LINE__);  }    // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }  //---------------------------------------------------------------------------  //  // 4. class-specific public methods:  //      computational methods       //  //---------------------------------------------------------------------------  // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing class-specific public methods: computational methods...\n");    Console::increaseIndention();  }      // setup variables for test  //  Reflection reflc;  VectorFloat input;  VectorFloat refl_coef;  VectorFloat pred_coef;  {    // declare the number of samples    //    int N = 24;    // declare the order    //    long M = 4;        // use the following data as input:    //     //  x(n) = 0 when n = 0, 1, 2, 3;     //  x(n) = 1*pow(0.99, n-4) - pow(0.99, 2(n-4)),  when 4 <= n < 20;    //  x(n) = 0 when n = 20, 21, 22, 23     //    input.setLength(N);    float z = 1;    for (long i = 4; i < 20; i++) {      input(i) = 2 * z - z * z;      z = 0.99 * z;    }        // expected prediction coeffience and reflection coefficients for the    // autocorrelation, covariance and burg analysis    //    VectorFloat res_pred_coef_autoc;    VectorFloat res_pred_coef_cov;    VectorFloat res_pred_coef_burg;    VectorFloat res_refl_coef_autoc;    VectorFloat res_refl_coef_cov;    VectorFloat res_refl_coef_burg;    VectorFloat zeros;        res_pred_coef_autoc.assign(L"1.000000, -0.9666891, 0.00009353, 0.00009286241, 0.03525937");    res_pred_coef_cov.assign(L"1.000000, -0.9666891, 0.0000935849, 0.000092812, 0.03525938");    res_pred_coef_burg.assign(L"1.0000000, -0.9666889, 0.00009363125, 0.00009251215, 0.03525940");     zeros.assign(L"0, 0, 0, 0");        res_refl_coef_autoc.assign(L"-0.9378492, 0.03325092, 0.03422026, 0.03525937");    res_refl_coef_cov.assign(L"-0.9378492, 0.03325093, 0.03422021, 0.03525938");    res_refl_coef_burg.assign(L"-0.9378492, 0.03325069, 0.03421993, 0.03525940");    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=    // case: Algorithm = AUTOCORRELATION, Implementation = DURBIN    //       Input = non-zero CORRELATION vector    // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=        // compute the autocorrelation coefficients with order M    //    Correlation autoCorr(Correlation::AUTO, Correlation::FACTORED,			 Correlation::NONE, M);    VectorFloat auto_coeff;    autoCorr.compute(auto_coeff, input);    // since the order for computing the autocorrelation coefficient is M    // we sould get M + 1 autocorrelation coefficient    //    if (auto_coeff.length() != M + 1) {      return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);

⌨️ 快捷键说明

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