FIRQ7.cpp 3.2 KB

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