FIRQ7.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include "FIRQ7.h"
  2. #include "Error.h"
  3. #define SNR_THRESHOLD 10
  4. #define ABS_ERROR_Q7 ((q7_t)2)
  5. #if defined(ARM_MATH_MVEI)
  6. static __ALIGNED(8) q7_t coeffArray[32];
  7. #endif
  8. void FIRQ7::test_fir_q7()
  9. {
  10. const int16_t *configp = configs.ptr();
  11. q7_t *statep = state.ptr();
  12. const q7_t *orgcoefsp = coefs.ptr();
  13. const q7_t *coefsp;
  14. const q7_t *inputp = inputs.ptr();
  15. q7_t *outp = output.ptr();
  16. int i,j;
  17. int blockSize;
  18. int numTaps;
  19. /*
  20. Python script is generating different tests with
  21. different blockSize and numTaps.
  22. We loop on those configs.
  23. */
  24. for(i=0; i < configs.nbSamples() >> 1; i++)
  25. {
  26. blockSize = configp[0];
  27. numTaps = configp[1];
  28. #if defined(ARM_MATH_MVEI)
  29. /* Copy coefficients and pad to zero
  30. */
  31. memset(coeffArray,0,32);
  32. for(j=0;j < numTaps; j++)
  33. {
  34. coeffArray[j] = orgcoefsp[j];
  35. }
  36. coefsp = coeffArray;
  37. #else
  38. coefsp = orgcoefsp;
  39. #endif
  40. /*
  41. The filter is initialized with the coefs, blockSize and numTaps.
  42. */
  43. arm_fir_init_q7(&this->S,numTaps,coefsp,statep,blockSize);
  44. /*
  45. Input pointer is reset since the same input pattern is used
  46. */
  47. inputp = inputs.ptr();
  48. /*
  49. Python script is filtering a 2*blockSize number of samples.
  50. We do the same filtering in two pass to check (indirectly that
  51. the state management of the fir is working.)
  52. */
  53. arm_fir_q7(&this->S,inputp,outp,blockSize);
  54. outp += blockSize;
  55. inputp += blockSize;
  56. arm_fir_q7(&this->S,inputp,outp,blockSize);
  57. outp += blockSize;
  58. configp += 2;
  59. orgcoefsp += numTaps;
  60. }
  61. ASSERT_EMPTY_TAIL(output);
  62. ASSERT_SNR(output,ref,(q7_t)SNR_THRESHOLD);
  63. ASSERT_NEAR_EQ(output,ref,ABS_ERROR_Q7);
  64. }
  65. void FIRQ7::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
  66. {
  67. Testing::nbSamples_t nb=MAX_NB_SAMPLES;
  68. switch(id)
  69. {
  70. case FIRQ7::TEST_FIR_Q7_1:
  71. break;
  72. }
  73. inputs.reload(FIRQ7::FIRINPUTS_Q7_ID,mgr);
  74. coefs.reload(FIRQ7::FIRCOEFS_Q7_ID,mgr);
  75. configs.reload(FIRQ7::FIRCONFIGS_S16_ID,mgr);
  76. ref.reload(FIRQ7::FIRREFS_Q7_ID,mgr);
  77. output.create(ref.nbSamples(),FIRQ7::OUT_Q7_ID,mgr);
  78. /* Max blockSize + numTaps - 1 as generated by Python script */
  79. state.create(35,FIRQ7::OUT_Q7_ID,mgr);
  80. }
  81. void FIRQ7::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  82. {
  83. output.dump(mgr);
  84. }