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

📄 pred_02.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
// file: $isip/class/algo/Prediction/pred_02.cc// version: $Id: pred_02.cc,v 1.12 2002/03/05 20:15:10 zheng Exp $//// isip include files//#include <Console.h>#include "Prediction.h"#include "LogAreaRatio.h"// method: diagnose//// arguments://  Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//boolean Prediction::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();  }  //  don't exit  //  Error::reset();  Error::set(Error::NONE);     //--------------------------------------------------------------------------  //  // 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  //  Prediction lp;  Prediction::setGrowSize((long)500);  Prediction* lpp = new Prediction();    for (long j = 1; j <= 100; j++) {    Prediction** lp1 = new Prediction*[j * 100];        // create the objects    //    for (long i = 0; i < j * 100; i++) {      lp1[i] = new Prediction();    }        // delete objects    //    for (long i = (j * 100) - 1; i >= 0; i--) {      delete lp1[i];    }          delete [] lp1;  }   delete lpp;    // test i/o methods  //  Prediction lp0;  Prediction lp1;  Prediction lp2;  lp0.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);  lp0.write(tmp_file0, (long)0);  lp0.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 (!lp1.read(tmp_file0, (long)0) ||      (lp1.getOrder() != lp0.getOrder()) ||      (lp1.getDynRange() != lp0.getDynRange()) ||      (lp1.getAlgorithm() != lp0.getAlgorithm())) {    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);  }  if (!lp2.read(tmp_file1, (long)0) ||      (lp2.getOrder() != lp0.getOrder()) ||      (lp2.getDynRange() != lp0.getDynRange()) ||      (lp2.getAlgorithm() != lp0.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  //  Prediction lp_0;  lp_0.setOrder(20);  Sof tmp_file2;  String tmp_filename2;  Integral::makeTemp(tmp_filename2);  tmp_file2.open(tmp_filename2, File::WRITE_ONLY);  lp_0.write(tmp_file2, (long)5);  // close the file  //  tmp_file2.close();  // open the file in read mode  //  tmp_file2.open(tmp_filename2);  lp_0.read(tmp_file2, (long)5);   if (lp_0.getOrder() != (long)20) {    lp_0.debug(L"lp_0");    return Error::handle(name(), L"readData", Error::TEST, __FILE__, __LINE__);  }    lp_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: get and set methods...\n");    Console::increaseIndention();  }  // set and get the order  //  Prediction lpc_1;  lpc_1.setOrder((long)4);  if (lpc_1.getOrder() != 4) {    return Error::handle(name(), L"set/get order", Error::TEST,                         __FILE__, __LINE__);  }  // set and get the algorithm  //  lpc_1.setAlgorithm(AUTOCORRELATION);   if (lpc_1.getAlgorithm() != AUTOCORRELATION) {    return Error::handle(name(), L"set/get algorithm", Error::TEST,                         __FILE__, __LINE__);  }    // set and get the dynamic range  //  lpc_1.setDynRange((double)4.5);  if (lpc_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;  lpc_1.set(AUTOCORRELATION, DURBIN, 4, 4.5);  lpc_1.get(alg, imp, ord, dyn);  if ((ord != 4) || (alg != AUTOCORRELATION) || (dyn != 4.5)) {    return Error::handle(name(), L"set/get set 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 vairables for test  //  Prediction lpc;  VectorFloat input;  VectorFloat pred_coef;  VectorFloat result_01(L"1, 0, 0, 0, 0");    // test LATTICE algorithm  //  {    // 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(24);    float z = 1;    for (long i = 4; i < 20; i++) {      input(i) = 2 * z - z * z;      z = 0.99 * z;    }        // expected prediction coefficients for the autocorrelation,    // covariance and burg analysis    //    VectorFloat res_pred_coef_autoc;    VectorFloat res_pred_coef_burg;    res_pred_coef_autoc.assign(L"1.000000, -0.9666891, 0.00009353, 0.00009286241, 0.03525937");    res_pred_coef_burg.assign(L"1.0000000, -0.9666889, 0.00009363125, 0.00009251215, 0.03525940");         // case: algorithm = LATTICE, implementation = BURG,    //       input = non-zero SIGNAL vector    //    lpc.set(LATTICE, BURG, 4, -200);

⌨️ 快捷键说明

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