FIRQ7.cpp 3.6 KB

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