| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- #include "FIRF32.h"
- #include <stdio.h>
- #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<<FIRCOEFPADDING;
- memset(coeffArray,0,round*sizeof(float32_t));
- //printf("blockSize=%d, numTaps=%d, round=%d (%d)\n",blockSize,numTaps,round,round - numTaps);
- for(j=0;j < numTaps; j++)
- {
- coeffArray[j] = orgcoefsp[j];
- }
-
- coefsp = coeffArray;
- #else
- coefsp = orgcoefsp;
- #endif
- /*
- The filter is initialized with the coefs, blockSize and numTaps.
- */
- arm_fir_init_f32(&this->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<Testing::param_t>& 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);
- }
|