DECIMQ31.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #include "DECIMQ31.h"
  2. #include <stdio.h>
  3. #include "Error.h"
  4. #define SNR_THRESHOLD 100
  5. /*
  6. Reference patterns are generated with
  7. a double precision computation.
  8. */
  9. #define ABS_ERROR_Q31 ((q31_t)2)
  10. #define ABS_ERROR_Q63 ((q63_t)(1<<17))
  11. #define ONEHALF 0x40000000
  12. void DECIMQ31::test_fir_decimate_q31()
  13. {
  14. int nbTests;
  15. int nb;
  16. uint32_t *pConfig = config.ptr();
  17. const q31_t * pSrc = input.ptr();
  18. q31_t * pDst = output.ptr();
  19. q31_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_q31(&(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_q31(
  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_Q31);
  47. }
  48. void DECIMQ31::test_fir_interpolate_q31()
  49. {
  50. int nbTests;
  51. int nb;
  52. uint32_t *pConfig = config.ptr();
  53. const q31_t * pSrc = input.ptr();
  54. q31_t * pDst = output.ptr();
  55. q31_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_q31(&(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_q31(
  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_Q31);
  83. }
  84. void DECIMQ31::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
  85. {
  86. (void)params;
  87. switch(id)
  88. {
  89. case DECIMQ31::TEST_FIR_DECIMATE_Q31_1:
  90. config.reload(DECIMQ31::CONFIGSDECIMQ31_ID,mgr);
  91. input.reload(DECIMQ31::INPUT1_Q31_ID,mgr);
  92. coefs.reload(DECIMQ31::COEFS1_Q31_ID,mgr);
  93. ref.reload(DECIMQ31::REF1_DECIM_Q31_ID,mgr);
  94. state.create(16 + 768 - 1,DECIMQ31::STATE_Q31_ID,mgr);
  95. break;
  96. case DECIMQ31::TEST_FIR_INTERPOLATE_Q31_2:
  97. config.reload(DECIMQ31::CONFIGSINTERPQ31_ID,mgr);
  98. input.reload(DECIMQ31::INPUT2_Q31_ID,mgr);
  99. coefs.reload(DECIMQ31::COEFS2_Q31_ID,mgr);
  100. ref.reload(DECIMQ31::REF2_INTERP_Q31_ID,mgr);
  101. state.create(16 + 768 - 1,DECIMQ31::STATE_Q31_ID,mgr);
  102. break;
  103. }
  104. output.create(ref.nbSamples(),DECIMQ31::OUT_Q31_ID,mgr);
  105. }
  106. void DECIMQ31::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  107. {
  108. (void)id;
  109. output.dump(mgr);
  110. }