📄 spec_02.cc
字号:
Console::increaseIndention(); } // declare the test variables // VectorFloat signal(L"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25.3972,17.3962,17.8608,0,18.7878,-19.2493,9.85443,30.249,30.9303,10.5356,-32.2773,0,11.1997,22.8325,-23.2601,-11.8409,0,0,12.4533,12.6502,-25.686,-26.0633,26.4318,0,-13.5706,-41.2218,0,0,-14.2196,0,-29.0227,-43.9456,44.3391,-29.8096,45.0708,15.1361,0,-46.0244,-46.3025,0,46.7977,-31.3428,0,15.7946,0,15.8893,47.7775,47.8653,-47.9313,0,47.9972,0,47.9752,-31.9542,47.8653,15.9258,-47.6679,-15.8455,31.5892,31.4731,-47.0141,46.7977,31.0403,0,-46.0244,-30.4841,-15.1361,45.0708,44.7143,14.7797,29.2971,0,-14.3683,14.2196,0,-27.8111,-41.2218,-40.7117,0,13.2159,0,-25.686,25.3003,-37.36,24.5054,0,35.5226,-34.8901,-34.2487,22.3994,21.9611,0,31.6067,30.9303,-30.249,-29.5633,0,9.39392,-9.16242,17.8608,-8.6981,8.46573,-16.4671,-8.00175,0,15.0806,21.9334,0,0,19.8972,0,0,-5.9717,0,5.54416,5.33492,0,0,0,-9.06581,0,8.31135,3.97367,0,7.24759,-10.3688,3.29392,6.27378,2.98535,5.67889,2.69932,7.69537,0,4.63003,-2.19936,2.09012,-5.96225,0,5.40597,-3.43892,0,-1.57516,-4.54064,-2.91806,-2.82335,1.37153,-4.01586,0,-1.29467,1.28367,-3.84"); // expected output // VectorFloat exp_full_spec(L"213.54,0,-98.4317,-66.3989,20.414,-22.5332,-18.3641,-117.681,-244.286,306.743,432.23,-15.7173,-141.806,-316.598,-106.143,138.435,-22.1858,94.4657,77.6981,-32.3186,-17.9067,1.67488,180.767,-30.3753,-346.874,-66.853,280.487,104.613,-220.615,-49.331,185.989,111.068,-16.2566,-147.374,-79.0549,6.47962,-37.9195,55.036,129.596,93.4283,-73.2533,-268.423,-51.8748,343.865,165.473,-273.824,-154.921,119.768,61.3019,-91.4918,-78.7142,187.877,159.298,-227.344,-192.879,227.01,285.885,-168.906,-324.455,-69.5254,63.0646,247.154,237.729,-135.335,-264.001,66.651,226.281,-214.296,-237.582,249.87,142.344,-158.647,-89.1673,134.23,132.876,27.7403,78.3628,-294.066,-429.878,204.037,417.342,100.192,-199.44,-93.4447,163.589,-98.9199,-138.002,211.688,107.723,-385.284,-379.001,418.19,614.091,26.7781,-309.321,-426.985,-77.371,201.788,-28.2436,140.651,224.375,-17.0141,-52.807,-169.946,-119.069,5.01486,-37.3025,112.979,138.281,132.892,113.106,-311.771,-323.684,72.4452,139.354,217.411,130.483,-200.411,-144.059,121.397,83.0865,-191.541,-116.035,194.115,107.171,-64.2338,-88.2139,-52.3065,138.244,276.615,3.63187,-608.332,-371.399,612.545,500.6,-248.277,-291.681,22.458,122.27,3.12732,-0.973726,-119.711,-260.421,124.983,411.669,201.121,-245.406,-438.693,48.1288,254.238,-64.6888,50.8051,196.158,-129.457,-264.876,2.2067,150.148,110.594,76.5673,-14.4247,-160.076,-198.906,102.595,248.921,-143.905,-176.391,194.259,228.011,-7.04008,-298.651,-255.429,166.437,318.978,38.2254,-231.853,-146.337,89.861,220.021,91.1781,-249.608,-150.331,142.83,-15.5059,-8.02728,195.121,9.95152,-180.332,-105.744,50.1433,146.923,16.1551,-67.3868,49.9787,-52.4733,-167.019,33.2638,144.766,163.363,90.0536,-282.284,-290.659,94.7904,158.444,213.334,199.699,-272.661,-397.403,75.7847,315.833,73.1655,-138.352,-74.1787,-37.8636,47.234,171.771,14.3399,-146.325,-127.47,62.4803,168.966,-130.521,-187.337,131.671,316.991,184.824,-346.586,-428.153,113.925,258.893,53.482,-41.186,-2.25672,1.38646,26.879,129.024,-83.4756,-269.357,-110.683,139.805,290.698,-41.6795,-150.97,260.733,18.4517,-428.195,-136.186,278.29,241.65,-51.5393,-193.921,-68.5357,58.3203,48.2095,155.662,132.499,-239.97,-258.826,0,132.499,239.97,48.2095,-155.662,-68.5357,-58.3203,-51.5393,193.921,278.29,-241.65,-428.195,136.186,260.733,-18.4517,-41.6795,150.97,139.805,-290.698,-269.357,110.683,129.024,83.4756,1.38646,-26.879,-41.186,2.25672,258.893,-53.482,-428.153,-113.925,184.824,346.586,131.671,-316.991,-130.521,187.337,62.4803,-168.966,-146.325,127.47,171.771,-14.3399,-37.8636,-47.234,-138.352,74.1787,315.833,-73.1655,-397.403,-75.7847,199.699,272.661,158.444,-213.334,-290.659,-94.7904,90.0536,282.284,144.766,-163.363,-167.019,-33.2638,49.9787,52.4733,16.1551,67.3868,50.1433,-146.923,-180.332,105.744,195.121,-9.95152,-15.5059,8.02728,-150.331,-142.83,91.1781,249.608,89.861,-220.021,-231.853,146.337,318.978,-38.2254,-255.429,-166.437,-7.04008,298.651,194.259,-228.011,-143.905,176.391,102.595,-248.921,-160.076,198.906,76.5673,14.4247,150.148,-110.594,-264.876,-2.2067,196.158,129.457,-64.6888,-50.8051,48.1288,-254.238,-245.406,438.693,411.669,-201.121,-260.421,-124.983,-0.973726,119.711,122.27,-3.12732,-291.681,-22.458,500.6,248.277,-371.399,-612.545,3.63187,608.332,138.244,-276.615,-88.2139,52.3065,107.171,64.2338,-116.035,-194.115,83.0865,191.541,-144.059,-121.397,130.483,200.411,139.354,-217.411,-323.684,-72.4452,113.106,311.771,138.281,-132.892,-37.3025,-112.979,-119.069,-5.01486,-52.807,169.946,224.375,17.0141,-28.2436,-140.651,-77.371,-201.788,-309.321,426.985,614.091,-26.7781,-379.001,-418.19,107.723,385.284,-138.002,-211.688,163.589,98.9199,-199.44,93.4447,417.342,-100.192,-429.878,-204.037,78.3628,294.066,132.876,-27.7403,-89.1673,-134.23,142.344,158.647,-237.582,-249.87,226.281,214.296,-264.001,-66.651,237.729,135.335,63.0646,-247.154,-324.455,69.5254,285.885,168.906,-192.879,-227.01,159.298,227.344,-78.7142,-187.877,61.3019,91.4918,-154.921,-119.768,165.473,273.824,-51.8748,-343.865,-73.2533,268.423,129.596,-93.4283,-37.9195,-55.036,-79.0549,-6.47962,-16.2566,147.374,185.989,-111.068,-220.615,49.331,280.487,-104.613,-346.874,66.853,180.767,30.3753,-17.9067,-1.67488,77.6981,32.3186,-22.1858,-94.4657,-106.143,-138.435,-141.806,316.598,432.23,15.7173,-244.286,-306.743,-18.3641,117.681,20.414,22.5332,-98.4317,66.3989"); VectorFloat exp_mag_spec(L"213.54,118.733,30.4052,119.105,392.132,432.516,346.905,174.444,97.036,84.1516,17.9848,183.302,353.257,299.361,226.063,216.629,148.268,79.32,66.8345,159.763,278.239,347.756,319.939,195.818,110.13,203.7,277.599,297.885,332.054,331.821,255.073,273.551,272.285,311.65,344.791,213.144,161.147,135.741,304.328,475.843,429.2,220.246,191.172,252.698,400.06,564.38,614.675,527.253,216.113,143.459,225.019,177.961,119.175,118.978,191.786,331.653,331.692,258.239,239.145,188.388,208.786,226.152,124.947,102.556,309.237,608.343,716.344,558.786,292.544,122.31,119.715,288.859,458.172,502.668,258.753,82.2544,235.025,264.885,186.482,77.9142,255.319,269.235,227.645,299.542,298.734,304.869,321.261,274.172,237.664,265.74,207.364,17.4606,195.375,209.049,155.244,69.2962,72.466,170.299,218.277,296.301,305.725,265.737,337.969,404.565,324.197,156.984,60.5368,172.369,194.061,180.148,228.322,343.25,392.787,443.05,264.36,41.2478,26.9148,153.673,291.211,322.57,156.618,261.385,449.33,368.565,200.653,89.9911,162.957,274.119"); VectorFloat exp_db_spec(L"46.5896,41.4914,29.6590,41.5186,51.8686,52.7200,50.8042,44.8331,39.7387,38.5013,25.0982,45.2633,50.9618,49.5239,47.0846,46.7143,43.4209,37.9876,36.5000,44.0695,48.8884,50.8255,50.1013,45.8371,40.8381,46.1798,48.8684,49.4810,50.4242,50.4181,48.1333,48.7408,48.7005,49.8734,50.7511,46.5735,44.1444,42.6542,49.6668,53.5493,52.6532,46.8582,45.6285,48.0521,52.0425,55.0314,55.7729,54.4404,46.6936,43.1346,47.0444,45.0065,41.5237,41.5093,45.6563,50.4137,50.4147,48.2404,47.5732,45.5011,46.3940,47.0880,41.9345,40.2192,49.8058,55.6830,57.1024,54.9449,49.3238,41.7493,41.5630,49.2137,53.2206,54.0256,48.2577,38.3032,47.4223,48.4612,45.4127,37.8323,48.1417,48.6026,47.1452,49.5291,49.5057,49.6823,50.1371,48.7605,47.5193,48.4891,46.3347,24.8412,45.8174,46.4050,43.8203,36.8143,37.2026,44.6242,46.7801,49.4347,49.7066,48.4890,50.5775,52.1398,50.2162,43.9171,35.6404,44.7292,45.7588,45.1126,47.1710,50.7122,51.8831,52.9291,48.4439,32.3080,28.5998,43.7319,49.2841,50.1725,43.8968,48.3456,53.0513,51.3303,46.0489,39.0840,44.2414,48.7588,48.2602,48.7588,44.2414,39.0840,46.0489,51.3303,53.0513,48.3456,43.8968,50.1725,49.2841,43.7319,28.5998,32.3080,48.4439,52.9291,51.8831,50.7122,47.1710,45.1126,45.7588,44.7292,35.6404,43.9171,50.2162,52.1398,50.5775,48.4890,49.7066,49.4347,46.7801,44.6242,37.2026,36.8143,43.8203,46.4050,45.8174,24.8412,46.3347,48.4891,47.5193,48.7605,50.1371,49.6823,49.5057,49.5291,47.1452,48.6026,48.1417,37.8323,45.4127,48.4612,47.4223,38.3032,48.2577,54.0256,53.2206,49.2137,41.5630,41.7493,49.3238,54.9449,57.1024,55.6830,49.8058,40.2192,41.9345,47.0880,46.3940,45.5011,47.5732,48.2404,50.4147,50.4137,45.6563,41.5093,41.5237,45.0065,47.0444,43.1346,46.6936,54.4404,55.7729,55.0314,52.0425,48.0521,45.6285,46.8582,52.6532,53.5493,49.6668,42.6542,44.1444,46.5735,50.7511,49.8734,48.7005,48.7408,48.1333,50.4181,50.4242,49.4810,48.8684,46.1798,40.8381,45.8371,50.1013,50.8255,48.8884,44.0695,36.5000,37.9876,43.4209,46.7143,47.0846,49.5239,50.9618,45.2633,25.0982,38.5013,39.7387,44.8331,50.8042,52.7200,51.8686,41.5186,29.6590,41.4914"); // declare test local variables // VectorComplexFloat output_complex; // local variables // VectorFloat mid(512); VectorFloat test_mid(512); VectorFloat test_signal(signal); VectorFloat output_real; // case: algorithm = FOURIER, implementation = COMPLEX, // input = non-zero SINGAL vector // spec0.set(FOURIER, COMPLEX); spec0.setDynRange((long)-100); spec0.setFtAlgorithm(FourierTransform::FFT); spec0.setFtImplementation(FourierTransform::SPLIT_RADIX); spec0.setFtOrder((long)256); spec0.compute(output_complex, signal); // covert the output complex vector to real vector // for (long i = 0, j = 0; i < 256; i++) { mid(j++) = output_complex(i).real(); mid(j++) = output_complex(i).imag(); } if (!mid.almostEqual(exp_full_spec)) { output_complex.debug(L"full_spec"); exp_full_spec.debug(L"exp_full_spec"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } // case: algorithm = FOURIER, implementation = COMPLEX, // input = zero SINGAL vector // test_mid.assign(0.0); test_signal.assign(0.0); spec0.set(FOURIER, COMPLEX); spec0.setDynRange((long)-100); spec0.setFtAlgorithm(FourierTransform::FFT); spec0.setFtImplementation(FourierTransform::SPLIT_RADIX); spec0.setFtOrder((long)256); spec0.compute(output_complex, test_signal); for (long i = 0, j = 0; i < 256; i++) { mid(j++) = output_complex(i).real(); mid(j++) = output_complex(i).imag(); } if (!mid.almostEqual(test_mid)) { output_complex.debug(L"full_spec"); test_mid.debug(L"exp_full_spec"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } // case: algorithm = FOURIER, implementation = MAGNITUDE, // input = non-zero SINGAL vector // spec0.set(FOURIER, MAGNITUDE); spec0.setDynRange((long)-100); spec0.setFtAlgorithm(FourierTransform::FFT); spec0.setFtImplementation(FourierTransform::SPLIT_RADIX); spec0.setFtOrder((long)256); spec0.compute(output_real, signal); output_real.setLength(output_real.length() / 2, false); if (!output_real.almostEqual(exp_mag_spec)) { output_real.debug(L"mag_spec"); exp_mag_spec.debug(L"exp_mag_spec"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } // case: algorithm = FOURIER, implementation = MAGNITUDE, // input = zero SINGAL vector // spec0.set(FOURIER, MAGNITUDE); spec0.setDynRange((long)-100); spec0.setFtAlgorithm(FourierTransform::FFT); spec0.setFtImplementation(FourierTransform::SPLIT_RADIX); spec0.setFtOrder((long)256); spec0.compute(output_real, test_signal); output_real.setLength(output_real.length() / 2, false); exp_mag_spec.assign(0.0); if (!output_real.almostEqual(exp_mag_spec)) { output_real.debug(L"mag_spec"); exp_mag_spec.debug(L"exp_mag_spec"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } // compute the spectrum via maximum entropy methods // VectorFloat spec_result(L"0.06876, 0.08023, 0.10769, 0.14247, 0.18078, 0.22123, 0.26326, 0.30663, 0.35122, 0.39693, 0.44368, 0.49136, 0.53986, 0.58903, 0.63873, 0.68877, 0.73896, 0.78910, 0.83899, 0.88842, 0.93718, 0.98509, 1.03195, 1.07759, 1.12187, 1.16464, 1.20581, 1.24529, 1.28302, 1.31898, 1.35317, 1.38563, 1.41642, 1.44561, 1.47331, 1.49966, 1.52480, 1.54889, 1.57208, 1.59454, 1.61643, 1.63790, 1.65908, 1.68009, 1.70100, 1.72189, 1.74277, 1.76365, 1.78448, 1.80520, 1.82570, 1.84587, 1.86556, 1.88459, 1.90280, 1.92000, 1.93601, 1.95063, 1.96371, 1.97507, 1.98457, 1.99210, 1.99755, 2.00085, 2.00195, 2.00085, 1.99755, 1.99210, 1.98457, 1.97507, 1.96371, 1.95063, 1.93601, 1.92000, 1.90280, 1.88459, 1.86556, 1.84587, 1.82570, 1.80520, 1.78448, 1.76365, 1.74277, 1.72189, 1.70100, 1.68009, 1.65908, 1.63790, 1.61643, 1.59454, 1.57208, 1.54889, 1.52480, 1.49966, 1.47331, 1.44561, 1.41642, 1.38563, 1.35317, 1.31898, 1.28302, 1.24529, 1.20581, 1.16464, 1.12187, 1.07759, 1.03195, 0.98509, 0.93718, 0.88842, 0.83899, 0.78910, 0.73896, 0.68877, 0.63873, 0.58903, 0.53986, 0.49136, 0.44368, 0.39693, 0.35122, 0.30663, 0.26326, 0.22123, 0.18078, 0.14247, 0.10769, 0.08023"); VectorFloat auto_coef(L"0.657422, 0.616563, 0.57561, 0.534578, 0.493479"); VectorFloat refl_coef(L"-0.9378492, 0.03325092, 0.03422026, 0.03525937"); VectorFloat pred_coef(L"1.0000000, -0.9666889, 0.00009363125, 0.00009251215, 0.03525940"); VectorFloat spec_zeros(spec_result); spec_zeros.assign(0.0); VectorFloat test_auto(L"0, 0, 0, 0, 0"); VectorFloat test_refl(L"0, 0, 0, 0"); VectorFloat test_pred(L"0, 0, 0, 0, 0"); double diff_power; double result_power; Double snr; VectorFloat diff_vector; // case: algorithm = MAXIMUM, implementation = MAGNITUDE, // input = non-zero PREDICTION vector // spec0.set(MAXIMUM_ENTROPY, MAGNITUDE); spec0.setDynRange((long)-100); spec0.setFtAlgorithm(FourierTransform::FFT); spec0.setFtImplementation(FourierTransform::SPLIT_RADIX); spec0.setFtOrder((long)128); spec0.compute(output_real, pred_coef, AlgorithmData::PREDICTION); // determine if the output is correct by computing the SNR // diff_vector.sub(output_real, spec_result); diff_power = diff_vector.sumSquare(); result_power = spec_result.sumSquare(); snr = result_power / diff_power; snr.log10(); snr *= Integral::DB_POW_SCALE_FACTOR; // error when the SNR is less than 80dB // if (snr < (double)80) { return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__); } // case: algorithm = MAXIMUM, implementation = MAGNITUDE, // input = zero PREDICTION vector // spec0.set(MAXIMUM_ENTROPY, MAGNITUDE); spec0.setDynRange((long)-100); spec0.setFtAlgorithm(FourierTransform::FFT); spec0.setFtImplementation(FourierTransform::SPLIT_RADIX); spec0.setFtOrder((long)128); spec0.compute(output_real, test_pred, AlgorithmData::PREDICTION); if (!output_real.almostEqual(spec_zeros)) { output_real.debug(L"mag_spec"); spec_zeros.debug(L"spec_zeros"); return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__); } // case: algorithm = MAXIMUM, implementation = MAGNITUDE, // input = zero REFLECTION vector // spec0.set(MAXIMUM_ENTROPY, MAGNITUDE); spec0.setDynRange((long)-200); spec0.setFtAlgorithm(FourierTransform::FFT); spec0.setFtImplementation(FourierTransform::SPLIT_RADIX); spec0.setFtOrder((long)128); spec0.compute(output_real, refl_coef, AlgorithmData::REFLECTION); // determine if the output is correct by computing the SNR // diff_vector.sub(output_real, spec_result); diff_power = diff_vector.sumSquare(); result_power = spec_result.sumSquare(); snr = result_power / diff_power; snr.log10(); snr *= Integral::DB_POW_SCALE_FACTOR; // error when the SNR is less than 80dB // if (snr < (double)80) { return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__); } // case: algorithm = MAXIMUM, implementation = MAGNITUDE, // input = zero CORRELATION vector // spec0.set(MAXIMUM_ENTROPY, MAGNITUDE); spec0.setDynRange((long)-200); spec0.setFtAlgorithm(FourierTransform::FFT); spec0.setFtImplementation(FourierTransform::SPLIT_RADIX); spec0.setFtOrder((long)128); spec0.compute(output_real, auto_coef, AlgorithmData::CORRELATION); // determine if the output is correct by computing the SNR // diff_vector.sub(output_real, spec_result); diff_power = diff_vector.sumSquare(); result_power = spec_result.sumSquare(); snr = result_power / diff_power; snr.log10(); snr *= Integral::DB_POW_SCALE_FACTOR; // error when the SNR is less than 80dB // if (snr < (double)80) { return Error::handle(name(), L"diagnose", 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) { String 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 + -