| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053 |
- /* ----------------------------------------------------------------------
- * Project: CMSIS DSP Library
- * Title: Error.cpp
- * Description: Error functions
- *
- * $Date: 20. June 2019
- * $Revision: V1.0.0
- *
- * Target Processor: Cortex-M cores
- * -------------------------------------------------------------------- */
- /*
- * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved.
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the License); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #include <cstdlib>
- #include <cstdio>
- #include "arm_math_types.h"
- #include "arm_math_types_f16.h"
- #include "Error.h"
- namespace Client {
- template <typename T>
- void assert_not_empty_generic(unsigned long nb, AnyPattern<T> &p)
- {
- if (p.nbSamples() == 0)
- {
- throw (Error(EMPTY_PATTERN_ERROR,nb));
- }
- if (p.ptr() == NULL)
- {
- throw (Error(EMPTY_PATTERN_ERROR,nb));
- }
- };
- template <>
- void assert_near_equal(unsigned long nb,double pa, double pb, double threshold)
- {
- if (fabs(pa - pb) > threshold)
- {
- char details[200];
- sprintf(details,"diff %g > %g (%g,%g)",fabs(pa - pb) , threshold,pa,pb);
- throw (Error(EQUAL_ERROR,nb,details));
- }
- };
- template <>
- void assert_near_equal(unsigned long nb,float32_t pa, float32_t pb, float32_t threshold)
- {
- if (fabs(pa - pb) > threshold)
- {
- char details[200];
- sprintf(details,"diff %g > %g (%g,%g)",fabs(pa - pb) , threshold, pa, pb);
- throw (Error(EQUAL_ERROR,nb,details));
- }
- };
- #if !defined (__CC_ARM) && defined(ARM_FLOAT16_SUPPORTED)
- template <>
- void assert_near_equal(unsigned long nb,float16_t pa, float16_t pb, float16_t threshold)
- {
- if (fabs(pa - pb) > threshold)
- {
- char details[200];
- sprintf(details,"diff %g > %g (%g,%g)",fabs(pa - pb) , threshold, pa, pb);
- throw (Error(EQUAL_ERROR,nb,details));
- }
- };
- #endif
- template <>
- void assert_near_equal(unsigned long nb,q63_t pa, q63_t pb, q63_t threshold)
- {
- if (abs(pa - pb) > threshold)
- {
- char details[200];
- sprintf(details,"diff %lld > %lld (0x%016llX,0x%016llX)",abs(pa - pb) , threshold,pa,pb);
- throw (Error(EQUAL_ERROR,nb,details));
- }
- };
- template <>
- void assert_near_equal(unsigned long nb,q31_t pa, q31_t pb, q31_t threshold)
- {
- if (abs(pa - pb) > threshold)
- {
- char details[200];
- sprintf(details,"diff %d > %d (0x%08X,0x%08X)",abs(pa - pb) , threshold,pa,pb);
- throw (Error(EQUAL_ERROR,nb,details));
- }
- };
- template <>
- void assert_near_equal(unsigned long nb,q15_t pa, q15_t pb, q15_t threshold)
- {
- if (abs(pa - pb) > threshold)
- {
- char details[200];
- sprintf(details,"diff %d > %d (0x%04X,0x%04X)",abs(pa - pb) , threshold,pa,pb);
- throw (Error(EQUAL_ERROR,nb,details));
- }
- };
- template <>
- void assert_near_equal(unsigned long nb,q7_t pa, q7_t pb, q7_t threshold)
- {
- if (abs(pa - pb) > threshold)
- {
- char details[200];
- sprintf(details,"diff %d > %d (0x%02X,0x%02X)",abs(pa - pb) , threshold,pa,pb);
- throw (Error(EQUAL_ERROR,nb,details));
- }
- };
- void assert_not_empty(unsigned long nb, AnyPattern<float64_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- void assert_not_empty(unsigned long nb, AnyPattern<float32_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- #if !defined( __CC_ARM ) && defined(ARM_FLOAT16_SUPPORTED)
- void assert_not_empty(unsigned long nb, AnyPattern<float16_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- #endif
- void assert_not_empty(unsigned long nb, AnyPattern<q63_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- void assert_not_empty(unsigned long nb, AnyPattern<q31_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- void assert_not_empty(unsigned long nb, AnyPattern<q15_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- void assert_not_empty(unsigned long nb, AnyPattern<q7_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- void assert_not_empty(unsigned long nb, AnyPattern<uint32_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- void assert_not_empty(unsigned long nb, AnyPattern<uint16_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- void assert_not_empty(unsigned long nb, AnyPattern<uint8_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- void assert_relative_error(unsigned long nb,float64_t &a, float64_t &b, double threshold)
- {
- float64_t rel,delta,average;
- delta=abs(a-b);
- average = (abs(a) + abs(b)) / 2.0f;
- if (average !=0)
- {
- rel = delta / average;
- //printf("%6.9f %6.9f %6.9f %g %g\n",a,b,rel,delta,average);
- if (rel > threshold)
- {
- //printf("rel = %g, threshold %g \n",rel,threshold);
- char details[200];
- sprintf(details,"diff (%g,%g), %g > %g",a,b,rel , threshold);
- throw (Error(RELATIVE_ERROR,nb,details));
- }
- }
- };
- void assert_relative_error(unsigned long nb,float32_t &a, float32_t &b, double threshold)
- {
- double rel,delta,average;
- delta=abs(a-b);
- average = (abs((float)a) + abs((float)b)) / 2.0f;
- if (average !=0)
- {
- rel = delta / average;
- //printf("%6.9f %6.9f %6.9f %g %g\n",a,b,rel,delta,average);
- if (rel > threshold)
- {
- //printf("rel = %g, threshold %g \n",rel,threshold);
- char details[200];
- sprintf(details,"diff (%g,%g), %g > %g",a,b,rel , threshold);
- throw (Error(RELATIVE_ERROR,nb,details));
- }
- }
- };
- #if !defined( __CC_ARM ) && defined(ARM_FLOAT16_SUPPORTED)
- void assert_relative_error(unsigned long nb,float16_t &a, float16_t &b, double threshold)
- {
- double rel,delta,average;
- delta=abs(a-b);
- average = (abs(a) + abs(b)) / 2.0f;
- if (average !=0)
- {
- rel = delta / average;
- //printf("%6.9f %6.9f %6.9f %g %g\n",a,b,rel,delta,average);
- if (rel > threshold)
- {
- //printf("rel = %g, threshold %g \n",rel,threshold);
- char details[200];
- sprintf(details,"diff (%g,%g), %g > %g",a,b,rel , threshold);
- throw (Error(RELATIVE_ERROR,nb,details));
- }
- }
- };
- #endif
- void assert_relative_error(unsigned long nb,AnyPattern<float64_t> &pa, AnyPattern<float64_t> &pb, double threshold)
- {
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- unsigned long i=0;
- float64_t *ptrA = pa.ptr();
- float64_t *ptrB = pb.ptr();
- char id[40];
- for(i=0; i < pa.nbSamples(); i++)
- {
- try
- {
- assert_relative_error(nb,ptrA[i],ptrB[i],threshold);
- }
- catch(Error &err)
- {
- sprintf(id," (nb=%lu)",i+1);
- strcat(err.details,id);
- throw(err);
- }
- }
- };
- void assert_relative_error(unsigned long nb,AnyPattern<float32_t> &pa, AnyPattern<float32_t> &pb, double threshold)
- {
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- unsigned long i=0;
- float32_t *ptrA = pa.ptr();
- float32_t *ptrB = pb.ptr();
- char id[40];
- for(i=0; i < pa.nbSamples(); i++)
- {
- try
- {
- assert_relative_error(nb,ptrA[i],ptrB[i],threshold);
- }
- catch(Error &err)
- {
- sprintf(id," (nb=%lu)",i+1);
- strcat(err.details,id);
- throw(err);
- }
- }
- };
- #if !defined( __CC_ARM ) && defined(ARM_FLOAT16_SUPPORTED)
- void assert_relative_error(unsigned long nb,AnyPattern<float16_t> &pa, AnyPattern<float16_t> &pb, double threshold)
- {
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- unsigned long i=0;
- float16_t *ptrA = pa.ptr();
- float16_t *ptrB = pb.ptr();
- char id[40];
- for(i=0; i < pa.nbSamples(); i++)
- {
- try
- {
- assert_relative_error(nb,ptrA[i],ptrB[i],threshold);
- }
- catch(Error &err)
- {
- sprintf(id," (nb=%lu)",i+1);
- strcat(err.details,id);
- throw(err);
- }
- }
- };
- #endif
- void assert_close_error(unsigned long nb,float64_t &ref, float64_t &val, double absthreshold,double relthreshold)
- {
-
- if (abs(val - ref) > (absthreshold + relthreshold * abs(ref)))
- {
- char details[200];
- sprintf(details,"close error %g > %g: (val = %g, ref = %g)",abs(val - ref) , absthreshold + relthreshold * abs(ref),val,ref);
- throw (Error(CLOSE_ERROR,nb,details));
- }
- };
- void assert_close_error(unsigned long nb,AnyPattern<float64_t> &pref, AnyPattern<float64_t> &pval, double absthreshold,double relthreshold)
- {
- ASSERT_NOT_EMPTY(pref);
- ASSERT_NOT_EMPTY(pval);
- if (pref.nbSamples() != pval.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- unsigned long i=0;
- char id[40];
- float64_t *ptrA = pref.ptr();
- float64_t *ptrB = pval.ptr();
- for(i=0; i < pref.nbSamples(); i++)
- {
- try
- {
- assert_close_error(nb,ptrA[i],ptrB[i],absthreshold,relthreshold);
- }
- catch(Error &err)
- {
- sprintf(id," (nb=%lu)",i+1);
- strcat(err.details,id);
- throw(err);
- }
-
- }
- };
- void assert_close_error(unsigned long nb,float32_t &ref, float32_t &val, double absthreshold,double relthreshold)
- {
-
- if (abs(val - ref) > (absthreshold + relthreshold * abs(ref)))
- {
- char details[200];
- sprintf(details,"close error %g > %g: (val = %g, ref = %g)",abs(val - ref) , absthreshold + relthreshold * abs(ref),val,ref);
- throw (Error(CLOSE_ERROR,nb,details));
- }
- };
- void assert_close_error(unsigned long nb,AnyPattern<float32_t> &pref, AnyPattern<float32_t> &pval, double absthreshold,double relthreshold)
- {
- ASSERT_NOT_EMPTY(pref);
- ASSERT_NOT_EMPTY(pval);
- if (pref.nbSamples() != pval.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- unsigned long i=0;
- char id[40];
- float32_t *ptrA = pref.ptr();
- float32_t *ptrB = pval.ptr();
- for(i=0; i < pref.nbSamples(); i++)
- {
- try
- {
- assert_close_error(nb,ptrA[i],ptrB[i],absthreshold,relthreshold);
- }
- catch(Error &err)
- {
- sprintf(id," (nb=%lu)",i+1);
- strcat(err.details,id);
- throw(err);
- }
-
- }
- };
- #if !defined( __CC_ARM ) && defined(ARM_FLOAT16_SUPPORTED)
- void assert_close_error(unsigned long nb,float16_t &ref, float16_t &val, double absthreshold,double relthreshold)
- {
-
- if (abs((float)val - (float)ref) > (absthreshold + relthreshold * abs((float)ref)))
- {
- char details[200];
- sprintf(details,"close error %g > %g: (val = %g, ref = %g)",abs(val - ref) , absthreshold + relthreshold * abs(ref),val,ref);
- throw (Error(CLOSE_ERROR,nb,details));
- }
- };
- void assert_close_error(unsigned long nb,AnyPattern<float16_t> &pref, AnyPattern<float16_t> &pval, double absthreshold,double relthreshold)
- {
- ASSERT_NOT_EMPTY(pref);
- ASSERT_NOT_EMPTY(pval);
- if (pref.nbSamples() != pval.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- unsigned long i=0;
- char id[40];
- float16_t *ptrA = pref.ptr();
- float16_t *ptrB = pval.ptr();
- for(i=0; i < pref.nbSamples(); i++)
- {
- try
- {
- assert_close_error(nb,ptrA[i],ptrB[i],absthreshold,relthreshold);
- }
- catch(Error &err)
- {
- sprintf(id," (nb=%lu)",i+1);
- strcat(err.details,id);
- throw(err);
- }
-
- }
- };
- #endif
- /**
- * @brief Calculation of SNR
- * @param float* Pointer to the reference buffer
- * @param float* Pointer to the test buffer
- * @param uint32_t total number of samples
- * @return float SNR
- * The function calculates signal to noise ratio for the reference output
- * and test output
- */
- /* If NaN, force SNR to 0.0 to ensure test will fail */
- #define IFNANRETURNZERO(val)\
- if (isnan((val))) \
- { \
- return(0.0); \
- }
- #define IFINFINITERETURN(val,def)\
- if (isinf((val))) \
- { \
- if ((val) > 0) \
- { \
- return(def); \
- } \
- else \
- { \
- return(-def); \
- } \
- }
- float arm_snr_f32(float *pRef, float *pTest, uint32_t buffSize)
- {
- float EnergySignal = 0.0, EnergyError = 0.0;
- uint32_t i;
- float SNR;
-
- for (i = 0; i < buffSize; i++)
- {
- /* Checking for a NAN value in pRef array */
- IFNANRETURNZERO(pRef[i]);
-
- /* Checking for a NAN value in pTest array */
- IFNANRETURNZERO(pTest[i]);
- EnergySignal += pRef[i] * pRef[i];
- EnergyError += (pRef[i] - pTest[i]) * (pRef[i] - pTest[i]);
- }
- /* Checking for a NAN value in EnergyError */
- IFNANRETURNZERO(EnergyError);
- SNR = 10 * log10f (EnergySignal / EnergyError);
- /* Checking for a NAN value in SNR */
- IFNANRETURNZERO(SNR);
- IFINFINITERETURN(SNR,100000.0);
-
- return (SNR);
- }
- #if !defined( __CC_ARM ) && defined(ARM_FLOAT16_SUPPORTED)
- float arm_snr_f16(float16_t *pRef, float16_t *pTest, uint32_t buffSize)
- {
- float EnergySignal = 0.0, EnergyError = 0.0;
- uint32_t i;
- float SNR;
-
- for (i = 0; i < buffSize; i++)
- {
- /* Checking for a NAN value in pRef array */
- IFNANRETURNZERO((float)pRef[i]);
-
- /* Checking for a NAN value in pTest array */
- IFNANRETURNZERO((float)pTest[i]);
- EnergySignal += pRef[i] * pRef[i];
- EnergyError += (pRef[i] - pTest[i]) * (pRef[i] - pTest[i]);
- }
- /* Checking for a NAN value in EnergyError */
- IFNANRETURNZERO(EnergyError);
- SNR = 10 * log10f (EnergySignal / EnergyError);
- /* Checking for a NAN value in SNR */
- IFNANRETURNZERO(SNR);
- IFINFINITERETURN(SNR,100000.0);
-
- return (SNR);
- }
- #endif
- float arm_snr_q63(q63_t *pRef, q63_t *pTest, uint32_t buffSize)
- {
- double EnergySignal = 0.0, EnergyError = 0.0;
- uint32_t i;
- float SNR;
-
- double testVal,refVal;
- for (i = 0; i < buffSize; i++)
- {
-
- testVal = ((double)pTest[i]) / 9223372036854775808.0;
- refVal = ((double)pRef[i]) / 9223372036854775808.0;
- EnergySignal += refVal * refVal;
- EnergyError += (refVal - testVal) * (refVal - testVal);
- }
- SNR = 10 * log10 (EnergySignal / EnergyError);
- /* Checking for a NAN value in SNR */
- IFNANRETURNZERO(SNR);
- IFINFINITERETURN(SNR,100000.0);
-
- //printf("SNR = %f\n",SNR);
- return (SNR);
- }
- float arm_snr_q31(q31_t *pRef, q31_t *pTest, uint32_t buffSize)
- {
- float EnergySignal = 0.0, EnergyError = 0.0;
- uint32_t i;
- float SNR;
-
- float32_t testVal,refVal;
- for (i = 0; i < buffSize; i++)
- {
-
- testVal = ((float32_t)pTest[i]) / 2147483648.0f;
- refVal = ((float32_t)pRef[i]) / 2147483648.0f;
- EnergySignal += refVal * refVal;
- EnergyError += (refVal - testVal) * (refVal - testVal);
- }
- SNR = 10 * log10f (EnergySignal / EnergyError);
- /* Checking for a NAN value in SNR */
- IFNANRETURNZERO(SNR);
- IFINFINITERETURN(SNR,100000.0);
-
- //printf("SNR = %f\n",SNR);
- return (SNR);
- }
- float arm_snr_q15(q15_t *pRef, q15_t *pTest, uint32_t buffSize)
- {
- float EnergySignal = 0.0, EnergyError = 0.0;
- uint32_t i;
- float SNR;
- float32_t testVal,refVal;
- for (i = 0; i < buffSize; i++)
- {
-
- testVal = ((float32_t)pTest[i]) / 32768.0f;
- refVal = ((float32_t)pRef[i]) / 32768.0f;
- EnergySignal += refVal * refVal;
- EnergyError += (refVal - testVal) * (refVal - testVal);
- }
- SNR = 10 * log10f (EnergySignal / EnergyError);
- /* Checking for a NAN value in SNR */
- IFNANRETURNZERO(SNR);
- IFINFINITERETURN(SNR,100000.0);
- //printf("SNR = %f\n",SNR);
- return (SNR);
- }
- float arm_snr_q7(q7_t *pRef, q7_t *pTest, uint32_t buffSize)
- {
- float EnergySignal = 0.0, EnergyError = 0.0;
- uint32_t i;
- float SNR;
-
- float32_t testVal,refVal;
- for (i = 0; i < buffSize; i++)
- {
-
- testVal = ((float32_t)pTest[i]) / 128.0f;
- refVal = ((float32_t)pRef[i]) / 128.0f;
- EnergySignal += refVal * refVal;
- EnergyError += (refVal - testVal) * (refVal - testVal);
- }
- SNR = 10 * log10f (EnergySignal / EnergyError);
- IFNANRETURNZERO(SNR);
- IFINFINITERETURN(SNR,100000.0);
- return (SNR);
- }
- double arm_snr_f64(double *pRef, double *pTest, uint32_t buffSize)
- {
- double EnergySignal = 0.0, EnergyError = 0.0;
- uint32_t i;
- double SNR;
-
- for (i = 0; i < buffSize; i++)
- {
- /* Checking for a NAN value in pRef array */
- IFNANRETURNZERO(pRef[i]);
-
- /* Checking for a NAN value in pTest array */
- IFNANRETURNZERO(pTest[i]);
-
- EnergySignal += pRef[i] * pRef[i];
- EnergyError += (pRef[i] - pTest[i]) * (pRef[i] - pTest[i]);
- }
- /* Checking for a NAN value in EnergyError */
- IFNANRETURNZERO(EnergyError);
- SNR = 10 * log10 (EnergySignal / EnergyError);
- /* Checking for a NAN value in SNR */
- IFNANRETURNZERO(SNR);
- IFINFINITERETURN(SNR,100000.0);
- return (SNR);
- }
- void assert_snr_error(unsigned long nb,AnyPattern<float32_t> &pa,AnyPattern<float32_t> &pb, float32_t threshold)
- {
- float32_t snr;
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- float32_t *ptrA = pa.ptr();
- float32_t *ptrB = pb.ptr();
- snr = arm_snr_f32(ptrA, ptrB, pa.nbSamples());
- //printf("SNR = %f\n",snr);
-
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_snr_error(unsigned long nb,float32_t a,float32_t b, float32_t threshold)
- {
- float32_t snr;
- snr = arm_snr_f32(&a, &b, 1);
- //printf("SNR = %f\n",snr);
-
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- #if !defined( __CC_ARM ) && defined(ARM_FLOAT16_SUPPORTED)
- void assert_snr_error(unsigned long nb,AnyPattern<float16_t> &pa,AnyPattern<float16_t> &pb, float32_t threshold)
- {
- float32_t snr;
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- float16_t *ptrA = pa.ptr();
- float16_t *ptrB = pb.ptr();
- snr = arm_snr_f16(ptrA, ptrB, pa.nbSamples());
- //printf("SNR = %f\n",snr);
-
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- #endif
- #if !defined (__CC_ARM) && defined(ARM_FLOAT16_SUPPORTED)
- void assert_snr_error(unsigned long nb,float16_t a,float16_t b, float32_t threshold)
- {
- float32_t snr;
- snr = arm_snr_f16(&a, &b, 1);
- //printf("SNR = %f\n",snr);
-
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- #endif
- void assert_snr_error(unsigned long nb,AnyPattern<float64_t> &pa,AnyPattern<float64_t> &pb, float64_t threshold)
- {
- float64_t snr;
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- float64_t *ptrA = pa.ptr();
- float64_t *ptrB = pb.ptr();
- snr = arm_snr_f64(ptrA, ptrB, pa.nbSamples());
- //printf("SNR = %f\n",snr);
-
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_snr_error(unsigned long nb,float64_t a,float64_t b, float64_t threshold)
- {
- float64_t snr;
- snr = arm_snr_f64(&a, &b, 1);
- //printf("SNR = %f\n",snr);
-
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_snr_error(unsigned long nb,AnyPattern<q63_t> &pa,AnyPattern<q63_t> &pb, float32_t threshold)
- {
- float32_t snr;
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- q63_t *ptrA = pa.ptr();
- q63_t *ptrB = pb.ptr();
- snr = arm_snr_q63(ptrA, ptrB, pa.nbSamples());
- //printf("SNR = %f\n",snr);
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_snr_error(unsigned long nb,q63_t a,q63_t b, float32_t threshold)
- {
- float32_t snr;
- snr = arm_snr_q63(&a, &b, 1);
- //printf("SNR = %f\n",snr);
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_snr_error(unsigned long nb,AnyPattern<q31_t> &pa,AnyPattern<q31_t> &pb, float32_t threshold)
- {
- float32_t snr;
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- q31_t *ptrA = pa.ptr();
- q31_t *ptrB = pb.ptr();
- snr = arm_snr_q31(ptrA, ptrB, pa.nbSamples());
- //printf("SNR = %f\n",snr);
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_snr_error(unsigned long nb,q31_t a,q31_t b, float32_t threshold)
- {
- float32_t snr;
- snr = arm_snr_q31(&a, &b, 1);
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_snr_error(unsigned long nb,AnyPattern<q15_t> &pa,AnyPattern<q15_t> &pb, float32_t threshold)
- {
- float32_t snr;
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- q15_t *ptrA = pa.ptr();
- q15_t *ptrB = pb.ptr();
- snr = arm_snr_q15(ptrA, ptrB, pa.nbSamples());
- //printf("SNR = %f\n",snr);
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_snr_error(unsigned long nb,q15_t a,q15_t b, float32_t threshold)
- {
- float32_t snr;
- snr = arm_snr_q15(&a, &b, 1);
- //printf("SNR = %f\n",snr);
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_snr_error(unsigned long nb,AnyPattern<q7_t> &pa,AnyPattern<q7_t> &pb, float32_t threshold)
- {
- float32_t snr;
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- q7_t *ptrA = pa.ptr();
- q7_t *ptrB = pb.ptr();
- snr = arm_snr_q7(ptrA, ptrB, pa.nbSamples());
- //printf("SNR = %f\n",snr);
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_snr_error(unsigned long nb,q7_t a,q7_t b, float32_t threshold)
- {
- float32_t snr;
- snr = arm_snr_q7(&a, &b, 1);
- //printf("SNR = %f\n",snr);
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_true(unsigned long nb,bool cond)
- {
- if (!cond)
- {
- throw (Error(BOOL_ERROR,nb));
- }
- }
- void assert_false(unsigned long nb,bool cond)
- {
- if (cond)
- {
- throw (Error(BOOL_ERROR,nb));
- }
- }
- }
|