FIRF32.cpp 3.1 KB

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