FIRF32.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #include "FIRF32.h"
  2. #include <stdio.h>
  3. #include "Error.h"
  4. #define SNR_THRESHOLD 120
  5. /*
  6. Reference patterns are generated with
  7. a double precision computation.
  8. */
  9. #define REL_ERROR (3.0e-5)
  10. #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  11. static __ALIGNED(8) float32_t coeffArray[32];
  12. #endif
  13. static void checkInnerTail(float32_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 FIRF32::test_fir_f32()
  21. {
  22. const int16_t *configp = configs.ptr();
  23. float32_t *statep = state.ptr();
  24. const float32_t *orgcoefsp = coefs.ptr();
  25. const float32_t *coefsp;
  26. const float32_t *inputp = inputs.ptr();
  27. float32_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. int nb=0;
  35. /*
  36. Python script is generating different tests with
  37. different blockSize and numTaps.
  38. We loop on those configs.
  39. */
  40. for(i=0; i < configs.nbSamples() ; i += 2)
  41. {
  42. blockSize = configp[0];
  43. numTaps = configp[1];
  44. nb += 2*blockSize;
  45. #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  46. /* Copy coefficients and pad to zero
  47. */
  48. memset(coeffArray,0,32*sizeof(float32_t));
  49. for(j=0;j < numTaps; j++)
  50. {
  51. coeffArray[j] = orgcoefsp[j];
  52. }
  53. coefsp = coeffArray;
  54. #else
  55. coefsp = orgcoefsp;
  56. #endif
  57. /*
  58. The filter is initialized with the coefs, blockSize and numTaps.
  59. */
  60. arm_fir_init_f32(&this->S,numTaps,coefsp,statep,blockSize);
  61. /*
  62. Input pointer is reset since the same input pattern is used
  63. */
  64. inputp = inputs.ptr();
  65. /*
  66. Python script is filtering a 2*blockSize number of samples.
  67. We do the same filtering in two pass to check (indirectly that
  68. the state management of the fir is working.)
  69. */
  70. arm_fir_f32(&this->S,inputp,outp,blockSize);
  71. outp += blockSize;
  72. checkInnerTail(outp);
  73. inputp += blockSize;
  74. arm_fir_f32(&this->S,inputp,outp,blockSize);
  75. outp += blockSize;
  76. checkInnerTail(outp);
  77. configp += 2;
  78. orgcoefsp += numTaps;
  79. }
  80. ASSERT_EMPTY_TAIL(output);
  81. ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD);
  82. ASSERT_REL_ERROR(output,ref,REL_ERROR);
  83. }
  84. void FIRF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
  85. {
  86. (void)params;
  87. switch(id)
  88. {
  89. case FIRF32::TEST_FIR_F32_1:
  90. break;
  91. }
  92. inputs.reload(FIRF32::FIRINPUTS_F32_ID,mgr);
  93. coefs.reload(FIRF32::FIRCOEFS_F32_ID,mgr);
  94. configs.reload(FIRF32::FIRCONFIGS_S16_ID,mgr);
  95. ref.reload(FIRF32::FIRREFS_F32_ID,mgr);
  96. output.create(ref.nbSamples(),FIRF32::OUT_F32_ID,mgr);
  97. /* Max 2*blockSize + numTaps - 1 as generated by Python script
  98. A temp buffer blockSize is used by Helium implementation.
  99. It is at beginning of state buffer and is NOT the state
  100. of the FIR which is in the following part.
  101. */
  102. state.create(47+47,FIRF32::OUT_F32_ID,mgr);
  103. }
  104. void FIRF32::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  105. {
  106. (void)id;
  107. output.dump(mgr);
  108. }