FIRQ15.cpp 2.9 KB

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