FIRQ31.cpp 3.3 KB

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