DECIMF32.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #include "DECIMF32.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 (8.0e-4)
  10. void DECIMF32::test_fir_decimate_f32()
  11. {
  12. int nbTests;
  13. int nb;
  14. uint32_t *pConfig = config.ptr();
  15. const float32_t * pSrc = input.ptr();
  16. float32_t * pDst = output.ptr();
  17. float32_t * pCoefs = coefs.ptr();
  18. nbTests=config.nbSamples() / 4;
  19. for(nb=0;nb < nbTests; nb++)
  20. {
  21. this->q = pConfig[0];
  22. this->numTaps = pConfig[1];
  23. this->blocksize = pConfig[2];
  24. this->refsize = pConfig[3];
  25. pConfig += 4;
  26. this->status=arm_fir_decimate_init_f32(&(this->S),
  27. this->numTaps,
  28. this->q,
  29. pCoefs,
  30. state.ptr(),
  31. this->blocksize);
  32. ASSERT_TRUE(this->status == ARM_MATH_SUCCESS);
  33. arm_fir_decimate_f32(
  34. &(this->S),
  35. pSrc,
  36. pDst,
  37. this->blocksize);
  38. pSrc += this->blocksize;
  39. pDst += this->refsize;
  40. pCoefs += this->numTaps;
  41. }
  42. ASSERT_EMPTY_TAIL(output);
  43. ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD);
  44. ASSERT_REL_ERROR(output,ref,REL_ERROR);
  45. }
  46. void DECIMF32::test_fir_interpolate_f32()
  47. {
  48. int nbTests;
  49. int nb;
  50. uint32_t *pConfig = config.ptr();
  51. const float32_t * pSrc = input.ptr();
  52. float32_t * pDst = output.ptr();
  53. float32_t * pCoefs = coefs.ptr();
  54. nbTests=config.nbSamples() / 4;
  55. for(nb=0;nb < nbTests; nb++)
  56. {
  57. this->q = pConfig[0];
  58. this->numTaps = pConfig[1];
  59. this->blocksize = pConfig[2];
  60. this->refsize = pConfig[3];
  61. pConfig += 4;
  62. this->status=arm_fir_interpolate_init_f32(&(this->SI),
  63. this->q,
  64. this->numTaps,
  65. pCoefs,
  66. state.ptr(),
  67. this->blocksize);
  68. ASSERT_TRUE(this->status == ARM_MATH_SUCCESS);
  69. arm_fir_interpolate_f32(
  70. &(this->SI),
  71. pSrc,
  72. pDst,
  73. this->blocksize);
  74. pSrc += this->blocksize;
  75. pDst += this->refsize;
  76. pCoefs += this->numTaps;
  77. }
  78. ASSERT_EMPTY_TAIL(output);
  79. ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD);
  80. ASSERT_REL_ERROR(output,ref,REL_ERROR);
  81. }
  82. void DECIMF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
  83. {
  84. (void)params;
  85. switch(id)
  86. {
  87. case DECIMF32::TEST_FIR_DECIMATE_F32_1:
  88. config.reload(DECIMF32::CONFIGSDECIMF32_ID,mgr);
  89. input.reload(DECIMF32::INPUT1_F32_ID,mgr);
  90. coefs.reload(DECIMF32::COEFS1_F32_ID,mgr);
  91. ref.reload(DECIMF32::REF1_DECIM_F32_ID,mgr);
  92. state.create(16 + 768 - 1,DECIMF32::STATE_F32_ID,mgr);
  93. break;
  94. case DECIMF32::TEST_FIR_INTERPOLATE_F32_2:
  95. config.reload(DECIMF32::CONFIGSINTERPF32_ID,mgr);
  96. input.reload(DECIMF32::INPUT2_F32_ID,mgr);
  97. coefs.reload(DECIMF32::COEFS2_F32_ID,mgr);
  98. ref.reload(DECIMF32::REF2_INTERP_F32_ID,mgr);
  99. state.create(16 + 768 - 1,DECIMF32::STATE_F32_ID,mgr);
  100. break;
  101. }
  102. output.create(ref.nbSamples(),DECIMF32::OUT_F32_ID,mgr);
  103. }
  104. void DECIMF32::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  105. {
  106. (void)id;
  107. output.dump(mgr);
  108. }