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

📄 cep_02.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
  //   ceps.setAlgorithm(IDCT);  // test using TYPE_I  //  ceps.setImplementation(TYPE_I);  // the input data is real magnitude of FFT of one cycle of a 1000 Hz  // cosine sampled at 16 KHz  //  realinput.assign(L"1.0000, 8.7079, 0.3839, 0.1354, 0.0676, 0.0383, 0.0222, 0.0117, 0.0037");  // get all the cepstral coeffs  //  ceps.setOrder(8);    // expected result is IDCT of the log of the above signal  //  realans.assign(L"-6.7049, 6.28358, 0.420223, 1.65386, -0.94425, 0.290068, -1.68546, -0.308728, -1.36924");  // compute the result  //  ceps.compute(realoutput, realinput);  if (!realoutput.almostEqual(realans, 20)) {    realans.debug(L"expected result:");    realoutput.debug(L"wrong result:");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }    // the input data is complex FFT of one cycle of a 1000 Hz cosine  // sampled at 16 KHz  //  complexinput.assign(L"1.0000, 8.5596 + 1.6001j, -0.3580 - 0.1387j, -0.1151 - 0.0713j, -0.0500 - 0.0456j, -0.0231 - 0.0306j, -0.0099 - 0.0199j, -0.0032 - 0.0113j, -0.0003 - 0.0037j");    // expected result is tha same as before, compute the result  //  ceps.compute(realoutput, complexinput);    if (!realoutput.almostEqual(realans, 20)) {    realans.debug(L"expected result:");    realoutput.debug(L"wrong result:");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }    // test using TYPE_II  //  ceps.setImplementation(TYPE_II);  // the input data is real magnitude of FFT of one cycle of a 1000 Hz  // cosine sampled at 16 KHz  //  realinput.assign(L"1.0000, 8.7079, 0.3839, 0.1354, 0.0676, 0.0383, 0.0222, 0.0117, 0.0037");    // expected result is IDCT of the log of the above signal  //  realans.assign(L"-4.2873, 7.6049, -1.7904, 2.7996, -1.7622, 0.8024, -1.6565, -0.4578, -1.2527");    // compute the result  //  ceps.compute(realoutput, realinput);  if (!realoutput.almostEqual(realans, 20)) {    realans.debug(L"expected result:");    realoutput.debug(L"wrong result:");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }    // the input data is complex FFT of one cycle of a 1000 Hz cosine  // sampled at 16 KHz  //  complexinput.assign(L"1.0000, 8.5596 + 1.6001j, -0.3580 - 0.1387j, -0.1151 - 0.0713j, -0.0500 - 0.0456j, -0.0231 - 0.0306j, -0.0099 - 0.0199j, -0.0032 - 0.0113j, -0.0003 - 0.0037j");    // expected result is tha same as before, compute the result  //  ceps.compute(realoutput, complexinput);    if (!realoutput.almostEqual(realans, 20)) {    realans.debug(L"expected result:");    realoutput.debug(L"wrong result:");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }    // test using TYPE_III  //  ceps.setImplementation(TYPE_III);  // the input data is real magnitude of FFT of one cycle of a 1000 Hz  // cosine sampled at 16 KHz  //  realinput.assign(L"1.0000, 8.7079, 0.3839, 0.1354, 0.0676, 0.0383, 0.0222, 0.0117, 0.0037");    // expected result is IDCT of the log of the above signal  //  realans.assign(L"-6.86812, 6.36626, 0.541492, 0.606799, -1.07368, -0.876116, -1.33646, -0.856119, -0.57994");    // compute the result  //  ceps.compute(realoutput, realinput);  if (!realoutput.almostEqual(realans, 20)) {    realans.debug(L"expected result:");    realoutput.debug(L"wrong result:");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }    // the input data is complex FFT of one cycle of a 1000 Hz cosine  // sampled at 16 KHz  //  complexinput.assign(L"1.0000, 8.5596 + 1.6001j, -0.3580 - 0.1387j, -0.1151 - 0.0713j, -0.0500 - 0.0456j, -0.0231 - 0.0306j, -0.0099 - 0.0199j, -0.0032 - 0.0113j, -0.0003 - 0.0037j");    // expected result is tha same as before, compute the result  //  ceps.compute(realoutput, complexinput);    if (!realoutput.almostEqual(realans, 20)) {    realans.debug(L"expected result:");    realoutput.debug(L"wrong result:");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }  // test using TYPE_IV  //  ceps.setImplementation(TYPE_IV);  // the input data is real magnitude of FFT of one cycle of a 1000 Hz  // cosine sampled at 16 KHz  //  realinput.assign(L"1.0000, 8.7079, 0.3839, 0.1354, 0.0676, 0.0383, 0.0222, 0.0117, 0.0037");    // expected result is IDCT of the log of the above signal  //  realans.assign(L"-3.50716, 7.13176, -2.38539, 1.98795, -2.95938, 0.585732, -2.727, 0.7846, -1.78334");  // compute the result  //  ceps.compute(realoutput, realinput);  if (!realoutput.almostEqual(realans, 20)) {    realans.debug(L"expected result:");    realoutput.debug(L"wrong result:");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }    // the input data is complex FFT of one cycle of a 1000 Hz cosine  // sampled at 16 KHz  //  complexinput.assign(L"1.0000, 8.5596 + 1.6001j, -0.3580 - 0.1387j, -0.1151 - 0.0713j, -0.0500 - 0.0456j, -0.0231 - 0.0306j, -0.0099 - 0.0199j, -0.0032 - 0.0113j, -0.0003 - 0.0037j");    // expected result is tha same as before, compute the result  //  ceps.compute(realoutput, complexinput);    if (!realoutput.almostEqual(realans, 20)) {    realans.debug(L"expected result:");    realoutput.debug(L"wrong result:");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }    // test the second algorithm that is IDFT  //    ceps.setAlgorithm(IDFT);    // test using CONVENTIONAL  //  ceps.setImplementation(CONVENTIONAL);    // the input data is real magnitude FFT of one cycle of a 1000 Hz  // cos + a 2000 Hz sin sampled at 16 KHz  //  realinput.assign(L"1.0000, 8.7270, 8.0161, 1.4306, 0.7777, 0.5766, 0.4838, 0.4369, 0.4166");    // expected result is complex IDFT of the log magnitude spectra  //  complexans.assign(L"0.1527, 0.2382 + 0.6513j, -0.1538 + 0.3177j, -0.1377 + 0.0415j, -0.0231 - 0.0206j, -0.0231 + 0.0206j, -0.1377 - 0.0415j, -0.1538 - 0.3177j, 0.2382 - 0.6513j");    // compute the result  //  ceps.compute(complexoutput, realinput);    if (!complexoutput.almostEqual(complexans, 20)) {    complexans.debug(L"expected result:");    complexoutput.debug(L"wrong result:");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }    // the input data is complex FFT of one cycle of a 1000 Hz cos + a  // 2000 Hz sin sampled at 16 KHz  //  complexinput.assign(L"1.0000, 8.6656 + 1.0334j, 2.5344 - 7.6049j, -0.8648 + 1.1396j, -0.5720 + 0.5270j, -0.4822 + 0.3162j, -0.4425 + 0.1955j, -0.4233 + 0.1082j,  -0.4152 + 0.0348j");  // the input data is complex as before, expected result is complex  // one cycle of a 1000 Hz cos + a 2000 Hz sine sampled at 16 KHz  //  complexans.assign(L"0.1527 + 1.6359j, 0.9561 + 0.1609j, 0.2648 + 0.3548j, -0.2375 + 0.0479j, -0.1764 - 0.3916j, 0.1302 - 0.3504j, -0.0379 - 0.0352j, -0.5724 - 0.2806j, -0.4796 - 1.1417j");    ceps.compute(complexoutput, complexinput);    if (!complexoutput.almostEqual(complexans, 20)) {    complexans.debug(L"expected result:");    complexoutput.debug(L"wrong result:");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }  // test using TRIGONOMETRIC  //  ceps.setImplementation(CONVENTIONAL);    // the input data is real magnitude FFT of one cycle of a 1000 Hz  // cos + a 2000 Hz sin sampled at 16 KHz  //  realinput.assign(L"1.0000, 8.7270, 8.0161, 1.4306, 0.7777, 0.5766, 0.4838, 0.4369, 0.4166");    // expected result is complex IDFT of the log magnitude spectra  //  complexans.assign(L"0.1527, 0.2382 + 0.6513j, -0.1538 + 0.3177j, -0.1377 + 0.0415j, -0.0231 - 0.0206j, -0.0231 + 0.0206j, -0.1377 - 0.0415j, -0.1538 - 0.3177j, 0.2382 - 0.6513j");    // compute the result  //  ceps.compute(complexoutput, realinput);    if (!complexoutput.almostEqual(complexans, 20)) {    complexans.debug(L"expected result:");    complexoutput.debug(L"wrong result:");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }    // the input data is complex FFT of one cycle of a 1000 Hz cos + a  // 2000 Hz sin sampled at 16 KHz  //  complexinput.assign(L"1.0000, 8.6656 + 1.0334j, 2.5344 - 7.6049j, -0.8648 + 1.1396j, -0.5720 + 0.5270j, -0.4822 + 0.3162j, -0.4425 + 0.1955j, -0.4233 + 0.1082j,  -0.4152 + 0.0348j");    // the input data is complex as before, expected result is complex  // one cycle of a 1000 Hz sine  //  complexans.assign(L"0.1527 + 1.6359j, 0.9561 + 0.1609j, 0.2648 + 0.3548j, -0.2375 + 0.0479j, -0.1764 - 0.3916j, 0.1302 - 0.3504j, -0.0379 - 0.0352j, -0.5724 - 0.2806j, -0.4796 - 1.1417j");    ceps.compute(complexoutput, complexinput);    if (!complexoutput.almostEqual(complexans, 20)) {    complexans.debug(L"expected result:");    complexoutput.debug(L"wrong result:");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }    // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }   //---------------------------------------------------------------------------  //  // 5. 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 + -