FIRQ15.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include "FIRQ15.h"
  2. #include "Error.h"
  3. #define SNR_THRESHOLD 59
  4. #define ABS_ERROR_Q15 ((q15_t)2)
  5. #if defined(ARM_MATH_MVEI)
  6. static __ALIGNED(8) q15_t coeffArray[32];
  7. #endif
  8. void FIRQ15::test_fir_q15()
  9. {
  10. const int16_t *configp = configs.ptr();
  11. q15_t *statep = state.ptr();
  12. const q15_t *orgcoefsp = coefs.ptr();
  13. const q15_t *coefsp;
  14. const q15_t *inputp = inputs.ptr();
  15. q15_t *outp = output.ptr();
  16. int i,j;
  17. int blockSize;
  18. int numTaps;
  19. int nb=0;
  20. /*
  21. Python script is generating different tests with
  22. different blockSize and numTaps.
  23. We loop on those configs.
  24. */
  25. for(i=0; i < configs.nbSamples(); i += 2)
  26. {
  27. blockSize = configp[0];
  28. numTaps = configp[1];
  29. #if defined(ARM_MATH_MVEI)
  30. /* Copy coefficients and pad to zero
  31. */
  32. memset(coeffArray,0,32);
  33. for(j=0;j < numTaps; j++)
  34. {
  35. coeffArray[j] = orgcoefsp[j];
  36. }
  37. coefsp = coeffArray;
  38. #else
  39. coefsp = orgcoefsp;
  40. #endif
  41. /*
  42. The filter is initialized with the coefs, blockSize and numTaps.
  43. */
  44. arm_fir_init_q15(&this->S,numTaps,coefsp,statep,blockSize);
  45. /*
  46. Input pointer is reset since the same input pattern is used
  47. */
  48. inputp = inputs.ptr();
  49. /*
  50. Python script is filtering a 2*blockSize number of samples.
  51. We do the same filtering in two pass to check (indirectly that
  52. the state management of the fir is working.)
  53. */
  54. arm_fir_q15(&this->S,inputp,outp,blockSize);
  55. outp += blockSize;
  56. inputp += blockSize;
  57. arm_fir_q15(&this->S,inputp,outp,blockSize);
  58. outp += blockSize;
  59. configp += 2;
  60. orgcoefsp += numTaps;
  61. nb += 2*blockSize;
  62. }
  63. ASSERT_EMPTY_TAIL(output);
  64. ASSERT_SNR(output,ref,(q15_t)SNR_THRESHOLD);
  65. ASSERT_NEAR_EQ(output,ref,ABS_ERROR_Q15);
  66. }
  67. void FIRQ15::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
  68. {
  69. Testing::nbSamples_t nb=MAX_NB_SAMPLES;
  70. switch(id)
  71. {
  72. case FIRQ15::TEST_FIR_Q15_1:
  73. break;
  74. }
  75. inputs.reload(FIRQ15::FIRINPUTS_Q15_ID,mgr);
  76. coefs.reload(FIRQ15::FIRCOEFS_Q15_ID,mgr);
  77. configs.reload(FIRQ15::FIRCONFIGS_S16_ID,mgr);
  78. ref.reload(FIRQ15::FIRREFS_Q15_ID,mgr);
  79. output.create(ref.nbSamples(),FIRQ15::OUT_Q15_ID,mgr);
  80. /* Max blockSize + numTaps - 1 as generated by Python script
  81. numTaps may be increased by 1 by Python script to force it to even values
  82. */
  83. state.create(36,FIRQ15::OUT_Q15_ID,mgr);
  84. }
  85. void FIRQ15::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  86. {
  87. output.dump(mgr);
  88. }