#include "FIRF32.h" #include #include "Error.h" #define SNR_THRESHOLD 120 /* Reference patterns are generated with a double precision computation. */ #define REL_ERROR (3.0e-5) #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) static __ALIGNED(8) float32_t coeffArray[32]; #endif static void checkInnerTail(float32_t *b) { ASSERT_TRUE(b[0] == 0.0f); ASSERT_TRUE(b[1] == 0.0f); ASSERT_TRUE(b[2] == 0.0f); ASSERT_TRUE(b[3] == 0.0f); } // Coef must be padded to a multiple of 4 #define FIRCOEFPADDING 2 void FIRF32::test_fir_f32() { const int16_t *configp = configs.ptr(); float32_t *statep = state.ptr(); const float32_t *orgcoefsp = coefs.ptr(); const float32_t *coefsp; const float32_t *inputp = inputs.ptr(); float32_t *outp = output.ptr(); unsigned long i; #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) int j; #endif int blockSize; int numTaps; #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) int round; #endif /* Python script is generating different tests with different blockSize and numTaps. We loop on those configs. */ for(i=0; i < configs.nbSamples() ; i += 2) { blockSize = configp[0]; numTaps = configp[1]; #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) /* Copy coefficients and pad to zero */ memset(coeffArray,127,32*sizeof(float32_t)); round = numTaps >> FIRCOEFPADDING; if ((round << FIRCOEFPADDING) < numTaps) { round ++; } round = round<S,numTaps,coefsp,statep,blockSize); /* Input pointer is reset since the same input pattern is used */ inputp = inputs.ptr(); /* Python script is filtering a 2*blockSize number of samples. We do the same filtering in two pass to check (indirectly that the state management of the fir is working.) */ arm_fir_f32(&this->S,inputp,outp,blockSize); outp += blockSize; checkInnerTail(outp); inputp += blockSize; arm_fir_f32(&this->S,inputp,outp,blockSize); outp += blockSize; checkInnerTail(outp); configp += 2; orgcoefsp += numTaps; } ASSERT_EMPTY_TAIL(output); ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD); ASSERT_REL_ERROR(output,ref,REL_ERROR); } void FIRF32::setUp(Testing::testID_t id,std::vector& params,Client::PatternMgr *mgr) { (void)params; switch(id) { case FIRF32::TEST_FIR_F32_1: break; } inputs.reload(FIRF32::FIRINPUTS_F32_ID,mgr); coefs.reload(FIRF32::FIRCOEFS_F32_ID,mgr); configs.reload(FIRF32::FIRCONFIGS_S16_ID,mgr); ref.reload(FIRF32::FIRREFS_F32_ID,mgr); output.create(ref.nbSamples(),FIRF32::OUT_F32_ID,mgr); /* Max 2*blockSize + numTaps - 1 as generated by Python script A temp buffer blockSize is used by Helium implementation. It is at beginning of state buffer and is NOT the state of the FIR which is in the following part. */ state.create(47+47,FIRF32::OUT_F32_ID,mgr); } void FIRF32::tearDown(Testing::testID_t id,Client::PatternMgr *mgr) { (void)id; output.dump(mgr); }