FIRF16.cpp 3.4 KB

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