FIRF16.cpp 3.9 KB

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