DECIMQ15.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #include "DECIMQ15.h"
  2. #include <stdio.h>
  3. #include "Error.h"
  4. #define SNR_THRESHOLD 70
  5. /*
  6. Reference patterns are generated with
  7. a double precision computation.
  8. */
  9. #define ABS_ERROR_Q15 ((q15_t)5)
  10. #define ABS_ERROR_Q63 ((q63_t)(1<<17))
  11. #define ONEHALF 0x40000000
  12. void DECIMQ15::test_fir_decimate_q15()
  13. {
  14. int nbTests;
  15. int nb;
  16. uint32_t *pConfig = config.ptr();
  17. const q15_t * pSrc = input.ptr();
  18. q15_t * pDst = output.ptr();
  19. q15_t * pCoefs = coefs.ptr();
  20. nbTests=config.nbSamples() / 4;
  21. for(nb=0;nb < nbTests; nb++)
  22. {
  23. this->q = pConfig[0];
  24. this->numTaps = pConfig[1];
  25. this->blocksize = pConfig[2];
  26. this->refsize = pConfig[3];
  27. pConfig += 4;
  28. this->status=arm_fir_decimate_init_q15(&(this->S),
  29. this->numTaps,
  30. this->q,
  31. pCoefs,
  32. state.ptr(),
  33. this->blocksize);
  34. ASSERT_TRUE(this->status == ARM_MATH_SUCCESS);
  35. arm_fir_decimate_q15(
  36. &(this->S),
  37. pSrc,
  38. pDst,
  39. this->blocksize);
  40. pSrc += this->blocksize;
  41. pDst += this->refsize;
  42. pCoefs += this->numTaps;
  43. }
  44. ASSERT_EMPTY_TAIL(output);
  45. ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD);
  46. ASSERT_NEAR_EQ(output,ref,ABS_ERROR_Q15);
  47. }
  48. void DECIMQ15::test_fir_interpolate_q15()
  49. {
  50. int nbTests;
  51. int nb;
  52. uint32_t *pConfig = config.ptr();
  53. const q15_t * pSrc = input.ptr();
  54. q15_t * pDst = output.ptr();
  55. q15_t * pCoefs = coefs.ptr();
  56. nbTests=config.nbSamples() / 4;
  57. for(nb=0;nb < nbTests; nb++)
  58. {
  59. this->q = pConfig[0];
  60. this->numTaps = pConfig[1];
  61. this->blocksize = pConfig[2];
  62. this->refsize = pConfig[3];
  63. pConfig += 4;
  64. this->status=arm_fir_interpolate_init_q15(&(this->SI),
  65. this->q,
  66. this->numTaps,
  67. pCoefs,
  68. state.ptr(),
  69. this->blocksize);
  70. ASSERT_TRUE(this->status == ARM_MATH_SUCCESS);
  71. arm_fir_interpolate_q15(
  72. &(this->SI),
  73. pSrc,
  74. pDst,
  75. this->blocksize);
  76. pSrc += this->blocksize;
  77. pDst += this->refsize;
  78. pCoefs += this->numTaps;
  79. }
  80. ASSERT_EMPTY_TAIL(output);
  81. ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD);
  82. ASSERT_NEAR_EQ(output,ref,ABS_ERROR_Q15);
  83. }
  84. void DECIMQ15::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
  85. {
  86. (void)params;
  87. config.reload(DECIMQ15::CONFIGSDECIMQ15_ID,mgr);
  88. switch(id)
  89. {
  90. case DECIMQ15::TEST_FIR_DECIMATE_Q15_1:
  91. config.reload(DECIMQ15::CONFIGSDECIMQ15_ID,mgr);
  92. input.reload(DECIMQ15::INPUT1_Q15_ID,mgr);
  93. coefs.reload(DECIMQ15::COEFS1_Q15_ID,mgr);
  94. ref.reload(DECIMQ15::REF1_DECIM_Q15_ID,mgr);
  95. state.create(16 + 768 - 1,DECIMQ15::STATE_Q15_ID,mgr);
  96. break;
  97. case DECIMQ15::TEST_FIR_INTERPOLATE_Q15_2:
  98. config.reload(DECIMQ15::CONFIGSINTERPQ15_ID,mgr);
  99. input.reload(DECIMQ15::INPUT2_Q15_ID,mgr);
  100. coefs.reload(DECIMQ15::COEFS2_Q15_ID,mgr);
  101. ref.reload(DECIMQ15::REF2_INTERP_Q15_ID,mgr);
  102. state.create(16 + 768 - 1,DECIMQ15::STATE_Q15_ID,mgr);
  103. break;
  104. }
  105. output.create(ref.nbSamples(),DECIMQ15::OUT_Q15_ID,mgr);
  106. }
  107. void DECIMQ15::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  108. {
  109. (void)id;
  110. output.dump(mgr);
  111. }